From patchwork Thu Jul 4 02:57: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: 13723127 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 5E266C3271E for ; Thu, 4 Jul 2024 02:58:30 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sPCg0-0001BO-QE; Thu, 04 Jul 2024 02:58:30 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sPCfy-0001BC-Pc for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:28 +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=k+tXib1XiY4++hXja8zoXeb2PNj4SrDnA7nNa6syYOo=; b=E+EO6FPqSFvgdxC9B6tGwt1A0I oeU1IyopS1tdqSHnMUR3pizlfF5hIkBj/q/BN6j/gNSEGSwFzjvqjiV34A9moYBPUfvitsYMdwrGU IgY4u7VdHOea/BXvY46I4t1NSl+AdkxnU/5ZKgKRgvgsiahB2EV+zvP1cZpcx9nKm2to=; 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=k+tXib1XiY4++hXja8zoXeb2PNj4SrDnA7nNa6syYOo=; b=QxxuGRW5HRXy+4j4rdCdioJiO8 aVqxlYmB8/E027/r3wpnNQZdLP/1vf6yZNmFEioInmjhTUsg25dHElBtIgttWBMLWVkpDWSf6Ie96 eJZbtlt1BaINNVVigbDnozSGtwHmgSw5NlFw70EXOPWGwEIGHiHZblzHh/VJj8N9pB30=; Received: from mail-sgaapc01on2054.outbound.protection.outlook.com ([40.107.215.54] 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 1sPCg0-00011d-22 for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EaP4bdtSGOUPCnC0qsMiTrzTtXxAVdBzVxZz/2FIR1MEqYGGRK6zzl4ntvN4JSE/1tYhHzNivQBXcxvb/P1YPvPxaQKheX/LzMp0vAkLZuJdGfs8D9Df6m8yXzK9DVSlj7ELwKsM13wu7mZRfFqBfcNCtCfs5SetD9OuXfVpR9ylCrmNuCk/bLH5itRMtfjWCkxlQ/DyNr6XSYt5i0C2Cnc/zEiLOg+v3xBrjITZ3S6edGZwo/OxT6F1lWEJ8pnxnz+N3wXfbME1+rfRaZdYy74d2ezKNzCjoNItJSLGSY4IFCzF3xa22+g295mFZLE8NU223MWubzjjh5FIy+l+HA== 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=k+tXib1XiY4++hXja8zoXeb2PNj4SrDnA7nNa6syYOo=; b=LlXEPjXDfmG2gpW6MH0Hrw2gM9ymOWH+sOqmWa0PUjNBHyGVyNAWN8qyCDGpgCHoC4JYfH8BFi8q3haN7O2sUiFxLChrqLUo6fFvrbnWkdAk9HMMyHk/vt2LnPgKOdQnZ7IVuEo4O/RE6ObjzaeCY68IcRfu0kQP0OEHFo2TQ8d2hB/vs8gwD3FjtEdGDidpDg++9TFmufXs5m/h18GYvJJWJSgn4hE/uY+Hb8AB6wkTFGqkmZMNOOVnu2PrlSzv9SVK2Hw0HTH81BDrf3o3nQ0utZHMR9An8V49tEFjE+9WpA6S9ASA7QQbasAEn4lO3JiheqBID/VPLTYZf2rxtQ== 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=k+tXib1XiY4++hXja8zoXeb2PNj4SrDnA7nNa6syYOo=; b=gNgL5klbu1a0/3Iwjcgds8Dm/8Qrc19bglmVonKObrav+NLs9tAKn1Jkr8UVy3i1855H2gqnKtKrGVxonuXxPidAPwF+XN725d/WEAeW9UMI8zB87XcZNSnt6HfdJFoUUgRh5p/k+UEqISWB8/mMRYEKVvdFn6fBVUDY9hEgeFU= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:08 +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.7719.029; Thu, 4 Jul 2024 02:58:08 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:31 +0800 Message-Id: <20240704025740.527171-2-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: c7cc720f-78a3-40da-4ddc-08dc9bd520f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: q3mPhi5hQgw3DEUcqPH9JR+2qfDSGoUdbylkvvYIBuKwTl4HT9QPtAFbMG7QwSY54/mpHRbOzwcFU7mo/0SnQG8Pjg7qaXtSepHPkEplFSyyTLuK8c4f3qTZqEpiGtMl+31RVsBB7ppW22l64fQ2vn0R6jdZtrWSR/e8cIEcp4S8bDxvixGCGw32VM0xysXAPOay+SX0r4meFNErCSqPSSQSrxxhKtsZEPs8Aa03iSlUsr/FLsx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qnsxo/WCgHDnlqVM5t8TIboxXY0t/SNqwUInnRFAzByWx+FhptPhzmFF6fWY5tAh7qg7QlAcawsYMNClf/fsM8cJAngXZlTQIaiKNSgu9ji8VA== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b7NRamK7o+xJ0USARBjtNPqgpgAwopAKojyjKlln/80UDjOJEfD4pGpuqfZMPXU5dTioTKOKsDx17r6aGKtcgjXPibgs8hrG9wwTON6E3lTl9EfbHDWNx8tRMZtBkYCqtSweigADomnalXREA60xkRQEMwWhZBammL+/LNuDttEF66hwXEuiNFXN9ldHjU2Lpl5IjQs2lpwjoAdcTh7mrufBgxJhKjjAn/bIUmkNfpFbIwzQs3mL+ocP98ZRRfDJnEIp2kdRNalcO9a0eXj4S/RZLsc1xueFcQ79lMgS90cnQUq88NJP/1d4K4XTD4yyWoJ5d/VS1BegneyVJKOxGSx/F1eZdTPWMteadiXLAAekzIMFkf0ZH3GHvkjulS/Vt+GNmkP9hLdxL+Ts7hh1N/7lNEiN8NLtqq65pXCx0jW4wZVCeE452RqLwvoyECCthbndfu/4XM8Wp2x8kPZrICO/R8zbReQ6EbkGn0BvMhrAY16T/1oxSBVU/OD5WdxoYhwdFpfN3EuSF2toA1LSQ5Dd1SSalD76iyr4aDynsgpUCBF2y+NeJyBySJkGkCqRfPLcoIu1Q9de5NB4UrDIhR/aattP/UfpEzC3K6N1LimgQUwvCGEiDu0A+n3uiNFO1+VuPu41vNiPmK7Ept9HQkoYCnFW95ZZnHmegDu1YMGSB4yhLDbXyihgGmr0opBBJqiTa674vzG2FcQau2Mk7bjLv/zqNMzLQdU1y5+rA0Tec4sY7LFGcumU0eCmPWj8cuMUR3XCp0JK1N91Prq/n9zhFA4GfmXLjsspPAa5cv81bcE9Z3+weUc7XKvFwb53RuZUjN4fH03a4Sp7pov46TUJwklSNmvffmlAurdWNY7V2ISdfd/idV1TEdoltis2FIJtGA7uPzRxqc/WPTI8LyFIZITSan847Clzi+vgJV2ERYAahIsiqF+P/t/o73u5uG9qzZKZRrq7OovD8oYJ5xsfCrK/TsWUHPB6KvugTWywWysVZWYZ6S2n36NbseTk9WhcJPyx/Mv1Cvb7B8x5x0P+uxD/FMfQ7v7EYoEpw02CrnPSLs76AlmTR8gZl3YUSdYtgvdc5d4qk7fbHl8bKsYBNZidtkY5MqJPsm+M4ZzRljW2DmPVN7I6WDlnERPJXWwwbRak8lX8AGKihhK6Xwa5iNm4mws/a/TwiHCmWsLhWWxZv6Ic5n4WpW0d9Q4iUFebGhY8tuhkeM4qCWpqQeVkHRHAAyjMQiwRab1+gpZuEmqsVD2LGwCB+SKzRnsbp6FJ47XCIG/Dph4UA6LDinHpv/GjYv1k4b6M8Y8zu+D0I1OB5gv8FoVr32KdlkF3DZWOnh9xtZ/uN2DCan+oGJ9Z/EIIgy9bPvhk9Pg7H6wSCUdml1h3NkKwGVUEi030A6Gj1CoAI0DlyvJ+AURC8XXZm5837119FRCNBadkzsKiCrLna0IKBFe9a39t73EiQ0RMMWk6OpDNIl7g8Ddn+jbIN/FsrPzMN3nvUVIgArS5T9CzWCe4EPc5k9/n9Qxjpi/U3jv8evLdCBe7wf5sKLFp7RNgKSHuzHX2LR6e3BUNuXRtDgOI+WRW4HdzfaEW X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7cc720f-78a3-40da-4ddc-08dc9bd520f5 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:08.0460 (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: mG+NAjWKYzAXe1GByAgwFAzLw05uapmvpM7o1feY4tUBJscH3Rfnsz2m88sDmBXVrbVG6Pkfb33uSftkvKw/WQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCg0-00011d-22 Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu 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 c13e287..c8469cd 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -171,7 +171,7 @@ void label_usage() exit(1); } -static int is_digits(char *optarg) +int is_digits(char *optarg) { unsigned int i; From patchwork Thu Jul 4 02:57: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: 13723122 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 CE794C2BD09 for ; Thu, 4 Jul 2024 02:58:23 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sPCft-0001Aq-FS; Thu, 04 Jul 2024 02:58:22 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sPCfs-0001Ak-QU for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:22 +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=UxSq6aGYgWdV5QYItzXb6dqZpARJm+GjUW1EMpyQk/A=; b=jihGDNA9kDMX5De/Rgf2w9mfQr pob50h26P2RVd3rnqYIWC9xOJTYKsZpN2mCLDAo4XjSoJQSpgSZ1+Ywkrf6VE0++BdKxa5mr2L+u3 b0m67bqlIRRjP7Kf6pdmhfjMiP4tgChKoa+WsoeIzdnmlspTPvl15j/Cl4OMUpK9WpCU=; 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=UxSq6aGYgWdV5QYItzXb6dqZpARJm+GjUW1EMpyQk/A=; b=YVJx1M1PDD+LjHDzFeCpUVOQEj 9mHizml7w8K18KyvmLmt4cu9bc8NzqPvD0JyKCATzDgXg09SYXeP7dtak7GWpTw+VGrmJS9d76+eb Gm/rk+u/OOm93GyeoBy/wEtCikEhYrIjgfNkEtpyAI+BUqERa7ef5dhqIQEvVTPjHRZ0=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCft-00010i-It for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mNhbA/xnJJo2cNYWL+ICTGR2Lh7wcfQ35ddqQfGrI5xcZV6Jg7m9tn8vS1rZGOsE7X8SILGTV5/aHlc4Yoc7mW6/84x1f1bu9rJ5Z8I1EfU1BEbpoNlzvzOfyhSNqB+mlc7lK66fQPq528uCyzBGZBE7Sa0SFlNuOL/dNY3FIEI8jQLIywQvrAfAwhlOuoR6OPsgsi/Aq0RZDJv5R2ccoheTeGgDTuUKtWRCZSuBuOjbtt73XjHbiNc9vHsTWmozza0c2Qb2+isLjNX7AB4o5FsX62uwBHDL00YeTJp7XhJSu5KkkY6YtmrIuMCELY+yzYgasuErL3nmHhRCP5LFtw== 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=UxSq6aGYgWdV5QYItzXb6dqZpARJm+GjUW1EMpyQk/A=; b=ewz79X877at7XfPALq1r3pRPBcDuKQqJtvfnpEMFeJhSeNi6hyx9+U96awsazSIl+pAMVSU9UQ3ttoN54BiFW2gTT2zn1RDNnTEXXXugQP/3yINg6ZRz2SiYpitWX4CPNxzcM3fVkooY2M+/ZmSkuAkYFY9QUyLveVpK9nu6MIIzFKWXB+fXG4vdiACIaiZSe2RdTHzQ/Sk3uUpocZTW5UFtUvjlnJ7isqu0yj8DCPBocyaG7C6yloayZELJg/PLJC36t+Py3FTVte+TD+zm1yNHyZkuihBtfCnIPRm3Lrd7Wr0eAzV6YP8agwfVrPo19uNcpkBnQxfSS7UCtXbduw== 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=UxSq6aGYgWdV5QYItzXb6dqZpARJm+GjUW1EMpyQk/A=; b=vKoBbD+OMqpRgVf2NE15BHOM8Esz9/6rgzRfFeKpoB++HcIMsRCweJlZU7bM1W/Id/nMXReO+94N92HGtj+6VkxtvecNFuB5v3EviVcuaIoFv+PNTB/G5CqimkKB2DUqwAFPSRel85wkpa0o+UnrIygy2MJSpF8qG7QFob3/KPw= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:09 +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.7719.029; Thu, 4 Jul 2024 02:58:09 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:32 +0800 Message-Id: <20240704025740.527171-3-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ad55b9f-ceac-48fb-3a50-08dc9bd52285 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: w9mb4xRgKtFR717GH0OsMuX7VxeGHVA3DxVExYeL4pjVpw/aP//ZGW1EuDn6ZTlAgQF/XZCYNGRRImvLhi/H9Lkif1hzfsc9p3s05eSEMb8DRNJGJxVh1qIbURebBtK/2u86V/cIm7hauwqWksVWflR3nZ95ipKEC1X4hQEf43HsZLKsjgJIe+nfW62gZDYpB/t0f1mlIDwAULpCOFRvqKF2AbVHDwlkOUlxsxtH26iqpZbQV7xMHHjex7sUD0O3/yuDuWBM78f6qP/wvuLwlV+YDkFSmez7I1PNfCtcUT264ZiiA4JxpleIMXmRCIc6zOYGCM3PWRwJPj0qKg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IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QWVwjZJcEGJPVFOAz49VU8tmYLzCsENBzpO0V9FZGOjiY3veUifgYryaHVUcZdnUE6Sf6HkMj/VlKufcV0j0+QJOphzp2/LB9Iuou7IntminXA6gHhYZfiPcDFj3ytX8+NPQDiUJxUbwJq5BkmHPptPi0GNP0ySN9uRVaZWq8Udj2W8DoSM/nlsauYlaHZK2mbmE9J1oo89XxQbl2GUiYOkK6w550O+NBi85wVf5vlZc9o9xr3FW2ubjsuC0gtJhOhZWlZ3ddhWaYgJ7oP16fnvOdE7UdNIgLrjlHoCyd0JqPAwx2iVANXtgTfoVCsYWwjDG/AtX6dD+32zCjVR9SOHTioEeo6NVbJ2JQ/WMS6OX3b0fcAfNpsOvrIfQrDNgKD1dDyil/VhAsf9MrGLtBbz46IPyyeuBq55iaLc8a5iebcCMXxoyF/iqrWdecAU1xSTXplVYAuH9mBsqzGDojRdtezpBTeZjDghx+Okl+BScDV0XSTvOaEZxEBWBVf+rMp1WM6Hr+H3RWl6d0fDz+A51cPzU2tpRPQO5wys29dFvA1U8B7NXMkz6CKoNKirrIWFMLgubwZbkvjR94exBT5NchJI90al1aBUjGyZtErqAfcHOrNztuVTkYLAEOP5X0B1qhsEG36O6Hh4s5wHbB9FoluQ3Ad9qmrpIOikV40WnJgNdCSOya+cWDB/Vo1RhnjR5uxV9xA1aUmFn93YEu8NHLe8QkYW0L+J2iMJK/MJvufLNOnu/2+T8FAZ9L0p8EHYHcdvTPcMM9QOw/m5+tv7Nfnw8F5vDv4Fb2Mod7G8sPfiP8t2YcgC5Jm9mUQ0TyrMh3hSqx53mGuotixy8LdH9VQzmkqvS9G3F0ETHbDjaO3OvKQZJXxOzMOXnk3WnorpRyb6vePu3SxfmsPAgcFzMOtKq1znC6cEa/1otyhCRQeWCmKa2iK6KCR4YqjQlloDpiMMsHG74d9Sli72Q21A0JwcfYHAz+vs+H7gv1ja0PNFdcLlyEHybGvzMD/z752YOKJgfMzvdjQt66xcdnr2PgEtjoswz7X7dn92WTiEowEvM3xTmAjiqQAz9TjewIA2UkEsQ/5mw1m7Sa4FDd2WlfDbwZexAausFgaPQ27zGGZ3WLfqn4lNR/eLTNQ8SricoNC142Nvb6hUQHjFbLeGkcYBD7vn966Nu18Zxy+f2lNYxvhu6k1xNvIT3m06RuPD6LSyE4Mt3W+qWNhYmxQyNKrvhWCDB6kyP/J15tAbsvIeaAlQkmAStV2diWK56pt1arDu3JDYUDZut0LkOGqrA48EueUKDTK3HXNiVVvD4c9gOzREi44yz/fPEbPJf09zyKXTs1GGqO3hK1reZ3O2/LfbOi3ojy0z/aDADwfrEG1Fnh0sJy7rjqQ1zBN4VNTxRggtAsmpLMce0mNDE5olHeXl/rJh8hM9Eb4/TQ5pZUWTgbeiiGLVl4Fs5QPlJBDFUkJUWw/HkjGedh0Yd+vzzprWiFBz2Z8DvHjK4TYz8cDtt71tfb5OPwXoIDqyzMAzAS614kSfY86+KGY/Wy338qMybsPlR+ym/9QCow9j6K3cQySr6eKwecKS0w8tB X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ad55b9f-ceac-48fb-3a50-08dc9bd52285 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:09.1262 (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: 1dt4/73XwUyMT/vqGQG1d3JGQ4iiXIK/S+VJ8Nyh2a8NMBFby8EH0SThY7GMcfCQn+mxtBq3OOomqmyAwRfXSw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCft-00010i-It Subject: [f2fs-dev] [RCF PATCH v3 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. Reviewed-by: Chao Yu 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 c8469cd..eca09aa 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; @@ -195,6 +204,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"); } @@ -809,6 +820,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) { @@ -1229,6 +1252,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 Thu Jul 4 02:57:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723123 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 DCA62C38150 for ; Thu, 4 Jul 2024 02:58:25 +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 1sPCfw-0006zh-Mr; Thu, 04 Jul 2024 02:58:25 +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 1sPCfv-0006zT-AE for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58: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=Wg8fhlFiwyjeBmS5+Axsac7ezSONaeyK6uaE6nwGIVk=; b=hHgCombzPLQZxFDbwGlWyidVEM reol3zpZFgAVQM1c2AvpOs4tYrEFbxPEytm8OnXdqAAQIXcXJ7Ehb4bEbYnz2yM7hvjYC3d96ao/K CnEgX4nZEUrq3FPSSs4N3BREJiwLeVegmYx3GrT1JY3pNPyijYnd5HaxezQy1sVI1sxs=; 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=Wg8fhlFiwyjeBmS5+Axsac7ezSONaeyK6uaE6nwGIVk=; b=mJ+8EiGzxkaUpmaUC4fdaJeFv9 yGeTIl5BVSuMxcqsLI+mDnqq8arqO96fhp8P9TqJIQ6vQ3AR472wqZuV5XS/EGmTyKkMcpG4jxtgP /L8NHkDCBHtbRySiqjyosAovBbN7rCb+RA0noN5EORLaIWU8eTUKCdjbkHnEHFTdChcM=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCfv-00010i-8d for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HvoXt2zkVqaNGy6MDM+9VCLNmXW0gW3pvVEGbU3JgCHl/k31nHX54711EkRE2+wSfAFpgXLk+CF4n/x5cG28Hhonk+oYq8/1FYBLvWWkhpON+5SUzpZEorIGhSgqRlahECpg73qD2mQfTh6EUuUDc+7IZ7XZPojbJekLVBJeCLXVThD4O6mAh9tjW3CuON+ZV002+wmkpzIfWmfVR71pKFfIYa0Dy5fdUzDIKuCjMv5c1K2o/2Fe13zk2W6qoMzCiFi00b4VTckGN8BujHIjddSRyV4TcprVKSrSE4dn83fMQww7P1nRllB0iHm2RofizKjWy6ncMApO9G1odBqhOQ== 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=Wg8fhlFiwyjeBmS5+Axsac7ezSONaeyK6uaE6nwGIVk=; b=k6fArJ0QTHjwUFtkfJHBLruPcyZtTMce5fJVlso5zZmxCEqv3CgNzSuXvB36D4eIw86C2ivN9yKeFHIU6oUspfFLOL328MxxObHF6f1ng/ehj8HU0oxil5kNpxhlMN4eBPBlu6vvznvdDJeP8FeNVoCmakNoNCcdaR9Oy6iLoCM1u70RtyapAIX4mJ7pY7LLPJkXf2QbgZZvv2M/B24sz6ca1H9ZS7EulxxXcUf487+FhEu9PZf98tDI38ua8h4k47BSsraYOPl6bJyv0rmMUiDueFgUXYuswg/UR/4UZnxOBLhEVkF1unbuIe7mjhfmpGx4DGL1gI9mMvmDdag+bQ== 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=Wg8fhlFiwyjeBmS5+Axsac7ezSONaeyK6uaE6nwGIVk=; b=AlyEmMRcbba6R0PHjRj62tY2V7TK/8/QPbXnyTrJNQifk5sYxNbh0+DYcjk0VLwCEIOR4PatNdEfqmvJas/WJ6pq+ODJ3o/f2LuN6IpeYYXGT0JaiYSlKlD93ph44m8Q/YbxLHZZaxwDF2HKoYMsT5kFWmXmmtzICguUN/e8+X8= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:10 +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.7719.029; Thu, 4 Jul 2024 02:58:10 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:33 +0800 Message-Id: <20240704025740.527171-4-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: 88e4aaf8-4840-40bc-bfee-08dc9bd5232f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: W1nc6er34mEcxTVDm2dU2/e3ZoXgMQc4scTQA88HizrLe1toH/nEAZ4FRRoPeRpWKRZ2i1zvy4xcBAeYfG6z0WrmOp0v/jF03ktX9GG188JWaTbxiCat30Y/sONEWhb+u27gqy0+bMrON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RNeNlLX51D0m/Y9BtVCLpmQ9IOC1uWwLZ/cFbweMck7f8dr+cn+1G9T90QjHbEAjr9D1OuQVE6utlTfFGUf7R2hgyqlmxPBdn+OTSS8Wm5JDntRGXzevZ1ySrj0QXpN3HN4TLcWEF2ClDQdyx3SIKVcjf3yI40wtOxIMnWzFfszCEoXfasvefXI8JK1A== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dxeVPfZp/tmYZ5VcXlOW7+ZUcDOqQh8Opq2YB8oJ+LlzauPH+HUdZliYwjNcIVNiUnDy0xPeobTKwQIDAlWKuKIXwuU896yUsl2lnsbv2EDKwwi7MTQrzoDl948ivD/xn7QIPZIoAeG6rYGoC/0FcuY+AhuoLRFhn0fTAwhnDmc21Bp+QfHEGME4TDH0QyXMi99yLxjm02sTYboi9Hr/N/JuRUCPJOXnt3XRJZhfRV7FATcbbhFiU6sFHaxiaCZiSJ5L5WMA1bv2gK8J7xXBq7oVP1yUm23NrDZwSNrGYQvj8n4qV7T1sK1wwEKwBXcoxmZCHmnwVbm4cYKSUrzZB/xvOaMjGGJUVWb/gUl6oykv5yBE/eqFuFPWBvL/ycYDDIHuw/dkH2oAyo5jH4xEnod9Zxf/1hvkFgGbZWbM+srY+dmWe222iTR2nKvllEpHcCMSp1uLv/t0E6zeC79Qu9z3Z2uXi8bAV/cWOCEDlXHJm5pOgTCV8kuTSmqPw2wtrVIvl147Sqr3NG8ZGQmXVxa/xA4H/ulAyOeoEJSuO1uf1Nvp2gfUACH8ZCeec6l1onbqgRGcjCKA0X8iV8MEy4ICx/9TuOMD+oAEgmVvrDcXjZILGSFp2U7Uabu0BgWKpJ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prd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:10.3475 (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: DtmsF2S9tonVRp1Do6a+aGFpJ1YfaVUdUeamBSTnBFx3Ue4hHSDBjNN4RMemX1ItHDRF3qHQWoxyJHpo71xtjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCfv-00010i-8d Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu --- fsck/inject.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++- fsck/inject.h | 5 ++ fsck/main.c | 5 +- fsck/mount.c | 4 +- 4 files changed, 150 insertions(+), 4 deletions(-) diff --git a/fsck/inject.c b/fsck/inject.c index f6fd346..f29e746 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -18,17 +18,43 @@ 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"; + char *endptr; 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 +65,38 @@ 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: + if (!is_digits(optarg)) + return EWRONG_OPT; + opt->idx = atoi(optarg); + MSG(0, "Info: inject slot index %d\n", opt->idx); + break; + case 4: + opt->val = strtoll(optarg, &endptr, 0); + if (opt->val == LLONG_MAX || opt->val == LLONG_MIN || + *endptr != '\0') + 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: + if (!is_digits(optarg)) + return EWRONG_OPT; + 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 +106,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 +119,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: %x -> %x\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); + ret = -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 eca09aa..40edf35 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -822,7 +822,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) { diff --git a/fsck/mount.c b/fsck/mount.c index 8524335..77e3919 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -1212,7 +1212,7 @@ int init_sb_info(struct f2fs_sb_info *sbi) c.devices[i].path = strdup((char *)sb->devs[i].path); if (get_device_info(i)) ASSERT(0); - } else { + } else if (c.func != INJECT) { ASSERT(!strcmp((char *)sb->devs[i].path, (char *)c.devices[i].path)); } @@ -4018,7 +4018,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi) } cp = F2FS_CKPT(sbi); - if (c.func != FSCK && c.func != DUMP && + if (c.func != FSCK && c.func != DUMP && c.func != INJECT && !is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) { ERR_MSG("Mount unclean image to replay log first\n"); return -1; From patchwork Thu Jul 4 02:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723124 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 DCA24C3814E for ; Thu, 4 Jul 2024 02:58:25 +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 1sPCfy-0004yr-5P; Thu, 04 Jul 2024 02:58:25 +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 1sPCfx-0004yl-Lq for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58: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=7x9qjhusIjWHMla9FWay4LUiPeDRlZSJKiBgatdQzQM=; b=AYMdPVvf0FzYbbgN0hXZ2QKtKR bCwQJHTgck7vAyEg5kz0NrMgsnNomH0AbWNMr7vpUqXUzGEqgNjn+T6kVk0Ac3wKEQIT9xCPWlCrx ysXKZu9k3Af7kjJtgPy2MOHUGBwhMj2fvcsReD5mf7JTgeLkuOXSrKCFAn7BVQknmtao=; 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=7x9qjhusIjWHMla9FWay4LUiPeDRlZSJKiBgatdQzQM=; b=JoM9MCbgeCx+jTFImWlCigGeaf 6wU9hPqzHWNXg0W6ZSUiD7xYrHiLY4hUfZo74LDmdehlo4juQpto1w7AKMn1mdt1BVys2rGHSChkH SLA+8l4USKyLRlKO5s9j2GBjC/iuqIwFK5I0vnTb3vC4Mk2RGd9OPjvRBXGZvE6aFTE8=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCfw-00010i-RU for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YjdJpqk91V0ZBN87E5WCctfG1OxFtF9r2jLEtHECm67Tw5jO2LYTlBNysTeWa6EkOYypWU+3JAgZ5MbnRKaI68tyvlyacyczKVB45pCo7MyGPGuoB2uCXLuOa+XIUt2iVOVHiuc2VnDXkuIHYJndibA827f73z/QRiu+i50PrDshV3/JoeUwORVi8KZ//e4f1uvt9LhTer9m7LJUJQGTdoIyF7jDh5pszziLJroUYAFgus/09rMVHgtOrOrvsIDt7tOBwO4KkfxhWIXmA4LTX6RKbKIY8bk9treaawHw+zTkP0hLZCEK3JxLiSMDx6Gab3aYsJTwY0C1Z/VqCb2+oQ== 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=7x9qjhusIjWHMla9FWay4LUiPeDRlZSJKiBgatdQzQM=; b=Wu6CSsTn4HNn68J3OyyRqEA3IUq0fT/KUj8sJdXKfKqLrGpD6FAj61T1y/7nuIAq9+mXMu26ERmcdZqvNFX8P/gHHTSb31lOTt8/zXgpvnE+aF7v77t13sXlRsrCmTCyVZMv8u2J3Vhm6i1GdzXbX6XoMCmT24RIEdlTnUcqnsy9j2bEKOkigG3fuASij8+OHLfI7eW5OTewrI/jSZm/DEueaCrOBw7iXFKNPAv52J4Rhrfdhj77gZDThUxbB20/B6TVesGJ+ebpWqptUpXaPlUIz4Zk1ehy0LKnpRbUMQGwJrVGs6zoE0/R90ycPhdKjXjgYIzrdiOOlih0FBN4hA== 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=7x9qjhusIjWHMla9FWay4LUiPeDRlZSJKiBgatdQzQM=; b=NjTxJrHHm/NVBSIP6Qs5BrmML3xBnTP6JLdN6C4X426lDFNEc7jVYdC1Cr4f8dk5rZfsVM4rA0noiJ9vpsJ/Cazjqvz+moj/PbbBPIFULA+3cp02mchJjhBLLbSEcfwx53xvXa2g/WE5QGUOp9IyRvF/mOCpOsGyxf/MGSEZe4Y= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:11 +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.7719.029; Thu, 4 Jul 2024 02:58:11 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:34 +0800 Message-Id: <20240704025740.527171-5-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: af756a24-8112-4fb6-022b-08dc9bd523e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: 7IuXdXvpKf35Lf3ZUnlE6tNTjjcKHHGqNcm9/9UFEMaXj03N2iw+6qhs84DP5//b+sN96uWFUUykehPdZlZI35YW1nqrR9Y3ZtBlwBlWaYA4+y1GgDtz/NSwIgGWwMGp3DKzslHznoSQQ5Y9D1Nbp/z5kaj8aiyMR4H6CK4oZkzWXhGUx15ed4wtXXuX0mykRgFZRn5pUn2EY/P9eWRZNQ8s5MVvOzi4j+YApMY3QZj6ji75+xsEaukKzgbgstPNojdw3LDffzkXlSPvGF5wrSRnCCo+Xgl1Q8mJIwATww0TqOxztNpwDk9jGi9f4QWFUP41a2uP63NLCuSxaUe7tDcypHZgqNJlwaLHyPkv4enHZHhce4Cu4JMakEgtoukWXWNxl4veM9WfImUDr1DDcv8fnkzKNqY0j6BvlUQBhrIrHjDgsmyBHqi0Mtj2SrGd7qN7u18yP4Vblu1eYCRNvO4uGDaHGEYmRP7aM2kGQnS/n7uLaWC53N7M18ytCkJknV5o4uYfiMqAno81EdrzUJFBA29ZFsOGHOCJkBi3Dg3PAuiDPO9bKu8V7DBjFQyBa2M6RvZudWgW4Y3r/exLCLx1Jc6u9rEZUBDwYnGb0lOcRKV/Lq/drAPOh3v3ubLrEnf7RqCxkBlMPZ+pqAf9V2r+nTDpC86o0ewmIdmbSCxhDqlPsPoR3Fnj7Htwn7YeFMMDlpPZ00ObYrRJ5qFmQ04CUG/M02ID+j/Y1eA6R7smYVvi30Mxt477hUYHX+5URERWEpQWsnAav5yZZHbyuxmRwpLWOwum2ci/M2ySVutx0uYx+L4F0TUgs32N36jLPiCieTTh4GXN0+vvyV0wEgXIOa5XknmkDvywMIAaF8HPLCNegEuWjqojFqh0CO10Fwgc0md99xjZBMOsKIdK/cyuXdXo8JQOBEz9hyP9XZAV0R1bkORnXZSRGgegiw0Qo4SiYaU/B5h55UVCCvo5auyjSRzTobhfAI+iHjqMJ2/usXRiGCWr+vD1i49A0Ra7DtIEBS2n3HufMwi4qtiLBC7lm5bkBTEPY9l7MEFzEoGtYKVPFRqawSVGobENSVa8BN5cd5mgkfsDY02qCOwhysxW67LHFt2Ea27NqJghgo9+aHqyFIFeFEiLvdiKDVdmtEu1kRcPTUv8nwdmOb1T48cpkRti4UOpnIAX6iY0mJ7XZ4HIb1+8ss8I8TD9vBhEG/VXma1R9PSduwq0IGSvS2C2QVj/gBjvvd+dO5uM3vy8X+PKYzbePqlwGTtVAitTtdZU5gi5fiTWtW45NEwIB5EGhIceBjH236lKXkmzRheIFMxbFRJB6yr75YEIxyPXS/tRDFcTgC9IH1gtll7LAK234usQ9mSXzyLpF8Ysr1M1wsocoZu7SCOgvirKXtzegoaNM8x63bldd7e4IEYfxw== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PJDlLFOoKJUlRqUojr0lHmGTmZiXsZ4dsBxu/a/v2t67zTN4dWLrU2hYHvWDLg7Ww4OmtC1q1LbN4mpUu3M7xlr7RV90n7qvvsdIf9762pGxk2DsMt+++zjhPDBKFs5WLTBCKlwoCsjdKADESmfcYZ2vOV1tBQ7tcD5cZm4i1/563VCGHRDDmvBnCgqssxj0KMqM6NLsIFT96AB2uNfwpwQWHk2E1FiSRl9qpsyUiVMfcO5FaX62fP+MXH711C9D7lo43nL6N8sDERT5/FfJmsSNTWf/zf3otySVlz8OW4WOwwF/s7WNc2aZ18C4rbrtpojzgDT/VRRCoPFs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1MmwnxgU/A4fWnDpk3+U/5m7cprgvEjRNqlOWCkbRqRFZrPhhI5xeYmSgV1lOWe6Rxrbcgj2JFVjkG9nzR31VTg1PFXD5I+PU2hyo7vkda3ch78oUjetiyXsxPfNASOeKyWInix9lkx2c3zTgmB4zDeaBGV32JKk8CHD7mY+pC9cStkghrDY9jrFd86gRqJ X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: af756a24-8112-4fb6-022b-08dc9bd523e4 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:11.4018 (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: WY+YE+BCibP5PubnFwbYa2ukQrknyyI3zU1FmKuJ5EQD8r2jmrokitfNNWE4+sY+6rNC6wIfKQEplcujdxJwiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCfw-00010i-RU Subject: [f2fs-dev] [RCF PATCH v3 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 write_raw_cp_blocks() is added to write the first and last blocks of a 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 Reviewed-by: Chao Yu Signed-off-by: Sheng Yong --- fsck/fsck.h | 3 ++ fsck/inject.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + fsck/main.c | 1 + fsck/mount.c | 26 +++++++++++ 5 files changed, 158 insertions(+) diff --git a/fsck/fsck.h b/fsck/fsck.h index 4ca75b3..02986ef 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -236,12 +236,15 @@ 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 write_raw_cp_blocks(struct f2fs_sb_info *sbi, + struct f2fs_checkpoint *cp, int which); 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 f29e746..da4356d 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; @@ -55,6 +72,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} }; @@ -97,6 +115,14 @@ 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: + if (!is_digits(optarg)) + return EWRONG_OPT; + 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; @@ -111,6 +137,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; } @@ -190,6 +219,102 @@ 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; + sbi->cur_cp = opt->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 cp->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 cp->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]), + (u16)opt->val); + set_cp(cur_node_blkoff[opt->idx], (u16)opt->val); + } else if (!strcmp(opt->mb, "cur_data_segno")) { + if (opt->idx >= MAX_ACTIVE_DATA_LOGS) { + ERR_MSG("invalid index %u of cp->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 cp->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]), + (u16)opt->val); + set_cp(cur_data_blkoff[opt->idx], (u16)opt->val); + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + ret = -EINVAL; + goto out; + } + + print_ckpt_info(sbi); + write_raw_cp_blocks(sbi, cp, 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; @@ -197,6 +322,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 40edf35..da58f0c 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -824,6 +824,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 77e3919..77b6144 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -3426,6 +3426,32 @@ void write_checkpoints(struct f2fs_sb_info *sbi) write_checkpoint(sbi); } +void write_raw_cp_blocks(struct f2fs_sb_info *sbi, + struct f2fs_checkpoint *cp, int which) +{ + struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); + uint32_t crc; + block_t cp_blkaddr; + int ret; + + crc = f2fs_checkpoint_chksum(cp); + *((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) = + cpu_to_le32(crc); + + cp_blkaddr = get_sb(cp_blkaddr); + if (which == 2) + cp_blkaddr += 1 << get_sb(log_blocks_per_seg); + + /* write the first cp block in this CP pack */ + ret = dev_write_block(cp, cp_blkaddr); + ASSERT(ret >= 0); + + /* write the second cp block in this CP pack */ + cp_blkaddr += get_cp(cp_pack_total_block_count) - 1; + ret = dev_write_block(cp, cp_blkaddr); + ASSERT(ret >= 0); +} + void build_nat_area_bitmap(struct f2fs_sb_info *sbi) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); From patchwork Thu Jul 4 02:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723126 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 3B674C31D97 for ; Thu, 4 Jul 2024 02:58:29 +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 1sPCg0-00060r-2k; Thu, 04 Jul 2024 02:58:28 +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 1sPCfy-00060h-3Z for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:26 +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=SNO9DdCJGKOaTEJOYyV+Qtq41nC822cbPSTvh+LHbqI=; b=ja66HASIhyOkDKQx3dpzQ11t0y +aQ5q7lO2vX4LzcvUT81RwQdL3jum9SM6OMtcJ4C9jQ3DnmTDJsMxstQL1JkGtv4zDjL6L1dA8pJ8 bARNTCO7WKgnT4fr4UIqN/HoQdH3CjiLhCo9ZBTh7lwihQ7KAC2SqX5nNghCtrvaZFI8=; 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=SNO9DdCJGKOaTEJOYyV+Qtq41nC822cbPSTvh+LHbqI=; b=h2MM28Vpcm2R6locLzse00Kiz/ i6L+GfD614KVrUSbyfbtlKjJdNIi0CZPi0aDKU4EjYSJJKYdNVWG0yNnm5SYAoVnAQ47MB59eP+ZX QEauJrIlPiZ7vBN5NBMpIF50HFmNdCVSmQGNY0/o7X49eQzdW+LsP2J44RLARDZ8BaHY=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCfy-00010i-Ah for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4WV1ikaTdQkXnlY68jP8mIpEtqHaRsTyMHZJY6wHfehg78CQlEnChtqQVikU/n9HuLW/i2rraRNeRCiFz62JwzJYRvzeJY8fC9MMCtfHuicok+6+YdDdJel7onfS88tSgZB7kg0G9vkfJ6npnUiBZ/vLDehnEH4De7SJ6Wxgj1oB8yyR+WWfwieOe0QK5laQFh20WncDp0Y2XKFgUma+vDh7/dbQCjJ/DlUIeOBXTBfnxmDCOUn6pJ8uGLBwevX3pk/0HgIyac5bTrTmtXzYvYzRFFcv8KnkTqesItlhHwwFsR6WevYw+KsBNXDTWrswR++Yb+DqmvzG0vmUPcQXg== 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=SNO9DdCJGKOaTEJOYyV+Qtq41nC822cbPSTvh+LHbqI=; b=LIfSne3ZYt4hbF97L3pfWY81U7J9W6Ujpo18smmUQ6c0FzhnDACAYYyQidZ2RjufMBC2tS+VReWlv8006qinhyhVdHkCp+7jdUsQpFTV+rWfiDGJmqQtwxje7y+3xydl26oySn/4WjNIT2sM0ycLF8b5hmu7qWd8UABrMRA8heOwbm5jm2lTUgs/VvXHgYOkeuBS8IPhNmDO0tFp6TKDXu2CjjGkY6p5Y39LznBK1iNBgS7iyLN2JQ0qodaEEWWa1Cyy3ARQursocfpMLZ72U++Kz2+TrxQ3W/65iTaFacoKRE+qlFQCOmGibd5UbTmPGLE1oTkyk01TAvxtvc944A== 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=SNO9DdCJGKOaTEJOYyV+Qtq41nC822cbPSTvh+LHbqI=; b=hSADm81rzjEt3mr67XiuiQKwIbcracUTlDLv/n2G4E6LmvSuJxJSF14MRQWc5RRVwya3JGoiKLdUnkNpnA703DZVrUb7zkYZw1PjSuG28CSzexzbWLKTkGrhwQUrul4BJ+uKHxnod1fQ0nU3ngBx/7dZluhGRjkDpcjrcykrj0c= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:12 +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.7719.029; Thu, 4 Jul 2024 02:58:12 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:35 +0800 Message-Id: <20240704025740.527171-6-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: ccba819f-276a-4b57-94e8-08dc9bd52484 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: u1bjkTx5ACm7amWIPHaXNPnEbvTrhf7XYKarBfyUSkOZNuVbsCbAWsxy++aIvutc3JEI+qVUtmQCKq8qsqhyEjpFXR125Ha1ieQZ2nkDn4EkK36wK7e7zcsntYtFUuQvBgaH+lT8AAii/VExRihFoe7cGFAM8cykChOmuwmfke7Xl+01tdxs67XkgAneZqxCJUgcabY+/RhoTpuzAQchXkOV0+w3pRNGOQhNp4g+zQzPaB8dtlJhajkYouSCHN/yj6+Qs40HFZWwT6WhlNKRXLnXrWt3ta/6P0dAO5OOWqEdUuqmr34jRLmHGHB81ag7lNvh1ZdlfMcQMzUagysKRPf4ARQp/1tELK2GxyLNLcEP1vAcmEcjj6C8tc9duH9sBbOkD1rxdp1I28FlePiUkok0clwGDoK6uOOz5nDEiB7vZ2eavk+wOK8YBqF662ZCFrhssUTpOBIr/RDOnctZtQPs7BFV+1Ws72BYYrT7NVzmulZ/uTHiTmem6qxK77pgZvm0vY/7bS60CfxuEM/Py2JXC5t8gZpkDsor7p+j6+t5IR1F4bO8sOozr2ZRzDiEXyGIuYHxxtEpNBfGQMIKVh23P5XRTzY45YWS3iNrfAQsmEFKX6luUD4kVVgsSV1W/QtyImh+PUNI7k/k6Pwx/0/QiEk6vTIKB22wdGsbVbY3tU16yREOL8sXSkjRUwtLGT2df8pNv/407gG4VcdfQuw+nMzwz+TnZQBvrz2fXWDNMloiNfcKvmWv6SKHmthO8wc/QY7Eu++62vb3iE61zZbeM+mxn5tWj+U3JIjlhkKjxaN2iT30PckDQcYnmqpN5iHUI53Mom50wSjjgCIhqxS4r9FRdgiAs9Styc5moX6FhVSBLMh0oF1T3ONZA2POxoQDeydOgAjCu+22DzyDnr5WaGBxcXEc+aiSK5Ow6IaH/MxWh77pt3faFDtFkeUg7BrNADZQINmPYYKZtA0RpJxG524ZxVy/TuMwkKysGrapNWLkLkVyILtZ6CGVaGWrzYqMHvMmxzwqtJ+x5ZEwz8jCb4xanWZtar/xjxqcQRZB/Bi0GRaY6hPxcczRZbX0UcDjExR2MH6uoRhXcJTiu3IHpqw6xPrr6STuEOxqo5L/U/kaSyvfEgWY1YtHgIKfv4C2+iEOWIQx0SbMZ6cLrmwcfFmtKDjPMFweD5SuCgdmrrNfvGzr+6mnE0GCauQFDyoR8Pg6MBlncOZtT+7B9dah9QwsSgumEChGhJ1c+hfncxCqNly9XOfnW3Mghj91FXoQzqTKM2kfOw+GTWoeeVu9bUmHUJaQCj0K7krNFPjlwQ0sqqdSTyNTshucL8jr2+okvya5AOD2/kGg1z0La2G9OvyxE81pM9Q66fhvog/wX0mX6hOYbM3SDmLoVuL0bWnTbJ0gNqClViWZFcTjMQ== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Maik1gW9ngFz2pm1KhiEeq8cWw1lFnN6gmkDW40gmFbIZ4Rr908u2OMjS8g0tbMeucm58S6BAQlxIv6B05wGEw+KTun1Xuj48h9kfnM/EuhVh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IgP25feCxsqaLXOS7MbmmJEU/8sOLyndytfb1/31i+jtSGjLD18BVWZrBsF1N5LlBNOEN9P6wngRuzELcF2tkYC7OFMHBPV5w/K1n/buI0obfLBa0YWcOPdGbn+7jEHCVufJx5SrpUCLxFU4RE+uiKiwCHAToCIjC7a0OTAdO1wFqMhhyYRTRwr4OPXstgo/OiJOw9uKiNutpROGWtoswkvzXYTIn9VziiESHLPxQxAn4cNhxHoQ0FBYFNLXSGiqKfYf0DQCQK0M4Arqw727Ul2X6ZLJJ1zdXqvMbuvYeH/CGt20973WnwafbYjkLuXic39kAvcPzPVOv6LvoLzZUIyHSiS3du+OOIvUx6TP2Vh+hY6NbFdq4y1fWZY78zjNEDwEZwZotXbw0Ts0zT/dZ/ X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ccba819f-276a-4b57-94e8-08dc9bd52484 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:12.4477 (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: FlRcdbazQjWPUZCeqs574QbEm+AEo90ozxKhGRQBQcPuvXiQU9I80evvR81CF0VxvHxUqnr9HMFXMBsHH0sHVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCfy-00010i-Ah Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu Signed-off-by: Sheng Yong --- fsck/inject.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 2 + fsck/main.c | 2 + 3 files changed, 126 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index da4356d..b6f5c59 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; @@ -73,6 +98,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} }; @@ -123,6 +150,21 @@ 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: + if (!is_digits(optarg)) + return EWRONG_OPT; + 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, &endptr, 0); + if (opt->nid == LONG_MAX || opt->nid == LONG_MIN || + *endptr != '\0') + 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; @@ -140,6 +182,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; } @@ -315,6 +360,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; @@ -324,6 +444,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 da58f0c..8527199 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -825,7 +825,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 Thu Jul 4 02:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723125 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 E8244C2BD09 for ; Thu, 4 Jul 2024 02:58:28 +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 1sPCg0-00070T-9r; Thu, 04 Jul 2024 02:58:28 +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 1sPCfz-00070H-Nd for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:28 +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=9JfHNXlW7FxB70zshkv6GRcNJPJIrNGl4CMKq1AiHa8=; b=iIFX6fqgYTmrRmAsPU5qvrFvqv YPSzFDTCLZT5EWMYljWjU00QqZbbkwluLo1ateMwZQnH297Rhf6ux+OpUMZWz7xJZG9oaNs/tRURf HILllt8DdqOKBSu6muHQH8rQR8Lb/PHCbS+gSSsvgasnKyG3tMJa09rKE9WXik7ntup4=; 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=9JfHNXlW7FxB70zshkv6GRcNJPJIrNGl4CMKq1AiHa8=; b=R5LMZULJMvDQNXmJkK2tS2Ol3D wPgSSDNzTjI5fdaYHmWsbANb9TwMkQLjImAew5cW9f94xT6b4hIuJqduPUktEOd+P5+s01VPCwJkO iEYKBt5qXc4Z9RsTzIRyd8VeG8OEHWqIh0A7zP/v0gyrP+cPxu9XBhrlI/Cx6/OhoT0M=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCfz-00010i-Om for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kXsiQ8R1YbCxIbzDf6sdnvmHzo+KikQh2HV0HgyJ/aBMuSieOSybkJWXRQHciwmotHKE10xY+vGiqE3cj3k2ur9e9HvnuonuUmma6seAaY2n0r4MXHxenMMdwnNsHxZUPuqRUpxW01dN4BrHU47yNNsoCj8OBacawfnLBkNxA6xvJL7kiPit6xvQagL1ON0B5a64EPeOjfABsu/JwaWTF90fPQcB59g+nrmPTY+Y5DyTI2FQ1ou+4qEMtut2fbkY9wIoNv3SIXkM1k81tcgUjNZ389JH2gNsTwsWuzQENZJiJBEThXMr3xq5oPpHlo6+8GKAAX1Wf313hi+LMF1Yzw== 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=9JfHNXlW7FxB70zshkv6GRcNJPJIrNGl4CMKq1AiHa8=; b=VQ5hmVbEJcNFqzKddRwSmptYzTKM/YeOibIQA/JWm8HJ3NOo5G2gnisjYsXTBh41Yu8TNWqWtCXy0iWZQB1BkVCW7Kuex9Jz/cwaw8NJDNHukc9ffz3eyko3LnNR0QkU6HIo7Tqpcz+GQe0gk5gYLW/oQy/M6EklJXIP5aMWsO7wz1Oco6Yh4ZwOJwkziajx1K5QqBOcQMNlp/3CyMmxj60vMNmog+go2wpBkWUUDVYeR/MrEi+aSDhttI9p1eNrSaKNUQDAM3do+AbQsWJS38t77dYFZEIZPco30tIi1b8yIozRBmn9ppEVn52KTkQeHQlG2aZBfjM3Yl1VMx6Ngg== 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=9JfHNXlW7FxB70zshkv6GRcNJPJIrNGl4CMKq1AiHa8=; b=Mu/wOLKQKdVCuF/eyIyrvnMonNA8QEF3skyLaMYvaSnQrcA71DnEuTzAVHymn2xXbB+AWB2m61vl2W7/RbWje3qNSJRMeuuUR5JoTqiilSnkqrfQuMMSePQDDv7IY7PUOqpSasjmLUtVHTTiokhXqq/JFxUY6Xd7yzWdxVdWB98= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:14 +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.7719.029; Thu, 4 Jul 2024 02:58:14 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:36 +0800 Message-Id: <20240704025740.527171-7-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: 958bfcbc-69fe-4131-5fec-08dc9bd52525 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: XmyAB56SknGQymJc/hqJMIlwMSGuggcfrgOk7v9SwYTWyGEHNHIAGFiv/esQ9wKjye45UnG1JW8m19ig+cR0u+POTenzw01H8N297iy+Q6tBnrHhNY6smuIkKOltmgcs5fmfR/+ztbWVqa0vg+uG74iaRwcyzqPdlpftD6oJLFbiAAl3oZvFVCzc8jslGWeTRkPLRYvHw1FBDPihTHA/HVA4KKF/oKOvRP3JOM+gbdm1zGBbWvAJQcahMd7NuiGFrAEjFAJ7k/sQqHgX7Xk+2YI/n+I6kjGg3QoZyljFyGx0VNhLllYlm4nX8xuAWhUireb6feknvQLzSSElKGP+Fjpk4qYyoB5rhmyZCWjPBODQzn3Ggc3My2ZKgUw0C4pzQxdm5nQs/1X7ym0y0MQ1kJf9BFn6rsatRPK0PM+emQqJWfIhV6SVSmmw7VzHgX3kBaVxibNaS6GDJ3bycq/6mnmmk+ICberXk0pmvLr9d3cc8yZPv6AB+X6CPxaLrXaX7jujsTjY0X/fzjCe1jgCB3wp7C132TMNBRofgK7fG6BKdMN2OMXwLiRYRK+W9K0wjyl5M8mhgyLpYbAGws2q32NojqKAxoDmJxPpni6uC/Sp/PkvKceQCDy42lQOzPhX9++en0thrWD5xcQWDoccPAQRyd/SVBAfCvh05lMSpkSyrRpHNznBHjWm7N8Ot0Ao/rXxMCSmDF+LeaIpO2KJEhcV3t4ihfN+Ebm1WYlEBkNpkpOq88u0CLUA0yjnCnERXSQrfGoOONkLAuJi+qqNVaDbdZXlKff2LfYJ9veyIs1F5V22aRjltcXej6juLqvTnPN7zkerwH67tS2Fo+ipau6Dd0ElddHkEbMGf8C5O6JnU2Y38VVhqeE5RD8Se99FSXwQ7lDPByU0XurOlMoitDMCHJJpnSkDDxLDaEQWEZROSX5OErrACyzcXoD4JNLgbgt2ie1muwNq0F01mSBGzg7NcmH7JqGV+KGShZlBdCmL7OTQ67Eqx/wYI8GUtTu2XuUvh8YEF1jq1OMD1RRBi73BlcD+2a9p6HMPsalROmPAwjrzs5r0Ldch6chi4ZmXxJxiz8BArGTPcxKPjOAHirA6IMTC8gF1+416mMCC8TPFYHihkq5VRdKv4/Fys6Ly64iDIiDAaQP429lorBs4dPTecUnINHfL2tvgUt9WqQgmD6RFsgE63KukMe9zY7Ia7KGhr+xuCLbZ6qRUvIvsdyOOOXe48ZC6toKus9EHrhC72c0oyHCkGJQ2KcKBxDbVcaOs4gMjPsSCc5d33Ns3knTQXW19WgWiJ7FKnQWJdneO14wh5JX5NKMiZMwgMtW2bmWtIgWs0o19uQV5UHMLxCzfvIpiRtBHGU4neUqlQ0Zyl+mZZFtam6A/KgepHza2PwzhMqmK8av28t3tbxNq/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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TDDZ9IppZj9ubc/Z3q5tz4/tRK5hWE+v2RaErRZ5OkR4EH/jF100nb5sypDeWzef9iEYBO5R4ZWrWt9XRWcwCFJIDYqkUbj7YAL7QufsS5Fs3Hc4KpZ41gCFC5NgkArdTv+fluADLb5U2EcOpEYU4O4jzodhrVBr/4rqPPjonN1dd930KmI46bUNL9Vip52rRtj+yJ2I/51ENexg5ObxQoT7LC+TmrILVnarMtRDmPNaGrvQZRWmgMkezFJlrHyoCqIbumeQmu54wVX4m6r+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yeLRr6rBKw7bjgtyriHOSuqmGXjbnB5MHEE2SAgIaVq0EtUWhCCUydJU/aGtcXxe+kWYdr0iVlu4/R392uc7sgHNeDYOewZtzlmSsxS7rkrgROSqOhI9KamWTZwGWRSRgwrL/4nKcDS5jjsrIyj3LvGZ/4FOlgNGSRp3dBL2hvicf88cA57jkI6AinOSPx9f01PFx2LM1oqD3cbdMDO/W0knydQ1Ak+rDqY1DV4D8bFtTWkXPkP1uNmZ X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 958bfcbc-69fe-4131-5fec-08dc9bd52525 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:14.1413 (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: ILi0U4Kz/I2PkH3lRnj2SCmIH0D2IhJ/1gEcOf+ARyilkgNV4bq8K20nF3bHuQB3vZfNPeYiUepGxuZwWivCGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCfz-00010i-Om Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu Signed-off-by: Sheng Yong --- fsck/inject.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 2 + fsck/main.c | 1 + 3 files changed, 136 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index b6f5c59..5799353 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; @@ -100,6 +136,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} }; @@ -165,6 +203,21 @@ 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: + if (!is_digits(optarg)) + return EWRONG_OPT; + 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, &endptr, 0); + if (opt->blk == LONG_MAX || opt->blk == LONG_MIN || + *endptr != '\0') + 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; @@ -185,6 +238,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; } @@ -435,6 +491,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; @@ -446,6 +577,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 8527199..bfdb5ba 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -826,6 +826,7 @@ void f2fs_parse_options(int argc, char *argv[]) .sb = -1, .cp = -1, .nat = -1, + .sit = -1, .idx = -1, .nid = -1, }; From patchwork Thu Jul 4 02:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723129 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 A2576C2BD09 for ; Thu, 4 Jul 2024 02:58:34 +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 1sPCg6-0004zQ-H0; Thu, 04 Jul 2024 02:58:33 +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 1sPCg2-0004z9-3e for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:29 +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=zUuIXMqloQyxW7GSOX+XY77UUnIMcrh1MT6Uc7daSjs=; b=OGa2/4Dt4ZpWRU5bRtNIydi6F0 HNV2a4gjm1rtay5R7uvK2sgPb8vI2Ddv2vDRDt+Tklc7pb1WmsrNXosbOMUmlte+xhXsR1dMlEFhN juqZ1WiXNgLImMUD9dK0zCpb0+W+qqXh7PBbagnbxl8+1XInlYh7rdRz57Np7tvKfugo=; 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=zUuIXMqloQyxW7GSOX+XY77UUnIMcrh1MT6Uc7daSjs=; b=KuUMm5MnjGAO/c8mzIxeS9KMEL 0ZgK27n5ejqOTj1APuFTahmrmSQzprQcEiTgwniTVXkt7mk6fSemiNP65TjxpyWxVucNMAqWQtUw7 RjNf4qiM6sZMHpobGe3Ydq5qlzG/RTHf4ABKQErx8jkZv7oXT9HH8qddpuxfQKMxMVEo=; Received: from mail-sgaapc01on2054.outbound.protection.outlook.com ([40.107.215.54] 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 1sPCg1-00011d-6H for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZM+SrCMqFaZH09CnIg0z76gM35KF70EsWD8ldqDHCyva5L8fdZamiO0g4Aq5JJPvTvcCAfxdB1YoopFODwHUYuMnsDnx18gDILCza9naKFLsX+OvISoXGgmV3i2khe8xOzf00kpocRXSzvbe1r7ZTkfyhIwFzv/5/TQb72jE/mpzz48aArjzIiFL2AdzI/mmtph65aNlKrEXITjo+fEod7sJrX9rWzscGRjmJPAwHqjPBKgiWfJcyklPgyMqdSapd/Gby8YIzaMz7yj5gLhdbjr8L4RiO1PYXbQLVeV7JTyn5G6rNA8j0Nw+VypJazdu5luWXWolsUMpcyBSpO4uiw== 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=zUuIXMqloQyxW7GSOX+XY77UUnIMcrh1MT6Uc7daSjs=; b=b1o0OfnFcIn9F81Je6haLJeD+UCqw2C2a2S+xio63shGbUNMKwW7t3PylLI6GNJvPT2SQFLmk5lS6vAo+tIG1LDouJpou0mG0L5hw66MImEmPFRMQfPmwoAgqavCG0WztlG2GvMTwhj6VbDasWAScTCZJLTUp/R/V/sPRTxCCpNv4M9hoHxVi37QmJ6a775LQ8iVIv0m2yN4mEDU//PUt+/JW/WTsatj4x+PK/9OhpixxB2bIw4g4fqGx9m9JbmwK1N1YzC5SuAu2t8Zjz0iq7qVdF8hjyqH4PNNB83o8vw1ItDbT8p4ythWiSxUJuREribam2DCiEuiQJJd/pGp7Q== 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=zUuIXMqloQyxW7GSOX+XY77UUnIMcrh1MT6Uc7daSjs=; b=oYTVLaA1Yr3+WIJOAdk8QqBQ84I4wU4SuhQg/0HpXYQxZ0JELPhBzTdQnzYRZwEt6ZScT9ZT2hFHXv9AA2wjXHVkAAbT/78wQz8NjH0pszNNh3F0IWJQZJ35rnFEjX1marjeodbGixWdm2vtER6n1ZLK+ajrVBqI2ZtjZWBKF+c= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:15 +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.7719.029; Thu, 4 Jul 2024 02:58:15 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:37 +0800 Message-Id: <20240704025740.527171-8-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: fe580eeb-9c77-4dbe-789b-08dc9bd52626 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: DRSAkxD3vRCzdj0hTlXkV+cwOi79qcrSpCmUzSq9dKtfxgwHMNPPFjJm/fUcq973DjTif8KzPCOVFNbNs5k7UcrUeZMgTIBc4ALc0p/MCi6PU9S9Y0NSNRg+4EtoM80kmD8RjZqx+gUA1eUWOWkn5b3wypvkphxA/nd2sLL7G015kGTki5mhTdDKmcZF1i/uoiG5NItk4D2j1Tjc6fE9BPSiZiwaqOMEIW5lpAob/9FrImLs7N88MK7Q0p+m9yvb7LHUT5l6vmPZdiclC0sUIsUBh/fXO1ZMKx7FCK97f7jPNGLwKDaChqU/Mp8556FKUO8vWtQpdtlzU8cE02RZyHr7gr6uiPcgkcL17V3BtiSmspVnjEs6jiV/XKMcmiz2UaGAgoPqYzVJM5VenLRgFGu5+QtdYuydDVMyJoIhcYw8vTnlUmNR0H1TGEA3uYTT2ulfdu/3bAImhOSLBsIYmQ8NTXBi67kv5EjzepIhq5+KLef+Jj7P0X+ZD5/EQhlj304xRB+7M0L0wFQGX9BDobJHqJ9OA44Ul9u/28O1bit09KSmtrdvXcfEfEEZnCYv77/AKE5U9a1fWcKUi8htnhyuMEKa1BAAqbnnyFJQn3pMAa060ixXuCcjBusOuYObTsAzy1Y/O+vxtdT59i97CSXu0irju4xiCgQlduc5Of89T7NKpFhFXWxvac/YlvefoOzg9HmR7MoVq0krYfZd3n+nHQDjk2XM+NS40i25C2WmfnRViNlh5zJE7MNCoeLQ89zV07kBDfkL2HE4I3ROpbXUNDR9m6iFz+BRU9MbV6FKHh9bjeoK3nI0XkSWk/jRXzHd1dXwIdziBc7wcRRki9cOStJhe3C426ZhJuVrcAFAgMz0f+pbYZWDF4pWgs9VssS4uVuroSjoxnMUKTQ0kQSM+HoAmkO3vWXUdIeZdknq1XUDxzzuwhUseRxi9eUvmmGwZIcBfxoRERf8ZPSmSAtAQLEms1ZOStIzzgtd/VF4z2x4SFdsrDqHFmvH8eSYyLprNyBeXy2K6A1CF0aMGlFbr6sfRVekcae6eI4pt9+RNMKZA17D2KwO4eicaLu8+vMZ9E012r47oNp/7Ty5/u+FoXkWUVFCxmzBRDNyH4P2R9HO2GD0t1iMmL69GOeK3eeHds9eAFQWoJ+NQ8ervmoM/vxQEIHcNYnrzc8jfK7zdUVb+EeTNs8gqOYYIcDFpH1xZ3m1Kq71xQC9cLg/GYsVCspfKsf458U7ObNHhNOrpVPjBCMJ7BEuESX6usRSADmh0dFa66e/TLPUGkMu8QktScq8D5MbSLKshBBpW7BLElsmhNib/3Yj3QaYP+orRZ/mYrrBT5XH+GsTFg9wOrcRD2uxb3iiH44tGTiHFtKVZYeTdtmjs0kDZiD95wNCgTiGrjb9SJdAjgFBslTGRA== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O/pFJBne6RZtLhPsWsVUJBTK0x14hAPumy0q6LHJ9cHwFMkstH9+8Us7ZaqpnMM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OBD/LtFk6sAca5bes99RqDgNECWzw8xhmdNkiawZ39Xq/TWX2QEgI4IlL52aHhXmpVxShDQG6l/RQwIh6+j0YxZvzQ30R0CF7D0MGzhkELiTzWBGzG6XPcifHivBAyQ8dUJalDusgRGZ54YB7PrAZSeB3mklCJbmzCP6iwtppt4BV9RvSeBdDOWyfuvZ+se5aKCcFWxQAmji8+fe7+jdgWGXpx1DUOjQSl8mmceqLiYYsdkkuf+I4ES7g/nPekxrS1iziTx2EISXPHMZKrLbeRPb+7wgg2vv8vxo9xDG2cQrK0eY5SGCSoL2Lv7kczZyK9agzb+/IavqKvTV6zUpLOel310K9QE2bebxk2yecS0OMEQrqm8l6pBTm/vxl1Km7+1omLacUW+pdOmNDTzCnb3j3GozolMzAlvOPRxgGGLo6zOQysSLVWLFDqernJloJHlBVcae X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe580eeb-9c77-4dbe-789b-08dc9bd52626 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:15.2420 (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: fxjO5Kk0uw+oxkUoGqCbigej0lVQtE6dCFttDLSVRaRI6hjM340ZCt3UY9Pgvm/OgO8V9uuycis+VEmhGhLSew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCg1-00011d-6H Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu 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 5799353..d6f8774 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; @@ -241,6 +277,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; } @@ -566,6 +605,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; @@ -579,6 +700,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 Thu Jul 4 02:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723128 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 9DEF2C38150 for ; Thu, 4 Jul 2024 02:58:31 +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 1sPCg2-00061P-Ds; Thu, 04 Jul 2024 02:58:30 +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 1sPCg1-000618-3x for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:29 +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=QCtAYjmzpWHd5wSlUx2o0NPuLZIfetrskU+CGIKzbm8=; b=aFUIa055HQ9O0V4PahMxqr9eFW xHGNH+xJDb/VE+TlGUCmpiydAzXye/1rbTy9YEq+6702CNrRhkGuIvaeqAM2eeguiWxnP0RQxuQcG yHZ9RO6/9CWnnrlBUHITjGPayzFxE8pjUr2OcCGJJgbucT7EthL5YWACDYCoz7qQ5ncY=; 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=QCtAYjmzpWHd5wSlUx2o0NPuLZIfetrskU+CGIKzbm8=; b=i63e/WFLXZMlWPD4cxu+0WAmB9 eywjxxRiWIT+iMHsTsFEAjur+jf53WihSWKtXdPSdHALpFRcLloXWSe14ss5dQH/R6bfYHMZmmPJY HyeOQcMef7ooqwTpnCSvMjofyOyrVAHmHL3EniMQrVfSiSMRK94GBP7fDnJ5Tj7GDKQk=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCg1-00010i-8A for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KcjpnN2xsws+HGA0mdZMCKjlQYcgml2QP56sT0ElikoCmIaUO3+K2pUqxzfyiO3cjyoIYWic8GXAq+rpSN0rWLyOT6fcFoDh6eSXPVqN2i7ycVgg1i3+xB/6iz4yiN0QhQMezZ1iBmjHZQFPrNJGzIa+dr/cR5lER8phVHlvXm78j0waQgmKsNnbb0Ewvl6jy0GfjP9rgUuSDsUl47PVk2NAv4TlEdu0rd3q/rwrBBiZQqdjT3AbOUb8Ie2X6vAozoo0hNpdzKqJ3Azyc5LOeCC948Ougt6yu/v45X0QUR460SNj0VD9JyJtZ/Ww2t9EBT4/siFpCd69ocV2Dwk2aw== 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=QCtAYjmzpWHd5wSlUx2o0NPuLZIfetrskU+CGIKzbm8=; b=SoMpLURA++t0fbAB1bNZnEU6sIvpQrJYCt0qP4zSJnHNZXsilhk09zqyBTJLITjLZMUTcGUqSS3moV3weKIegJnGU2/ZiRe0ain3pL92xIQUv9ZoWhzRbUQ7IxivL95GAYPbduWTL0hm50yPU4bbj0cRxJNylKqMkznowXsLFRqhObXyTBQDo45eOSkVpcmqI10r4BgV3I1xoWVnW0dRo6f2fGaAhbVmbQdBDPYGO6rVgrl1N0aiqNRFycOEsVTCgaApR6uw1YEYn7r4YYoBjwCviId/DIh5Wqdn0fRf28wOQ/iBC715g2qooYyGCJcaE9qkMg6BzXvGYj7xxyizog== 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=QCtAYjmzpWHd5wSlUx2o0NPuLZIfetrskU+CGIKzbm8=; b=uRwoDPziVul/sz+ejkJ6cTla19ACKEmssQdpw2QgnZk4HXXAza8NS3jgSc0yoDkreJpWRnXamDQXhN0qixokA8CNxnFC2CbvdUDUTc0x806nXI0d15KslwiXs/nk0EywADOnxFN4fvS+L/fTWZu2ivYRYYE3Ia+02nVu9nk1fH4= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:16 +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.7719.029; Thu, 4 Jul 2024 02:58:16 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:38 +0800 Message-Id: <20240704025740.527171-9-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: fc7656b8-1d0d-4dd9-eef7-08dc9bd526ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: H9kgEC+36xzp7y146ddLPnRiWTXS03a/ntWU019SdEys2Ix3h5OiYSo0GKbd+D3HesunaXorqdxfOmQahGRByyeVYqh0yaTuQX68N5FiC/KACU+tUPaJdHrnswR6yTFPR0AnllaK7LCAbgXLA3txHvoKPyfqEi5zv7xdDDNj+xG9aU/NCyxv0c4ciK9LWGM02Ch9Jcvj3D09c6Jn/iCJUlk98YfFO8aLb6jmfBXYY9GMLdfOajfm6strJdL04vBYzCr78D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ENThlJxjl4ByPfeXP+XMgASqMOX5ii3rGT3cZ3Mgh5Fkr6LfXGfrXAyZiF278SIZlCgagtBlA== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HEhOdWvGquqTLo3V9MJuE9+EtxwF5W/XX/FOwTPLiMrvMAyDIMqAbJ+PTyrbBD2HeEhQJGAdw2HN6unRr+lyUZw94lc/elmWJN71Ez6j5DvTj9hoVoxKrUCT2VYpb2JF0q+PH0LpgxW5fJvbto3IBO5ieGWzypHhcozL7NQeOICz9slMbxnJ1YPTsnz7ZiRyVwu2h6KXy9MVv3eyfsTqmDvh3PDDkz4n0vtDYy4BEGGQEr0NC79PnO/c5WCFrVwz8q9hQUqIoWdiIkaScJ6/jKnhPQKSie+enYqKQWG/yI9e2bcB0uajEpjgRCk0ditmkYdykfBk1P3yhP0fqqxtqnrr4GhgFVa5GEUnz61IimxnTRcMHVOQvZibgyVjEqLeozhL4rAs0itrAtEdS3DmGboru5F6HA08rSImMBy2vab2Px19mro2eS/aqDUcJsvVuaLQ0XCCt6vj/bPvmHmp+yhypax1R4YT/UkyJqoge8xOV8U6kzlP+mZSQQ9w/2vXICJwR46KfJ6Xkltej/AKPQ17UoKj2h00SufSpCCI9olYwD/Ti/rR0sjo7SpKrTd6k4XPsH8mEDsJ/zCo/fosc1lMio74s/GbkcFHvwPAm5tG32Vg7A9r58YqJ80lf7fLiRKt21gQ8UyyhHg7gTwO9UYamt/dXIgcbqORllRCtLeZn6zreo9XUPf8pcL6JG6xQ3qqt9+j3eS02soCQY3rAxDzK6YnrdgfxbezxWIXp7DZQ0z4+zh86Sv0kuYbIFY2TV2XqBmDWeve6Ldm/3u6fbxW95tYQSWTmGiPIXERqe3K2itf4g6ivAz/dREWvp82fabfv26/8CxvkgCTyfRHo9Ow6ZmtJglfNTvGL2giSGGm98L8F07GIl7xhejrD75QxLTn18Y8yTSLGXMYOKzFVDXvYMfCRmPKlBG0UcFqVKdPMnviHdrcOOGGupGKodD+cNsjxNsTEbKWZqQghh6mR0DT9XPHdzxv/dq9W0PYuVgcqY6un9am3btnqq7SeW+nAookzFiN8YcLH2pySb694sLWjkC0fvtjWksqgheTmCWyeamT/keoKyVbLaa2LUwpoRuJpd9/woSicUl2PiJ1YyJ8xuwjVx38X1sydGW9voGxpn09LUIELZoNZ/XctIl0pTFZAdqS0wMnqmvdhJM5rSuaLFR7pXvH+x2HBtpijw/C9GwZ7NxOvRLt5j6W/lIQO/GJ0oCShEGG6Y/RzPy9pYYAVrbbOkWaTueo0KFfuuZxu1LNrBjTbx7+J4/4aeSLbknAz870i6lIbjxYA425aMAKBjljVqYbAAQi38XxTsn3UYgwYHSJqBvUCqafkVT/mnMXsH+I/QWbf19t9WVhkREsFK9F88IKuM6ALQC3tJhIM42l56EbUh3Fpt1p0AjNNfGqeW9vwznz9VBUgWXU/J5XZPPAv8OCy81c7M/nCYcUvsoBPFfBkI0vLfJSZKknvSi+Qhff4lF+9wzFDoTTr8fSSfnSGtHfhJNKwRNwTRu/GAHVe5EFeYTHrgmOlm6Db3J0RCBPCObw/9mG/qTPCWDFceOR/ZAueeK3Jx4ocRSh5gf8AiLOWaE8qNyrNhLU X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc7656b8-1d0d-4dd9-eef7-08dc9bd526ce X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:16.3693 (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: awOqCmSbvpF2l3b8fjNT0ZK1KReBF5yOpWhBeH7MbGe+nnNCjdQMEupwZARzuYP60ICHlTyI79g6mfy6UeeHQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCg1-00010i-8A Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu Signed-off-by: Sheng Yong --- fsck/inject.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 214 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index d6f8774..2a21dae 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; @@ -170,6 +205,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} }; @@ -254,6 +290,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; @@ -280,6 +320,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; } @@ -687,6 +730,174 @@ 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 i_inode_checksum is injected, should call update_block() to + * avoid recalculate inode checksum + */ + if (ni.nid == ni.ino && strcmp(opt->mb, "i_inode_checksum")) + 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; @@ -702,6 +913,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 Thu Jul 4 02:57:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723131 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 83DFEC31D97 for ; Thu, 4 Jul 2024 02:58:36 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sPCg6-0001CO-IH; Thu, 04 Jul 2024 02:58:35 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sPCg1-0001Bi-ND for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:30 +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=q1hs1+hdANdVN1BUwneBSp0vasIxkCokM8rAz7mqWiM=; b=TStO4d8TpUosGGwxwKOi6v4om5 191qM0Eskpcp+Rr0xT7R0fgIW9m2t2/oRU5Nw8kWAX6zEtiaj7mXdMl6uVPkNIvpLJwzkGrZEmk14 Q4VlV0DQCeL+x8M5sCrSDCacWt0wweOlzoHsL2BxgG4srPLLHGEsfTTRTV1LkaaPIBnQ=; 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=q1hs1+hdANdVN1BUwneBSp0vasIxkCokM8rAz7mqWiM=; b=jdLRvIgefgmzZRPbOaEymFnQru fYa77y8ZeAm8/ors5k7hdBpX1GcPgy5L2SVDjgMiK/I+JVOisdk24H8cGX5d1DloQLATqylbM1ffG hSTE+I6WQ0U52MB7NA2WZdcp90rd10m5Sk27xpy8sgMmAdwjfofl4sl2j51ve25kspec=; Received: from mail-sgaapc01on2054.outbound.protection.outlook.com ([40.107.215.54] 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 1sPCg2-00011d-Iy for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lH9/N7l2Bn9b1uFmPGGxxef42+cJ5h0Ex2bJvJYHpNjL/LepExsxu5skskKq3eLJ9U0t3Q26IYYURAd2U7sjajkoplI/zP8P88UOSqztvk6U1Zy1bfQG9T5TBXR5i1jfyCFnou5Bztrlz6ocWUTl4uG+/glZs9xjKi0MdJF8x//P2hb7neUebydzlDu3YhHTB5LuNEpBRzvUW63yPOKXDLx/C0cuIMGUhiJmSmHe/y0NyANm5FSsWdTvSugbzRjdZgRuzPoM2w/JlPflOOdFVbOPW31D+Ua8ODueWxiZbWuNfFu/mQXhxeru9tPaFGb/Sfy0+HrhGRB/rCHUXg8Y0g== 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=q1hs1+hdANdVN1BUwneBSp0vasIxkCokM8rAz7mqWiM=; b=CMkCwfg+1nS8wpfWDMfYuBn9Ir3n7GCoK0qW9w5oKSJI/nus6kQ7sDBEt8SVlGF9RaQ8pzyDE+hZmke8KA3Y2xU/9YlRq8Iw/IER3wdu7aJJ67d7gwH9uclWw/X0XJP+Lr2lKOeSS1VuV9Sk/1z9xbXlEoD0PcxbAyQ0bkxF02c5C1qRrelSAIKYCBRooTjxJR0RvvnAFwiqMGlup3JWqmc42/k9m8oi03VPeHo9GNUGvwOYH0NTJzqenpn566xEwAbblMKlfErSR8GtOFU1Zs9sznXoIF2bUmov3dco0JgB6Mn56M8MYVpWlVlRoTk3BwOTRRtFDujpTTP2qq4e9A== 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=q1hs1+hdANdVN1BUwneBSp0vasIxkCokM8rAz7mqWiM=; b=hE2gvqg1PqWVnoH6POLnsu2CDAvEzrQU/t5vWa6PlsEYPmxJm/0MvflQPLAiwatyYSbZq+Hjn82rpKJxR0+qUANOWg01/8aZMw8YbyDm2b7YKeC01ufEkP7hAFrzwKocU83eCUHkgTiUulP+MmzTp9DWUFCJWp9tn1YbDsF6gYg= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:17 +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.7719.029; Thu, 4 Jul 2024 02:58:17 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:39 +0800 Message-Id: <20240704025740.527171-10-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: 03d015f7-d8a7-4412-2c53-08dc9bd5277e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: JkE/QnuoxwZrmvYXL6QUvCFoQhrTVakpL1yRAZMBQXi316BhbApOKB7tVJewpBGfuYiy8MFKwhl6UaPVdlUUiYBuKJePUL4SF/z1BkUyemRctampgqlNTe+yX0oPwdMUnyKZy7ptQbGn9yllZBDLUSLltEFRipuCYLZbQJg47oFTwYMu+Wj1/mINv1lEtSe5HS/PaFHjTjZgX4qL594C/fB+LyaDnvcj9D2bo1k1RZjE9nPgUftlRvFfIMHBhPHEbdMuie5Y74ajsrKhAu+5AYtNGhIJob3Ps9xLcBGsFk825dqj8/mzxDKpIGmtre2UCPvtYHkYvyQutBKyG+Gvwo7odJFB0/MHB97zOJ2Kq6h7c/bvEOUFrysklJ/5VNLsc0Ls6r0KIpEKFDm4XfPQjmH2VBwltP2r5xFpIcqJKeXvAz/5bGYCmSHrp8Vdifxd+ZTOZIsFn3QhCbEBEdS6nRUtYwLOXHmK7TzBwQJpsjco/LdETnerrPtONckv1WxusSVumjX3epu9n+8DUiCykmmMohkOlyQCPt+Dq6gE//ea6roilLMgJwjcGaZVeNTaSiUby6cIZYtz8FC+CmsrAITTXqIdNgye4Jc8mKDMHRFQ6ocPwpho/TtVkybzM6ilFBmdSTT0lGbki1ergkqREseYmixoMAknYwUZX2/LBk4iSbXo4b/6dDv9bJinpkVr67tiE6F5NpNtDWxE2DJSrZVKnUYsB3MwnyYcSLpX8E0cLGw5TWgInk1cvAv1hSJd/TPNx3SLxoSuyjteOddCsBdFx5C1MSLc+GCdziLO/0uk9G/PfeuB7PdCYTdoM5xYOsPG4kTDTB/VjVxaelnXlXqFVvbQX6kyFZQSYEak4zEVuaHvLVMZ5cvftrZ/UCgWXjX/j12p+gRHMD5pwJliV6er+vnSm9GVNJebbK5Kw2/JuY3Q31MagwpBT5acyzOKVF5KaOmHbrAbzqs8Sb0pgDntm7DGJ2k07QRRENLlqhMPSGwhajva6dhcOvPS3v1igNA1DGCc4yZD8/3+uEV7udQ+aq4/5jk6A/NXVeFVbVLqjos+C+2G4NwknUCFK8VQK4ijTaB+3vCAkBzCDj1Ef1JbyNH+uKCzEzetguraoSpdemYb4hzky3+xvsnZMDA2Iq2kGsALHW9YKgKn90xcRV/mx4GxSejty7RY/+W36lpD/AeyizgZM6nzvWGzmKBW8UjTVjo91fvyI4qfdbw3Zly9BHNGR6blzB6fCL25t+ekV0Yx+g1wj01B64Jsw3sc2IRy8Vd8zPxvzNldpnrHSuKU/3ZDwo2d5W0zqRJMDb7qQBz93t5JHUVLw+eEkayOOHkrtC37cnbAaAJlbfOgjR2oBnf81Zi2oTBoG8IVtIwHw/uOgRMXNbcqkBbYhIxzS0yCoLYsulhtpeO1MP/S6Q== 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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4vJ4JCYWGCWofz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msnEsIelB4sf7f42h5BGQH7tnjx9Ksg3mD3sjrOdvxJaGuJIFYUo6sMJGytOw2Dy2y8MTgpLyyH6/HU/1SIA1LBnrGVqOwmsCDgrNeF/IrtUDJFruGujWal9YmIxU7AKFSkfUc2cIv2+WpDo7vM2kdOUscYa+M+cR8i7Mcjzvhsohl+Y90mnWNvCeQc34vAYdcapqW1MIiITFQ8SoVfydXOAeymgbmve3+3dJcftCMjxQagr1A+rDYUNX/h1vK3pglDwzSr0M9aj1BQZFjudjKN4/ZczRhwR8MbVL5VroZ76PaftNaMunQ4czqYpVPbGkxNCmHo5WEOjpY9oS/YC0MWGD6VcgxNTDft/rA+iPWrS40w3Mf1whKnG+b2olCsG7JWs9NNuLpUq9DtiLqNQ+AqVtM2Kjoa1O1QHnwIixgIw74BlH5fNPLKAT60armUNpBh/oiomyxB2KVFD03ihjg7uPc9Q0kp/+EAGRSUNL1+bQaY3q/zuUGCA X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03d015f7-d8a7-4412-2c53-08dc9bd5277e X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:17.5010 (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: jnf+B7mu3xhF7wp27TELnYUSUMI1WXOjQgds6yy2weA2EWN5AVlCQ7Un/4BR9RLhWXBRP+faTcu4jWXcHA9v8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCg2-00011d-Iy Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu --- fsck/inject.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 185 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index 2a21dae..a7d2a2c 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -10,6 +10,7 @@ */ #include +#include "node.h" #include "inject.h" static void print_raw_nat_entry_info(struct f2fs_nat_entry *ne) @@ -74,6 +75,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 +104,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 +199,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; @@ -206,6 +229,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} }; @@ -294,6 +318,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; @@ -323,6 +351,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; } @@ -898,6 +929,157 @@ out: return ret; } +static int find_dir_entry(struct f2fs_dentry_ptr *d, nid_t ino) +{ + struct f2fs_dir_entry *de; + int slot = 0; + + while (slot < d->max) { + if (!test_bit_le(slot, d->bitmap)) { + slot++; + continue; + } + + de = &d->dentry[slot]; + if (le32_to_cpu(de->ino) == ino && de->hash_code != 0) + return slot; + if (de->name_len == 0) { + slot++; + continue; + } + slot += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); + } + + return -ENOENT; +} + +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; + struct f2fs_dir_entry *dent = NULL; + struct dnode_of_data dn; + nid_t pino; + int slot = -ENOENT, ret; + + node_blk = malloc(F2FS_BLKSIZE); + ASSERT(node_blk != NULL); + + /* get child inode */ + get_node_info(sbi, opt->nid, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + pino = le32_to_cpu(node_blk->i.i_pino); + + /* get parent inode */ + get_node_info(sbi, pino, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + inode = &node_blk->i; + + /* find child dentry */ + 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; + + slot = find_dir_entry(&d, opt->nid); + if (slot >= 0) + dent = &d.dentry[slot]; + } else { + unsigned int level, dirlevel, nbucket; + unsigned long i, end; + + level = le32_to_cpu(inode->i_current_depth); + dirlevel = le32_to_cpu(inode->i_dir_level); + nbucket = dir_buckets(level, dirlevel); + end = dir_block_index(level, dirlevel, nbucket) + + bucket_blocks(level); + + dent_blk = malloc(F2FS_BLKSIZE); + ASSERT(dent_blk != NULL); + + for (i = 0; i < end; i++) { + memset(&dn, 0, sizeof(dn)); + set_new_dnode(&dn, node_blk, NULL, pino); + ret = get_dnode_of_data(sbi, &dn, i, LOOKUP_NODE); + if (ret < 0) + break; + addr = dn.data_blkaddr; + if (dn.inode_blk != dn.node_blk) + free(dn.node_blk); + if (addr == NULL_ADDR || addr == NEW_ADDR) + continue; + if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC)) { + MSG(0, "invalid blkaddr 0x%x at offset %lu\n", + addr, i); + continue; + } + ret = dev_read_block(dent_blk, addr); + ASSERT(ret >= 0); + + make_dentry_ptr(&d, node_blk, dent_blk, 1); + slot = find_dir_entry(&d, opt->nid); + if (slot >= 0) { + dent = &d.dentry[slot]; + buf = dent_blk; + break; + } + } + } + + if (slot < 0) { + 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; @@ -915,6 +1097,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 Thu Jul 4 02:57:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13723130 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 70038C3271E for ; Thu, 4 Jul 2024 02:58:35 +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 1sPCg6-00071b-RL; Thu, 04 Jul 2024 02:58:35 +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 1sPCg2-000715-UN for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:31 +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=2c1EobU3iBL3ITOx1tLgmqk2H2KecIqK18n40b2rZOk=; b=f28as2CUfTSKqvub98DfYFPOQA LXQKBjAy1M5jCkkZ9Y5BUjUkvSy3O5DIFC8ZJK29S/qYVGwLC2u6Gyi1ybPMooLH1zu1N1zGnRycT 06yJFLLzvn0CE9yUYtyYAowpDQeDYyCAkVQHbLpMAKq4weCYVQdwgv/Lhv09AzVbe2eU=; 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=2c1EobU3iBL3ITOx1tLgmqk2H2KecIqK18n40b2rZOk=; b=LormLVlzWbWRbql83Iu7vKS26B uYh7B/B3eJ7a0LOxEgDPnV+J8MzSZMQX/kRuEol4lNOMZf32CGkhCa6JfMkv00/0/ffh5cFCgy6Cn kzahbaXz5jIQL+618GA8xIY07F2YwVOE3OHPLOysytZ2H3wpJCtKgfj+WDcUszHs6HEQ=; Received: from mail-sgaapc01on2042.outbound.protection.outlook.com ([40.107.215.42] 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 1sPCg3-00010i-6z for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jul 2024 02:58:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X4nRGNGRU4NEpDyeDWzj7pmPz6jiZMZLNXykKbWVaYg7dFF1tBeiyBuJHqqaCgWFDXvzEBMlBg+amDO2pY8EIQ/ZdgYEczOAFfbLtIsxs3ox8AnNDm/O/TJexC1WHHmD2IqH3SvdJAYTru48BWYKjQ9WyTurwQUeJ+UVlEHJiDGugocB1xACto+Xb0A1qwg9BmjeCh7w1Y/GoXcUYQOuSlzoC0PDOqmTd8pWLpLA+OrzGVLLnFC5kmEBlrWMcIoYWQxNzNqFUfSccPA0CURL9BiR73ADiNjx4zeIoCLncbF3Cgq26oo1jDJxhDvnuj/hqjts+xBXPBCOjVZX53fVUA== 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=2c1EobU3iBL3ITOx1tLgmqk2H2KecIqK18n40b2rZOk=; b=eF3dLlwPvlqJBMdEU98OSLyXMHD3BLirH9ek3YWHKLr4TMMYD3wqcFHmPVgZdkeotv9G7aFr3vEVkBJz/Zsu4dX6F0AHerWMp+H55miiwsAXcrSYVLyNY5UpC3aib4NihuQSrEBiooiJsfmxbf/Ri18zq2gPdgxeaOJNI1u35QQJ96CbcPoYrdW9tDILmg1HOS/7OoZ/fGCpjTFQQBXfSpnsLHKv/oAOmAICrFdbRY/qeG5FbTqNe44coIUnlhk/CmT9lJIfAvh3pRE4GP4euzcVkkBmyg3A30pie0wV9w1p4qBVa/ga8kTxQBL0xonceaWPclaDgQrkW2aqrw+Bwg== 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=2c1EobU3iBL3ITOx1tLgmqk2H2KecIqK18n40b2rZOk=; b=QrofsM9iYgwilhLIRaIi3voWpYVOlLsAsA4q19KBEfE9rvIEwHM5rHE7lrQLZ+wcVL/sBCefXD5oaVMcuauUvHKL2ffNmNpR0OFdf7xGjPRRahDQIHFy/1vLVQA3LaAP6+TYWK8jln7mHuJoU4WP6v8mtOVkN0xrcBJqEiFtCk8= 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 SEYPR02MB7733.apcprd02.prod.outlook.com (2603:1096:101:20c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.25; Thu, 4 Jul 2024 02:58:18 +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.7719.029; Thu, 4 Jul 2024 02:58:18 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 4 Jul 2024 10:57:40 +0800 Message-Id: <20240704025740.527171-11-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240704025740.527171-1-shengyong@oppo.com> References: <20240704025740.527171-1-shengyong@oppo.com> X-ClientProxiedBy: TYAPR01CA0220.jpnprd01.prod.outlook.com (2603:1096:404:11e::16) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEYPR02MB7733:EE_ X-MS-Office365-Filtering-Correlation-Id: 2bb77452-f573-4105-c7ae-08dc9bd52827 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: rMaK3HA/m7AY5MZXgvSYypvlNtufNlij4weOEnylxnytyUcbI8XJRlJ4jM/veHcnQ92rlk4Vx64hPr94npwpzTjRLhMZBm4mM9plEz3sdjScpgXru57+qPDGteiyxL+/zE3Ca63EgXVR6rN8S7WeqSkHu846Hz+HwTbBQcB4gAvgSoftYz6xw5EmaZIQpeNsKC9t5zaOYhcJu7iv+cf9nDeytEGM/o2UonML9mP/+JuZsDusKiXVTCT+dQ8GsglefI1A/W0h22iduc9BCznFEq6YeIt+NaaWHE+sf8G+4S2+HBCLZlxDNo2nkybzDTh5F98SxBWJxrNdeWOBtttc6cyfrYa4ZUbeTbf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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:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Jm9wVcBFu6+rO2C9KFWL1ytibIXAkH4Zmn1Nch6dDV9t3t8EqjGlHEHC6nSWYvQjeKnO9MesY0ZmHfsKJ3MsuQcs1esmvPz54+vIcU0FBK5k3FIqxQIwANvmML++AuACwT70iUpQ3pvoR+If1UiF0XFpkME1FgS12NxptjL3HDXsIpJXnqZ7B+h3NvlOQyiqtZxqf0cWgNFIGg1JqUWClsobc+p7gYjsq3IMlazljv1cJeyfE8OrWhlHwJd/WUtYYJjGqhBlAPb5XqmJg91JCKstKbiB2mSZ9tDaIeNXjzvm6nqtgliXSBljPZF9x3rmwc+IRbQUv5O5aazDcoOWXHKFzEUd4md+pvQO5hJAgLeJtqOfmmae6IAaNq7HdfYPXTfb25oj4EZ3NLHMBeR3rDY0prDH7XEjRrDquQgFIC1m80Rp50KudR3c8oqNZKn1+u6xpqLkTJMTrXZYpRCqqMX4DaM0B14zzvEzTMEqzbBl+WXakSLCTcG/LyPLo0WhIBRwMRlXW1YJnWAfzCdyuJ2pbeNwVBZPWqxovWTG/WVopDoRj0pm04HkGNmItpM0M9qv5tdNysj8x+rjnKSgsr4gLLiST1TO/S3wXr+l+6KC4CtMotKOFjB11IyTncoNg7cYL3yKuygNp15YEYa4zkVMi8dGsT3iqND9EJjO6e/bfjAkmUUcc0biIju+B0LQ3j7AS8Soj+NW5um88gxokZ25GGOGA05IeNMbQ547dEOFPygWQdG/Sl94nrZA+HDgXyuNt794jVUOadBAL0XT00c7fH59CchfH9gvQnK7uWlJgLxMyJ/q1kiDGuKYpbSkj5+R9ZRVIQPDaS1Josy7my10pkTJZmbLZq8J197frxMgPqg9aOb1NXglPsbnAlzO57BLMkmXI0mBS4oGFL9Z05xL1x+8R8WrBMjGkQDJRnBv7tVjsblBVsbgG3dUOyfrnPHeKDsO4xrVSoR5h7bq63Oi/B2o2AUsNbOvgN2HXmYvAHgD0s2bq+DIHy0IdcJyNrhLHlPwd+Ka6+oHaKwIeWSpQyMD4Y9Fabfgir48bq6f+dyVEf+95BG5GL/hpn+p3LH2nLAGa543r6nSpq3bAGPcLIcw9tGHe8CidRlKFQvQhfIok5f+PyvIIxkaLbkanHD+VxzkNgRzjXo9fl6Jm6EypbIqnGf1Ymx87AQe0RfQa+3qgds6zKsiJuVMYM3vNM3KanJBgdfcWUlUVZK9XS+NBIX5LrKXaqByfscgODBwCTdU+qD877EiXJDTPjOifiFN8fhlOylrt4sUc5l+WJJhOtzq/0di6jSJSZhO6bWBP6s7oopKwURlz51mAtUKup9YVB30FFeAcxxG8QUjCJw4GQwmQg/CP5bI++Wa/JO5pDJOkotczkxv77hCPR4KUpptA4EVHwByT/GME1rLDolzWNmX2uQs7DeBgF1zZ4dAXC/t0Z7uhbPa2n4KjQ8FLO364jjC99RjYRHHrr/uKwblN2Qldw83/mn35P6X4CDTZLYl0s99bNtwWTdSqWBhv+BkFVrtDbfsuUjD+RAt4vSIkB47TPkg65CyRdZIBkL/wYf0No3B1heK2BHTwlPc X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bb77452-f573-4105-c7ae-08dc9bd52827 X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2024 02:58:18.5613 (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: SybQkeK5hjmYw746bY3UwEAS2tFJ3MRs+Qj+P5GjZem6mWBDAeMsWScyQtYy9JQ9feD7iWnjhgpIZYl56DRIeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB7733 X-Headers-End: 1sPCg3-00010i-6z Subject: [f2fs-dev] [RCF PATCH v3 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 Reviewed-by: Chao Yu 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).