aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-26 23:49:21 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-26 23:49:21 +0000
commitde7965ca7ee65f21042739f1be5a337da4138343 (patch)
treed65019c9c8fa30e9fb3c50bd04022075de769772
parent5cbdd712f5320ffc109053a94b7cf36c82292cf6 (diff)
downloadbusybox-w32-de7965ca7ee65f21042739f1be5a337da4138343.tar.gz
busybox-w32-de7965ca7ee65f21042739f1be5a337da4138343.tar.bz2
busybox-w32-de7965ca7ee65f21042739f1be5a337da4138343.zip
Shuffle location of generic code into utility.c
-Erik
-rw-r--r--internal.h2
-rw-r--r--mount.c71
-rw-r--r--util-linux/mount.c71
-rw-r--r--utility.c70
4 files changed, 71 insertions, 143 deletions
diff --git a/internal.h b/internal.h
index 9611c1922..39f7e0c5e 100644
--- a/internal.h
+++ b/internal.h
@@ -177,6 +177,8 @@ extern pid_t findInitPid();
177 177
178#if defined BB_FEATURE_MOUNT_LOOP 178#if defined BB_FEATURE_MOUNT_LOOP
179extern int del_loop(const char *device); 179extern int del_loop(const char *device);
180extern int set_loop(const char *device, const char *file, int offset, int *loopro);
181extern char *find_unused_loop_device (void);
180#endif 182#endif
181 183
182#if defined BB_GUNZIP || defined BB_GZIP || defined BB_PRINTF || defined BB_TAIL 184#if defined BB_GUNZIP || defined BB_GZIP || defined BB_PRINTF || defined BB_TAIL
diff --git a/mount.c b/mount.c
index 3c1568aad..4b0901f2a 100644
--- a/mount.c
+++ b/mount.c
@@ -51,8 +51,6 @@
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <linux/loop.h> 52#include <linux/loop.h>
53 53
54static int set_loop(const char *device, const char *file, int offset, int *loopro);
55static char *find_unused_loop_device (void);
56 54
57static int use_loop = 0; 55static int use_loop = 0;
58#endif 56#endif
@@ -177,75 +175,6 @@ extern void whine_if_fstab_is_missing()
177#endif 175#endif
178 176
179 177
180#if defined BB_FEATURE_MOUNT_LOOP
181static int set_loop(const char *device, const char *file, int offset, int *loopro)
182{
183 struct loop_info loopinfo;
184 int fd, ffd, mode;
185
186 mode = *loopro ? O_RDONLY : O_RDWR;
187 if ((ffd = open (file, mode)) < 0 && !*loopro
188 && (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
189 perror (file);
190 return 1;
191 }
192 if ((fd = open (device, mode)) < 0) {
193 close(ffd);
194 perror (device);
195 return 1;
196 }
197 *loopro = (mode == O_RDONLY);
198
199 memset(&loopinfo, 0, sizeof(loopinfo));
200 strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
201 loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
202
203 loopinfo.lo_offset = offset;
204
205 loopinfo.lo_encrypt_key_size = 0;
206 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
207 perror("ioctl: LOOP_SET_FD");
208 close(fd);
209 close(ffd);
210 return 1;
211 }
212 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
213 (void) ioctl(fd, LOOP_CLR_FD, 0);
214 perror("ioctl: LOOP_SET_STATUS");
215 close(fd);
216 close(ffd);
217 return 1;
218 }
219 close(fd);
220 close(ffd);
221 return 0;
222}
223
224char *find_unused_loop_device (void)
225{
226 char dev[20];
227 int i, fd;
228 struct stat statbuf;
229 struct loop_info loopinfo;
230
231 for(i = 0; i <= 7; i++) {
232 sprintf(dev, "/dev/loop%d", i);
233 if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
234 if ((fd = open (dev, O_RDONLY)) >= 0) {
235 if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1) {
236 if (errno == ENXIO) { /* probably free */
237 close (fd);
238 return strdup(dev);
239 }
240 }
241 close (fd);
242 }
243 }
244 }
245 return NULL;
246}
247#endif /* BB_FEATURE_MOUNT_LOOP */
248
249/* Seperate standard mount options from the nonstandard string options */ 178/* Seperate standard mount options from the nonstandard string options */
250static void 179static void
251parse_mount_options ( char *options, unsigned long *flags, char *strflags) 180parse_mount_options ( char *options, unsigned long *flags, char *strflags)
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 3c1568aad..4b0901f2a 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -51,8 +51,6 @@
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <linux/loop.h> 52#include <linux/loop.h>
53 53
54static int set_loop(const char *device, const char *file, int offset, int *loopro);
55static char *find_unused_loop_device (void);
56 54
57static int use_loop = 0; 55static int use_loop = 0;
58#endif 56#endif
@@ -177,75 +175,6 @@ extern void whine_if_fstab_is_missing()
177#endif 175#endif
178 176
179 177
180#if defined BB_FEATURE_MOUNT_LOOP
181static int set_loop(const char *device, const char *file, int offset, int *loopro)
182{
183 struct loop_info loopinfo;
184 int fd, ffd, mode;
185
186 mode = *loopro ? O_RDONLY : O_RDWR;
187 if ((ffd = open (file, mode)) < 0 && !*loopro
188 && (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
189 perror (file);
190 return 1;
191 }
192 if ((fd = open (device, mode)) < 0) {
193 close(ffd);
194 perror (device);
195 return 1;
196 }
197 *loopro = (mode == O_RDONLY);
198
199 memset(&loopinfo, 0, sizeof(loopinfo));
200 strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
201 loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
202
203 loopinfo.lo_offset = offset;
204
205 loopinfo.lo_encrypt_key_size = 0;
206 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
207 perror("ioctl: LOOP_SET_FD");
208 close(fd);
209 close(ffd);
210 return 1;
211 }
212 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
213 (void) ioctl(fd, LOOP_CLR_FD, 0);
214 perror("ioctl: LOOP_SET_STATUS");
215 close(fd);
216 close(ffd);
217 return 1;
218 }
219 close(fd);
220 close(ffd);
221 return 0;
222}
223
224char *find_unused_loop_device (void)
225{
226 char dev[20];
227 int i, fd;
228 struct stat statbuf;
229 struct loop_info loopinfo;
230
231 for(i = 0; i <= 7; i++) {
232 sprintf(dev, "/dev/loop%d", i);
233 if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
234 if ((fd = open (dev, O_RDONLY)) >= 0) {
235 if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1) {
236 if (errno == ENXIO) { /* probably free */
237 close (fd);
238 return strdup(dev);
239 }
240 }
241 close (fd);
242 }
243 }
244 }
245 return NULL;
246}
247#endif /* BB_FEATURE_MOUNT_LOOP */
248
249/* Seperate standard mount options from the nonstandard string options */ 178/* Seperate standard mount options from the nonstandard string options */
250static void 179static void
251parse_mount_options ( char *options, unsigned long *flags, char *strflags) 180parse_mount_options ( char *options, unsigned long *flags, char *strflags)
diff --git a/utility.c b/utility.c
index 643c3b5f2..5ff03d7a0 100644
--- a/utility.c
+++ b/utility.c
@@ -1169,6 +1169,74 @@ extern int del_loop(const char *device)
1169 close(fd); 1169 close(fd);
1170 return( TRUE); 1170 return( TRUE);
1171} 1171}
1172#endif 1172
1173extern int set_loop(const char *device, const char *file, int offset, int *loopro)
1174{
1175 struct loop_info loopinfo;
1176 int fd, ffd, mode;
1177
1178 mode = *loopro ? O_RDONLY : O_RDWR;
1179 if ((ffd = open (file, mode)) < 0 && !*loopro
1180 && (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
1181 perror (file);
1182 return 1;
1183 }
1184 if ((fd = open (device, mode)) < 0) {
1185 close(ffd);
1186 perror (device);
1187 return 1;
1188 }
1189 *loopro = (mode == O_RDONLY);
1190
1191 memset(&loopinfo, 0, sizeof(loopinfo));
1192 strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
1193 loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
1194
1195 loopinfo.lo_offset = offset;
1196
1197 loopinfo.lo_encrypt_key_size = 0;
1198 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
1199 perror("ioctl: LOOP_SET_FD");
1200 close(fd);
1201 close(ffd);
1202 return 1;
1203 }
1204 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
1205 (void) ioctl(fd, LOOP_CLR_FD, 0);
1206 perror("ioctl: LOOP_SET_STATUS");
1207 close(fd);
1208 close(ffd);
1209 return 1;
1210 }
1211 close(fd);
1212 close(ffd);
1213 return 0;
1214}
1215
1216extern char *find_unused_loop_device (void)
1217{
1218 char dev[20];
1219 int i, fd;
1220 struct stat statbuf;
1221 struct loop_info loopinfo;
1222
1223 for(i = 0; i <= 7; i++) {
1224 sprintf(dev, "/dev/loop%d", i);
1225 if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
1226 if ((fd = open (dev, O_RDONLY)) >= 0) {
1227 if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1) {
1228 if (errno == ENXIO) { /* probably free */
1229 close (fd);
1230 return strdup(dev);
1231 }
1232 }
1233 close (fd);
1234 }
1235 }
1236 }
1237 return NULL;
1238}
1239#endif /* BB_FEATURE_MOUNT_LOOP */
1240
1173 1241
1174/* END CODE */ 1242/* END CODE */