]> git.pld-linux.org Git - packages/util-linux.git/blob - util-linux-losetup-all.patch
- AC-branch only,
[packages/util-linux.git] / util-linux-losetup-all.patch
1 - losetup missing option -a [new feature]
2
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
5 @@ -9,6 +9,8 @@
6  .B losetup
7  .I loop_device
8  .sp
9 +.B losetup -a
10 +.sp
11  .in -5
12  Delete loop:
13  .sp
14 @@ -66,6 +68,8 @@
15  .B \-e
16  option.)
17  .SH OPTIONS
18 +.IP \fB\-a\fP
19 +Show status of all loop devices.
20  .IP \fB\-d\fP
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
25 @@ -28,6 +28,8 @@
26  extern char *xstrdup (const char *s);  /* not: #include "sundries.h" */
27  extern void error (const char *fmt, ...);      /* idem */
28  
29 +#define SIZE(a) (sizeof(a)/sizeof(a[0]))
30 +
31  #ifdef LOOP_SET_FD
32  
33  static int
34 @@ -128,6 +130,42 @@
35         close (fd);
36         return 1;
37  }
38 +
39 +static int
40 +show_used_loop_devices (void) {
41 +       char dev[20];
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;
46 +
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)) {
51 +                       somedev++;
52 +                       fd = open (dev, O_RDONLY);
53 +                       if (fd >= 0) {
54 +                               if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
55 +                                       show_loop(dev);
56 +                               close (fd);
57 +                               somedev++;
58 +                       } else if (errno == EACCES)
59 +                               permission++;
60 +                       continue; /* continue trying as long as devices exist */
61 +               }
62 +               break;
63 +           }
64 +       }
65 +
66 +       if (somedev==0 && permission) {
67 +               error(_("%s: no permission to look at /dev/loop#"), progname);
68 +               return 1;
69 +       }
70 +       return 0;
71 +}
72 +
73 +
74  #endif
75  
76  int
77 @@ -139,8 +177,6 @@
78                 major(statbuf.st_rdev) == LOOPMAJOR);
79  }
80  
81 -#define SIZE(a) (sizeof(a)/sizeof(a[0]))
82 -
83  char *
84  find_unused_loop_device (void) {
85         /* Just creating a device, say in /tmp, is probably a bad idea -
86 @@ -403,12 +439,13 @@
87  
88  static void
89  usage(void) {
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"),
102 +               progname);
103         exit(1);
104  }
105  
106 @@ -442,7 +479,7 @@
107  int
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;
112         int res = 0;
113         int ro = 0;
114         int pfd = -1;
115 @@ -452,7 +489,7 @@
116         bindtextdomain(PACKAGE, LOCALEDIR);
117         textdomain(PACKAGE);
118  
119 -       delete = find = 0;
120 +       delete = find = all = 0;
121         off = 0;
122         offset = encryption = passfd = NULL;
123  
124 @@ -460,8 +497,11 @@
125         if ((p = strrchr(progname, '/')) != NULL)
126                 progname = p+1;
127  
128 -       while ((c = getopt(argc, argv, "de:E:fo:p:v")) != -1) {
129 +       while ((c = getopt(argc, argv, "ade:E:fo:p:v")) != -1) {
130                 switch (c) {
131 +               case 'a':
132 +                       all = 1;
133 +                       break;
134                 case 'd':
135                         delete = 1;
136                         break;
137 @@ -489,17 +529,22 @@
138         if (argc == 1) {
139                 usage();
140         } else if (delete) {
141 -               if (argc != optind+1 || encryption || offset || find)
142 +               if (argc != optind+1 || encryption || offset || find || all)
143                         usage();
144         } else if (find) {
145 -               if (argc < optind || argc > optind+1)
146 +               if (all || argc < optind || argc > optind+1)
147 +                       usage();
148 +       } else if (all) {
149 +               if (argc > 2)
150                         usage();
151         } else {
152                 if (argc < optind+1 || argc > optind+2)
153                         usage();
154         }
155  
156 -       if (find) {
157 +       if (all)
158 +               return show_used_loop_devices();
159 +       else if (find) {
160                 device = find_unused_loop_device();
161                 if (device == NULL)
162                         return -1;
This page took 0.056601 seconds and 3 git commands to generate.