More portable handling of loop header files, as done in util-linux

This commit is contained in:
Eric Andersen 2000-09-21 02:04:51 +00:00
parent 8847b9a03a
commit 624cc771da
5 changed files with 123 additions and 12 deletions

View File

@ -42,7 +42,7 @@ DODMALLOC = false
# If you are running a cross compiler, you may want to set this
# to something more interesting...
CROSS =
CROSS = #powerpc-linux-
CC = $(CROSS)gcc
STRIPTOOL = $(CROSS)strip
@ -83,12 +83,13 @@ else
ifeq ($(DOSTATIC),true)
LDFLAGS += --static
#
#use '-ffunction-sections -fdata-sections' and '--gc-sections' if they work
#to try and strip out any unused junk. Doesn't do much for me, but you may
#want to give it a shot...
#use '-ffunction-sections -fdata-sections' and '--gc-sections' (if they
# work) to try and strip out any unused junk. Doesn't do much for me,
# but you may want to give it a shot...
#
#ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
# -o /dev/null -xc /dev/null 2>/dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1)
# -o /dev/null -xc /dev/null 2>/dev/null && $(LD) \
# --gc-sections -v >/dev/null && echo 1),1)
# CFLAGS += -ffunction-sections -fdata-sections
# LDFLAGS += --gc-sections
#endif
@ -106,7 +107,8 @@ ifdef BB_INIT_SCRIPT
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
endif
all: busybox busybox.links doc
all: loop.h busybox busybox.links doc
doc: olddoc
@ -164,6 +166,11 @@ busybox.links: busybox.def.h
nfsmount.o cmdedit.o: %.o: %.h
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
utility.o:
loop.h:
@./mk_loop_h.sh
test tests:
cd tests && $(MAKE) all

34
libbb/mk_loop_h.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
#
# Figure out (i) the type of dev_t (ii) the defines for loop stuff
#
rm -f loop.h
# Since 1.3.79 there is an include file <asm/posix_types.h>
# that defines __kernel_dev_t.
# (The file itself appeared in 1.3.78, but there it defined __dev_t.)
# If it exists, we use it, or, rather, <linux/posix_types.h> which
# avoids namespace pollution. Otherwise we guess that __kernel_dev_t
# is an unsigned short (which is true on i386, but false on alpha).
if [ -f /usr/include/linux/posix_types.h ]; then
echo '#include <linux/posix_types.h>' >> loop.h
echo '#undef dev_t' >> loop.h
echo '#define dev_t __kernel_dev_t' >> loop.h
else
echo '#undef dev_t' >> loop.h
echo '#define dev_t unsigned short' >> loop.h
fi
# Next we have to find the loop stuff itself.
# First try kernel source, then a private version.
if [ -f /usr/include/linux/loop.h ]; then
echo '#include <linux/loop.h>' >> loop.h
else
echo '#include "real_loop.h"' >> loop.h
fi
echo '#undef dev_t' >> loop.h

34
mk_loop_h.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
#
# Figure out (i) the type of dev_t (ii) the defines for loop stuff
#
rm -f loop.h
# Since 1.3.79 there is an include file <asm/posix_types.h>
# that defines __kernel_dev_t.
# (The file itself appeared in 1.3.78, but there it defined __dev_t.)
# If it exists, we use it, or, rather, <linux/posix_types.h> which
# avoids namespace pollution. Otherwise we guess that __kernel_dev_t
# is an unsigned short (which is true on i386, but false on alpha).
if [ -f /usr/include/linux/posix_types.h ]; then
echo '#include <linux/posix_types.h>' >> loop.h
echo '#undef dev_t' >> loop.h
echo '#define dev_t __kernel_dev_t' >> loop.h
else
echo '#undef dev_t' >> loop.h
echo '#define dev_t unsigned short' >> loop.h
fi
# Next we have to find the loop stuff itself.
# First try kernel source, then a private version.
if [ -f /usr/include/linux/loop.h ]; then
echo '#include <linux/loop.h>' >> loop.h
else
echo '#include "real_loop.h"' >> loop.h
fi
echo '#undef dev_t' >> loop.h

37
real_loop.h Normal file
View File

@ -0,0 +1,37 @@
/*
* include/linux/loop.h
*
* Written by Theodore Ts'o, 3/29/93.
*
* Copyright 1993 by Theodore Ts'o. Redistribution of this file is
* permitted under the GNU Public License.
*/
#define LO_NAME_SIZE 64
#define LO_KEY_SIZE 32
struct loop_info {
int lo_number; /* ioctl r/o */
dev_t lo_device; /* ioctl r/o */
unsigned long lo_inode; /* ioctl r/o */
dev_t lo_rdevice; /* ioctl r/o */
int lo_offset;
int lo_encrypt_type;
int lo_encrypt_key_size; /* ioctl w/o */
int lo_flags; /* ioctl r/o */
char lo_name[LO_NAME_SIZE];
unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
unsigned long lo_init[2];
char reserved[4];
};
#define LO_CRYPT_NONE 0
#define LO_CRYPT_XOR 1
#define LO_CRYPT_DES 2
#define LO_CRYPT_IDEA 3
#define MAX_LO_CRYPT 4
#define LOOP_SET_FD 0x4C00
#define LOOP_CLR_FD 0x4C01
#define LOOP_SET_STATUS 0x4C02
#define LOOP_GET_STATUS 0x4C03

View File

@ -53,11 +53,6 @@
#include <sys/ioctl.h>
#include <sys/utsname.h> /* for uname(2) */
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include <linux/loop.h> /* Pull in loop device support */
#endif
/* Busybox mount uses either /proc/filesystems or /dev/mtab to get the
* list of available filesystems used for the -t auto option */
#if defined BB_FEATURE_USE_PROCFS && defined BB_FEATURE_USE_DEVPS_PATCH
@ -1459,7 +1454,11 @@ extern int vdprintf(int d, const char *format, va_list ap)
}
#endif /* BB_SYSLOGD */
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
#include "loop.h" /* Pull in loop device support */
extern int del_loop(const char *device)
{
int fd;