From patchwork Tue Mar 24 04:52:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Antonov X-Patchwork-Id: 6077151 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A4FFEBF90F for ; Tue, 24 Mar 2015 04:57:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0C1C2025B for ; Tue, 24 Mar 2015 04:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65876201FA for ; Tue, 24 Mar 2015 04:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752302AbbCXE5N (ORCPT ); Tue, 24 Mar 2015 00:57:13 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=AjIRuxa0+VAGi/D4Qly/9KVu/Ivui3TeCeyFEJ64GEY=; b=YRUE694Ess1s9utHzu62czuxpWr6bszvtmP+P/kSUhWB7oRxW6Wp/iJHKUdtdiCxuI Vc5fKMYWthsQpSB7XPcU0QBLLw3axMBBz8R/RNQDoaEaDPYn+XEK2KrosKb4xYXMJfB9 1vOCuaWuNzPSTcZQbjZiQ2chpQuhJkiZRGtZ+y22OPIlxAL0ZaIx8t88oa+t5mx6+yL0 l5pQapy7jbMdaDGrQfs56pIywNMhUCKm5IUC2fnw30UV3bTriknTPxiaM1VHEiU4V7nW NYDSNWPtTW55OoBDsMwDmb/pIXi8yO/1vu8Diu5jgLavpIIjKdxtSIVz7xPlKW9jLGf+ Nhjg== X-Received: by 10.180.104.33 with SMTP id gb1mr24717493wib.33.1427173030980; Mon, 23 Mar 2015 21:57:10 -0700 (PDT) Received: from localhost.localdomain (HSI-KBW-046-005-223-100.hsi8.kabel-badenwuerttemberg.de. [46.5.223.100]) by mx.google.com with ESMTPSA id hj10sm4264123wjc.48.2015.03.23.21.57.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2015 21:57:10 -0700 (PDT) From: Sergei Antonov To: linux-fsdevel@vger.kernel.org Cc: Andrew Morton , Vyacheslav Dubeyko , Hin-Tak Leung , Anton Altaparmakov , Al Viro , Christoph Hellwig , Sougata Santra , 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> X-Mailer: git-send-email 2.3.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Anton Altaparmakov --- 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); }