From nobody Tue Dec 23 14:13:31 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 8F872EADF for ; Thu, 28 Dec 2023 01:39:30 +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.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4T0rgD571Xz1FGNZ; Thu, 28 Dec 2023 09:35:36 +0800 (CST) Received: from kwepemm000013.china.huawei.com (unknown [7.193.23.81]) by mail.maildlp.com (Postfix) with ESMTPS id A40321A019B; Thu, 28 Dec 2023 09:39:13 +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:15 +0800 From: Zhihao Cheng To: , , , , CC: , Subject: [PATCH RFC 15/17] ubifs: repair: Write master node Date: Thu, 28 Dec 2023 09:41:10 +0800 Message-ID: <20231228014112.2836317-16-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: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000013.china.huawei.com (7.193.23.81) Content-Type: text/plain; charset="utf-8" This is the 13/13 step of repairing. Since all meta areas are ready, master node can be updated. After this step, a consistent UBIFS image can be mounted, and it should pass all tests from chk_fs, chk_general, chk_index, chk_lprops and chk_orphans. Signed-off-by: Zhihao Cheng --- fs/ubifs/repair.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/fs/ubifs/repair.c b/fs/ubifs/repair.c index 42124cda5d7d..f2600bbb1431 100644 --- a/fs/ubifs/repair.c +++ b/fs/ubifs/repair.c @@ -2225,6 +2225,8 @@ static int traverse_files_and_nodes(struct ubifs_info= *c) ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), c->vi.ubi_num, c->vi.vol_id); =20 + c->highest_inum =3D max(c->highest_inum, file->inum); + err =3D parse_node_info(c, &file->ino.header, &file->ino.key, NULL, 0, &idx_list, &idx_cnt); if (err) @@ -2404,6 +2406,75 @@ static int clean_log(struct ubifs_info *c) return 0; } =20 +/** + * write_master - write master nodes. + * @c: UBIFS file-system description object + * + * This function updates meta information into master node and writes mast= er + * node into master area. + */ +static int write_master(struct ubifs_info *c) +{ + int err, lnum; + struct ubifs_mst_node *mst; + + mst =3D kzalloc(c->mst_node_alsz, GFP_KERNEL); + if (!mst) + return -ENOMEM; + + mst->ch.node_type =3D UBIFS_MST_NODE; + mst->log_lnum =3D cpu_to_le32(UBIFS_LOG_LNUM); + mst->highest_inum =3D cpu_to_le64(c->highest_inum); + mst->cmt_no =3D 0; + mst->root_lnum =3D cpu_to_le32(c->zroot.lnum); + mst->root_offs =3D cpu_to_le32(c->zroot.offs); + mst->root_len =3D cpu_to_le32(c->zroot.len); + mst->gc_lnum =3D cpu_to_le32(c->gc_lnum); + mst->ihead_lnum =3D cpu_to_le32(c->ihead_lnum); + mst->ihead_offs =3D cpu_to_le32(c->ihead_offs); + mst->index_size =3D cpu_to_le64(c->calc_idx_sz); + mst->lpt_lnum =3D cpu_to_le32(c->lpt_lnum); + mst->lpt_offs =3D cpu_to_le32(c->lpt_offs); + mst->nhead_lnum =3D cpu_to_le32(c->nhead_lnum); + mst->nhead_offs =3D cpu_to_le32(c->nhead_offs); + mst->ltab_lnum =3D cpu_to_le32(c->ltab_lnum); + mst->ltab_offs =3D cpu_to_le32(c->ltab_offs); + mst->lsave_lnum =3D cpu_to_le32(c->lsave_lnum); + mst->lsave_offs =3D cpu_to_le32(c->lsave_offs); + mst->lscan_lnum =3D cpu_to_le32(c->main_first); + mst->empty_lebs =3D cpu_to_le32(c->lst.empty_lebs); + mst->idx_lebs =3D cpu_to_le32(c->lst.idx_lebs); + mst->leb_cnt =3D cpu_to_le32(c->leb_cnt); + mst->total_free =3D cpu_to_le64(c->lst.total_free); + mst->total_dirty =3D cpu_to_le64(c->lst.total_dirty); + mst->total_used =3D cpu_to_le64(c->lst.total_used); + mst->total_dead =3D cpu_to_le64(c->lst.total_dead); + mst->total_dark =3D cpu_to_le64(c->lst.total_dark); + mst->flags |=3D cpu_to_le32(UBIFS_MST_NO_ORPHS); + + lnum =3D UBIFS_MST_LNUM; + err =3D ubifs_leb_unmap(c, lnum); + if (err) + goto out; + err =3D ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, lnum, 0, + offsetof(struct ubifs_mst_node, hmac)); + if (err) + goto out; + lnum++; + err =3D ubifs_leb_unmap(c, lnum); + if (err) + goto out; + err =3D ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, lnum, 0, + offsetof(struct ubifs_mst_node, hmac)); + if (err) + goto out; + +out: + kfree(mst); + + return err; +} + static int do_repair(struct ubifs_info *c) { int err =3D 0; @@ -2463,6 +2534,12 @@ static int do_repair(struct ubifs_info *c) goto out; =20 err =3D ubifs_clear_orphans(c); + if (err) + goto out; + + /* Step 13. Write master node. */ + ubifs_msg(c, "Step 13: Write master"); + err =3D write_master(c); =20 out: destroy_scanned_info(c, &si); --=20 2.31.1