fix printf warning
[oweals/busybox.git] / libbb / loop.c
index 29128abe4b728394cc99d029b1c9355e8d780089..8c3ad2ce03c390f9317fe4d62d8d05236094d0b4 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * Utility routines.
  *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ * Copyright (C) 1999-2004 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
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#include <features.h>
+#if defined (__GLIBC__) && !defined(__UCLIBC__)
+#include <linux/posix_types.h>
+#endif
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include "libbb.h"
-#include "loop.h" /* Pull in loop device support */
+
+/* Grumble...  The 2.6.x kernel breaks asm/posix_types.h
+ * so we get to try and cope as best we can... */
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+#define __bb_kernel_dev_t   __kernel_old_dev_t
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define __bb_kernel_dev_t   __kernel_dev_t
+#else
+#define __bb_kernel_dev_t   unsigned short
+#endif
+
+/* Stuff stolen from linux/loop.h */
+#define LO_NAME_SIZE        64
+#define LO_KEY_SIZE         32
+#define LOOP_SET_FD         0x4C00
+#define LOOP_CLR_FD         0x4C01
+#define LOOP_SET_STATUS     0x4C02
+#define LOOP_GET_STATUS     0x4C03
+struct loop_info {
+       int                lo_number;
+       __bb_kernel_dev_t  lo_device;
+       unsigned long      lo_inode;
+       __bb_kernel_dev_t  lo_rdevice;
+       int                lo_offset;
+       int                lo_encrypt_type;
+       int                lo_encrypt_key_size;
+       int                lo_flags;
+       char               lo_name[LO_NAME_SIZE];
+       unsigned char      lo_encrypt_key[LO_KEY_SIZE];
+       unsigned long      lo_init[2];
+       char               reserved[4];
+};
 
 extern int del_loop(const char *device)
 {
@@ -37,6 +74,7 @@ extern int del_loop(const char *device)
                return (FALSE);
        }
        if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
+               close(fd);
                bb_perror_msg("ioctl: LOOP_CLR_FD");
                return (FALSE);
        }