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