diff options
author | Jack O'Sullivan <jackos1998@gmail.com> | 2019-05-28 15:28:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-30 16:22:52 +0200 |
commit | 726cbb1be8620496cdf05d23bd98bdeb0983b4f0 (patch) | |
tree | c85dcdbbe86fe8e3920ec1f0869736c6594fd1ee | |
parent | bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a (diff) | |
download | busybox-w32-726cbb1be8620496cdf05d23bd98bdeb0983b4f0.tar.gz busybox-w32-726cbb1be8620496cdf05d23bd98bdeb0983b4f0.tar.bz2 busybox-w32-726cbb1be8620496cdf05d23bd98bdeb0983b4f0.zip |
losetup: Add partition scanning option
Add -P option from util-linux losetup to scan for partitions.
function old new delta
losetup_main 449 482 +33
packed_usage 33264 33292 +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0) Total: 61 bytes
Signed-off-by: Jack O'Sullivan <jackos1998@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | util-linux/losetup.c | 27 |
2 files changed, 18 insertions, 10 deletions
diff --git a/include/libbb.h b/include/libbb.h index 33766e989..3a870bf80 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1471,6 +1471,7 @@ extern int set_loop(char **devname, const char *file, unsigned long long offset, | |||
1471 | /* These constants match linux/loop.h (without BB_ prefix): */ | 1471 | /* These constants match linux/loop.h (without BB_ prefix): */ |
1472 | #define BB_LO_FLAGS_READ_ONLY 1 | 1472 | #define BB_LO_FLAGS_READ_ONLY 1 |
1473 | #define BB_LO_FLAGS_AUTOCLEAR 4 | 1473 | #define BB_LO_FLAGS_AUTOCLEAR 4 |
1474 | #define BB_LO_FLAGS_PARTSCAN 8 | ||
1474 | 1475 | ||
1475 | /* Returns malloced str */ | 1476 | /* Returns malloced str */ |
1476 | char *bb_ask_noecho(int fd, int timeout, const char *prompt) FAST_FUNC; | 1477 | char *bb_ask_noecho(int fd, int timeout, const char *prompt) FAST_FUNC; |
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index 2248f2cba..b52d693ec 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -20,13 +20,14 @@ | |||
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: "[-rP] [-o OFS] {-f|LOOPDEV} FILE: associate loop devices\n" |
24 | //usage: " losetup -c LOOPDEV: reread file size\n" | 24 | //usage: " losetup -c LOOPDEV: reread file size\n" |
25 | //usage: " losetup -d LOOPDEV: disassociate\n" | 25 | //usage: " losetup -d LOOPDEV: disassociate\n" |
26 | //usage: " losetup -a: show status\n" | 26 | //usage: " losetup -a: show status\n" |
27 | //usage: " losetup -f: show next free loop device" | 27 | //usage: " losetup -f: show next free loop device" |
28 | //usage:#define losetup_full_usage "\n\n" | 28 | //usage:#define losetup_full_usage "\n\n" |
29 | //usage: " -o OFS Start OFS bytes into FILE" | 29 | //usage: " -o OFS Start OFS bytes into FILE" |
30 | //usage: "\n -P Scan for partitions" | ||
30 | //usage: "\n -r Read-only" | 31 | //usage: "\n -r Read-only" |
31 | //usage: "\n -f Show/use next free loop device" | 32 | //usage: "\n -f Show/use next free loop device" |
32 | //usage: | 33 | //usage: |
@@ -35,8 +36,9 @@ | |||
35 | //usage: "(if any), or disassociate it (with -d). The display shows the offset\n" | 36 | //usage: "(if any), or disassociate it (with -d). The display shows the offset\n" |
36 | //usage: "and filename of the file the loop device is currently bound to.\n\n" | 37 | //usage: "and filename of the file the loop device is currently bound to.\n\n" |
37 | //usage: "Two arguments (losetup /dev/loop1 file.img) create a new association,\n" | 38 | //usage: "Two arguments (losetup /dev/loop1 file.img) create a new association,\n" |
38 | //usage: "with an optional offset (-o 12345). Encryption is not yet supported.\n" | 39 | //usage: "with optional partition scanning (creates /dev/loop1p1, /dev/loop1p2\n" |
39 | //usage: "losetup -f will show the first loop free loop device\n\n" | 40 | //usage: "etc. with -P) and with an optional offset (-o 12345). Encryption is\n" |
41 | //usage: "not yet supported. losetup -f will show the first free loop device\n\n" | ||
40 | 42 | ||
41 | #include "libbb.h" | 43 | #include "libbb.h" |
42 | 44 | ||
@@ -53,13 +55,14 @@ int losetup_main(int argc UNUSED_PARAM, char **argv) | |||
53 | enum { | 55 | enum { |
54 | OPT_c = (1 << 0), | 56 | OPT_c = (1 << 0), |
55 | OPT_d = (1 << 1), | 57 | OPT_d = (1 << 1), |
56 | OPT_o = (1 << 2), | 58 | OPT_P = (1 << 2), |
57 | OPT_f = (1 << 3), | 59 | OPT_o = (1 << 3), |
58 | OPT_a = (1 << 4), | 60 | OPT_f = (1 << 4), |
59 | OPT_r = (1 << 5), | 61 | OPT_a = (1 << 5), |
62 | OPT_r = (1 << 6), | ||
60 | }; | 63 | }; |
61 | 64 | ||
62 | opt = getopt32(argv, "^" "cdo:far" "\0" "?2:d--ofar:a--ofr", &opt_o); | 65 | opt = getopt32(argv, "^" "cdPo:far" "\0" "?2:d--Pofar:a--Pofr", &opt_o); |
63 | argv += optind; | 66 | argv += optind; |
64 | 67 | ||
65 | /* LOOPDEV */ | 68 | /* LOOPDEV */ |
@@ -127,7 +130,7 @@ int losetup_main(int argc UNUSED_PARAM, char **argv) | |||
127 | } | 130 | } |
128 | } | 131 | } |
129 | 132 | ||
130 | /* [-r] [-o OFS] {-f|LOOPDEV} FILE */ | 133 | /* [-rP] [-o OFS] {-f|LOOPDEV} FILE */ |
131 | if (argv[0] && ((opt & OPT_f) || argv[1])) { | 134 | if (argv[0] && ((opt & OPT_f) || argv[1])) { |
132 | unsigned long long offset = 0; | 135 | unsigned long long offset = 0; |
133 | char *d = dev; | 136 | char *d = dev; |
@@ -138,7 +141,11 @@ int losetup_main(int argc UNUSED_PARAM, char **argv) | |||
138 | d = *argv++; | 141 | d = *argv++; |
139 | 142 | ||
140 | if (argv[0]) { | 143 | if (argv[0]) { |
141 | if (set_loop(&d, argv[0], offset, (opt & OPT_r) ? BB_LO_FLAGS_READ_ONLY : 0) < 0) | 144 | unsigned flags = (opt & OPT_r) ? BB_LO_FLAGS_READ_ONLY : 0; |
145 | if (opt & OPT_P) { | ||
146 | flags |= BB_LO_FLAGS_PARTSCAN; | ||
147 | } | ||
148 | if (set_loop(&d, argv[0], offset, flags) < 0) | ||
142 | bb_simple_perror_msg_and_die(argv[0]); | 149 | bb_simple_perror_msg_and_die(argv[0]); |
143 | return EXIT_SUCCESS; | 150 | return EXIT_SUCCESS; |
144 | } | 151 | } |