aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-02-06 07:16:36 +0000
committerEric Andersen <andersen@codepoet.org>2004-02-06 07:16:36 +0000
commitef8cd3be17f0be6017af50f70e09093f5908c7c3 (patch)
tree8fb031797cc9e0c0a7c54ba7ef27e0948feab913
parent7495b0d4b1959b1391c460f24c285b46417730ea (diff)
downloadbusybox-w32-ef8cd3be17f0be6017af50f70e09093f5908c7c3.tar.gz
busybox-w32-ef8cd3be17f0be6017af50f70e09093f5908c7c3.tar.bz2
busybox-w32-ef8cd3be17f0be6017af50f70e09093f5908c7c3.zip
Make the loop support stuff be much less evil, and make it cope
with 2.6.x asm/posix_types.h, which has done singularly evil thing by yanking __kernel_dev_t and renaming it. The loop interface was really poorly designed in the first place. The new 64 bit loop interface looks to be somewhat less horrible, too bad it is only present in 2.6.x kernels. -Erik
-rw-r--r--libbb/Makefile.in6
-rw-r--r--libbb/loop.c35
-rwxr-xr-xlibbb/mk_loop_h.sh37
-rw-r--r--libbb/real_loop.h37
4 files changed, 34 insertions, 81 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index 979419b62..a656a5a53 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -96,9 +96,3 @@ $(LIBBB_MOBJS2): $(LIBBB_MSRC2)
96$(LIBBB_MOBJS3): $(LIBBB_MSRC3) 96$(LIBBB_MOBJS3): $(LIBBB_MSRC3)
97 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@ 97 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@
98 98
99$(LIBBB_DIR)loop.o: $(LIBBB_DIR)loop.h
100
101$(LIBBB_DIR)loop.h: $(LIBBB_DIR)mk_loop_h.sh
102 @ $(SHELL) $< > $@
103
104
diff --git a/libbb/loop.c b/libbb/loop.c
index 7dba3e274..4d73dc4cc 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -26,7 +26,40 @@
26#include <unistd.h> 26#include <unistd.h>
27#include <sys/ioctl.h> 27#include <sys/ioctl.h>
28#include "libbb.h" 28#include "libbb.h"
29#include "loop.h" /* Pull in loop device support */ 29
30/* Grumble... The 2.6.x kernel breaks asm/posix_types.h
31 * so we get to try and cope as best we can... */
32#include <linux/version.h>
33#include <asm/posix_types.h>
34#if LINUX_VERSION_CODE >= 132608
35#define __bb_kernel_dev_t __kernel_old_dev_t
36#elif LINUX_VERSION_CODE >= 0x20600
37#define __bb_kernel_dev_t __kernel_dev_t
38#else
39#define __bb_kernel_dev_t unsigned short
40#endif
41
42/* Stuff stolen from linux/loop.h */
43#define LO_NAME_SIZE 64
44#define LO_KEY_SIZE 32
45#define LOOP_SET_FD 0x4C00
46#define LOOP_CLR_FD 0x4C01
47#define LOOP_SET_STATUS 0x4C02
48#define LOOP_GET_STATUS 0x4C03
49struct loop_info {
50 int lo_number;
51 __bb_kernel_dev_t lo_device;
52 unsigned long lo_inode;
53 __bb_kernel_dev_t lo_rdevice;
54 int lo_offset;
55 int lo_encrypt_type;
56 int lo_encrypt_key_size;
57 int lo_flags;
58 char lo_name[LO_NAME_SIZE];
59 unsigned char lo_encrypt_key[LO_KEY_SIZE];
60 unsigned long lo_init[2];
61 char reserved[4];
62};
30 63
31extern int del_loop(const char *device) 64extern int del_loop(const char *device)
32{ 65{
diff --git a/libbb/mk_loop_h.sh b/libbb/mk_loop_h.sh
deleted file mode 100755
index 71c987376..000000000
--- a/libbb/mk_loop_h.sh
+++ /dev/null
@@ -1,37 +0,0 @@
1#!/bin/sh
2#
3# Figure out (i) the type of dev_t (ii) the defines for loop stuff
4#
5# Output of this script is normally redirected to "loop.h".
6
7# Since 1.3.79 there is an include file <asm/posix_types.h>
8# that defines __kernel_dev_t.
9# (The file itself appeared in 1.3.78, but there it defined __dev_t.)
10# If it exists, we use it, or, rather, <linux/posix_types.h> which
11# avoids namespace pollution. Otherwise we guess that __kernel_dev_t
12# is an unsigned short (which is true on i386, but false on alpha).
13
14# BUG: This test is actually broken if your gcc is not configured to
15# search /usr/include, as may well happen with cross-compilers.
16# It would be better to ask $(CC) if these files can be found.
17
18if [ -f /usr/include/linux/posix_types.h ]; then
19 echo '#include <linux/posix_types.h>'
20 echo '#undef dev_t'
21 echo '#define dev_t __kernel_dev_t'
22else
23 echo '#undef dev_t'
24 echo '#define dev_t unsigned short'
25fi
26
27# Next we have to find the loop stuff itself.
28# First try kernel source, then a private version.
29
30if [ -f /usr/include/linux/loop.h ]; then
31 echo '#include <linux/loop.h>'
32else
33 echo '#include "real_loop.h"'
34fi
35
36echo '#undef dev_t'
37
diff --git a/libbb/real_loop.h b/libbb/real_loop.h
deleted file mode 100644
index 1bd7fa87a..000000000
--- a/libbb/real_loop.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * include/linux/loop.h
3 *
4 * Written by Theodore Ts'o, 3/29/93.
5 *
6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
7 * permitted under the GNU Public License.
8 */
9
10#define LO_NAME_SIZE 64
11#define LO_KEY_SIZE 32
12
13struct loop_info {
14 int lo_number; /* ioctl r/o */
15 dev_t lo_device; /* ioctl r/o */
16 unsigned long lo_inode; /* ioctl r/o */
17 dev_t lo_rdevice; /* ioctl r/o */
18 int lo_offset;
19 int lo_encrypt_type;
20 int lo_encrypt_key_size; /* ioctl w/o */
21 int lo_flags; /* ioctl r/o */
22 char lo_name[LO_NAME_SIZE];
23 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
24 unsigned long lo_init[2];
25 char reserved[4];
26};
27
28#define LO_CRYPT_NONE 0
29#define LO_CRYPT_XOR 1
30#define LO_CRYPT_DES 2
31#define LO_CRYPT_IDEA 3
32#define MAX_LO_CRYPT 4
33
34#define LOOP_SET_FD 0x4C00
35#define LOOP_CLR_FD 0x4C01
36#define LOOP_SET_STATUS 0x4C02
37#define LOOP_GET_STATUS 0x4C03