From: Sergei Antonov Date: Thu, 16 Apr 2015 19:47:15 +0000 (-0700) Subject: hfsplus: fix expand when not enough available space X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=059a704c43ea8800a689cf90fadb48f1e985c7eb;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git hfsplus: fix expand when not enough available space 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= 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. Signed-off-by: Sergei Antonov Cc: Vyacheslav Dubeyko Cc: Hin-Tak Leung Reviewed-by: Anton Altaparmakov Cc: Al Viro Cc: Christoph Hellwig Cc: Sougata Santra Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 5f86cadb0542..6229214ef7c1 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -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); }