]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: make --remove a long-only option with mutual exclusivity
authorKarel Zak <kzak@redhat.com>
Thu, 16 Oct 2025 09:56:08 +0000 (11:56 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 21 Oct 2025 09:17:47 +0000 (11:17 +0200)
Change --remove from '-R, --remove' to a long-only option '--remove'.
This makes it consistent with other administrative options and adds
mutual exclusivity with other major actions like -d, -D, -a, -c, -f,
-j, -l, and -O.

Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/losetup
sys-utils/losetup.8.adoc
sys-utils/losetup.c

index b668782fbf6984bb566f98a2ed89f926464ca8a2..783d966c79c933356b1b61938eb293cc915ddf35 100644 (file)
@@ -15,7 +15,7 @@ _losetup_module()
                        COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
                        return 0
                        ;;
-               '-c'|'--set-capacity')
+               '-c'|'--set-capacity'|'--remove')
                        ARG="$(for I in /dev/loop[0-9]*; do if [ -e $I ]; then echo $I; fi; done)"
                        COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
                        return 0
@@ -57,6 +57,7 @@ _losetup_module()
                                --sizelimit
                                --partscan
                                --read-only
+                               --remove
                                --show
                                --verbose
                                --json
index 4437088b8afa7e1f9dc7517659f64fd5522ec51b..fa6ff119dfac65495d4f66ccd4ba3c13bba3e1eb 100644 (file)
@@ -38,7 +38,7 @@ Resize a loop device:
 
 Remove a loop device:
 
-*losetup* *-R* _loopdev_ ...
+*losetup* *--remove* _loopdev_ ...
 
 == DESCRIPTION
 
@@ -127,7 +127,7 @@ Use the raw *--list* output format.
 *-J*, *--json*::
 Use JSON format for *--list* output.
 
-*-R*, *--remove* _loopdev_...::
+*--remove* _loopdev_...::
 The parameter is not recommended for direct use.
 *-d* or *-D* option to disconnect the file from the loop device, we can see a loop device
 of size 0 by running 'lsblk -a'. At this point, the loop device will still in the system.
index d694190be397c35f1efdb36de8f1597bbb90ebec..8320d580548f5e3ddf4c5893cf69fe4b7cfcbdab 100644 (file)
@@ -489,7 +489,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -c, --set-capacity <loopdev>  resize the device\n"), out);
        fputs(_(" -j, --associated <file>       list all devices associated with <file>\n"), out);
        fputs(_(" -L, --nooverlap               avoid possible conflict between devices\n"), out);
-       fputs(_(" -R, --remove <loopdev>...     remove one or more devices\n"), out);
+       fputs(_("     --remove <loopdev>...     remove one or more devices\n"), out);
 
        /* commands options */
        fputs(USAGE_SEPARATOR, out);
@@ -704,7 +704,8 @@ int main(int argc, char **argv)
                OPT_RAW,
                OPT_REF,
                OPT_DIO,
-               OPT_OUTPUT_ALL
+               OPT_OUTPUT_ALL,
+               OPT_REMOVE
        };
        static const struct option longopts[] = {
                { "all",          no_argument,       NULL, 'a'           },
@@ -731,14 +732,14 @@ int main(int argc, char **argv)
                { "show",         no_argument,       NULL, OPT_SHOW      },
                { "verbose",      no_argument,       NULL, 'v'           },
                { "version",      no_argument,       NULL, 'V'           },
-               { "remove",       required_argument, NULL, 'R'           },
+               { "remove",       required_argument, NULL, OPT_REMOVE    },
                { NULL, 0, NULL, 0 }
        };
 
        static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
-               { 'D','a','c','d','f','j' },
-               { 'D','c','d','f','l' },
-               { 'D','c','d','f','O' },
+               { 'D','a','c','d','f','j',OPT_REMOVE },
+               { 'D','c','d','f','l',OPT_REMOVE },
+               { 'D','c','d','f','O',OPT_REMOVE },
                { 'J',OPT_RAW },
                { 0 }
        };
@@ -752,7 +753,7 @@ int main(int argc, char **argv)
        if (loopcxt_init(&lc, 0))
                err(EXIT_FAILURE, _("failed to initialize loopcxt"));
 
-       while ((c = getopt_long(argc, argv, "ab:c:d:Dfhj:JlLno:O:PrvVR:",
+       while ((c = getopt_long(argc, argv, "ab:c:d:Dfhj:JlLno:O:PrvV",
                                longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -846,7 +847,7 @@ int main(int argc, char **argv)
                case 'V':
                        print_version(EXIT_SUCCESS);
 
-               case 'R':
+               case OPT_REMOVE:
                        act = A_REMOVE;
                        if (loopcxt_set_device(&lc, optarg))
                                err(EXIT_FAILURE, _("%s: failed to use device"),