* [PATCH 1/2] losetup: print verbose messages if requested
@ 2011-09-30 10:05 Petr Uzel
2011-09-30 10:05 ` [PATCH 2/2] losetup: new -D option to delete all used loop devices Petr Uzel
2011-10-03 13:51 ` [PATCH 1/2] losetup: print verbose messages if requested Karel Zak
0 siblings, 2 replies; 4+ messages in thread
From: Petr Uzel @ 2011-09-30 10:05 UTC (permalink / raw)
To: util-linux
verbose can't be > 1
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
mount/lomount.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mount/lomount.c b/mount/lomount.c
index ff99413..441860b 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -930,7 +930,7 @@ set_loop(const char *device, const char *file, unsigned long long offset,
if (!(*options & SETLOOP_AUTOCLEAR))
close (fd);
- if (verbose > 1)
+ if (verbose)
printf(_("set_loop(%s,%s,%llu,%llu): success\n"),
device, filename, offset, sizelimit);
if (file != filename)
@@ -951,7 +951,7 @@ del_loop (const char *device) {
goto error;
}
close (fd);
- if (verbose > 1)
+ if (verbose)
printf(_("del_loop(%s): success\n"), device);
return 0;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] losetup: new -D option to delete all used loop devices
2011-09-30 10:05 [PATCH 1/2] losetup: print verbose messages if requested Petr Uzel
@ 2011-09-30 10:05 ` Petr Uzel
2011-10-03 13:52 ` Karel Zak
2011-10-03 13:51 ` [PATCH 1/2] losetup: print verbose messages if requested Karel Zak
1 sibling, 1 reply; 4+ messages in thread
From: Petr Uzel @ 2011-09-30 10:05 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
mount/lomount.c | 45 +++++++++++++++++++++++++++++++++++++++++----
mount/losetup.8 | 6 ++++++
2 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/mount/lomount.c b/mount/lomount.c
index 441860b..ae49157 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -938,6 +938,32 @@ set_loop(const char *device, const char *file, unsigned long long offset,
return 0;
}
+static int
+delete_all_devices (void)
+{
+ struct looplist ll;
+ int fd;
+ int ok;
+
+ if (looplist_open(&ll, LLFLG_USEDONLY) == -1) {
+ error(_("%s: /dev directory does not exist."), progname);
+ return 1;
+ }
+
+ while((fd = looplist_next(&ll)) != -1) {
+ close(fd);
+ ok |= del_loop(ll.name);
+ }
+ looplist_close(&ll);
+
+ if (!ll.ct_succ && ll.ct_perm) {
+ error(_("%s: no permission to look at /dev/loop%s<N>"), progname,
+ (ll.flag & LLFLG_SUBDIR) ? "/" : "");
+ return 1;
+ }
+ return ok;
+}
+
int
del_loop (const char *device) {
int fd, errsv;
@@ -1015,6 +1041,7 @@ usage(FILE *out) {
_(" %1$s loop_device give info\n"
" %1$s -a | --all list all used\n"
" %1$s -d | --detach <loopdev> [<loopdev> ...] delete\n"
+ " %1$s -D | --detach-all delete all used\n"
" %1$s -f | --find find unused\n"
" %1$s -c | --set-capacity <loopdev> resize\n"
" %1$s -j | --associated <file> [-o <num>] list all associated with <file>\n"
@@ -1037,7 +1064,7 @@ usage(FILE *out) {
int
main(int argc, char **argv) {
char *p, *offset, *sizelimit, *encryption, *passfd, *device, *file, *assoc;
- int delete, find, c, all, capacity;
+ int delete, delete_all, find, c, all, capacity;
int res = 0;
int showdev = 0;
int ro = 0;
@@ -1048,6 +1075,7 @@ main(int argc, char **argv) {
{ "all", 0, 0, 'a' },
{ "set-capacity", 0, 0, 'c' },
{ "detach", 0, 0, 'd' },
+ { "detach-all", 0, 0, 'D' },
{ "encryption", 1, 0, 'e' },
{ "find", 0, 0, 'f' },
{ "help", 0, 0, 'h' },
@@ -1065,14 +1093,14 @@ main(int argc, char **argv) {
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- capacity = delete = find = all = 0;
+ capacity = delete = delete_all = find = all = 0;
assoc = offset = sizelimit = encryption = passfd = NULL;
progname = argv[0];
if ((p = strrchr(progname, '/')) != NULL)
progname = p+1;
- while ((c = getopt_long(argc, argv, "acde:E:fhj:o:p:rsv",
+ while ((c = getopt_long(argc, argv, "acdDe:E:fhj:o:p:rsv",
longopts, NULL)) != -1) {
switch (c) {
case 'a':
@@ -1087,6 +1115,9 @@ main(int argc, char **argv) {
case 'd':
delete = 1;
break;
+ case 'D':
+ delete_all = 1;
+ break;
case 'E':
case 'e':
encryption = optarg;
@@ -1128,10 +1159,14 @@ main(int argc, char **argv) {
if (argc < optind+1 || encryption || offset || sizelimit ||
capacity || find || all || showdev || assoc || ro)
usage(stderr);
+ } else if (delete_all) {
+ if (argc > optind || encryption || offset || sizelimit ||
+ capacity || find || all || showdev || assoc || ro)
+ usage(stderr);
} else if (find) {
if (capacity || all || assoc || argc < optind || argc > optind+1)
usage(stderr);
- } else if (all) {
+ } else if (all || delete_all) {
/* only -v is allowed */
if ((argc == 3 && verbose == 0) || argc > 3)
usage(stderr);
@@ -1159,6 +1194,8 @@ main(int argc, char **argv) {
if (all)
return show_used_loop_devices();
+ else if (delete_all)
+ return delete_all_devices();
else if (assoc)
return show_associated_loop_devices(assoc, off, offset ? 1 : 0);
else if (find) {
diff --git a/mount/losetup.8 b/mount/losetup.8
index f1db80b..a6b45a0 100644
--- a/mount/losetup.8
+++ b/mount/losetup.8
@@ -24,6 +24,12 @@ Delete loop:
.IR loopdev ...
.sp
.in -5
+Delete all used loop devices:
+.sp
+.in +5
+.B "losetup \-D"
+.sp
+.in -5
Print name of first unused loop device:
.sp
.in +5
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] losetup: print verbose messages if requested
2011-09-30 10:05 [PATCH 1/2] losetup: print verbose messages if requested Petr Uzel
2011-09-30 10:05 ` [PATCH 2/2] losetup: new -D option to delete all used loop devices Petr Uzel
@ 2011-10-03 13:51 ` Karel Zak
1 sibling, 0 replies; 4+ messages in thread
From: Karel Zak @ 2011-10-03 13:51 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Fri, Sep 30, 2011 at 12:05:25PM +0200, Petr Uzel wrote:
> mount/lomount.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] losetup: new -D option to delete all used loop devices
2011-09-30 10:05 ` [PATCH 2/2] losetup: new -D option to delete all used loop devices Petr Uzel
@ 2011-10-03 13:52 ` Karel Zak
0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2011-10-03 13:52 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Fri, Sep 30, 2011 at 12:05:26PM +0200, Petr Uzel wrote:
>
> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
> ---
> mount/lomount.c | 45 +++++++++++++++++++++++++++++++++++++++++----
> mount/losetup.8 | 6 ++++++
> 2 files changed, 47 insertions(+), 4 deletions(-)
>
> diff --git a/mount/lomount.c b/mount/lomount.c
> index 441860b..ae49157 100644
> --- a/mount/lomount.c
> +++ b/mount/lomount.c
> @@ -938,6 +938,32 @@ set_loop(const char *device, const char *file, unsigned long long offset,
> return 0;
> }
>
> +static int
> +delete_all_devices (void)
> +{
> + struct looplist ll;
> + int fd;
> + int ok;
int ok = 0; :-)
> + if (looplist_open(&ll, LLFLG_USEDONLY) == -1) {
> + error(_("%s: /dev directory does not exist."), progname);
> + return 1;
> + }
> +
> + while((fd = looplist_next(&ll)) != -1) {
> + close(fd);
> + ok |= del_loop(ll.name);
> + }
[...]
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-03 13:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-30 10:05 [PATCH 1/2] losetup: print verbose messages if requested Petr Uzel
2011-09-30 10:05 ` [PATCH 2/2] losetup: new -D option to delete all used loop devices Petr Uzel
2011-10-03 13:52 ` Karel Zak
2011-10-03 13:51 ` [PATCH 1/2] losetup: print verbose messages if requested Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).