Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp810934lqt; Thu, 6 Jun 2024 21:43:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1dD6jRJ3+VwqGHQapOSLN5XwWdXgP9T8wMxJjaxAVHUx+Fv+9oQnlWNWHKnOhaeWkm50+pqjKM+CUwM+jMkkT6OfwWceTHSmb7jI5GQ== X-Google-Smtp-Source: AGHT+IE8NgMwzutRRd3qXL4Z4zJsU+oJZ/Ijp93NETWA6BViGRifLgXyjeS8ae7HB+tZJxU81JfA X-Received: by 2002:a50:c319:0:b0:57c:4882:3e3f with SMTP id 4fb4d7f45d1cf-57c509a7dbemr620144a12.27.1717735403270; Thu, 06 Jun 2024 21:43:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717735403; cv=pass; d=google.com; s=arc-20160816; b=q0WL36qDoGAGM1rISEpR7y3CqpVeXVubDvDVf0enzzGzdd/JU/KtqX2BHCAWM5MUj0 YRlfyqdEuSSvC1pAWJbS1kS5GzevLQMphozrc/CjYCHCZdFzmXh2f01xvKsK6X9Ju8tU of7lzzda8/wFpAyn7yx9bTpB/KmFrMsQwzqtwwfbcAzH6680GoruGbH0wZxcxpweGkD/ I3NaqQyOgnUxKhevJlbE47c+L+pxQyJWNAJbL9Xf1weKBgacvCndsn9HpNdn8hwbt1Qt Q0aE0IWTq0cOFMCEdX/W36d3SPoQ4eIzXPVioVO/jpmaavVyMYW0nR5jA15t5mnuqvUS Gg+g== ARC-Message-Signature: i=2; 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=QE5g8RPnwusKOTRuYKyfQyTkrwluhoS5aHv/QqmVEHA=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=CCU87Oztqe0j3eLpc5lHlQhOb7XGKJL8OdacYl5Fhp9qNOJsUM04mtV1wwMOx6gXxi GfBEKPwpPW0gBv6UxKwl3b+CPryp43zrk7eZIau3+FViyuc30pKYbYWIQD6zKWdNfCY/ 2M8XQAYjF5z99vXHjBqlRqg2PNzFRg5Ob33jQ/gNhDu/nw5X7VJY4YZDUCjJrzC1e7fH zTN9kYkjjF4S5B5H4Tjj37umOfmB2iUbJQYJSHBGAenMguh3UZqoQaEue9B5nCOx9c5D r+nFsvmoVmyOvH58zKqchrlHnfgpJHPr5WSsekjT0Q1RZd/wXnBzH1nLF70ahQ4v+esp qgvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205346-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae0c6660si1365975a12.25.2024.06.06.21.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:43:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205346-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C6B8C1F233EC for ; Fri, 7 Jun 2024 04:43:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 135D615E5DD; Fri, 7 Jun 2024 04:27:40 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 4116215AD99 for ; Fri, 7 Jun 2024 04:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734453; cv=none; b=hl+GI34DMmXeCgJR5jbI4CLd/m4tTJbBETn3vPxfqsoluhsoNmaqO8dBgG4Cz5pBzh46kussnfKKuFwLHNFkksmbrikhhbJVhiN0/xl2y7pb6Iw9l2NHMX5nKOeajZY04Vj5/r2N3ZaQRwDsLPIW/624PCTubc+FZSF+Trsa3fo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734453; c=relaxed/simple; bh=YpmmaI5uCiwrl9HICNRlp8QNM1o21Go0LRC4Wjv/mrQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mpB/0U/JVBUYpwbKBXWE9AMwPMrZX6d1RsSNmaRbttjgX3hdWNX674gcvQ7wGPYAIxWojQ1H38m2F14hsIQUpVNtB5PN8CJP/mZa65iC95U2vMQn5Sww9f3bYIXvmxArc4NKatO5AmdLV76/VYTAjJjT2tR7KGBL6ND5fDS+j+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 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.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VwSk722sLzwSGt; Fri, 7 Jun 2024 12:23:27 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 32409180AA7; Fri, 7 Jun 2024 12:27:26 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 12:27:14 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 065/110] fsck.ubifs: rebuild_fs: Add valid nodes into file Date: Fri, 7 Jun 2024 12:25:30 +0800 Message-ID: <20240607042615.2069840-66-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607042615.2069840-1-chengzhihao1@huawei.com> References: <20240607042615.2069840-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 kwepemm600013.china.huawei.com (7.193.23.68) This is the 3/12 step of rebuilding. Generate file according to left valid inode nodes and dentry nodes. Based on the results from step 2, it is easy to understand: Step 2 has done: valid_inos - del_inos = left_inos valid_dents - del_dents = left_dents Step 3 should do: Traverse left_inos and left_dents, insert inode/dentry nodes into corresponding file. After that, 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.), which will be done in next step. Signed-off-by: Zhihao Cheng --- ubifs-utils/fsck.ubifs/rebuild_fs.c | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/ubifs-utils/fsck.ubifs/rebuild_fs.c b/ubifs-utils/fsck.ubifs/rebuild_fs.c index dbb0f3bc..a86430d0 100644 --- a/ubifs-utils/fsck.ubifs/rebuild_fs.c +++ b/ubifs-utils/fsck.ubifs/rebuild_fs.c @@ -476,6 +476,61 @@ 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; + struct rb_root *tree = &FSCK(c)->rebuild->scanned_files; + + this = rb_first(&si->valid_inos); + while (this) { + 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, tree, 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) { + 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, tree, sn, type, inum); + if (err) + return err; + + rb_erase(&dent_node->rb, &si->valid_dents); + kfree(dent_node); + } + + return 0; +} + +/** * ubifs_rebuild_filesystem - Rebuild filesystem. * @c: UBIFS file-system description object * @@ -509,6 +564,12 @@ int ubifs_rebuild_filesystem(struct ubifs_info *c) log_out(c, "Remove deleted nodes"); remove_del_nodes(c, &si); + /* Step 3: Add valid nodes into file. */ + log_out(c, "Add valid nodes into file"); + err = add_valid_nodes_into_file(c, &si); + if (err) + exit_code |= FSCK_ERROR; + out: destroy_scanned_info(c, &si); destroy_rebuild_info(c); -- 2.13.6