summaryrefslogtreecommitdiff
path: root/ext2fs/truncate.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2025-03-18 01:58:27 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2025-03-18 01:58:40 +0100
commitc180703603f314ef83c39aae5a15c83c72918a64 (patch)
tree1370d75389fc7ad1f4d9807734625ec342443206 /ext2fs/truncate.c
parentf5eb71362af4104f6c0e3bdae9e2a89159094016 (diff)
ext2fs: Do not try to frob inline data for regular files and directories
Inline data in i_data is only used by symlinks (and apparently some device nodes in linux). For regular files and directories we don't store data there. This is actually important since otherwise int fd = open("foo.txt", O_WRONLY|O_CREAT); ftruncate(fd, 1024); ftruncate(fd, 10); leads to trying to frob beyond i_data end.
Diffstat (limited to 'ext2fs/truncate.c')
-rw-r--r--ext2fs/truncate.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c
index 44aab3c7..aa3a5a60 100644
--- a/ext2fs/truncate.c
+++ b/ext2fs/truncate.c
@@ -291,7 +291,9 @@ diskfs_truncate (struct node *node, off_t length)
if (length >= node->dn_stat.st_size)
return 0;
- if (! node->dn_stat.st_blocks)
+ if (! node->dn_stat.st_blocks
+ && !S_ISREG (node->dn_stat.st_mode)
+ && !S_ISDIR (node->dn_stat.st_mode))
/* There aren't really any blocks allocated, so just frob the size. This
is true for fast symlinks, and also apparently for some device nodes
in linux. */