summaryrefslogtreecommitdiffstats
path: root/mount
diff options
context:
space:
mode:
authorKarel Zak2009-02-19 18:36:25 +0100
committerKarel Zak2009-02-19 18:51:43 +0100
commit27d320d6f9219cc4238d3bf69e8f66185f123e7e (patch)
tree01a24ddb14657f1e5a2ea6d35652d1ce0c24d0ec /mount
parenttests: refresh expected mount(8) outputs (diff)
downloadkernel-qcow2-util-linux-27d320d6f9219cc4238d3bf69e8f66185f123e7e.tar.gz
kernel-qcow2-util-linux-27d320d6f9219cc4238d3bf69e8f66185f123e7e.tar.xz
kernel-qcow2-util-linux-27d320d6f9219cc4238d3bf69e8f66185f123e7e.zip
losetup: detach more devices by "-d <loop> [<loop> ..]"
This patch allows to detach more devices by "losetup -d", for example: # losetup -a /dev/loop0: [0804]:9955739 (/home/images/ary0.img) /dev/loop1: [0804]:9955740 (/home/images/ary1.img) /dev/loop2: [0804]:9955745 (/home/images/ary2.img) # losetup -d /dev/loop0 /dev/loop1 /dev/loop2 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r--mount/lomount.c33
-rw-r--r--mount/losetup.84
2 files changed, 22 insertions, 15 deletions
diff --git a/mount/lomount.c b/mount/lomount.c
index ece0003e5..93bcb466b 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -807,23 +807,27 @@ set_loop(const char *device, const char *file, unsigned long long offset,
int
del_loop (const char *device) {
- int fd;
+ int fd, errsv;
if ((fd = open (device, O_RDONLY)) < 0) {
- int errsv = errno;
- fprintf(stderr, _("loop: can't delete device %s: %s\n"),
- device, strerror (errsv));
- return 1;
+ errsv = errno;
+ goto error;
}
if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
- perror ("ioctl: LOOP_CLR_FD");
- close(fd);
- return 1;
+ errsv = errno;
+ goto error;
}
close (fd);
if (verbose > 1)
printf(_("del_loop(%s): success\n"), device);
return 0;
+
+error:
+ fprintf(stderr, _("loop: can't delete device %s: %s\n"),
+ device, strerror(errsv));
+ if (fd >= 0)
+ close(fd);
+ return 1;
}
#else /* no LOOP_SET_FD defined */
@@ -868,7 +872,7 @@ usage(void) {
fprintf(stderr, _("\nUsage:\n"
" %1$s loop_device give info\n"
" %1$s -a | --all list all used\n"
- " %1$s -d | --detach <loopdev> delete\n"
+ " %1$s -d | --detach <loopdev> [<loopdev> ...] delete\n"
" %1$s -f | --find find unused\n"
" %1$s -j | --associated <file> [-o <num>] list all associated with <file>\n"
" %1$s [ options ] {-f|--find|loopdev} <file> setup\n"),
@@ -971,7 +975,7 @@ main(int argc, char **argv) {
if (argc == 1) {
usage();
} else if (delete) {
- if (argc != optind+1 || encryption || offset || sizelimit ||
+ if (argc < optind+1 || encryption || offset || sizelimit ||
find || all || showdev || assoc || ro)
usage();
} else if (find) {
@@ -1009,7 +1013,7 @@ main(int argc, char **argv) {
return 0;
}
file = argv[optind];
- } else {
+ } else if (!delete) {
device = argv[optind];
if (argc == optind+1)
file = NULL;
@@ -1017,9 +1021,10 @@ main(int argc, char **argv) {
file = argv[optind+1];
}
- if (delete)
- res = del_loop(device);
- else if (file == NULL)
+ if (delete) {
+ while (optind < argc)
+ res += del_loop(argv[optind++]);
+ } else if (file == NULL)
res = show_loop(device);
else {
if (passfd && sscanf(passfd, "%d", &pfd) != 1)
diff --git a/mount/losetup.8 b/mount/losetup.8
index 84f82e7a1..179101895 100644
--- a/mount/losetup.8
+++ b/mount/losetup.8
@@ -19,6 +19,8 @@ Delete loop:
.in +5
.B "losetup \-d"
.I loop_device
+.RB [ \fIloop_device\fP
+.RB ...]
.sp
.in -5
Print name of first unused loop device:
@@ -71,7 +73,7 @@ and finds the module that knows how to perform that encryption.
.IP "\fB\-a, \-\-all\fP"
show status of all loop devices
.IP "\fB\-d, \-\-detach\fP"
-detach the file or device associated with the specified loop device
+detach the file or device associated with the specified loop device(s)
.IP "\fB\-e, \-E, \-\-encryption \fIencryption_type\fP"
enable data encryption with specified name or number
.IP "\fB\-f, \-\-find\fP"