aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r--util-linux/mount.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index b92e2c297..19ac13930 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -1886,6 +1886,58 @@ static int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts)
1886 1886
1887#endif // !ENABLE_FEATURE_MOUNT_NFS 1887#endif // !ENABLE_FEATURE_MOUNT_NFS
1888 1888
1889// Find "...,NAME=NUM,..." in the option string, remove "NAME=NUM" option
1890// and return NUM.
1891// Return 0 if not found.
1892// All instances must be parsed and removed (for example, since kernel 5.4
1893// squashfs: Unknown parameter 'sizelimit'
1894// will result if loopback mount option "sizelimit=NNN" is not removed
1895// and squashfs sees it in option string).
1896static unsigned long long cut_out_ull_opt(char *opts, const char *name_eq)
1897{
1898 unsigned long long ret = 0;
1899
1900 if (!opts) // allow NULL opts (simplifies callers' work)
1901 return ret;
1902
1903 for (;;) {
1904 char *end;
1905 char *opt;
1906
1907 // Find comma-delimited "NAME="
1908 for (;;) {
1909 opt = strstr(opts, name_eq);
1910 if (!opt)
1911 return ret;
1912 if (opt == opts)
1913 break; // found it (it's first opt)
1914 if (opt[-1] == ',') {
1915 opts = opt - 1;
1916 break; // found it (it's not a first opt)
1917 }
1918 // False positive like "VNAME=", we are at "N".
1919 // - skip it, loop back to searching
1920 opts = opt + 1;
1921 }
1922
1923 ret = bb_strtoull(opt + strlen(name_eq), &end, 0);
1924 if (errno && errno != EINVAL) {
1925 err:
1926 bb_error_msg_and_die("bad option '%s'", opt);
1927 }
1928 if (*end == '\0') {
1929 // It is "[,]NAME=NUM\0" - truncate it and return
1930 *opts = '\0';
1931 return ret;
1932 }
1933 if (*end != ',')
1934 goto err;
1935 // We are at trailing comma
1936 // Remove "NAME=NUM," and loop back to check for duplicate opts
1937 overlapping_strcpy(opt, end + 1);
1938 }
1939}
1940
1889// Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem 1941// Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem
1890// type detection. Returns 0 for success, nonzero for failure. 1942// type detection. Returns 0 for success, nonzero for failure.
1891// NB: mp->xxx fields may be trashed on exit 1943// NB: mp->xxx fields may be trashed on exit
@@ -2029,9 +2081,16 @@ static int singlemount(struct mntent *mp, int ignore_busy)
2029 ) { 2081 ) {
2030 // Do we need to allocate a loopback device for it? 2082 // Do we need to allocate a loopback device for it?
2031 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { 2083 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
2084 unsigned long long offset;
2085 unsigned long long sizelimit;
2086
2032 loopFile = bb_simplify_path(mp->mnt_fsname); 2087 loopFile = bb_simplify_path(mp->mnt_fsname);
2033 mp->mnt_fsname = NULL; // will receive malloced loop dev name 2088 mp->mnt_fsname = NULL; // will receive malloced loop dev name
2034 2089
2090 // Parse and remove loopback options
2091 offset = cut_out_ull_opt(filteropts, "offset=");
2092 sizelimit = cut_out_ull_opt(filteropts, "sizelimit=");
2093
2035 // mount always creates AUTOCLEARed loopdevs, so that umounting 2094 // mount always creates AUTOCLEARed loopdevs, so that umounting
2036 // drops them without any code in the userspace. 2095 // drops them without any code in the userspace.
2037 // This happens since circa linux-2.6.25: 2096 // This happens since circa linux-2.6.25:
@@ -2040,7 +2099,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
2040 // Subject: Allow auto-destruction of loop devices 2099 // Subject: Allow auto-destruction of loop devices
2041 loopfd = set_loop(&mp->mnt_fsname, 2100 loopfd = set_loop(&mp->mnt_fsname,
2042 loopFile, 2101 loopFile,
2043 0, 2102 offset,
2103 sizelimit,
2044 ((vfsflags & MS_RDONLY) ? BB_LO_FLAGS_READ_ONLY : 0) 2104 ((vfsflags & MS_RDONLY) ? BB_LO_FLAGS_READ_ONLY : 0)
2045 | BB_LO_FLAGS_AUTOCLEAR 2105 | BB_LO_FLAGS_AUTOCLEAR
2046 ); 2106 );