Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3700931rdb; Wed, 27 Dec 2023 17:41:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGR6rCwQy5xtegBaIMSm8mjWPqkDuv0YYu/ZcPulle5xyv/8HOjqP3gaJfn7rPZtMMG7+q X-Received: by 2002:a17:903:228a:b0:1d4:8a75:a6c3 with SMTP id b10-20020a170903228a00b001d48a75a6c3mr913795plh.133.1703727667289; Wed, 27 Dec 2023 17:41:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703727667; cv=none; d=google.com; s=arc-20160816; b=Fyw/CJCKRWvGkuMW7wLdlnC3XLREz1rSXW6AKcvvX2iwefcgUgkwofmDFhuxAW+FRv wSSb+r09e/oMi1gV1LqPUYrLZPBgb5uMfhkBlDLwCNg6Cdgh8B7L2aPWdK/1Wr504QLB cm4qrqqPgxRHW0wKwnR2menTO45qF/4cIut+olzgTeRilLu5RHd8xvRXQth2rHcaUOEX srt6+X0SUeoouEN/2qG4ex9waZfzl+30Ul5STgpfaDYJ2B1y9cJmCvzOf2+wtxtJzYyk aZbpn0sDqIkUi7R+V7j557j0qaCemqgzQDy5mqw8YHJoi5OXFm2yNu5t8j7MrUcs6a9B h63A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=24WByi1X1CAy8om8CxC4dZ0HuTnn8at14iPmbhe+3IM=; fh=3kaVOPShTC55oj708yh1yJALapWuogKx6Yvc3sQq9zY=; b=PZBwOqFWMwcckX4TbiF+QL3emUdip6P8gBPjpQnBVMh5puNPuMHg/boKaR2YkuXrOQ c65PwCdBVwwXZVX0wnueFMjVcS3w137dv41wp5a5RxSyBJvJgh5tNAKNc+H7DveYunyV o2DtEGhpIkOXb2lqyUUV5Ki4yMCNG853WeS9Wf7gbJ9eiGtBZC7ClbeSPRlfFYrKJOBE 7Ydt1QHzXkB5leTJekVkqgwzzumWsMAXZT2xLEcRGeO0qTVaeV2EGwW8JdM8IGfHpXBm epccwSUsp4+zDMg0YwdIjublWg93KTO0koNTCOscHuVwp0DCxtMO+mDEA0yt4+QJLHj7 7EzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id jh12-20020a170903328c00b001d3d66cfdddsi11968433plb.336.2023.12.27.17.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:41:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 429B9B22586 for ; Thu, 28 Dec 2023 01:40:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39C5179D2; Thu, 28 Dec 2023 01:38:19 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6E606FAD for ; Thu, 28 Dec 2023 01:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4T0rjZ00SdzWksy; Thu, 28 Dec 2023 09:37:37 +0800 (CST) Received: from kwepemm000013.china.huawei.com (unknown [7.193.23.81]) by mail.maildlp.com (Postfix) with ESMTPS id 135F91800BF; Thu, 28 Dec 2023 09:38:09 +0800 (CST) Received: from huawei.com (10.175.127.227) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 28 Dec 2023 09:38:08 +0800 From: Zhihao Cheng To: , , , , CC: , Subject: [PATCH RFC 04/17] ubifs: repair: Add valid nodes into file Date: Thu, 28 Dec 2023 09:40:59 +0800 Message-ID: <20231228014112.2836317-5-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231228014112.2836317-1-chengzhihao1@huawei.com> References: <20231228014112.2836317-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000013.china.huawei.com (7.193.23.81) This is the 4/13 step of repairing. Generate file according to left valid inode nodes and dentry nodes. Based on results from step 3, it is easy to understand: Step 3 has done: valid_inos - del_inos = left_inos valid_dents - del_dents = left_dents Step 4 should do: Traverse left_inos and left_dents, insert inode/dentry nodes into corresponding file. Now, all files are generated by scanning, the next thing to do is dropping invalid files(eg. nonconsistent file type between inode node and dentry nodes, file has no dentry nodes(excepts '/'), encrypted file has no xattr information, etc.). Signed-off-by: Zhihao Cheng --- fs/ubifs/repair.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/fs/ubifs/repair.c b/fs/ubifs/repair.c index d932c16ec893..7a1732ef903f 100644 --- a/fs/ubifs/repair.c +++ b/fs/ubifs/repair.c @@ -1043,6 +1043,62 @@ static void remove_del_nodes(struct ubifs_info *c, struct scanned_info *si) } } +/** + * add_valid_nodes_into_file - add valid nodes into file. + * @c: UBIFS file-system description object + * @si: records nodes and files information during scanning + * + * This function adds valid nodes into corresponding file, all valid ino/dent + * nodes will be removed from @si->valid_inos/@si->valid_dents if the function + * is executed successfully. + */ +static int add_valid_nodes_into_file(struct ubifs_info *c, + struct scanned_info *si) +{ + int err, type; + ino_t inum; + struct scanned_node *sn; + struct scanned_ino_node *ino_node; + struct scanned_dent_node *dent_node; + struct rb_node *this; + + this = rb_first(&si->valid_inos); + while (this) { + cond_resched(); + ino_node = rb_entry(this, struct scanned_ino_node, rb); + this = rb_next(this); + + sn = (struct scanned_node *)ino_node; + type = key_type(c, &ino_node->key); + inum = key_inum(c, &ino_node->key); + err = insert_or_update_file(c, sn, type, inum); + if (err) + return err; + + rb_erase(&ino_node->rb, &si->valid_inos); + kfree(ino_node); + } + + this = rb_first(&si->valid_dents); + while (this) { + cond_resched(); + dent_node = rb_entry(this, struct scanned_dent_node, rb); + this = rb_next(this); + + sn = (struct scanned_node *)dent_node; + inum = dent_node->inum; + type = key_type(c, &dent_node->key); + err = insert_or_update_file(c, sn, type, inum); + if (err) + return err; + + rb_erase(&dent_node->rb, &si->valid_dents); + kfree(dent_node); + } + + return 0; +} + static int do_repair(struct ubifs_info *c) { int err = 0; @@ -1060,6 +1116,10 @@ static int do_repair(struct ubifs_info *c) ubifs_msg(c, "Step 3: Remove deleted nodes"); remove_del_nodes(c, &si); + /* Step 4: Add valid nodes into file. */ + ubifs_msg(c, "Step 4: Add valid nodes into file"); + err = add_valid_nodes_into_file(c, &si); + out: destroy_scanned_info(c, &si); return err; -- 2.31.1