diff options
-rw-r--r-- | mount/lomount.c | 33 | ||||
-rw-r--r-- | mount/losetup.8 | 4 |
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" |