1From 228e9f0567eebd4597bd1771fc4bf3650190cf3e Mon Sep 17 00:00:00 2001 2From: zhanchengbin <zhanchengbin1@huawei.com> 3Date: Thu, 24 Feb 2022 10:06:30 +0800 4Subject: [PATCH] resize2fs: resize2fs disk hardlinks will be error 5 6Resize2fs disk hardlinks which mounting after the same name as tmpfs 7 filesystem it will be error. The items in /proc/mounts are traversed, 8when you get to tmpfs, file!=mnt->mnt_fsname, therefore, the 9stat(mnt->mnt_fsname, &st_buf) branch is used, however, the values of 10 file_rdev and st_buf.st_rdev are the same, As a result, the system 11mistakenly considers that disk is mounted to /root/tmp. As a result 12, resize2fs fails. 13 14example: 15dev_name="/dev/sdc" (ps: a disk in you self) 16mkdir /root/tmp 17mkdir /root/mnt 18mkfs.ext4 -F -b 1024 -E "resize=10000000" "${dev_name}" 32768 19mount -t tmpfs "${dev_name}" /root/tmp 20mount "${dev_name}" /root/tmp 21ln "${dev_name}" "${dev_name}"-ln 22resize2fs "${dev_name}"-ln 6G 23 24Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com> 25Signed-off-by: guiyao <guiyao@huawei.com> 26--- 27 lib/ext2fs/ismounted.c | 9 +++++++-- 28 1 file changed, 7 insertions(+), 2 deletions(-) 29 30diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c 31index aee7d72..463a82a 100644 32--- a/lib/ext2fs/ismounted.c 33+++ b/lib/ext2fs/ismounted.c 34@@ -98,6 +98,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, 35 { 36 struct mntent *mnt; 37 struct stat st_buf; 38+ struct stat dir_st_buf; 39 errcode_t retval = 0; 40 dev_t file_dev=0, file_rdev=0; 41 ino_t file_ino=0; 42@@ -144,8 +145,12 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, 43 if (stat(mnt->mnt_fsname, &st_buf) == 0) { 44 if (ext2fsP_is_disk_device(st_buf.st_mode)) { 45 #ifndef __GNU__ 46- if (file_rdev && (file_rdev == st_buf.st_rdev)) 47- break; 48+ if (file_rdev && (file_rdev == st_buf.st_rdev)) { 49+ if (stat(mnt->mnt_dir, &dir_st_buf) != 0) 50+ continue; 51+ if (file_rdev == dir_st_buf.st_dev) 52+ break; 53+ } 54 if (check_loop_mounted(mnt->mnt_fsname, 55 st_buf.st_rdev, file_dev, 56 file_ino) == 1) 57-- 581.8.3.1 59 60