From patchwork Mon Jun 24 13:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 13709573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B662DC2D0D1 for ; Mon, 24 Jun 2024 14:28:41 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLkgT-0008T2-6C; Mon, 24 Jun 2024 14:28:40 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLkgO-0008Su-Fu for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:28:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=OlSocSyEzPzcyw8ZE82LyfwgjU u1cpRRO9F3er7WSDu3skc2O1ScQVL0ICnZi1axluqdLmKoesfzOoU6UtuUWQh+Db9t1XgnOwns6d5 bO/5AP1jnj/mtOq7FE0TCrvnjElJtP+NrElAgv8vhWTE6VUW3ZTnSOogdlPm2TtigJfY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=fo7xwrYsr5o8F5Nkq3jRVTDoqm 3qjET72cPtABFfOzNb44XkO+kL7jpI6HCmHdkNaz4bbgG8EFmAenCg1jx8V+k2IVZAdDVu0pjrlVG b29X7c1+hdM7oNkSKfrAMeEzy/rMc1jbyyxg4Dzdmobe74L44atvS6bdNdkdDj+7YHwA=; Received: from mail-psaapc01on2078.outbound.protection.outlook.com ([40.107.255.78] helo=APC01-PSA-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLkgN-0004fL-Bf for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2024 14:28:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NMfXUDlK8RrqnzHqCUx4gxUdEhcsar5HSggFkqt6O3aXaMCdLKuxE9nYh52ZHBaDqGNXOK0dZJWW5JlsZjnn/poJjYeXcJ/MBPf2fm55FJCGQJ2T4f8GNuwIAHY/Ev2QAtmAWihg7eS/Aki5s0dbfQ1wKqjfQceLyqzT4zDL82/95FzzC/2RyQeg3DhXg4BccAnOyjqJWJvtqIXlyWiuBopYGi5SFiRZuqf9wiB87V1PQ8hMXFBy1PwIhAJJzg/wAOXVsDrOmLZkf4LP2FIGh4oaAKtcVHEU4Pywni9q7oGmXH9YWERYrICeOanJEdvZ8VJaOJaFbul02CCnLYn07Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=CoF+2sjr1bSTQU/mSeHB3lDpifR3bbNLB9gL0f9AqqWVvlgNy0iXFzi2Drtvn2SkPY3Ayg8+MCbgmcwADrRWhUu3shLWYfFSzkR3XEIcFDMzg/KfkXE1mplyPK0aFwLDubD9v43adgRJwAviZH6C2NSPees0levIvUv3mVt6XIy0q2grtVbBGxohtFnSac+V0mxAP7leXSaTZGYLCcEG4e5qXWdDICpTEwhAEBF8dY0CQcDDKg83zuVdunJzO4z9I8JN/s3HPQ2F9/zBOI9YLi5re6+Xnaq+GEdowuRGozYMHuFK32LTCX1A5WLfsWiOSxz3qAx5MUnEj5Dc9KL0/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KWM2n9SD88FaU7l5JNb4ykZEpdLFdKPp1BXOouJeSWw=; b=jHywBCnBiqrz1c+aapGJUa6jfX5cy+QEk9hxaTyFFs86ZxFLGw6fGEDL3SrVbnyA9DNYo55J/K4C0JdHGOxTZ+Ls0aq9Wg7ea/CTXYkwPXVMG9UWLK4Amemk+j6rh4bx2g9+TXNFkcmZYKA3eCDAIRbi6BKPLSPdOcjjtvplaRg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) by SEZPR02MB7515.apcprd02.prod.outlook.com (2603:1096:101:1f8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Mon, 24 Jun 2024 13:56:04 +0000 Received: from SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796]) by SEYPR02MB6014.apcprd02.prod.outlook.com ([fe80::bb06:c283:a50:7796%7]) with mapi id 15.20.7677.033; Mon, 24 Jun 2024 13:56:04 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Mon, 24 Jun 2024 21:55:32 +0800 Message-Id: <20240624135532.3330136-10-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240624135532.3330136-1-shengyong@oppo.com> References: <20240624135532.3330136-1-shengyong@oppo.com> X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To SEYPR02MB6014.apcprd02.prod.outlook.com (2603:1096:101:6b::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR02MB6014:EE_|SEZPR02MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 7069de40-4faa-4ad7-c3b6-08dc945563cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|376011|52116011|38350700011; X-Microsoft-Antispam-Message-Info: 5KVBvyxBezSbhwudwbjV29fYlphLb5DwD/T80yln+5BRAwg0p15AgwR1VdR6pSK4monwDYl9S6DNWONIRJ84bsd7B/j/UUc6T9R6MZcmqip6CKYm5Nc9PdVjZfeft9vS85TRV6pmy+8a9xNNR1e/U2BfGpEez4fr3rdHz+6L1XOeHmtVOTIQmOkSY8F/1z9ttzBoZEG7QvyM1Q/Poy02GKN5epQvrE4ky5myLEbf/17nsxAfEIsLH1hXmxWpTaLROE7lP7UrFdcRRRBxqVeLFenLPS+Hqw7v1UQDkGU4J7fSj9QCc+L9kw/JR62ZeRlQ/JMLHvWbr7S27a9tiMUwi672W9loM8GJnM+oO5iPFZS19F5EtTdtZp0VFxA6sjUZYFOvKiUFF6a5Jmd8uSq1GKQBcIoKxZacrbuBb9Hj5dVBrNKhUfCTI+USNDEBzTSVm2sg8/zOYse71ixgL+oMJzp/eJ82NBKQq3X5mFt9gYWM2vSJWqav2Iet3YtWyWOx4t5ZvZyWn7lFtvdCGOR98Wuc47d/Gcc6eVc94YJBiEGLT9S3A/IYtMIC9x/JboHfQaKCUmYEBS4sMID+hbyjQsznHtGTKin+03uEDz89uL+dDruTyL6ig+ZPCyFbpuPsYFDKUiqCiNmRsTtqsa2N3fTuR2mDywM2yWILOKJL+jZJOYiVvhgABzaQrToIrtXEKjRC1GJgPFJcfCHJqPB/PVX4h9MkpQsgPcDOzSdx07zL6kRj07m4flafHuAwO50w1Fp4aQijOFv0t2D9RCS5nrvDg0GE0NXyiuAhSIpn94fJ3zeBhvX/Ji48RZhswZanICIG6adiKtHQJ7IxnQtsdzpCaALhtMO5hJzujTG0QAV6HXAzUtAdMzCly/Cb2IEWLeaZw4Xy/SbKdn4O7Hqh4M/Y3syb5Z7hYaJ19pHo7uZSuuxDoPig+3gn+6Hw7vx3e9Ek9uKop01yo1APVhd1CUVsovrnY+dXZSSw0bLSOtbcqS+j+JQ/NEp5CHP7i7bUX2OeP7zsPivt7fyzlyi0m48eNuQAd5dDzMxm3qqBcZbfP/na7dvicfVAZ5A8BDF4ujCKL+YYI9Q/HxdhAcrlKHQ55iPmTo1RUqRDuYY2NobQ3GB8kYPAnkyMkX3YtjokM4PifEbGy/g+HFl3AfMvkLn9J6qWUhb1X7elHZB2FrjO6HsgqmMOOKF74Mp4X4aa3y6xA3VsxRq0isHA2EFkwk6Ncj3tbEnXtiPUxjUvvgNQfyym4MRp/iHo+kyCMlBIsBTZKOsvTfiEXNcQQxtbNwtucCAlwochv8CNTVv5jiBDPOdSlAMwLokGF9SnBFBsETAQlkVZUpv9eyX8fUGAgrquXb8FNaLidGjD64xTw+c= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEYPR02MB6014.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(376011)(52116011)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eZviv5sY6+HnyMpOQ+fV7APlNZ0eQT4JWKIu0j/NLw5ctRUXgbhXr4ln5x8qN3G2Cnut5aN3ftwlnijKsiuRGjmrnfyNcn2aJWZ4N10U4FnIIcHNJrPNNVDZ259ZU/exmVBrKHwo3GmNgPVLMPnaV2ArNicPwaedgVhZ0N2knlcbvYyjgFZUYb2Nk3fAhwT/njnLdaOJhig/r69HEuc8T9d2NC9nHEcHQbo27XabTVXz93r2YcxRMENNa/HCnx/vz7WG2S+ZPTh6lGn8ivCL6NZmrBgmTM2naCxcnj/DgUMqDMdHSPf+A9pFRHCjEpmnpZbu5XrdZLbMyuI6rORxMK/P/gaCQxKdNP+KwOk/DylUC5pHoLpDwnHmkSk7uctlmM2RjwXWesDhSvtvnrqoHXBcgNX/dnITx2Z4FVG9sNLuJh3pS78dFlgo39E/yx6DEhgAbEtNnqWloJt6Z/wciFTeP0vvg/sz/aalmyR+MC2Iz6VlITxj+FTfTZrILkNgMl+FOsBX8+oO9c/jYkoZaEBxVuxtok+9qXd9piFsY1GhTWpaN7Bg37agpKIX4QZpKbtK7uX6QqeIzl3fLXoBvT7O6Le8ja88G314T5ykHiWzMr1/89yVm1C38XDprrggMu6f0T5nwQILUaeveRnjPuUyQV7Wo7WZAeFEapWFc2eKfq/Ozp7CZEX2wJR9RymU70Tt9TRte0HRj3kHaNfkSx/k1De30JA4qBSh9l11+B7w4TuH5Ra4axRahgzWYZ+efJz7nJC4Ix4ZylS2tH3QStDqLi0ON2ygRLKm3P7Iq/JvLpECmZbZH3klpJ8AWfxylvGRh/8m9hCEgMaNTAb5fdZ6RL8kVlK6KSw9xI5b5NTISjzn6tyQ1ZXVGjaxrB11Eo3UP99XJVpQeqMDdrhkP0veAjt1ljikkpNnfL9Zwgvio3bNuWy59w4QL076PGUQUl4AiSYu4MV16S6XjSNWE9xqrrROghTkJyK18zm74Kke+Mku2Ijtu16azd9n2j3UElpnnU5t8GXreuG01Iyvb69Cu4+1RmViX+kTZfZplNhi9bOb7kPnJP+mDWpwcQNHGMDBxAcQJYyavJpVSJ0rXJbDtYxod2ihoU9mqVP1FBeztoBiLxHyD6m7nHiE8QrGAZkPCskwPzWVo12p6z5kSYA57FN08YDVwrxiNT9zR/3vROvTLz+nl4wGzxNCBccjb1XUvTOOGNOVTD7+2T0cBhFWHptiqDOE9+Lrk33zTpQrOZriOuwm9onEtroUwkpvRGVJNRSqvOinEyApWACfbaellSMut1gJ5e5PQmbqakdRDAC3Af9AqzzDboTqJIDKe3ob/D/05uWFNGPO3mD2h24l4ihFlm6F8SFc+3HeZeUQSWshIR+xXOMEBJY/hAALWt2qYdRczeAsHLD/zuturCIs4bCzZotMeOUrsd2Ay6r4uyxH9EsL37vvJEt5xucOeUooLxWKt8nzOFRraWGlTnAevXtY0kFZO6nFl9v1aSdpaOaU4Cn9BGDoBRXB5Yw3cB00D2gq8NmRjH5IZWE87r4/NbgEWXzWKXUMU06UXfJZSTlzoPfzLrnyuMLErX8Y X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7069de40-4faa-4ad7-c3b6-08dc945563cd X-MS-Exchange-CrossTenant-AuthSource: SEYPR02MB6014.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 13:56:04.8915 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 96uq2pMVvyy40T4cnnOrVVrw99yfirSn+lb6ffUk2P/NzkR4rgz/awiuW2+ZxuEkFRwGVexniENV/uuLEVu5zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR02MB7515 X-Headers-End: 1sLkgN-0004fL-Bf Subject: [f2fs-dev] [RFC PATCH 09/10] inject.f2fs: add dentry injection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sheng Yong via Linux-f2fs-devel From: Sheng Yong Reply-To: Sheng Yong Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch enables injecting dentry block or dir entry. print_raw_dentry_info() is added to show values of node footer. The meanings of options are: * dent: means dentry is injected. The members could be injected in cp contains: * d_bitmap: dentry block d_bitmap of nid * d_hash: dentry hash * d_ino: dentry ino * d_ftype: dentry ftype Signed-off-by: Sheng Yong --- fsck/inject.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsck/inject.h | 1 + 2 files changed, 149 insertions(+) diff --git a/fsck/inject.c b/fsck/inject.c index 20ae87c..3d26b25 100644 --- a/fsck/inject.c +++ b/fsck/inject.c @@ -74,6 +74,17 @@ static void print_node_footer_info(struct node_footer *footer) DISP_u32(footer, next_blkaddr); } +static void print_raw_dentry_info(struct f2fs_dir_entry *dentry) +{ + if (!c.dbg_lv) + return; + + DISP_u32(dentry, hash_code); + DISP_u32(dentry, ino); + DISP_u16(dentry, name_len); + DISP_u8(dentry, file_type); +} + void inject_usage(void) { MSG(0, "\nUsage: inject.f2fs [options] device\n"); @@ -92,6 +103,7 @@ void inject_usage(void) MSG(0, " --sit <0|1|2> --mb --blk [--idx ] --val inject sit entry\n"); MSG(0, " --ssa --mb --blk [--idx ] --val inject summary entry\n"); MSG(0, " --node --mb --nid [--idx ] --val inject node\n"); + MSG(0, " --dent --mb --nid [--idx ] --val inject ino's dentry\n"); MSG(0, " --dry-run do not really inject\n"); exit(1); @@ -186,6 +198,16 @@ static void inject_node_usage(void) MSG(0, " addr: inject {in}direct node nid/addr array selected by --idx \n"); } +static void inject_dent_usage(void) +{ + MSG(0, "inject.f2fs --dent --mb --nid [--idx ] --val inject dentry\n"); + MSG(0, "[mb]:\n"); + MSG(0, " d_bitmap: inject dentry block d_bitmap of nid\n"); + MSG(0, " d_hash: inject dentry hash\n"); + MSG(0, " d_ino: inject dentry ino\n"); + MSG(0, " d_ftype: inject dentry ftype\n"); +} + int inject_parse_options(int argc, char *argv[], struct inject_option *opt) { int o = 0; @@ -205,6 +227,7 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) {"blk", required_argument, 0, 11}, {"ssa", no_argument, 0, 12}, {"node", no_argument, 0, 13}, + {"dent", no_argument, 0, 14}, {0, 0, 0, 0} }; @@ -280,6 +303,10 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) opt->node = true; MSG(0, "Info: inject node\n"); break; + case 14: + opt->dent = true; + MSG(0, "Info: inject dentry\n"); + break; case 'd': if (optarg[0] == '-' || !is_digits(optarg)) return EWRONG_OPT; @@ -309,6 +336,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt) } else if (opt->node) { inject_node_usage(); exit(0); + } else if (opt->dent) { + inject_dent_usage(); + exit(0); } return EUNKNOWN_OPT; } @@ -879,6 +909,122 @@ out: return ret; } +static int inject_dentry(struct f2fs_sb_info *sbi, struct inject_option *opt) +{ + struct node_info ni; + struct f2fs_node *node_blk = NULL; + struct f2fs_inode *inode; + struct f2fs_dentry_ptr d; + void *inline_dentry; + struct f2fs_dentry_block *dent_blk = NULL; + block_t addr = 0; + void *buf = NULL; + int ofs; + int i, slot; + struct f2fs_dir_entry *dent = NULL; + nid_t pino; + int ret; + + node_blk = malloc(F2FS_BLKSIZE); + ASSERT(node_blk != NULL); + + /* child */ + get_node_info(sbi, opt->nid, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + inode = &node_blk->i; + pino = le32_to_cpu(inode->i_pino); + + /* parent */ + get_node_info(sbi, pino, &ni); + ret = dev_read_block(node_blk, ni.blk_addr); + ASSERT(ret >= 0); + inode = &node_blk->i; + + /* locate dentry */ + ofs = get_extra_isize(node_blk); + if (inode->i_inline & F2FS_INLINE_DENTRY) { + inline_dentry = inline_data_addr(node_blk); + make_dentry_ptr(&d, node_blk, inline_dentry, 2); + addr = ni.blk_addr; + buf = node_blk; + + for (slot = 0; slot < d.max; slot++) { + dent = &d.dentry[slot]; + if (dent->ino == opt->nid && dent->hash_code != 0) + break; + dent = NULL; + } + } else { + dent_blk = malloc(F2FS_BLKSIZE); + ASSERT(dent_blk != NULL); + + for (i = ofs; i < DEF_ADDRS_PER_INODE; i++) { + addr = le32_to_cpu(inode->i_addr[i]); + if (addr == NULL_ADDR || addr == COMPRESS_ADDR || addr == NEW_ADDR) + continue; + + ret = dev_read_block(dent_blk, addr); + ASSERT(ret >= 0); + + make_dentry_ptr(&d, node_blk, dent_blk, 1); + buf = dent_blk; + for (slot = 0; slot < d.max; slot++) { + dent = &d.dentry[slot]; + if (dent->ino == opt->nid && dent->hash_code != 0) + break; + dent = NULL; + } + if (dent != NULL) + break; + } + } + + if (dent == NULL) { + ERR_MSG("dentry of ino %u not found\n", opt->nid); + ret = -ENOENT; + goto out; + } + + if (!strcmp(opt->mb, "d_bitmap")) { + MSG(0, "Info: inject dentry bitmap of nid %u: 1 -> 0\n", + opt->nid); + test_and_clear_bit_le(slot, d.bitmap); + } else if (!strcmp(opt->mb, "d_hash")) { + MSG(0, "Info: inject dentry d_hash of nid %u: " + "0x%x -> 0x%x\n", opt->nid, le32_to_cpu(dent->hash_code), + (u32)opt->val); + dent->hash_code = cpu_to_le32((u32)opt->val); + } else if (!strcmp(opt->mb, "d_ino")) { + MSG(0, "Info: inject dentry d_ino of nid %u: " + "%u -> %u\n", opt->nid, le32_to_cpu(dent->ino), + (nid_t)opt->val); + dent->ino = cpu_to_le32((nid_t)opt->val); + } else if (!strcmp(opt->mb, "d_ftype")) { + MSG(0, "Info: inject dentry d_type of nid %u: " + "%d -> %d\n", opt->nid, dent->file_type, + (u8)opt->val); + dent->file_type = (u8)opt->val; + } else { + ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb); + ret = -EINVAL; + goto out; + } + + print_raw_dentry_info(dent); + + if (inode->i_inline & F2FS_INLINE_DENTRY) + ret = update_inode(sbi, buf, &addr); + else + ret = update_block(sbi, buf, &addr, NULL); + ASSERT(ret >= 0); + +out: + free(node_blk); + free(dent_blk); + return ret; +} + int do_inject(struct f2fs_sb_info *sbi) { struct inject_option *opt = (struct inject_option *)c.private; @@ -896,6 +1042,8 @@ int do_inject(struct f2fs_sb_info *sbi) ret = inject_ssa(sbi, opt); else if (opt->node) ret = inject_node(sbi, opt); + else if (opt->dent) + ret = inject_dentry(sbi, opt); return ret; } diff --git a/fsck/inject.h b/fsck/inject.h index 9b14c31..43c21b5 100644 --- a/fsck/inject.h +++ b/fsck/inject.h @@ -32,6 +32,7 @@ struct inject_option { int sit; /* which sit pack */ bool ssa; bool node; + bool dent; }; void inject_usage(void);