~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to debian/patches/losetup_add_option_f.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2008-08-22 11:57:17 UTC
  • mfrom: (8.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080822115717-v8wfa8pxwlfvyje0
Tags: 2.13.1-4
* patches/losetup_add_option_f.dpatch: 
  - Added to support "find next free loop" in losetup.
    (closes: #495682)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## losetup_add_option_f.patch by Max Vozeler <xam@debian.org>
 
3
##
 
4
## DP: Add support for option -f ("find next free loop") which is
 
5
## DP: supported in util-linux-ng proper. See Bug#495682.
 
6
 
 
7
@DPATCH@
 
8
diff -urNad trunk~/mount/lomount.c trunk/mount/lomount.c
 
9
--- trunk~/mount/lomount.c      2008-08-19 20:19:35.000000000 +0200
 
10
+++ trunk/mount/lomount.c       2008-08-19 20:19:53.000000000 +0200
 
11
@@ -163,7 +163,6 @@
 
12
 
 
13
 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
 
14
 
 
15
-#if !defined(MAIN)
 
16
 char *
 
17
 find_unused_loop_device (void) {
 
18
        /* Just creating a device, say in /tmp, is probably a bad idea -
 
19
@@ -205,6 +204,7 @@
 
20
        return 0;
 
21
 }
 
22
 
 
23
+#if !defined(MAIN)
 
24
 int is_loop_active(const char *dev, const char *backdev)
 
25
 {
 
26
        int fd;
 
27
@@ -1081,12 +1081,13 @@
 
28
   %s -F [options] loop_device [file]   # setup, read /etc/fstab\n\
 
29
   %s loop_device                       # give info\n\
 
30
   %s -a                                # give info of all loops\n\
 
31
+  %s -f                                # show next free loop device\n\
 
32
   %s -d loop_device                    # delete\n\
 
33
   %s -R loop_device                    # resize\n\
 
34
 options:  -e encryption  -o offset  -s sizelimit  -p passwdfd  -T  -S pseed\n\
 
35
           -H phash  -I loinit  -K gpgkey  -G gpghome  -C itercountk  -v  -r\n\
 
36
           -P cleartextkey\n"),
 
37
-               progname, progname, progname, progname, progname, progname);
 
38
+               progname, progname, progname, progname, progname, progname, progname);
 
39
        exit(1);
 
40
 }
 
41
 
 
42
@@ -1252,7 +1253,8 @@
 
43
 int
 
44
 main(int argc, char **argv) {
 
45
        char *partitionName = NULL;
 
46
-       int delete,c,option_a=0,option_F=0,option_R=0,setup_o=0;
 
47
+       char *device = NULL;
 
48
+       int delete,find,c,option_a=0,option_F=0,option_R=0,setup_o=0;
 
49
        int res = 0;
 
50
        int ro = 0;
 
51
 
 
52
@@ -1260,9 +1262,9 @@
 
53
        bindtextdomain(PACKAGE, LOCALEDIR);
 
54
        textdomain(PACKAGE);
 
55
 
 
56
-       delete = 0;
 
57
+       delete = find = 0;
 
58
        progname = argv[0];
 
59
-       while ((c = getopt(argc,argv,"aC:de:FG:H:I:K:o:p:P:rRs:S:Tv")) != -1) {
 
60
+       while ((c = getopt(argc,argv,"aC:de:fFG:H:I:K:o:p:P:rRs:S:Tv")) != -1) {
 
61
                switch (c) {
 
62
                case 'a':               /* show status of all loops */
 
63
                        option_a = 1;
 
64
@@ -1278,6 +1280,9 @@
 
65
                        loopEncryptionType = optarg;
 
66
                        setup_o = 1;
 
67
                        break;
 
68
+               case 'f':               /* find free loop */
 
69
+                       find = 1;
 
70
+                       break;
 
71
                case 'F':               /* read loop related options from /etc/fstab */
 
72
                        option_F = 1;
 
73
                        setup_o = 1;
 
74
@@ -1336,12 +1341,22 @@
 
75
                        usage();
 
76
                }
 
77
        }
 
78
-       if (option_a + delete + option_R + setup_o > 1) usage();
 
79
+       if (option_a + delete + option_R + setup_o + find > 1) usage();
 
80
        if (option_a) {
 
81
                /* show all loops */
 
82
                if (argc != optind) usage();
 
83
                show_all_loops();
 
84
                res = 0;
 
85
+       } else if (find) {
 
86
+               if (argc != optind)
 
87
+                       usage();
 
88
+               device = find_unused_loop_device();
 
89
+               if (device == NULL)
 
90
+                       return -1;
 
91
+               if (verbose)
 
92
+                       printf("Loop device is %s\n", device);
 
93
+               printf("%s\n", device);
 
94
+               res = 0;
 
95
        } else if (delete) {
 
96
                /* delete loop */
 
97
                if (argc != optind+1) usage();
 
98
diff -urNad trunk~/mount/losetup.8 trunk/mount/losetup.8
 
99
--- trunk~/mount/losetup.8      2008-08-19 20:19:35.000000000 +0200
 
100
+++ trunk/mount/losetup.8       2008-08-19 20:19:35.000000000 +0200
 
101
@@ -21,6 +21,8 @@
 
102
 .br
 
103
 .B losetup -a
 
104
 .br
 
105
+.B losetup -f
 
106
+.br
 
107
 .B losetup
 
108
 .B \-R
 
109
 .I loop_device
 
110
@@ -64,6 +66,8 @@
 
111
 configuration or corresponding modules have been loaded to kernel.
 
112
 .PD
 
113
 .RE
 
114
+.IP "\fB\-f\fP"
 
115
+Find and show next unused loop device.
 
116
 .IP "\fB\-F\fP"
 
117
 Reads and uses mount options from /etc/fstab that match specified loop
 
118
 device, including offset= sizelimit= encryption= pseed= phash= loinit=