[BusyBox] [patch] Cleanup for libbb/loop.c

Rob Landley rob at landley.net
Tue Nov 16 05:51:39 MST 2004


The suckage in loop.c continues to bite me (just had a build break
with 2.6.0.0 headers, and if I upgrade to 2.6.9.1 I can't build under
knoppix), but I think I've got it figured out:

bits/kernel_types.h is broken, its guard #defines
identify it as asm/posix_types.h, so if it's already been included
including asm/posix_types.h does nothing.  Since kernel_types
doesn't define __kernel_old_dev_t, you MUST include posix_types.h
first (before anybody else includes kernel_types..h), or linux/loop.h
dies with an error.

The solution is simply to move the includes to the top of the file,
and delete the ugly #ifdefs and block copied header stuff.
This fixed it for me on 2.6.  Anybody wanna test 2.4?

P.S.  Why are we including kernel_types.h in a userspace program
at all?  Anybody know?

Rob

--- busybox/busybox/libbb/loop.c	2004-08-16 04:36:28.000000000 -0400
+++ lfs/newbuild/lfs/tools/sources/busybox-new/libbb/loop.c	2004-11-16 05:50:57.000000000 -0500
@@ -19,6 +19,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#include <asm/posix_types.h>
+#include <linux/loop.h>
+
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -27,41 +30,6 @@
 #include <sys/ioctl.h>
 #include "libbb.h"
 
-/* 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>
-#include <asm/posix_types.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)
 {
 	int fd;



More information about the busybox mailing list