From patchwork Mon Mar 18 05:21:29 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: 13594974 Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) (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 8324420B0E for ; Mon, 18 Mar 2024 05:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.132.183.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739321; cv=fail; b=ftlNe0jwYebiTEleK2axhTcjqbCixO11YA+DyHR12geT0/9N+RPtYQEZG20RjYoavqgNAUB9JJ1Rs0r4BVv3LbnWGyhIfMpvM3E2bbVAwW+XAIngSUbmd4Gh42+DapfZZvU9McbZ2pZBttfwiZ1nQ6YBQE/6oYbYFGJpJ0h8iJQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739321; c=relaxed/simple; bh=PnhzH8fGr0WSfz7Yzn2ZxGPtd6zTHnHVS/hK3zIJFio=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sIRVgRgIbAXdcj3908OEb6yZJuuaUM1oChEK1r1XFqCHxBla9g3CPIeQF3VQJ7KooZyQUe2de+CE4zruLL/h08Ad3b1CVy8I0zHoLXmMjAZ2ZSs8TlvT5U+bmQ7uRPsERktHNUKA26HHgbvvundWPQ8WWAST9RiZHZ/bf2fptsk= 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=gxebkXCS; arc=fail smtp.client-ip=185.132.183.11 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="gxebkXCS" Received: from pps.filterd (m0209326.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42I5EV3U022214; Mon, 18 Mar 2024 05:21: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=PnhzH8fGr0WSfz7Yzn2ZxGPtd6zTHnHVS/hK3zIJFio=; b=gxebkXCS48IBoOa45MheQKxXeSODFd2UYqqh11RQTa1Ic2wDxUIrffiVKs7BCdGPu67Y UfJQmx+3eNmkM9Yybk1ATHxao0wju5de+kYNSDrIxsicRRElUN4qtkFaxqnS0PiEXwQ9 sPzCN2Hfjm/ZKW4ktbD6Ecz0Yckbw82n+ExU7+YI1M/sGxrbrvLkpD4Z05ANXzJsD92/ aGJwdOOZs5bHcO3w4D8Hb23FZ38oGgW2cmTb683umMYxOvkKtfJw52phDe7gj+KD/Mel xZ53XmxNct6FrCHp69LRDY7tfaAmPk2KqmxgvM4GfNHoszBVTiFC8Fcaboq0rsIuIlqg wA== 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 3ww1mg9qcj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Mar 2024 05:21:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OKKODVDRw7NDNl5C6N9ZLL0aoUEUeVALB1jBbTh+JEaZaH3vsyVDwf9oIlWvXvtW341lDrDlLq5aPkvaYa8HRep0Z/rxGiGFfzYD+yXnMbtqSl6wYxgJVVXhZ2Lq9IzupLEVzwK2dttu3Z+aJf9C0fYQrIcSKvQkl1MjdM4EByo14+Jbj9fYyr1GHZXVQhgL3FQtA0R7sgjCCXIWCBI33bm4H50jNp65xXqQH1aayTxEV3SKIJsD9qi7ILcUVY/OlpXaZM5/E62OkbzdtePGZvaUDxBFZu6NtlVKXtIIsSlgnYYwCaDp+0YJrAVm6TFdQ5KSUBEkEDC0nNadT2ggRg== 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=PnhzH8fGr0WSfz7Yzn2ZxGPtd6zTHnHVS/hK3zIJFio=; b=IwNL/lqDgT1t8wzKDHaeGDdjkZS1a/kzRgaR4SJwBBlMRc7doLy+YwsfwtdMri3LzRTJUEz1v6YXA5/rXqBErIPANffkvCmGZbwumZPWf/CswOTnCFs8iencXMXbcum1FnOQOzpFuKm3nsU4+m/tYX4/rcrOQ9vE7LPwV4uT7J3vC+4k1qYHahC3YweweKOgHYfWBY9H8EVCXLewIPg7Rflae1hO0QUXRFDtWBgslUSjleSoxoEO0VdY9jnb54i22WiQeLn2Q/yZ/qWQYkcjOiHFyQHHGxh+sXrTo/HeNN2NWA+Lm0o+kQ68F/QfGW10cv2JV+opdCjLY/SZDSasgA== 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 SI2PR04MB5895.apcprd04.prod.outlook.com (2603:1096:4:1eb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 05:21:29 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::7414:91e1:bb61:1c8d]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::7414:91e1:bb61:1c8d%7]) with mapi id 15.20.7386.022; Mon, 18 Mar 2024 05:21:29 +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" , Dan Carpenter Subject: [PATCH v4 01/10] exfat: add __exfat_get_dentry_set() helper Thread-Topic: [PATCH v4 01/10] exfat: add __exfat_get_dentry_set() helper Thread-Index: AdopyBE5IlGSbIfjRuOO+PgQhKYhxBPKZcsg Date: Mon, 18 Mar 2024 05:21:29 +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_|SI2PR04MB5895:EE_ x-ms-office365-filtering-correlation-id: 5fb0f5e8-25c5-43d4-210b-08dc470b4473 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1Gwhp6nbjdXkuVI+Emtx7gqZrLpmc/uAHp0j9cdAuE2JmiUWqnYJQMzIHr4mCBVmDKYvhGvDDupwshs3a0KY7rXjByEh9YIBtSzIBkJ2jVtSKUzvLoYAkJvIlMiJSzztqHKuHRHm9bW5npM0ajQwAqtMEAWbdJPAJAy67EM3be7oQe8/Q8SvqWnGZEE7okIKicFBZa5aBPf70NQ42Dp7TXCiVEgCOnIqV0NMJdCB8aAajnK4+zS7WCKFwOJ8bAnoFQsF4JTfptMRl0UT+H95TcJFkfyo2GYEbzuaZeSsMo85ppDjEJwUzacHrW/xpQMyhkBu7kTp1zba8YQSz+KjIl7Qw+qb5BpVN/tlZfEb9TcSryHC7aI6Z+oC00DCzycznBlN33dq3oks9tpYS9Wi6cg7+BGxoN8+GD4UO8g5d/hnZUy5Umm0f/mjV7FBVDn7LwdaNqcx790XAWKq6GiCNxnidR7WOm0DxSzUSJhBZyf9RYHJnW5G7xBOJhjrPUP8qxNzo4enkfq0ixeNRzdxFfEyzMTWE5d3vKlJHmJxErtJuffRt5TEKbx640UjLWTvW0fX0y/ElDkm8PGaW8LaozaIi+Oaq0LrmLOMzM4hZfzlc4koBeUWqyXPJ/YGn9flEe/fAoz3UomOiturWcbBPI2WA+nEbFRXIdZj3kz5r215/8LlsTB7JB9o7zGv2kcKbPuI6Kqs7+gaM3uQSPQMku9oS2f5R/uC9+qQk8e/P60= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:zh-cn;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?at0W3k0yrd1RSnx9+MelAV6Uuh9z?= =?utf-8?q?Sm3kUbB0haJbPpHycC1p23zA8MNnCSrDmJ4dib8vcL0sR8RG5zfNYPDUN2y25vmqv?= =?utf-8?q?eyNxry1ypRh94Dvp+6fZoaMt9beHkdCkduwI1u7Szcybnzz72gZSoHWt2A1f4/8zJ?= =?utf-8?q?P17vo4dCZqIkbJE0X8uNZFTbKfcxYGozthjGYqXwtawV5DFmTjG3W3nv3YhtACtT3?= =?utf-8?q?Tv9A8H0tryMPU4ueorDs+TngetR48QQMR2fBt6xNAVgI8eOITBeWZK3qQ3jM18nwe?= =?utf-8?q?qlkLp3thU0E9Ahel6YSJ1RSHEsYvWqfM499tqTrKDKSQAg1Jkc3slW2p6cTr1Yqr5?= =?utf-8?q?G1yWfsOnNaJ8d6+ozeGTTB/7o4EGVtpGiNyPr+wyR6YQPKwpQiSjPV+s0RJg7nuJV?=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c5?= =?utf-8?q?zIpy2J1utVAsspKd7Wvh5eUZgcFN2WDHLyIUI2Zd25cEYP3NwMpf126JD9hSJn3a4?= =?utf-8?q?ZXoK7o2l3kZE11sScYmRfPnarq/AhgCsbIgZX8oGyQTg0uIuZuFZjih9G2Ap1rke9?= =?utf-8?q?CQOlpUTEqZqhfRHb6YIt/m7+T6jkFLC0yfwCBKOp5EruzRL8ScrDIopXVRicIAq2u?= =?utf-8?q?5lZnHYYNdtTvpIYwEpyOLlO5RCfEwoTMCS32DlXCxuJC5H3kexAgvcy9kDv01UGzx?= =?utf-8?q?xRiiRQ0wseBQ?= 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: wyNtDLQrkXxkNIX3CGtIa5oUjWcJBB0VK1H6jj1NQCYXiQzu7DvCtEI9lBy9ia20cL3oOVbYR61pUBPwmDtGfk02xGZFhhFt9VrqEutS4N3Qy6Se1xgEWXhGQuTMzYUQrphkqHXUbXZnmDtVhy+R/JeFVo/bcelx4zak/VU9UgL27d3G9daxWk/xhSbl62t720K6+uA2NPEM+AWemN6BsxT3PuSqKxG+3xRjRBTICiOnragA21H0w683ImpLOvr43ecmtI8M+v0gY83fwltcUi6y5SAgQrQl9eiTRXL0+Fyvq+ecEDXl37mX+gPzBPCfFfQw6+K67W4EU/osPl9r3smEXMJ51GNG9HmRUOZ7MjoeRBTyDkgBT6Ipl3zORUE3L+hYNghZX0nxspx9qOJBzqJ3Z2Ra6XEi28FldnGhBqkmuZUkiJcer0txigEtBhqDi+lCYaGQqkGg00s/8YoUDFpeFMZnXIKhVJ/RUo4ZTWGTuoCtvBSRMG78f87vT4I+evVx2G0InGS8GOCGGkrxIYIKqXc4GRw99I2+K7Klvyt6CUCXgfv1JW8Gn7YTLoLvy2llVqo5mz7CZPkSf+MAx9KyM8Mpsq+vIk/Wc3l6PRc475RLsncYCdOGeDZk3rj/ 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: 5fb0f5e8-25c5-43d4-210b-08dc470b4473 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2024 05:21:29.8350 (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: pnNIjrI7G2zQuCzD5OBtQDolQR73lJ5ASSyWwkyCgnXFWgjQ0ilxWtkplvK/F+h+862gVOB9umuSvzBef0FCXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR04MB5895 X-Proofpoint-ORIG-GUID: hznLZX5XCRJuzbMkCOfo3UzyrdpIuDSr X-Proofpoint-GUID: hznLZX5XCRJuzbMkCOfo3UzyrdpIuDSr X-Sony-Outbound-GUID: hznLZX5XCRJuzbMkCOfo3UzyrdpIuDSr 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-17_12,2024-03-15_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 Reviewed-by: Sungjong Seo Signed-off-by: Namjae Jeon --- fs/exfat/dir.c | 63 ++++++++++++++++++++++++++++++--------------- fs/exfat/exfat_fs.h | 2 +- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 9f9295847a4e..543b01a5479e 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,18 @@ 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) { + brelse(bh); + return -EIO; + } + + 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 +920,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 361595433480..037e8827a56f 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -501,7 +501,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);