From nobody Thu Feb 12 22:03:10 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 25E2860B8A for ; Fri, 7 Jun 2024 04:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734464; cv=none; b=dxiCwiLc6rQ69+3lwHcYqijAXPTAPw2x+OiWDrwGRq/YGvzAz7sgS5y8YgZ9YFBK83llMFRjcduZzfvsUg4h9IrlG96vQ++Rk92T36/S++Sh91460aevKvoI+CWdffkXHY1AdR9XNTGj4B/BpF27rKEnIgubM90mkbTKfOFfUaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734464; c=relaxed/simple; bh=76w+3CDTfjp/pa3E+o/4BSA/lnfPkin7Nv/v431dY2w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F4GsUhxM3kahtrdxMvkAlUbWWpV4BXMOZdarmESx1na+T45/EWFPC+aFq6yVyJIkZJTZGYMYamhZWCN+ANEpFRL+FTLlzcM1m0RdMVRXa5I4N3yF/IEkX/Ii7eIB9ACMIIFf4K0MqTLeWt10Fz9oHm3TnCrbVnHF7Uooz+qt+f8= 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.255 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 szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VwSkP4dvtz1SB0f; Fri, 7 Jun 2024 12:23:41 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 6211B180AA6; Fri, 7 Jun 2024 12:27:40 +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:21 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 074/110] fsck.ubifs: rebuild_fs: Clean up log and orphan area Date: Fri, 7 Jun 2024 12:25:39 +0800 Message-ID: <20240607042615.2069840-75-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: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) Content-Type: text/plain; charset="utf-8" This is the 11/12 step of rebuilding. Clean up log and orphan area, all nodes have been recovered, these two areas should be cleared, otherwise old content in journal/orphan could be replayed in next mounting. Signed-off-by: Zhihao Cheng --- ubifs-utils/fsck.ubifs/rebuild_fs.c | 46 +++++++++++++++++++++++++++++++++= ++++ 1 file changed, 46 insertions(+) diff --git a/ubifs-utils/fsck.ubifs/rebuild_fs.c b/ubifs-utils/fsck.ubifs/r= ebuild_fs.c index 085df2b9..9ea4c224 100644 --- a/ubifs-utils/fsck.ubifs/rebuild_fs.c +++ b/ubifs-utils/fsck.ubifs/rebuild_fs.c @@ -1312,6 +1312,39 @@ static int build_lpt(struct ubifs_info *c) } =20 /** + * clean_log - clean up log area. + * @c: UBIFS file-system description object + * + * This function cleans up log area, since there is no need to do recovery + * in next mounting. + */ +static int clean_log(struct ubifs_info *c) +{ + int lnum, err; + struct ubifs_cs_node *cs; + + for (lnum =3D UBIFS_LOG_LNUM; lnum <=3D c->log_last; lnum++) { + err =3D ubifs_leb_unmap(c, lnum); + if (err) + return err; + } + + cs =3D kzalloc(ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size), GFP_KERNEL); + if (!cs) + return -ENOMEM; + + cs->ch.node_type =3D UBIFS_CS_NODE; + cs->cmt_no =3D cpu_to_le64(0); + + err =3D ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, 0); + kfree(cs); + if (err) + return err; + + return 0; +} + +/** * ubifs_rebuild_filesystem - Rebuild filesystem. * @c: UBIFS file-system description object * @@ -1383,6 +1416,19 @@ int ubifs_rebuild_filesystem(struct ubifs_info *c) /* Step 10. Build LPT. */ log_out(c, "Build LPT"); err =3D build_lpt(c); + if (err) { + exit_code |=3D FSCK_ERROR; + goto out; + } + + /* Step 11. Clean up log & orphan. */ + log_out(c, "Clean up log & orphan"); + err =3D clean_log(c); + if (err) { + exit_code |=3D FSCK_ERROR; + goto out; + } + err =3D ubifs_clear_orphans(c); if (err) exit_code |=3D FSCK_ERROR; =20 --=20 2.13.6