summaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorSteffen Trumtrar2020-07-29 10:43:53 +0200
committerDenys Vlasenko2020-10-01 00:31:11 +0200
commit6561e07460acc5b38af99aa5e80283dc04953eca (patch)
treec73a8a3194c18fa52b712de4e8b3a304470725b4 /util-linux
parentabefc3c276ac2450f756c5232745a145bd14dbdf (diff)
downloadbusybox-6561e07460acc5b38af99aa5e80283dc04953eca.zip
busybox-6561e07460acc5b38af99aa5e80283dc04953eca.tar.gz
mount: support the sizelimit and offset option for loop devices
Starting with linux kernel v5.4 squashfs has a more strict parameter checking implemented. Unlike util-linux mount, busybox never supported the sizelimit option but simply forwards it to the kernel. Since v5.4 mounting will fail with squashfs: Unknown parameter 'sizelimit' Support the sizelimit parameter by setting it in the LOOP_SET_STATUS64 structure before handing it to the kernel. While at it also add support for the offset option, which currently will always be set to 0. function old new delta cut_out_ull_opt - 167 +167 singlemount 1230 1266 +36 set_loop 834 862 +28 losetup_main 479 483 +4 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/0 up/down: 235/0) Total: 235 bytes Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/losetup.c2
-rw-r--r--util-linux/mount.c62
2 files changed, 62 insertions, 2 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c
index ac8b795..24f7a23 100644
--- a/util-linux/losetup.c
+++ b/util-linux/losetup.c
@@ -150,7 +150,7 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_P) {
flags |= BB_LO_FLAGS_PARTSCAN;
}
- if (set_loop(&d, argv[0], offset, flags) < 0)
+ if (set_loop(&d, argv[0], offset, 0, flags) < 0)
bb_simple_perror_msg_and_die(argv[0]);
return EXIT_SUCCESS;
}
diff --git a/util-linux/mount.c b/util-linux/mount.c
index b92e2c2..19ac139 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)
#endif // !ENABLE_FEATURE_MOUNT_NFS
+// Find "...,NAME=NUM,..." in the option string, remove "NAME=NUM" option
+// and return NUM.
+// Return 0 if not found.
+// All instances must be parsed and removed (for example, since kernel 5.4
+// squashfs: Unknown parameter 'sizelimit'
+// will result if loopback mount option "sizelimit=NNN" is not removed
+// and squashfs sees it in option string).
+static unsigned long long cut_out_ull_opt(char *opts, const char *name_eq)
+{
+ unsigned long long ret = 0;
+
+ if (!opts) // allow NULL opts (simplifies callers' work)
+ return ret;
+
+ for (;;) {
+ char *end;
+ char *opt;
+
+ // Find comma-delimited "NAME="
+ for (;;) {
+ opt = strstr(opts, name_eq);
+ if (!opt)
+ return ret;
+ if (opt == opts)
+ break; // found it (it's first opt)
+ if (opt[-1] == ',') {
+ opts = opt - 1;
+ break; // found it (it's not a first opt)
+ }
+ // False positive like "VNAME=", we are at "N".
+ // - skip it, loop back to searching
+ opts = opt + 1;
+ }
+
+ ret = bb_strtoull(opt + strlen(name_eq), &end, 0);
+ if (errno && errno != EINVAL) {
+ err:
+ bb_error_msg_and_die("bad option '%s'", opt);
+ }
+ if (*end == '\0') {
+ // It is "[,]NAME=NUM\0" - truncate it and return
+ *opts = '\0';
+ return ret;
+ }
+ if (*end != ',')
+ goto err;
+ // We are at trailing comma
+ // Remove "NAME=NUM," and loop back to check for duplicate opts
+ overlapping_strcpy(opt, end + 1);
+ }
+}
+
// Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem
// type detection. Returns 0 for success, nonzero for failure.
// NB: mp->xxx fields may be trashed on exit
@@ -2029,9 +2081,16 @@ static int singlemount(struct mntent *mp, int ignore_busy)
) {
// Do we need to allocate a loopback device for it?
if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
+ unsigned long long offset;
+ unsigned long long sizelimit;
+
loopFile = bb_simplify_path(mp->mnt_fsname);
mp->mnt_fsname = NULL; // will receive malloced loop dev name
+ // Parse and remove loopback options
+ offset = cut_out_ull_opt(filteropts, "offset=");
+ sizelimit = cut_out_ull_opt(filteropts, "sizelimit=");
+
// mount always creates AUTOCLEARed loopdevs, so that umounting
// drops them without any code in the userspace.
// This happens since circa linux-2.6.25:
@@ -2040,7 +2099,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
// Subject: Allow auto-destruction of loop devices
loopfd = set_loop(&mp->mnt_fsname,
loopFile,
- 0,
+ offset,
+ sizelimit,
((vfsflags & MS_RDONLY) ? BB_LO_FLAGS_READ_ONLY : 0)
| BB_LO_FLAGS_AUTOCLEAR
);