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; From patchwork Tue Aug 29 04:50:30 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: 13368552 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 D63D8C71153 for ; Tue, 29 Aug 2023 04:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbjH2Eu7 (ORCPT ); Tue, 29 Aug 2023 00:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235658AbjH2Euz (ORCPT ); Tue, 29 Aug 2023 00:50:55 -0400 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3085C1A1 for ; Mon, 28 Aug 2023 21:50:47 -0700 (PDT) Received: from pps.filterd (m0209318.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37SN0fYC017063; Tue, 29 Aug 2023 04:50:36 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=pJ8lL+feJg/f4Rvxpz8FM8tisfvmxGCxc0Jb5PBfpCY=; b=Gj8OLYKex4zEykYy3xRp986f10DjJ8MxP7nvyTvT4uc+1rRxvOjv2m+qkPH4b1aRzB/d PRWVG4j1WO40sogvq7kgMwjWMHTKkBdfFjZNp3/ILExPF4YzC/0CSHRVkbNV81lTMv1F zfxz97RBlUGkJEdvgfUKID/qONMiMeNK396dQyKaxbmKb7yA9S5/6wXKzySppLSCThDZ n8dDQZorffOPiUueoYxjFESNN1F0BnkV6nUejUeaWRwR3qKkIxTM8z7WZ82ONhGmslGa nYm+w3UhFsF926hY0J3lNQa676uJAhxYbUho1wu3IJWSbb1fdDb3SHOpZ9njm4HmeAZK nw== Received: from apc01-sg2-obe.outbound.protection.outlook.com (mail-sgaapc01lp2112.outbound.protection.outlook.com [104.47.26.112]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3sq9hpj7jq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Aug 2023 04:50:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E0+8nbnRhH+bL+wMf+Sd1/oICDIPpNeL8r8MjCRomgtZMm3rLa6KxiFx6/IZfXwFfn7egt/lgBDuaDRgrl4FBP1rSzAvktK91iCMUDLh2rb/kEllZQr2pAyv/fpYpnINfiDvFsSR5PY3rWhzYzQ1vEtg0RQkCrHV1GQRgphWzxUr1aiXwop/qdge+IA3YbgX9qdzUn3hLk1i45rmbyXuGIRZ27Y7v9h0g/LYQLhx5Y+RJQFtBBMAbHFaRI6Q1A5es84ZQgXbl689GIzz53cfPqp8bdU8s6efR/eRIFhOkqAsXLBEjyD/70CeHq7MOFdu+2tgGFi01Gc9ufYm84md9w== 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=pJ8lL+feJg/f4Rvxpz8FM8tisfvmxGCxc0Jb5PBfpCY=; b=kvqu3MV1TztVcwNhMVTCOcL+tqP7SjHR0P7CZWkTZYZ2tVZn2DJfPi7mTx8tbUZ9eBlUXIjWI12yC2TjoX4TuiehcjpU4Mk5XqNHIJC0oG6bFC08Y1qNlAQA/23n++jPxnnwPNT1qROkbX0+srYDhS46ANppmmuF6lpOpqi4Yzw4S7kRRQ5ZpefhF6kc/U84YjjhY3NegZpYoAuACfYUYng23kbxAKqEqEXBelcKXsF4nyn0mEmpwMhu64OtnVwJOl4nUggo7Qjlq9gJiLjLwrQ2OMcDYYMsigwoW67bWTQ73ltcA6Fu6RYcV1zRVwpgDQ45rq4jcjomYjo0OL3qJg== 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:30 +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:30 +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 2/2] exfat: support create zero-size directory Thread-Topic: [PATCH v1 2/2] exfat: support create zero-size directory Thread-Index: AdnaNBrmKC9P4VmURO2B4RgAsTksTw== Date: Tue, 29 Aug 2023 04:50:30 +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: b5a17500-e2aa-42e6-ddee-08dba84b789f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Z077RsQSdqG6NjGeUVA4LzN+HIyZa55yaFpE1Jcav9lD3PaKQrE5H2lRw+ZEwv3L6QNTf9KCgTcpr07BrShvQAs42ckQvP9BJdU50tN5gQrLqv0fvr3JOB4Zc/byPi66cGbAD+0xXGdLz8JRjFDl+exUxdOKpO6wNHTxhIIMS7hdkBRVakAzjX3oSWn3XqYhTDhf0vJF2ldtvEujJYn/7LTalmQX35ULV5w5roSrczPifKVGBa1JVw2w0uesIR+wDQQMfKzdAb7oquMyVLjOx5xY9Ie0eoH3gO80Zy40W+8MTuN+iVN9eWyAU+16/qpFNcg0o8O6kdjTbfot8hHR6J1reLrL8TDE+QJBr9AykP1Er7dt14svw787OOcqMuMiZLdr8V/+szJ/FS/wyLWefqhB3MpAb3ybZ7q7v/UuoV7sXwVKVR8wOyDQ3WVTs3YRutgsOAVeYnh63AJn5mzHtLjguIUy/wJJEdl4TJq+2NEG33jfclfofQ5hMKl82rn05IZojq540aLZn24sS/h0O4m0wr131xZimrLX9iAOWItxZHunRAQhQqPVi5qG86scVjdFBHVGc/3YCAPkzRYQRf7koQJSdg280YcCJQn9Qts8OqQH9//tmE4yjXthSEHt 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-exchange-antispam-messagedata-0: =?utf-8?q?FoIbnaBD6NXb3iQrwlhfAJTFfExB?= =?utf-8?q?G++a6Im404NIf/kV2pT2WnaMMr1VJBYbB90VfywnUOvKrcqnygOZQfofG7/Pefygb?= =?utf-8?q?C6Eka+JPIriUrZlS/X7v63APWObxnuB1YOXVUvELlAHTPBx8O9l0H4rJ8gr7OZn5h?= =?utf-8?q?XPFWsApHx6QIY2o/uG7s8YdwxgNft6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4+xh1CNak0+/fngCZ+oR2?= =?utf-8?q?1Gtf7eXdIZYBqTdmGu74kIIWroBRwRFnEIJS6qLJaCuUYrjM3WFRD5SSHl6rxtGQx?= =?utf-8?q?25HwVWGJtuo9aCkWbVvTSh4A33LC2Ldd1YAYoLIUd3l8dlSR2P8TMzFjkyw0QaUOf?= =?utf-8?q?ED/z5bWkzkFAa/vk9o/M830azqCdu/LalOGq2BpmLlbo23U0UeoeRHyCDbQyRrwDt?= =?utf-8?q?KIRLDVBeqgJED3bu6DMpbe5U32MY6OWfxcprr1xAyDn/itZoixoI3LI58WaM3LR2M?= =?utf-8?q?lEed7+sWMRoZfHOYT7UhBdoP1eo1AlzkDMs8b+Hlt8dL3aB+qP8UBb0fIl9xsMaAf?= =?utf-8?q?UmgRFUBC7r77gP7SfbN5y9DQAmS+Fx7+P94W23LfQqfUnBTFp4+U5D8xb8WoPyZaw?= =?utf-8?q?mTbbGXqSEDwDErvCZmvwLzcxbLUJydLaFaDP9Wnx2wkAm3FkcaoqagQtdAIcgh/GD?= =?utf-8?q?stZh3cA01sYw?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +c/wfOT1WAk6ccGkEkue5pIoh7Dg12+5bZTYvfHBMtC805RFVh3lxnCjjMFpPLi/aawRQF77v+wW8dPI37lxhMiG3URK7CQLC1HiRtwQ7BXfXCF5OIoYvK4CitIRSZbl4paAeguLsElVj6lDaX4RyWUcHYYzqIthAxvIIRxNKJYRx1KT9H86LzkUZoitYqLlpsKCQ/OrgQzeUCCrXmbH7mYwJRabeZkbfoj65l89kxrBd1wAwYDUDSVDTLKzUwqg//EMYKr6u5p8WTgTnBx9DXjgplOtq6t6pZVKkWJ8Tsjpz4C1oLkS+Wi3VvXWcJglrry/URXkdZa4jF3Kn1UF7szvAOFpwUYaMAaGxmek3LOTXSV41wM6F0yD/sR+E9SQCFw4R5BriaRiC+SQME82SslpvUuyLn26g9DxXA0U1clnyQB9JjTDAduJ4ULtv+2quJYLo0AdODnzRcybsmCkphQwZOWGD4D1IEuspG0E5TBNfkXVlyn5apsiTG/+T/Cz9y/9QNhQ7uWVXGBAqwdCYebSY9DxxIP29wsEPueNPD5fSmPV/5/pC88NGOqPowyGFiqjY/gdQ6mePA9dRbYcuQzPe69UgY7HdJXE2CbL4OtzdUd1ZcMTc4068Grt8xVYAbH2nzmi6JxpFrXXF8Z+6FL/fhNKuGGupeAe8gaeLfW4Bc/c7jozNig3Fvns8Fmg7fEx3IS4FkX6CVT+iJvIPQSrNuwnTfN08kSgrZxXpXMcZPiN5SNhmT1twMyrx3kTUJBGlWB+/QX6l/OwChkaScPx5JcfVyx0KQTHusuxUKdpHjyo2R1T2Fy7zRdHqfBL63oGSbEOw3+tVbNMyILDQg== 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: b5a17500-e2aa-42e6-ddee-08dba84b789f X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 04:50:30.2709 (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: 2AhPr2TeSZuqZr5uO1KK8TmpI81sp3lmph3N3YUkl2kqsV34VUQIxx+Umbz3GbhCveMdJlIHJMOLBDh0gghQUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB4340 X-Proofpoint-ORIG-GUID: 1KVPk9FkpFlakBRLnoFSVMxDjQ3Ulh7h X-Proofpoint-GUID: 1KVPk9FkpFlakBRLnoFSVMxDjQ3Ulh7h X-Sony-Outbound-GUID: 1KVPk9FkpFlakBRLnoFSVMxDjQ3Ulh7h 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 This commit adds mount option 'zero_size_dir'. If this option enabled, don't allocate a cluster to directory when creating it, and set the directory size to 0. On Windows, a cluster is allocated for a directory when it is created, so the mount option is disabled by default. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 12 ++++++------ fs/exfat/exfat_fs.h | 2 ++ fs/exfat/namei.c | 7 +++++-- fs/exfat/super.c | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 598081d0d059..9ad5ff01456e 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -417,11 +417,13 @@ static void exfat_set_entry_type(struct exfat_dentry *ep, unsigned int type) } static void exfat_init_stream_entry(struct exfat_dentry *ep, - unsigned char flags, unsigned int start_clu, - unsigned long long size) + unsigned int start_clu, unsigned long long size) { exfat_set_entry_type(ep, TYPE_STREAM); - ep->dentry.stream.flags = flags; + if (size == 0) + ep->dentry.stream.flags = ALLOC_FAT_CHAIN; + else + ep->dentry.stream.flags = ALLOC_NO_FAT_CHAIN; ep->dentry.stream.start_clu = cpu_to_le32(start_clu); ep->dentry.stream.valid_size = cpu_to_le64(size); ep->dentry.stream.size = cpu_to_le64(size); @@ -487,9 +489,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, if (!ep) return -EIO; - exfat_init_stream_entry(ep, - (type == TYPE_FILE) ? ALLOC_FAT_CHAIN : ALLOC_NO_FAT_CHAIN, - start_clu, size); + exfat_init_stream_entry(ep, start_clu, size); exfat_update_bh(bh, IS_DIRSYNC(inode)); brelse(bh); diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 729ada9e26e8..cbf32949ff67 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -234,6 +234,8 @@ struct exfat_mount_options { discard:1, /* Issue discard requests on deletions */ keep_last_dots:1; /* Keep trailing periods in paths */ int time_offset; /* Offset of timestamps from UTC (in minutes) */ + /* Support creating zero-size directory, default: false */ + bool zero_size_dir; }; /* diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 43774693f65f..23220dd874e3 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -518,7 +518,7 @@ static int exfat_add_entry(struct inode *inode, const char *path, goto out; } - if (type == TYPE_DIR) { + if (type == TYPE_DIR && !sbi->options.zero_size_dir) { ret = exfat_alloc_new_dir(inode, &clu); if (ret) goto out; @@ -551,7 +551,10 @@ static int exfat_add_entry(struct inode *inode, const char *path, info->num_subdirs = 0; } else { info->attr = ATTR_SUBDIR; - info->start_clu = start_clu; + if (sbi->options.zero_size_dir) + info->start_clu = EXFAT_EOF_CLUSTER; + else + info->start_clu = start_clu; info->size = clu_size; info->num_subdirs = EXFAT_MIN_SUBDIR; } diff --git a/fs/exfat/super.c b/fs/exfat/super.c index 8c32460e031e..b1e03276e0a0 100644 --- a/fs/exfat/super.c +++ b/fs/exfat/super.c @@ -174,6 +174,8 @@ static int exfat_show_options(struct seq_file *m, struct dentry *root) seq_puts(m, ",sys_tz"); else if (opts->time_offset) seq_printf(m, ",time_offset=%d", opts->time_offset); + if (opts->zero_size_dir) + seq_puts(m, ",zero_size_dir"); return 0; } @@ -218,6 +220,7 @@ enum { Opt_keep_last_dots, Opt_sys_tz, Opt_time_offset, + Opt_zero_size_dir, /* Deprecated options */ Opt_utf8, @@ -246,6 +249,7 @@ static const struct fs_parameter_spec exfat_parameters[] = { fsparam_flag("keep_last_dots", Opt_keep_last_dots), fsparam_flag("sys_tz", Opt_sys_tz), fsparam_s32("time_offset", Opt_time_offset), + fsparam_flag("zero_size_dir", Opt_zero_size_dir), __fsparam(NULL, "utf8", Opt_utf8, fs_param_deprecated, NULL), __fsparam(NULL, "debug", Opt_debug, fs_param_deprecated, @@ -314,6 +318,9 @@ static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param) return -EINVAL; opts->time_offset = result.int_32; break; + case Opt_zero_size_dir: + opts->zero_size_dir = true; + break; case Opt_utf8: case Opt_debug: case Opt_namecase: