6 Star 5 Fork 56

OpenHarmony/third_party_e2fsprogs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
0024-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch 2.35 KB
一键复制 编辑 原始数据 按行查看 历史
f房芷仪 提交于 2024-04-08 10:31 . e2fsprogs升级
From f7c9598655420102353ff87946f5bf77ebf465bc Mon Sep 17 00:00:00 2001
From: "lihaoxiang (F)" <lihaoxiang9@huawei.com>
Date: Tue, 29 Nov 2022 14:58:12 +0800
Subject: [PATCH] tune2fs: check return value of ext2fs_mmp_update2 in
rewrite_metadata_checksums
Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
failed, multi-mount protection couldn't guard there has the only node
(i.e. this program) accessing this device in the meantime.
We solve this problem to verify the return value of ext2fs_mmp_update2.
It terminate rewrite_metadata_checksums and exit immediately if the
wrong error code returned.
Signed-off-by: lihaoxiang <lihaoxiang9@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
misc/tune2fs.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index b1e49b3..cb5f575 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
ext2fs_free_mem(&ctx.ea_buf);
}
-static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
+static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
{
errcode_t retval;
dgrp_t i;
@@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
rewrite_inodes(fs, flags);
ext2fs_mark_ib_dirty(fs);
ext2fs_mark_bb_dirty(fs);
- ext2fs_mmp_update2(fs, 1);
+ retval = ext2fs_mmp_update2(fs, 1);
+ if (retval)
+ return retval;
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
if (ext2fs_has_feature_metadata_csum(fs->super))
@@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
else
fs->super->s_checksum_type = 0;
ext2fs_mark_super_dirty(fs);
+ return 0;
}
static void enable_uninit_bg(ext2_filsys fs)
@@ -3412,8 +3415,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
}
}
- if (rewrite_checksums)
- rewrite_metadata_checksums(fs, rewrite_checksums);
+ if (rewrite_checksums) {
+ retval = rewrite_metadata_checksums(fs, rewrite_checksums);
+ if (retval != 0) {
+ printf("Failed to rewrite metadata checksums\n");
+ rc = 1;
+ goto closefs;
+ }
+ }
if (l_flag)
list_super(sb);
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/third_party_e2fsprogs.git
git@gitee.com:openharmony/third_party_e2fsprogs.git
openharmony
third_party_e2fsprogs
third_party_e2fsprogs
master

搜索帮助