$ git clone https://github.com/karelzak/util-linux.git $ cd util-linux/ $ git co v2.34 $ ./autogen.sh $ ./configure CFLAGS="-g -O0" --prefix=/usr --disable-all-programs --enable-libblkid --enable-libmount --enable-mount $ make
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ cd .libs $ ls libblkid.a libblkid.lai libblkid.so.1 libcommon.a libmount.a libmount.lai libmount.so.1 libmount.so.1.1.0T libtcolors.la umount libblkid.la libblkid.so libblkid.so.1.1.0 libcommon.la libmount.la libmount.so libmount.so.1.1.0 libtcolors.a mount $ export LD_LIBRARY_PATH=$PWD $ gdb ./umount (gdb) set args /media (gdb) b mnt_context_prepare_umount Function "mnt_context_prepare_umount" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (mnt_context_prepare_umount) pending. (gdb) r Starting program: /home/runsisi/working/cpp/util-linux/.libs/umount /media [Detaching after fork from child process 76658]
Breakpoint 1, mnt_context_prepare_umount (cxt=0x555555560538) at libmount/src/context_umount.c:877 877 {
fs = mnt_table_find_pair(fstab, src, tgt, MNT_ITER_FORWARD); if (!fs) { /* * It's possible that there is /path/file.img in fstab and * /dev/loop0 in mtab -- then we have to check the relation * between loopdev and the file. */ fs = mnt_table_find_target(fstab, tgt, MNT_ITER_FORWARD); if (fs) { structlibmnt_cache *cache = mnt_context_get_cache(cxt); constchar *sp = mnt_fs_get_srcpath(cxt->fs); /* devname from mtab */ constchar *dev = sp && cache ? mnt_resolve_path(sp, cache) : sp;
if (!dev || !is_associated_fs(dev, fs)) fs = NULL; } if (!fs) { DBG(CXT, ul_debugobj(cxt, "umount %s: mtab disagrees with fstab", tgt)); goto eperm; } }
// /etc/fstab 中找到了相关的 mount 条目,接下来检测 user, users, owner, group 之类的选项
/* * User mounting and unmounting is allowed only if fstab contains one * of the options `user', `users' or `owner' or `group'. * * The option `users' allows arbitrary users to mount and unmount - * this may be a security risk. * * The options `user', `owner' and `group' only allow unmounting by the * user that mounted (visible in mtab). */ optstr = mnt_fs_get_user_options(fs); /* FSTAB mount options! */ if (!optstr) goto eperm;
if (mnt_optstr_get_flags(optstr, &u_flags, mnt_get_builtin_optmap(MNT_USERSPACE_MAP))) goto eperm;
eperm: // 不满足权限检测要求,返回错误 umount failed: Operation not permitted.
DBG(CXT, ul_debugobj(cxt, "umount is not allowed for you")); return -EPERM; }