Patch from vodz:
[oweals/busybox.git] / libbb / loop.c
index 4754b8da18e6a8c2b75437c3f3952014eba5e6d1..7dba3e274b85ee19edce518d3f6dfc676a317b9b 100644 (file)
@@ -2,9 +2,7 @@
 /*
  * Utility routines.
  *
- * Copyright (C) tons of folks.  Tracking down who wrote what
- * isn't something I'm going to worry about...  If you wrote something
- * here, please feel free to acknowledge your work.
+ * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
- * Permission has been granted to redistribute this code under the GPL.
- *
  */
 
 #include <stdio.h>
@@ -39,11 +33,12 @@ extern int del_loop(const char *device)
        int fd;
 
        if ((fd = open(device, O_RDONLY)) < 0) {
-               perror_msg("%s", device);
+               bb_perror_msg("%s", device);
                return (FALSE);
        }
        if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
-               perror_msg("ioctl: LOOP_CLR_FD");
+               close(fd);
+               bb_perror_msg("ioctl: LOOP_CLR_FD");
                return (FALSE);
        }
        close(fd);
@@ -59,12 +54,12 @@ extern int set_loop(const char *device, const char *file, int offset,
        mode = *loopro ? O_RDONLY : O_RDWR;
        if ((ffd = open(file, mode)) < 0 && !*loopro
                && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) {
-               perror_msg("%s", file);
+               bb_perror_msg("%s", file);
                return 1;
        }
        if ((fd = open(device, mode)) < 0) {
                close(ffd);
-               perror_msg("%s", device);
+               bb_perror_msg("%s", device);
                return 1;
        }
        *loopro = (mode == O_RDONLY);
@@ -76,14 +71,14 @@ extern int set_loop(const char *device, const char *file, int offset,
 
        loopinfo.lo_encrypt_key_size = 0;
        if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
-               perror_msg("ioctl: LOOP_SET_FD");
+               bb_perror_msg("ioctl: LOOP_SET_FD");
                close(fd);
                close(ffd);
                return 1;
        }
        if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
                (void) ioctl(fd, LOOP_CLR_FD, 0);
-               perror_msg("ioctl: LOOP_SET_STATUS");
+               bb_perror_msg("ioctl: LOOP_SET_STATUS");
                close(fd);
                close(ffd);
                return 1;
@@ -101,7 +96,7 @@ extern char *find_unused_loop_device(void)
        struct loop_info loopinfo;
 
        for (i = 0; i <= 7; i++) {
-               sprintf(dev, "/dev/loop%d", i);
+               sprintf(dev, LOOP_FORMAT, 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) != 0) {