Oleg Goldshmidt wrote:
Sounds like a good reason to patch losetup and release the update to
the community...
Patch attached. You will notice that the patch does not touch the area
where the loops are merely reported (losetup -a), but the resulting
binary is able to report when a loop has a size limit anyways.
Shachar
diff -ru util-linux-2.13.1.orig/AUTHORS util-linux-2.13.1/AUTHORS
--- util-linux-2.13.1.orig/AUTHORS 2008-01-16 13:37:26.000000000 +0200
+++ util-linux-2.13.1/AUTHORS 2008-04-11 12:12:54.000000000 +0300
@@ -87,6 +87,7 @@
Samuel Thibault <[EMAIL PROTECTED]>
Santiago Vila Doncel <[EMAIL PROTECTED]>
Sascha Sommer <[EMAIL PROTECTED]>
+ Shachar Shemesh <[EMAIL PROTECTED]>
Simon Mihevc <[EMAIL PROTECTED]>
Stepan Kasal <[EMAIL PROTECTED]>
Steve Grubb <[EMAIL PROTECTED]>
diff -ru util-linux-2.13.1.orig/mount/lomount.c util-linux-2.13.1/mount/lomount.c
--- util-linux-2.13.1.orig/mount/lomount.c 2008-04-11 12:17:59.000000000 +0300
+++ util-linux-2.13.1/mount/lomount.c 2008-04-11 12:09:21.000000000 +0300
@@ -276,7 +276,8 @@
int
set_loop(const char *device, const char *file, unsigned long long offset,
- const char *encryption, int pfd, int *loopro, int keysz, int hash_pass) {
+ unsigned long long sizelimit, const char *encryption, int pfd, int *loopro,
+ int keysz, int hash_pass) {
struct loop_info64 loopinfo64;
int fd, ffd, mode, i;
char *pass;
@@ -312,6 +313,7 @@
}
loopinfo64.lo_offset = offset;
+ loopinfo64.lo_sizelimit = sizelimit;
#ifdef MCL_FUTURE
/*
@@ -453,8 +455,8 @@
close (fd);
if (verbose > 1)
- printf(_("set_loop(%s,%s,%llu): success\n"),
- device, file, offset);
+ printf(_("set_loop(%s,%s,%llu,%llu): success\n"),
+ device, file, offset, sizelimit);
return 0;
}
@@ -488,8 +490,9 @@
}
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;
}
@@ -530,6 +533,7 @@
" -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"
+ " -S | --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"
@@ -574,7 +578,7 @@
int
main(int argc, char **argv) {
- char *p, *offset, *encryption, *passfd, *device, *file;
+ char *p, *offset, *sizelimit, *encryption, *passfd, *device, *file;
char *keysize;
int delete, find, c, all;
int res = 0;
@@ -583,7 +587,7 @@
int pfd = -1;
int keysz = 0;
int hash_pass = 1;
- unsigned long long off;
+ unsigned long long off, slimit;
struct option longopts[] = {
{ "all", 0, 0, 'a' },
{ "detach", 0, 0, 'd' },
@@ -594,6 +598,7 @@
{ "nopasshash", 0, 0, 'N' },
{ "nohashpass", 0, 0, 'N' },
{ "offset", 1, 0, 'o' },
+ { "sizelimit", 1, 0, 'S' },
{ "pass-fd", 1, 0, 'p' },
{ "read-only", 0, 0, 'r' },
{ "show", 0, 0, 's' },
@@ -607,7 +612,8 @@
delete = find = all = 0;
off = 0;
- offset = encryption = passfd = NULL;
+ slimit = 0;
+ offset = sizelimit = encryption = passfd = NULL;
keysize = NULL;
progname = argv[0];
@@ -642,6 +648,9 @@
case 'o':
offset = optarg;
break;
+ case 'S':
+ sizelimit = optarg;
+ break;
case 'p':
passfd = optarg;
break;
@@ -659,7 +668,7 @@
if (argc == 1) {
usage();
} else if (delete) {
- if (argc != optind+1 || encryption || offset || find || all || showdev)
+ if (argc != optind+1 || encryption || offset || sizelimit || find || all || showdev)
usage();
} else if (find) {
if (all || argc < optind || argc > optind+1)
@@ -700,12 +709,14 @@
else {
if (offset && sscanf(offset, "%llu", &off) != 1)
usage();
+ if (sizelimit && sscanf(sizelimit, "%llu", &slimit) != 1)
+ usage();
if (passfd && sscanf(passfd, "%d", &pfd) != 1)
usage();
if (keysize && sscanf(keysize,"%d",&keysz) != 1)
usage();
do {
- res = set_loop(device, file, off, encryption, pfd, &ro, keysz, hash_pass);
+ res = set_loop(device, file, off, slimit, encryption, pfd, &ro, keysz, hash_pass);
if (res == 2 && find) {
if (verbose)
printf("stolen loop=%s...trying again\n",
diff -ru util-linux-2.13.1.orig/mount/lomount.h util-linux-2.13.1/mount/lomount.h
--- util-linux-2.13.1.orig/mount/lomount.h 2008-04-11 12:17:59.000000000 +0300
+++ util-linux-2.13.1/mount/lomount.h 2008-04-11 12:09:58.000000000 +0300
@@ -1,5 +1,5 @@
extern int verbose;
-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 *, int, int);
extern int del_loop(const char *);
extern int is_loop_device(const char *);
Only in util-linux-2.13.1/mount: losetup
diff -ru util-linux-2.13.1.orig/mount/losetup.8 util-linux-2.13.1/mount/losetup.8
--- util-linux-2.13.1.orig/mount/losetup.8 2008-04-11 12:17:59.000000000 +0300
+++ util-linux-2.13.1/mount/losetup.8 2008-04-11 12:15:29.000000000 +0300
@@ -33,6 +33,8 @@
.IR encryption ]
.RB [ \-o
.IR offset ]
+.RB [ \-S
+.IR sizelimit ]
.RB [ \-p
.IR pfd ]
.RB [ \-r ]
@@ -84,6 +86,8 @@
.IP "\fB\-o, \-\-offset \fIoffset\fP"
The data start is moved \fIoffset\fP bytes into the specified file or
device.
+.IP "\fB\-S, \-\-sizelimit \fIsizelimit\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 -ru util-linux-2.13.1.orig/mount/mount.c util-linux-2.13.1/mount/mount.c
--- util-linux-2.13.1.orig/mount/mount.c 2008-04-11 12:17:59.000000000 +0300
+++ util-linux-2.13.1/mount/mount.c 2008-04-11 12:10:13.000000000 +0300
@@ -891,7 +891,7 @@
keysz = strtoul(opt_keybits, NULL, 0);
if (opt_nohashpass)
hash_pass=0;
- if ((res = set_loop(*loopdev, *loopfile, offset,
+ if ((res = set_loop(*loopdev, *loopfile, offset, 0,
opt_encryption, pfd, &loopro, keysz, hash_pass))) {
if (res == 2) {
/* loop dev has been grabbed by some other process,