1 - losetup missing option -a [new feature]
3 --- util-linux-2.13-pre6/mount/losetup.8.all 2006-10-12 10:34:47.000000000 +0200
4 +++ util-linux-2.13-pre6/mount/losetup.8 2006-10-12 10:37:35.000000000 +0200
19 +Show status of all loop devices.
21 Detach the file or device associated with the specified loop device.
22 .IP "\fB\-E \fIencryption_type\fP"
23 --- util-linux-2.13-pre6/mount/lomount.c.all 2004-12-20 23:11:04.000000000 +0100
24 +++ util-linux-2.13-pre6/mount/lomount.c 2006-10-12 10:29:55.000000000 +0200
26 extern char *xstrdup (const char *s); /* not: #include "sundries.h" */
27 extern void error (const char *fmt, ...); /* idem */
29 +#define SIZE(a) (sizeof(a)/sizeof(a[0]))
40 +show_used_loop_devices (void) {
42 + char *loop_formats[] = { "/dev/loop%d", "/dev/loop/%d" };
43 + int i, j, fd, permission = 0, somedev = 0;
44 + struct stat statbuf;
45 + struct loop_info loopinfo;
47 + for (j = 0; j < SIZE(loop_formats); j++) {
48 + for(i = 0; i < 256; i++) {
49 + sprintf(dev, loop_formats[j], i);
50 + if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
52 + fd = open (dev, O_RDONLY);
54 + if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
58 + } else if (errno == EACCES)
60 + continue; /* continue trying as long as devices exist */
66 + if (somedev==0 && permission) {
67 + error(_("%s: no permission to look at /dev/loop#"), progname);
78 major(statbuf.st_rdev) == LOOPMAJOR);
81 -#define SIZE(a) (sizeof(a)/sizeof(a[0]))
84 find_unused_loop_device (void) {
85 /* Just creating a device, say in /tmp, is probably a bad idea -
90 - fprintf(stderr, _("usage:\n\
91 - %s loop_device # give info\n\
92 - %s -d loop_device # delete\n\
93 - %s -f # find unused\n\
94 - %s [-e encryption] [-o offset] {-f|loop_device} file # setup\n"),
95 - progname, progname, progname, progname);
96 + fprintf(stderr, _("usage:\n"
97 + " %1$s loop_device # give info\n"
98 + " %1$s -d loop_device # delete\n"
99 + " %1$s -f # find unused\n"
100 + " %1$s -a # list all used\n"
101 + " %1$s [-e encryption] [-o offset] {-f|loop_device} file # setup\n"),
108 main(int argc, char **argv) {
109 char *p, *offset, *encryption, *passfd, *device, *file;
110 - int delete, find, c;
111 + int delete, find, c, all;
116 bindtextdomain(PACKAGE, LOCALEDIR);
120 + delete = find = all = 0;
122 offset = encryption = passfd = NULL;
125 if ((p = strrchr(progname, '/')) != NULL)
128 - while ((c = getopt(argc, argv, "de:E:fo:p:v")) != -1) {
129 + while ((c = getopt(argc, argv, "ade:E:fo:p:v")) != -1) {
137 @@ -489,17 +529,22 @@
141 - if (argc != optind+1 || encryption || offset || find)
142 + if (argc != optind+1 || encryption || offset || find || all)
145 - if (argc < optind || argc > optind+1)
146 + if (all || argc < optind || argc > optind+1)
152 if (argc < optind+1 || argc > optind+2)
158 + return show_used_loop_devices();
160 device = find_unused_loop_device();