From patchwork Mon Mar 18 05:21:40 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: 13594973 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 8327F20B0F 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=1710739320; cv=fail; b=f2NBJMCeQG4NBFtMJHnWNt4gPGH/lvE8mhWLJKZY5y6LIlk5nq8wGeVLhYoavu2cXhcdJx9XFvJCj9uOjLnwYynp8i1M7RUzBjl27Y0B47qjfhSIBUROddSN1NGVrgHxPLR7NbUJz8dyefDxZK13AJZbA/KRFSmHXh2Xw2RHLX8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710739320; c=relaxed/simple; bh=PnMJitd6KqA1dBq18vmCdBFleL6RXGlCR5nD6Zl5XfM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=HpdLQdT3lknqKzk4J0zI0GsdJTuNTkFoJHAlPufxxG4ImOZkFwrsJzW8LdxjXOgvF/9nxNZXNXDnWss0HHkj6X4Yv682S8QCQj1TXbw5FzERs7iSPP3YGIAWPNMpgdbMB0zCqq3f6vgQwztOqLuyEjl1TF61aLJ1AGwTKnuT0dE= 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=XqsnwV9h; 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="XqsnwV9h" Received: from pps.filterd (m0209328.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42I1sKIr014434; Mon, 18 Mar 2024 05:21:47 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=PnMJitd6KqA1dBq18vmCdBFleL6RXGlCR5nD6Zl5XfM=; b=XqsnwV9h1LjrMagcubu7BisjE/iJYk1mAKraGjJcwo1XIRBD7kulvx53gLLXHzz/blbL OHpLYtY9HeZbNdAbn20e8wLTg6yUgt3YPFwMF8qTv07j3xxGgMI6KXB7NR54BtTaVQDZ Fb538Zq2x9ZOxtQpPnr+Ze8ORCc7FyzUay2PBdoXG/dXJTWnfyps6tMFkegwWZuK6H8Q DN4FLmj+FfZsFY1lH4635IzNMeftSK5BTq82jaJOWYU0cn5JxvdTHSMgRZQwPNKsRUSq wnuGy9qd47XEtAXnHbzH0+S+0ruQxZuj/hQ0BcpzTKRf33ozqKDWWt5V84njjCHiWld5 zg== 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 3ww4km9n0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Mar 2024 05:21:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lJHOjadUYZPhCEtrmPtL96B7wOhBiJhrzUX0APRz2RRfjkKJiAArC8lmkSsaSwhKuYj8Ti/Lk4hpg+oedi3psn72EsCCFw5JFKErzjKdvzZALknd+tON5sD+Ys7Wbe/PqQHbXoUeyeCx1RVfQMULLDMOHB4kjaCHcWx3dRIG3U+D3EArLpnX5rqQB4pPU/qZIH7YCGsinkBdpUJQ6uWYja8ds4crEl5Upye7hB2Er+lXXhTtnlUdbgh0BlUEKvoU0BSvHxbsMldpF0XiXJ0zL8VQKgdl0EJfm1gFmwZPXomiViX2Vyr0iWQzoJcUO0eFi+NijmcLt6ez9egOagHAOw== 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=PnMJitd6KqA1dBq18vmCdBFleL6RXGlCR5nD6Zl5XfM=; b=n2BQkx2jOhE3R8FAojCoDU5ZO8wfETLgd8capOyUp+3OAYnFrsMXNhfLVndadYXmgUwIpb3xPp9ceaa6zsrm+SYJQa0g0jzFykEQIx3auYMJ8e/0j8EFjBV+mVwuiCG6+T4xPgvgE8pVXIm9LMZSS8x3gM6DbnwUsFtAh85/jNk9UK0v177mGunMEgOcmr42uU77NWYHADIT0vkyWjkOCMqgKMWl+Q0eEsj/M4m1WK7amAaX5KfZNy3wHW2H5kVAhFSCzUvnRRHji0opwNN3HFC44Ng6Z0iaj11W2t/4Hnb5YAwRmshRdXWeDMZQxZ4inWW/V7be5ujvWld8Jk2jaw== 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:40 +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:40 +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 v4 02/10] exfat: add exfat_get_empty_dentry_set() helper Thread-Topic: [PATCH v4 02/10] exfat: add exfat_get_empty_dentry_set() helper Thread-Index: AdoLEwb381t7blsHTr6+hyR/PEn/jRt3t2MQ Date: Mon, 18 Mar 2024 05:21:40 +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: 3216dccd-49c8-49a6-8143-08dc470b4aee x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6pRgIrsGfstv4CXml3iBtaT78PbxnfD8mISdhirY13UyrSC/y0dh8TZ42RTUaSsymgNH3M7sjrF3iOc+IIMN12AevPWgA5oDroOqEdtzG2HPdV/6hDmDtRj4Hf5hS1G3T7vsnlneSEfZOPOiX02xwcIdh3jfSCBsU9pZ2+8Qlxvp/ZeVVizLoRKn1KaRXiims6Or/7Mf89B9pQiF5/TorMPGY+hq1oIrwGJPhRNbGrSraLVNXXJ7Zis15eeD7JBgGHnus1Ey4QUYocSi4UojgmmJ7P2TcEwfigaSrItkksdlYzvOKCN5SrvwLaSyyRZj2eNuin9LYfju8n5CDVqMHbJYxLPwiPuSxUNNrGRd06QvGIBjxyp9ab397bv+lHSVcpInVlgCTFQUYeU7U8iquEOBlHIJaOet/kwu4bds8qZd3UpE9UotbLG4FnqYwnhv3LDx4iGMMF6wJskvpXUGhmn8zdU5RYkafgP4+AqQMCb3sbjr+SAKmixrOGaobSvxt1+gpkeTH5irtLvxX2KsEpFSiF6YTTbG2myp7ZfLmB6d30RdX6Pf2jYNGvarVNv1ymC/e/3qGavVj7qXjLUn6OCzZxNwGMxclVkoKF6MkDTbToXaiOs45JeEcX9OvCVTml2+bAELf2H3dwWbZCNKse2XkCFDoijJg3ftSd6D0KLOq920cxsj0AesERg9AsB8JEsi3TLb1l/okS3dCv8tnLVNTUOR9qeMhSiG9NZSxBA= 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?QAVYcE3r6YrZutp/4avtk4ufAhBB?= =?utf-8?q?zhizTcSurkdVR4c6gH+g/mTBqm2huU3e7owEYGdZ0RAHuy8fMZ9nPLl8fARAVB9V9?= =?utf-8?q?PqIu9mqYs16rHHR0rZZ8F9b6pHDjThHNIvuYItUKFgE1XUvFgl/DfI8KpBeS4TuTw?= =?utf-8?q?aL1xNIOmnX54XHIzRK/ubcqSy/tVh7q3oOzEQFqlHenCXV0i8/9w0kAlc8zQIZBv0?= =?utf-8?q?aUrOXyeYDt2zM/vCdH6rynSuNGQbnipjWzYCOaX93gjH7LnSWDSp7E4sfmddGP2vI?= =?utf-8?q?HBF/FgmWvDr+coJCKzr140fmV6mvNJmdKblw3Rq4MEFlAN2Gi2Z6PxWy33u6o5usG?= =?utf-8?q?MQ5y5LolKBa8jyxcNZn3O6pgVJIwoCUcI8NDXpRL/O5jMhP3bdupW4hdUPjCznB1Z?= =?utf-8?q?FrlwmQtZTnmT697v/7rC910dbgS7bYp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/nK5AQWu5W26nQ+Z0MqKC5eNyPIh?= =?utf-8?q?/mIsk6ZDex1Jr+LYDzFlSATdkwPvCEkjjIWmM+Sto81sBq/GkE+muYfeP1ZZhj1Ha?= =?utf-8?q?Gh2gpqSuQ2F81F2K1AfBCBo/mB/oyiny5MhxRU2kBglSa8BluxBunP51DmUL6nT/a?= =?utf-8?q?Tebw5RgJFf1JWEnTjoaFxFGowkt7yRlM13NHpunQQ3lsk2FdzCwVohw8EFIzbI+5H?= =?utf-8?q?RKc33qS4QQzu?= 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: usca9gYycQNTA7YFWFYaY+1B+2C/jzgHuvUCiMFXwYfiGLZqOk/JGqT0A2jQ1fFtqPtRiZyDo4VdF1JDOmyrJ968sIeafHTzXJhJGdKguG8FgjzaeJaWFb2AQZPchDELofS9ufmLzENlxK4ogAwCju8e0W5C0OHJSdU2nX95d8RGp7838dMc0WvCJmKRCqNqxbakP63LBUfrB2zd8qycx37FKab+1lWv2LPPe2A/ELGeh5qvt3sSqhq5QzP6hCzm0cw2KkkSNoRkPN8cW76wppII3SBFNzHlCNQB8G80u5SqmdROZjIlOkjxTsvXEBChj8UOMLMJLoX61CdWN0eDOOMOnKiTAir4mInFy/L4YDRNabiVc/8551MfAcuz1oQiv9y/lDbtD/dNREt5A3Ft/JPGnbNGdNoS3/QGXzHRX9y69zZUK2VzeX594rYg2ee3ExP3mePm5NSBdYakRgP0ARlEO7AbGIcF2sqxWIJmIZzOPLe9IYeaJ2BExIfLJAxYce9aOni6J2hbV1v9Uycl+NILpkZ9010ptjQuSg6icvC3QCW22HqxX6N5iey65Pp0SxEp6mXhpnEK76Zpxalys6suaXDz4lgpRoxhlTC8GFWVK+kwRsi1zrU8NHWPcBly 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: 3216dccd-49c8-49a6-8143-08dc470b4aee X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2024 05:21:40.6981 (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: ZEzaErxHnN2gBqRZT1A3h/XBJce1NbiZxjrmDLkCbRUxCmgDSYsXb8YmrrJgp37hzcR03Jqw/dnzqpCTZh2ZcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR04MB5895 X-Proofpoint-GUID: aN6G09HUgux5632t1PD3E3vWwIeZd7UD X-Proofpoint-ORIG-GUID: aN6G09HUgux5632t1PD3E3vWwIeZd7UD X-Sony-Outbound-GUID: aN6G09HUgux5632t1PD3E3vWwIeZd7UD 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 This helper is used to lookup empty dentry set. If there are no enough empty dentries at the input location, this helper will return the number of dentries that need to be skipped for the next lookup. 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 | 79 +++++++++++++++++++++++++++++++++++++++++++++ fs/exfat/exfat_fs.h | 3 ++ 2 files changed, 82 insertions(+) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 543b01a5479e..e228cdfcc9c9 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -952,6 +952,85 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, return -EIO; } +static int exfat_validate_empty_dentry_set(struct exfat_entry_set_cache *es) +{ + struct exfat_dentry *ep; + struct buffer_head *bh; + int i, off; + bool unused_hit = false; + + /* + * ONLY UNUSED OR DELETED DENTRIES ARE ALLOWED: + * Although it violates the specification for a deleted entry to + * follow an unused entry, some exFAT implementations could work + * like this. Therefore, to improve compatibility, let's allow it. + */ + for (i = 0; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); + if (ep->type == EXFAT_UNUSED) { + unused_hit = true; + } else if (!IS_EXFAT_DELETED(ep->type)) { + if (unused_hit) + goto err_used_follow_unused; + i++; + goto count_skip_entries; + } + } + + return 0; + +err_used_follow_unused: + off = es->start_off + (i << DENTRY_SIZE_BITS); + bh = es->bh[EXFAT_B_TO_BLK(off, es->sb)]; + + exfat_fs_error(es->sb, + "in sector %lld, dentry %d should be unused, but 0x%x", + bh->b_blocknr, off >> DENTRY_SIZE_BITS, ep->type); + + return -EIO; + +count_skip_entries: + es->num_entries = EXFAT_B_TO_DEN(EXFAT_BLK_TO_B(es->num_bh, es->sb) - es->start_off); + for (; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); + if (IS_EXFAT_DELETED(ep->type)) + break; + } + + return i; +} + +/* + * Get an empty dentry set. + * + * in: + * sb+p_dir+entry: indicates the empty dentry location + * num_entries: specifies how many empty dentries should be included. + * out: + * es: pointer of empty dentry set on success. + * return: + * 0 : on success + * >0 : the dentries are not empty, the return value is the number of + * dentries to be skipped for the next lookup. + * <0 : on failure + */ +int exfat_get_empty_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; + + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries); + if (ret < 0) + return ret; + + ret = exfat_validate_empty_dentry_set(es); + if (ret) + exfat_put_dentry_set(es, false); + + return ret; +} + static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) { hint_femp->eidx = EXFAT_HINT_NONE; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 037e8827a56f..c6f684bf7b92 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -502,6 +502,9 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es, 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 exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es, + struct super_block *sb, struct exfat_chain *p_dir, int entry, + 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);