2012-05-25 11:33 1747 if (!argc) 1748 { 1749 if (!(opt & OPT_ALL)) { 1750 FILE *mountTable = setmntent(bb_path_mtab_file, "r" ; 1751 printf("[%s:%d]bb_path_mtab_file=%s\n",__FILE__,__LINE__,bb_path_mtab_file); 1752 1753 if (!mountTable) bb_error_msg_and_die("no %s", bb_path_mtab_file); 1754 1755 while (getmntent_r(mountTable, &mtpair[0], getmntent_buf,sizeof(getmntent_buf))) 1756 { 1757 // Don't show rootfs. FIXME: why?? 1758 // util-linux 2.12a happily shows rootfs... 1759 //if (!strcmp(mtpair->mnt_fsname, "rootfs" ) continue; 1760 1761 if (!fstype || !strcmp(mtpair->mnt_type, fstype)) 1762 { 1763 printf("%s on %s type %s (%s)\n", mtpair->mnt_fsname,mtpair->mnt_dir, mtpair->mnt_type,mtpair->mnt_opts); 1764 } 1765 } 1766 if (ENABLE_FEATURE_CLEAN_UP) 1767 { 1768 endmntent(mountTable); 1769 } 1770 return EXIT_SUCCESS; 1771 } 1772 } 1773 else 1774 { 1775 storage_path = bb_simplify_path(argv[0]); 1776 } line:1755 到line1765是依次从bb_path_mtab指向的文件中读取一行一行的数据,这些数据是 struct mntent格式的。Line1761 到line1763是打印出来的信息,如在命令行下直接输入:mount则显示: [zl@zhanglei ~]$ mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) devtmpfs on /dev type devtmpfs (rw,nosuid,relatime,seclabel,size=956748k,nr_inodes=214073,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,relatime,seclabel) /dev/sda3 on / type ext4 (rw,relatime,seclabel,user_xattr,acl,barrier=1,data=ordered) tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,seclabel,mode=755) selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime) tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,relatime,seclabel,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=21,pgrp=1,timeout=300,minproto=5,maxproto=5,direct) mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel) debugfs on /sys/kernel/debug type debugfs (rw,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel) securityfs on /sys/kernel/security type securityfs (rw,relatime) tmpfs on /media type tmpfs (rw,nosuid,nodev,noexec,relatime,rootcontext=system_u bject_r:mnt_t:s0,seclabel,mode=755) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) /dev/sda5 on /mnt/sda5 type ext2 (rw,relatime,seclabel,user_xattr,acl,barrier=1) /dev/sda6 on /mnt/sda6 type ext2 (rw,relatime,seclabel,user_xattr,acl,barrier=1) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime) gvfs-fuse-daemon on /home/zl/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) [zl@zhanglei ~]$ 同时查看/etc/fstab的内容为: [zl@zhanglei ~]$ cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Dec 8 17:01:18 2011 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs( , mount( and/or blkid( for more info # UUID=a95fe862-ce64-485c-8bc6-10c3047b2fdb / ext4 defaults 1 1 UUID=869aca65-bf53-48e1-ab81-e6d2296cb818 swap swap defaults 0 0 /dev/sda5 /mnt/sda5 ext2 defaults 1 1 /dev/sda6 /mnt/sda6 ext2 defaults 1 1 [zl@zhanglei ~]$ cat /proc/mounts rootfs / rootfs rw 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0 devtmpfs /dev devtmpfs rw,seclabel,nosuid,relatime,size=956748k,nr_inodes=214073,mode=755 0 0 devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev,relatime 0 0 tmpfs /run tmpfs rw,seclabel,nosuid,nodev,relatime,mode=755 0 0 /dev/sda3 / ext4 rw,seclabel,relatime,user_xattr,acl,barrier=1,data=ordered 0 0 tmpfs /run tmpfs rw,seclabel,nosuid,nodev,relatime,mode=755 0 0 selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0 tmpfs /sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,relatime,mode=755 0 0 cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd 0 0 cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0 cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0 cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0 cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0 cgroup /sys/fs/cgroup/net_cls cgroup rw,nosuid,nodev,noexec,relatime,net_cls 0 0 cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0 cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0 systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=21,pgrp=1,timeout=300,minproto=5,maxproto=5,direct 0 0 mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,relatime 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0 securityfs /sys/kernel/security securityfs rw,relatime 0 0 tmpfs /media tmpfs rw,rootcontext=system_u bject_r:mnt_t:s0,seclabel,nosuid,nodev,noexec,relatime,mode=755 0 0 sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0 /dev/sda5 /mnt/sda5 ext2 rw,seclabel,relatime,user_xattr,acl,barrier=1 0 0 /dev/sda6 /mnt/sda6 ext2 rw,seclabel,relatime,user_xattr,acl,barrier=1 0 0 binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0 fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0 gvfs-fuse-daemon /home/zl/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0 也验证了mount是从/proc/mounts中读取的信息,这两个内容差不多。 2012-05-28 15:06 继续: 1798 1799 // When we have two arguments, the second is the directory and we can 1800 // skip looking at fstab entirely. We can always abspath() the directory 1801 // argument when we get it. 1802 1803 if (argc == 2) 1804 { 1805 if (nonroot) 1806 { 1807 bb_error_msg_and_die(must_be_root); 1808 } 1809 mtpair->mnt_fsname = argv[0]; 1810 mtpair->mnt_dir = argv[1]; 1811 mtpair->mnt_type = fstype; 1812 mtpair->mnt_opts = cmdopts; 1813 printf("[%s:%d]...argv[0]=%s,argv[1]=%s,fstype=%s,cmdopts=%s\n",__FILE__,__LINE__,argv[0],argv[1],fstype,cmdopts); 1814 rc = singlemount(mtpair, 0); 1815 goto clean_up; 1816 } 1817 接下来是对当参数为2的时候的处理。 Argc==2,通过上面的流程可知,到了当前的位置,只能是argc=2或者argc=1. Line:1805是root权限的检查。 line:1809----line:1813是将当前的有关mntent结构的参数复制到mtpairt中,然后调用singlemout(). 这个函数就在mount.c中。 1510 1511 // Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem 1512 // type detection. Returns 0 for success, nonzero for failure. 1513 // NB: mp->xxx fields may be trashed on exit 1514 static int singlemount(struct mntent *mp, int ignore_busy) 1515 { 1516 int rc = -1, vfsflags; 1517 char *loopFile = 0, *filteropts = 0; 1518 llist_t *fl = 0; 1519 struct stat st; 1520 1521 //filteropts为过滤指针 1522 vfsflags = parse_mount_options(mp->mnt_opts, &filteropts); 1523 1524 // Treat fstype "auto" as unspecified. 1525 1526 if (mp->mnt_type && strcmp(mp->mnt_type,"auto" == 0) 1527 { 1528 mp->mnt_type = 0; 1529 } 1530 1531 // Might this be a virtual filesystem? 1532 1533 if (ENABLE_FEATURE_MOUNT_HELPERS && (strchr(mp->mnt_fsname,'#'))) 1534 { 1535 char *s, *p, *args[35]; 1536 int n = 0; 1537 for (s = p = mp->mnt_fsname; *s && n < 35-3; ++s) 1538 { 1539 if (s[0] == '#' && s[1] != '#') 1540 { 1541 *s = '\0'; 1542 args[n++] = p; 1543 p = s + 1; 1544 } 1545 } 1546 args[n++] = p; 1547 args[n++] = mp->mnt_dir; 1548 args[n] = NULL; 1549 rc = wait4pid(xspawn(args)); 1550 goto report_error; 1551 } 。。。。。。。 |