From 5509af7073ffff75d86ff8c67a2075169a859efd Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Sun, 23 Jan 2000 18:19:02 +0000 Subject: * added (and documented) "-n" option for head - contributed Friedrich Vedder * Cleanup for a number of usage messages -- also contributed Friedrich Vedder -Erik --- util-linux/mount.c | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'util-linux/mount.c') diff --git a/util-linux/mount.c b/util-linux/mount.c index 713e5e850..709c7fc49 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -428,44 +428,42 @@ static int set_loop(const char *device, const char *file, int offset, int *loopr loopinfo.lo_encrypt_key_size = 0; if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { perror("ioctl: LOOP_SET_FD"); - exit(1); + close(fd); + close(ffd); + return 1; } if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { (void) ioctl(fd, LOOP_CLR_FD, 0); perror("ioctl: LOOP_SET_STATUS"); - exit(1); + close(fd); + close(ffd); + return 1; } close(fd); close(ffd); return 0; } -static char *find_unused_loop_device (void) +char *find_unused_loop_device (void) { - char dev[20]; - int i, fd, somedev = 0, someloop = 0; - struct stat statbuf; - struct loop_info loopinfo; - - for(i = 0; i < 256; i++) { - sprintf(dev, "/dev/loop%d", i); - if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) { - somedev++; - fd = open (dev, O_RDONLY); - if (fd >= 0) { - if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0) - someloop++; /* in use */ - else if (errno == ENXIO) { - close (fd); - return strdup(dev); /* probably free */ - } - close (fd); - } - continue; - } - if (i >= 7) - break; - } - return NULL; + char dev[20]; + int i, fd; + struct stat statbuf; + struct loop_info loopinfo; + + for(i = 0; i <= 7; i++) { + sprintf(dev, "/dev/loop%d", i); + if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) { + if ((fd = open (dev, O_RDONLY)) >= 0) { + if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1 && + errno == ENXIO) { /* probably free */ + close (fd); + return strdup(dev); + } + close (fd); + } + } + } + return NULL; } #endif /* BB_FEATURE_MOUNT_LOOP */ -- cgit v1.2.3