hfsplus: fix expand when not enough available space
Subsystems (2)
PATCH v2 1/1 hfsplus: fix expand when not enough available space
v1->v2
* Description clarified.
Fix a bug which is reproduced as follows. Create a file:
echo abc > test_file
Try to expand the file beyond available space:
truncate --size=<size exceeding available space> test_file
Since HFS+ does not support file size > allocated size, truncate should fail. However, it ends successfully. The driver returns success despite having been unable to allocate the requested space for the file. Also filesystem check finds an error:
Checking catalog file.
Incorrect size for file test_file
(It should be 469094400 instead of 1000000000)
Add a piece of code analogous to code in the fat driver. Now a proper error is returned and filesystem remains consistent.
--- fs/hfsplus/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/hfsplus/inode.c +6 -0
@@ -254,6 +254,12 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)if ((attr->ia_valid &ATTR_SIZE ) && attr->ia_size !=i_size_read (inode)) {inode_dio_wait (inode); +if (attr->ia_size > inode->i_size) { + error =generic_cont_expand_simple (inode, + attr->ia_size); +if (error) +return error; + }truncate_setsize (inode, attr->ia_size);hfsplus_file_truncate (inode); }
Signature · 1 line
2.1.2
Hi Sergei,
Quoted 17 lines · Sergei Antonov
v1->v2
* Description clarified.Fix a bug which is reproduced as follows. Create a file:
echo abc >test_file
Try to expand the file beyond available space:
truncate --size=<size exceeding available space>test_file
Since HFS+ does not support file size > allocated size, truncate should fail. However, it ends successfully. The driver returns success despite having been unable to allocate the requested space for the file. Also filesystem check finds an error:
Checking catalog file.
Incorrect size for filetest_file
(It should be 469094400 instead of 1000000000)
Quoted 2 lines
Add a piece of code analogous to code in the fat driver. Now a proper error is returned and filesystem remains consistent.
Your patch makes sense and looks good.
Best regards,
Anton
Quoted 31 lines
Cc Andrew Morton <[email protected]>Cc Vyacheslav Dubeyko <[email protected]>Cc Hin-Tak Leung <[email protected]>Cc Anton Altaparmakov <[email protected]>Cc Al Viro <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Sougata Santra <[email protected]>Signed-off-by Sergei Antonov <[email protected]>---
fs/hfsplus/inode.c| 6 ++++++1 file changed, 6 insertions(+)fs/hfsplus/inode.c +6
-0@@ -254,6 +254,12 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)if ((attr->ia_valid &ATTR_SIZE ) && attr->ia_size !=i_size_read (inode)) {inode_dio_wait (inode); +if (attr->ia_size > inode->i_size) { + error =generic_cont_expand_simple (inode, + attr->ia_size); +if (error) +return error; + }truncate_setsize (inode, attr->ia_size);hfsplus_file_truncate (inode); }Signature · 1 line
2.1.2
Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @) Lead in File System Development, Tuxera Inc., http://www.tuxera.com/ Linux NTFS maintainer