util-linux/util-linux-2.13-losetup-all.patch
kzak 35b20313b2 - fix #169628 - /usr/bin/floppy doesn't work with /dev/fd0
- fix #168436 - login will attempt to run if it has no read/write access to
    its terminal
- fix #168434 - login's timeout can fail - needs to call
    siginterrupt(SIGALRM,1)
- fix #165253 – losetup missing option -a [new feature]
- update PAM files (replace pam_stack with new "include" PAM directive)
- remove kbdrate from src.rpm
- update to 2.13pre4
2005-10-07 19:34:46 +00:00

141 lines
3.6 KiB
Diff

--- util-linux-2.13-pre2/mount/lomount.c.all 2005-08-29 16:59:06.000000000 +0200
+++ util-linux-2.13-pre2/mount/lomount.c 2005-08-29 17:17:49.000000000 +0200
@@ -28,6 +28,8 @@
extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
extern void error (const char *fmt, ...); /* idem */
+#define SIZE(a) (sizeof(a)/sizeof(a[0]))
+
#ifdef LOOP_SET_FD
static int
@@ -128,6 +130,42 @@
close (fd);
return 1;
}
+
+static int
+show_used_loop_devices (void) {
+ char dev[20];
+ char *loop_formats[] = { "/dev/loop%d", "/dev/loop/%d" };
+ int i, j, fd, permission = 0, somedev = 0;
+ struct stat statbuf;
+ struct loop_info loopinfo;
+
+ for (j = 0; j < SIZE(loop_formats); j++) {
+ for(i = 0; i < 256; i++) {
+ sprintf(dev, loop_formats[j], i);
+ if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
+ somedev++;
+ fd = open (dev, O_RDONLY);
+ if (fd >= 0) {
+ if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
+ show_loop(dev);
+ close (fd);
+ somedev++;
+ } else if (errno == EACCES)
+ permission++;
+ continue; /* continue trying as long as devices exist */
+ }
+ break;
+ }
+ }
+
+ if (somedev==0 && permission) {
+ error(_("%s: no permission to look at /dev/loop#"), progname);
+ return 1;
+ }
+ return 0;
+}
+
+
#endif
int
@@ -139,8 +177,6 @@
major(statbuf.st_rdev) == LOOPMAJOR);
}
-#define SIZE(a) (sizeof(a)/sizeof(a[0]))
-
char *
find_unused_loop_device (void) {
/* Just creating a device, say in /tmp, is probably a bad idea -
@@ -403,12 +439,13 @@
static void
usage(void) {
- fprintf(stderr, _("usage:\n\
- %s loop_device # give info\n\
- %s -d loop_device # delete\n\
- %s -f # find unused\n\
- %s [-e encryption] [-o offset] {-f|loop_device} file # setup\n"),
- progname, progname, progname, progname);
+ fprintf(stderr, _("usage:\n"
+ " %1$s loop_device # give info\n"
+ " %1$s -d loop_device # delete\n"
+ " %1$s -f # find unused\n"
+ " %1$s -a # list all used\n"
+ " %1$s [-e encryption] [-o offset] {-f|loop_device} file # setup\n"),
+ progname);
exit(1);
}
@@ -442,7 +479,7 @@
int
main(int argc, char **argv) {
char *p, *offset, *encryption, *passfd, *device, *file;
- int delete, find, c;
+ int delete, find, c, all;
int res = 0;
int ro = 0;
int pfd = -1;
@@ -452,7 +489,7 @@
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- delete = find = 0;
+ delete = find = all = 0;
off = 0;
offset = encryption = passfd = NULL;
@@ -460,8 +497,11 @@
if ((p = strrchr(progname, '/')) != NULL)
progname = p+1;
- while ((c = getopt(argc, argv, "de:E:fo:p:v")) != -1) {
+ while ((c = getopt(argc, argv, "ade:E:fo:p:v")) != -1) {
switch (c) {
+ case 'a':
+ all = 1;
+ break;
case 'd':
delete = 1;
break;
@@ -489,17 +529,22 @@
if (argc == 1) {
usage();
} else if (delete) {
- if (argc != optind+1 || encryption || offset || find)
+ if (argc != optind+1 || encryption || offset || find || all)
usage();
} else if (find) {
- if (argc < optind || argc > optind+1)
+ if (all || argc < optind || argc > optind+1)
+ usage();
+ } else if (all) {
+ if (argc > 2)
usage();
} else {
if (argc < optind+1 || argc > optind+2)
usage();
}
- if (find) {
+ if (all)
+ return show_used_loop_devices();
+ else if (find) {
device = find_unused_loop_device();
if (device == NULL)
return -1;