From patchwork Thu Dec 28 06:59:20 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: 13505638 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 525D53D72 for ; Thu, 28 Dec 2023 06:59:38 +0000 (UTC) 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="JJZddn5F" 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 3BS6U2Aj009401; Thu, 28 Dec 2023 06:59:29 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=5ugyRy1AFcODDRZ1CCVGKkPQmTrClcdKuVI3SqG9oJE=; b=JJZddn5FuYHaivVg0sEeAysB4Am4mKFz9TqmJa5XYmNvu0hgppaaNDzIOBey+ksoibNE CL9zi5LmNv2VJmT7cf/eREncWEfAaxt66+ul57j9QluWL6iOzk9MFYGCcEgnaPtme1EI AQZXQWxs8cTBy3ui7pM90Yj/0d5WeyAm2iRo2gZQufS2Ql7TGMajDTISZ9ImAjftps8E q/qNYoN1BAgLYZJlbzkPNOM6N6z/iVhtdVYhii7zDhXbKOYUxytcorV5ZB4tPdvBT4ST FHttq6dG+VCAnYfK2mYQ86jjhtGTlZjjVRm/woF1pBjNR82gpkhbeGl8dUuAXjj8YWnb Vw== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2041.outbound.protection.outlook.com [104.47.110.41]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3v5my4uvag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Dec 2023 06:59:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BDuo5dSD4lvd3xxu5jDVhs0Jd2LMk5NUXud7EEIvaVFIy6JoQ1cFB0t8PwBrVBo/KLVnbAc578feBVhL8J3qb8TUofu9W906tuWKiFQ9EMS/zpGyWtwtlRn61a1UodC+fYnzGKaWkO0H+Okh78ryG72KjnyNrP7oTI0xhN081KIz3GJZx8jKo0HlT6Zihn65fNtpAStZ9i8pr0XWPrGX4uQmQ1EDYzBNuY0zvWo/AHl7HNsTJBxGFpjlOxsJv8gPK0BZRxSY/XCBaVvcJmsY1fpSZ/2gT1PhNH+VoF9SBMz6oCmeQ6aEGDeqfZDAlzhmR3tf6jMGhnU9MO0S+tRt4w== 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=5ugyRy1AFcODDRZ1CCVGKkPQmTrClcdKuVI3SqG9oJE=; b=ahFBEU+PA2+gm9ExmrIdZ9NhakqNi7IdLOUlKsOkg3pCTSrJoewa9TgYFEqLGoz5Emy7POMSNSLOGHMvAhIRRCk5GgaMs9n5CXX+/8JZ+vKDAxYTG4fL6PA/IhdMfElvF08PlV6nDuTir9KETtwRXH2v7ruRI6xnOvt7rB7S5mb9e2uE8YbPDTHOWliJHEmAcpZAZBCkfe70e/Fr3Yh2agrstyVYAvW/cwriI2odVnDvKHLLRZlrKmM/Hkr0dbb9ZG2fXcgBy/ak9wJ1HPj8C8SOIbXZpE2j0sC39BKiOJb2eC4XwAXf93nwx3w2tVmY59AXnG/GRRF2f6xPtnPuqg== 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 KL1PR04MB6878.apcprd04.prod.outlook.com (2603:1096:820:d5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Thu, 28 Dec 2023 06:59:20 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::5914:6fc7:b79d:7e34]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::5914:6fc7:b79d:7e34%7]) with mapi id 15.20.7113.026; Thu, 28 Dec 2023 06:59:20 +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 v2 02/10] exfat: add exfat_get_empty_dentry_set() helper Thread-Topic: [PATCH v2 02/10] exfat: add exfat_get_empty_dentry_set() helper Thread-Index: Ado5WSoMFJmHKVpOTLmXDrw3gU+2Cg== Date: Thu, 28 Dec 2023 06:59:20 +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_|KL1PR04MB6878:EE_ x-ms-office365-filtering-correlation-id: 3bab8acd-d61b-4f18-1910-08dc0772845a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UUnHA5+ThB/pMl8oMkigRAcq+iulAYcDvDao8LeWvaLP9MRjiQWq+hpBlSLahBFOk3ZQWLIPv8geJQKW2zF9IZDf4puZlP9cLMyjuePaJQM2tRXbPKTS3qk6gsRgk4SJCkLBhRgbk5E+hmPJDtSalbYiHiIJs+2uLEEU7J6vx5mQN1qd/DP5UQwYZVDGGMhmt8446LQtQ4CX5TVT+G/vrA9IFT+1cr9wq6jyINQe+F4cxeNP0kr7av07OffW7ESCF/zjOSJ+UuIyegektzicWOFuXxAwqMQHKqFzOtxtycS51EwXIozf5lAVMn97JasUwnpJ1EO/F3PxQMFYxLRm4M65Rtebo6WvoW7joP1DoP81Xv/w1SNvyxPAnU+1Jxk03gds5V7xL9QKRKa2Ycq4H5tSvaBmLs9IclcqEL/yU1gJRheCwuLkTrOtX1o3t0p2Y0UlIRErEERr2ORFYIi+dWVJDiL5XXm+lzBqEC/25vqQpQXfpZ2eGQ50SojIZRVqXEtvXlO/7/7mfqduDGirKFUSNsx3dcBGASDfazDci5LU6OdPZ5Trp4UAAvt9OaDT0YLWX5bmfRSrC1jbPGhlsESRdE7xhUcEVo2ZrkaMXTlcxSFhP9SvBvMzv3PcZqgr 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)(346002)(396003)(366004)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(33656002)(9686003)(6506007)(71200400001)(83380400001)(7696005)(478600001)(107886003)(26005)(38100700002)(122000001)(82960400001)(41300700001)(316002)(54906003)(110136005)(66556008)(66946007)(66446008)(66476007)(64756008)(4326008)(8676002)(8936002)(52536014)(5660300002)(76116006)(2906002)(38070700009)(55016003)(86362001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?hQ7ZsWFVS4MbtMkMwWhgVJ/Ga3Va?= =?utf-8?q?X/9wWKwg51rqPtue2lgSiGmXxjLc6c++BnA8OUkTqckCnJBGbDaTT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?= =?utf-8?q?PGwLtsWY6X4NVskeNHgTfFK6/y4xkWrs0txdhfyFLP49qxJGhmB3SPzj5+o5Zisue?= =?utf-8?q?gpI+FJ1H4P0pCd7nPBAv0B01f+JRR0LNiBAsFgkfAAj1pMblJYy395BIsUpxnbQ8r?= =?utf-8?q?5HNqITxFHQU1/dl5c66sgT682c7qK3U74o0ANNtuV8bw/caoohg5VuNOuX1KBtkfV?= =?utf-8?q?Dm++HsHD+ust0A2y3byEg8jNq6mjFSuKCc3Yd4/SQKmyvS/2q5xDMJjuOAsK8KuBG?= =?utf-8?q?OvtgubPHmZtERCM8q0UB1Ov1qQMC4x37lqs++WUknu6KNGIT5Zt7kkq8YmR/gP2IT?= =?utf-8?q?zpZqmT/E8fN24cGeZR6r1Tv2FtI2YH+sEDXwu174h2Eequ+aXc41QCwupSRBFs/K7?= =?utf-8?q?uwRingxI6PSlHPyLmb4izBpfWJH3rpwdyvMV2yJf1LtVutpjN3lcFaI/C3U0cx4dR?= =?utf-8?q?xOzcBORkcIjyeMM7noqdZJ8f93ZMxCn4YDKUWUK1jpM9cNjudhrgLCszm4lSawYW2?= =?utf-8?q?qIEMDHNshkla5pqR+uK/XMYH+Z4tUSzv2TvCDcsZVsorqqKC14DBSwJJb4h0V5iaO?= =?utf-8?q?E7MEXmzcs7Rx?= 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: jwZkYPfTurb41ztsRvRVatM9pju8zPkQlmaFPuLhABZHU0C8Dq7fYBAb3H/bUc8QlPsY0YGnaHzN4LMtIHuXZE81GzvhqdzCGN88vbRsXTnnKsZnQ0OK2m9luWA4lCRiObFNXDbnMnyYsaJh6uBXiIcvu+75pG/hjJC4d+QIGZ7wCIm8Y2KHU5+sy3labnu6PPUMObp1ihyHCDNkzkiK31Lr+RHRNrV0+OA4gbwJuQCshelJZpcmRgFzaobgJN1CZda+pac1q5urRMvL6f2SdrYsqaIqel8DmE8Hzx6x4TCE6bU/EN6cga7OB8/7Xi2z/bYwKn9GcMav3E1le+YnjP0rQzI/n16a0ueCoMcX430VdBwMwACxvDJeFi7axnE59KyF5dzYiGolaJea15QyXprDrumYnvxK4TxB4csa+RKvrwzzimTLoy+P10VNoGKvhzuHV9GupHFGry0hFGvO5Cpw51UA4Q7qDheKYHNqEmWoSsJQcE5N6VUpsbQYB0GqH/SWRpqZmgLwOF6jSlx6XfRXeg6C4IT6FZIsMRFTp1cr1l0nsShjmkb0fdjRK8JYF/tlB11+M5LL4Fw63vhMa4ihjw9PWVcVR4enwIHZYcetBo+LPgogudMG2x9mmo/C 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: 3bab8acd-d61b-4f18-1910-08dc0772845a X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Dec 2023 06:59:20.7720 (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: 03weZQEyLg1tcOjcIlOVX0873FB14blgO3Qa0BiXD0nXLkdmk5klq2rPVgL1lIQITYFc4mLQQRcrmaSjdl8THw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR04MB6878 X-Proofpoint-ORIG-GUID: rh1ECNr0qvzJ3wVpdruqU3jqo7E_S199 X-Proofpoint-GUID: rh1ECNr0qvzJ3wVpdruqU3jqo7E_S199 X-Sony-Outbound-GUID: rh1ECNr0qvzJ3wVpdruqU3jqo7E_S199 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-28_02,2023-12-27_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 --- fs/exfat/dir.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ fs/exfat/exfat_fs.h | 3 ++ 2 files changed, 80 insertions(+) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index cea9231d2fda..a5c8cd19aca6 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -950,6 +950,83 @@ 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; + + 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 out; + } else { + if (unused_hit) + goto out; + + i++; + goto count_skip_entries; + } + } + + return 0; + +out: + 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 d6c4b75cdf6f..542136b14a2e 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);