[Bug 6314] New: losetup : when -o and -r are combined, -o is ignored
bugzilla at busybox.net
bugzilla at busybox.net
Tue Jun 11 10:19:05 UTC 2013
https://bugs.busybox.net/show_bug.cgi?id=6314
Summary: losetup : when -o and -r are combined, -o is ignored
Product: Busybox
Version: unspecified
Platform: PC
OS/Version: Windows
Status: NEW
Severity: minor
Priority: P5
Component: Other
AssignedTo: unassigned at busybox.net
ReportedBy: vincent_galceran at yahoo.com
CC: busybox-cvs at busybox.net
Estimated Hours: 0.0
Hi,
I'm using busybox 1.20.2.
I think this is a bug : using losetup, when -r and -o options are combined, -o
option is ignored.
Also, combining -r and -d, behaves like no options.
The search of free loop devices was also limited to 8. This is set by kernel
command line "max_loop=##" and I want more than 8 loop devices.
Most of the time, losetup was exiting without error.
Here is the patch :
--- util-linux/losetup.c.orig 2013-05-30 11:02:40.000000000 +0200
+++ util-linux/losetup.c 2013-05-30 12:03:54.000000000 +0200
@@ -38,7 +38,7 @@
OPT_d = (1 << 0),
OPT_o = (1 << 1),
OPT_f = (1 << 2),
- OPT_r = (1 << 3), /* must be last */
+ OPT_r = (1 << 3),
};
/* max 2 args, -d,-o,-f opts are mutually exclusive */
@@ -46,13 +46,15 @@
opt = getopt32(argv, "do:fr", &opt_o);
argv += optind;
- if (opt == OPT_o)
+ if (opt & OPT_o)
offset = xatoull(opt_o);
- if (opt == OPT_d) {
+ if (opt & OPT_d) {
/* -d BLOCKDEV */
- if (!argv[0] || argv[1])
+ if (!argv[0] || argv[1]){
bb_show_usage();
+ return EXIT_FAILURE;
+ }
if (del_loop(argv[0]))
bb_simple_perror_msg_and_die(argv[0]);
return EXIT_SUCCESS;
@@ -61,12 +63,14 @@
if (argv[0]) {
char *s;
- if (opt == OPT_f) /* -f should not have arguments */
+ if (opt & OPT_f){ /* -f should not have arguments */
bb_show_usage();
+ return EXIT_FAILURE;
+ }
if (argv[1]) {
/* [-r] [-o OFS] BLOCKDEV FILE */
- if (set_loop(&argv[0], argv[1], offset, (opt / OPT_r)) < 0)
+ if (set_loop(&argv[0], argv[1], offset, (opt & OPT_r)?1:0) < 0)
bb_simple_perror_msg_and_die(argv[0]);
return EXIT_SUCCESS;
}
@@ -88,20 +92,20 @@
sprintf(dev, LOOP_FORMAT, n);
s = query_loop(dev);
- n++;
if (!s) {
- if (n > 9 && errno && errno != ENXIO)
- return EXIT_SUCCESS;
- if (opt == OPT_f) {
+ if (errno && errno != ENXIO)
+ return (opt & OPT_f) ? EXIT_FAILURE : EXIT_SUCCESS;
+ if (opt & OPT_f) {
puts(dev);
return EXIT_SUCCESS;
}
} else {
- if (opt != OPT_f)
+ if (!(opt & OPT_f))
printf("%s: %s\n", dev, s);
if (ENABLE_FEATURE_CLEAN_UP)
free(s);
}
+ n++;
}
return EXIT_SUCCESS;
}
----------------------------------------------------------------------
Note that I saw a strange way to determine the length of the name of a loop
device in libbb.h :
# define LOOP_NAMESIZE (sizeof("/dev/loop") + sizeof(int)*3 + 1)
or
# define LOOP_NAMESIZE (sizeof("/dev/loop/") + sizeof(int)*3 + 1)
"sizeof(int)" is not the length of one digit character.... Anyway, this is
larger, so it won't harm.
Thanks,
--
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the busybox-cvs
mailing list