From patchwork Mon Jun 24 13:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709539 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 752F6C41513 for ; Mon, 24 Jun 2024 13:56:10 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkB0-0007fm-Ic; Mon, 24 Jun 2024 13:56:10 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkAy-0007ff-VM for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1XkzWrJunNjwg07SZ0xtl89vq9kjD5f3AOik3evu6LI=; b=IOc9qKMGBM+Van3V3cK6FtjQ1a W4r5r9bKfVvMk2PI7+gu7jJnOHVIM4ZHxQ4Z4ekBTJhVV4OrhQbGLP1N+wwEkfera2UeULkJ35VJg KDAx0hSp+3y4sR6CNpr+bSJpKGeumlcuCTne4RUgUz2gbNRgxINml3vp37dp6ooTsq4E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1XkzWrJunNjwg07SZ0xtl89vq9kjD5f3AOik3evu6LI=; b=i6AhTq3A7ptX0H4wxobXMFB3kq gf6HH58Lm5TGk26slaMUllTnJYCxcVIRCEMyhwb7nTRdT9pdLDLOpaNx6N2vJHWQdZVaXS3Vu7U9h apre57gLO8/B542hDktNQM8/P1pBVhGnaGOMV5t6EOlVRMF1fR0umcQd5/BIN/wbGSKE=; Received: from mail-sgaapc01on2083.outbound.protection.outlook.com ([40.107.215.83] helo=APC01-SG2-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkAx-00018a-Jt for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QJpox9wENd691wH9e5+T7W/XlUnc9my8JoQS04XICnl4vvdXLv+pkNe+nuco4gyDio7EG0R/EIteJgXJXDdh2pvK2SitV77BaRjeHPzTspKIEMwNBTfN5inHg7UXSuSJ3Kj/YxdpY4B5VzHAu7KmjIvLZb+DjrW4BD7rq4gux3e11L110jAQcc4TZwyXqMV99uPK/GV3liiWLNpOyJfgNDjIErRh+OPcUf6oNu5A5GJ9FFde0qtNIXau8xF8zPtlh2xYgXb6TPqMgicOaaeBb3LwNqHqYHUO79ATuQnuCV7WpUPe/OJyglxlQUVc4kk9ZniynIuL/hlgBl2emFrBqA== 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=1XkzWrJunNjwg07SZ0xtl89vq9kjD5f3AOik3evu6LI=; b=dg4wIU+0+D0OWheJ4TtAp+b+2ksQeutcy1emmo0ajuKilg9xvK/VO7o+vPfesbzpcurgOinZxG++IA/aGhGb7yGckP2p++A1G8/ktDGf2r1vQ1EHjshJAPAAEH3/ukbIFe3epjNMgJUY0UKeoABMtByNVL3xphRugsMGQR3bH1Sc4NRgVDimwp6J6DYiuNhHfDrNLCsCjk3+4FM8RBbLV2M2RBwLVZqObN1Zo70s5F42pXrTSeixzP4sVg3I51OtSlD9pm5qs0lkGW6Ug9W3qMQmrBWHaVuEUueYpqhseRByG8Eiaf/OZMAcGAC290TR0pYzH0aWMQc8453BtlfFMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1XkzWrJunNjwg07SZ0xtl89vq9kjD5f3AOik3evu6LI=; b=tbrJhf66Y3NZ2fInGvdnYA4cknln5IqVodPZAJL1WzkcqGzonpGH4QngX0bHYsUAwQ5QrKX36eQvXEnsz6fmz66r/69xbqGSupt9rzz2OSBdds3CO11O7yLLwV8vVkV1x616Jin5wA3ON54FdFewSpynpJmSBNs9/kbqueS2an8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEYPR02MB7438.apcprd02.prod.outlook.com (2603:1096:101:1e5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 13:55:54 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:55:54 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:24 +0800 Message-Id: <20240624135532.3330136-2-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7438:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ebb7a23-6436-41d4-500e-08dc94555db5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: XwvPW59p1GZ/qDXjYEXxUfvsWvvrKYVaWtS0WaZvuVJyF+Ta34EFKWTRpTbrxD9G80C3AmhvS9Hd5UetS9CPmSLESegiVMNT5MR9hnRB5Yy21vIii04uMKBf5SQ9IExfR06MYb6V6oFmZNAwcxm6qls7MhZeliG4sqyqVx7jXRrmAv+RSGTt8+ap2iskRuxdoPHNBfMTF5/qs09u9gZFNLAZzBLEOUm4Xm5m8yAKZYdVydy9RkauxGt6A8SS2e34N88feThYLUTiStfVV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HLC87KXzWY5A366VoxJs= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dJAQPGoDtpXBZaJR+6+sEAQuQmgRHcyMRfcbeK5yVwDoiU7Ihm8Cr2kygC/mJKPlt2G2URH6DvhKOtKi/UdCrPSH5qAu/8fIAq7IQLUr4kHKFPINI1iiMOMSAB08CsQOPWtm2HpK3/CTvLeQH1uWpHMPXhPZH5RWCVZlKrW9/+5RigX14wOz9/vcouN5OYUfRE+UAUJPz0Q5n1UsFIraUxZCsOQGPKBQzIc3R9rgc5mhHjLBYGTU7oRGDRrZIuIjs5oBD5Dlx0kGzAcPEBq3qpWQ4IcixkpOFUaIsSNp+9lj6PKlcTolpsNddUDXxo0dbw/UfJ4kR5j3TbuHtAs520jHUtoL69Mt5V6B03kkY6grpwqddDaVhql5aYOkf7t9B3vGSFSN2A2tKsDK6bIN9H8xred5SYVnEHBhqgbToYyLU1AWNc4ZxfiJXPzzCeliTpgK/YA3TSCctZfTRLGKFOvKYwxNig3FOPUfFuIgTowblewfENV6Fxy31E0yQsAZ1CLSeG/x/GrptkMQFcYtMmJ6IfNxvbHvG58m/RZey7bD3wcx0oxeKrwU6o8mtB00sYjq/+9+fX881wF6XfdXliBciMXkwWS1ly8OJMtWuAOjyuv7ffCKrLq8kRc7FBZeTE3T0Qw0lsSRJH0HAO58kLfi5j1tOvDiewP43fBVLgWZiUN1X2j7nxywEZYEL7nvZVUIdL/ejF0bS/swfWnQdEgArrPcoNipbcD4CML+aR+UxfJC/jLX4d7czgMOCjX1S+gxUgR2XKLSmkoInpy4jvMltsjyZdYBWpu/qI6zdMJ0EoE4pwmofSzMQRPVqhZ4mLUGbAMBTSp/MGESQ+dfTXpaM/xExB6ZYsdTMuDuTlizxvkNSjsdMn9RXWJ06ecVevOGpqmZRLtk8qQGZ3yc7BdIGWrdAGmDFL3BPzie07d1AOWe0BuvqRgyKM7V2/Eg74BLjp9cqejx16Sh3AZOGiIO/rt0G2EwdBHzDu3oeihkuK4bGw2GReWfO/KreetZG8k1UyBaRXkx5gpW6pWyCvv7gMVIK0ZilTzi2uOAnbIcVLMG2+dfnms/BKEAgqqM5H0mqE3vt1Y8sfM5a1ZvY2b4qlLtVtiVimAnZGuU3ODaboWtP09Lp6PviJu4WwnUDijCdxmQi6lxIa8NIB338JiOYPo3rfoKgfwS4ML8H0pXv5HDXVd+ncF8YY2QGHB6pIpSjZbBtjjccxBMuDsKjCXMbwe6Z49c967VO9P0I1VLZBlxwMm5Odztw9+9tWpp7Wrcp5rZEoJeyyhXeO1TvoGMhOK+WvyT9j7NMs3uwVGq1cLbV99QcVrAdC3z+UbZJdEthmKTuJuNiv1B6GAg5zgRL0undb7+GWeCXoeazcKdK47mVo4ZRYGsfCuf753zmS9YIADzLGv6meHB9wfXYLzdgRCNoKvgar/xm+S4SX9+Z1nzdBRacntQ+LrTA9r0X2OQUpJlrUqNJ10akiOiLkYAZTXjasIKWzW+f2gjclqibcFgtEBmby/lvXiC4rfsYTeXBmT5nYaeTHeBwUDo6n2rP/bmUhNgXV/ni/pdgdtoOvP3H22CI+NHx4c5vNtW X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ebb7a23-6436-41d4-500e-08dc94555db5 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:55:54.6970 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7mvNkGxODablXfcoB9CUJZIN9Hrbk/CHNa46U2uQMPuQSFmc6RTc9UTlCdQy+IJhbXxeJuy9Xdi1bc0I6F/FYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7438 X-Headers-End: 1sLkAx-00018a-Jt Subject: [f2fs-dev] [RFC PATCH 01/10] f2fs-tools: export is_digits X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Signed-off-by: Sheng Yong --- fsck/fsck.h | 3 +++ fsck/main.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fsck/fsck.h b/fsck/fsck.h index 6cac926..4ca75b3 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -353,4 +353,7 @@ int update_inode(struct f2fs_sb_info *sbi, struct f2fs_node *inode, int flush_nat_journal_entries(struct f2fs_sb_info *sbi); int flush_sit_journal_entries(struct f2fs_sb_info *sbi); +/* main.c */ +int is_digits(char *optarg); + #endif /* _FSCK_H_ */ diff --git a/fsck/main.c b/fsck/main.c index 6edc902..9bda412 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -166,7 +166,7 @@ void label_usage() exit(1); } -static int is_digits(char *optarg) +int is_digits(char *optarg) { unsigned int i; From patchwork Mon Jun 24 13:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709555 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DC49C2BD09 for ; Mon, 24 Jun 2024 14:11:11 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkPW-0001jY-Ny; Mon, 24 Jun 2024 14:11:11 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkPU-0001jP-IH for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:11:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Qn7nbywE3y7Hclvot0YEg6FFhfxcalDvo/L3BxCEGeo=; b=grzIpViOGCvomzwB6PnU8yZIox +rc/AYvBOgiJ0aj1oxkZfS3hR/S++HDC2tzXxqdq13VtjeLPHOyYjsxiWbcVC9ODa6hOmQi9Xxllf ALjBSPNf8EzKl2XYR2/jcCu9FxNTuRyVFGK4L7aeEvv10zOBLTKfU4QuV9CqPXZEI0cY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Qn7nbywE3y7Hclvot0YEg6FFhfxcalDvo/L3BxCEGeo=; b=U5aFUDomA5Hp1+vCUdNREdohbJ 1bd7BcSM7+57MiGpnmesfNhHPuLzQUDUiiW2qqOidjAaSE6XHbabEUsGZ2x/pEEN/HWBxMOmJLzef YvNmIGCo2bpsa6GUOx0Ion6a+OZjcC6J3rAThZGvrF4Z0DtBMa4e7idh19JAlXFqWpJA=; Received: from mail-tyzapc01on2057.outbound.protection.outlook.com ([40.107.117.57] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkPS-0002nE-5J for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:11:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hmvCj2bb5bLz48wPv6VhAldhN3JZTggFnmG97WSfmuTavEXd7F7NEyYTDlDsVOaM4KBEES9voMLYUwcBm70A1kmjDjzFPicqDsazspvXBNp6JxjC+GYzqPd3SzGAxcAnFwyiGxd8g0eL8/U1STjXEG1rIEzShN1DvupVbPu8MLja/gNB474cIV7atih3nZ5ulFlNvqgwm2pcApYgrDdjdSa63Y9pZseoVA+XhtVlJZtyKDg2zoOR14XxehRZy7hoMTfvDZaxnzlsvF2Z5aomCzDAcR2Hmi42GsDiipcQEQunQWOS+tiFHwYGOteoLrfCXR/Kv0GlFBWTBPjWrBD6gA== 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=Qn7nbywE3y7Hclvot0YEg6FFhfxcalDvo/L3BxCEGeo=; b=G1T6IiBPRSM2sHescXwgCnE0yAs2L/Ec8IgodQU0soWKkS7F/QNC4d6AUNMpMlLKBA3m2xDEBz/aM1O17wslbjYFY0uCqeUtdAVFnJeCBHG5ZOA11OI6Pe2nFfmfPBHX9s9x+6EDHcL7lTGc/Z+eJHT9o/OvJjgUJj5tHoE30/nAA2XnAPzHcO8N/miPNKI/Efk6B6KvVQiKfJyTdE5xBFLpGMTUt/EhklroFXwYvLBdPJVy5ZUiRLqj4btoCCfDa5qdzO4XVh0i7MfSnVwsPFdSIfS2bbrFOc6ouLkodnh54NxD2ydILKyejcBIQYh5S2taJZU5lMh185vNORpESg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qn7nbywE3y7Hclvot0YEg6FFhfxcalDvo/L3BxCEGeo=; b=eH6sZ86CUBxhe3nA0seoDSp1ovOcIssk1fmNDY24sjZN57DEa/IpAAj9zKh4DcaPKnAA/z1L8vAl+oUqXEAQwXRpCASrm/hlRqd7Ea3XUYo0NzSSZQKG7eAsB5sEej+ky8x8L4z8wVvmY8/R1VitLzJT1+xbzgxE5c+dMPi2S30= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by PUZPR02MB6233.apcprd02.prod.outlook.com (2603:1096:301:f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 13:55:55 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:55:55 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:25 +0800 Message-Id: <20240624135532.3330136-3-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|PUZPR02MB6233:EE_ X-MS-Office365-Filtering-Correlation-Id: 7534db64-4240-48d5-2610-08dc94555e75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: S3Vs7cdt4/ZV8JkwfqeGs8lehe+ZkOBz2O/on5L42QNYJAgAHn5sNo419m3QPA2Fq2/b7AwKO4krrPBZ9uOfxeON4yURmHmmrk7k2ahp7MuvyX/ruz3/w485Kzqzu8MVURdyNZzILowGYiAhH3Vu4A6rrCQDypSgIJKoYtHOm8RBTVbTM6fecacl2jE3nlyjNUuKPJoEU+Bzv5pclrVCmUj3070dTDRekqhkACCZkLfbpaxjJOuLiW+dKTfDeDeSO3CuWt9H0I8FRnpthY1NQQtgssgxA5gr1RfKjBUMiXVX1NrxJtchFY4zt4uDV9rE2IwOb7SM2Z7rvsTeZ0t9BcUBwOVA9rB0pB3P0cVl96U1xdjiZcefWQQ02x9NBVGB0klzUgjLohnCbePDx7CLWXkNeYl9gdv+cz6Ag82uddGpsFAZinuUAE6i9gzIVGmUSAaGA0niBSSB118vsOL62X0brn4YkOIaUI5mJchUxPLZYb6VttUgxSzUdP/jcuD1ZA3MYMmrlqZ27A0/Znegg1EATiGhdl6ysi5Xl63+hbXKqdEI4++UZWmdl9rOm5RSEIK2qqnrBNxPR+2z1VxCgmlNhJNkH+Jv9c/2pkQiHuNFGT9YecZ6QWrnX0liSaqX/N7XBfJJVDfog+fHLh10pP0XBL7oSXbzdkg39Mn4NS3iOU3+2e3hvdmxgG1AOD5vew45eYQtkBt+5Pjfews9jZOwdruEe4J6iitlgd4/Cy5snDt1mlBaHxTm/AsqawvJR5ZACyfbb8Z2ZjjJXFtM/kglsnbtRrNEeM+7jaYA80jHQ6pktJxXTYjaAHRUOBX1/0k2fd7sjf0vs+eqtx91xn0zQd+rtX2RPy8/5+ihPjoUB8RNxqNoTUM0v6jZF+gDb1FMhVOV6j06MAl9q5D6YPs6a3sLHn7d2E07B1ff+RaFCKzOjg+1vkHVK5F7IR08bLDq2U6SSnCzF51R62kz06D4VGPJfnvj48+m6z499xGwylAYGoj4VTROwxWL4uISmfqBaw2w2Yovc8Xh5iZQ6FdabUnoCQAl2Kd5SB+nc6NZ8m5Ksf/Q6aGaOexZ6tO6VVBoLF1fHoYCnbR0xZNpFl2c1tJ9yCws2OrE/R1cP81mS3f6tT7G0i1UCWHu84DUxnR/8SFdpRzKA9tOw1HJ1pNi0brQN9KDSKuaZ7K/C0FjRJ9N7m7ns/iPnySOZp38dbJls4js6znM7Ign70d3Jd3d0a4rf2I15P4AylkwVZXdvcIpQnU8b5IAWzdAFRq6a5OgPTzjgZRdBS4W/Ipx2DTVg6Gxba3GGOs4wwUR7zPPtFTKAFduk/R6QctHRZ+g X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011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Aa6kN5dF2NkwXp3UqI6K7eEgKzm4im5m/VY7VehOPTfbUrahneWj3wumncuKfbjLMPhwms/7W9JXiD/71doXinA3h9htBBvB732Ropax45a5q1lJZtYbIlJH5+MUeF4N7XRGXvcG6s3zdt2dfVf+JqAzkia6jQJlWBBGaq3iVHO2DqKi328c6RU6F49Uuzc8Y3w6c5VjSzQNSWXfUYmq4xuzCt6lg+bdE4dgNE8XvJF2zS/cpqYBxMsAuY1VfNE3Gd552H+5yIAXIoLPj+GiHpXjwe9zZ6p7dNLPBdSN+yFAefzAxQTP/48Pn+dSlO+BNEGxlNZL/HRr/EtYa/XmJEtCf9eB0g5eEp1xr2BTeFRyopa7oXLkYDT4dfJmJ9gU2TOqZ+ZgMQ4/gbKiOsuRT6wUnEhgb9wkmkeKr218HNYuMuDK9zHEH9a94jVwJlGq7wjIhMiSYtd/zp516nm0gOsbRXMLPkOBmyT9waLwi8c+goltcZNembq99TTVkj10AEXIWcNqmR97Rf1TLOpgF6mOJrzci5fEoFwhrCibL9oIKdJpR2okcg8UoOFHd1k1L/Z9p1d X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7534db64-4240-48d5-2610-08dc94555e75 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:55:55.9200 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i/xmccaP/vBDhL0072ANsaLUI7I3zyxB7IGkF+z21z3NvUVzS9vLux8YTxdvrWMU3oDpKtUZN9qnDq6UxOVwKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR02MB6233 X-Headers-End: 1sLkPS-0002nE-5J Subject: [f2fs-dev] [RFC PATCH 02/10] inject.f2fs: introduce inject.f2fs X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch introduces a new tool inject.f2fs to modify metadata or data (directory entry) of f2fs image offline flexibly. With inject.f2fs, it is easier to generate a corrupted f2fs image, which can help verify fsck or reproduce userspace behaviors of some a fault. If option `--dry-run' is used, nothing really gets changed, and that could be used to get the value of a specified field. The following patches enable injecting each part of f2fs. Signed-off-by: Sheng Yong --- fsck/Makefile.am | 5 ++-- fsck/inject.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 28 +++++++++++++++++++++ fsck/main.c | 29 +++++++++++++++++++++ include/f2fs_fs.h | 2 ++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 fsck/inject.c create mode 100644 fsck/inject.h diff --git a/fsck/Makefile.am b/fsck/Makefile.am index 40d31b8..48402ab 100644 --- a/fsck/Makefile.am +++ b/fsck/Makefile.am @@ -4,11 +4,12 @@ AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 sbin_PROGRAMS = fsck.f2fs noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h \ - quotaio_tree.h quotaio_v2.h xattr.h compress.h + quotaio_tree.h quotaio_v2.h xattr.h compress.h inject.h include_HEADERS = $(top_srcdir)/include/quota.h fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \ node.c segment.c dir.c sload.c xattr.c compress.c \ - dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c + dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c \ + inject.c fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} \ ${liblzo2_LIBS} ${liblz4_LIBS} ${libwinpthread_LIBS} \ $(top_builddir)/lib/libf2fs.la diff --git a/fsck/inject.c b/fsck/inject.c new file mode 100644 index 0000000..f6fd346 --- /dev/null +++ b/fsck/inject.c @@ -0,0 +1,64 @@ +/** + * inject.c + * + * Copyright (c) 2024 OPPO Mobile Comm Corp., Ltd. + * http://www.oppo.com/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include "inject.h" + +void inject_usage(void) +{ + MSG(0, "\nUsage: inject.f2fs [options] device\n"); + MSG(0, "[options]:\n"); + MSG(0, " -d debug level [default:0]\n"); + MSG(0, " -V print the version number and exit\n"); + MSG(0, " --dry-run do not really inject\n"); + + exit(1); +} + +int inject_parse_options(int argc, char *argv[], struct inject_option *opt) +{ + int o = 0; + const char *option_string = "d:V"; + struct option long_opt[] = { + {"dry-run", no_argument, 0, 1}, + {0, 0, 0, 0} + }; + + while ((o = getopt_long(argc, argv, option_string, + long_opt, NULL)) != EOF) { + switch (o) { + case 1: + c.dry_run = 1; + MSG(0, "Info: Dry run\n"); + break; + case 'd': + if (optarg[0] == '-' || !is_digits(optarg)) + return EWRONG_OPT; + c.dbg_lv = atoi(optarg); + MSG(0, "Info: Debug level = %d\n", c.dbg_lv); + break; + case 'V': + show_version("inject.f2fs"); + exit(0); + default: + return EUNKNOWN_OPT; + } + } + + return 0; +} + +int do_inject(struct f2fs_sb_info *sbi) +{ + int ret = -EINVAL; + + return ret; +} diff --git a/fsck/inject.h b/fsck/inject.h new file mode 100644 index 0000000..62543c1 --- /dev/null +++ b/fsck/inject.h @@ -0,0 +1,28 @@ +/** + * inject.h + * + * Copyright (c) 2024 OPPO Mobile Comm Corp., Ltd. + * http://www.oppo.com/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _INJECT_H_ +#define _INJECT_H_ + +#include +#include +#include + +#include "f2fs_fs.h" +#include "fsck.h" + +struct inject_option { +}; + +void inject_usage(void); +int inject_parse_options(int argc, char *argv[], struct inject_option *inject_opt); +int do_inject(struct f2fs_sb_info *sbi); +#endif diff --git a/fsck/main.c b/fsck/main.c index 9bda412..f093ca7 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -29,6 +29,15 @@ #include #include "quotaio.h" #include "compress.h" +#ifdef WITH_INJECT +#include "inject.h" +#else +static void inject_usage(void) +{ + MSG(0, "\ninject.f2fs not supported\n"); + exit(1); +} +#endif struct f2fs_fsck gfsck; @@ -190,6 +199,8 @@ static void error_out(char *prog) sload_usage(); else if (!strcmp("f2fslabel", prog)) label_usage(); + else if (!strcmp("inject.f2fs", prog)) + inject_usage(); else MSG(0, "\nWrong program.\n"); } @@ -804,6 +815,18 @@ void f2fs_parse_options(int argc, char *argv[]) c.vol_label = NULL; } #endif /* WITH_LABEL */ + } else if (!strcmp("inject.f2fs", prog)) { +#ifdef WITH_INJECT + static struct inject_option inject_opt; + + err = inject_parse_options(argc, argv, &inject_opt); + if (err < 0) { + err = EWRONG_OPT; + } + + c.func = INJECT; + c.private = &inject_opt; +#endif /* WITH_INJECT */ } if (err == NOERROR) { @@ -1224,6 +1247,12 @@ fsck_again: if (do_label(sbi)) goto out_err; break; +#endif +#ifdef WITH_INJECT + case INJECT: + if (do_inject(sbi)) + goto out_err; + break; #endif default: ERR_MSG("Wrong program name\n"); diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 870a6e4..3a5d146 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -45,6 +45,7 @@ #define WITH_RESIZE #define WITH_SLOAD #define WITH_LABEL +#define WITH_INJECT #endif #include @@ -427,6 +428,7 @@ enum f2fs_config_func { RESIZE, SLOAD, LABEL, + INJECT, }; enum default_set { From patchwork Mon Jun 24 13:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709541 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C260CC2BD09 for ; Mon, 24 Jun 2024 13:56:12 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkB2-0001Ox-03; Mon, 24 Jun 2024 13:56:12 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkAz-0001Oo-Iv for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=chRiwWzhTC8eY6J0yNVFaAk6QJW1jumVmvMImm4+nA8=; b=lXFg0jObeR1UmY1WSUkyd4cYGi sB9OTRfgshjBljhJQq78TDctRdJRHFq5ml6IFfRQt4FZdz3keDI+Im1rhx2FiTJ+CWvPEJtog9vWm 5n1f3nMnZYOLCBkI5r7mJsV39BDLbRc3Laq4tYGgzb4/uJN223lvYBC5jYHJP9P0wKFc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=chRiwWzhTC8eY6J0yNVFaAk6QJW1jumVmvMImm4+nA8=; b=QlQrQJh8uuoCI3DLFTmkfqkTx8 ekELHJLfEPTIUG5SzBxI593ratFk4YSbORJP5wU/qjjF+v/5DMrjP4XqjhqKGk9AS5mnlEa0c+F1n 530SV/6Px3WXNTZ1vGnomgMWDuYhzeyD2T3KkL9zYO8KXSTWPMusbAGZBBb2UWFqoX18=; Received: from mail-sgaapc01on2083.outbound.protection.outlook.com ([40.107.215.83] helo=APC01-SG2-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkAz-00018a-Kr for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PU13LC0wjEN4uRqAepu3u5WTAr6QR3zDkKPBO44ZNJXEMORRn+YgHl6HBsJsbJkQcxw7PcMhnj0Fh3lYWsE553stJ6xZ1wVRvrHSYIAcC0DE8e6QGUsE7ANIb11AHCUmlpSolVEDvq3YhHkz1yudSQrdC1Z+TaBivBQqZeHydiuHvB/+Xya0Ud5pog7BA1IgSG3vqpGBluuvIHmg8nlzpdChdSzv+pbrSzkGB3x/ScUTiKzko3Tzt0LMJ6QZAxOA9ZpdA+sVnkrGxmO6b1lYAILGUOokeJfBUfpk+GXTCF8L7hTTm9Sw8FSgC+mv8G4x0PPOhg3A/gF0aDe3ORgCUA== 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=chRiwWzhTC8eY6J0yNVFaAk6QJW1jumVmvMImm4+nA8=; b=eQDeZaOAUwAiTYnqIK8jlzpycefh2tblfCB6GHKOk44qRCGHJK28tPIy7QUGSeLsqRxEZgroPXxPStIZpvACMcHjsoI2JJPGpn24R9niGHP3YXZ7Qxkgl3P9vVVSaTA0hDCz/lCewwIspcITDozqE6YjJIHyFUTrRvZXgnWetT4dDsDWY2usQyCz+Z196WYv3HdPaNPVJluwZYr8QFeV5gNheAMU0AH8WtoBoR42XM9j7NmnfKGpDqinsamhD42Mx1R+UvO3VdPOFsjvcaTJd8TueSpAbvcyONI8KUes8+r8OpVrkvsuF7VJPxC/uPQzl7GF5aFEhVxdr6X3xaQplw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=chRiwWzhTC8eY6J0yNVFaAk6QJW1jumVmvMImm4+nA8=; b=dg9Vk06GFVs35h7hu5ujcvik7qTOM9mamzT/YgPdrdMK8/U9RiOSD8wtWW6X7sJiw/ReABIe9oaUBs57pzA8aMeh6wOTgopBoNiCCOLeGtRMqbSn9FEQPTiLHlkB6XTn6fdOmUDJiqtdOR/wpY7ZwCO/k3TofDRMs7+RNZlt+uA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEYPR02MB7438.apcprd02.prod.outlook.com (2603:1096:101:1e5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 13:55:57 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:55:57 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:26 +0800 Message-Id: <20240624135532.3330136-4-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7438:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ee353ac-305b-465d-27b6-08dc94555f31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: 458knOpXTuw/OS9F+z+Mu6tkJb9FCvNHUZ1nwuj1RgUooFiBw5dJ8x5LcVjgteAyuUXKiJp115Gzmd11tEmDi6TK8C90HyPfGADRmkpuzcFMY/eTmPUFfxmIKau0AIUfyhEZ3J3d0TzFJSj076w49hTMj4kYEmf2zgMAGU/2XXjh7KozJdhKYBcWkQ2Upd/ZUpeow2gSUmvPwTJ3wKD25xgKpTtE1xy6enwj5Rz8JCQKqwkF9RREe6X1Qd4YtEX3pR+m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XEpd4InP0zf2lcPzBYSW8Ti5C8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S0JTajs7dna2ZjBm/AFFd3M+Gs/hgJpeEJfKUninDnd6XUoBZdej9/i7pYiIwhlMiWnFjdnB2Cml1guYFCsEsKt0zbRFH9co11riycFtvQNL8SV5Z/nWuX0koJnWMdQkKQZRetPx1aAhiXYZbmIV8pZmvVgV348IHsgF+xBivhf82AC04avQyvarnIWuwkcwDDPefELQ9DYVJnfMGHjUwipOIbI6lirIxQxEgODG9lzaSimX6GX2aNqLlGRBZVykJcFwcAMPK1Y8vdBYHrjr7nFr2GeN/JsNDsSo9B7Gl1kHxrwsfAQjJ1PbtoJ0sP7tEDsLFlokaP4YqrDhehzvMqtdLB7medtm/aB8LzGjvN531dagYjwXmeXYLvK4U+Pf0LwW8bdlFxEcujY3MC+jJ+ntgxOvvyn16XYT9WK5UqzZ2o8O+lCmSM5jYhRqtmRxbhxt88wJkIfTtnt63Wn4pMlhqFjDBLknBDqr3dVfeQYo1fooBewqbJw7zzTU5475cvaUzwe62+ECx9XNcoNkuZkx+VbT0mX6cXtzyqksPPecI5H860K4QZbRmtQ8kcqyUD6djMYW6p6ZjjolTws8irYooF57QUgqVvC2L/TpOmEL7zViFYbbCqfl+q2IFpHoDvZE/skyflinsYqqn/PHAHKsNHaw7Zj2hWAkBCYo4zJXIsvzvM46j75yMZJxRMkFApNQI0Q+C15rCrh30XDtKSQ6VMgEZGn/gJOaGtwrwmBqcGXbBYC3vrHZN0R4z72REB0LWPru8ePJz0g79zGpNUE4q+1taTMEEP6BR/tR3z8lk9cD1qVDygGNy29I6ybW/Mc+eR1GeUuJcJBxS3s+lE1MU1bOuyNq0gLx9gQtyWFgB1p1BVkRtL8jrOyGlEWoLiyfFAufsY7czMYFIgCOikL3GKUGDhhhcuiVj/saBUW97aY6kVIzxwiratlK164gTcPDS9fHSc9DYelpB+BXMAuvwGXET/F+zP+XSihfQ4NAW1YfA+9UstBA7kvJLiGxCBdrESSDpW+OSs78HfLFLtXmimSAJhpUm1SvbnE9WCpZzI2GDCGXMvRiyPnP7KLh0CH17t8kwOcSURM71bdgfDJTNGXeV6nKDBHrRZjMuvCNspdbzD4NgUacyFDBhd1BgOdqwWL1baHRtbszLuhnjX1UfFR7uCXcsl7wcdSq7SJfk6+VHmMcFuCdfBOQBAMmHLJSrG3aJdgTEFH3sKn7jeuRRGM+5QE/VEMQlU1LaKFDWQNy7I706+a3eK6at6Tj5kuoTM+xrA1zOjleHi4rZtHMBrs0JMKh1fQYvhm1dQIy5krLsH+LwLatH65TJid+O8c9DIOHROg98r5jU7hNMvU2z+8xoJLz4BGNQBaB3y0DBzWxbYciFcWd8EApG1Clki0NjrmY11iNYvyS261LMSOGhABTyeFyzBSGMEPOT9cklG69bFFeFWxSP1QXUusXBuOsUY0vNWanNRCjLyYoBgsZdBbCcvVy4uNjSwonM857bo2QyyilATGF1ViMWH3va5M+i5S9diIF/ZD/Rv+io0E+n7voRy070r0KqqeypEKCKn33J0XBtWB+l3iLn44w X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ee353ac-305b-465d-27b6-08dc94555f31 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:55:57.1565 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: glQMVkDIkzX/59ClAX2aak4H4y+YIk8axDIgXbi4O0VDMSE4yBQSlXJlzpKhg9ZlhhXkZbgCr7kBvfW2QmjK/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7438 X-Headers-End: 1sLkAz-00018a-Kr Subject: [f2fs-dev] [RFC PATCH 03/10] inject.f2fs: add sb injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting super block. The meanings of options are: * sb: means sb is injected, its argument chooses which sb pack to be injected, where 0 means the current valid sb is choosen automatically. * mb: indicates which member in sb is injected, its argument is the member name. * idx: is used when the mb is an array, its argument is the index of the array. * val: is the new value to be set when the type of mb is a number. * str: is the new value to be set when the type of mb is a string. The members could be injected in sb contains: * magic: magic number * s_stop_reason: s_stop_reason array * s_errors: s_errors array * devs.path: path in devs array Signed-off-by: Sheng Yong --- fsck/inject.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++- fsck/inject.h | 5 ++ fsck/main.c | 5 +- 3 files changed, 142 insertions(+), 2 deletions(-) diff --git a/fsck/inject.c b/fsck/inject.c index f6fd346..1d40b72 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -18,17 +18,42 @@ void inject_usage(void) MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -V print the version number and exit\n"); + MSG(0, " --mb which member is injected in a struct\n"); + MSG(0, " --val new value to set\n"); + MSG(0, " --str new string to set\n"); + MSG(0, " --idx which slot is injected in an array\n"); + MSG(0, " --sb <0|1|2> --mb [--idx ] --val/str inject superblock\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); } +static void inject_sb_usage(void) +{ + MSG(0, "inject.f2fs --sb <0|1|2> --mb [--idx ] --val/str \n"); + MSG(0, "[sb]:\n"); + MSG(0, " 0: auto select the first super block\n"); + MSG(0, " 1: select the first super block\n"); + MSG(0, " 2: select the second super block\n"); + MSG(0, "[mb]:\n"); + MSG(0, " magic: inject magic number\n"); + MSG(0, " s_stop_reason: inject s_stop_reason array selected by --idx \n"); + MSG(0, " s_errors: inject s_errors array selected by --idx \n"); + MSG(0, " devs.path: inject path in devs array selected by --idx specified by --str \n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; - const char *option_string = "d:V"; + const char *pack[] = {"auto", "1", "2"}; + const char *option_string = "d:Vh"; struct option long_opt[] = { {"dry-run", no_argument, 0, 1}, + {"mb", required_argument, 0, 2}, + {"idx", required_argument, 0, 3}, + {"val", required_argument, 0, 4}, + {"str", required_argument, 0, 5}, + {"sb", required_argument, 0, 6}, {0, 0, 0, 0} }; @@ -39,6 +64,33 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) c.dry_run = 1; MSG(0, "Info: Dry run\n"); break; + case 2: + opt->mb = optarg; + MSG(0, "Info: inject member %s\n", optarg); + break; + case 3: + opt->idx = atoi(optarg); + MSG(0, "Info: inject slot index %d\n", opt->idx); + break; + case 4: + opt->val = strtoll(optarg, NULL, 0); + if (opt->val == ULLONG_MAX || opt->val == LLONG_MIN) + return -ERANGE; + MSG(0, "Info: inject value %lld : 0x%llx\n", opt->val, + (unsigned long long)opt->val); + break; + case 5: + opt->str = strdup(optarg); + if (!opt->str) + return -ENOMEM; + MSG(0, "Info: inject string %s\n", opt->str); + break; + case 6: + opt->sb = atoi(optarg); + if (opt->sb < 0 || opt->sb > 2) + return -ERANGE; + MSG(0, "Info: inject sb %s\n", pack[opt->sb]); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -48,7 +100,12 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) case 'V': show_version("inject.f2fs"); exit(0); + case 'h': default: + if (opt->sb >= 0) { + inject_sb_usage(); + exit(0); + } return EUNKNOWN_OPT; } } @@ -56,9 +113,84 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) return 0; } +static int inject_sb(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct f2fs_super_block *sb; + char *buf; + int ret; + + buf = calloc(1, F2FS_BLKSIZE); + ASSERT(buf != NULL); + + if (opt->sb == 0) + opt->sb = 1; + + ret = dev_read_block(buf, opt->sb == 1 ? SB0_ADDR : SB1_ADDR); + ASSERT(ret >= 0); + + sb = (struct f2fs_super_block *)(buf + F2FS_SUPER_OFFSET); + + if (!strcmp(opt->mb, "magic")) { + MSG(0, "Info: inject magic of sb %d: 0x%x -> 0x%x\n", + opt->sb, get_sb(magic), (u32)opt->val); + set_sb(magic, (u32)opt->val); + } else if (!strcmp(opt->mb, "s_stop_reason")) { + if (opt->idx >= MAX_STOP_REASON) { + ERR_MSG("invalid index %u of sb->s_stop_reason[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject s_stop_reason[%d] of sb %d: %d -> %d\n", + opt->idx, opt->sb, sb->s_stop_reason[opt->idx], + (u8)opt->val); + sb->s_stop_reason[opt->idx] = (u8)opt->val; + } else if (!strcmp(opt->mb, "s_errors")) { + if (opt->idx >= MAX_F2FS_ERRORS) { + ERR_MSG("invalid index %u of sb->s_errors[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject s_errors[%d] of sb %d: %d -> %d\n", + opt->idx, opt->sb, sb->s_errors[opt->idx], (u8)opt->val); + sb->s_errors[opt->idx] = (u8)opt->val; + } else if (!strcmp(opt->mb, "devs.path")) { + if (opt->idx >= MAX_DEVICES) { + ERR_MSG("invalid index %u of sb->devs[]\n", opt->idx); + ret = -EINVAL; + goto out; + } + if (strlen(opt->str) >= MAX_PATH_LEN) { + ERR_MSG("invalid length of option str\n"); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject devs[%d].path of sb %d: %s -> %s\n", + opt->idx, opt->sb, (char *)sb->devs[opt->idx].path, opt->str); + strcpy((char *)sb->devs[opt->idx].path, opt->str); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + return -EINVAL; + goto out; + } + + print_raw_sb_info(sb); + update_superblock(sb, SB_MASK((u32)opt->sb - 1)); + +out: + free(buf); + free(opt->str); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { + struct inject_option *opt = (struct inject_option *)c.private; int ret = -EINVAL; + if (opt->sb >= 0) + ret = inject_sb(sbi, opt); + return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index 62543c1..c7d0e33 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -20,6 +20,11 @@ #include "fsck.h" struct inject_option { + const char *mb; /* member name */ + unsigned int idx; /* slot index */ + long long val; /* new value */ + char *str; /* new string */ + int sb; /* which sb */ }; void inject_usage(void); diff --git a/fsck/main.c b/fsck/main.c index f093ca7..d6a7a47 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -817,7 +817,10 @@ void f2fs_parse_options(int argc, char *argv[]) #endif /* WITH_LABEL */ } else if (!strcmp("inject.f2fs", prog)) { #ifdef WITH_INJECT - static struct inject_option inject_opt; + static struct inject_option inject_opt = { + .sb = -1, + .idx = -1, + }; err = inject_parse_options(argc, argv, &inject_opt); if (err < 0) { From patchwork Mon Jun 24 13:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709554 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2A56C2D0D1 for ; Mon, 24 Jun 2024 14:11:06 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkPR-0003T1-Vu; Mon, 24 Jun 2024 14:11:06 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkPQ-0003So-QG for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:11:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=w6fxcWA0sbaYv8uaJufgXMhBumGTwRyITQA5KBTuja0=; b=Yz40htssiWhp3ILVPUJ2QmZ2+N mWmgfqHh8b/p2BZoNHvmf3EVW213AbHQSzPhdQF91qIpaGDlc7CzaZmsbIG2CO4z5et7tJqaIex8a AKP3W4CbtJ53MtpaSXtafJv/qKZrREaemJ9PviiVDDS+rl0BGYbNnQuG30THLnAfy2Mc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=w6fxcWA0sbaYv8uaJufgXMhBumGTwRyITQA5KBTuja0=; b=gczS2fDDdIebLfrXUYsYD4iZcF 2dNnNcGBBcjEgw6/6Zd8t9Xk7J7c3bXZgCE1V1pzvtJMAZ6vAyi0l0zUQkxs+JMVAP1r10I3S/vzL cp+0ouzTQX0qmF6IIUkTCHmOw28GUSWytQU7+AZI5FyXweMnwRbt0zKsMywY08dv/E0A=; Received: from mail-tyzapc01on2057.outbound.protection.outlook.com ([40.107.117.57] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkPQ-0002nE-Cr for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:11:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LAMTllvmTCT3WUoMStP8Pr1yDITLklrVmpNQUmGEiYqn0MMD8tL7I5nxfOJXo0oEZK3nHeqeMnYLL1ZruzLe6ojaThl3R6ONbyJy1k19ouVci+R7V4hyE5H7l8v/X/dOEwctVQyYdJ/xSnsz3DzQUCj5dPci0hjhdL0u9v25ZJqiO3Jf/VyKJlWQAwlIbmdq+z10N2nw3kRwzj3PCK7j85tk31z37L+7NPKbnkI5zROdRuZAh6ZKh219ucXpSYfXKZTuZdX0n0Ekg/3YarmNOSNWcjtAUwcbNkq9XEt2PNNhcApr9hljPmsuVO3ErVT0tS4ucAV2na0QhqEeoHhelw== 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=w6fxcWA0sbaYv8uaJufgXMhBumGTwRyITQA5KBTuja0=; b=FT869X1wV/lSCDbYkHfLdnd2fT4onTBzQB3VE1DW5eBdGLNQTapj6K79UiB35Fnv6xesma43VOPAmmxVT3+yunJnvoqfBLKgL7inP9vhpmmRYYKNSInNzkXSv+KGU4xw6iPrtWCUoricN34Yx7YgmX0vQdFB8MHZUiZwrIKMkagBl8MA9OMxm6qHWHm+ayjkNLAU1tHSTlGUvfvl5bsupPJBSKwJUwNkK5zqs4+HXJXiLDZj4if9+Nf/teNZq0EynvnTXWinAAthRb/MK/nAnIHsbRb7YMsPpdKIPgXcAKsKCkP5vjcza/ynLFpLSSLWq3dU9IbFrWCE7HKBVaOBpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w6fxcWA0sbaYv8uaJufgXMhBumGTwRyITQA5KBTuja0=; b=A08TnSI4Ytdh6tYaaceh1yp/OU8WKNSHTbi2ZS10i8y4NKp/QUt9rZ1F8nsM1UsP8nTi5G90dGEjEbCFhwn/ZdGvE2HzG/US+9nYaVS6pVp2vfVdcO4JwOoCKe8bESCHjBrtbS2l+vRiLYtU2gizB/Xh1Ei2fJ5LF8NL36fYocc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by PUZPR02MB6233.apcprd02.prod.outlook.com (2603:1096:301:f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 13:55:58 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:55:58 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:27 +0800 Message-Id: <20240624135532.3330136-5-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|PUZPR02MB6233:EE_ X-MS-Office365-Filtering-Correlation-Id: c2c48219-90ec-4ed0-4641-08dc94555fee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: sAAeuwx5NJzGbtM/DwVbTjeBQqcKrKnYhQo5iqlhoHcM+HFByVVG8Z3jKYFeaP8N6C416zUDdTm+PqEimY3kWraObYSaodGrl9lv7A3NjE+Ye77rbG4ubk6rCm0tXFLPods/jyKsSizXWUCNfOx3dAicQVlSY5qQ5laTty+n0KDcxaeTOu9VINT5I2DA6zfQgqxzGDORUKI1mbjCRPd7DPfNUUfnyXYROuEzzg7X//5vuUIEh5WkCDTF8Tt3ZIKIL5vvTaThNwJYyfG5o6vq17BFTKSnxigTgxS2ipAkoF1l8Qvw+tcASSTt6ULhvSw3XqZsovb0zYBtf96eDuuOHwy7a9fO7sg/tCg1TEgcHdEGImbJ5z2C5fe2wFJFcRbFJkIIS0y9oFRdZ7TUxdsowsFdr26RMIJgJekW+hzbPIzz0OLCFd1sCKLrDKeyfgU8yh6AGgl4vh48M3wSE4Bn2k5B3yA/fTasq4cmtYBH8lzZ1i3nbnwdsjXbhgIl0wQy9XWraU8z27GlQ6X833ypUOTcSE/kGEeztl5RDnOquHkHyHAqq7aVE2zsU7DaOknL5nqgpYsLf73WhlqRpf/9oe8rNw+KROhP125Afmr4KMeIY5ovX7ed38eXGkiz2bmT1fym5fPZCJLZ+AY43fdQjg61YW1WE6aWHNeSpjMrJBnlS4WUDVPeF+uy0e6x/XuJXCSsrGvsF1hsgA08DijDuCiEROUeilmxlD+VX6Sko4+ji5ajXRaizlPRkYeMbVt7dgSAXAtjwwv+gCwhyjTphLcDBivDJMhnlB/6MJHCjwMkVISC4PG8ZsAPFFEIljMRihcOV002BXwnzhINQqQ5gOvy5HKhyLewr3yQhiLvoDNadgoPhKBTMBq82fRgOAcVsmmhZtCXGkm4blceG2GfJgo+Xpk0HAy7uedQ6PDI+8QIEtY7C+qCQ8hXHpK6gZM1ZVYv43ruAr1ZQfMz/gw2WrkmXRimf2lYhIQpOtM8J6KhHPTbZ6zp4dpjOBNhiUAW3/uE2/T41AlkP4Y8rBVpUC4g5/kN3M7BhzO7i0pUvMhYSj8UDHveaXC+jI6T4dtY8XfCIj7fVdcRe25v4AOxLNruoRibzSeJXQzEyyRiGVDQGb4LjXTJDQ3t/gmsPdigCfRXmkCzySfEmAbR5OXt7aAqxEBGTh5tp02kSVnI5345EZNOu9OUEBCTx+uzAW96Xovci0HT0T8yu2ZvOwmESGgHvvL4by9h+joDLM22/eyxmBor94mFPMzTps4hH+phi1lRNnoJt/qlccp6HPes5VRYXYvM+esF3IHw+Ow2U8y7MDloo/WetmS0uyV2Hmkr0pUBjPpjf6kdidXrI9iHtVwlsXA8kLd8KXpyknYzHDo= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jBhDljdYBAAr01e3p1/obHAVpm7MNykDI1cn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V236kB5k+nlC13+NHFY+XSUDymeZO9BRrqg8oBlUJxlE3NiVs/YIdjdktY7Jb217WQ2iEpctesLRUVjH3nF+EGFHb6EktT8X3Q5FNX2ek/FWRfbRJVS9YGyuJbkw/7p8ndmvtk0+qCIygL8REK9SGk/fqGeXNRS4ziTmNS+UCJNhNeSuMipZn3kCRYLWyb93hBl2btg7G1cwGaJvz+214y2ILJfAffYKd8D6AH4vFh0Sx4L3fC5uKPRPZFEuoT/Bz31zXCTY7gL0QZ3dA4FBFcj8n5cFx9AxrCX/b4UBubQC+l+kdAJMvuVFvVoz6mFbBuOvDuITp7swl7DPGAm0Zksnd1yzk++8ZgI4Vp7W43R0X4bD8R0+xbuFzSy31wGVt4KIMVdNujcM7s40nE1wG6C2Peq3C3HMtzs0OocbhatUh1RGHY2pDmPjAYkbJ0abzECuhyv9s3cS5smKPdyQ7qp X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2c48219-90ec-4ed0-4641-08dc94555fee X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:55:58.5250 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: v5qLabKicXKAcbgx7KVhLgEIMcreZSzLA/SXFU7K12WrLL1jfckasiz6/9AzhSf7+Hv/4szrDy+5NjrXzkTzzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR02MB6233 X-Headers-End: 1sLkPQ-0002nE-Cr Subject: [f2fs-dev] [RFC PATCH 04/10] inject.f2fs: add cp injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting checkpoint. To archive this, a helper update_checkpoint() is added to write specific cp. And print_ckpt_info() is exported to show new checkpoint info. The meanings of options are: * cp: means cp is injected, its argument chooses which cp pack to be injected, where 0 means the current valid cp is choosen automatically. The members could be injected in cp contains: * checkpoint_ver: checkpoint version * ckpt_flags: checkpoint flags * cur_node_segno: cur_node_segno array * cur_node_blkoff: cur_node_blkoff array * cur_data_segno: cur_data_segno array * cur_data_blkoff: cur_data_blkoff array Signed-off-by: Sheng Yong --- fsck/fsck.h | 2 + fsck/inject.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + fsck/main.c | 1 + fsck/mount.c | 6 +++ 5 files changed, 134 insertions(+) diff --git a/fsck/fsck.h b/fsck/fsck.h index 4ca75b3..381dc9c 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -236,12 +236,14 @@ extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int, bool); extern void duplicate_checkpoint(struct f2fs_sb_info *); extern void write_checkpoint(struct f2fs_sb_info *); extern void write_checkpoints(struct f2fs_sb_info *); +extern void update_checkpoint(struct f2fs_sb_info *, int); extern void update_superblock(struct f2fs_super_block *, int); extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t, struct f2fs_node *); extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t); extern void print_raw_sb_info(struct f2fs_super_block *); +extern void print_ckpt_info(struct f2fs_sb_info *); extern bool is_checkpoint_stop(struct f2fs_super_block *, bool); extern bool is_inconsistent_error(struct f2fs_super_block *); extern pgoff_t current_nat_addr(struct f2fs_sb_info *, nid_t, int *); diff --git a/fsck/inject.c b/fsck/inject.c index 1d40b72..e7ec329 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -23,6 +23,7 @@ void inject_usage(void) MSG(0, " --str new string to set\n"); MSG(0, " --idx which slot is injected in an array\n"); MSG(0, " --sb <0|1|2> --mb [--idx ] --val/str inject superblock\n"); + MSG(0, " --cp <0|1|2> --mb [--idx ] --val inject checkpoint\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -42,6 +43,22 @@ static void inject_sb_usage(void) MSG(0, " devs.path: inject path in devs array selected by --idx specified by --str \n"); } +static void inject_cp_usage(void) +{ + MSG(0, "inject.f2fs --cp <0|1|2> --mb [--idx ] --val inject checkpoint\n"); + MSG(0, "[cp]:\n"); + MSG(0, " 0: auto select the current cp pack\n"); + MSG(0, " 1: select the first cp pack\n"); + MSG(0, " 2: select the second cp pack\n"); + MSG(0, "[mb]:\n"); + MSG(0, " checkpoint_ver: inject checkpoint_ver\n"); + MSG(0, " ckpt_flags: inject ckpt_flags\n"); + MSG(0, " cur_node_segno: inject cur_node_segno array selected by --idx \n"); + MSG(0, " cur_node_blkoff: inject cur_node_blkoff array selected by --idx \n"); + MSG(0, " cur_data_segno: inject cur_data_segno array selected by --idx \n"); + MSG(0, " cur_data_blkoff: inject cur_data_blkoff array selected by --idx \n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -54,6 +71,7 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"val", required_argument, 0, 4}, {"str", required_argument, 0, 5}, {"sb", required_argument, 0, 6}, + {"cp", required_argument, 0, 7}, {0, 0, 0, 0} }; @@ -91,6 +109,12 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) return -ERANGE; MSG(0, "Info: inject sb %s\n", pack[opt->sb]); break; + case 7: + opt->cp = atoi(optarg); + if (opt->cp < 0 || opt->cp > 2) + return -ERANGE; + MSG(0, "Info: inject cp pack %s\n", pack[opt->cp]); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -105,6 +129,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) if (opt->sb >= 0) { inject_sb_usage(); exit(0); + } else if (opt->cp >= 0) { + inject_cp_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -184,6 +211,101 @@ out: return ret; } +static int inject_cp(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct f2fs_checkpoint *cp, *cur_cp = F2FS_CKPT(sbi); + char *buf = NULL; + int ret = 0; + + if (opt->cp == 0) + opt->cp = sbi->cur_cp; + + if (opt->cp != sbi->cur_cp) { + struct f2fs_super_block *sb = sbi->raw_super; + block_t cp_addr; + + buf = calloc(1, F2FS_BLKSIZE); + ASSERT(buf != NULL); + + cp_addr = get_sb(cp_blkaddr); + if (opt->cp == 2) + cp_addr += 1 << get_sb(log_blocks_per_seg); + ret = dev_read_block(buf, cp_addr); + ASSERT(ret >= 0); + + cp = (struct f2fs_checkpoint *)buf; + sbi->ckpt = cp; + } else { + cp = cur_cp; + } + + if (!strcmp(opt->mb, "checkpoint_ver")) { + MSG(0, "Info: inject checkpoint_ver of cp %d: 0x%llx -> 0x%lx\n", + opt->cp, get_cp(checkpoint_ver), (u64)opt->val); + set_cp(checkpoint_ver, (u64)opt->val); + } else if (!strcmp(opt->mb, "ckpt_flags")) { + MSG(0, "Info: inject ckpt_flags of cp %d: 0x%x -> 0x%x\n", + opt->cp, get_cp(ckpt_flags), (u32)opt->val); + set_cp(ckpt_flags, (u32)opt->val); + } else if (!strcmp(opt->mb, "cur_node_segno")) { + if (opt->idx >= MAX_ACTIVE_NODE_LOGS) { + ERR_MSG("invalid index %u of sb->cur_node_segno[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject cur_node_segno[%d] of cp %d: 0x%x -> 0x%x\n", + opt->idx, opt->cp, get_cp(cur_node_segno[opt->idx]), + (u32)opt->val); + set_cp(cur_node_segno[opt->idx], (u32)opt->val); + } else if (!strcmp(opt->mb, "cur_node_blkoff")) { + if (opt->idx >= MAX_ACTIVE_NODE_LOGS) { + ERR_MSG("invalid index %u of sb->cur_node_blkoff[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject cur_node_blkoff[%d] of cp %d: 0x%x -> 0x%x\n", + opt->idx, opt->cp, get_cp(cur_node_blkoff[opt->idx]), + (u32)opt->val); + set_cp(cur_node_blkoff[opt->idx], (u32)opt->val); + } else if (!strcmp(opt->mb, "cur_data_segno")) { + if (opt->idx >= MAX_ACTIVE_DATA_LOGS) { + ERR_MSG("invalid index %u of sb->cur_data_segno[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject cur_data_segno[%d] of cp %d: 0x%x -> 0x%x\n", + opt->idx, opt->cp, get_cp(cur_data_segno[opt->idx]), + (u32)opt->val); + set_cp(cur_data_segno[opt->idx], (u32)opt->val); + } else if (!strcmp(opt->mb, "cur_data_blkoff")) { + if (opt->idx >= MAX_ACTIVE_DATA_LOGS) { + ERR_MSG("invalid index %u of sb->cur_data_blkoff[]\n", + opt->idx); + ret = -EINVAL; + goto out; + } + MSG(0, "Info: inject cur_data_blkoff[%d] of cp %d: 0x%x -> 0x%x\n", + opt->idx, opt->cp, get_cp(cur_data_blkoff[opt->idx]), + (u32)opt->val); + set_cp(cur_data_blkoff[opt->idx], (u32)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + ret = -EINVAL; + goto out; + } + + print_ckpt_info(sbi); + update_checkpoint(sbi, opt->cp); + +out: + free(buf); + sbi->ckpt = cur_cp; + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -191,6 +313,8 @@ int do_inject(struct f2fs_sb_info *sbi) if (opt->sb >= 0) ret = inject_sb(sbi, opt); + else if (opt->cp >= 0) + ret = inject_cp(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index c7d0e33..907309f 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -25,6 +25,7 @@ struct inject_option { long long val; /* new value */ char *str; /* new string */ int sb; /* which sb */ + int cp; /* which cp */ }; void inject_usage(void); diff --git a/fsck/main.c b/fsck/main.c index d6a7a47..0318873 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -819,6 +819,7 @@ void f2fs_parse_options(int argc, char *argv[]) #ifdef WITH_INJECT static struct inject_option inject_opt = { .sb = -1, + .cp = -1, .idx = -1, }; diff --git a/fsck/mount.c b/fsck/mount.c index 8524335..ad41215 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -3426,6 +3426,12 @@ void write_checkpoints(struct f2fs_sb_info *sbi) write_checkpoint(sbi); } +void update_checkpoint(struct f2fs_sb_info *sbi, int which) +{ + sbi->cur_cp = which == 1 ? 2 : 1; + write_checkpoint(sbi); +} + void build_nat_area_bitmap(struct f2fs_sb_info *sbi) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); From patchwork Mon Jun 24 13:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709576 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86B2BC2BD09 for ; Mon, 24 Jun 2024 14:31:24 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkj6-00007h-P2; Mon, 24 Jun 2024 14:31:24 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkj5-00007b-OH for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:31:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=iohESym0hMEMsIt7cKZdAuJhsVLYFFLlIIgu3OiqWqI=; b=mf1+/xzfj3bBrRnalQ5DsphW1Y 0R+omJ9dva/DylobNanjonQqB2A6JAk0rSuHiOeLPuDUBhybOJXnQTxYbpo1XWRHaKTnoJvtkKpCq Hp/nx6LQYbqIZczGAjArG120aDm+geHjaL1dJbXaQvYW1WWlW1YJUUp5WJZX0WlAdxJY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iohESym0hMEMsIt7cKZdAuJhsVLYFFLlIIgu3OiqWqI=; b=YYSxgf4MifBvpK1UHREomPC+M5 XaoVwDWPFSbsbWDTq+xH4FLSr6h/PZ+0m+6Wd3adaOiqAFmvWVeLYD+fyZ2c920SJhOVlas1qbk9I yJHZfAQMWEreIzi5O2mQqYHsCKqKsDp5flxYCwTaah6tPnHuIR9GlzKta1YEp+T/IXBg=; Received: from mail-tyzapc01on2077.outbound.protection.outlook.com ([40.107.117.77] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkj4-0004y3-Uo for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:31:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HBItx3x+bLTP7aRVzF9JR6rZKWmHMt57nc9cN7iynLULSYTI7HwsmrOA0b+swejavrdUPDNKc7MdeBKznQqu566XRtdsRHndo91OtIeKQDrAla8EiFh+XwfSzQsf1YSgSaEZnx2FQkbE5gcIWN6WqHO81Hw80qp9/FkkFcFZdkAvkZ7IDuP4Grj1bZqjoRV+FNDvCo/r1Ax5OXCqKYtmoci5YbplS8T8y3zsSCBYv8A3WimW8m2FOs4PPV0CadiJp00jIS2D46rZFsQOu9ActaVSQMms0VE55ojHtGzA4xNgnwTmU8d0Bra/7a/n+Ywr3PEeaFLrqNhPagk03KANqQ== 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=iohESym0hMEMsIt7cKZdAuJhsVLYFFLlIIgu3OiqWqI=; b=gFj+R0mf/bLdruB3Mr5WcFdcfIPDf0MtKr6/9/owMmhhXLP3ezGB9kUsnQ6TazaONsPOH/Kv7fkSEhldqywLXfwjx6bVyTu7q0ZaAPaXsccbcT0rxd1878HhkBxxBvDGTM1Fb9XZ5TTUQ1L3kBtkob0O/HufuRuOIpWdZWu+SBy4yuTl9hg8UsaLYq3TN/10dXIbw0e21FdocLIo3+TYWwhVkUxBXeryCsb4ja/k1RiZpwSBf+sMl1UCZ8ynkO3pYeuZXYBlAJ7Cr1DpSa8wg0jnBXOlGq86P15aLaK+Cuq6NMlu7j6a6BslqmFnh2JlZab1xvBhkRIUp39Gn3GzPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iohESym0hMEMsIt7cKZdAuJhsVLYFFLlIIgu3OiqWqI=; b=Z4RTOQc7zYWJs+nyOEtnbGPogfbdBnfQUdmKObAmVXVLSQxR9bnsDLkdiTAwJ5bSTINXdjVHWH5tVBjBlOnEJ1D5OANQ8TE+HORakGshcBWStxSelnM+xRePNhQE7/gyPU2FouAdJS/ihliXTFtqqaVaKtLCxP2sCr+D9pKahsk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:56:00 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:55:59 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:28 +0800 Message-Id: <20240624135532.3330136-6-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 8078fc18-18ac-495d-23bd-08dc945560cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|376011|52116011|38350700011; X-Microsoft-Antispam-Message-Info: b5wAbeEra/tXWs3+o/eLK0KRtD84vzJtWPIjGQmm1JHHjU6l2vzMX69Q7BM+N4ar6Gi60OTSzauqy1cSWOQd/QTDO6jG7FqcxZflI3Nnz5S6wrJO46gfMA2kscC6FYPVaBW37dY9lE1FDQol6Y+e0HVR5WW3/wia6xbGBCC5j82fkAL1IAP2ZnUOFsNHdUbWUmb8XiQFYQcouVGjL9eBzkd3mDEu4i9pBOdwRKxmWraKoExgvC3/wuPGSaJ0Pefs5o96y6BZ6k9izM4SZimlOSHqZ8WOZB8Uw7LxY1z40gXsQCa0EAFi8WMqbNLx60FnzILUjNYqad+8kZbTTeRArYbdTElLfpx0UqYwOgwHrUlXPghLUDpMMk4EUDFb9mVEQGi3FmGmYRfx266lc2yKVh2PK2+/TzRBRTeTRqALU3AenE92G0IcVXd16OlRGwEjlr34g8P12VCwOtm7a2tSPnaei3SLDlxkdQRdXyriYJPuPgqJ9yXZHlei3XN9KHvJtErExIceTLFmfopa/jGC5KLbnHvKYA4VA2rF516kwxAesBBKB2Yhip6tOmDiovFCZaXjUOrw6ENXD/9AUnPbOc2Y1/Aa4EjPQzTPr8kS8NAM/AFt0rYECGPI83wttH2S3QCD4BwpLiaGJyRnNsjovd/8Q4XQ1aY2eJgzvY7kSu+DhUsV8iYJ60BYJOcjSddHf5/VNLeqkzOptfioAPb5CQnjBmAuufweipcdhRq7WU7Gem0+usPu99OCbwbccVdsLQtg/rbHJC1YsfE6G64qXOhvWK62t80GwjGbD15FJ8LTKg3G1MvSxKL8L3weySwKZx9VxW/aSJ3fthVhYpWPsQWrCAiTY9YiEE6LzM9b3ODbKG/2RkjvZwG8asJQSoGPRcMxX3WKPmsQ7Zygefl1LuMimvvjRl1sAIDtespm2jPle/lsceHEmikYHzNHjvJr1/k3R8JJ3+1QCBOI9HRyTWOdgJE3o2iXdHkLd+jEl8PsidNUIdbF8hLZCUU3cjTyWMPD4wvcG7HWwUKcswamVvfH6s0RbVuHwFss2MIzAwJfLqM+jHLRa5D2VPa9B4dDQ0hQAqybVfdVCW6WJ/C6Jr0xq0Z5//m2AlSNwQqe1xJQq/qjt3C0wP6e7eCn/UPnfosgmb70MfbB3aefE/aVrBphOaiP6Asq722CalirLf3dyGGpe6JCW7h7hfrYhyVhdIsMxidgDPyo13i1sublTa/KBgWalw2oqLWFg+4FFP+Gt7E1wP1EFAiJyGmG9zXFxukM6dfcQftNdljN4t4YKc6EYB4f5GDXvVbJm4Q63Zl9JL47DvNaJUMeMtmMiym+RonxZBmhpS8zpV7EOhUFo2FhOT98u2gGMwDY31z7ctg= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ohjqJkaVNmYHoxpKtluVUFQDHukLXQellGeq71+NiRNe/XSHPUiIn305dOXG6KGCdKDZhSWQSM5ujwerdLVWOYFtveNdBA+cn1RC63H8iVdBcjOp7/q8QW+y69RPDR+kDOJBeu63F4xy7vzg1ShYRCDrhoV5He2hHnFaQrCnDN/ViJbLKGq7CaXLlieTC1jkkrAFaVF79Vve0wvWBzzlA5BvV65OdeFfqGDij9TIyCS7vr9hvJgxoB2FcCCHIvxV+0ML3sYbVWVOxQU/VuqpO52oyZ2tnEoDGpdvNleM/U0EYVPHRH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Y6HpbaTiyUSta/abgghrEbfjYTT8kq7frCvDMYIiOs3UinyWvcA2uoqWTYNej8iXmyQxz9K0NAdLCxuyyvc5c4cwplhaZUgbCQEAX40Nq4ibtwY7v3/2GPVMl8mkKDTK/msU1zTbtpbGJuhyPJaYMtODwLxeqXfQ1ZdSNYtc8XR1RIc3XzdnCVjGgwjVFb+IoExlisf6NgVxoph X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8078fc18-18ac-495d-23bd-08dc945560cd X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:55:59.8597 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +ZlcAx5vR+wu/udhZiV4KU90t/S3g2JDfbF0gN71RI2hJwyKVXFae/YKapmkldfZa36oqsI01ok5pUGpGb8HRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkj4-0004y3-Uo Subject: [f2fs-dev] [RFC PATCH 05/10] inject.f2fs: add nat injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting nat entry. print_raw_nat_entry_info() is added to show values of the nat entry. The meanings of options are: * nat: means nat entry is injected, its argument chooses which nat pack to be injected, where 0 means the current valid nat is choosen automatically. * nid: is the nid of the nat entry The members could be injected in cp contains: * version: nat entry version * ino: nat entry ino * block_addr: nat entry block_addr Signed-off-by: Sheng Yong --- fsck/inject.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 2 + fsck/main.c | 2 + 3 files changed, 123 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index e7ec329..c2deaba 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -12,6 +12,16 @@ #include #include "inject.h" +static void print_raw_nat_entry_info(struct f2fs_nat_entry *ne) +{ + if (!c.dbg_lv) + return; + + DISP_u8(ne, version); + DISP_u32(ne, ino); + DISP_u32(ne, block_addr); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -22,8 +32,10 @@ void inject_usage(void) MSG(0, " --val new value to set\n"); MSG(0, " --str new string to set\n"); MSG(0, " --idx which slot is injected in an array\n"); + MSG(0, " --nid which nid is injected\n"); MSG(0, " --sb <0|1|2> --mb [--idx ] --val/str inject superblock\n"); MSG(0, " --cp <0|1|2> --mb [--idx ] --val inject checkpoint\n"); + MSG(0, " --nat <0|1|2> --mb --nid --val inject nat entry\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -59,6 +71,19 @@ static void inject_cp_usage(void) MSG(0, " cur_data_blkoff: inject cur_data_blkoff array selected by --idx \n"); } +static void inject_nat_usage(void) +{ + MSG(0, "inject.f2fs --nat <0|1|2> --mb --nid --val inject nat entry\n"); + MSG(0, "[nat]:\n"); + MSG(0, " 0: auto select the current nat pack\n"); + MSG(0, " 1: select the first nat pack\n"); + MSG(0, " 2: select the second nat pack\n"); + MSG(0, "[mb]:\n"); + MSG(0, " version: inject nat entry version\n"); + MSG(0, " ino: inject nat entry ino\n"); + MSG(0, " block_addr: inject nat entry block_addr\n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -72,6 +97,8 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"str", required_argument, 0, 5}, {"sb", required_argument, 0, 6}, {"cp", required_argument, 0, 7}, + {"nat", required_argument, 0, 8}, + {"nid", required_argument, 0, 9}, {0, 0, 0, 0} }; @@ -115,6 +142,18 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) return -ERANGE; MSG(0, "Info: inject cp pack %s\n", pack[opt->cp]); break; + case 8: + opt->nat = atoi(optarg); + if (opt->nat < 0 || opt->nat > 2) + return -ERANGE; + MSG(0, "Info: inject nat pack %s\n", pack[opt->nat]); + break; + case 9: + opt->nid = strtol(optarg, NULL, 0); + if (opt->nid == ULONG_MAX || opt->nid == LONG_MIN) + return -ERANGE; + MSG(0, "Info: inject nid %u : 0x%x\n", opt->nid, opt->nid); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -132,6 +171,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->cp >= 0) { inject_cp_usage(); exit(0); + } else if (opt->nat >= 0) { + inject_nat_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -306,6 +348,81 @@ out: return ret; } +static int inject_nat(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct f2fs_nm_info *nm_i = NM_I(sbi); + struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); + struct f2fs_nat_block *nat_blk; + struct f2fs_nat_entry *ne; + block_t blk_addr; + unsigned int offs; + bool is_set; + int ret; + + if (!IS_VALID_NID(sbi, opt->nid)) { + ERR_MSG("Invalid nid %u range [%u:%lu]\n", opt->nid, 0, + NAT_ENTRY_PER_BLOCK * + ((get_sb(segment_count_nat) << 1) << + sbi->log_blocks_per_seg)); + return -EINVAL; + } + + nat_blk = calloc(F2FS_BLKSIZE, 1); + ASSERT(nat_blk); + + /* change NAT version bitmap temporarily to select specified pack */ + is_set = f2fs_test_bit(opt->nid, nm_i->nat_bitmap); + if (opt->nat == 0) { + opt->nat = is_set ? 2 : 1; + } else { + if (opt->nat == 1) + f2fs_clear_bit(opt->nid, nm_i->nat_bitmap); + else + f2fs_set_bit(opt->nid, nm_i->nat_bitmap); + } + + blk_addr = current_nat_addr(sbi, opt->nid, NULL); + + ret = dev_read_block(nat_blk, blk_addr); + ASSERT(ret >= 0); + + offs = opt->nid % NAT_ENTRY_PER_BLOCK; + ne = &nat_blk->entries[offs]; + + if (!strcmp(opt->mb, "version")) { + MSG(0, "Info: inject nat entry version of nid %u " + "in pack %d: %d -> %d\n", opt->nid, opt->nat, + ne->version, (u8)opt->val); + ne->version = (u8)opt->val; + } else if (!strcmp(opt->mb, "ino")) { + MSG(0, "Info: inject nat entry ino of nid %u " + "in pack %d: %d -> %d\n", opt->nid, opt->nat, + le32_to_cpu(ne->ino), (nid_t)opt->val); + ne->ino = cpu_to_le32((nid_t)opt->val); + } else if (!strcmp(opt->mb, "block_addr")) { + MSG(0, "Info: inject nat entry block_addr of nid %u " + "in pack %d: 0x%x -> 0x%x\n", opt->nid, opt->nat, + le32_to_cpu(ne->block_addr), (block_t)opt->val); + ne->block_addr = cpu_to_le32((block_t)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + free(nat_blk); + return -EINVAL; + } + print_raw_nat_entry_info(ne); + + ret = dev_write_block(nat_blk, blk_addr); + ASSERT(ret >= 0); + /* restore NAT version bitmap */ + if (is_set) + f2fs_set_bit(opt->nid, nm_i->nat_bitmap); + else + f2fs_clear_bit(opt->nid, nm_i->nat_bitmap); + + free(nat_blk); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -315,6 +432,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_sb(sbi, opt); else if (opt->cp >= 0) ret = inject_cp(sbi, opt); + else if (opt->nat >= 0) + ret = inject_nat(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index 907309f..db45fb9 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -24,8 +24,10 @@ struct inject_option { unsigned int idx; /* slot index */ long long val; /* new value */ char *str; /* new string */ + nid_t nid; int sb; /* which sb */ int cp; /* which cp */ + int nat; /* which nat pack */ }; void inject_usage(void); diff --git a/fsck/main.c b/fsck/main.c index 0318873..3ab49a4 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -820,7 +820,9 @@ void f2fs_parse_options(int argc, char *argv[]) static struct inject_option inject_opt = { .sb = -1, .cp = -1, + .nat = -1, .idx = -1, + .nid = -1, }; err = inject_parse_options(argc, argv, &inject_opt); From patchwork Mon Jun 24 13:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709574 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53A67C2BD09 for ; Mon, 24 Jun 2024 14:29:27 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkhC-0005C7-7k; Mon, 24 Jun 2024 14:29:26 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkhB-0005Bv-1d for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:29:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LYLBi3KZh5mCffkoxkRYX2vtpRjqRotR8GMfHoh22gw=; b=l2M9DP2NTTQK6kRLpQC8YxJFPS 7PihNViPC52HJrlDonbWqAwBmK1A1x02Fka8bpruLz+R9gnOJpq2Bflqq3sILmvG/mWRMfbWHkgyf CIiNdng+0npNVCJQB5SEV4gnWrEAMPshIE2XeXDigxl+gYN1BNV0TyWE19I0gF0aFxYo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LYLBi3KZh5mCffkoxkRYX2vtpRjqRotR8GMfHoh22gw=; b=U9sHn4rLHSFGDIjaKqxFe7a+tY zL8Qv7rs13O50fEBkJ5821aT6GhjKdeKUIixhCdUFqtaxcPVCdVK85xKu/XnwCItrJXHj7tHPsCh1 xMBodFodFuPhtPxNEJG1g/+DHCECPpeaFwTAQjXL0e3EcywdlzawNT0lTA+nHV8GCO20=; Received: from mail-sgaapc01on2056.outbound.protection.outlook.com ([40.107.215.56] helo=APC01-SG2-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkh8-0004kM-Vl for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:29:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ptb6xe5W8enzOATTEa0yk6R60S14a/O+PDtOnzeswFRd4dYqjraS577pNhz0daJVPson4mVc19yXlUQTH2RmtX05YrZ/ku1dOaM09JjS/bgEbzilQkKfnaDx7SO0CYsfQMblLigy0wBxFJyWkPY7n0uDw95M8p3B1vlv1GvxMmMKflJKkPIRmOEG67233qLaPalb3xMIzRer55bUhxpqCxFfntdBG2FQKF5vZozN0sD3trKUciodGHZyoWiftcQTEcQ2yeOzo+fp6LnlaV4H2jqu86UQO/4cpWRjxydztY8fpqDWA8Kk7egLtwEpf2aHxgT7THnlxHaJBho3/QV6yA== 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=LYLBi3KZh5mCffkoxkRYX2vtpRjqRotR8GMfHoh22gw=; b=T/haH4L9tPU4bd0QNUOO/XSYoyi1cNk4RWiCCy3IWX5sToylq1ZdjMKunUC4sjJi6CgbZw3LbckNEfEcCP8846AOHGvh+unCN/4oNLMrxgVGZ+9+liIQGfgv0aYiqRHZ2LjCGM/gl0BtT8V1bz4Dnz6p7ZVXM4Fh3hHfAhmovti2AJUrSk9G2hFrNXVjgUVbuFoleJAcsDgq0YsBrwbVHMkc0ZnksYzqI+EL57pL4KljF2nLnxLYEa1YELKE8IC0NrEzEAqR7BqvYjaTb2jKkdEXx8L0FSXKhGzoRBUKmgaCCNggvWtOWNq8afeuEDLMa6mnsj7+Ta5xI42LSeWZYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LYLBi3KZh5mCffkoxkRYX2vtpRjqRotR8GMfHoh22gw=; b=nCL3KXip5Xor4d01zyOTf/vsooYA0NqB1wtPswpxSFe/eiA2dLy29o+EfH71AnyqIkTWOp/eAIucVoUeFgxMEz5l6s3ScTpyHauWKxC1L7xormBvxBLVVctE29BD4iw2DJTq9GN4+d1loc2KxPXn2TH5p+i9GHZlMMXtHyusA3Q= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:56:01 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:56:01 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:29 +0800 Message-Id: <20240624135532.3330136-7-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 19eed5e4-dd2b-463a-a42d-08dc94556189 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|376011|52116011|38350700011; X-Microsoft-Antispam-Message-Info: rDAyNclYiP+5dv+ctJ8ALoqe3pen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jrz9/rRIrf/L7src9ges6nFaBIJu2XjQF6uj7jxg/OEZigjlh4SDZ2xS0M+aOj2sEukVAsducdfW7VUzWZbfrgO2zRECidATxa6qoJzAYSEAEydJxvq0DQG2CJMtvyiBWaFjsOmmdwrBbNMM0GnOkmW4LVU0HdacW+s6i457+Hy87t10ebi+ZeC/XRumYxJNuUcIIw6Y7ElaqYWLHxJhtEmkHULBbzDNBFebw3Rd5WonZFhhqd6hHf2KkOlxdn2f5SK30N+4+A= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iGh6ycajTgAx6k93E1WNO1o5rlpGW0cexcUFCRBATMkg1+w3D7MHU5+VEoMwBO+hAJbS5s3i/O51E2C2hMfa6PsnSCmBNNoGTXJgroJ99FsrrNvRo5ETcf1vo+crAJzIK68vjuCIcpc4i3LN0+0RdRYJGq+Cd0cd4mqmf6ahZzOoYar+52WEUVKa3vAW93LLrlZjZqCdEfBtH5TDa5ey+aFJdSgllg7/qFR64PzgM+4UUZE0Oc3qDcFAuxHfZb1o3/EJGKYUBi8j1wmIZEnNwo29WqDFQDRJb3sjIj45rYMNfOrfKnQzbyBprWjnBgIiaTk9Vk+BmTo+LCmqNRhOqjfJk1Cp1SN+DHq77NAm7Z6uipJFJhI2ln4DpaphHayP+8l0Xgqm6OCb/lPOCJPciWpYm6xgKx4xVFIKzL0tZ24HQthwZVMUxD+ke4O9xGFeZVGXCZ0WFwQbQRRSnKppxXf2NH0gdETZh2Rxs+FzYaGyu7aUxY2ugHQRBuwoMOwWDWtQcU9Qual285WkUlT7pCNHTmP0MIVdIrftOyoUYaZVAFmLN4PGxAK+fTtJ+BhQJIa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Id: 19eed5e4-dd2b-463a-a42d-08dc94556189 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:56:01.0928 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XZxsevbeZFL+aZ4Oj4uN1qE4nPJkAOhtnEm2vpAxPPBlDCuqErg7f601Pi0qP4waDcrTSsB6AhTv6h2Fa/5jDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkh8-0004kM-Vl Subject: [f2fs-dev] [RFC PATCH 06/10] inject.f2fs: add sit injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting sit entry. print_raw_sit_entry_info() is added to show values of the sit entry. The meanings of options are: * sit: means sit entry is injected, its argument chooses which sit pack to be injected, where 0 means the current valid sit is choosen automatically. * blk: is the block address of the sit entry. The members could be injected in cp contains: * vblocks: sit entry vblocks * valid_map: sit entry valid_map * mtime: sit entry mtime Signed-off-by: Sheng Yong --- fsck/inject.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 2 + fsck/main.c | 1 + 3 files changed, 133 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index c2deaba..f854651 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -22,6 +22,27 @@ static void print_raw_nat_entry_info(struct f2fs_nat_entry *ne) DISP_u32(ne, block_addr); } +static void print_raw_sit_entry_info(struct f2fs_sit_entry *se) +{ + int i; + + if (!c.dbg_lv) + return; + + DISP_u16(se, vblocks); + if (c.layout) + printf("%-30s ", "valid_map:"); + else + printf("%-30s\t\t[", "valid_map"); + for (i = 0; i < SIT_VBLOCK_MAP_SIZE; i++) + printf("%02x", se->valid_map[i]); + if (c.layout) + printf("\n"); + else + printf("]\n"); + DISP_u64(se, mtime); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -33,9 +54,11 @@ void inject_usage(void) MSG(0, " --str new string to set\n"); MSG(0, " --idx which slot is injected in an array\n"); MSG(0, " --nid which nid is injected\n"); + MSG(0, " --blk which blkaddr is injected\n"); MSG(0, " --sb <0|1|2> --mb [--idx ] --val/str inject superblock\n"); MSG(0, " --cp <0|1|2> --mb [--idx ] --val inject checkpoint\n"); MSG(0, " --nat <0|1|2> --mb --nid --val inject nat entry\n"); + MSG(0, " --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -84,6 +107,19 @@ static void inject_nat_usage(void) MSG(0, " block_addr: inject nat entry block_addr\n"); } +static void inject_sit_usage(void) +{ + MSG(0, "inject.f2fs --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); + MSG(0, "[sit]:\n"); + MSG(0, " 0: auto select the current sit pack\n"); + MSG(0, " 1: select the first sit pack\n"); + MSG(0, " 2: select the second sit pack\n"); + MSG(0, "[mb]:\n"); + MSG(0, " vblocks: inject sit entry vblocks\n"); + MSG(0, " valid_map: inject sit entry valid_map\n"); + MSG(0, " mtime: inject sit entry mtime\n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -99,6 +135,8 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"cp", required_argument, 0, 7}, {"nat", required_argument, 0, 8}, {"nid", required_argument, 0, 9}, + {"sit", required_argument, 0, 10}, + {"blk", required_argument, 0, 11}, {0, 0, 0, 0} }; @@ -154,6 +192,18 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) return -ERANGE; MSG(0, "Info: inject nid %u : 0x%x\n", opt->nid, opt->nid); break; + case 10: + opt->sit = atoi(optarg); + if (opt->sit < 0 || opt->sit > 2) + return -ERANGE; + MSG(0, "Info: inject sit pack %s\n", pack[opt->sit]); + break; + case 11: + opt->blk = strtol(optarg, NULL, 0); + if (opt->blk == ULONG_MAX || opt->blk == LONG_MIN) + return -ERANGE; + MSG(0, "Info: inject blkaddr %u : 0x%x\n", opt->blk, opt->blk); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -174,6 +224,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->nat >= 0) { inject_nat_usage(); exit(0); + } else if (opt->sit >= 0) { + inject_sit_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -423,6 +476,81 @@ static int inject_nat(struct f2fs_sb_info *sbi, struct inject_option *opt) return ret; } +static int inject_sit(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct sit_info *sit_i = SIT_I(sbi); + struct f2fs_sit_block *sit_blk; + struct f2fs_sit_entry *sit; + unsigned int segno, offs; + bool is_set; + + if (!f2fs_is_valid_blkaddr(sbi, opt->blk, DATA_GENERIC)) { + ERR_MSG("Invalid blkaddr 0x%x (valid range [0x%x:0x%lx])\n", + opt->blk, SM_I(sbi)->main_blkaddr, + (unsigned long)le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count)); + return -EINVAL; + } + + sit_blk = calloc(F2FS_BLKSIZE, 1); + ASSERT(sit_blk); + + segno = GET_SEGNO(sbi, opt->blk); + /* change SIT version bitmap temporarily to select specified pack */ + is_set = f2fs_test_bit(segno, sit_i->sit_bitmap); + if (opt->sit == 0) { + opt->sit = is_set ? 2 : 1; + } else { + if (opt->sit == 1) + f2fs_clear_bit(segno, sit_i->sit_bitmap); + else + f2fs_set_bit(segno, sit_i->sit_bitmap); + } + get_current_sit_page(sbi, segno, sit_blk); + offs = SIT_ENTRY_OFFSET(sit_i, segno); + sit = &sit_blk->entries[offs]; + + if (!strcmp(opt->mb, "vblocks")) { + MSG(0, "Info: inject sit entry vblocks of block 0x%x " + "in pack %d: %u -> %u\n", opt->blk, opt->sit, + le16_to_cpu(sit->vblocks), (u16)opt->val); + sit->vblocks = cpu_to_le16((u16)opt->val); + } else if (!strcmp(opt->mb, "valid_map")) { + if (opt->idx == -1) { + MSG(0, "Info: auto idx = %u\n", offs); + opt->idx = offs; + } + if (opt->idx >= SIT_VBLOCK_MAP_SIZE) { + ERR_MSG("invalid idx %u of valid_map[]\n", opt->idx); + free(sit_blk); + return -ERANGE; + } + MSG(0, "Info: inject sit entry valid_map[%d] of block 0x%x " + "in pack %d: 0x%02x -> 0x%02x\n", opt->idx, opt->blk, + opt->sit, sit->valid_map[opt->idx], (u8)opt->val); + sit->valid_map[opt->idx] = (u8)opt->val; + } else if (!strcmp(opt->mb, "mtime")) { + MSG(0, "Info: inject sit entry mtime of block 0x%x " + "in pack %d: %lu -> %lu\n", opt->blk, opt->sit, + le64_to_cpu(sit->mtime), (u64)opt->val); + sit->mtime = cpu_to_le64((u64)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + free(sit_blk); + return -EINVAL; + } + print_raw_sit_entry_info(sit); + + rewrite_current_sit_page(sbi, segno, sit_blk); + /* restore SIT version bitmap */ + if (is_set) + f2fs_set_bit(segno, sit_i->sit_bitmap); + else + f2fs_clear_bit(segno, sit_i->sit_bitmap); + + free(sit_blk); + return 0; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -434,6 +562,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_cp(sbi, opt); else if (opt->nat >= 0) ret = inject_nat(sbi, opt); + else if (opt->sit >= 0) + ret = inject_sit(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index db45fb9..ece4915 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -25,9 +25,11 @@ struct inject_option { long long val; /* new value */ char *str; /* new string */ nid_t nid; + block_t blk; int sb; /* which sb */ int cp; /* which cp */ int nat; /* which nat pack */ + int sit; /* which sit pack */ }; void inject_usage(void); diff --git a/fsck/main.c b/fsck/main.c index 3ab49a4..7ec4da7 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -821,6 +821,7 @@ void f2fs_parse_options(int argc, char *argv[]) .sb = -1, .cp = -1, .nat = -1, + .sit = -1, .idx = -1, .nid = -1, }; From patchwork Mon Jun 24 13:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709575 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A070C2BD09 for ; Mon, 24 Jun 2024 14:30:58 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkif-0002FR-BI; Mon, 24 Jun 2024 14:30:57 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkie-0002FG-8W for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:30:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zOvhJIS+xFsE041MZhz+mb7CFLPWSyNsfVslzqmHHRI=; b=OQX2mt8prXO5o07uFAawcOXRB9 O74V3lip0mRSQ2Tay0Xnmnk9XFUpoPLIApbrCdUYCHaeKgv6vktkzHbl5Z3q4hcwyAcu1LtHJ5cK2 3UN4JxSdozHQ3MNBu8IgRELSIy14Z7wr08JyhJm69wgGhEwGx3BwLplSSS4a0J87gfNI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zOvhJIS+xFsE041MZhz+mb7CFLPWSyNsfVslzqmHHRI=; b=gIATj/wZWGo4VpM58+4YCSrWrd O2Dse3PdhrwOQAYg8qLOPWSUw8CqA/l7NC+nK4i08IdvC2OWOKz5EpVAfi2U0A0WjW+3PmpI17zwk fiNva2M82Bq9fkYW5Pg1e+gJUU7/tSS7LoD8yg83L6/FYA2OfSEEV+XAUQ/DilyaSgpI=; Received: from mail-sgaapc01on2076.outbound.protection.outlook.com ([40.107.215.76] helo=APC01-SG2-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkie-0004us-7z for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:30:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nsp/7sjXA9bGH50FVwYhTBCSfqdmkpNeNS5oVOokqQwiMwLamJtG+iVyQrbKpgsEhPIywGFh46++pCDY1bpYvCQwhedKc61GcJUnsUOVh2/gxHeFyQrsBUS18CJqhtF2dSMTFdvyGyY5OkTdVBeBPkn1otmbopM/s1qdEmdlE6D8C5P0nZADEd8rU7RXCbq8duEhJbQKrq8holt/LKU5wHg1U6ljJq/RG1omAitAZZH1ZKftPSEd+229mUe4qgv8v3j/phs3nKJosloBEUJ5FfzUSCnjVBohouRdzF7bN8d6ZOCR/tt+1MFVlBc6RXA0fga/5MzYd9IgJEgXczMNoA== 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=zOvhJIS+xFsE041MZhz+mb7CFLPWSyNsfVslzqmHHRI=; b=hYJ7fprbs0Mdo33EZ4sJIuCELvfntle3d8kugi2bz85g6LlW8U/WGg8gFBnv5HB8Z/6u6aRPMLczAxrduG5HAZXHHznoL260kxmyiyarUSE0jbtSp4XNOpg0dlqsfQHva6p6nKrFtWJc7H66fY1EbEjOWBQooS+Gmn9RXzc5t/qXOJ8/6BUNBUzsAkHsnnE74eojm/5luqT6v3zYGEJnjvwkDtnYDYLCGjQEQBPUUTb1SVElAipFJ66PgdKrOSs14JqScef5AKToMpi4oF9XxhWzxPGNPyypU9rQONkUyWDEZtTYy23lWDR1Ul/p+UoslgJxhc6r+sQDMqJ2/mYqmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zOvhJIS+xFsE041MZhz+mb7CFLPWSyNsfVslzqmHHRI=; b=SIc7a+eaIWqi93K3zwKLT9OMTohAeD/745BZ6AYJItRWHgIyWVMts/FPh7h49sViGKjkdTen2l2X1zlDesDk1TtQTfQkbRboT+WWKbWDgcWDXLbid1UDPHU9uxZUDv2oY87PKM1v11KzN5C0THU+Vt0lMgkB76BAcPSSFM1iKPE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:56:02 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:56:02 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:30 +0800 Message-Id: <20240624135532.3330136-8-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 62f137c6-cfd0-4a5b-6ba3-08dc94556249 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|376011|52116011|38350700011; X-Microsoft-Antispam-Message-Info: IPz49tv8POfZc3OOFdW4silJD3LrEJITBU+qlKlL4mWTk04H4zaZIjo24zYMOQ2FeWwePR6VQExWOnprWpRHCFgybrcIeMlxwOwXhXGCS4ssmaFvgbTw9R2jGy4OOP1q76zJsTLKk7sBE7Z6kBgDod9Y1nnDPzh6TB/kwKJkcEOG/II9T1ChJug//Iwm1MgYn/m9Owb3Vstaxv0O49CxNy3Dxe/jI+ERWAUoIAawfldtezYy4e0jveihLW/7hKB8fmlxz/gSeAgn98bKKRfov4/nWwuJ89l+6cnz6Uwv8eDHR+A0h16ygI9OZ5/sz1CGupZdvB9x8MgRXhAhgXmvbqUh7aWDtBufxTb36PHUCx95kpm9JzjsNd/DRyaMvkALp8M/bIFC84wua9yQYlDrG8qj5C2/KOIzGBf5jX3Eo7RmUOBUZN/ipd2065rzzd1nfF4Kw8njDzb0o++8PyFFjwIiOT3aTiP4OQQJTvb5Hzr8tTeb8sPofFTAQk2GdpzETiBm8Pg69Olr6n7aMVR0fNcGakjAHqLnrs1jqSSKdAYa3azHTWBlvkKa3xCOjPpUk1kZ0hLkMsp+OrR5tQrlqJ3NJPogLd0Rj0kPe+0sL82Ah2waeqe6+IqZvy014NV/keg/Vem+/qjzxI/HCJA9nb4ywpezmmqzyFVjP6oVT+C0UGm4RSwjtKmPKF4Qptyog5l/CHhPWrXYKwPEzGtz6L9kks5+ArXnSpcRxVi9SZhYtdXUuVMAHxjI5xNanTluSsPGiPgY0dK5O8EGZxxuFTlQTP7sYo6fY/1SMLBEZHGEJWWSQx/Ik2oPzeTdUO/6uRyq9aznlk9KrL3F/m0wnWAK5L6eFvooLOmGnoWzN4Y/g8gKDghvGfjo1NTI0MVOzgrjRhAOuBdEYYHH9OGCHMfDCQeZJMEifKaw1xSnjgoz7vXTEuPZj9X7f6BMWVArZFsho/VZqlW/Qugj1z6VCWYYQN2O+e5rmfQOyG6FZPBBk3buXZ6Z8/ujZLx/YUlb1UnErztoIxWxUmPT447Q8HrZtYpZfiUAc0kC/L2ZcOTy08RVM+KMPYeE51GAkVf1eZvf6RjRS1cGQEHg/QJvqnb4K6rUHkwKMBoBBU31G1qRhCLx97jiJfcHwZj0TQmeunArtFkc72QV64YKyF+8HOU3lcMRYOAXJrg2XqMz5hWUSxR14nJs4BtMaeV414DJDDR9kInfWtEcsrSenLMdR/YPWoANZPtiQuVj2sQZXIi2D/+vioDSHeX38A3XU3NXpw6Ge+BMmix3soGRPxr9MugNBGVx1uPXCRnL/LXXzv7sV2HPiZSzW+kZcWPKRKp5bsiOVF+wIeYMtrAzQNFAVR/ie+nXCZlQcD4kvn22uzY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NDMZlmZJpA+pZmOxb2y4qJIDhj7EZtKc8IcBBUaypP1Lx4E6+pGQ8IABGGW/+JvUdFj5JS4ADAhFu4Aaqk367v8wYWKt4MDZb7uDbv19UnOaWeyif/4lyMOE4MmveXY3SREGCA19w4dx06B+QOmvx/h35Xj61lHtHzvLn57zBsKfJMjG4/AqvrJyMXXwTR7S/i/rsGrrDAGlcFFGEqzDu1Ld9BRIiXdA/fD205rOQ0o3lg3r3m42GjnpPwJypJd6n52sNuDgRgdmMUkQV8dz6pPra2fK7XeeTF6/exNJpUkHl5PI1i10eBzMv7BGp0tMO9SHF2m1Na23vwcBOa5oVOOD6/SXLoVciNaYB/QRWrbAqNmfIE8vEID7qnHnrnjaXBr64Yn2j/dUngxH91ksawgj3qDt4cLhqk4HvDBol4sDemOC83h2lVo/b/ReArj1/fQy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GwjFybATb1v165vVaUrrO4TAB88xuCkpj3sQ19dns7tgwNw7pH+2y4aDB0IptoEGGfGEO5KAn7Lm0k9H5SzL X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62f137c6-cfd0-4a5b-6ba3-08dc94556249 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:56:02.3575 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EFsaq6hQzKCtw0KpIeCQPYDX3ojybzVFYLBOtNSJEr2lnyj4ZTbom5hVJIjqenKGZfzvy6YOYDBvEuoA9s88dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkie-0004us-7z Subject: [f2fs-dev] [RFC PATCH 07/10] inject.f2fs: add ssa injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting summary block or summary entry. print_raw_sum_entry_info() and print_sum_footer_info() are added to show values of the ssa entry and summary footer. The meanings of options are: * ssa: means ssa entry is injected. The members could be injected in cp contains: * entry_type: summary block footer entry_type * check_sum: summary block footer check_sum * nid: summary entry nid * version: summary entry version * ofs_in_node: summary entry ofs_in_node Signed-off-by: Sheng Yong --- fsck/inject.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 124 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index f854651..0f67f80 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -43,6 +43,25 @@ static void print_raw_sit_entry_info(struct f2fs_sit_entry *se) DISP_u64(se, mtime); } +static void print_raw_sum_entry_info(struct f2fs_summary *sum) +{ + if (!c.dbg_lv) + return; + + DISP_u32(sum, nid); + DISP_u8(sum, version); + DISP_u16(sum, ofs_in_node); +} + +static void print_sum_footer_info(struct summary_footer *footer) +{ + if (!c.dbg_lv) + return; + + DISP_u8(footer, entry_type); + DISP_u32(footer, check_sum); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -59,6 +78,7 @@ void inject_usage(void) MSG(0, " --cp <0|1|2> --mb [--idx ] --val inject checkpoint\n"); MSG(0, " --nat <0|1|2> --mb --nid --val inject nat entry\n"); MSG(0, " --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); + MSG(0, " --ssa --mb --blk [--idx ] --val inject summary entry\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -120,6 +140,17 @@ static void inject_sit_usage(void) MSG(0, " mtime: inject sit entry mtime\n"); } +static void inject_ssa_usage(void) +{ + MSG(0, "inject.f2fs --ssa --mb --blk [--idx ] --val inject summary entry\n"); + MSG(0, "[mb]:\n"); + MSG(0, " entry_type: inject summary block footer entry_type\n"); + MSG(0, " check_sum: inject summary block footer check_sum\n"); + MSG(0, " nid: inject summary entry nid selected by --idx blk, opt->blk); break; + case 12: + opt->ssa = true; + MSG(0, "Info: inject ssa\n"); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -227,6 +263,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->sit >= 0) { inject_sit_usage(); exit(0); + } else if (opt->ssa) { + inject_ssa_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -551,6 +590,88 @@ static int inject_sit(struct f2fs_sb_info *sbi, struct inject_option *opt) return 0; } +static int inject_ssa(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct f2fs_summary_block *sum_blk; + struct summary_footer *footer; + struct f2fs_summary *sum; + u32 segno, offset; + block_t ssa_blkaddr; + int type; + int ret; + + if (!f2fs_is_valid_blkaddr(sbi, opt->blk, DATA_GENERIC)) { + ERR_MSG("Invalid blkaddr %#x (valid range [%#x:%#lx])\n", + opt->blk, SM_I(sbi)->main_blkaddr, + (unsigned long)le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count)); + return -ERANGE; + } + + segno = GET_SEGNO(sbi, opt->blk); + offset = OFFSET_IN_SEG(sbi, opt->blk); + + sum_blk = get_sum_block(sbi, segno, &type); + sum = &sum_blk->entries[offset]; + footer = F2FS_SUMMARY_BLOCK_FOOTER(sum_blk); + + if (!strcmp(opt->mb, "entry_type")) { + MSG(0, "Info: inject summary block footer entry_type of " + "block 0x%x: %d -> %d\n", opt->blk, footer->entry_type, + (unsigned char)opt->val); + footer->entry_type = (unsigned char)opt->val; + } else if (!strcmp(opt->mb, "check_sum")) { + MSG(0, "Info: inject summary block footer check_sum of " + "block 0x%x: 0x%x -> 0x%x\n", opt->blk, + le32_to_cpu(footer->check_sum), (u32)opt->val); + footer->check_sum = cpu_to_le32((u32)opt->val); + } else { + if (opt->idx == -1) { + MSG(0, "Info: auto idx = %u\n", offset); + opt->idx = offset; + } + if (opt->idx >= ENTRIES_IN_SUM) { + ERR_MSG("invalid idx %u of entries[]\n", opt->idx); + ret = -EINVAL; + goto out; + } + sum = &sum_blk->entries[opt->idx]; + if (!strcmp(opt->mb, "nid")) { + MSG(0, "Info: inject summary entry nid of " + "block 0x%x: 0x%x -> 0x%x\n", opt->blk, + le32_to_cpu(sum->nid), (u32)opt->val); + sum->nid = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "version")) { + MSG(0, "Info: inject summary entry version of " + "block 0x%x: %d -> %d\n", opt->blk, + sum->version, (u8)opt->val); + sum->version = (u8)opt->val; + } else if (!strcmp(opt->mb, "ofs_in_node")) { + MSG(0, "Info: inject summary entry ofs_in_node of " + "block 0x%x: %d -> %d\n", opt->blk, + sum->ofs_in_node, (u16)opt->val); + sum->ofs_in_node = cpu_to_le16((u16)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + ret = -EINVAL; + goto out; + } + + print_raw_sum_entry_info(sum); + } + + print_sum_footer_info(footer); + + ssa_blkaddr = GET_SUM_BLKADDR(sbi, segno); + ret = dev_write_block(sum_blk, ssa_blkaddr); + ASSERT(ret >= 0); + +out: + if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA || + type == SEG_TYPE_MAX) + free(sum_blk); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -564,6 +685,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_nat(sbi, opt); else if (opt->sit >= 0) ret = inject_sit(sbi, opt); + else if (opt->ssa) + ret = inject_ssa(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index ece4915..c828f3f 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -30,6 +30,7 @@ struct inject_option { int cp; /* which cp */ int nat; /* which nat pack */ int sit; /* which sit pack */ + bool ssa; }; void inject_usage(void); From patchwork Mon Jun 24 13:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709542 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 604E6C2BD09 for ; Mon, 24 Jun 2024 13:56:20 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkB9-00028E-Mb; Mon, 24 Jun 2024 13:56:20 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkB8-000283-RP for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wkuJD25xSiCNTgTv3BS6OHvzgd1UyabDSlTEuLqjYP8=; b=QViom5a9nyeLo4mp8hkkFgIymE BZW5sYSnNNenUiodUcBIK9+zJJYEalQ7OHSbesVLPYUYr8sQL4yUpE90LNfCko8SWXoz4rlgAQc/9 piiTqWawLxGoz53RMC/pNAWHAAyvMteaZhRnsz6bBFg6Vv26hzMB/woHnUeIEtlVGGoA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wkuJD25xSiCNTgTv3BS6OHvzgd1UyabDSlTEuLqjYP8=; b=gwnqfhvWtOMCbFWtL5iNs2XVFD qQ/jb3ts5ItTo7X/v3sY7y9xXZ4y5aLPA07j6SZdmY7LeqMJ5mUYZaMG3ka9aEqEUP4O1f11eNswi 3NE015jOI1wDGoOc6DAmAprZAbW3NCpa8f3kq2IVvFIsCygYDrqkfP9AporkgT11inS4=; Received: from mail-sgaapc01on2056.outbound.protection.outlook.com ([40.107.215.56] helo=APC01-SG2-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkB8-0001AS-BB for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 13:56:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PaCjxMhBXv7IwLN+qvHDAOd7TB32dWZOnTw4NeGY8ObrrenwjnBdzTlCre0pNabGKw6weHnSaqmukBEBsVWF7yhPUhJCb72j5J5jBp8Ulwno93moqIX3Q1ysv614EBabczpKJvOlJKxCcrJPhLQk/mzg4DP15SMZCcvO94+iyVtRB4/KBCz5XEFOaR7Q+AHgZFQ2fdEVOJRlId9V/As59FUI6r//x1N/apOsv27+EU+t6p0hc3KCpZi7XfPkzCWzg06LpoIuQd4VfqC3wYYKthqb+IQsme3DyflTMwds6fFumEI43ux+/BuaJAGKomlOcXXfDoEB0S7qdAZAarTWvA== 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=wkuJD25xSiCNTgTv3BS6OHvzgd1UyabDSlTEuLqjYP8=; b=hjz38vUgyEaJ4SilBHMaPkRePR/lVEjRRYTiQlle4G1AbTSZlMFe5V1lnw466jMdm03raH3sRi7zs17+vFq5wXhLFfVBLWN9dDUro9XQsLVSjNy1jbrcdxHpoOJHfbk4vcGRuh8LQm6pxhyZ6dpDrvaZV5FNtdftLXPdOXXjuFDQvwOOIVvrTi8sCKK4Ta18slA0+V+nahR9yXOXhaJHfELfTnXIUEW4WE54EjfTojNIPiu+nxPkmkECenPTQGGAwVZwx9OO9Q0vPcmgF+wvOT2P/nqQnhTbNv24Qr6aFD0GYZ8qO9nBlm90FztR7tYhmtrqCM6uGxYOxzdMOMvqXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wkuJD25xSiCNTgTv3BS6OHvzgd1UyabDSlTEuLqjYP8=; b=c5uURhg8bVe6MFQlzyXz0qlBtHJXbRLAdOo+Nc8V9VRPZSqrdMGwiw7wSNVCQgUsQEjMCdePhLOGX0eXB+ED/+BOk5WZn+nvyLZ7mDpOeFJs9aRzJYs+UALd4o+mnOJLgEhVtIs4pevbq0vnbBL/U+o4IV32V7ycm4A9JyI44vQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SI2PR02MB6004.apcprd02.prod.outlook.com (2603:1096:4:1eb::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.34; Mon, 24 Jun 2024 13:56:03 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:56:03 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:31 +0800 Message-Id: <20240624135532.3330136-9-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SI2PR02MB6004:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b61b9ee-2528-4753-393d-08dc9455631d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|376011|52116011|1800799021|366013|38350700011; X-Microsoft-Antispam-Message-Info: 0HL1l1STOzzQgf9qbtpNDEM+qWia39hRtI3bz/r2SX44UZMXonnVk3wjaFZNQ3iZlhv/s1OrHX/axwp6mZcZDI3VTd+iUUKtAlhct0adHVXmknnhx+D350GhW2SvgNcYgzm+Is5KzmviQn3bQfXy3FAG/e5cH+4CVVe8IQGHTlhJF2+P6UtbOlROuZIyH40ELx5/5kxEHJDN/98a6FDGNKSD1lruoheAmLluOaaoVLBiYzLPZAxq0sfIc+Zlmu9skwPYO0fpJkXaioac3MbUptNjOZIEgFf2YKX7oCjOvRQN0FeFUWOrr0EDaFpWJ8g5ktVt6wdD/KQH+o0ucmpW/edu5UMmm4ASGZFjI4ybE+epCxxIpdNaYH9IkBOPGF/ny2PgqADfYA9GkKD9fvxN8TG6sjmMK3cEVhk7WsCw2fQB3DlNXvW+ZGKNT/67vsdIaO1zcatlugIdoQPPYFUgrir+mflyeToHWufJm2D9Q9TOhWt7kuX4dnnc+wRUYE4bSEe4RrWbr2EhyWx2WAu+xWNVMeH4YyaXUCyePanKeJrC+cmg5a6QXhNSUF0k43+5AWdW9z/qfOQH+1QSz4P6yDzvGyXo9hVOn4qMWf/ts+ls0EY1GJXtSJbgLoZSfHgzKMZXN14HsTgMekLpo5AkzYb8Zg6v1G48V9NNNfRCQP8Ix8lxc7U89cvpirV8GLo1TMRLINsxUBJLzXn2uQaFcrYjt507IC/Y1w/lZ/F3y1v5qdQwRbZoy7S2NBMhsbpw/SDXw7gufjXyUWy/BKr/sKE1tKDQ3diRSz+Hff29cdmMK1wo1Xrd1koVrTnXXFZoL1pui4WnMk6uMcPjBdewJWO/vP5EiLD8Zj0+B1KYHYw2fnrxmekoe78C51Lt5rP3vGKO2wFZUJzNyV8gZIg8xlx/xHT7wNZsEpKlCco4liY7Oep5R/JEvu/8ABZefENsUbmexqFdFnlWKMHwxIj5vAcFzP5bgIv4nplDk94WNqxcK1n4Rc722Ze3CBtG4AO4twIPNlwBC0XSV789rnETm4AZk2LDQwq4E+jTFwnJ/JPlJfT+CAgnqtENWnCFL/kZasyiv4JJOFDej6U/ZtbdCuwWRSZ/jeG7jTGnYggffAX50zXFBGg4t8Zf5JoIPTwEWCNoIEfenozVQpnjKuhQASMnycSfJ4X6HI7LDWQy7i9IPSxQfW/8CXoRnkCGw/wTV1e9U2psxZXZPo19OtVGb0xx8pfPtf4rbSbXLa2gkQsLbC99Kc/Z8K10d0vXHI08czv5KPdPbP3a5SpiHlg9cVK3dPPRK3Qs8HuMsD3Y+yjbo5yLOLXXJAFpJQTdisjSHRLW30N1k7iiiX9orHyl7I0I7Plwav44WO6dPNkaul4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(376011)(52116011)(1800799021)(366013)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WcwQWBNsk5Atg0jMvsS0VmNPNSw1iJb2NTNGeSHDkPiPj2qI5CYxhkhtNxmHALnvwra42N6MvUewOM5cV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NNqmiaaskEbEiqZ1rf4hdT584bhlbol5iwmvb+LrWwV9Pj6Pf4/VV24FLFQkjc5nfL7uQMDYoIoR/WCjRzW2YJ4NA/X1TATotXNgusxnBz1yDlunD02L/O3+Te4LbN68y8S1tst5GRYkHgm0W8Eotz92wmnmjNIo9GPGaNqUmx8B2uG90heGBoJN01YnRZhJORY/Xbkyvhidx/Jxxbj+Jox/HfnOBw4Ro5qVcji0W1d3Kt+K5+UVd8YXds/COgguwJVqfbWCqbt8zZgQQ8A4yjl/ehbskyRIHI+AsdNIfo6AIAVUeomKYrSswQA/SyO2Gy4j2qhKvVw0bROiyFkelwT62EddiF/69NyzJHPLaemZEjI4eiRrxTS2IuswhgfleiSUd0DFtTIBZyCuHf0xuvCEpFER3xRp31faLzC1e+wYzaezg5uTz40eQ0a X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b61b9ee-2528-4753-393d-08dc9455631d X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:56:03.6663 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3D/WsTWZocFhzTHY9RtOpOPPt7wsMHLLvaFHzuaH8dkYl9/yVXHJtUJTPNJw1H+ImRnRgcdgQ8ljmdjrP5611A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR02MB6004 X-Headers-End: 1sLkB8-0001AS-BB Subject: [f2fs-dev] [RFC PATCH 08/10] inject.f2fs: add node injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting node block. print_node_footer_info() is added to show values of node footer. The meanings of options are: * node: means node is injected. The members could be injected in cp contains: * nid: node footer nid * ino: node footer ino * flag: node footer flag * cp_ver: node footer cp_ver * next_blkaddr: node footer next_blkaddr * i_mode: inode i_mode * i_advise: inode i_advise * i_inline: inode i_inline * i_links: inode i_links * i_size: inode i_size * i_blocks: inode i_blocks * i_extra_isize: inode i_extra_isize * i_inode_checksum: inode i_inode_checksum * i_addr: inode i_addr array * i_nid: inode i_nid array * addr: {in}direct node nid/addr array Signed-off-by: Sheng Yong --- fsck/inject.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 210 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index 0f67f80..20ae87c 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -62,6 +62,18 @@ static void print_sum_footer_info(struct summary_footer *footer) DISP_u32(footer, check_sum); } +static void print_node_footer_info(struct node_footer *footer) +{ + if (!c.dbg_lv) + return; + + DISP_u32(footer, nid); + DISP_u32(footer, ino); + DISP_u32(footer, flag); + DISP_u64(footer, cp_ver); + DISP_u32(footer, next_blkaddr); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -79,6 +91,7 @@ void inject_usage(void) MSG(0, " --nat <0|1|2> --mb --nid --val inject nat entry\n"); MSG(0, " --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); MSG(0, " --ssa --mb --blk [--idx ] --val inject summary entry\n"); + MSG(0, " --node --mb --nid [--idx ] --val inject node\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -151,6 +164,28 @@ static void inject_ssa_usage(void) MSG(0, " ofs_in_node: inject summary entry ofs_in_node selected by --idx --nid [--idx ] --val inject node\n"); + MSG(0, "[mb]:\n"); + MSG(0, " nid: inject node footer nid\n"); + MSG(0, " ino: inject node footer ino\n"); + MSG(0, " flag: inject node footer flag\n"); + MSG(0, " cp_ver: inject node footer cp_ver\n"); + MSG(0, " next_blkaddr: inject node footer next_blkaddr\n"); + MSG(0, " i_mode: inject inode i_mode\n"); + MSG(0, " i_advise: inject inode i_advise\n"); + MSG(0, " i_inline: inject inode i_inline\n"); + MSG(0, " i_links: inject inode i_links\n"); + MSG(0, " i_size: inject inode i_size\n"); + MSG(0, " i_blocks: inject inode i_blocks\n"); + MSG(0, " i_extra_isize: inject inode i_extra_isize\n"); + MSG(0, " i_inode_checksum: inject inode i_inode_checksum\n"); + MSG(0, " i_addr: inject inode i_addr array selected by --idx \n"); + MSG(0, " i_nid: inject inode i_nid array selected by --idx \n"); + MSG(0, " addr: inject {in}direct node nid/addr array selected by --idx \n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -169,6 +204,7 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"sit", required_argument, 0, 10}, {"blk", required_argument, 0, 11}, {"ssa", no_argument, 0, 12}, + {"node", no_argument, 0, 13}, {0, 0, 0, 0} }; @@ -240,6 +276,10 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) opt->ssa = true; MSG(0, "Info: inject ssa\n"); break; + case 13: + opt->node = true; + MSG(0, "Info: inject node\n"); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -266,6 +306,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->ssa) { inject_ssa_usage(); exit(0); + } else if (opt->node) { + inject_node_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -672,6 +715,170 @@ out: return ret; } +static int inject_inode(struct f2fs_sb_info *sbi, struct f2fs_node *node, + struct inject_option *opt) +{ + struct f2fs_inode *inode = &node->i; + + if (!strcmp(opt->mb, "i_mode")) { + MSG(0, "Info: inject inode i_mode of nid %u: 0x%x -> 0x%x\n", + opt->nid, le16_to_cpu(inode->i_mode), (u16)opt->val); + inode->i_mode = cpu_to_le16((u16)opt->val); + } else if (!strcmp(opt->mb, "i_advise")) { + MSG(0, "Info: inject inode i_advise of nid %u: 0x%x -> 0x%x\n", + opt->nid, inode->i_advise, (u8)opt->val); + inode->i_advise = (u8)opt->val; + } else if (!strcmp(opt->mb, "i_inline")) { + MSG(0, "Info: inject inode i_inline of nid %u: 0x%x -> 0x%x\n", + opt->nid, inode->i_inline, (u8)opt->val); + inode->i_inline = (u8)opt->val; + } else if (!strcmp(opt->mb, "i_links")) { + MSG(0, "Info: inject inode i_links of nid %u: %u -> %u\n", + opt->nid, le32_to_cpu(inode->i_links), (u32)opt->val); + inode->i_links = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "i_size")) { + MSG(0, "Info: inject inode i_size of nid %u: %lu -> %lu\n", + opt->nid, le64_to_cpu(inode->i_size), (u64)opt->val); + inode->i_size = cpu_to_le64((u64)opt->val); + } else if (!strcmp(opt->mb, "i_blocks")) { + MSG(0, "Info: inject inode i_blocks of nid %u: %lu -> %lu\n", + opt->nid, le64_to_cpu(inode->i_blocks), (u64)opt->val); + inode->i_blocks = cpu_to_le64((u64)opt->val); + } else if (!strcmp(opt->mb, "i_extra_isize")) { + /* do not care if F2FS_EXTRA_ATTR is enabled */ + MSG(0, "Info: inject inode i_extra_isize of nid %u: %d -> %d\n", + opt->nid, le16_to_cpu(inode->i_extra_isize), (u16)opt->val); + inode->i_extra_isize = cpu_to_le16((u16)opt->val); + } else if (!strcmp(opt->mb, "i_inode_checksum")) { + MSG(0, "Info: inject inode i_inode_checksum of nid %u: " + "0x%x -> 0x%x\n", opt->nid, + le32_to_cpu(inode->i_inode_checksum), (u32)opt->val); + inode->i_inode_checksum = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "i_addr")) { + /* do not care if it is inline data */ + if (opt->idx >= DEF_ADDRS_PER_INODE) { + ERR_MSG("invalid index %u of i_addr[]\n", opt->idx); + return -EINVAL; + } + MSG(0, "Info: inject inode i_addr[%d] of nid %u: " + "0x%x -> 0x%x\n", opt->idx, opt->nid, + le32_to_cpu(inode->i_addr[opt->idx]), (u32)opt->val); + inode->i_addr[opt->idx] = cpu_to_le32((block_t)opt->val); + } else if (!strcmp(opt->mb, "i_nid")) { + if (opt->idx >= 5) { + ERR_MSG("invalid index %u of i_nid[]\n", opt->idx); + return -EINVAL; + } + MSG(0, "Info: inject inode i_nid[%d] of nid %u: " + "0x%x -> 0x%x\n", opt->idx, opt->nid, + le32_to_cpu(F2FS_INODE_I_NID(inode, opt->idx)), + (u32)opt->val); + F2FS_INODE_I_NID(inode, opt->idx) = cpu_to_le32((nid_t)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + return -EINVAL; + } + + if (c.dbg_lv > 0) + print_node_info(sbi, node, 1); + + return 0; +} + +static int inject_index_node(struct f2fs_sb_info *sbi, struct f2fs_node *node, + struct inject_option *opt) +{ + struct direct_node *dn = &node->dn; + + if (strcmp(opt->mb, "addr")) { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + return -EINVAL; + } + + if (opt->idx >= DEF_ADDRS_PER_BLOCK) { + ERR_MSG("invalid index %u of nid/addr[]\n", opt->idx); + return -EINVAL; + } + + MSG(0, "Info: inject node nid/addr[%d] of nid %u: 0x%x -> 0x%x\n", + opt->idx, opt->nid, le32_to_cpu(dn->addr[opt->idx]), + (block_t)opt->val); + dn->addr[opt->idx] = cpu_to_le32((block_t)opt->val); + + if (c.dbg_lv > 0) + print_node_info(sbi, node, 1); + + return 0; +} + +static int inject_node(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct f2fs_super_block *sb = sbi->raw_super; + struct node_info ni; + struct f2fs_node *node_blk; + struct node_footer *footer; + int ret; + + if (!IS_VALID_NID(sbi, opt->nid)) { + ERR_MSG("Invalid nid %u range [%u:%lu]\n", opt->nid, 0, + NAT_ENTRY_PER_BLOCK * + ((get_sb(segment_count_nat) << 1) << + sbi->log_blocks_per_seg)); + return -EINVAL; + } + + node_blk = calloc(F2FS_BLKSIZE, 1); + ASSERT(node_blk); + + get_node_info(sbi, opt->nid, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + footer = F2FS_NODE_FOOTER(node_blk); + + if (!strcmp(opt->mb, "nid")) { + MSG(0, "Info: inject node footer nid of nid %u: %u -> %u\n", + opt->nid, le32_to_cpu(footer->nid), (u32)opt->val); + footer->nid = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "ino")) { + MSG(0, "Info: inject node footer ino of nid %u: %u -> %u\n", + opt->nid, le32_to_cpu(footer->ino), (u32)opt->val); + footer->ino = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "flag")) { + MSG(0, "Info: inject node footer flag of nid %u: " + "0x%x -> 0x%x\n", opt->nid, le32_to_cpu(footer->flag), + (u32)opt->val); + footer->flag = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "cp_ver")) { + MSG(0, "Info: inject node footer cp_ver of nid %u: " + "0x%lx -> 0x%lx\n", opt->nid, le64_to_cpu(footer->cp_ver), + (u64)opt->val); + footer->cp_ver = cpu_to_le64((u64)opt->val); + } else if (!strcmp(opt->mb, "next_blkaddr")) { + MSG(0, "Info: inject node footer next_blkaddr of nid %u: " + "0x%x -> 0x%x\n", opt->nid, + le32_to_cpu(footer->next_blkaddr), (u32)opt->val); + footer->next_blkaddr = cpu_to_le32((u32)opt->val); + } else if (ni.nid == ni.ino) { + ret = inject_inode(sbi, node_blk, opt); + } else { + ret = inject_index_node(sbi, node_blk, opt); + } + if (ret) + goto out; + + print_node_footer_info(footer); + + if (ni.nid == ni.ino) + ret = update_inode(sbi, node_blk, &ni.blk_addr); + else + ret = update_block(sbi, node_blk, &ni.blk_addr, NULL); + ASSERT(ret >= 0); + +out: + free(node_blk); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -687,6 +894,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_sit(sbi, opt); else if (opt->ssa) ret = inject_ssa(sbi, opt); + else if (opt->node) + ret = inject_node(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index c828f3f..9b14c31 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -31,6 +31,7 @@ struct inject_option { int nat; /* which nat pack */ int sit; /* which sit pack */ bool ssa; + bool node; }; void inject_usage(void); From patchwork Mon Jun 24 13:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709573 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B662DC2D0D1 for ; Mon, 24 Jun 2024 14:28:41 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkgT-0008T2-6C; Mon, 24 Jun 2024 14:28:40 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkgO-0008Su-Fu for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:28:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=OlSocSyEzPzcyw8ZE82LyfwgjU u1cpRRO9F3er7WSDu3skc2O1ScQVL0ICnZi1axluqdLmKoesfzOoU6UtuUWQh+Db9t1XgnOwns6d5 bO/5AP1jnj/mtOq7FE0TCrvnjElJtP+NrElAgv8vhWTE6VUW3ZTnSOogdlPm2TtigJfY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=fo7xwrYsr5o8F5Nkq3jRVTDoqm 3qjET72cPtABFfOzNb44XkO+kL7jpI6HCmHdkNaz4bbgG8EFmAenCg1jx8V+k2IVZAdDVu0pjrlVG b29X7c1+hdM7oNkSKfrAMeEzy/rMc1jbyyxg4Dzdmobe74L44atvS6bdNdkdDj+7YHwA=; Received: from mail-psaapc01on2078.outbound.protection.outlook.com ([40.107.255.78] helo=APC01-PSA-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkgN-0004fL-Bf for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:28:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NMfXUDlK8RrqnzHqCUx4gxUdEhcsar5HSggFkqt6O3aXaMCdLKuxE9nYh52ZHBaDqGNXOK0dZJWW5JlsZjnn/poJjYeXcJ/MBPf2fm55FJCGQJ2T4f8GNuwIAHY/Ev2QAtmAWihg7eS/Aki5s0dbfQ1wKqjfQceLyqzT4zDL82/95FzzC/2RyQeg3DhXg4BccAnOyjqJWJvtqIXlyWiuBopYGi5SFiRZuqf9wiB87V1PQ8hMXFBy1PwIhAJJzg/wAOXVsDrOmLZkf4LP2FIGh4oaAKtcVHEU4Pywni9q7oGmXH9YWERYrICeOanJEdvZ8VJaOJaFbul02CCnLYn07Q== 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=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=CoF+2sjr1bSTQU/mSeHB3lDpifR3bbNLB9gL0f9AqqWVvlgNy0iXFzi2Drtvn2SkPY3Ayg8+MCbgmcwADrRWhUu3shLWYfFSzkR3XEIcFDMzg/KfkXE1mplyPK0aFwLDubD9v43adgRJwAviZH6C2NSPees0levIvUv3mVt6XIy0q2grtVbBGxohtFnSac+V0mxAP7leXSaTZGYLCcEG4e5qXWdDICpTEwhAEBF8dY0CQcDDKg83zuVdunJzO4z9I8JN/s3HPQ2F9/zBOI9YLi5re6+Xnaq+GEdowuRGozYMHuFK32LTCX1A5WLfsWiOSxz3qAx5MUnEj5Dc9KL0/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=jHywBCnBiqrz1c+aapGJUa6jfX5cy+QEk9hxaTyFFs86ZxFLGw6fGEDL3SrVbnyA9DNYo55J/K4C0JdHGOxTZ+Ls0aq9Wg7ea/CTXYkwPXVMG9UWLK4Amemk+j6rh4bx2g9+TXNFkcmZYKA3eCDAIRbi6BKPLSPdOcjjtvplaRg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:56:04 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:56:04 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:32 +0800 Message-Id: <20240624135532.3330136-10-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 7069de40-4faa-4ad7-c3b6-08dc945563cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA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bUX2OeP7zsPivt7fyzlyi0m48eNuQAd5dDzMxm3qqBcZbfP/na7dvicfVAZ5A8BDF4ujCKL+YYI9Q/HxdhAcrlKHQ55iPmTo1RUqRDuYY2NobQ3GB8kYPAnkyMkX3YtjokM4PifEbGy/g+HFl3AfMvkLn9J6qWUhb1X7elHZB2FrjO6HsgqmMOOKF74Mp4X4aa3y6xA3VsxRq0isHA2EFkwk6Ncj3tbEnXtiPUxjUvvgNQfyym4MRp/iHo+kyCMlBIsBTZKOsvTfiEXNcQQxtbNwtucCAlwochv8CNTVv5jiBDPOdSlAMwLokGF9SnBFBsETAQlkVZUpv9eyX8fUGAgrquXb8FNaLidGjD64xTw+c= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eZviv5sY6+HnyMpOQ+fV7APlNZ0eQT4JWKIu0j/NLw5ctRUXgbhXr4ln5x8qN3G2Cnut5aN3ftwlnijKsiuRGjmrnfyNcn2aJWZ4N10U4FnIIcHNJrPNNVDZ259ZU/exmVBrKHwo3GmNgPVLMPnaV2ArNicPwaedgVhZ0N2knlcbvYyjgFZUYb2Nk3fAhwT/njnLdaOJhig/r69HEuc8T9d2NC9nHEcHQbo27XabTVXz93r2YcxRMENNa/HCnx/vz7WG2S+ZPTh6lGn8ivCL6NZmrBgmTM2naCxcnj/DgUMqDMdHSPf+A9pFRHCjEpmnpZbu5XrdZLbMyuI6rORxMK/P/gaCQxKdNP+KwOk/DylUC5pHoLpDwnHmkSk7uctlmM2RjwXWesDhSvtvnrqoHXBcgNX/dnITx2Z4FVG9sNLuJh3pS78dFlgo39E/yx6DEhgAbEtNnqWloJt6Z/wciFTeP0vv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XzWKXUMU06UXfJZSTlzoPfzLrnyuMLErX8Y X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7069de40-4faa-4ad7-c3b6-08dc945563cd X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:56:04.8915 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 96uq2pMVvyy40T4cnnOrVVrw99yfirSn+lb6ffUk2P/NzkR4rgz/awiuW2+ZxuEkFRwGVexniENV/uuLEVu5zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkgN-0004fL-Bf Subject: [f2fs-dev] [RFC PATCH 09/10] inject.f2fs: add dentry injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting dentry block or dir entry. print_raw_dentry_info() is added to show values of node footer. The meanings of options are: * dent: means dentry is injected. The members could be injected in cp contains: * d_bitmap: dentry block d_bitmap of nid * d_hash: dentry hash * d_ino: dentry ino * d_ftype: dentry ftype Signed-off-by: Sheng Yong --- fsck/inject.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 149 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index 20ae87c..3d26b25 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -74,6 +74,17 @@ static void print_node_footer_info(struct node_footer *footer) DISP_u32(footer, next_blkaddr); } +static void print_raw_dentry_info(struct f2fs_dir_entry *dentry) +{ + if (!c.dbg_lv) + return; + + DISP_u32(dentry, hash_code); + DISP_u32(dentry, ino); + DISP_u16(dentry, name_len); + DISP_u8(dentry, file_type); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -92,6 +103,7 @@ void inject_usage(void) MSG(0, " --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); MSG(0, " --ssa --mb --blk [--idx ] --val inject summary entry\n"); MSG(0, " --node --mb --nid [--idx ] --val inject node\n"); + MSG(0, " --dent --mb --nid [--idx ] --val inject ino's dentry\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -186,6 +198,16 @@ static void inject_node_usage(void) MSG(0, " addr: inject {in}direct node nid/addr array selected by --idx \n"); } +static void inject_dent_usage(void) +{ + MSG(0, "inject.f2fs --dent --mb --nid [--idx ] --val inject dentry\n"); + MSG(0, "[mb]:\n"); + MSG(0, " d_bitmap: inject dentry block d_bitmap of nid\n"); + MSG(0, " d_hash: inject dentry hash\n"); + MSG(0, " d_ino: inject dentry ino\n"); + MSG(0, " d_ftype: inject dentry ftype\n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -205,6 +227,7 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"blk", required_argument, 0, 11}, {"ssa", no_argument, 0, 12}, {"node", no_argument, 0, 13}, + {"dent", no_argument, 0, 14}, {0, 0, 0, 0} }; @@ -280,6 +303,10 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) opt->node = true; MSG(0, "Info: inject node\n"); break; + case 14: + opt->dent = true; + MSG(0, "Info: inject dentry\n"); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -309,6 +336,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->node) { inject_node_usage(); exit(0); + } else if (opt->dent) { + inject_dent_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -879,6 +909,122 @@ out: return ret; } +static int inject_dentry(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct node_info ni; + struct f2fs_node *node_blk = NULL; + struct f2fs_inode *inode; + struct f2fs_dentry_ptr d; + void *inline_dentry; + struct f2fs_dentry_block *dent_blk = NULL; + block_t addr = 0; + void *buf = NULL; + int ofs; + int i, slot; + struct f2fs_dir_entry *dent = NULL; + nid_t pino; + int ret; + + node_blk = malloc(F2FS_BLKSIZE); + ASSERT(node_blk != NULL); + + /* child */ + get_node_info(sbi, opt->nid, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + inode = &node_blk->i; + pino = le32_to_cpu(inode->i_pino); + + /* parent */ + get_node_info(sbi, pino, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + inode = &node_blk->i; + + /* locate dentry */ + ofs = get_extra_isize(node_blk); + if (inode->i_inline & F2FS_INLINE_DENTRY) { + inline_dentry = inline_data_addr(node_blk); + make_dentry_ptr(&d, node_blk, inline_dentry, 2); + addr = ni.blk_addr; + buf = node_blk; + + for (slot = 0; slot < d.max; slot++) { + dent = &d.dentry[slot]; + if (dent->ino == opt->nid && dent->hash_code != 0) + break; + dent = NULL; + } + } else { + dent_blk = malloc(F2FS_BLKSIZE); + ASSERT(dent_blk != NULL); + + for (i = ofs; i < DEF_ADDRS_PER_INODE; i++) { + addr = le32_to_cpu(inode->i_addr[i]); + if (addr == NULL_ADDR || addr == COMPRESS_ADDR || addr == NEW_ADDR) + continue; + + ret = dev_read_block(dent_blk, addr); + ASSERT(ret >= 0); + + make_dentry_ptr(&d, node_blk, dent_blk, 1); + buf = dent_blk; + for (slot = 0; slot < d.max; slot++) { + dent = &d.dentry[slot]; + if (dent->ino == opt->nid && dent->hash_code != 0) + break; + dent = NULL; + } + if (dent != NULL) + break; + } + } + + if (dent == NULL) { + ERR_MSG("dentry of ino %u not found\n", opt->nid); + ret = -ENOENT; + goto out; + } + + if (!strcmp(opt->mb, "d_bitmap")) { + MSG(0, "Info: inject dentry bitmap of nid %u: 1 -> 0\n", + opt->nid); + test_and_clear_bit_le(slot, d.bitmap); + } else if (!strcmp(opt->mb, "d_hash")) { + MSG(0, "Info: inject dentry d_hash of nid %u: " + "0x%x -> 0x%x\n", opt->nid, le32_to_cpu(dent->hash_code), + (u32)opt->val); + dent->hash_code = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "d_ino")) { + MSG(0, "Info: inject dentry d_ino of nid %u: " + "%u -> %u\n", opt->nid, le32_to_cpu(dent->ino), + (nid_t)opt->val); + dent->ino = cpu_to_le32((nid_t)opt->val); + } else if (!strcmp(opt->mb, "d_ftype")) { + MSG(0, "Info: inject dentry d_type of nid %u: " + "%d -> %d\n", opt->nid, dent->file_type, + (u8)opt->val); + dent->file_type = (u8)opt->val; + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + ret = -EINVAL; + goto out; + } + + print_raw_dentry_info(dent); + + if (inode->i_inline & F2FS_INLINE_DENTRY) + ret = update_inode(sbi, buf, &addr); + else + ret = update_block(sbi, buf, &addr, NULL); + ASSERT(ret >= 0); + +out: + free(node_blk); + free(dent_blk); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -896,6 +1042,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_ssa(sbi, opt); else if (opt->node) ret = inject_node(sbi, opt); + else if (opt->dent) + ret = inject_dentry(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index 9b14c31..43c21b5 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -32,6 +32,7 @@ struct inject_option { int sit; /* which sit pack */ bool ssa; bool node; + bool dent; }; void inject_usage(void); From patchwork Mon Jun 24 13:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709579 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8452EC2D0D1 for ; Mon, 24 Jun 2024 14:31:47 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkjT-00009F-CI; Mon, 24 Jun 2024 14:31:46 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkjR-000094-KY for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:31:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Dq3dmc001amoNkyNORSo8UT5tprSJxmwuGIVCtG2oHk=; b=Y+rJ/LIXdSDvmfypStF6t1ELjw msEhAWhJ0EFS55iCKbKLss0UrVs082oVEg2AtPnT2ScnRgWHyTaKDD6A0Wdbo/YpahhOWx/fqSKgw 33jgonqKfmmVX7fw7Fvfp7SEzU7+e9+4X4+bYomSWZoITrPADQSgH1hWffPL7bTDBTZU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Dq3dmc001amoNkyNORSo8UT5tprSJxmwuGIVCtG2oHk=; b=D11dR22uaLKZPYP4HWJhHqcLOB 9qkBd3yTGKCf+1O3YNyliAVVPK+ReHojn45d4jVzzPHCopXcbnP5hdBtZRPFCySFuRymz4LS83Rsx kqdEZUtaJ74txaNebT9FTnX0pJcp9EzzIgYV0LzeqhmQ1f6PI+ZiFDtMTGogspE76eCY=; Received: from mail-tyzapc01on2074.outbound.protection.outlook.com ([40.107.117.74] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkjQ-00050N-Uf for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:31:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ke/LBckTWqVPxmDLdmchdn8aM0hFOS5dFYzyRLe57sTznPSFOJQq8lLH1cnRySgVtW+VKmmckEJnqqv69I0ZFTHZtuQ2kEyOfCtv0oy3IVIDLeV4wUJsIvEFvg9Nt02FsutCz+6qbHLxpoM0zZGVQ5JetcnWW27OfZoAYpec0p6YueV7N1MiN8+hEwyQsfqd72vDTEZbhnIYtrAZPWNxnlcaF/njEM0VSxv0SpjHwpNiDNsWOicG+6RRHyzkPgVOZYQzA8WLOv6r8Wx39dpCCAcjNwtzBrDOJEm43pe0XsmHB6QVCoj+GlsKpyNyVu6q5f7jYbIh/SKYKXPwwMDStw== 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=Dq3dmc001amoNkyNORSo8UT5tprSJxmwuGIVCtG2oHk=; b=V3MLWGa7jVVrcv8V09iqnlyhiV6Y5GaNPixH+qFfMjfHJ6WPAzXSpR1gs/YymsNGchCurJT03Er5MUW/HRqh/PkNYzBy3LoC7MIToAsNoBCJL3G2+RJwgGpbN92AYAdjP2ZJu8ByPKscR1D8W3cvXtorU3SWIbGjYEtZLp1WopZ5I4is3s4qXxmamqRPtctBC4RHfMNICBvCyBaH49J/QvV82rfBK9HyxeIXh8YCAAqVDor0JGtO0bgsFXFYIpo+L63qK/kQPpCsh1ljZcjA66RuszIkLZECixm1No3PCheHkBr/KtxoJJOiE3SjaOTwbOBcQjNFu+dgbQ7d7A3hrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Dq3dmc001amoNkyNORSo8UT5tprSJxmwuGIVCtG2oHk=; b=sZmDecekymip8e1bw3Sx3VlaQP5bNcVuyVR6K5YzcrzYR9LWaroMhmmq2fGppvC12HQ5S9UkLs+UPSrRW1UxEc43GsE5LojXNEckwqxM9m7KIdXwZsnnoUWRqTHZIcCp8DqlOpbrYfD0QpN7/Dgs/86Hof6ZiSWK428fuCIINS0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:59:31 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:59:31 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:59:08 +0800 Message-Id: <20240624135908.3331089-1-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SG2PR06CA0224.apcprd06.prod.outlook.com (2603:1096:4:68::32) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: c3ab58b5-b6c6-49e7-e9ba-08dc9455dede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|376011|52116011|38350700011; X-Microsoft-Antispam-Message-Info: owTbZ/hPLILCGsxFm9eXFaggxjtH0szsce7NwAkFNFIkiAV5eaxUALzu6kEKb0vdnBwN1mgRPXiuddQdCqg+IcggVUJm0VbDRTd5hLFvEI0QhYDHWLK09jO1JC48zcHRgU65iGbh8/JxPju0XQ9uLNbcUl0kqyUUp0rajGNeJnHvuMsn+xbNcYK0aaoWH+fYir+1pAxqLhBDhPwqBN3NEakgoTlk+06BNjmzJU2Y/4co8kTHhKNJwpdZ9/ShstajAGW1xWotnlxxRhr12ASMCVK99hlULoJ8rMcj++de0Ekdo7/ZAuML0hsqyt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-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ano9acGfZxPlAYF3CQwd6I+AC3I1A7kJ5YmnKR6HHrPbj0iicFuOa2WIhCbSD818jtF7wnsqT2Mtty1Dh9owiOJrKSYGpfc5xJ46luINiNHUneWt9shJGWpPvQDlvsOCpXyQZbOHg8yn5VNpe0Ips2s6i+s9Iz1C8O1yLBnH3viWEXXJYcNP26Ln5Bzpn7QUIK2gZciFJb1/n5x8spUlsVcrZSj9J0Tx94DPrdM78EH0w6R+rWapEz3jk7RUF8E7Ax83oVlAa4U9KEGs75qP2G1qhryFzAz9+07CaanoGc3KsTlom9CKvNy0+8ow7c3TU9Sx6ewNd45PcH0vpl7a0Opcc/1sHfTOFJGYFY1ZCwtnoAQHNDktQgYizzhdwbp676eD0fkf975L14l9T6bhqMzs6YY5wI1yvy50ChizEUZOxd+Bukgi0yYbCGzwulDpQKFMfSO6Iantmn+uXdn/9fjTZ4q9AThXMCLeRYmYBNvCqdtIRGBVwVSGA1BaI+E6RVWmgStw5sQRMf6OVHr3T+5KGtYsD7lHx5vEcApeorWx80D8YdzU+nSwS6UPwCy69fMHfCEH9qzGOOczCSwHexQoK/F6J1eNiSLP0sEZW3TaJBoZOJu/5zpClzjb48+skdWOl/PCSEJKdq002fR/pSbavcgRznwbYbYNOM4iWUfOlNqA1OvXU+3JmQYYy9HJI+IGVdAFRb8HO2gsAALNTUkLtOrgf4QvfV09Pj2VyorVqrtVKlU1KMKoVUg2GVuDtrOxLPrJUjCOTOl+94JFs2+tumz1B5N2SbztQAHeP06UBSyCr7s5vKlM4i8VJ/2iMcWnxfdtwUph1RlI75dsnIwFRukPYFha7JrJg5N9gcmwXKELD3AlUruNekGESpO6CJfVQaJQuyOUHvWCUbeQE0vrL3DFpxQRM5imb98NTuST7GK4yEccYp63z8oqYImjm35OoAchIKRc0q35Mzw4KrzkusGS3ilkIhdLHMX4E076uq0h7DrHicrz0wOY5WMNccQ3BreQiWaT9jkQmzKYOMrTMTXV7FLgtsntwIRdZGsskx6SC4ovNTA3IM6RzS/qZumQunMGYWEYGrZAz/y9kDK0ZjtCPX7yMeoRh9QRLYwI+wJgOJ6AkoILsFTBVBB2wPu/fkXlEzgjV5EMrdnvEbwnCVEPgTAbJpiZBsc/dIMHOnKzBPjhoXi9EIETa/e4RxqfI7mcHn4BnMhzWaSEXoyrtMeuK3K7wIu3qc1pfMArGCrslbNFjqGuActgcfN6VC8v4sBNixxfTRkWeLJwJ5qP4wcKv/n/pRkNUhmH2SJi6Wlh1HHlOhRO81jRPePLn2iLM15E+9eoVXMhurh5WdgEADd9DO9dNiOCaN/RavICbKQSu4JOtqOXjtCDDisivuWY6ZpKmzEcpJ5LGKby4eGDpBB4TeGjob82TF7rAqAAdqV0RszlgeaGwL2qW/lmsBuPxhdJKNEos3R21DMmzeypQXoVmr44nCYeORJ6+v1EKUD5MepJo8GLsTcil42ctmjO8U2Saoyopl+OdpnDZG+5vbt38E24CDYH6ue9Z0PGdsMgOHKQOWY18lfgUPJT X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3ab58b5-b6c6-49e7-e9ba-08dc9455dede X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:59:31.3721 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ETwKBZe2lcrhvbZtS4ENncCf/sTuSTnkHU4qV/fkKHJ2VoSSC7lvCavDiFU51CDTvecPjvzkvBRgrkvJ0+5d7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkjQ-00050N-Uf Subject: [f2fs-dev] [RFC PATCH 10/10] man: add inject.f2fs man page X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Signed-off-by: Sheng Yong --- man/Makefile.am | 2 +- man/inject.f2fs.8 | 225 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 man/inject.f2fs.8 diff --git a/man/Makefile.am b/man/Makefile.am index 9363b82..b78344a 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -1,3 +1,3 @@ ## Makefile.am -dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 f2fs_io.8 f2fslabel.8 +dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 f2fs_io.8 f2fslabel.8 inject.f2fs.8 diff --git a/man/inject.f2fs.8 b/man/inject.f2fs.8 new file mode 100644 index 0000000..01d58ef --- /dev/null +++ b/man/inject.f2fs.8 @@ -0,0 +1,225 @@ +.\" Copyright (c) 2024 OPPO Mobile Comm Corp., Ltd. +.\" +.TH INJECT.F2FS 8 +.SH NAME +inject.f2fs \- inject a Linux F2FS file system +.SH SYNOPSIS +.B inject.f2fs +[ +.I options +] +.I device +.SH DESCRIPTION +.B inject.f2fs +is used to modify metadata or data (directory entry) of f2fs file system +image offline flexibly. +.SH OPTIONS +.TP +.BI \-d " debug level [default:0]" +Specify the level of debugging options. +.TP +.BI \-V +Print the version number and exit. +.TP +.BI \-\-mb " member name" +Specify the member name in a struct that is injected. +.TP +.BI \-\-val " new value" +New value to set if \fImb\fP is a number. +.TP +.BI \-\-str " new string" +New string to set if \fImb\fP is a string. +.TP +.BI \-\-idx " slot index" +Specify which slot is injected if \fImb\fP is an array. +.TP +.BI \-\-nid " nid" +Specify which nid is injected. +.TP +.BI \-\-blk " blkaddr" +Specify which blkaddr is injected. +.TP +.BI \-\-sb " 0 or 1 or 2" +Inject super block, its argument means which sb pack is injected, where 0 choses the current valid sb automatically. +The available \fImb\fP of \fIsb\fP are: +.RS 1.2i +.TP +.BI magic +magic numbe. +.TP +.BI s_stop_reason +s_stop_reason array. +.TP +.BI s_errors +s_errors array. +.TP +.BI devs.path +path in devs array. +.RE +.TP +.BI \-\-cp " 0 or 1 or 2" +Inject checkpoint, its argument means which cp pack is injected, where 0 choses the current valid cp automatically. +The available \fImb\fP of \fIcp\fP are: +.RS 1.2i +.TP +.BI checkpoint_ver +checkpoint version. +.TP +.BI ckpt_flags +checkpoint flags. +.TP +.BI cur_node_segno +cur_node_segno array. +.TP +.BI cur_node_blkoff +cur_node_blkoff array. +.TP +.BI cur_data_segno +cur_data_segno array. +.TP +.BI cur_data_blkoff +cur_data_blkoff array. +.RE +.TP +.BI \-\-nat " 0 or 1 or 2" +Inject nat entry specified by \fInid\fP, its argument means which nat pack is injected, where 0 choses the current valid nat automatically. +The available \fImb\fP of \fInat\fP are: +.RS 1.2i +.TP +.BI version +nat entry version. +.TP +.BI ino +nat entry ino. +.TP +.BI block_addr +nat entry block_addr. +.RE +.TP +.BI \-\-sit " 0 or 1 or 2" +Inject sit entry specified by \fIblk\fP, its argument means which sit pack is injected, where 0 choses the current valid sit automatically. +The available \fImb\fP of \fIsit\fP are: +.RS 1.2i +.TP +.BI vblocks +sit entry vblocks. +.TP +.BI valid_map +sit entry valid_map. +.TP +.BI mtime +sit entry mtime. +.RE +.TP +.BI \-\-ssa +Inject summary block or summary entry specified by \fIblk\fP. +The available \fImb\fP of \fIssa\fP are: +.RS 1.2i +.TP +.BI entry_type +summary block footer entry_type. +.TP +.BI check_sum +summary block footer check_sum. +.TP +.BI nid +summary entry nid. +.TP +.BI version +summary entry version. +.TP +.BI ofs_in_node +summary entry ofs_in_node. +.RE +.TP +.BI \-\-node +Inject node block specified by \fInid\P. +The available \fImb\fP of \fInode\fP are: +.RS 1.2i +.TP +.BI nid +node footer nid. +.TP +.BI ino +node footer ino. +.TP +.BI flag +node footer flag. +.TP +.BI cp_ver +node footer cp_ver. +.TP +.BI next_blkaddr +node footer next_blkaddr. +.TP +.BI i_mode +inode i_mode. +.TP +.BI i_advise +inode i_advise. +.TP +.BI i_inline +inode i_inline. +.TP +.BI i_links +inode i_links. +.TP +.BI i_size +inode i_size. +.TP +.BI i_blocks +inode i_blocks. +.TP +.BI i_extra_isize +inode i_extra_isize. +.TP +.BI i_inode_checksum +inode i_inode_checksum. +.TP +.BI i_addr +inode i_addr array specified by \fIidx\fP. +.TP +.BI i_nid +inode i_nid array specified by \fIidx\fP. +.TP +.BI addr +{in}direct node nid/addr array specified by \fIidx\fP. +.RE +.TP +.BI \-\-dent +Inject dentry block or dir entry specified \fInid\fP. +The available \fImb\fP of \fIdent\fP are: +.RS 1.2i +.TP +.BI d_bitmap +dentry block d_bitmap. +.TP +.BI d_hash +dentry hash. +.TP +.BI d_ino +dentry ino. +.TP +.BI d_ftype +dentry ftype. +.RE +.TP +.BI \-\-dry\-run +Do not really inject. + +.PP +.SH AUTHOR +This version of +.B inject.f2fs +has been written by Sheng Yong . +.SH AVAILABILITY +.B inject.f2fs +is available from git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git. +.SH "SEE ALSO" +.BR mkfs.f2fs(8), +.BR fsck.f2fs(8), +.BR dump.f2fs(8), +.BR defrag.f2fs(8), +.BR resize.f2fs(8), +.BR sload.f2fs(8), +.BR defrag.f2fs(8).