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 */
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"),
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) {
return 0;
}
file = argv[optind];
- } else {
+ } else if (!delete) {
device = argv[optind];
if (argc == optind+1)
file = NULL;
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)
.in +5
.B "losetup \-d"
.I loop_device
+.RB [ \fIloop_device\fP
+.RB ...]
.sp
.in -5
Print name of first unused loop device:
.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"