From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sergei Antonov Subject: [PATCH v2] hfsplus: fix expand when not enough available space Date: Tue, 24 Mar 2015 05:52:51 +0100 Message-ID: <1427172771-933-1-git-send-email-saproj@gmail.com> Cc: Andrew Morton , Vyacheslav Dubeyko , Hin-Tak Leung , Anton Altaparmakov , Al Viro , Christoph Hellwig , Sougata Santra , Sergei Antonov To: linux-fsdevel@vger.kernel.org Return-path: Received: from mail-wg0-f54.google.com ([74.125.82.54]:36603 "EHLO mail-wg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750906AbbCXE5M (ORCPT ); Tue, 24 Mar 2015 00:57:12 -0400 Received: by wgra20 with SMTP id a20so161928322wgr.3 for ; Mon, 23 Mar 2015 21:57:11 -0700 (PDT) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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= 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. Cc: Andrew Morton Cc: Vyacheslav Dubeyko Cc: Hin-Tak Leung Cc: Anton Altaparmakov Cc: Al Viro Cc: Christoph Hellwig Cc: Sougata Santra Signed-off-by: Sergei Antonov --- fs/hfsplus/inode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 0cf786f..7691cc1 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); } -- 2.1.2