diff options
-rw-r--r-- | util-linux/mount.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index d473fd0a1..deedd17da 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -36,6 +36,10 @@ | |||
36 | //usage: IF_FEATURE_MTAB_SUPPORT( | 36 | //usage: IF_FEATURE_MTAB_SUPPORT( |
37 | //usage: "\n -n Don't update /etc/mtab" | 37 | //usage: "\n -n Don't update /etc/mtab" |
38 | //usage: ) | 38 | //usage: ) |
39 | //usage: IF_FEATURE_MOUNT_VERBOSE( | ||
40 | //usage: "\n -v Verbose" | ||
41 | //usage: ) | ||
42 | ////usage: "\n -s Sloppy (ignored)" | ||
39 | //usage: "\n -r Read-only mount" | 43 | //usage: "\n -r Read-only mount" |
40 | //usage: "\n -w Read-write mount (default)" | 44 | //usage: "\n -w Read-write mount (default)" |
41 | //usage: "\n -t FSTYPE[,...] Filesystem type(s)" | 45 | //usage: "\n -t FSTYPE[,...] Filesystem type(s)" |
@@ -224,7 +228,7 @@ static const int32_t mount_options[] = { | |||
224 | IF_DESKTOP(/* "user" */ MOUNT_USERS,) | 228 | IF_DESKTOP(/* "user" */ MOUNT_USERS,) |
225 | IF_DESKTOP(/* "users" */ MOUNT_USERS,) | 229 | IF_DESKTOP(/* "users" */ MOUNT_USERS,) |
226 | /* "_netdev" */ 0, | 230 | /* "_netdev" */ 0, |
227 | IF_DESKTOP(/* "comment" */ 0,) /* systemd uses this in fstab */ | 231 | IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ |
228 | ) | 232 | ) |
229 | 233 | ||
230 | IF_FEATURE_MOUNT_FLAGS( | 234 | IF_FEATURE_MOUNT_FLAGS( |
@@ -283,7 +287,7 @@ static const char mount_option_str[] = | |||
283 | IF_DESKTOP("user\0") | 287 | IF_DESKTOP("user\0") |
284 | IF_DESKTOP("users\0") | 288 | IF_DESKTOP("users\0") |
285 | "_netdev\0" | 289 | "_netdev\0" |
286 | IF_DESKTOP("comment\0") /* systemd uses this in fstab */ | 290 | IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ |
287 | ) | 291 | ) |
288 | IF_FEATURE_MOUNT_FLAGS( | 292 | IF_FEATURE_MOUNT_FLAGS( |
289 | // vfs flags | 293 | // vfs flags |
@@ -475,10 +479,13 @@ static unsigned long parse_mount_options(char *options, char **unrecognized) | |||
475 | // FIXME: use hasmntopt() | 479 | // FIXME: use hasmntopt() |
476 | // Find this option in mount_options | 480 | // Find this option in mount_options |
477 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { | 481 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { |
478 | /* We support "option=" match for "comment=" thingy */ | ||
479 | unsigned opt_len = strlen(option_str); | 482 | unsigned opt_len = strlen(option_str); |
483 | |||
480 | if (strncasecmp(option_str, options, opt_len) == 0 | 484 | if (strncasecmp(option_str, options, opt_len) == 0 |
481 | && (options[opt_len] == '\0' || options[opt_len] == '=') | 485 | && (options[opt_len] == '\0' |
486 | /* or is it "comment=" thingy in fstab? */ | ||
487 | IF_FEATURE_MOUNT_FSTAB(IF_DESKTOP( || option_str[opt_len-1] == '=' )) | ||
488 | ) | ||
482 | ) { | 489 | ) { |
483 | unsigned long fl = mount_options[i]; | 490 | unsigned long fl = mount_options[i]; |
484 | if (fl & BB_MS_INVERTED_VALUE) | 491 | if (fl & BB_MS_INVERTED_VALUE) |
@@ -1817,31 +1824,44 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
1817 | ) { | 1824 | ) { |
1818 | int len; | 1825 | int len; |
1819 | char c; | 1826 | char c; |
1827 | char *hostname, *share; | ||
1828 | char *dotted, *ip; | ||
1820 | len_and_sockaddr *lsa; | 1829 | len_and_sockaddr *lsa; |
1821 | char *hostname, *dotted, *ip; | 1830 | |
1831 | // Parse mp->mnt_fsname of the form "//hostname/share[/dir1/dir2]" | ||
1822 | 1832 | ||
1823 | hostname = mp->mnt_fsname + 2; | 1833 | hostname = mp->mnt_fsname + 2; |
1824 | len = strcspn(hostname, "/\\"); | 1834 | len = strcspn(hostname, "/\\"); |
1825 | if (len == 0 // 1st char is a [back]slash (IOW: empty hostname) | 1835 | share = hostname + len + 1; |
1826 | || hostname[len] == '\0' // no [back]slash after hostname | 1836 | if (len == 0 // 3rd char is a [back]slash (IOW: empty hostname) |
1827 | || hostname[len+1] == '\0' // empty share name | 1837 | || share[-1] == '\0' // no [back]slash after hostname |
1838 | || share[0] == '\0' // empty share name | ||
1828 | ) { | 1839 | ) { |
1829 | goto report_error; | 1840 | goto report_error; |
1830 | } | 1841 | } |
1831 | c = hostname[len]; | 1842 | c = share[-1]; |
1832 | hostname[len] = '\0'; | 1843 | share[-1] = '\0'; |
1844 | len = strcspn(share, "/\\"); | ||
1833 | 1845 | ||
1834 | // "unc=\\hostname\share" option is mandatory | 1846 | // "unc=\\hostname\share" option is mandatory |
1835 | // after CIFS option parsing was rewritten in Linux 3.4. | 1847 | // after CIFS option parsing was rewritten in Linux 3.4. |
1836 | // Must pass it to the kernel. Must use backslashes. | 1848 | // Must use backslashes. |
1849 | // If /dir1/dir2 is present, also add "prefixpath=dir1/dir2" | ||
1837 | { | 1850 | { |
1838 | char *unc = xasprintf("unc=\\\\%s\\%s", hostname, hostname + len + 1); | 1851 | char *unc = xasprintf( |
1839 | parse_mount_options(unc, &filteropts); | 1852 | share[len] != '\0' /* "/dir1/dir2" exists? */ |
1840 | if (ENABLE_FEATURE_CLEAN_UP) free(unc); | 1853 | ? "unc=\\\\%s\\%.*s,prefixpath=%s" |
1854 | : "unc=\\\\%s\\%.*s", | ||
1855 | hostname, | ||
1856 | len, share, | ||
1857 | share + len + 1 /* "dir1/dir2" */ | ||
1858 | ); | ||
1859 | parse_mount_options(unc, &filteropts); | ||
1860 | if (ENABLE_FEATURE_CLEAN_UP) free(unc); | ||
1841 | } | 1861 | } |
1842 | 1862 | ||
1843 | lsa = host2sockaddr(hostname, 0); | 1863 | lsa = host2sockaddr(hostname, 0); |
1844 | hostname[len] = c; | 1864 | share[-1] = c; |
1845 | if (!lsa) | 1865 | if (!lsa) |
1846 | goto report_error; | 1866 | goto report_error; |
1847 | 1867 | ||
@@ -1853,8 +1873,6 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
1853 | parse_mount_options(ip, &filteropts); | 1873 | parse_mount_options(ip, &filteropts); |
1854 | if (ENABLE_FEATURE_CLEAN_UP) free(ip); | 1874 | if (ENABLE_FEATURE_CLEAN_UP) free(ip); |
1855 | 1875 | ||
1856 | // "-o mand" is required [why?] | ||
1857 | vfsflags |= MS_MANDLOCK; | ||
1858 | mp->mnt_type = (char*)"cifs"; | 1876 | mp->mnt_type = (char*)"cifs"; |
1859 | rc = mount_it_now(mp, vfsflags, filteropts); | 1877 | rc = mount_it_now(mp, vfsflags, filteropts); |
1860 | 1878 | ||