diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-12 02:13:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-12 08:30:16 +0200 |
commit | 13e709c53f700a18a660feebdf72c613a233bf48 (patch) | |
tree | 248b913b7bb6629b751bbd5a79a7e3c6b55dd1af /libbb | |
parent | dd1061b6a79b0161597799e825bfefc27993ace5 (diff) | |
download | busybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.tar.gz busybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.tar.bz2 busybox-w32-13e709c53f700a18a660feebdf72c613a233bf48.zip |
losetup: implement -r option. Closes 4033.
function old new delta
packed_usage 28595 28633 +38
losetup_main 285 290 +5
singlemount 906 908 +2
set_loop 674 672 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/loop.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libbb/loop.c b/libbb/loop.c index b798932fa..b3a520848 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -84,7 +84,7 @@ int FAST_FUNC del_loop(const char *device) | |||
84 | search will re-use an existing loop device already bound to that | 84 | search will re-use an existing loop device already bound to that |
85 | file/offset if it finds one. | 85 | file/offset if it finds one. |
86 | */ | 86 | */ |
87 | int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offset) | 87 | int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offset, int ro) |
88 | { | 88 | { |
89 | char dev[LOOP_NAMESIZE]; | 89 | char dev[LOOP_NAMESIZE]; |
90 | char *try; | 90 | char *try; |
@@ -93,11 +93,13 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
93 | int i, dfd, ffd, mode, rc = -1; | 93 | int i, dfd, ffd, mode, rc = -1; |
94 | 94 | ||
95 | /* Open the file. Barf if this doesn't work. */ | 95 | /* Open the file. Barf if this doesn't work. */ |
96 | mode = O_RDWR; | 96 | mode = ro ? O_RDONLY : O_RDWR; |
97 | ffd = open(file, mode); | 97 | ffd = open(file, mode); |
98 | if (ffd < 0) { | 98 | if (ffd < 0) { |
99 | mode = O_RDONLY; | 99 | if (mode != O_RDONLY) { |
100 | ffd = open(file, mode); | 100 | mode = O_RDONLY; |
101 | ffd = open(file, mode); | ||
102 | } | ||
101 | if (ffd < 0) | 103 | if (ffd < 0) |
102 | return -errno; | 104 | return -errno; |
103 | } | 105 | } |