From patchwork Thu Jan 5 02:56:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13089360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F320C53210 for ; Thu, 5 Jan 2023 02:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjAEC6M (ORCPT ); Wed, 4 Jan 2023 21:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbjAEC6J (ORCPT ); Wed, 4 Jan 2023 21:58:09 -0500 Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F21244364; Wed, 4 Jan 2023 18:58:06 -0800 (PST) Received: from pps.filterd (m0209327.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 304NNw06029174; Thu, 5 Jan 2023 02:57:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=S1; bh=5N9JmxjPdUjuu1UTMYcLIEk+Rf3+aA0PTzb6wV6paDw=; b=gK3p+/CpFlyjGmAZiwWygNpYYaSCUngUItfFqVppIQcKd32UV9MEoo8kqR+gtRK5cpss 1yW6Y0M0rwFiavt5s76RWuMIZaVtNofXwJOX/l9vy8tCbCNGDRM5Yfwi43FW8myNWAjD SfwsqUAt3fTeWpYRxHcmVYz/ZgW5IuH2G+0TxGN0IyCihkpSS7WlWvE6oP3Ybk/30dZN xSXio+v4kq3PLLkBicxMhHqUR7UWYsDN8qnFmRvJwwGPeCANO59HFGaLdDnI7+TeqQax SkLxWunPGw+LI2YH4oEZEhndXVl1V4hCn6QWiZf8iuNCNEB5zOZMTod/rOaZLf3KyHmZ Bg== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2042.outbound.protection.outlook.com [104.47.110.42]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3mtby1c36q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 05 Jan 2023 02:57:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TMPpUZ7h5DDIxqe9dTwG7GGEm1JuXOAmO7BVNGh0UM+T51Oh8jWZ3QosW6gzOpeOj4oTqAjuPpfPAzQY19Lcfg4t7SBdTBOhBFbVPsWm/7zt9mVts+OtPog0x8/de/rRhROP1Ie3IKVr0GNLlC4folbG4eHjGdekvYX8G3zegy+IqAJoEiTClGSYxOK0PKteXtK5EgXdopm0Qbqwj6QvhQ7fBa7JSAywMG/urU8zD8O3aYr3Q3PpmUINE3xKRIFH6C62SdrZ9v8xhBxVP8sU7wOJ7Uab65bHkwdB7HqpQhW3ycG5+Zn2QZy3pyYTPrxv5YjgtUD5H0W+M51AOefyvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5N9JmxjPdUjuu1UTMYcLIEk+Rf3+aA0PTzb6wV6paDw=; b=JMQgeWBFZAzsDQmVfa9AiFH8SEkzVnbBF4s5KeLZapRMsqvxdTj9ViYlbhtwPUrBpZFqa5HU2O7pROv4uC94LMuUiEvXIcAxPJhcycXA7CCt/hAIFnaWS2SxhMIvE/gSYw09Wy0fcHujlNTb1HRN8CY051fXwqtauWKP1aWelAAsNRPkSb6YigUUyDlR6LH2ei2Cv9IAluJW6VUHkHo5wFNQvpBG3L71zXVphWfUy8hfZuS7wtp3TtC06ghv/3FhZUaL61p/P6U7tvocxOGApfGLhBGd3HaKXSwKK0kb6S6ciW3N/AeBlZCj6YEcGrEh7M4VpA0oaYPxnAfoisvuBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by PSAPR04MB4453.apcprd04.prod.outlook.com (2603:1096:301:30::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.14; Thu, 5 Jan 2023 02:56:50 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::1cb5:18cc:712d:1f13]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::1cb5:18cc:712d:1f13%7]) with mapi id 15.20.5986.009; Thu, 5 Jan 2023 02:56:50 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , Wang Yugui Subject: [PATCH v1] exfat: fix inode->i_blocks for non-512 byte sector size device Thread-Topic: [PATCH v1] exfat: fix inode->i_blocks for non-512 byte sector size device Thread-Index: AdkgsPfQiYBCZ5ikRJGUYBPhyntvuQ== Date: Thu, 5 Jan 2023 02:56:50 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|PSAPR04MB4453:EE_ x-ms-office365-filtering-correlation-id: 50856df9-2636-47e6-646f-08daeec87e22 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: CL/cNRMVVP9T+S4287cKjnH6QGb2YztxT0QbdAHNJaa/7dlHf5i9/vZ+ZSSR8JzEPO1t/eE3Eg2GbTD0KIMrwiGlmnCLAhLRiVPEEq9vjKezD7fVHJlJIdOz6/n1M8LT76VS7rByJ76wOSD96K7x3pmFukK1HsspNu9fbOk61Y6w83Zjf7UCC++YnaU0RTxbF7r19IKllu22JRUZxFJH0DfGWvgc7+KFN9OTsh7sfGikit+v3PVM7liAQ1HY8e39gfs+P0C9Ep1F5r90KasMEb5WBITrJ+PUmCIyPKQOI1bOz3DywXtnYyQB2xZRsuCo+X0z2o3kiOK6cTntHhzCvLO/wdO1ltRLKak3IAAuKfasgv4Yo/UNK1pttatMgracT/TNpADNg9/GHlAk9bcPt+PMSLRTxgD4BeKAWI9bJifpXs21CwETpZ16W99InjV8TSeLJwfrIPL1yQ7NNvkFtYMj1phm2TWjbHfE5h+NLSVUECrPSCqCTm+BoWKfEKUC4bwyStNM2r0l4rZjF6SWMI/Ym7AuAV8gE/tj011xlC9fYUujvDF+h213FKNA6jbmsdRga1WDt9mcJ4lcJsR9KQIdAqlNg7xQoW4N7tl3Q4PRs2+Y6+hwps8j+EUFjzJ7rBcycd6jK6xEklYoAK7jrGrRbguvQTxcUOGAaDQe5GngOGi/ws3FdE7w9CCtvI6s0U4dDNS5B/J0CIG4utHmqw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(396003)(366004)(136003)(346002)(376002)(451199015)(478600001)(7696005)(186003)(71200400001)(6506007)(26005)(86362001)(9686003)(122000001)(33656002)(110136005)(54906003)(64756008)(66446008)(8676002)(66476007)(4326008)(38070700005)(316002)(66946007)(66556008)(76116006)(82960400001)(41300700001)(38100700002)(83380400001)(52536014)(8936002)(5660300002)(55016003)(2906002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?pQ9jTrn03dCJtkbm4A//VXulL8bW?= =?utf-8?q?LfBWwK8oE0Cml1IfhLrQw9IWbiFRf1ZqWBb6Z5ij1EWIVRNPWKkcqnc6ivKCeIx5V?= =?utf-8?q?wFw4faD6siA6qmFytHe+YLJBr0QtCMPKqZF/QSD1AZyVLKReUsYLSLAr+lbaXeN2Y?= =?utf-8?q?Y8o5A/8lLA2HvaWk23nU8Ha9AXhKE6xqRlnUmwyE8rmSVKu02rG2/EkKl+Xm4prDb?= =?utf-8?q?NmEGrrAt4rt3ICJxp+zNIwZN1FEnT8Q/KVFTwkgN2JPzj0HSTOmsfU+ecG3hGVIWg?= =?utf-8?q?BGUU59v/MI5ROMU3ZcJRz1BuOQoEljt/rcqix9ohSbo1TJY2nF+11NhpwSyiG8d8Y?= =?utf-8?q?sFbfwao8ApkL9JbU8fIoiw1FCCwUFTB79Mz9xELzlEASHA02C9Zrgw8DbO8tbFctE?= =?utf-8?q?kUsC3e6hMAEs3gMlAvLyl/g/0BsSq6lVW+A/oDta0v/9JuOev+o+xPPUwmfu78zfR?= =?utf-8?q?tzas4fafRMijVEt+ocINgxl7NMJjX9keRZLf3DJaMdRD2Osq0tdJPy1u6AXPRakjb?= =?utf-8?q?KxgIGAWWqG18TlwvKBpRB5uAsSqGtsJYciAnQDkYPgA17i9xIpJbjIWhk4fr9WVnz?= =?utf-8?q?LYMij+2xmQMsW4LAnXqnKl/rmjOnxdP4+QuRUWW4kjT5zt5qgFXoJ18SFcBLUvHFe?= =?utf-8?q?JuKdpU+JM8IgEyDwannSfbMCVSjKdZF5TQKSuihr2Pdh8dQMuJSm1l8DNDxWr3nhm?= =?utf-8?q?K9xTnzseDsB8WhyUSSxLbVhOYU4sfJt9MtwYyMoAWTgCwBt4hqVWsW+2DLM7TlHHm?= =?utf-8?q?VkTIu0oCAWingTTO1NviyC9o1K5RMVnxSmK3RtXyMcFzvAQ6IA5dvqJxomwAQWLoE?= =?utf-8?q?APAusnhcVG+ZDbdAFhrmFKa0PZqhlVhCq9WDWIjBObiEjeu6/i+UW2lztuiL/CdyQ?= =?utf-8?q?3D2UBvSc2Vxuvo+8jBBJBCe2qWPGTF+MwGkoGl2gytIFWg6RZcw/YO+z+xJb54NIX?= =?utf-8?q?avES7dqSPOEJ2LJXxrgRCgNNH5kg15NjSh/DmkzmKI+DcMr+DmatYLAE0ehwXgc4U?= =?utf-8?q?BE54eUiET3N1P399zPjXRiVBemA3MhcRzb4VTbgm8BpqJZd2JiEzxpP+9VvsZzS4k?= =?utf-8?q?IbWkg0gbsTRJHCSEMCboyNA1X9523g9kVAgXCfYiTAFcypkxVcYpvatCPVJeBRdfU?= =?utf-8?q?NrJmtEVacxaxSwK5H/gwE86XBsu17Q7BJA+5qeo62MzUVWNULJVWKnEdS47ljshzq?= =?utf-8?q?zoyIlLqEc99eGCnDM2FAL4AWJseV329vw5lTNX2hwkxxxKQxt5epbYLngbSZN5CTH?= =?utf-8?q?YMi/pBfAQtg7fPzBzAIRp/TOW4Uw4ufC0BqBtYxhpxAvvZZ1gxnZZ+iBdN1OoTa+q?= =?utf-8?q?7uJgFQ63E9OCVeCD2xQ3xAaoCMwgnKMg/ZsX+WvVCqxzE9fpT0qugmFVZMpH6pleP?= =?utf-8?q?rjkV3VNleUr1UsUz5WhKbCxKHbXaDQ35pwyntjVCcTZrrLEjxmokLGs2ndkJyZ3kz?= =?utf-8?q?gOz6k4O3h44wBL8TIeaEHsEfeKzM3Be1tXVilz30aA/Kcgb/bWwur3xg7O3ISRtHR?= =?utf-8?q?hXJhDELcYUXZ?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6JofU1/QFOjXIn6zCoPn3sykiykrpSrhz8sCY6UN58Jz/6hTe4BWBrK8VAPgx48X8f789Gr8Gt3r77ucGBR9w4hhav6cN6JQ8vqO8DW6W52S2GRLKedixLpboMLPplhIDbRTUs2jd4FMSt8gBLBUxRzyPfyjgWEIWonc+fE1tzGkW/wVkm32NLAMboI6NbX8kkDTSaphMs27wujjtzhIurH24lHhNDE5CrbDQPnvftM/jxgWG9U2K0bLteAgBz7ZKAzRXIi6AFoNpX0gjBTQcmmn3bEFtbj0AqsvceXcx5StylncVukcPRshmklfC9Ocj4DhIDS84pLaqRXNg/DEeIYmqSubHgDdSegqNFdjCVcs3M3OPWGZYxcQdTR3sWDyzFETNlpL1s7X75A7Uqw676B9BRYvGqK7bI+Xe5dxXk8p2Rr/gm8/X7C97lkVDIRlijpMrgB0OMDfL8nvAPvnyjHzlqwC6WNAjfk7dGZQ9mlMxRo7xinejy5zRRzV068+PkeWlEDPhlWWec3nqyMsru/F1WuuooBoOLjFsRllAqzY6PI9ZhuPOjVyefKmQDQa6EGxMgOeyl0fExiy970EHUMDHBMgDNrMsd0p79+uRRVw0kWrGQNi1v9VMtdfIxYT6IeWqUWNdWCRcAaii9ur6ZnaRqq5hCfjw8bfpErzjdLIR9ueZoLuD0d/LfT9V+CdHxMfPz3CwdR0XmApBzzo1LMurqfe5ljhDdQcTE2NmJ2yTBaZaRNjJOgMyr4FRid+7m5/PEIuRsw1RSAsTQZE/UZ9m3SOcPZx4cuLgZeGqb3JaBDrNuCh8EYC1XfKVRxWYQNOrT5roTwNcYzT90TiB9q2JNVidl+zvM+EIJeiQSTQkijRh1MN0KyeRrid/8hX X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50856df9-2636-47e6-646f-08daeec87e22 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jan 2023 02:56:50.2930 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: IHsf7j8hWaI3lVKI0jlMGEXgIEszCIfyIEsv5+5ZaAJ5ug4bBP7niAVd759/eLhKTDD5QAiicX0qeUsrYUrWRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR04MB4453 X-Proofpoint-GUID: ipv8LHlwJN9-92FROU-Y3loRIXWV3k6y X-Proofpoint-ORIG-GUID: ipv8LHlwJN9-92FROU-Y3loRIXWV3k6y X-Sony-Outbound-GUID: ipv8LHlwJN9-92FROU-Y3loRIXWV3k6y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-04_07,2023-01-04_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org inode->i_blocks is not real number of blocks, but 512 byte ones. There are inode_add_bytes() and inode_set_bytes() to updata or set inode->i_blocks, this commit uses them to fix the bug. Fixes: 98d917047e8b ("exfat: add file operations") Fixes: 5f2aa075070c ("exfat: add inode operations") Fixes: 719c1e182916 ("exfat: add super block operations") Reported-by: Wang Yugui Signed-off-by: Yuezhang Mo --- fs/exfat/file.c | 3 +-- fs/exfat/inode.c | 6 ++---- fs/exfat/namei.c | 2 +- fs/exfat/super.c | 3 +-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index f5b29072775d..fb8be941ff00 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -209,8 +209,7 @@ void exfat_truncate(struct inode *inode) if (err) goto write_size; - inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> - inode->i_blkbits; + inode_set_bytes(inode, round_up(i_size_read(inode), sbi->cluster_size)); write_size: aligned_size = i_size_read(inode); if (aligned_size & (blocksize - 1)) { diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 5b644cb057fa..97aaea4b6cfa 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -220,8 +220,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset, num_clusters += num_to_be_allocated; *clu = new_clu.dir; - inode->i_blocks += - num_to_be_allocated << sbi->sect_per_clus_bits; + inode_add_bytes(inode, EXFAT_CLU_TO_B(num_to_be_allocated, sbi)); /* * Move *clu pointer along FAT chains (hole care) because the @@ -576,8 +575,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info) exfat_save_attr(inode, info->attr); - inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> - inode->i_blkbits; + inode_set_bytes(inode, round_up(i_size_read(inode), sbi->cluster_size)); inode->i_mtime = info->mtime; inode->i_ctime = info->mtime; ei->i_crtime = info->crtime; diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 5f995eba5dbb..6ad3dff43d10 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -396,7 +396,7 @@ static int exfat_find_empty_entry(struct inode *inode, ei->i_size_ondisk += sbi->cluster_size; ei->i_size_aligned += sbi->cluster_size; ei->flags = p_dir->flags; - inode->i_blocks += 1 << sbi->sect_per_clus_bits; + inode_add_bytes(inode, EXFAT_CLU_TO_B(1, sbi)); } return dentry; diff --git a/fs/exfat/super.c b/fs/exfat/super.c index 35f0305cd493..fa0e78913427 100644 --- a/fs/exfat/super.c +++ b/fs/exfat/super.c @@ -373,8 +373,7 @@ static int exfat_read_root(struct inode *inode) inode->i_op = &exfat_dir_inode_operations; inode->i_fop = &exfat_dir_operations; - inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> - inode->i_blkbits; + inode_set_bytes(inode, round_up(i_size_read(inode), sbi->cluster_size)); ei->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff; ei->i_size_aligned = i_size_read(inode); ei->i_size_ondisk = i_size_read(inode);