diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-14 22:57:20 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-14 22:57:20 +0000 |
commit | 7aaedcf21ee4c9eb49d7f1f74500c1b84cef75e7 (patch) | |
tree | 72f83132e3d6e64a67956ff2160fff7c8c9f22c1 /util-linux | |
parent | 447ab18cf6e2a05842bab443255b0fdf0f4e598e (diff) | |
download | busybox-w32-7aaedcf21ee4c9eb49d7f1f74500c1b84cef75e7.tar.gz busybox-w32-7aaedcf21ee4c9eb49d7f1f74500c1b84cef75e7.tar.bz2 busybox-w32-7aaedcf21ee4c9eb49d7f1f74500c1b84cef75e7.zip |
mount: support "-O option"; stop trying to mount swap partitions
function old new delta
mount_main 975 1152 +177
umount_main 640 636 -4
packed_usage 25666 25662 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 177/-8) Total: 169 bytes
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/mount.c | 103 | ||||
-rw-r--r-- | util-linux/umount.c | 4 |
2 files changed, 90 insertions, 17 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index 3b8311318..d647c71b1 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -63,7 +63,7 @@ enum { | |||
63 | }; | 63 | }; |
64 | 64 | ||
65 | 65 | ||
66 | #define OPTION_STR "o:t:rwanfvsi" | 66 | #define OPTION_STR "o:t:rwanfvsiO:" |
67 | enum { | 67 | enum { |
68 | OPT_o = (1 << 0), | 68 | OPT_o = (1 << 0), |
69 | OPT_t = (1 << 1), | 69 | OPT_t = (1 << 1), |
@@ -75,6 +75,7 @@ enum { | |||
75 | OPT_v = (1 << 7), | 75 | OPT_v = (1 << 7), |
76 | OPT_s = (1 << 8), | 76 | OPT_s = (1 << 8), |
77 | OPT_i = (1 << 9), | 77 | OPT_i = (1 << 9), |
78 | OPT_O = (1 << 10), | ||
78 | }; | 79 | }; |
79 | 80 | ||
80 | #if ENABLE_FEATURE_MTAB_SUPPORT | 81 | #if ENABLE_FEATURE_MTAB_SUPPORT |
@@ -1721,6 +1722,45 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
1721 | return rc; | 1722 | return rc; |
1722 | } | 1723 | } |
1723 | 1724 | ||
1725 | /* -O support | ||
1726 | * Unlike -t, -O should interpret "no" prefix differently: | ||
1727 | * -t noa,b,c = -t no(a,b,c) = mount all except fs'es with types a,b, and c | ||
1728 | * -O noa,b,c = -O noa,b,c = mount all with without option a, | ||
1729 | * or with option b or c. | ||
1730 | * But for now we do not support -O a,b,c at all (only -O a). | ||
1731 | * | ||
1732 | * Another difference from -t support (match_fstype) is that | ||
1733 | * we need to examine the _list_ of options in fsopt, not just a string. | ||
1734 | */ | ||
1735 | static int match_opt(const char *fs_opt, const char *O_opt) | ||
1736 | { | ||
1737 | int match = 1; | ||
1738 | int len; | ||
1739 | |||
1740 | if (!O_opt) | ||
1741 | return match; | ||
1742 | |||
1743 | if (O_opt[0] == 'n' && O_opt[1] == 'o') { | ||
1744 | match--; | ||
1745 | O_opt += 2; | ||
1746 | } | ||
1747 | |||
1748 | len = strlen(O_opt); | ||
1749 | while (1) { | ||
1750 | if (strncmp(fs_opt, O_opt, len) == 0 | ||
1751 | && (fs_opt[len] == '\0' || fs_opt[len] == ',') | ||
1752 | ) { | ||
1753 | return match; | ||
1754 | } | ||
1755 | fs_opt = strchr(fs_opt, ','); | ||
1756 | if (!fs_opt) | ||
1757 | break; | ||
1758 | fs_opt++; | ||
1759 | } | ||
1760 | |||
1761 | return !match; | ||
1762 | } | ||
1763 | |||
1724 | // Parse options, if necessary parse fstab/mtab, and call singlemount for | 1764 | // Parse options, if necessary parse fstab/mtab, and call singlemount for |
1725 | // each directory to be mounted. | 1765 | // each directory to be mounted. |
1726 | static const char must_be_root[] ALIGN1 = "you must be root"; | 1766 | static const char must_be_root[] ALIGN1 = "you must be root"; |
@@ -1728,8 +1768,9 @@ static const char must_be_root[] ALIGN1 = "you must be root"; | |||
1728 | int mount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1768 | int mount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1729 | int mount_main(int argc UNUSED_PARAM, char **argv) | 1769 | int mount_main(int argc UNUSED_PARAM, char **argv) |
1730 | { | 1770 | { |
1731 | char *cmdopts = xstrdup(""); | 1771 | char *cmdopts = xzalloc(1); |
1732 | char *fstype = NULL; | 1772 | char *fstype = NULL; |
1773 | char *O_optmatch = NULL; | ||
1733 | char *storage_path; | 1774 | char *storage_path; |
1734 | llist_t *lst_o = NULL; | 1775 | llist_t *lst_o = NULL; |
1735 | const char *fstabname; | 1776 | const char *fstabname; |
@@ -1752,9 +1793,9 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1752 | argv[j] = NULL; | 1793 | argv[j] = NULL; |
1753 | 1794 | ||
1754 | // Parse remaining options | 1795 | // Parse remaining options |
1755 | // Max 2 params; -v is a counter | 1796 | // Max 2 params; -o is a list, -v is a counter |
1756 | opt_complementary = "?2o::" USE_FEATURE_MOUNT_VERBOSE(":vv"); | 1797 | opt_complementary = "?2o::" USE_FEATURE_MOUNT_VERBOSE("vv"); |
1757 | opt = getopt32(argv, OPTION_STR, &lst_o, &fstype | 1798 | opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch |
1758 | USE_FEATURE_MOUNT_VERBOSE(, &verbose)); | 1799 | USE_FEATURE_MOUNT_VERBOSE(, &verbose)); |
1759 | while (lst_o) append_mount_options(&cmdopts, llist_pop(&lst_o)); // -o | 1800 | while (lst_o) append_mount_options(&cmdopts, llist_pop(&lst_o)); // -o |
1760 | if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r | 1801 | if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r |
@@ -1807,7 +1848,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1807 | // Past this point, we are handling either "mount -a [opts]" | 1848 | // Past this point, we are handling either "mount -a [opts]" |
1808 | // or "mount [opts] single_param" | 1849 | // or "mount [opts] single_param" |
1809 | 1850 | ||
1810 | i = parse_mount_options(cmdopts, 0); // FIXME: should be "long", not "int" | 1851 | i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int" |
1811 | if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags | 1852 | if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags |
1812 | bb_error_msg_and_die(must_be_root); | 1853 | bb_error_msg_and_die(must_be_root); |
1813 | 1854 | ||
@@ -1865,20 +1906,29 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1865 | 1906 | ||
1866 | // If we're mounting all | 1907 | // If we're mounting all |
1867 | } else { | 1908 | } else { |
1868 | // Do we need to match a filesystem type? | 1909 | // No, mount -a won't mount anything, |
1869 | if (fstype && match_fstype(mtcur, fstype)) | 1910 | // even user mounts, for mere humans |
1911 | if (nonroot) | ||
1912 | bb_error_msg_and_die(must_be_root); | ||
1913 | |||
1914 | // Does type match? (NULL matches always) | ||
1915 | if (!match_fstype(mtcur, fstype)) | ||
1870 | continue; | 1916 | continue; |
1871 | 1917 | ||
1872 | // Skip noauto and swap anyway. | 1918 | // Skip noauto and swap anyway. |
1873 | if (parse_mount_options(mtcur->mnt_opts, 0) & (MOUNT_NOAUTO | MOUNT_SWAP)) | 1919 | if ((parse_mount_options(mtcur->mnt_opts, NULL) & (MOUNT_NOAUTO | MOUNT_SWAP)) |
1920 | // swap is bogus "fstype", parse_mount_options can't check fstypes | ||
1921 | || strcasecmp(mtcur->mnt_type, "swap") == 0 | ||
1922 | ) { | ||
1874 | continue; | 1923 | continue; |
1924 | } | ||
1875 | 1925 | ||
1876 | // No, mount -a won't mount anything, | 1926 | // Does (at least one) option match? |
1877 | // even user mounts, for mere humans | 1927 | // (NULL matches always) |
1878 | if (nonroot) | 1928 | if (!match_opt(mtcur->mnt_opts, O_optmatch)) |
1879 | bb_error_msg_and_die(must_be_root); | 1929 | continue; |
1880 | 1930 | ||
1881 | resolve_mount_spec(&mtpair->mnt_fsname); | 1931 | resolve_mount_spec(&mtcur->mnt_fsname); |
1882 | 1932 | ||
1883 | // NFS mounts want this to be xrealloc-able | 1933 | // NFS mounts want this to be xrealloc-able |
1884 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); | 1934 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); |
@@ -1895,13 +1945,35 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1895 | // End of fstab/mtab is reached. | 1945 | // End of fstab/mtab is reached. |
1896 | // Were we looking for something specific? | 1946 | // Were we looking for something specific? |
1897 | if (argv[0]) { | 1947 | if (argv[0]) { |
1948 | long l; | ||
1949 | |||
1898 | // If we didn't find anything, complain | 1950 | // If we didn't find anything, complain |
1899 | if (!mtcur->mnt_fsname) | 1951 | if (!mtcur->mnt_fsname) |
1900 | bb_error_msg_and_die("can't find %s in %s", | 1952 | bb_error_msg_and_die("can't find %s in %s", |
1901 | argv[0], fstabname); | 1953 | argv[0], fstabname); |
1954 | |||
1955 | // What happens when we try to "mount swap_partition"? | ||
1956 | // (fstab containts "swap_partition swap swap defaults 0 0") | ||
1957 | // util-linux-ng 2.13.1 does this: | ||
1958 | // stat("/sbin/mount.swap", 0x7fff62a3a350) = -1 ENOENT (No such file or directory) | ||
1959 | // mount("swap_partition", "swap", "swap", MS_MGC_VAL, NULL) = -1 ENOENT (No such file or directory) | ||
1960 | // lstat("swap", 0x7fff62a3a640) = -1 ENOENT (No such file or directory) | ||
1961 | // write(2, "mount: mount point swap does not exist\n", 39) = 39 | ||
1962 | // exit_group(32) = ? | ||
1963 | #if 0 | ||
1964 | // In case we want to simply skip swap partitions: | ||
1965 | l = parse_mount_options(mtcur->mnt_opts, NULL); | ||
1966 | if ((l & MOUNT_SWAP) | ||
1967 | // swap is bogus "fstype", parse_mount_options can't check fstypes | ||
1968 | || strcasecmp(mtcur->mnt_type, "swap") == 0 | ||
1969 | ) { | ||
1970 | goto ret; | ||
1971 | } | ||
1972 | #endif | ||
1902 | if (nonroot) { | 1973 | if (nonroot) { |
1903 | // fstab must have "users" or "user" | 1974 | // fstab must have "users" or "user" |
1904 | if (!(parse_mount_options(mtcur->mnt_opts, 0) & MOUNT_USERS)) | 1975 | l = parse_mount_options(mtcur->mnt_opts, NULL); |
1976 | if (!(l & MOUNT_USERS)) | ||
1905 | bb_error_msg_and_die(must_be_root); | 1977 | bb_error_msg_and_die(must_be_root); |
1906 | } | 1978 | } |
1907 | 1979 | ||
@@ -1914,6 +1986,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1914 | free(mtcur->mnt_opts); | 1986 | free(mtcur->mnt_opts); |
1915 | } | 1987 | } |
1916 | 1988 | ||
1989 | //ret: | ||
1917 | if (ENABLE_FEATURE_CLEAN_UP) | 1990 | if (ENABLE_FEATURE_CLEAN_UP) |
1918 | endmntent(fstab); | 1991 | endmntent(fstab); |
1919 | if (ENABLE_FEATURE_CLEAN_UP) { | 1992 | if (ENABLE_FEATURE_CLEAN_UP) { |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 901c9094f..5b22bfacc 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -73,9 +73,9 @@ int umount_main(int argc UNUSED_PARAM, char **argv) | |||
73 | } else { | 73 | } else { |
74 | while (getmntent_r(fp, &me, path, PATH_MAX)) { | 74 | while (getmntent_r(fp, &me, path, PATH_MAX)) { |
75 | /* Match fstype if passed */ | 75 | /* Match fstype if passed */ |
76 | if (fstype && match_fstype(&me, fstype)) | 76 | if (!match_fstype(&me, fstype)) |
77 | continue; | 77 | continue; |
78 | m = xmalloc(sizeof(struct mtab_list)); | 78 | m = xzalloc(sizeof(*m)); |
79 | m->next = mtl; | 79 | m->next = mtl; |
80 | m->device = xstrdup(me.mnt_fsname); | 80 | m->device = xstrdup(me.mnt_fsname); |
81 | m->dir = xstrdup(me.mnt_dir); | 81 | m->dir = xstrdup(me.mnt_dir); |