From patchwork Mon Mar 11 04:24:46 2024 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: 13588278 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BB62DF41 for ; Mon, 11 Mar 2024 04:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.30.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710131110; cv=fail; b=m7A1KB9h9Sgs6V0uiVO8syyQBVMI1H2fhsnK45c4jRvznFa74m96hTIsZT46S/YjSYwAfsI3Lt4w+pW3zRZXrL90j4pDqERcJpJwhrDN6ReonYSyYoGr01PupsSpkDEPGWAa7KJfgZD7d9iVCbZzrSz4mnYmfQVv6Tpbaq2rUdg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710131110; c=relaxed/simple; bh=pvo0EiKX8AgLZ9hQQsHQ4GWCXMQL+AEmjxDv2EL01gg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XLTV8b1sHU7FwNiiJDfNW5eKbPsCXjN2sO+sx18weHdj29Jqiv2d2Vc00RKF5gAIJu/c8wd2PjLIGtU4MCC8PrrLNy/G8jXan+sohUqaj6BLafmTbL5XmCg6Ec9sRHkYgHEkkMw0xvWwNUsZUQJDvwmgB9E6EY56slZUR+NQfz0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=PVaKXJSq; arc=fail smtp.client-ip=185.183.30.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="PVaKXJSq" 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 42B0NPOi022127; Mon, 11 Mar 2024 04:24:52 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=pvo0EiKX8AgLZ9hQQsHQ4GWCXMQL+AEmjxDv2EL01gg=; b=PVaKXJSqfQBw/p5K4RZUSxa2IxSrlIfN0ELYqV7WmOMdk+/CpM1A0g2j6Di6Ok3AK6en FwJnfieoN2fWKrfrHyWaolEZ3R4qQlQbCGH3Gvj1lCnaxupbif84dvVnrSyuGzbDAuGC TR6vi7qJmMxeE6dwkh5c3sXaQcD+sjUY7eW+blcHQI0qA+0Crn4Z8090AXxlABNdwwSa jslDz7XbHRmHaYDVzoLdROb2utzVmYsnCuQCAQZ+E+pWy35kbx2FF3RNZtzfHqDiCfBU BUfHcelOO+E9o4ZuZIBv15FXUkLY3Q07HIFSbLlTqvJS/v7GHpBVtvTs4xDhCencOaYk bg== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2041.outbound.protection.outlook.com [104.47.26.41]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3wreb6sdau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Mar 2024 04:24:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DSEPTmvFoEZnE4uyuoogGC+dXPhAxnU39C/aQ4/vMAOysnLSDHVp6YcVvsssWv+vQ2+NErWVtU+Q0N1kFzEnJDWLGJaa9LKJ/fNnpTT7rMxxED3Dws+UolyVQc60dBHHQemooFA55nNXr4COL6Lz8FzzvQHDpRP/SmmnyGqaNs4/mzpCcQ6VfvNrvlfzEXwG3tQ7ohyZKNozmDu7R5LyJkQZ7v50w7uczW5cWvtBnJtttC9pMn1e00r6k68eiZw3cqknZQ2EEuE1vrXUHUwdevAWIIfk4DfniRHKPg9bv7zW34yCLRhQD2Fv2JcZaQo+kXmELCzREne8jYSycahAuQ== 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=pvo0EiKX8AgLZ9hQQsHQ4GWCXMQL+AEmjxDv2EL01gg=; b=SEvbv+mvlLu61WJUFYIqIY1O3DTCAVoihZ/SsxYdHR7g058CgxgWj8GlmUKjF8PihM7uUBOlwP4+wZOkQ90zqqraymnnxlQLr5CkTlKWoZ7+IIqB7yRRZ2+m+F+AJS8LfTSSVX7xgfDd5Bq7TMXZBDBsdXbecMUarPtM+onIOeFwIOYDsGI+NUl7+qxVBXzMJTg658bm3dk605cU/YdAYM97Xx/QbU0gm2rVDPqQ/SYaE2cMsgOd6ZcLaQgx4/SsixdwDZ4Vs38FnBEsxTgp/dAR4HscmN+rXi9/w7ntLDC+EvjYRgx5GILK85Fx/J24WYkFCnJzORnmkx8AQHfgtw== 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 TY0PR04MB6328.apcprd04.prod.outlook.com (2603:1096:400:279::9) by SEYPR04MB7362.apcprd04.prod.outlook.com (2603:1096:101:1a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.34; Mon, 11 Mar 2024 04:24:46 +0000 Received: from TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::c5b0:d335:658e:20bd]) by TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::c5b0:d335:658e:20bd%7]) with mapi id 15.20.7362.031; Mon, 11 Mar 2024 04:24:46 +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 v3 01/10] exfat: add __exfat_get_dentry_set() helper Thread-Topic: [PATCH v3 01/10] exfat: add __exfat_get_dentry_set() helper Thread-Index: AdopyBE5MTMUlvobQIejoYD2xnrYkRJoXQdw Date: Mon, 11 Mar 2024 04:24:46 +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: TY0PR04MB6328:EE_|SEYPR04MB7362:EE_ x-ms-office365-filtering-correlation-id: a5e50f92-64b2-4768-dac8-08dc41832f3c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /wa1M7WsDBC5bX4ftJi9HBYECD/abQ6fLlBjj7Sp+weKbXA5vEiedxw1BbGZmGjyZEHEB47OpGR4254Oyam9kHYVqELz8OQOVT1fMbM5MNr+SOURsf8fB4Rhtb28vIke+l/gZMyQMPX3843E4LMfJA0c2asgSrT8DIlo1gLC9bObkEwdEHPG4HL+PTlg1JRkphByEMwiQroKkSSThypc1S2YJgy7jfuKAbMejt/nr+OjwmdjHJYfolxtHBbtKMhZUEFFSg0xdvp585RXnMgQngIgXcUixRagsuBbvuHTbLWpm5gzPaz8gmu940K7he2VKk3UK496gjw6Rn84ObDt5TiJ8zJc5cyhXieNbjAO1KTY0X8/SmyMe+gpYyoGSgSTOsrKmlFSZZso8l928AxFJVBqQaXfegC6gylsPM8mbajZNailOwlmtlIyF1lSPWUkc5BAH77OA8Y6h0NPS4vVExgzvitFiAHfL77zr7O3BQJcDuhxuKUOOXJGw00LXHnQJjtaTFNH+bZmyBoCHVMYOMwtlLagWTZdO4r+flKgFzx/WdHJ4J+8MZzxgdMACwIz7jO2u3LibwPtErmZlL2gTZqnQhj/KXr0LZPMUvllqjsAwnTzpeXnFx23MWCNy4VMAA4oWvJgLRckylvk99mX7C1MH5w79+M6wvSDrK31RpWzPqxNLT0CSwvwvE5dIrhk0UQCJiKruYqV+VaWY5v3665I2XA69d57KVOE6jtOTBg= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:zh-cn;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TY0PR04MB6328.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?JqUeCtg9Z5uWBQrPKe/VF1MLzic1?= =?utf-8?q?aZo37+gKRBHEQ1BowOU/anCgSD3KR724eqWxMSF2tn1KlXoeRG882ggRucHtrBdTy?= =?utf-8?q?xhZa3/jEJA4dgTmNVizyx1HnJAllySUCAHt78dg+1+JluFLqT12dpwonaKM+6Av4J?= =?utf-8?q?T9S0VmQ0mAe8wufGHW5MgsQ3SYu5IRaD0kmC2sq/OZFArEsfbE4ni6NT/is18fM9x?= =?utf-8?q?98K9vvKAuVkkpZVqPbwYfoNHXGOirlnoIj0NFjzgehjY8Y/kKiaUx5YmcS9MwOzgK?= =?utf-8?q?LFJK2/N0qLAtUbzW73IDtl82B4lYGSDQ4m5eUdSd4sQQ9Zvno8/KHTcb1DNBcUEWx?= =?utf-8?q?MqvTpQRRK7NXEFPU0tU8Y5wdDJAwDKEZP2h5vjVgfv3u3Aj53nopcE+8nLE6Ttoz4?= =?utf-8?q?8UK75Fm/c71F5Zi/yKoiOHSkIa5yL3tEvihkK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6QyiKCFttan9rs?= =?utf-8?q?/CLrcxNCAfF/9zK83z68Xk1+zzy3kceUlNhI3gIMxIkLuuJQ7rLoMrrxChE8321rE?= =?utf-8?q?Pw1Oi6fPUTr+kdDZP3uP9E63DIWSQkpKvdDPlZC9Rudq7K/cGcvE0eAnOWawGt7h4?= =?utf-8?q?LiDmPFChV5bf4VWIFufvg+qyge3BJUwOrmO28QNVF5lNEwGLMAb3XUWqJN22QKY5g?= =?utf-8?q?nO54zqP3J5TK?= Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ZQ+7vdM1BhOzFc81OGiFZSdJX5EouNFJ9ELT1Y6zSH+43pWG1zMtkaDWogJarTGHHR14LI2FZ/xC2x970HX2l1C9b0URn6QuuwFqC55lgJdwXVwo5s1iYY2BivIR1INwdlsdBzPpl2H7mawA0kPC67m9dK1swEXPGXfsT8bEHXJ1Qt/0tI8g/4CD2m1TJzqI+2LVXFX8grJwluz6I04pu1RkQHpE0bYMDGltK2/1msh6bujamzNzL2r2xFe46Xp/TbPjWaIpCcHs8GCWDhAr/Z7txD1semXBHBvQ6y8siIslIfB3o15JJhHDCf2PEZW83j2zeYLRGA9P0oqQfNfDX8cnKPsntIY1X9erdHhBSw5YA5SaW+68XrzPKKdTqn9JRptOMUaC/jd8fwQaDKzd/izC0CpMTJR6ztued0KVIGwZTzPB+f/3U9/p9LZWVKIJy1+foN00y3+Jf2sjSvzYvYBvMLT6WO96TzEmMNMYrWP6O4My9etAZengDhfe0llCYj8fuHRGt9xLNGY6nTZKhg5g0biwaPE2n25heFK2GKrMt8wrnkzLX3Hy3RjGoaWveGJbvG5Y/Q4YyO9eXGpPmNH1W+3uUV4MQMHmYKRfUBv8KTN6mKQN3zGJAefCOQsk X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TY0PR04MB6328.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5e50f92-64b2-4768-dac8-08dc41832f3c X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Mar 2024 04:24:46.8687 (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: YGUZAOzMjmH+0wpMcxSSO19tzGrwVoXR7M4KqEE1SFdEWg1Au75D8Tco9ue7eRoSc1/WZjheJ41nUrgY7jV+vA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR04MB7362 X-Proofpoint-GUID: iYGzSnvhyO9MB-9M_HgO_peEOu3V_DHY X-Proofpoint-ORIG-GUID: iYGzSnvhyO9MB-9M_HgO_peEOu3V_DHY X-Sony-Outbound-GUID: iYGzSnvhyO9MB-9M_HgO_peEOu3V_DHY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-11_01,2024-03-06_01,2023-05-22_02 Since exfat_get_dentry_set() invokes the validate functions of exfat_validate_entry(), it only supports getting a directory entry set of an existing file, doesn't support getting an empty entry set. To remove the limitation, add this helper. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 61 +++++++++++++++++++++++++++++---------------- fs/exfat/exfat_fs.h | 2 +- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 9f9295847a4e..cea9231d2fda 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -775,7 +775,6 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb, } enum exfat_validate_dentry_mode { - ES_MODE_STARTED, ES_MODE_GET_FILE_ENTRY, ES_MODE_GET_STRM_ENTRY, ES_MODE_GET_NAME_ENTRY, @@ -790,11 +789,6 @@ static bool exfat_validate_entry(unsigned int type, return false; switch (*mode) { - case ES_MODE_STARTED: - if (type != TYPE_FILE && type != TYPE_DIR) - return false; - *mode = ES_MODE_GET_FILE_ENTRY; - break; case ES_MODE_GET_FILE_ENTRY: if (type != TYPE_STREAM) return false; @@ -834,7 +828,7 @@ struct exfat_dentry *exfat_get_dentry_cached( } /* - * Returns a set of dentries for a file or dir. + * Returns a set of dentries. * * Note It provides a direct pointer to bh->data via exfat_get_dentry_cached(). * User should call exfat_get_dentry_set() after setting 'modified' to apply @@ -842,22 +836,24 @@ struct exfat_dentry *exfat_get_dentry_cached( * * in: * sb+p_dir+entry: indicates a file/dir - * type: specifies how many dentries should be included. + * num_entries: specifies how many dentries should be included. + * It will be set to es->num_entries if it is not 0. + * If num_entries is 0, es->num_entries will be obtained + * from the first dentry. + * out: + * es: pointer of entry set on success. * return: - * pointer of entry set on success, - * NULL on failure. + * 0 on success + * -error code on failure */ -int exfat_get_dentry_set(struct exfat_entry_set_cache *es, +static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es, struct super_block *sb, struct exfat_chain *p_dir, int entry, - unsigned int type) + unsigned int num_entries) { int ret, i, num_bh; unsigned int off; sector_t sec; struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct exfat_dentry *ep; - int num_entries; - enum exfat_validate_dentry_mode mode = ES_MODE_STARTED; struct buffer_head *bh; if (p_dir->dir == DIR_DELETED) { @@ -880,12 +876,16 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, return -EIO; es->bh[es->num_bh++] = bh; - ep = exfat_get_dentry_cached(es, ES_IDX_FILE); - if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) - goto put_es; + if (num_entries == ES_ALL_ENTRIES) { + struct exfat_dentry *ep; + + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); + if (ep->type != EXFAT_FILE) + goto put_es; + + num_entries = ep->dentry.file.num_ext + 1; + } - num_entries = type == ES_ALL_ENTRIES ? - ep->dentry.file.num_ext + 1 : type; es->num_entries = num_entries; num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb); @@ -918,8 +918,27 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, es->bh[es->num_bh++] = bh; } + return 0; + +put_es: + exfat_put_dentry_set(es, false); + return -EIO; +} + +int exfat_get_dentry_set(struct exfat_entry_set_cache *es, + struct super_block *sb, struct exfat_chain *p_dir, + int entry, unsigned int num_entries) +{ + int ret, i; + struct exfat_dentry *ep; + enum exfat_validate_dentry_mode mode = ES_MODE_GET_FILE_ENTRY; + + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries); + if (ret < 0) + return ret; + /* validate cached dentries */ - for (i = ES_IDX_STREAM; i < num_entries; i++) { + for (i = ES_IDX_STREAM; i < es->num_entries; i++) { ep = exfat_get_dentry_cached(es, i); if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) goto put_es; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 9474cd50da6d..800aea2943e2 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -500,7 +500,7 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es, int num); int exfat_get_dentry_set(struct exfat_entry_set_cache *es, struct super_block *sb, struct exfat_chain *p_dir, int entry, - unsigned int type); + unsigned int num_entries); int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync); int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);