aboutsummaryrefslogtreecommitdiff
path: root/libbb/loop.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
committerRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
commit40514a0309939f2446f0d4ed9600cad5de396e7f (patch)
tree0f5f4a57d4bb7893418b5bb11d482858eb17ba8b /libbb/loop.c
parent9db164d6e39050d09f38288c6045cd2a2cbf6d63 (diff)
parentc0cae52662ccced9df19f19ec94238d1b1e3bd71 (diff)
downloadbusybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.gz
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.bz2
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.zip
Merge commit 'c0cae52662ccced9df19f19ec94238d1b1e3bd71' into merge
Conflicts: Makefile.flags scripts/basic/fixdep.c
Diffstat (limited to 'libbb/loop.c')
-rw-r--r--libbb/loop.c10
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 */
87int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offset) 87int 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 }