From patchwork Tue Aug 29 04:50:25 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: 13368553 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 64C4CC83F12 for ; Tue, 29 Aug 2023 04:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbjH2Evb (ORCPT ); Tue, 29 Aug 2023 00:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234840AbjH2EvE (ORCPT ); Tue, 29 Aug 2023 00:51:04 -0400 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 019311B6 for ; Mon, 28 Aug 2023 21:50:50 -0700 (PDT) Received: from pps.filterd (m0209321.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T2CthE004986; Tue, 29 Aug 2023 04:50:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=S1; bh=dnoL8fw4gbNSdVCT6FzfvAWl9JhHVkgeA7esLoe8fpA=; b=cc6hbJtIL7sHhIRef9cuVv9ZA36pXAL00ErCKHDxdGc5iT+gEYfYw51msPh6qffcB4ch mcY738rQL9OBdKFqKKVGlEOmIxZg5iu/lHHitqoNfb5sXmp6YrJQepXZJyO392zz53Zk YJxWz09ccnT951tjkOeGY+t1Cc2PWQB9daI+1WgDmnpsB7TIO/zhvzX00Cx+isTpR4ZO zunzjqLwaJeL548gDoSQ9YD4myRLIJHBL6zYQxSfNqOF1yg3YOHe0ylKQi1ulqdbpXNS ODhNVajbUDIPMZQ/qma5XhVPQO40TGbaxagkf93Ajc6W4RPDJEy3Lg+Z7uoJ8duaHKPx Rg== Received: from apc01-sg2-obe.outbound.protection.outlook.com (mail-sgaapc01lp2104.outbound.protection.outlook.com [104.47.26.104]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3sq9eq27vh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Aug 2023 04:50:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ryy6hSpCtS15W03C7tXqnJG7x3A++7YfHQK40WKMTMhkYuC+s3OA3YDV/S+FkQjvCH88pr2+uN5VVrbUNSpeGARBYvGzuRPrB3az8GNbN05qWtN+EZP0sjCDe1ucbGiZUpXveVWpzhNpUAidl4n606wtfL22FIlCwpE+wcsi2ZtbRXv4KpK5FXSvnBysLJoKVP353bFGAgdWM5rXQiJWVmYMV/8bysZ3bN2bmiumUCmGAxfeNjFq0NCsKQh3dEK+zN+0CqaTJL9xYBCTZr6qc6RGvbIqFuCHt0v9gy57XUmZTTI4jdwJA6CQAuXi1fadSGVTBlto4zA5WWJQ3/BzHg== 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=dnoL8fw4gbNSdVCT6FzfvAWl9JhHVkgeA7esLoe8fpA=; b=KdlmjjO6tM7qvKv2HopVncsuUPMT6e+RwGCLGQDkSh5zuHEtVv7TZsEmXDW7OhJoBgYg1VAiA0nvscbbOMUF+zlvaSiYVnxsaPgc17CQpLQhWLtpFx14ZjoHr1YK/OyGkO7Y2fzah9tS9VvIwtetdYS77TtuVNRHVEQDbBVjsn1cycMldDbQp70Omlh7n6q2yEgECroV055W5YyB0lIqXbxrXIjpr4gawZdnOjiGmAWzw6pjynim2aGKb9EKJUlUli8ZfcfUBbVmw/agrPSz9DOpXcBBvvcrcz5tO1ubQHLH4H7gf4vv2Ax4pGQhliMTQQ8wb/9ADAVgl0uUMBYiLg== 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 KL1PR0401MB4340.apcprd04.prod.outlook.com (2603:1096:820:24::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 04:50:25 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::9391:4226:3529:ac7c]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::9391:4226:3529:ac7c%7]) with mapi id 15.20.6699.035; Tue, 29 Aug 2023 04:50:25 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v1 1/2] exfat: support handle zero-size directory Thread-Topic: [PATCH v1 1/2] exfat: support handle zero-size directory Thread-Index: AdnaM6+rTi+c67iESxawzowej0Gbfw== Date: Tue, 29 Aug 2023 04:50:25 +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_|KL1PR0401MB4340:EE_ x-ms-office365-filtering-correlation-id: e236c12f-1021-435f-e1d7-08dba84b75fa x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: rOu22CMuEg+QEUwQ5SIgVUu6Z/nlvMyT3PHILVowWCtRcrFhnZ9q98CMPSDQCPeVJOm9r2Jcr/g4onWy8z2MNcXObQLn9hYL0uRTvLRNHBIzGcSJz42mJxzdxaoy8m+R2kZUzW+GN5di/n4YGAiIgCFL6pJAddXjyAb4EJsGzwtPnXS0vO1Dc7Lrriy4u5kGSlRPephc2r7KKL+QqStPFrzYfecGeDsoMWUyYdOWbR89mpFN/7vvw+Xe7vtG+a/QLtGkcHh5Uu8nYqLfJE5NB14FrajIENZZ3Txr+PJIQWCljvudotIdEbPXQcZR4u6S1Z5mWpspsRXrdZdY7BhVW1ESMHwSe4Q4tfRr9NYtKBe5F71gPa249rhUDj+YPnvyIZp5SWNP6nNkpTuO2uWOe6F+spCEvFSRZVviZVcQTYFhR5gN6tgj+0/k8CyxzCj9pCG2q4RQDB4zd5QipgcHZUM+fy3kSZ+EChGeHK3seaJvSQE2dNk631N4qZmHTMkibNrYMFk6/428Kj3U6R2HKlJ9+6q+fFTOhfu6rOiXScAM44otuSqBVfSQvziHJnoeTr+k/Jg0U7HL+3ByAPEmJeyxWBSQJ9NxqsLOqB5FiL494RDHbnVcDTvvcSGNcBdm 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:(13230031)(39860400002)(136003)(376002)(366004)(396003)(346002)(186009)(451199024)(1800799009)(9686003)(7696005)(6506007)(71200400001)(478600001)(83380400001)(107886003)(76116006)(26005)(2906002)(54906003)(316002)(64756008)(66446008)(66476007)(66946007)(52536014)(66556008)(110136005)(41300700001)(8936002)(5660300002)(8676002)(4326008)(33656002)(55016003)(122000001)(82960400001)(38070700005)(38100700002)(86362001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-ex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io5H8v9dDXDMJ4G3x7SOAgFq7VMrmyFS9b8t4h5TGPdg54RiMGfMilIDAKn+cj8RRLaTxri5H3YkugtWBNW0ikLfEtlVi3eR51SE5hhOXGCAu9TDiyGg9uhXVsIwx7UCR6MJ2/GL8x5UyEcKKy+x9Zq4xcqFKy0ovZ8kfMmuqTWt6Er63dS0kv/UsXllqV/8HXUtMgfcIIpulpQSibkVVDriqlS8XfQ24HCz/HxG+8a7Sate/SQnzpR3xj5PX2FnGHtty+SW5ClxMjTs7QHXegzpuJFPKSKQxJ0nKf/iryfV4kmJdSWiRCh+NRq2gvwQPl0s+O4u81tJkhQS8nmCEayDqD1ssKOEoNo2dqCGaF85wi+vhfIJXPSAqYXjnCQ/i4N7EFaPkI5rlO9EyhzP8MRJpLA1Ij4gMPhyPP3uwYGolx2pT+CtabRLpkH9Z+NKhplbJcg9uPyjtTLc/rTPQNMF+dvRZS+85P/MfFMZRn303J5/UeMlJP++sfXgEhZrNhErI4N9RSgrNFRCe/8gHxFDzKm6wffAmMPzLNJUQN8ceP2RBeXWou8KjcwNoJn5roiRrFRnt8QALzfgPaqb70Pi47TK5cPieXV1rbLtEy9DA3VeTZY+LP7ah5o1UILqYGrFLp2htnhAI6ErzDwv/FGLEaRlsGld1nc+PsYbm3XsOOJ1f7p6C07rD+JZDYt1JbL3AzJa+eVoNyhTGv5Si6uOQ== 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: e236c12f-1021-435f-e1d7-08dba84b75fa X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 04:50:25.8197 (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: yM2yAIS/OdfvNVqF445AcqkvqZXXg10G9A+UWtXkydLSfVKyMWPz4gZutl42o6r/D6h7VD2GY07BCH9zwTUxDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB4340 X-Proofpoint-GUID: zfbWYtTGJBVKVqVJgZAC5YveUBwsfIsD X-Proofpoint-ORIG-GUID: zfbWYtTGJBVKVqVJgZAC5YveUBwsfIsD X-Sony-Outbound-GUID: zfbWYtTGJBVKVqVJgZAC5YveUBwsfIsD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_01,2023-08-28_04,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org After repairing a corrupted file system with exfatprogs' fsck.exfat, zero-size directories may result. It is also possible to create zero-size directories in other exFAT implementation, such as Paragon ufsd dirver. As described in the specification, the lower directory size limits is 0 bytes. Without this commit, sub-directories and files cannot be created under a zero-size directory, and it cannot be removed. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/namei.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index e0ff9d156f6f..43774693f65f 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -351,14 +351,20 @@ static int exfat_find_empty_entry(struct inode *inode, if (exfat_check_max_dentries(inode)) return -ENOSPC; - /* we trust p_dir->size regardless of FAT type */ - if (exfat_find_last_cluster(sb, p_dir, &last_clu)) - return -EIO; - /* * Allocate new cluster to this directory */ - exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags); + if (ei->start_clu != EXFAT_EOF_CLUSTER) { + /* we trust p_dir->size regardless of FAT type */ + if (exfat_find_last_cluster(sb, p_dir, &last_clu)) + return -EIO; + + exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags); + } else { + /* This directory is empty */ + exfat_chain_set(&clu, EXFAT_EOF_CLUSTER, 0, + ALLOC_NO_FAT_CHAIN); + } /* allocate a cluster */ ret = exfat_alloc_cluster(inode, 1, &clu, IS_DIRSYNC(inode)); @@ -368,6 +374,11 @@ static int exfat_find_empty_entry(struct inode *inode, if (exfat_zeroed_cluster(inode, clu.dir)) return -EIO; + if (ei->start_clu == EXFAT_EOF_CLUSTER) { + ei->start_clu = clu.dir; + p_dir->dir = clu.dir; + } + /* append to the FAT chain */ if (clu.flags != p_dir->flags) { /* no-fat-chain bit is disabled, @@ -646,7 +657,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname, info->type = exfat_get_entry_type(ep); info->attr = le16_to_cpu(ep->dentry.file.attr); info->size = le64_to_cpu(ep2->dentry.stream.valid_size); - if ((info->type == TYPE_FILE) && (info->size == 0)) { + if (info->size == 0) { info->flags = ALLOC_NO_FAT_CHAIN; info->start_clu = EXFAT_EOF_CLUSTER; } else { @@ -890,6 +901,9 @@ static int exfat_check_dir_empty(struct super_block *sb, dentries_per_clu = sbi->dentries_per_clu; + if (p_dir->dir == EXFAT_EOF_CLUSTER) + return 0; + exfat_chain_dup(&clu, p_dir); while (clu.dir != EXFAT_EOF_CLUSTER) { @@ -1257,7 +1271,8 @@ static int __exfat_rename(struct inode *old_parent_inode, } /* Free the clusters if new_inode is a dir(as if exfat_rmdir) */ - if (new_entry_type == TYPE_DIR) { + if (new_entry_type == TYPE_DIR && + new_ei->start_clu != EXFAT_EOF_CLUSTER) { /* new_ei, new_clu_to_free */ struct exfat_chain new_clu_to_free;