aboutsummaryrefslogtreecommitdiff
path: root/mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'mount.c')
-rw-r--r--mount.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/mount.c b/mount.c
index 713e5e850..709c7fc49 100644
--- a/mount.c
+++ b/mount.c
@@ -428,44 +428,42 @@ static int set_loop(const char *device, const char *file, int offset, int *loopr
428 loopinfo.lo_encrypt_key_size = 0; 428 loopinfo.lo_encrypt_key_size = 0;
429 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { 429 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
430 perror("ioctl: LOOP_SET_FD"); 430 perror("ioctl: LOOP_SET_FD");
431 exit(1); 431 close(fd);
432 close(ffd);
433 return 1;
432 } 434 }
433 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { 435 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
434 (void) ioctl(fd, LOOP_CLR_FD, 0); 436 (void) ioctl(fd, LOOP_CLR_FD, 0);
435 perror("ioctl: LOOP_SET_STATUS"); 437 perror("ioctl: LOOP_SET_STATUS");
436 exit(1); 438 close(fd);
439 close(ffd);
440 return 1;
437 } 441 }
438 close(fd); 442 close(fd);
439 close(ffd); 443 close(ffd);
440 return 0; 444 return 0;
441} 445}
442 446
443static char *find_unused_loop_device (void) 447char *find_unused_loop_device (void)
444{ 448{
445 char dev[20]; 449 char dev[20];
446 int i, fd, somedev = 0, someloop = 0; 450 int i, fd;
447 struct stat statbuf; 451 struct stat statbuf;
448 struct loop_info loopinfo; 452 struct loop_info loopinfo;
449 453
450 for(i = 0; i < 256; i++) { 454 for(i = 0; i <= 7; i++) {
451 sprintf(dev, "/dev/loop%d", i); 455 sprintf(dev, "/dev/loop%d", i);
452 if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) { 456 if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
453 somedev++; 457 if ((fd = open (dev, O_RDONLY)) >= 0) {
454 fd = open (dev, O_RDONLY); 458 if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1 &&
455 if (fd >= 0) { 459 errno == ENXIO) { /* probably free */
456 if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0) 460 close (fd);
457 someloop++; /* in use */ 461 return strdup(dev);
458 else if (errno == ENXIO) { 462 }
459 close (fd); 463 close (fd);
460 return strdup(dev); /* probably free */ 464 }
461 } 465 }
462 close (fd); 466 }
463 } 467 return NULL;
464 continue;
465 }
466 if (i >= 7)
467 break;
468 }
469 return NULL;
470} 468}
471#endif /* BB_FEATURE_MOUNT_LOOP */ 469#endif /* BB_FEATURE_MOUNT_LOOP */