From: Zhiqiang Liu <liuzhiqiang26@xxxxxxxxxx> tune2fs is used to adjust various tunable filesystem pars, which may conflict with kernel operations. So we should check whether device is mounted or in use at the begin similar to e2fsck and mke2fs. Of course, we can ignore this check if -f is set. Reported-by: Baokun Li <libaokun1@xxxxxxxxxx> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@xxxxxxxxxx> Signed-off-by: zhanchengbin <zhanchengbin1@xxxxxxxxxx> --- misc/tune2fs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 458f7cf6..b667e1f4 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -3327,6 +3327,22 @@ retry_open: goto closefs; } + if (open_flag & EXT2_FLAG_RW) { + if (mount_flags & EXT2_MF_MOUNTED) { + fprintf(stderr, _("Warning! %s is mounted.\n"), device_name); + if (!f_flag) { + rc = 1; + goto closefs; + } + } else if (mount_flags & EXT2_MF_BUSY) { + fprintf(stderr, _("Warning! %s is in use by the system.\n"), + device_name); + if (!f_flag) { + rc = 1; + goto closefs; + } + } + } #ifdef NO_RECOVERY /* Warn if file system needs recovery and it is opened for writing. */ if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) && -- 2.33.0