OSDN Git Service

Update files to reduce dependance on kernel version...
authorEric Andersen <andersen@codepoet.org>
Sat, 8 Jul 2000 18:55:24 +0000 (18:55 -0000)
committerEric Andersen <andersen@codepoet.org>
Sat, 8 Jul 2000 18:55:24 +0000 (18:55 -0000)
 -Erik

23 files changed:
chvt.c
console-tools/chvt.c
console-tools/deallocvt.c
console-tools/loadkmap.c
console-tools/setkeycodes.c
coreutils/ls.c
deallocvt.c
dmesg.c
fdflush.c
init.c
init/init.c
insmod.c
loadkmap.c
ls.c
modutils/insmod.c
mount.c
setkeycodes.c
umount.c
util-linux/dmesg.c
util-linux/fdflush.c
util-linux/mount.c
util-linux/umount.c
utility.c

diff --git a/chvt.c b/chvt.c
index 45a0439..c5c86b6 100644 (file)
--- a/chvt.c
+++ b/chvt.c
@@ -5,12 +5,16 @@
  * busyboxed by Erik Andersen
  */
 #include "internal.h"
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <linux/vt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+/* From <linux/vt.h> */
+#define VT_ACTIVATE     0x5606  /* make vt active */
+#define VT_WAITACTIVE   0x5607  /* wait for vt active */
+
 
 int chvt_main(int argc, char **argv)
 {
index 45a0439..c5c86b6 100644 (file)
@@ -5,12 +5,16 @@
  * busyboxed by Erik Andersen
  */
 #include "internal.h"
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <linux/vt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+/* From <linux/vt.h> */
+#define VT_ACTIVATE     0x5606  /* make vt active */
+#define VT_WAITACTIVE   0x5607  /* wait for vt active */
+
 
 int chvt_main(int argc, char **argv)
 {
index b65f7b0..0cad771 100644 (file)
@@ -5,11 +5,14 @@
  */
 #include "internal.h"
 #include <stdlib.h>
+#include <stdio.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
-#include <linux/vt.h>
-#include <stdio.h>
+
+/* From <linux/vt.h> */
+#define VT_DISALLOCATE  0x5608  /* free memory associated to vt */
+
 
 char *progname;
 
index 9057414..0e8c090 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <linux/kd.h>
-#include <linux/keyboard.h>
 #include <sys/ioctl.h>
 
+/* From <linux/kd.h> */
+struct kbentry {
+       unsigned char kb_table;
+       unsigned char kb_index;
+       unsigned short kb_value;
+};
+#define KDSKBENT        0x4B47  /* sets one entry in translation table */
+
+/* From <linux/keyboard.h> */
+#define NR_KEYS         128
+#define MAX_NR_KEYMAPS  256
+
 
 static const char loadkmap_usage[] = "loadkmap\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
index 9062caf..1bdb909 100644 (file)
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/kd.h>
+
+
+/* From <linux/kd.h> */
+struct kbkeycode {
+       unsigned int scancode, keycode;
+};
+#define KDSETKEYCODE    0x4B4D  /* write kernel keycode table entry */
+
 
 static const char setkeycodes_usage[] =
        "setkeycodes SCANCODE KEYCODE ...\n"
index 75fa654..98ccbed 100644 (file)
 /************************************************************************/
 
 #include "internal.h"
-#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
-# include <linux/types.h>
-#else
+//#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+//# include <linux/types.h>
+//#else
 # include <sys/types.h>
-#endif
+//#endif
 #include <sys/stat.h>
 #include <stdio.h>
 #include <unistd.h>
index b65f7b0..0cad771 100644 (file)
@@ -5,11 +5,14 @@
  */
 #include "internal.h"
 #include <stdlib.h>
+#include <stdio.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
-#include <linux/vt.h>
-#include <stdio.h>
+
+/* From <linux/vt.h> */
+#define VT_DISALLOCATE  0x5608  /* free memory associated to vt */
+
 
 char *progname;
 
diff --git a/dmesg.c b/dmesg.c
index 20846f7..e88f549 100644 (file)
--- a/dmesg.c
+++ b/dmesg.c
@@ -16,7 +16,6 @@
  */
 
 #include "internal.h"
-#include <linux/unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -24,6 +23,7 @@
 
 #ifndef __alpha__
 # define __NR_klogctl __NR_syslog
+#include <linux/unistd.h>
 static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
 #else                                                  /* __alpha__ */
 #define klogctl syslog
index 81f0472..d993735 100644 (file)
--- a/fdflush.c
+++ b/fdflush.c
 #include "internal.h"
 #include <stdio.h>
 #include <sys/ioctl.h>
-#include <linux/fd.h>
 #include <fcntl.h>
 
+/* From <linux/fd.h> */
+#define FDFLUSH  _IO(2,0x4b)
 
 extern int fdflush_main(int argc, char **argv)
 {
diff --git a/init.c b/init.c
index 35f2255..b368c00 100644 (file)
--- a/init.c
+++ b/init.c
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
-#include <asm/types.h>
-#include <linux/serial.h>              /* for serial_struct */
-#include <linux/version.h>
-#include <linux/reboot.h>
-#include <linux/unistd.h>
-#include <linux/vt.h>                          /* for vt_stat */
 #include <sys/fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 # include <sys/syslog.h>
 #endif
 
+/* From <linux/vt.h> */
+struct vt_stat {
+       unsigned short v_active;        /* active vt */
+       unsigned short v_signal;        /* signal to send */
+       unsigned short v_state;         /* vt bitmask */
+};
+#define VT_GETSTATE     0x5603  /* get global vt state info */
+
+/* From <linux/serial.h> */
+struct serial_struct {
+       int     type;
+       int     line;
+       int     port;
+       int     irq;
+       int     flags;
+       int     xmit_fifo_size;
+       int     custom_divisor;
+       int     baud_base;
+       unsigned short  close_delay;
+       char    reserved_char[2];
+       int     hub6;
+       unsigned short  closing_wait; /* time to wait before closing */
+       unsigned short  closing_wait2; /* no longer used... */
+       int     reserved[4];
+};
+
+
 
 #ifndef RB_HALT_SYSTEM
 #define RB_HALT_SYSTEM  0xcdef0123
 #include <sys/time.h>
 #endif
 
-#ifndef KERNEL_VERSION
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-#endif
 
 #if defined(__GLIBC__)
 #include <sys/kdaemon.h>
 #else
+#include <linux/unistd.h>              /* for _syscall() macro */
 static _syscall2(int, bdflush, int, func, int, data);
 #endif                                                 /* __GLIBC__ */
 
@@ -568,7 +588,7 @@ static void shutdown_system(void)
        run_lastAction();
 
        sync();
-       if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
+       if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
                /* bdflush, kupdate not needed for kernels >2.2.11 */
                bdflush(1, 0);
                sync();
@@ -587,11 +607,9 @@ static void halt_signal(int sig)
        /* allow time for last message to reach serial console */
        sleep(2);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
-       if (sig == SIGUSR2)
+       if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
                init_reboot(RB_POWER_OFF);
        else
-#endif
                init_reboot(RB_HALT_SYSTEM);
        exit(0);
 }
index 35f2255..b368c00 100644 (file)
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
-#include <asm/types.h>
-#include <linux/serial.h>              /* for serial_struct */
-#include <linux/version.h>
-#include <linux/reboot.h>
-#include <linux/unistd.h>
-#include <linux/vt.h>                          /* for vt_stat */
 #include <sys/fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 # include <sys/syslog.h>
 #endif
 
+/* From <linux/vt.h> */
+struct vt_stat {
+       unsigned short v_active;        /* active vt */
+       unsigned short v_signal;        /* signal to send */
+       unsigned short v_state;         /* vt bitmask */
+};
+#define VT_GETSTATE     0x5603  /* get global vt state info */
+
+/* From <linux/serial.h> */
+struct serial_struct {
+       int     type;
+       int     line;
+       int     port;
+       int     irq;
+       int     flags;
+       int     xmit_fifo_size;
+       int     custom_divisor;
+       int     baud_base;
+       unsigned short  close_delay;
+       char    reserved_char[2];
+       int     hub6;
+       unsigned short  closing_wait; /* time to wait before closing */
+       unsigned short  closing_wait2; /* no longer used... */
+       int     reserved[4];
+};
+
+
 
 #ifndef RB_HALT_SYSTEM
 #define RB_HALT_SYSTEM  0xcdef0123
 #include <sys/time.h>
 #endif
 
-#ifndef KERNEL_VERSION
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-#endif
 
 #if defined(__GLIBC__)
 #include <sys/kdaemon.h>
 #else
+#include <linux/unistd.h>              /* for _syscall() macro */
 static _syscall2(int, bdflush, int, func, int, data);
 #endif                                                 /* __GLIBC__ */
 
@@ -568,7 +588,7 @@ static void shutdown_system(void)
        run_lastAction();
 
        sync();
-       if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
+       if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
                /* bdflush, kupdate not needed for kernels >2.2.11 */
                bdflush(1, 0);
                sync();
@@ -587,11 +607,9 @@ static void halt_signal(int sig)
        /* allow time for last message to reach serial console */
        sleep(2);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
-       if (sig == SIGUSR2)
+       if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
                init_reboot(RB_POWER_OFF);
        else
-#endif
                init_reboot(RB_HALT_SYSTEM);
        exit(0);
 }
index 0064688..75058b9 100644 (file)
--- a/insmod.c
+++ b/insmod.c
@@ -71,7 +71,7 @@
 #ifndef MODUTILS_MODULE_H
 #define MODUTILS_MODULE_H 1
 
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.12 2000/07/08 18:55:24 andersen Exp $"
 
 /* This file contains the structures used by the 2.0 and 2.1 kernels.
    We do not use the kernel headers directly because we do not wish
@@ -277,7 +277,7 @@ int delete_module(const char *);
 #ifndef MODUTILS_OBJ_H
 #define MODUTILS_OBJ_H 1
 
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.12 2000/07/08 18:55:24 andersen Exp $"
 
 /* The relocatable object is manipulated using elfin types.  */
 
@@ -530,6 +530,9 @@ _syscall2(int, new_sys_init_module, const char *, name,
 _syscall5(int, old_sys_init_module, const char *, name, char *, code,
                  unsigned, codesize, struct old_mod_routines *, routines,
                  struct old_symbol_table *, symtab)
+#ifndef __NR_query_module
+#define __NR_query_module     167
+#endif
 _syscall5(int, query_module, const char *, name, int, which,
                void *, buf, size_t, bufsize, size_t*, ret);
 #ifndef BB_RMMOD
index 9057414..0e8c090 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <linux/kd.h>
-#include <linux/keyboard.h>
 #include <sys/ioctl.h>
 
+/* From <linux/kd.h> */
+struct kbentry {
+       unsigned char kb_table;
+       unsigned char kb_index;
+       unsigned short kb_value;
+};
+#define KDSKBENT        0x4B47  /* sets one entry in translation table */
+
+/* From <linux/keyboard.h> */
+#define NR_KEYS         128
+#define MAX_NR_KEYMAPS  256
+
 
 static const char loadkmap_usage[] = "loadkmap\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
diff --git a/ls.c b/ls.c
index 75fa654..98ccbed 100644 (file)
--- a/ls.c
+++ b/ls.c
 /************************************************************************/
 
 #include "internal.h"
-#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
-# include <linux/types.h>
-#else
+//#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+//# include <linux/types.h>
+//#else
 # include <sys/types.h>
-#endif
+//#endif
 #include <sys/stat.h>
 #include <stdio.h>
 #include <unistd.h>
index 0064688..75058b9 100644 (file)
@@ -71,7 +71,7 @@
 #ifndef MODUTILS_MODULE_H
 #define MODUTILS_MODULE_H 1
 
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.12 2000/07/08 18:55:24 andersen Exp $"
 
 /* This file contains the structures used by the 2.0 and 2.1 kernels.
    We do not use the kernel headers directly because we do not wish
@@ -277,7 +277,7 @@ int delete_module(const char *);
 #ifndef MODUTILS_OBJ_H
 #define MODUTILS_OBJ_H 1
 
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.12 2000/07/08 18:55:24 andersen Exp $"
 
 /* The relocatable object is manipulated using elfin types.  */
 
@@ -530,6 +530,9 @@ _syscall2(int, new_sys_init_module, const char *, name,
 _syscall5(int, old_sys_init_module, const char *, name, char *, code,
                  unsigned, codesize, struct old_mod_routines *, routines,
                  struct old_symbol_table *, symtab)
+#ifndef __NR_query_module
+#define __NR_query_module     167
+#endif
 _syscall5(int, query_module, const char *, name, int, which,
                void *, buf, size_t, bufsize, size_t*, ret);
 #ifndef BB_RMMOD
diff --git a/mount.c b/mount.c
index 76f048b..01e9b3d 100644 (file)
--- a/mount.c
+++ b/mount.c
 #if defined BB_FEATURE_USE_DEVPS_PATCH
 #include <linux/devmtab.h>
 #endif
-#ifndef MS_RDONLY
-#include <linux/fs.h>
+
+/* 2.0.x. kernels don't know about MS_NODIRATIME */
+#ifndef MS_NODIRATIME
+#define MS_NODIRATIME   2048    /* Do not update directory access times */
 #endif
 
 
+
 #if defined BB_FEATURE_MOUNT_LOOP
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/loop.h>
 
 
 static int use_loop = FALSE;
index 9062caf..1bdb909 100644 (file)
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/kd.h>
+
+
+/* From <linux/kd.h> */
+struct kbkeycode {
+       unsigned int scancode, keycode;
+};
+#define KDSETKEYCODE    0x4B4D  /* write kernel keycode table entry */
+
 
 static const char setkeycodes_usage[] =
        "setkeycodes SCANCODE KEYCODE ...\n"
index 61f7f90..d790d68 100644 (file)
--- a/umount.c
+++ b/umount.c
 #include <stdio.h>
 #include <mntent.h>
 #include <errno.h>
+#include <sys/mount.h>
 #include <linux/unistd.h>
 
 
-//#include <sys/mount.h>
-/* Include our own version of sys/mount.h, since libc5 doesn't
- * know about umount2 */
-static _syscall1(int, umount, const char *, special_file);
-static _syscall2(int, umount2, const char *, special_file, int, flags);
-static _syscall5(int, mount, const char *, special_file, const char *, dir,
-               const char *, fstype, unsigned long int, rwflag, const void *, data);
+/* Include our own version of umount2 if we need it... */
+#ifndef __NR_umount2
+#define __NR_umount2           52
 #define MNT_FORCE              1
-#define MS_MGC_VAL             0xc0ed0000              /* Magic flag number to indicate "new" flags */
-#define MS_REMOUNT             32                              /* Alter flags of a mounted FS.  */
-#define MS_RDONLY              1                               /* Mount read-only.  */
+#define MS_MGC_VAL             0xc0ed0000 /* Magic number indicatng "new" flags */
+#define MS_REMOUNT             32      /* Alter flags of a mounted FS.  */
+#define MS_RDONLY              1       /* Mount read-only.  */
+
+#endif
+static _syscall2(int, umount2, const char *, special_file, int, flags);
 
 
 static const char umount_usage[] =
index 20846f7..e88f549 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "internal.h"
-#include <linux/unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -24,6 +23,7 @@
 
 #ifndef __alpha__
 # define __NR_klogctl __NR_syslog
+#include <linux/unistd.h>
 static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
 #else                                                  /* __alpha__ */
 #define klogctl syslog
index 81f0472..d993735 100644 (file)
 #include "internal.h"
 #include <stdio.h>
 #include <sys/ioctl.h>
-#include <linux/fd.h>
 #include <fcntl.h>
 
+/* From <linux/fd.h> */
+#define FDFLUSH  _IO(2,0x4b)
 
 extern int fdflush_main(int argc, char **argv)
 {
index 76f048b..01e9b3d 100644 (file)
 #if defined BB_FEATURE_USE_DEVPS_PATCH
 #include <linux/devmtab.h>
 #endif
-#ifndef MS_RDONLY
-#include <linux/fs.h>
+
+/* 2.0.x. kernels don't know about MS_NODIRATIME */
+#ifndef MS_NODIRATIME
+#define MS_NODIRATIME   2048    /* Do not update directory access times */
 #endif
 
 
+
 #if defined BB_FEATURE_MOUNT_LOOP
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/loop.h>
 
 
 static int use_loop = FALSE;
index 61f7f90..d790d68 100644 (file)
 #include <stdio.h>
 #include <mntent.h>
 #include <errno.h>
+#include <sys/mount.h>
 #include <linux/unistd.h>
 
 
-//#include <sys/mount.h>
-/* Include our own version of sys/mount.h, since libc5 doesn't
- * know about umount2 */
-static _syscall1(int, umount, const char *, special_file);
-static _syscall2(int, umount2, const char *, special_file, int, flags);
-static _syscall5(int, mount, const char *, special_file, const char *, dir,
-               const char *, fstype, unsigned long int, rwflag, const void *, data);
+/* Include our own version of umount2 if we need it... */
+#ifndef __NR_umount2
+#define __NR_umount2           52
 #define MNT_FORCE              1
-#define MS_MGC_VAL             0xc0ed0000              /* Magic flag number to indicate "new" flags */
-#define MS_REMOUNT             32                              /* Alter flags of a mounted FS.  */
-#define MS_RDONLY              1                               /* Mount read-only.  */
+#define MS_MGC_VAL             0xc0ed0000 /* Magic number indicatng "new" flags */
+#define MS_REMOUNT             32      /* Alter flags of a mounted FS.  */
+#define MS_RDONLY              1       /* Mount read-only.  */
+
+#endif
+static _syscall2(int, umount2, const char *, special_file, int, flags);
 
 
 static const char umount_usage[] =
index e1e0f71..271b101 100644 (file)
--- a/utility.c
+++ b/utility.c
 #include <dirent.h>
 #include <time.h>
 #include <utime.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
 #include <sys/utsname.h>               /* for uname(2) */
 
 #if defined BB_FEATURE_MOUNT_LOOP
 #include <fcntl.h>
-#include <sys/ioctl.h>
 #include <linux/loop.h>
 #endif
 
@@ -904,9 +904,10 @@ unsigned long my_getpwnamegid(char *name)
 
 #if (defined BB_CHVT) || (defined BB_DEALLOCVT) || (defined BB_SETKEYCODES)
 
-
-#include <linux/kd.h>
-#include <sys/ioctl.h>
+/* From <linux/kd.h> */ 
+#define KDGKBTYPE       0x4B33  /* get keyboard type */
+#define         KB_84           0x01
+#define         KB_101          0x02    /* this is what we always answer */
 
 int is_a_console(int fd)
 {