aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-05-23 16:11:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-05-23 16:11:42 +0200
commit309f5e3775ed9cc0837c6d93482735bc4f117d5b (patch)
tree86fff2acd2b6253afbd8829803aa37998078a52c
parent1115e40c887fc4d9ddddbe2b0d71c091065ee997 (diff)
downloadbusybox-w32-309f5e3775ed9cc0837c6d93482735bc4f117d5b.tar.gz
busybox-w32-309f5e3775ed9cc0837c6d93482735bc4f117d5b.tar.bz2
busybox-w32-309f5e3775ed9cc0837c6d93482735bc4f117d5b.zip
losetup: implement -c
function old new delta losetup_main 422 449 +27 packed_usage 33243 33264 +21 get_next_block 1677 1681 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 52/0) Total: 52 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/losetup.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c
index bf480e9bf..2248f2cba 100644
--- a/util-linux/losetup.c
+++ b/util-linux/losetup.c
@@ -20,10 +20,11 @@
20//kbuild:lib-$(CONFIG_LOSETUP) += losetup.o 20//kbuild:lib-$(CONFIG_LOSETUP) += losetup.o
21 21
22//usage:#define losetup_trivial_usage 22//usage:#define losetup_trivial_usage
23//usage: "[-r] [-o OFS] {-f|LOOPDEV} FILE - associate loop devices\n" 23//usage: "[-r] [-o OFS] {-f|LOOPDEV} FILE: associate loop devices\n"
24//usage: " losetup -d LOOPDEV - disassociate\n" 24//usage: " losetup -c LOOPDEV: reread file size\n"
25//usage: " losetup -a - show status\n" 25//usage: " losetup -d LOOPDEV: disassociate\n"
26//usage: " losetup -f - show next free loop device" 26//usage: " losetup -a: show status\n"
27//usage: " losetup -f: show next free loop device"
27//usage:#define losetup_full_usage "\n\n" 28//usage:#define losetup_full_usage "\n\n"
28//usage: " -o OFS Start OFS bytes into FILE" 29//usage: " -o OFS Start OFS bytes into FILE"
29//usage: "\n -r Read-only" 30//usage: "\n -r Read-only"
@@ -50,14 +51,15 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
50 char *opt_o; 51 char *opt_o;
51 char dev[LOOP_NAMESIZE]; 52 char dev[LOOP_NAMESIZE];
52 enum { 53 enum {
53 OPT_d = (1 << 0), 54 OPT_c = (1 << 0),
54 OPT_o = (1 << 1), 55 OPT_d = (1 << 1),
55 OPT_f = (1 << 2), 56 OPT_o = (1 << 2),
56 OPT_a = (1 << 3), 57 OPT_f = (1 << 3),
57 OPT_r = (1 << 4), /* must be last */ 58 OPT_a = (1 << 4),
59 OPT_r = (1 << 5),
58 }; 60 };
59 61
60 opt = getopt32(argv, "^" "do:far" "\0" "?2:d--ofar:a--ofr", &opt_o); 62 opt = getopt32(argv, "^" "cdo:far" "\0" "?2:d--ofar:a--ofr", &opt_o);
61 argv += optind; 63 argv += optind;
62 64
63 /* LOOPDEV */ 65 /* LOOPDEV */
@@ -73,6 +75,16 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
73 return EXIT_SUCCESS; 75 return EXIT_SUCCESS;
74 } 76 }
75 77
78 /* -c LOOPDEV */
79 if (opt == OPT_c && argv[0]) {
80 int fd = xopen(argv[0], O_RDONLY);
81#ifndef LOOP_SET_CAPACITY
82# define LOOP_SET_CAPACITY 0x4C07
83#endif
84 xioctl(fd, LOOP_SET_CAPACITY, /*ignored:*/0);
85 return EXIT_SUCCESS;
86 }
87
76 /* -d LOOPDEV */ 88 /* -d LOOPDEV */
77 if (opt == OPT_d && argv[0]) { 89 if (opt == OPT_d && argv[0]) {
78 if (del_loop(argv[0])) 90 if (del_loop(argv[0]))