Karel Zak wrote:
We need to support the option in mount(8) too.
My suggestion is to use the long options only: * mark '-s' in util-linux-ng as deprecated and suggest to use the long option '--show' only. * use (only) the long option '--sizelimit' for the loop sizelimit. It means without '-S'.
Attached is a patch with both changes, against the git repository. Shachar
diff --git a/AUTHORS b/AUTHORS index 2c25a0e..334a5e4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -102,6 +102,7 @@ CONTRIBUTORS: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx> Santiago Vila Doncel <sanvila@xxxxxxx> Sascha Sommer <ssommer@xxxxxxx> + Shachar Shemesh <shachar@xxxxxxxxxx> Simon Mihevc <simonmihevc@xxxxxxxx> Stefan Krah <stefan@xxxxxxxxxxxx> Stepan Kasal <skasal@xxxxxxxxxx> diff --git a/mount/lomount.c b/mount/lomount.c index ac379c0..81a6ac3 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -609,7 +609,7 @@ digits_only(const char *s) { int set_loop(const char *device, const char *file, unsigned long long offset, - const char *encryption, int pfd, int *options) { + unsigned long long sizelimit, const char *encryption, int pfd, int *options) { struct loop_info64 loopinfo64; int fd, ffd, mode, i; char *pass; @@ -657,6 +657,7 @@ set_loop(const char *device, const char *file, unsigned long long offset, } loopinfo64.lo_offset = offset; + loopinfo64.lo_sizelimit = sizelimit; #ifdef MCL_FUTURE /* @@ -758,8 +759,8 @@ set_loop(const char *device, const char *file, unsigned long long offset, close (fd); if (verbose > 1) - printf(_("set_loop(%s,%s,%llu): success\n"), - device, filename, offset); + printf(_("set_loop(%s,%s,%llu,%llu): success\n"), + device, filename, offset, sizelimit); if (file != filename) free(filename); return 0; @@ -795,8 +796,9 @@ mutter(void) { } int -set_loop (const char *device, const char *file, unsigned long long offset, - const char *encryption, int *loopro) { +set_loop(const char *device, const char *file, unsigned long long offset, + unsigned long long sizelimit, const char *encryption, int pfd, int *loopro, + int keysz, int hash_pass) { mutter(); return 1; } @@ -835,6 +837,7 @@ usage(void) { " -e | --encryption <type> enable data encryption with specified <name/num>\n" " -h | --help this help\n" " -o | --offset <num> start at offset <num> into file\n" + " --sizelimit <num> loop limited to only <num> bytes of the file\n" " -p | --pass-fd <num> read passphrase from file descriptor <num>\n" " -r | --read-only setup read-only loop device\n" " -s | --show print device name (with -f <file>)\n" @@ -845,13 +848,14 @@ usage(void) { int main(int argc, char **argv) { - char *p, *offset, *encryption, *passfd, *device, *file, *assoc; + char *p, *offset, *sizelimit, *encryption, *passfd, *device, *file, *assoc; int delete, find, c, all; int res = 0; int showdev = 0; int ro = 0; int pfd = -1; - unsigned long long off; + unsigned long long off, slimit; +#define SIZELIMIT_OPT 1 struct option longopts[] = { { "all", 0, 0, 'a' }, { "detach", 0, 0, 'd' }, @@ -860,6 +864,7 @@ main(int argc, char **argv) { { "help", 0, 0, 'h' }, { "associated", 1, 0, 'j' }, { "offset", 1, 0, 'o' }, + { "sizelimit", 1, 0, SIZELIMIT_OPT }, { "pass-fd", 1, 0, 'p' }, { "read-only", 0, 0, 'r' }, { "show", 0, 0, 's' }, @@ -873,7 +878,8 @@ main(int argc, char **argv) { delete = find = all = 0; off = 0; - assoc = offset = encryption = passfd = NULL; + slimit = 0; + assoc = offset = sizelimit = encryption = passfd = NULL; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) @@ -904,6 +910,9 @@ main(int argc, char **argv) { case 'o': offset = optarg; break; + case SIZELIMIT_OPT: + sizelimit = optarg; + break; case 'p': passfd = optarg; break; @@ -921,7 +930,7 @@ main(int argc, char **argv) { if (argc == 1) { usage(); } else if (delete) { - if (argc != optind+1 || encryption || offset || + if (argc != optind+1 || encryption || offset || sizelimit || find || all || showdev || assoc || ro) usage(); } else if (find) { @@ -941,6 +950,9 @@ main(int argc, char **argv) { if (offset && sscanf(offset, "%llu", &off) != 1) usage(); + if (sizelimit && sscanf(sizelimit, "%llu", &slimit) != 1) + usage(); + if (all) return show_used_loop_devices(); else if (assoc) @@ -972,7 +984,7 @@ main(int argc, char **argv) { if (passfd && sscanf(passfd, "%d", &pfd) != 1) usage(); do { - res = set_loop(device, file, off, encryption, pfd, &ro); + res = set_loop(device, file, off, slimit, encryption, pfd, &ro); if (res == 2 && find) { if (verbose) printf("stolen loop=%s...trying again\n", diff --git a/mount/lomount.h b/mount/lomount.h index a5c1ae8..f332a70 100644 --- a/mount/lomount.h +++ b/mount/lomount.h @@ -1,4 +1,4 @@ -extern int set_loop(const char *, const char *, unsigned long long, +extern int set_loop(const char *, const char *, unsigned long long, unsigned long long, const char *, int, int *); extern int del_loop(const char *); extern int is_loop_device(const char *); diff --git a/mount/losetup.8 b/mount/losetup.8 index 400ec2c..69bd867 100644 --- a/mount/losetup.8 +++ b/mount/losetup.8 @@ -35,6 +35,7 @@ Setup loop device: .IR encryption ] .RB [ \-o .IR offset ] +.RB [ \-\-sizelimit=\fIlimit\fP ] .RB [ \-p .IR pfd ] .RB [ \-r ] @@ -84,6 +85,8 @@ show status of all loop devices associated with given .IP "\fB\-o, \-\-offset \fIoffset\fP" the data start is moved \fIoffset\fP bytes into the specified file or device +.IP "\fB\-\-sizelimit \fIlimit\fP" +The data end is set to no more than \fIsizelimit\fP bytes after the data start. .IP "\fB\-p, \-\-pass-fd \fInum\fP" read the passphrase from file descriptor with number .I num @@ -97,7 +100,7 @@ option and a .I file argument are present .IP "\fB\-v, \-\-verbose\fP" -verbose mode +verbose mode. The short form of this option (\fB\-s\fP) is deprecated. .SH RETURN VALUE .B losetup diff --git a/mount/mount.c b/mount/mount.c index fcc5531..bed792d 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -182,8 +182,8 @@ static const struct opt_map opt_map[] = { static int opt_nofail = 0; -static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption, - *opt_speed, *opt_comment, *opt_uhelper; +static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_sizelimit, + *opt_encryption, *opt_speed, *opt_comment, *opt_uhelper; static int mounted (const char *spec0, const char *node0); static int check_special_mountprog(const char *spec, const char *node, @@ -197,6 +197,7 @@ static struct string_opt_map { { "loop=", 0, &opt_loopdev }, { "vfs=", 1, &opt_vfstype }, { "offset=", 0, &opt_offset }, + { "sizelimit=", 0, &opt_sizelimit }, { "encryption=", 0, &opt_encryption }, { "speed=", 0, &opt_speed }, { "comment=", 1, &opt_comment }, @@ -872,7 +873,7 @@ loop_check(const char **spec, const char **type, int *flags, int *loop, const char **loopdev, const char **loopfile, const char *node) { int looptype; - unsigned long long offset; + unsigned long long offset, sizelimit; /* * In the case of a loop mount, either type is of the form lo@/dev/loop5 @@ -897,7 +898,7 @@ loop_check(const char **spec, const char **type, int *flags, *type = opt_vfstype; } - *loop = ((*flags & MS_LOOP) || *loopdev || opt_offset || opt_encryption); + *loop = ((*flags & MS_LOOP) || *loopdev || opt_offset || opt_sizelimit || opt_encryption); *loopfile = *spec; if (*loop) { @@ -913,6 +914,7 @@ loop_check(const char **spec, const char **type, int *flags, loop_opts |= SETLOOP_RDONLY; offset = opt_offset ? strtoull(opt_offset, NULL, 0) : 0; + sizelimit = opt_sizelimit ? strtoull(opt_sizelimit, NULL, 0) : 0; if (is_mounted_same_loopfile(node, *loopfile, offset)) { error(_("mount: according to mtab %s is already mounted on %s as loop"), *loopfile, node); @@ -927,7 +929,7 @@ loop_check(const char **spec, const char **type, int *flags, if (verbose) printf(_("mount: going to use the loop device %s\n"), *loopdev); - if ((res = set_loop(*loopdev, *loopfile, offset, + if ((res = set_loop(*loopdev, *loopfile, offset, sizelimit, opt_encryption, pfd, &loop_opts))) { if (res == 2) { /* loop dev has been grabbed by some other process,