diff options
author | Rob Landley <rob@landley.net> | 2006-03-18 02:38:10 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-03-18 02:38:10 +0000 |
commit | aae8b3405e9f8f911a57aa3b127056e307977e9f (patch) | |
tree | 9a4a76b5d7305d67866ab90cf7587eb7f0b03a69 | |
parent | 5a5782156582bc57cb5462d74abe11f4cf415eb9 (diff) | |
download | busybox-w32-aae8b3405e9f8f911a57aa3b127056e307977e9f.tar.gz busybox-w32-aae8b3405e9f8f911a57aa3b127056e307977e9f.tar.bz2 busybox-w32-aae8b3405e9f8f911a57aa3b127056e307977e9f.zip |
Whitespace cleanup and minor tweak (return -ERRNO instead of ERRNO so
EPERM doesn't register as a successful read-only mount.
-rw-r--r-- | libbb/loop.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/libbb/loop.c b/libbb/loop.c index 81dfca4d1..2f9d02924 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -90,23 +90,24 @@ int set_loop(char **device, const char *file, int offset) | |||
90 | bb_loop_info loopinfo; | 90 | bb_loop_info loopinfo; |
91 | struct stat statbuf; | 91 | struct stat statbuf; |
92 | int i, dfd, ffd, mode, rc=-1; | 92 | int i, dfd, ffd, mode, rc=-1; |
93 | 93 | ||
94 | /* Open the file. Barf if this doesn't work. */ | 94 | /* Open the file. Barf if this doesn't work. */ |
95 | if((ffd = open(file, mode=O_RDWR))<0 && (ffd = open(file,mode=O_RDONLY))<0) | 95 | if((ffd = open(file, mode=O_RDWR))<0 && (ffd = open(file,mode=O_RDONLY))<0) |
96 | return errno; | 96 | return -errno; |
97 | 97 | ||
98 | /* Find a loop device. */ | 98 | /* Find a loop device. */ |
99 | try=*device ? : dev; | 99 | try=*device ? : dev; |
100 | for(i=0;rc;i++) { | 100 | for(i=0;rc;i++) { |
101 | sprintf(dev, LOOP_FORMAT, i); | 101 | sprintf(dev, LOOP_FORMAT, i); |
102 | |||
102 | /* Ran out of block devices, return failure. */ | 103 | /* Ran out of block devices, return failure. */ |
103 | if(stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) { | 104 | if(stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) { |
104 | rc=ENOENT; | 105 | rc=-ENOENT; |
105 | break; | 106 | break; |
106 | } | 107 | } |
107 | /* Open the sucker and check its loopiness. */ | 108 | /* Open the sucker and check its loopiness. */ |
108 | if((dfd=open(try, mode))<0 && errno==EROFS) | 109 | if((dfd=open(try, mode))<0 && errno==EROFS) |
109 | dfd=open(try,mode=O_RDONLY); | 110 | dfd=open(try, mode = O_RDONLY); |
110 | if(dfd<0) goto try_again; | 111 | if(dfd<0) goto try_again; |
111 | 112 | ||
112 | rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); | 113 | rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); |
@@ -120,6 +121,7 @@ int set_loop(char **device, const char *file, int offset) | |||
120 | if(!ioctl(dfd, LOOP_SET_FD, ffd) && | 121 | if(!ioctl(dfd, LOOP_SET_FD, ffd) && |
121 | !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; | 122 | !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; |
122 | else ioctl(dfd, LOOP_CLR_FD, 0); | 123 | else ioctl(dfd, LOOP_CLR_FD, 0); |
124 | |||
123 | /* If this block device already set up right, re-use it. | 125 | /* If this block device already set up right, re-use it. |
124 | (Yes this is racy, but associating two loop devices with the same | 126 | (Yes this is racy, but associating two loop devices with the same |
125 | file isn't pretty either. In general, mounting the same file twice | 127 | file isn't pretty either. In general, mounting the same file twice |
@@ -137,12 +139,3 @@ try_again: | |||
137 | return mode==O_RDONLY ? 1 : 0; | 139 | return mode==O_RDONLY ? 1 : 0; |
138 | } else return rc; | 140 | } else return rc; |
139 | } | 141 | } |
140 | |||
141 | /* END CODE */ | ||
142 | /* | ||
143 | Local Variables: | ||
144 | c-file-style: "linux" | ||
145 | c-basic-offset: 4 | ||
146 | tab-width: 4 | ||
147 | End: | ||
148 | */ | ||