From: Karel Zak Date: Thu, 16 Oct 2025 09:56:08 +0000 (+0200) Subject: losetup: make --remove a long-only option with mutual exclusivity X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8008075ce50114478cc1d4c9411e9a2439cac6bf;p=thirdparty%2Futil-linux.git losetup: make --remove a long-only option with mutual exclusivity 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 --- diff --git a/bash-completion/losetup b/bash-completion/losetup index b668782fb..783d966c7 100644 --- a/bash-completion/losetup +++ b/bash-completion/losetup @@ -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 diff --git a/sys-utils/losetup.8.adoc b/sys-utils/losetup.8.adoc index 4437088b8..fa6ff119d 100644 --- a/sys-utils/losetup.8.adoc +++ b/sys-utils/losetup.8.adoc @@ -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. diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index d694190be..8320d5805 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -489,7 +489,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -c, --set-capacity resize the device\n"), out); fputs(_(" -j, --associated list all devices associated with \n"), out); fputs(_(" -L, --nooverlap avoid possible conflict between devices\n"), out); - fputs(_(" -R, --remove ... remove one or more devices\n"), out); + fputs(_(" --remove ... 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"),