From: Shachar Shemesh Date: Tue, 15 Apr 2008 10:57:35 +0000 (+0200) Subject: losetup: add --sizelimit option X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bcefc7f03aa5e2c346c92e0c9b780f51c716dee;p=util-linux losetup: add --sizelimit option [kzak@redhat.com: split the original patch to small patches] Signed-off-by: Shachar Shemesh Signed-off-by: Karel Zak --- diff --git a/AUTHORS b/AUTHORS index 2c25a0ec..334a5e49 100644 --- a/AUTHORS +++ b/AUTHORS @@ -102,6 +102,7 @@ CONTRIBUTORS: Samuel Thibault Santiago Vila Doncel Sascha Sommer + Shachar Shemesh Simon Mihevc Stefan Krah Stepan Kasal diff --git a/mount/lomount.c b/mount/lomount.c index ac379c0d..953fe86b 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 enable data encryption with specified \n" " -h | --help this help\n" " -o | --offset start at offset into file\n" + " --sizelimit loop limited to only bytes of the file\n" " -p | --pass-fd read passphrase from file descriptor \n" " -r | --read-only setup read-only loop device\n" " -s | --show print device name (with -f )\n" @@ -845,13 +848,13 @@ 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; struct option longopts[] = { { "all", 0, 0, 'a' }, { "detach", 0, 0, 'd' }, @@ -860,6 +863,7 @@ main(int argc, char **argv) { { "help", 0, 0, 'h' }, { "associated", 1, 0, 'j' }, { "offset", 1, 0, 'o' }, + { "sizelimit", 1, 0, 128 }, { "pass-fd", 1, 0, 'p' }, { "read-only", 0, 0, 'r' }, { "show", 0, 0, 's' }, @@ -873,7 +877,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) @@ -913,6 +918,11 @@ main(int argc, char **argv) { case 'v': verbose = 1; break; + + case 128: /* --sizelimit */ + sizelimit = optarg; + break; + default: usage(); } @@ -921,7 +931,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 +951,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 +985,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 a5c1ae8d..f332a70d 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 400ec2ca..c6ba75f1 100644 --- a/mount/losetup.8 +++ b/mount/losetup.8 @@ -35,6 +35,8 @@ Setup loop device: .IR encryption ] .RB [ \-o .IR offset ] +.RB [ \-\-sizelimit +.IR limit ] .RB [ \-p .IR pfd ] .RB [ \-r ] @@ -84,6 +86,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 diff --git a/mount/mount.c b/mount/mount.c index fcc5531b..7445314f 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -927,7 +927,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, 0, opt_encryption, pfd, &loop_opts))) { if (res == 2) { /* loop dev has been grabbed by some other process,