My latest ramblings.
authorErik Andersen <andersen@codepoet.org>
Thu, 23 Mar 2000 01:09:18 +0000 (01:09 -0000)
committerErik Andersen <andersen@codepoet.org>
Thu, 23 Mar 2000 01:09:18 +0000 (01:09 -0000)
 -Erik

33 files changed:
Changelog
TODO
applets/busybox.c
archival/tar.c
busybox.c
busybox.def.h
console-tools/loadkmap.c
coreutils/date.c
coreutils/dd.c
coreutils/ls.c
coreutils/tee.c
date.c
dd.c
fbset.c
fdflush.c
freeramdisk.c
fsck_minix.c
init.c
init/init.c
internal.h
loadkmap.c
ls.c
mount.c
tar.c
tee.c
umount.c
util-linux/fbset.c
util-linux/fdflush.c
util-linux/freeramdisk.c
util-linux/fsck_minix.c
util-linux/mount.c
util-linux/umount.c
utility.c

index c0ffd23cd43e457ae2ad2f5e91183711184af09e..f3899dc12139c67e8d08ce8605d86ac22e51bb8f 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@
        * all mallocs now use xmalloc (and so are OOM error safe), and
            the common error handling saves a few bytes.  Thanks to 
            Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
+       * Fix "+" parsing bug in date, from "Merle F. McClelland" <mfm@cts.com>.
 
 
        -Erik Andersen
diff --git a/TODO b/TODO
index daa21cffdd4588f90b507cc99f5f825b5348eb85..87f48db38487c78f8dd7041cad446db62a371793 100644 (file)
--- a/TODO
+++ b/TODO
@@ -128,3 +128,341 @@ I'll add this to the TODO list,
  does also...
 
 
+------------------------------------------------------------------
+
+
+Date:  Fri, 25 Feb 2000 08:23:12 +0000 (GMT)
+From: Riley Williams <rhw@MemAlpha.CX>
+X-Sender: rhw@moo.cus.org.uk
+To: almesber@lrc.di.epfl.ch
+Cc: "Albert D. Cahalan" <acahalan@cs.uml.edu>,
+       Linux Kernel <linux-kernel@vger.rutgers.edu>
+Subject: Re: What /proc should contain [was: /proc/driver/microcode]
+In-Reply-To: <20000224165245.A29790@lrc.di.epfl.ch>
+Message-ID: <Pine.LNX.4.21.0002250806220.8741-100000@moo.cus.org.uk>
+Sender: owner-linux-kernel@vger.rutgers.edu
+Precedence: bulk
+
+Hi there.
+
+ >> Nope, most /proc access is does via programs written in C.
+
+ > That varies a lot from file to file. E.g. I haven't seen any
+ > programs that are specificly designed to read /proc/atm/* yet,
+ > and I know of only one (fuser) that reads /proc/mounts,
+ > extracting only partial information (just to pick two examples
+ > that I'm quite familiar with).
+
+As a point of reference, here's a slightly tweaked analysis of the
+programs on the system I'm reading your mail on. Basically, I ran the
+following script...
+
+ Q> #!/bin/bash
+ Q> function use() {
+ Q>     for Z in $* ; do
+ Q>         strings $Z | grep /proc | sed "s=^=$Z ="
+ Q>     done
+ Q> }
+ Q> use /{,s}bin/* /usr/{,s}bin/* | sort -u | tee proc-usage
+
+...and then went through it removing comments and print format
+strings. Replace /proc with /dev and you'd soon have an equivalent
+list for that - although I can report that such is MUCH larger...
+
+There are three programs therein that refer to /proc/mounts ...
+
+       /bin/mount
+       /bin/umount
+       /usr/bin/eject
+
+...and, as you stated, none that refer to /proc/atm on this system.
+However, as this is a RedHat Linux 5.0 based system, that's not
+necessarily an up to date reference thereto...
+
+Here's the list anyway...
+
+/bin/kill /proc/%d/cmdline
+/bin/kill /proc/%d/stat
+
+/bin/mount /proc/devices
+/bin/mount /proc/filesystems
+/bin/mount /proc/mounts
+
+/bin/netstat /proc/net
+/bin/netstat /proc/net/appletalk
+/bin/netstat /proc/net/ax25
+/bin/netstat /proc/net/ax25_route
+/bin/netstat /proc/net/dev
+/bin/netstat /proc/net/ip_masquerade
+/bin/netstat /proc/net/ipx
+/bin/netstat /proc/net/ipx_route
+/bin/netstat /proc/net/netstat
+/bin/netstat /proc/net/nr
+/bin/netstat /proc/net/nr_neigh
+/bin/netstat /proc/net/nr_nodes
+/bin/netstat /proc/net/raw
+/bin/netstat /proc/net/route
+/bin/netstat /proc/net/rt_cache
+/bin/netstat /proc/net/snmp
+/bin/netstat /proc/net/tcp
+/bin/netstat /proc/net/udp
+/bin/netstat /proc/net/unix
+
+/bin/umount /proc/devices
+/bin/umount /proc/mounts
+
+/sbin/arp /proc/net/appletalk
+/sbin/arp /proc/net/arp
+/sbin/arp /proc/net/ax25
+/sbin/arp /proc/net/ipx
+/sbin/arp /proc/net/nr
+/sbin/arp /proc/net/unix
+
+/sbin/cardctl /proc/devices
+
+/sbin/cardmgr /proc/devices
+
+/sbin/fdisk /proc/ide/%s/media
+/sbin/fdisk /proc/scsi/scsi
+
+/sbin/getty /proc/version
+
+/sbin/ifconfig /proc/net
+/sbin/ifconfig /proc/net/appletalk
+/sbin/ifconfig /proc/net/ax25
+/sbin/ifconfig /proc/net/dev
+/sbin/ifconfig /proc/net/ipx
+/sbin/ifconfig /proc/net/nr
+/sbin/ifconfig /proc/net/unix
+
+/sbin/ifup /proc/sys/kernel/modprobe
+
+/sbin/ipchains /proc/net/ip_fwchains
+/sbin/ipchains /proc/net/ip_fwnames
+/sbin/ipchains /proc/net/ip_masquerade
+/sbin/ipchains /proc/sys/net/ipv4/ip_forward
+
+/sbin/ipmaddr /proc/net/dev_mcast
+/sbin/ipmaddr /proc/net/igmp
+/sbin/ipmaddr /proc/net/igmp6
+
+/sbin/iptunnel /proc/net/dev
+
+/sbin/killall5 /proc/%s/cmdline
+/sbin/killall5 /proc/%s/exe
+/sbin/killall5 /proc/%s/stat
+/sbin/killall5 /proc/version
+
+/sbin/klogd /proc/kmsg
+
+/sbin/lsmod /proc/modules
+
+/sbin/modprobe /proc/modules
+
+/sbin/pidof /proc/%s/cmdline
+/sbin/pidof /proc/%s/exe
+/sbin/pidof /proc/%s/stat
+/sbin/pidof /proc/version
+
+/sbin/probe /proc/pci
+
+/sbin/rarp /proc/net/ax25
+/sbin/rarp /proc/net/nr
+/sbin/rarp /proc/net/rarp
+
+/sbin/rmmod /proc/modules
+
+/sbin/rmmod.static /proc/modules
+
+/sbin/route /proc/net/appletalk
+/sbin/route /proc/net/ax25
+/sbin/route /proc/net/ax25_route
+/sbin/route /proc/net/ipx
+/sbin/route /proc/net/ipx_route
+/sbin/route /proc/net/nr
+/sbin/route /proc/net/nr_neigh
+/sbin/route /proc/net/nr_nodes
+/sbin/route /proc/net/route
+/sbin/route /proc/net/rt_cache
+/sbin/route /proc/net/unix
+
+/sbin/scsi_info /proc/scsi
+/sbin/scsi_info /proc/scsi/%s
+/sbin/scsi_info /proc/scsi/scsi
+
+/sbin/slattach /proc/net/ax25
+/sbin/slattach /proc/net/nr
+
+/sbin/swapoff /proc/swaps
+
+/sbin/swapon /proc/swaps
+
+/sbin/uugetty /proc/version
+
+/usr/bin/dig /proc/
+/usr/bin/dig /proc/interrupts
+/usr/bin/dig /proc/meminfo
+/usr/bin/dig /proc/rtc
+/usr/bin/dig /proc/self/status
+/usr/bin/dig /proc/stat
+
+/usr/bin/dnsquery /proc/
+/usr/bin/dnsquery /proc/interrupts
+/usr/bin/dnsquery /proc/meminfo
+/usr/bin/dnsquery /proc/rtc
+/usr/bin/dnsquery /proc/self/status
+/usr/bin/dnsquery /proc/stat
+
+/usr/bin/eject /proc/mounts
+
+/usr/bin/emacs /proc/loadavg
+
+/usr/bin/fetchmail /proc/net/dev
+
+/usr/bin/free /proc/meminfo
+
+/usr/bin/gmake /proc/loadavg
+
+/usr/bin/gpm-root /proc/loadavg
+/usr/bin/gpm-root /proc/meminfo
+
+/usr/bin/host /proc/
+/usr/bin/host /proc/interrupts
+/usr/bin/host /proc/meminfo
+/usr/bin/host /proc/rtc
+/usr/bin/host /proc/self/status
+/usr/bin/host /proc/stat
+
+/usr/bin/hoststat /proc/loadavg
+
+/usr/bin/hwdiag /proc/cpuinfo
+/usr/bin/hwdiag /proc/pci
+/usr/bin/hwdiag /proc/scsi/scsi
+/usr/bin/hwdiag /proc/version
+
+/usr/bin/lsdev /proc/dma
+/usr/bin/lsdev /proc/interrupts
+/usr/bin/lsdev /proc/ioports
+
+/usr/bin/mailq /proc/loadavg
+
+/usr/bin/make /proc/loadavg
+
+/usr/bin/mcookie /proc/loadavg
+/usr/bin/mcookie /proc/stat
+
+/usr/bin/newaliases /proc/loadavg
+
+/usr/bin/nslookup /proc/
+/usr/bin/nslookup /proc/interrupts
+/usr/bin/nslookup /proc/meminfo
+/usr/bin/nslookup /proc/rtc
+/usr/bin/nslookup /proc/self/status
+/usr/bin/nslookup /proc/stat
+
+/usr/bin/nsupdate /proc/
+/usr/bin/nsupdate /proc/interrupts
+/usr/bin/nsupdate /proc/meminfo
+/usr/bin/nsupdate /proc/rtc
+/usr/bin/nsupdate /proc/self/status
+/usr/bin/nsupdate /proc/stat
+
+/usr/bin/pgp /proc/version
+/usr/bin/pgpe /proc/version
+/usr/bin/pgpk /proc/version
+/usr/bin/pgps /proc/version
+/usr/bin/pgpv /proc/version
+
+/usr/bin/procinfo /proc/cmdline
+/usr/bin/procinfo /proc/devices
+/usr/bin/procinfo /proc/dma
+/usr/bin/procinfo /proc/filesystems
+/usr/bin/procinfo /proc/interrupts
+/usr/bin/procinfo /proc/loadavg
+/usr/bin/procinfo /proc/meminfo
+/usr/bin/procinfo /proc/modules
+/usr/bin/procinfo /proc/stat
+/usr/bin/procinfo /proc/uptime
+/usr/bin/procinfo /proc/version
+
+/usr/bin/purgestat /proc/loadavg
+
+/usr/bin/screen /proc/loadavg
+
+/usr/bin/strace /proc/%d/stat
+
+/usr/bin/top /proc/cpuinfo
+/usr/bin/top /proc/meminfo
+/usr/bin/top /proc/stat
+
+/usr/bin/vmstat /proc/%s/stat
+/usr/bin/vmstat /proc/meminfo
+/usr/bin/vmstat /proc/stat
+
+/usr/sbin/atd /proc/loadavg
+
+/usr/sbin/dnskeygen /proc/
+/usr/sbin/dnskeygen /proc/interrupts
+/usr/sbin/dnskeygen /proc/meminfo
+/usr/sbin/dnskeygen /proc/rtc
+/usr/sbin/dnskeygen /proc/self/status
+/usr/sbin/dnskeygen /proc/stat
+
+/usr/sbin/fuser /proc/%d/stat
+/usr/sbin/fuser /proc/net/%s
+/usr/sbin/fuser /proc/net/unix
+
+/usr/sbin/in.identd /proc/net/tcp
+
+/usr/sbin/irpd /proc/
+/usr/sbin/irpd /proc/interrupts
+/usr/sbin/irpd /proc/meminfo
+/usr/sbin/irpd /proc/rtc
+/usr/sbin/irpd /proc/self/status
+/usr/sbin/irpd /proc/stat
+
+/usr/sbin/named /proc/
+/usr/sbin/named /proc/interrupts
+/usr/sbin/named /proc/meminfo
+/usr/sbin/named /proc/rtc
+/usr/sbin/named /proc/self/status
+/usr/sbin/named /proc/stat
+
+/usr/sbin/named-xfer /proc/
+/usr/sbin/named-xfer /proc/interrupts
+/usr/sbin/named-xfer /proc/meminfo
+/usr/sbin/named-xfer /proc/rtc
+/usr/sbin/named-xfer /proc/self/status
+/usr/sbin/named-xfer /proc/stat
+
+/usr/sbin/readprofile /proc/profile
+
+/usr/sbin/rwhod /proc/loadavg
+/usr/sbin/rwhod /proc/uptime
+
+/usr/sbin/sendmail /proc/loadavg
+
+/usr/sbin/setconsole /proc/openprom/options
+/usr/sbin/setconsole /proc/openprom/options/${console}-mode
+/usr/sbin/setconsole /proc/openprom/options/input-device
+/usr/sbin/setconsole /proc/openprom/options/output-device
+
+Best wishes from Riley.
+
+ * Copyright (C) 1999, Memory Alpha Systems.
+ * All rights and wrongs reserved.
+
++----------------------------------------------------------------------+
+| There is something frustrating about the quality and speed of Linux  |
+| development, ie., the quality is too high and the speed is too high, |
+| in other words, I can implement this XXXX feature, but I bet someone |
+| else has already done so and is just about to release their patch.   |
++----------------------------------------------------------------------+
+ * http://www.memalpha.cx/Linux/Kernel/
+
+
+-
+To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
+the body of a message to majordomo@vger.rutgers.edu
+Please read the FAQ at http://www.tux.org/lkml/
+
index ee745e73e1753e98f560f199241a507e31e07706..95fee63d6d99b4d153a6da2661c6d993ec394d6b 100644 (file)
@@ -32,301 +32,301 @@ void *__libc_stack_end;
 
 static const struct Applet applets[] = {
 
-#ifdef BB_BASENAME                             //usr/bin/basename
+#ifdef BB_BASENAME
        {"basename", basename_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_BUSYBOX                              //bin
+#ifdef BB_BUSYBOX
        {"busybox", busybox_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_BLOCK_DEVICE                 //sbin
+#ifdef BB_BLOCK_DEVICE
        {"block_device", block_device_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_CAT                                  //bin
+#ifdef BB_CAT
        {"cat", cat_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHROOT                               //sbin
+#ifdef BB_CHROOT
        {"chroot", chroot_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_CLEAR                                        //usr/bin
+#ifdef BB_CLEAR
        {"clear", clear_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_CHVT                                 //usr/bin
+#ifdef BB_CHVT
        {"chvt", chvt_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_CP_MV                                        //bin
+#ifdef BB_CP_MV
        {"cp", cp_mv_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CP_MV                                        //bin
+#ifdef BB_CP_MV
        {"mv", cp_mv_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DATE                                 //bin
+#ifdef BB_DATE
        {"date", date_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DD                                   //bin
+#ifdef BB_DD
        {"dd", dd_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DF                                   //bin
+#ifdef BB_DF
        {"df", df_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DIRNAME                              //usr/bin
+#ifdef BB_DIRNAME
        {"dirname", dirname_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_DMESG                                        //bin
+#ifdef BB_DMESG
        {"dmesg", dmesg_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DU                                   //bin
+#ifdef BB_DU
        {"du", du_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DUTMP                                        //usr/sbin
+#ifdef BB_DUTMP
        {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
 #endif
-#ifdef BB_ECHO                                 //bin
+#ifdef BB_ECHO
        {"echo", echo_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_FBSET                                        //usr/sbin
+#ifdef BB_FBSET
        {"fbset", fbset_main, _BB_DIR_USR_SBIN},
 #endif
-#ifdef BB_FDFLUSH                              //bin
+#ifdef BB_FDFLUSH
        {"fdflush", fdflush_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_FIND                                 //usr/bin
+#ifdef BB_FIND
        {"find", find_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FREE                                 //usr/bin
+#ifdef BB_FREE
        {"free", free_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FREERAMDISK                  //sbin
+#ifdef BB_FREERAMDISK
        {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_DEALLOCVT                            //usr/bin
+#ifdef BB_DEALLOCVT
        {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FSCK_MINIX                   //sbin
+#ifdef BB_FSCK_MINIX
        {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MKFS_MINIX                   //sbin
+#ifdef BB_MKFS_MINIX
        {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_GREP                                 //bin
+#ifdef BB_GREP
        {"grep", grep_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_HALT                                 //sbin
+#ifdef BB_HALT
        {"halt", halt_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_HEAD                                 //bin
+#ifdef BB_HEAD
        {"head", head_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_HOSTID                               //usr/bin
+#ifdef BB_HOSTID
        {"hostid", hostid_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_HOSTNAME                             //bin
+#ifdef BB_HOSTNAME
        {"hostname", hostname_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_INIT                                 //sbin
+#ifdef BB_INIT
        {"init", init_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_INSMOD                               //sbin
+#ifdef BB_INSMOD
        {"insmod", insmod_main, _BB_DIR_SBIN},
 #endif
 #ifdef BB_FEATURE_LINUXRC              //
        {"linuxrc", init_main, _BB_DIR_ROOT},
 #endif
-#ifdef BB_KILL                                 //bin
+#ifdef BB_KILL
        {"kill", kill_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_KILLALL                              //usr/bin
+#ifdef BB_KILLALL
        {"killall", kill_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LENGTH                               //usr/bin
+#ifdef BB_LENGTH
        {"length", length_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LN                                   //bin
+#ifdef BB_LN
        {"ln", ln_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_LOADACM                              //usr/bin
+#ifdef BB_LOADACM
        {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOADFONT                             //usr/bin
+#ifdef BB_LOADFONT
        {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOADKMAP                             //sbin
+#ifdef BB_LOADKMAP
        {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_LS                                   //bin
+#ifdef BB_LS
        {"ls", ls_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_LSMOD                                        //sbin
+#ifdef BB_LSMOD
        {"lsmod", lsmod_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MAKEDEVS                             //sbin
+#ifdef BB_MAKEDEVS
        {"makedevs", makedevs_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MATH                                 //usr/bin
+#ifdef BB_MATH
        {"math", math_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MKDIR                                        //bin
+#ifdef BB_MKDIR
        {"mkdir", mkdir_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MKFIFO                               //usr/bin
+#ifdef BB_MKFIFO
        {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MKNOD                                        //bin
+#ifdef BB_MKNOD
        {"mknod", mknod_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MKSWAP                               //sbin
+#ifdef BB_MKSWAP
        {"mkswap", mkswap_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MNC                                  //usr/bin
+#ifdef BB_MNC
        {"mnc", mnc_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MORE                                 //bin
+#ifdef BB_MORE
        {"more", more_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MOUNT                                        //bin
+#ifdef BB_MOUNT
        {"mount", mount_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MT                                   //bin
+#ifdef BB_MT
        {"mt", mt_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_NSLOOKUP                             //usr/bin
+#ifdef BB_NSLOOKUP
        {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_PING                                 //bin
+#ifdef BB_PING
        {"ping", ping_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_POWEROFF                             //sbin
+#ifdef BB_POWEROFF
        {"poweroff", poweroff_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_PRINTF                               //usr/bin
+#ifdef BB_PRINTF
        {"printf", printf_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_PS                                   //bin
+#ifdef BB_PS
        {"ps", ps_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_PWD                                  //bin
+#ifdef BB_PWD
        {"pwd", pwd_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_REBOOT                               //sbin
+#ifdef BB_REBOOT
        {"reboot", reboot_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_RM                                   //bin
+#ifdef BB_RM
        {"rm", rm_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_RMDIR                                        //bin
+#ifdef BB_RMDIR
        {"rmdir", rmdir_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_RMMOD                                        //sbin
+#ifdef BB_RMMOD
        {"rmmod", rmmod_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SED                                  //bin
+#ifdef BB_SED
        {"sed", sed_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SH                                   //bin
+#ifdef BB_SH
        {"sh", shell_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SFDISK                               //sbin
+#ifdef BB_SFDISK
        {"fdisk", sfdisk_main, _BB_DIR_SBIN},
-#ifdef BB_SFDISK                               //sbin
+#ifdef BB_SFDISK
 #endif
        {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SLEEP                                        //bin
+#ifdef BB_SLEEP
        {"sleep", sleep_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SORT                                 //bin
+#ifdef BB_SORT
        {"sort", sort_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SYNC                                 //bin
+#ifdef BB_SYNC
        {"sync", sync_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SYSLOGD                              //sbin
+#ifdef BB_SYSLOGD
        {"syslogd", syslogd_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_LOGGER                               //usr/bin
+#ifdef BB_LOGGER
        {"logger", logger_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOGNAME                              //usr/bin
+#ifdef BB_LOGNAME
        {"logname", logname_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_SWAPONOFF                            //sbin
+#ifdef BB_SWAPONOFF
        {"swapon", swap_on_off_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SWAPONOFF                            //sbin
+#ifdef BB_SWAPONOFF
        {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_TAIL                                 //usr/bin
+#ifdef BB_TAIL
        {"tail", tail_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TAR                                  //bin
+#ifdef BB_TAR
        {"tar", tar_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TELNET                               //usr/bin
+#ifdef BB_TELNET
        {"telnet", telnet_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEST                                 //usr/bin
+#ifdef BB_TEST
        {"[", test_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEST                                 //usr/bin
+#ifdef BB_TEST
        {"test", test_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEE                                  //bin
+#ifdef BB_TEE
        {"tee", tee_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TOUCH                                        //usr/bin
+#ifdef BB_TOUCH
        {"touch", touch_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TR                                   //usr/bin
+#ifdef BB_TR
        {"tr", tr_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TRUE_FALSE                   //bin
+#ifdef BB_TRUE_FALSE
        {"true", true_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TRUE_FALSE                   //bin
+#ifdef BB_TRUE_FALSE
        {"false", false_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TTY                                  //usr/bin
+#ifdef BB_TTY
        {"tty", tty_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_UMOUNT                               //bin
+#ifdef BB_UMOUNT
        {"umount", umount_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UNAME                                        //bin
+#ifdef BB_UNAME
        {"uname", uname_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UPTIME                               //usr/bin
+#ifdef BB_UPTIME
        {"uptime", uptime_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_UNIQ                                 //bin
+#ifdef BB_UNIQ
        {"uniq", uniq_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UPDATE                               //sbin
+#ifdef BB_UPDATE
        {"update", update_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_WC                                   //usr/bin
+#ifdef BB_WC
        {"wc", wc_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_WHOAMI                               //usr/bin
+#ifdef BB_WHOAMI
        {"whoami", whoami_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_YES                                  //usr/bin
+#ifdef BB_YES
        {"yes", yes_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_GUNZIP                               //bin
+#ifdef BB_GUNZIP
        {"zcat", gunzip_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_GUNZIP                               //bin
+#ifdef BB_GUNZIP
        {"gunzip", gunzip_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_GZIP                                 //bin
+#ifdef BB_GZIP
        {"gzip", gzip_main, _BB_DIR_BIN},
 #endif
        {0}
index 8f802de64544cf5a8a6697548856fab761c1ce73..8f83d04a6058d3acb7977ee0a981f780514051ae 100644 (file)
@@ -68,57 +68,84 @@ static const char tar_usage[] =
 #endif
 
 
-/*
- * Tar file constants.
- */
-#define TAR_BLOCK_SIZE 512
-#define TAR_NAME_SIZE  100
+/* Tar file constants  */
 
 
-/*
- * The POSIX (and basic GNU) tar header format.
- * This structure is always embedded in a TAR_BLOCK_SIZE sized block
- * with zero padding.  We only process this information minimally.
- */
-typedef struct {
-       char name[TAR_NAME_SIZE];
-       char mode[8];
-       char uid[8];
-       char gid[8];
-       char size[12];
-       char mtime[12];
-       char checkSum[8];
-       char typeFlag;
-       char linkName[TAR_NAME_SIZE];
-       char magic[6];
-       char version[2];
-       char uname[32];
-       char gname[32];
-       char devMajor[8];
-       char devMinor[8];
-       char prefix[155];
-} TarHeader;
-
-#define        TAR_MAGIC       "ustar"
-#define        TAR_VERSION     "00"
-
-#define        TAR_TYPE_REGULAR        '0'
-#define        TAR_TYPE_HARD_LINK      '1'
-#define        TAR_TYPE_SOFT_LINK      '2'
+/* POSIX tar Header Block, from POSIX 1003.1-1990  */
+struct TarHeader
+{
+                                /* byte offset */
+       char name[100];               /*   0 */
+       char mode[8];                 /* 100 */
+       char uid[8];                  /* 108 */
+       char gid[8];                  /* 116 */
+       char size[12];                /* 124 */
+       char mtime[12];               /* 136 */
+       char chksum[8];               /* 148 */
+       char typeflag;                /* 156 */
+       char linkname[100];           /* 157 */
+       char magic[6];                /* 257 */
+       char version[2];              /* 263 */
+       char uname[32];               /* 265 */
+       char gname[32];               /* 297 */
+       char devmajor[8];             /* 329 */
+       char devminor[8];             /* 337 */
+       char prefix[155];             /* 345 */
+       /* padding                       500 */
+};
+typedef struct TarHeader TarHeader;
+
+
+/* A few useful constants */
+#define TAR_MAGIC          "ustar"        /* ustar and a null */
+#define TAR_VERSION        "00"           /* 00 and no null */
+#define TAR_MAGIC_LEN       6
+#define TAR_VERSION_LEN     2
+#define TAR_NAME_LEN        100
+#define TAR_BLOCK_SIZE      512
+
+/* A nice enum with all the possible tar file content types */
+enum TarFileType 
+{
+       REGTYPE  = '0',            /* regular file */
+       REGTYPE0 = '\0',           /* regular file (ancient bug compat)*/
+       LNKTYPE  = '1',            /* hard link */
+       SYMTYPE  = '2',            /* symbolic link */
+       CHRTYPE  = '3',            /* character special */
+       BLKTYPE  = '4',            /* block special */
+       DIRTYPE  = '5',            /* directory */
+       FIFOTYPE = '6',            /* FIFO special */
+       CONTTYPE = '7',            /* reserved */
+};
+typedef enum TarFileType TarFileType;
+
+/* This struct ignores magic, non-numeric user name, 
+ * non-numeric group name, and the checksum, since
+ * these are all ignored by BusyBox tar. */ 
+struct TarInfo
+{
+       int              tarFd;          /* An open file descriptor for reading from the tarball */
+       char *           name;           /* File name */
+       mode_t           mode;           /* Unix mode, including device bits. */
+       uid_t            uid;            /* Numeric UID */
+       gid_t            gid;            /* Numeric GID */
+       size_t           size;           /* Size of file */
+       time_t           mtime;          /* Last-modified time */
+       enum TarFileType type;           /* Regular, directory, link, etc */
+       char *           linkname;       /* Name for symbolic and hard links */
+       dev_t            device;         /* Special device for mknod() */
+};
+typedef struct TarInfo TarInfo;
+
+/* Static data  */
+static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum);
 
 
 /*
  * Static data.
  */
-static int listFlag;
-static int extractFlag;
-static int createFlag;
-static int verboseFlag;
-static int tostdoutFlag;
-
 static int inHeader;                   // <- check me
 static int badHeader;
-static int errorFlag;
 static int skipFileFlag;
 static int warnedRoot;
 static int eofFlag;
@@ -134,7 +161,6 @@ static time_t mtime;
 /*
  * Static data associated with the tar file.
  */
-static const char *tarName;
 static int tarFd;
 static dev_t tarDev;
 static ino_t tarInode;
@@ -143,35 +169,25 @@ static ino_t tarInode;
 /*
  * Local procedures to restore files from a tar file.
  */
-static void readTarFile(int fileCount, char **fileTable);
+static int readTarFile(const char* tarName, int extractFlag, int listFlag, 
+               int tostdoutFlag, int verboseFlag);
 static void readData(const char *cp, int count);
 static long getOctal(const char *cp, int len);
-
-static void readHeader(const TarHeader * hp,
-
-                                          int fileCount, char **fileTable);
-
+static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header);
 static int wantFileName(const char *fileName,
-
-                                               int fileCount, char **fileTable);
+                                               int argc, char **argv);
 
 #ifdef BB_FEATURE_TAR_CREATE
 /*
  * Local procedures to save files into a tar file.
  */
 static void saveFile(const char *fileName, int seeLinks);
-
 static void saveRegularFile(const char *fileName,
-
                                                        const struct stat *statbuf);
-
 static void saveDirectory(const char *fileName,
-
                                                  const struct stat *statbuf);
-
 static void writeHeader(const char *fileName, const struct stat *statbuf);
-
-static void writeTarFile(int fileCount, char **fileTable);
+static void writeTarFile(int argc, char **argv);
 static void writeTarBlock(const char *buf, int len);
 static int putOctal(char *cp, int len, long value);
 
@@ -180,7 +196,13 @@ static int putOctal(char *cp, int len, long value);
 
 extern int tar_main(int argc, char **argv)
 {
+       const char *tarName=NULL;
        const char *options;
+       int listFlag     = FALSE;
+       int extractFlag  = FALSE;
+       int createFlag   = FALSE;
+       int verboseFlag  = FALSE;
+       int tostdoutFlag = FALSE;
 
        argc--;
        argv++;
@@ -188,21 +210,7 @@ extern int tar_main(int argc, char **argv)
        if (argc < 1)
                usage(tar_usage);
 
-
-       errorFlag = FALSE;
-       extractFlag = FALSE;
-       createFlag = FALSE;
-       listFlag = FALSE;
-       verboseFlag = FALSE;
-       tostdoutFlag = FALSE;
-       tarName = NULL;
-       tarDev = 0;
-       tarInode = 0;
-       tarFd = -1;
-
-       /* 
-        * Parse the options.
-        */
+       /* Parse options  */
        if (**argv == '-')
                options = (*argv++) + 1;
        else
@@ -212,13 +220,12 @@ extern int tar_main(int argc, char **argv)
        for (; *options; options++) {
                switch (*options) {
                case 'f':
-                       if (tarName != NULL) {
-                               fprintf(stderr, "Only one 'f' option allowed\n");
-
-                               exit(FALSE);
-                       }
+                       if (tarName != NULL)
+                               fatalError( "Only one 'f' option allowed\n");
 
                        tarName = *argv++;
+                       if (tarName == NULL)
+                               fatalError( "Option requires an argument: No file specified\n");
                        argc--;
 
                        break;
@@ -253,9 +260,8 @@ extern int tar_main(int argc, char **argv)
                        break;
 
                default:
-                       fprintf(stderr, "Unknown tar flag '%c'\n"
+                       fatalError( "Unknown tar flag '%c'\n" 
                                        "Try `tar --help' for more information\n", *options);
-                       exit(FALSE);
                }
        }
 
@@ -265,23 +271,22 @@ extern int tar_main(int argc, char **argv)
         */
        if (createFlag == TRUE) {
 #ifndef BB_FEATURE_TAR_CREATE
-               fprintf(stderr,
-                               "This version of tar was not compiled with tar creation support.\n");
-               exit(FALSE);
+               fatalError( "This version of tar was not compiled with tar creation support.\n");
 #else
-               writeTarFile(argc, argv);
+               exit(writeTarFile(argc, argv));
 #endif
        } else {
-               readTarFile(argc, argv);
+               exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag));
        }
-       if (errorFlag == TRUE) {
-               fprintf(stderr, "\n");
-       }
-       exit(!errorFlag);
 
   flagError:
-       fprintf(stderr, "Exactly one of 'c', 'x' or 't' must be specified\n");
-       exit(FALSE);
+       fatalError( "Exactly one of 'c', 'x' or 't' must be specified\n");
+}
+                                       
+static void
+tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
+{
+
 }
 
 
@@ -289,178 +294,148 @@ extern int tar_main(int argc, char **argv)
  * Read a tar file and extract or list the specified files within it.
  * If the list is empty than all files are extracted or listed.
  */
-static void readTarFile(int fileCount, char **fileTable)
+static int readTarFile(const char* tarName, int extractFlag, int listFlag, 
+               int tostdoutFlag, int verboseFlag)
 {
-       const char *cp;
-       int cc;
-       int inCc;
-       int blockSize;
-       char buf[BUF_SIZE];
-
-       skipFileFlag = FALSE;
-       badHeader = FALSE;
-       warnedRoot = FALSE;
-       eofFlag = FALSE;
-       inHeader = TRUE;
-       inCc = 0;
-       dataCc = 0;
-       outFd = -1;
-       blockSize = sizeof(buf);
-       cp = buf;
+       int status, tarFd=0;
+       int errorFlag=FALSE;
+       TarHeader rawHeader;
+       TarInfo header;
 
-       /* 
-        * Open the tar file for reading.
-        */
-       if ((tarName == NULL) || !strcmp(tarName, "-")) {
+       /* Open the tar file for reading.  */
+       if (!strcmp(tarName, "-"))
                tarFd = fileno(stdin);
-       else
+       else
                tarFd = open(tarName, O_RDONLY);
-
        if (tarFd < 0) {
-               perror(tarName);
-               errorFlag = TRUE;
-               return;
+               errorMsg( "Error opening '%s': %s", tarName, strerror(errno));
+               return ( FALSE);
        }
 
-       /* 
-        * Read blocks from the file until an end of file header block
-        * has been seen.  (A real end of file from a read is an error.)
-        */
-       while (eofFlag == FALSE) {
-               /* 
-                * Read the next block of data if necessary.
-                * This will be a large block if possible, which we will
-                * then process in the small tar blocks.
-                */
-               if (inCc <= 0) {
-                       cp = buf;
-                       inCc = fullRead(tarFd, buf, blockSize);
-
-                       if (inCc < 0) {
-                               perror(tarName);
-                               errorFlag = TRUE;
-                               goto done;
-                       }
-
-                       if (inCc == 0) {
-                               fprintf(stderr,
-                                               "Unexpected end of file from \"%s\"", tarName);
-                               errorFlag = TRUE;
-                               goto done;
+       /* Read the tar file */
+       while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
+               /* Now see if the header looks ok */
+               if ( parseTarHeader(&rawHeader, &header) == FALSE ) {
+                       close( tarFd);
+                       if ( *(header.name) == '\0' ) {
+                               goto endgame;
+                       } else {
+                               errorFlag=TRUE;
+                               errorMsg("Bad tar header, skipping\n");
+                               continue;
                        }
                }
-
-               /* 
-                * If we are expecting a header block then examine it.
-                */
-               if (inHeader == TRUE) {
-                       readHeader((const TarHeader *) cp, fileCount, fileTable);
-
-                       cp += TAR_BLOCK_SIZE;
-                       inCc -= TAR_BLOCK_SIZE;
-
-                       continue;
+               if ( *(header.name) == '\0' )
+                               goto endgame;
+
+               /* If we got here, we can be certain we have a legitimate 
+                * header to work with.  So work with it.  */
+               switch ( header.type ) {
+                       case REGTYPE:
+                       case REGTYPE0:
+                               /* If the name ends in a '/' then assume it is
+                                * supposed to be a directory, and fall through */
+                               if (header.name[strlen(header.name)-1] != '/') {
+                                       tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                                       break;
+                               }
+#if 0
+                       case Directory:
+                               tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case HardLink:
+                               tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case SymbolicLink:
+                               tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case CharacterDevice:
+                       case BlockDevice:
+                       case FIFO:
+                               tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+#endif
+                       default:
+                               close( tarFd);
+                               return( FALSE);
                }
-
-               /* 
-                * We are currently handling the data for a file.
-                * Process the minimum of the amount of data we have available
-                * and the amount left to be processed for the file.
-                */
-               cc = inCc;
-
-               if (cc > dataCc)
-                       cc = dataCc;
-
-               readData(cp, cc);
-
-               /* 
-                * If the amount left isn't an exact multiple of the tar block
-                * size then round it up to the next block boundary since there
-                * is padding at the end of the file.
-                */
-               if (cc % TAR_BLOCK_SIZE)
-                       cc += TAR_BLOCK_SIZE - (cc % TAR_BLOCK_SIZE);
-
-               cp += cc;
-               inCc -= cc;
        }
 
-  done:
-       /* 
-        * Close the tar file if needed.
-        */
-       if ((tarFd >= 0) && (close(tarFd) < 0))
-               perror(tarName);
-
-       /* 
-        * Close the output file if needed.
-        * This is only done here on a previous error and so no
-        * message is required on errors.
-        */
-       if (tostdoutFlag == FALSE) {
-               if (outFd >= 0) {
-                       close(outFd);
-               }
+       close(tarFd);
+       if (status > 0) {
+               /* Bummer - we read a partial header */
+               errorMsg( "Error reading '%s': %s", tarName, strerror(errno));
+               return ( FALSE);
        }
+       else 
+               return( status);
+
+       /* Stuff we do when we know we are done with the file */
+endgame:
+       close( tarFd);
+       if ( *(header.name) == '\0' ) {
+               if (errorFlag==FALSE)
+                       return( TRUE);
+       } 
+       return( FALSE);
 }
 
-
 /*
- * Examine the header block that was just read.
- * This can specify the information for another file, or it can mark
- * the end of the tar file.
+ * Read an octal value in a field of the specified width, with optional
+ * spaces on both sides of the number and with an optional null character
+ * at the end.  Returns -1 on an illegal format.
  */
-static void
-readHeader(const TarHeader * hp, int fileCount, char **fileTable)
+static long getOctal(const char *cp, int size)
 {
-       int checkSum;
-       int cc;
-       int hardLink;
-       int softLink;
-       int devFileFlag;
-       unsigned int major;
-       unsigned int minor;
-       long size;
-       struct utimbuf utb;
-
-       /* 
-        * If the block is completely empty, then this is the end of the
-        * archive file.  If the name is null, then just skip this header.
-        */
-       outName = hp->name;
-
-       if (*outName == '\0') {
-               for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) {
-                       if (*outName++)
-                               return;
-               }
+       long val = 0;
 
-               eofFlag = TRUE;
-
-               return;
+       for(;(size > 0) && (*cp == ' '); cp++, size--);
+       if ((size == 0) || !isOctal(*cp))
+               return -1;
+       for(; (size > 0) && isOctal(*cp); size--) {
+               val = val * 8 + *cp++ - '0';
        }
+       for (;(size > 0) && (*cp == ' '); cp++, size--);
+       if ((size > 0) && *cp)
+               return -1;
+       return val;
+}
 
-       /* 
-        * There is another file in the archive to examine.
-        * Extract the encoded information and check it.
-        */
-       mode = getOctal(hp->mode, sizeof(hp->mode));
-       uid = getOctal(hp->uid, sizeof(hp->uid));
-       gid = getOctal(hp->gid, sizeof(hp->gid));
-       size = getOctal(hp->size, sizeof(hp->size));
-       mtime = getOctal(hp->mtime, sizeof(hp->mtime));
-       checkSum = getOctal(hp->checkSum, sizeof(hp->checkSum));
-       major = getOctal(hp->devMajor, sizeof(hp->devMajor));
-       minor = getOctal(hp->devMinor, sizeof(hp->devMinor));
-
-       if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
-               if (badHeader == FALSE)
-                       fprintf(stderr, "Bad tar header, skipping\n");
-
-               badHeader = TRUE;
+/* Parse the tar header and fill in the nice struct with the details */
+static int
+parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
+{
+       long major, minor, chksum, sum;
+
+       header->name  = rawHeader->name;
+       header->mode  = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
+       header->uid   =  getOctal(rawHeader->uid, sizeof(rawHeader->uid));
+       header->gid   =  getOctal(rawHeader->gid, sizeof(rawHeader->gid));
+       header->size  = getOctal(rawHeader->size, sizeof(rawHeader->size));
+       header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime));
+       chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
+       header->type  = rawHeader->typeflag;
+       header->linkname  = rawHeader->linkname;
+       header->device  = MAJOR(getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor))) |
+               MINOR(getOctal(rawHeader->devminor, sizeof(rawHeader->devminor)));
+
+       /* Check the checksum */
+       sum = ' ' * sizeof(rawHeader->chksum);
+       for ( i = TarChecksumOffset; i > 0; i-- )
+               sum += *s++;
+       s += sizeof(h->chksum);       
+       for ( i = (512 - TarChecksumOffset - sizeof(h->chksum)); i > 0; i-- )
+               sum += *s++;
+       if (sum == checksum )
+               return ( TRUE);
+       return( FALSE);
+}
 
-               return;
+#if 0
+       if ((header->mode < 0) || (header->uid < 0) || 
+                       (header->gid < 0) || (header->size < 0)) {
+               errorMsg(stderr, "Bad tar header, skipping\n");
+               return( FALSE);
        }
 
        badHeader = FALSE;
@@ -502,7 +477,7 @@ readHeader(const TarHeader * hp, int fileCount, char **fileTable)
         * See if we want this file to be restored.
         * If not, then set up to skip it.
         */
-       if (wantFileName(outName, fileCount, fileTable) == FALSE) {
+       if (wantFileName(outName, argc, argv) == FALSE) {
                if (!hardLink && !softLink && (S_ISREG(mode) || S_ISCHR(mode)
                                                                           || S_ISBLK(mode) || S_ISSOCK(mode)
                                                                           || S_ISFIFO(mode))) {
@@ -726,7 +701,7 @@ static void readData(const char *cp, int count)
  * Returns TRUE if the file is selected.
  */
 static int
-wantFileName(const char *fileName, int fileCount, char **fileTable)
+wantFileName(const char *fileName, int argc, char **argv)
 {
        const char *pathName;
        int fileLength;
@@ -735,7 +710,7 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        /* 
         * If there are no files in the list, then the file is wanted.
         */
-       if (fileCount == 0)
+       if (argc == 0)
                return TRUE;
 
        fileLength = strlen(fileName);
@@ -743,8 +718,8 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        /* 
         * Check each of the test paths.
         */
-       while (fileCount-- > 0) {
-               pathName = *fileTable++;
+       while (argc-- > 0) {
+               pathName = *argv++;
 
                pathLength = strlen(pathName);
 
@@ -762,43 +737,6 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        return FALSE;
 }
 
-/*
- * Read an octal value in a field of the specified width, with optional
- * spaces on both sides of the number and with an optional null character
- * at the end.  Returns -1 on an illegal format.
- */
-static long getOctal(const char *cp, int len)
-{
-       long val;
-
-       while ((len > 0) && (*cp == ' ')) {
-               cp++;
-               len--;
-       }
-
-       if ((len == 0) || !isOctal(*cp))
-               return -1;
-
-       val = 0;
-
-       while ((len > 0) && isOctal(*cp)) {
-               val = val * 8 + *cp++ - '0';
-               len--;
-       }
-
-       while ((len > 0) && (*cp == ' ')) {
-               cp++;
-               len--;
-       }
-
-       if ((len > 0) && *cp)
-               return -1;
-
-       return val;
-}
-
-
-
 
 /* From here to the end of the file is the tar writing stuff.
  * If you do not have BB_FEATURE_TAR_CREATE defined, this will
@@ -809,14 +747,14 @@ static long getOctal(const char *cp, int len)
 /*
  * Write a tar file containing the specified files.
  */
-static void writeTarFile(int fileCount, char **fileTable)
+static void writeTarFile(int argc, char **argv)
 {
        struct stat statbuf;
 
        /* 
         * Make sure there is at least one file specified.
         */
-       if (fileCount <= 0) {
+       if (argc <= 0) {
                fprintf(stderr, "No files specified to be saved\n");
                errorFlag = TRUE;
        }
@@ -852,8 +790,8 @@ static void writeTarFile(int fileCount, char **fileTable)
         * Append each file name into the archive file.
         * Follow symbolic links for these top level file names.
         */
-       while (errorFlag == FALSE && (fileCount-- > 0)) {
-               saveFile(*fileTable++, FALSE);
+       while (errorFlag == FALSE && (argc-- > 0)) {
+               saveFile(*argv++, FALSE);
        }
 
        /* 
@@ -1284,3 +1222,4 @@ static int putOctal(char *cp, int len, long value)
 #endif
 
 /* END CODE */
+#endif
index ee745e73e1753e98f560f199241a507e31e07706..95fee63d6d99b4d153a6da2661c6d993ec394d6b 100644 (file)
--- a/busybox.c
+++ b/busybox.c
@@ -32,301 +32,301 @@ void *__libc_stack_end;
 
 static const struct Applet applets[] = {
 
-#ifdef BB_BASENAME                             //usr/bin/basename
+#ifdef BB_BASENAME
        {"basename", basename_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_BUSYBOX                              //bin
+#ifdef BB_BUSYBOX
        {"busybox", busybox_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_BLOCK_DEVICE                 //sbin
+#ifdef BB_BLOCK_DEVICE
        {"block_device", block_device_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_CAT                                  //bin
+#ifdef BB_CAT
        {"cat", cat_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHMOD_CHOWN_CHGRP            //bin
+#ifdef BB_CHMOD_CHOWN_CHGRP
        {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CHROOT                               //sbin
+#ifdef BB_CHROOT
        {"chroot", chroot_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_CLEAR                                        //usr/bin
+#ifdef BB_CLEAR
        {"clear", clear_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_CHVT                                 //usr/bin
+#ifdef BB_CHVT
        {"chvt", chvt_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_CP_MV                                        //bin
+#ifdef BB_CP_MV
        {"cp", cp_mv_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_CP_MV                                        //bin
+#ifdef BB_CP_MV
        {"mv", cp_mv_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DATE                                 //bin
+#ifdef BB_DATE
        {"date", date_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DD                                   //bin
+#ifdef BB_DD
        {"dd", dd_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DF                                   //bin
+#ifdef BB_DF
        {"df", df_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DIRNAME                              //usr/bin
+#ifdef BB_DIRNAME
        {"dirname", dirname_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_DMESG                                        //bin
+#ifdef BB_DMESG
        {"dmesg", dmesg_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DU                                   //bin
+#ifdef BB_DU
        {"du", du_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_DUTMP                                        //usr/sbin
+#ifdef BB_DUTMP
        {"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
 #endif
-#ifdef BB_ECHO                                 //bin
+#ifdef BB_ECHO
        {"echo", echo_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_FBSET                                        //usr/sbin
+#ifdef BB_FBSET
        {"fbset", fbset_main, _BB_DIR_USR_SBIN},
 #endif
-#ifdef BB_FDFLUSH                              //bin
+#ifdef BB_FDFLUSH
        {"fdflush", fdflush_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_FIND                                 //usr/bin
+#ifdef BB_FIND
        {"find", find_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FREE                                 //usr/bin
+#ifdef BB_FREE
        {"free", free_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FREERAMDISK                  //sbin
+#ifdef BB_FREERAMDISK
        {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_DEALLOCVT                            //usr/bin
+#ifdef BB_DEALLOCVT
        {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_FSCK_MINIX                   //sbin
+#ifdef BB_FSCK_MINIX
        {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MKFS_MINIX                   //sbin
+#ifdef BB_MKFS_MINIX
        {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_GREP                                 //bin
+#ifdef BB_GREP
        {"grep", grep_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_HALT                                 //sbin
+#ifdef BB_HALT
        {"halt", halt_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_HEAD                                 //bin
+#ifdef BB_HEAD
        {"head", head_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_HOSTID                               //usr/bin
+#ifdef BB_HOSTID
        {"hostid", hostid_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_HOSTNAME                             //bin
+#ifdef BB_HOSTNAME
        {"hostname", hostname_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_INIT                                 //sbin
+#ifdef BB_INIT
        {"init", init_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_INSMOD                               //sbin
+#ifdef BB_INSMOD
        {"insmod", insmod_main, _BB_DIR_SBIN},
 #endif
 #ifdef BB_FEATURE_LINUXRC              //
        {"linuxrc", init_main, _BB_DIR_ROOT},
 #endif
-#ifdef BB_KILL                                 //bin
+#ifdef BB_KILL
        {"kill", kill_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_KILLALL                              //usr/bin
+#ifdef BB_KILLALL
        {"killall", kill_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LENGTH                               //usr/bin
+#ifdef BB_LENGTH
        {"length", length_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LN                                   //bin
+#ifdef BB_LN
        {"ln", ln_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_LOADACM                              //usr/bin
+#ifdef BB_LOADACM
        {"loadacm", loadacm_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOADFONT                             //usr/bin
+#ifdef BB_LOADFONT
        {"loadfont", loadfont_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOADKMAP                             //sbin
+#ifdef BB_LOADKMAP
        {"loadkmap", loadkmap_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_LS                                   //bin
+#ifdef BB_LS
        {"ls", ls_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_LSMOD                                        //sbin
+#ifdef BB_LSMOD
        {"lsmod", lsmod_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MAKEDEVS                             //sbin
+#ifdef BB_MAKEDEVS
        {"makedevs", makedevs_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MATH                                 //usr/bin
+#ifdef BB_MATH
        {"math", math_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MKDIR                                        //bin
+#ifdef BB_MKDIR
        {"mkdir", mkdir_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MKFIFO                               //usr/bin
+#ifdef BB_MKFIFO
        {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MKNOD                                        //bin
+#ifdef BB_MKNOD
        {"mknod", mknod_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MKSWAP                               //sbin
+#ifdef BB_MKSWAP
        {"mkswap", mkswap_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_MNC                                  //usr/bin
+#ifdef BB_MNC
        {"mnc", mnc_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_MORE                                 //bin
+#ifdef BB_MORE
        {"more", more_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MOUNT                                        //bin
+#ifdef BB_MOUNT
        {"mount", mount_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_MT                                   //bin
+#ifdef BB_MT
        {"mt", mt_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_NSLOOKUP                             //usr/bin
+#ifdef BB_NSLOOKUP
        {"nslookup", nslookup_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_PING                                 //bin
+#ifdef BB_PING
        {"ping", ping_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_POWEROFF                             //sbin
+#ifdef BB_POWEROFF
        {"poweroff", poweroff_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_PRINTF                               //usr/bin
+#ifdef BB_PRINTF
        {"printf", printf_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_PS                                   //bin
+#ifdef BB_PS
        {"ps", ps_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_PWD                                  //bin
+#ifdef BB_PWD
        {"pwd", pwd_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_REBOOT                               //sbin
+#ifdef BB_REBOOT
        {"reboot", reboot_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_RM                                   //bin
+#ifdef BB_RM
        {"rm", rm_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_RMDIR                                        //bin
+#ifdef BB_RMDIR
        {"rmdir", rmdir_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_RMMOD                                        //sbin
+#ifdef BB_RMMOD
        {"rmmod", rmmod_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SED                                  //bin
+#ifdef BB_SED
        {"sed", sed_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SH                                   //bin
+#ifdef BB_SH
        {"sh", shell_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SFDISK                               //sbin
+#ifdef BB_SFDISK
        {"fdisk", sfdisk_main, _BB_DIR_SBIN},
-#ifdef BB_SFDISK                               //sbin
+#ifdef BB_SFDISK
 #endif
        {"sfdisk", sfdisk_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SLEEP                                        //bin
+#ifdef BB_SLEEP
        {"sleep", sleep_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SORT                                 //bin
+#ifdef BB_SORT
        {"sort", sort_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SYNC                                 //bin
+#ifdef BB_SYNC
        {"sync", sync_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_SYSLOGD                              //sbin
+#ifdef BB_SYSLOGD
        {"syslogd", syslogd_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_LOGGER                               //usr/bin
+#ifdef BB_LOGGER
        {"logger", logger_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_LOGNAME                              //usr/bin
+#ifdef BB_LOGNAME
        {"logname", logname_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_SWAPONOFF                            //sbin
+#ifdef BB_SWAPONOFF
        {"swapon", swap_on_off_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_SWAPONOFF                            //sbin
+#ifdef BB_SWAPONOFF
        {"swapoff", swap_on_off_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_TAIL                                 //usr/bin
+#ifdef BB_TAIL
        {"tail", tail_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TAR                                  //bin
+#ifdef BB_TAR
        {"tar", tar_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TELNET                               //usr/bin
+#ifdef BB_TELNET
        {"telnet", telnet_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEST                                 //usr/bin
+#ifdef BB_TEST
        {"[", test_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEST                                 //usr/bin
+#ifdef BB_TEST
        {"test", test_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TEE                                  //bin
+#ifdef BB_TEE
        {"tee", tee_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TOUCH                                        //usr/bin
+#ifdef BB_TOUCH
        {"touch", touch_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TR                                   //usr/bin
+#ifdef BB_TR
        {"tr", tr_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_TRUE_FALSE                   //bin
+#ifdef BB_TRUE_FALSE
        {"true", true_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TRUE_FALSE                   //bin
+#ifdef BB_TRUE_FALSE
        {"false", false_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_TTY                                  //usr/bin
+#ifdef BB_TTY
        {"tty", tty_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_UMOUNT                               //bin
+#ifdef BB_UMOUNT
        {"umount", umount_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UNAME                                        //bin
+#ifdef BB_UNAME
        {"uname", uname_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UPTIME                               //usr/bin
+#ifdef BB_UPTIME
        {"uptime", uptime_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_UNIQ                                 //bin
+#ifdef BB_UNIQ
        {"uniq", uniq_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_UPDATE                               //sbin
+#ifdef BB_UPDATE
        {"update", update_main, _BB_DIR_SBIN},
 #endif
-#ifdef BB_WC                                   //usr/bin
+#ifdef BB_WC
        {"wc", wc_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_WHOAMI                               //usr/bin
+#ifdef BB_WHOAMI
        {"whoami", whoami_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_YES                                  //usr/bin
+#ifdef BB_YES
        {"yes", yes_main, _BB_DIR_USR_BIN},
 #endif
-#ifdef BB_GUNZIP                               //bin
+#ifdef BB_GUNZIP
        {"zcat", gunzip_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_GUNZIP                               //bin
+#ifdef BB_GUNZIP
        {"gunzip", gunzip_main, _BB_DIR_BIN},
 #endif
-#ifdef BB_GZIP                                 //bin
+#ifdef BB_GZIP
        {"gzip", gzip_main, _BB_DIR_BIN},
 #endif
        {0}
index cfafc29c84575c0761443379650923d20f4a0928..388219a529e74f237de470144fef93a016d0b138 100644 (file)
 #define BB_FEATURE_SH_COMMAND_EDITING
 //
 //
+//Turn on extra fbset options
+//#define BB_FEATURE_FBSET_FANCY
+//
+//
 // End of Features List
 //
 //
index aa4f6bbc8667423105b4f7410d0a92c320c80464..fe533d5221f2f6642407f68a790543e039c41cac 100644 (file)
@@ -87,6 +87,8 @@ int loadkmap_main(int argc, char **argv)
                        }
                }
        }
-       close(fd);
+       /* Don't bother to close files.  Exit does that 
+        * automagically, so we can save a few bytes */
+       /* close(fd); */
        return 0;
 }
index 652db8d74c2cd93d211a665767b592fe08e06ccb..199a894c0ee0c990de0fbc80f3f3967b4f41c879 100644 (file)
@@ -202,8 +202,8 @@ int date_main(int argc, char **argv)
                                        usage(date_usage);
                                }
                } else {
-                       if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
-                               date_fmt = *argv;
+                       if ((date_fmt == NULL) && (**argv == '+'))
+                               date_fmt = *argv + 1;   /* Skip over the '+' */
                        else if (date_str == NULL) {
                                set_time = 1;
                                date_str = *argv;
index f40dec712d0d7c6801150f9589833684c2fd2a09..d50cf746b9eb630c7794645d8b14604d72d3d5e6 100644 (file)
@@ -125,9 +125,12 @@ extern int dd_main(int argc, char **argv)
                inFd = open(inFile, 0);
 
        if (inFd < 0) {
-               perror(inFile);
-               free(buf);
-               exit(FALSE);
+               /* Note that we are not freeing buf or closing
+                * files here to save a few bytes. This exits
+                * here anyways... */
+
+               /* free(buf); */
+               fatalError( inFile);
        }
 
        if (outFile == NULL)
@@ -136,10 +139,13 @@ extern int dd_main(int argc, char **argv)
                outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 
        if (outFd < 0) {
-               perror(outFile);
-               close(inFd);
-               free(buf);
-               exit(FALSE);
+               /* Note that we are not freeing buf or closing
+                * files here to save a few bytes. This exits
+                * here anyways... */
+
+               /* close(inFd);
+                  free(buf); */
+               fatalError( outFile);
        }
 
        lseek(inFd, skipBlocks * blockSize, SEEK_SET);
@@ -180,9 +186,13 @@ extern int dd_main(int argc, char **argv)
                perror(inFile);
 
   cleanup:
+       /* Note that we are not freeing memory or closing
+        * files here, to save a few bytes. */
+#if 0
        close(inFd);
        close(outFd);
        free(buf);
+#endif
 
        printf("%ld+%d records in\n", (long) (intotal / blockSize),
                   (intotal % blockSize) != 0);
index c2266f533a8b3a3e6160b69e61dbaa47fd44c6da..c4856cb713d8d63e1db18e05fcd9df7e85efd9fa 100644 (file)
 #define APPCHAR(mode)  ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
 #endif
 
-#ifndef MAJOR
-#define MAJOR(dev) (((dev)>>8)&0xff)
-#define MINOR(dev) ((dev)&0xff)
-#endif
-
 #define FMT_AUTO       0
 #define FMT_LONG       1                       /* one record per line, extended info */
 #define FMT_SINGLE     2                       /* one record per line */
index a3a1c8132b962f9b5e8e78a0433547875e8c1e6c..018fe117bed77627a57df69cefcd4d5315c455de 100644 (file)
@@ -125,8 +125,10 @@ int tee_main(int argc, char **argv)
 
        /* clean up */
        FL_apply(tee_fclose, 0);
-       free(FileList);
+       /* Don't bother to close files  Exit does that 
+        * automagically, so we can save a few bytes */
+       /* free(FileList); */
        exit(0);
 }
 
-/* $Id: tee.c,v 1.7 2000/03/08 00:14:35 beppu Exp $ */
+/* $Id: tee.c,v 1.8 2000/03/23 01:09:18 erik Exp $ */
diff --git a/date.c b/date.c
index 652db8d74c2cd93d211a665767b592fe08e06ccb..199a894c0ee0c990de0fbc80f3f3967b4f41c879 100644 (file)
--- a/date.c
+++ b/date.c
@@ -202,8 +202,8 @@ int date_main(int argc, char **argv)
                                        usage(date_usage);
                                }
                } else {
-                       if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
-                               date_fmt = *argv;
+                       if ((date_fmt == NULL) && (**argv == '+'))
+                               date_fmt = *argv + 1;   /* Skip over the '+' */
                        else if (date_str == NULL) {
                                set_time = 1;
                                date_str = *argv;
diff --git a/dd.c b/dd.c
index f40dec712d0d7c6801150f9589833684c2fd2a09..d50cf746b9eb630c7794645d8b14604d72d3d5e6 100644 (file)
--- a/dd.c
+++ b/dd.c
@@ -125,9 +125,12 @@ extern int dd_main(int argc, char **argv)
                inFd = open(inFile, 0);
 
        if (inFd < 0) {
-               perror(inFile);
-               free(buf);
-               exit(FALSE);
+               /* Note that we are not freeing buf or closing
+                * files here to save a few bytes. This exits
+                * here anyways... */
+
+               /* free(buf); */
+               fatalError( inFile);
        }
 
        if (outFile == NULL)
@@ -136,10 +139,13 @@ extern int dd_main(int argc, char **argv)
                outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 
        if (outFd < 0) {
-               perror(outFile);
-               close(inFd);
-               free(buf);
-               exit(FALSE);
+               /* Note that we are not freeing buf or closing
+                * files here to save a few bytes. This exits
+                * here anyways... */
+
+               /* close(inFd);
+                  free(buf); */
+               fatalError( outFile);
        }
 
        lseek(inFd, skipBlocks * blockSize, SEEK_SET);
@@ -180,9 +186,13 @@ extern int dd_main(int argc, char **argv)
                perror(inFile);
 
   cleanup:
+       /* Note that we are not freeing memory or closing
+        * files here, to save a few bytes. */
+#if 0
        close(inFd);
        close(outFd);
        free(buf);
+#endif
 
        printf("%ld+%d records in\n", (long) (intotal / blockSize),
                   (intotal % blockSize) != 0);
diff --git a/fbset.c b/fbset.c
index a75e431db011b15e8292bfc7ec3c96020603fa46..7ca41733b36edc8b54e72b49186f96e2c6fb17c9 100644 (file)
--- a/fbset.c
+++ b/fbset.c
@@ -62,7 +62,7 @@
 #define CMD_ALL         11
 #define CMD_INFO        12
 
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
 #define CMD_XRES       13
 #define CMD_YRES       14
 #define CMD_VXRES      15
@@ -105,7 +105,7 @@ struct cmdoptions_t {
        "-vsync", 1, CMD_VSYNC}, {
        "-laced", 1, CMD_LACED}, {
        "-double", 1, CMD_DOUBLE},
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
        {
        "--help", 0, CMD_HELP}, {
        "-all", 0, CMD_ALL}, {
@@ -164,8 +164,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
                }
        }
 #else
-       fprintf(stderr,
-                       "W: mode reading was disabled on this copy of fbset; ignoring request\n");
+       errorMsg( "mode reading not compiled in\n");
 #endif
        return 0;
 }
@@ -199,7 +198,7 @@ static void showmode(struct fb_var_screeninfo *v)
                                         v->vsync_len);
        }
        printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
        printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
                   hrate / 1e3, vrate);
 #endif
@@ -283,7 +282,7 @@ extern int fbset_main(int argc, char **argv)
                                        varset.hsync_len = strtoul(argv[6], 0, 0);
                                        varset.vsync_len = strtoul(argv[7], 0, 0);
                                        break;
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
                                case CMD_XRES:
                                        varset.xres = strtoul(argv[1], 0, 0);
                                        break;
@@ -323,7 +322,8 @@ extern int fbset_main(int argc, char **argv)
                if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
                        PERROR("fbset(ioctl)");
        showmode(&var);
-       close(fh);
+       /* Don't close the file, as exiting will take care of that */
+       /* close(fh); */
 
-       return (TRUE);
+       exit (TRUE);
 }
index 0b154c8a605fefc13577ff4668a3a8257675f32d..201cea89879141702cce973cd4aeef4d57711522 100644 (file)
--- a/fdflush.c
+++ b/fdflush.c
@@ -44,7 +44,9 @@ extern int fdflush_main(int argc, char **argv)
        }
 
        value = ioctl(fd, FDFLUSH, 0);
-       close(fd);
+       /* Don't bother closing.  Exit does
+        * that, so we can save a few bytes */
+       /* close(fd); */
 
        if (value) {
                perror(*argv);
index 43d42d424fb8c84a2949d31d674bfe88aadbc3ca..06937a70ff2b1ff5f5a7254738a8ccb3f2f5213f 100644 (file)
@@ -55,7 +55,9 @@ freeramdisk_main(int argc, char **argv)
        if (ioctl(f, BLKFLSBUF) < 0) {
                fatalError( "freeramdisk: failed ioctl on %s: %s", rname, strerror(errno));
        }
-       close(f);
+       /* Don't bother closing.  Exit does
+        * that, so we can save a few bytes */
+       /* close(f); */
        exit(TRUE);
 }
 
index 47e81ce421a4417d73ffa3d03d3ecbe313ac8e22..aa0a82432c6a85c3717955876a1746abcc84bb2f 100644 (file)
@@ -1242,6 +1242,7 @@ static void alloc_name_list(void)
                name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
 }
 
+#if 0
 /* execute this atexit() to deallocate name_list[] */
 /* piptigger was here */
 static void free_name_list(void)
@@ -1257,6 +1258,7 @@ static void free_name_list(void)
                free(name_list);
        }
 }
+#endif
 
 extern int fsck_minix_main(int argc, char **argv)
 {
@@ -1265,7 +1267,9 @@ extern int fsck_minix_main(int argc, char **argv)
        int retcode = 0;
 
        alloc_name_list();
-       atexit(free_name_list);
+       /* Don't bother to free memory.  Exit does
+        * that automagically, so we can save a few bytes */
+       //atexit(free_name_list);
 
        if (argc && *argv)
                program_name = *argv;
diff --git a/init.c b/init.c
index de5e2c05f4fd8b834288d18cd77fabadcbd61ff5..9079165375519b41ca5f52e92bed7af06cb6ad92 100644 (file)
--- a/init.c
+++ b/init.c
@@ -825,6 +825,9 @@ extern int init_main(int argc, char **argv)
        reboot(RB_DISABLE_CAD);
 #endif
 
+       /* Figure out what kernel this is running */
+       kernelVersion = get_kernel_revision();
+
        /* Figure out where the default console should be */
        console_init();
 
index de5e2c05f4fd8b834288d18cd77fabadcbd61ff5..9079165375519b41ca5f52e92bed7af06cb6ad92 100644 (file)
@@ -825,6 +825,9 @@ extern int init_main(int argc, char **argv)
        reboot(RB_DISABLE_CAD);
 #endif
 
+       /* Figure out what kernel this is running */
+       kernelVersion = get_kernel_revision();
+
        /* Figure out where the default console should be */
        console_init();
 
index 9f9461defaf15f719a528f17b18d3a14b575978f..84624b3943842d4d5805456118eede7310fa5d92 100644 (file)
 #define BUF_SIZE        8192
 #define EXPAND_ALLOC    1024
 
+
+#ifndef MAJOR
+#define MAJOR(dev) (((dev)>>8)&0xff)
+#define MINOR(dev) ((dev)&0xff)
+#endif
+
 #define isBlank(ch)     (((ch) == ' ') || ((ch) == '\t'))
 #define isDecimal(ch)   (((ch) >= '0') && ((ch) <= '9'))
 #define isOctal(ch)     (((ch) >= '0') && ((ch) <= '7'))
@@ -201,14 +207,12 @@ extern uid_t my_getpwnam(char *name);
 extern gid_t my_getgrnam(char *name); 
 extern void my_getpwuid(char* name, uid_t uid);
 extern void my_getgrgid(char* group, gid_t gid);
-extern int get_kernel_revision();
 extern int get_console_fd(char* tty_name);
 extern struct mntent *findMountPoint(const char *name, const char *table);
 extern void write_mtab(char* blockDevice, char* directory, 
        char* filesystemType, long flags, char* string_flags);
 extern void erase_mtab(const char * name);
 extern void mtab_read(void);
-extern void mtab_free(void);
 extern char *mtab_first(void **iter);
 extern char *mtab_next(void **iter);
 extern char *mtab_getinfo(const char *match, const char which);
index aa4f6bbc8667423105b4f7410d0a92c320c80464..fe533d5221f2f6642407f68a790543e039c41cac 100644 (file)
@@ -87,6 +87,8 @@ int loadkmap_main(int argc, char **argv)
                        }
                }
        }
-       close(fd);
+       /* Don't bother to close files.  Exit does that 
+        * automagically, so we can save a few bytes */
+       /* close(fd); */
        return 0;
 }
diff --git a/ls.c b/ls.c
index c2266f533a8b3a3e6160b69e61dbaa47fd44c6da..c4856cb713d8d63e1db18e05fcd9df7e85efd9fa 100644 (file)
--- a/ls.c
+++ b/ls.c
 #define APPCHAR(mode)  ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
 #endif
 
-#ifndef MAJOR
-#define MAJOR(dev) (((dev)>>8)&0xff)
-#define MINOR(dev) ((dev)&0xff)
-#endif
-
 #define FMT_AUTO       0
 #define FMT_LONG       1                       /* one record per line, extended info */
 #define FMT_SINGLE     2                       /* one record per line */
diff --git a/mount.c b/mount.c
index 03891371aa2ccd3d3a6bc2a30aa3234a9fe73052..30a060fc1e006a72d96835211089d554ba2bb27a 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -348,8 +348,12 @@ extern int mount_main(int argc, char **argv)
                                        mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, 
                                        mntentlist[i].mnt_passno);
                }
+               /* Don't bother to close files or free memory.  Exit 
+                * does that automagically, so we can save a few bytes */
+#if 0
                free( mntentlist);
                close(fd);
+#endif
                exit(TRUE);
        }
 #else
diff --git a/tar.c b/tar.c
index 8f802de64544cf5a8a6697548856fab761c1ce73..8f83d04a6058d3acb7977ee0a981f780514051ae 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -68,57 +68,84 @@ static const char tar_usage[] =
 #endif
 
 
-/*
- * Tar file constants.
- */
-#define TAR_BLOCK_SIZE 512
-#define TAR_NAME_SIZE  100
+/* Tar file constants  */
 
 
-/*
- * The POSIX (and basic GNU) tar header format.
- * This structure is always embedded in a TAR_BLOCK_SIZE sized block
- * with zero padding.  We only process this information minimally.
- */
-typedef struct {
-       char name[TAR_NAME_SIZE];
-       char mode[8];
-       char uid[8];
-       char gid[8];
-       char size[12];
-       char mtime[12];
-       char checkSum[8];
-       char typeFlag;
-       char linkName[TAR_NAME_SIZE];
-       char magic[6];
-       char version[2];
-       char uname[32];
-       char gname[32];
-       char devMajor[8];
-       char devMinor[8];
-       char prefix[155];
-} TarHeader;
-
-#define        TAR_MAGIC       "ustar"
-#define        TAR_VERSION     "00"
-
-#define        TAR_TYPE_REGULAR        '0'
-#define        TAR_TYPE_HARD_LINK      '1'
-#define        TAR_TYPE_SOFT_LINK      '2'
+/* POSIX tar Header Block, from POSIX 1003.1-1990  */
+struct TarHeader
+{
+                                /* byte offset */
+       char name[100];               /*   0 */
+       char mode[8];                 /* 100 */
+       char uid[8];                  /* 108 */
+       char gid[8];                  /* 116 */
+       char size[12];                /* 124 */
+       char mtime[12];               /* 136 */
+       char chksum[8];               /* 148 */
+       char typeflag;                /* 156 */
+       char linkname[100];           /* 157 */
+       char magic[6];                /* 257 */
+       char version[2];              /* 263 */
+       char uname[32];               /* 265 */
+       char gname[32];               /* 297 */
+       char devmajor[8];             /* 329 */
+       char devminor[8];             /* 337 */
+       char prefix[155];             /* 345 */
+       /* padding                       500 */
+};
+typedef struct TarHeader TarHeader;
+
+
+/* A few useful constants */
+#define TAR_MAGIC          "ustar"        /* ustar and a null */
+#define TAR_VERSION        "00"           /* 00 and no null */
+#define TAR_MAGIC_LEN       6
+#define TAR_VERSION_LEN     2
+#define TAR_NAME_LEN        100
+#define TAR_BLOCK_SIZE      512
+
+/* A nice enum with all the possible tar file content types */
+enum TarFileType 
+{
+       REGTYPE  = '0',            /* regular file */
+       REGTYPE0 = '\0',           /* regular file (ancient bug compat)*/
+       LNKTYPE  = '1',            /* hard link */
+       SYMTYPE  = '2',            /* symbolic link */
+       CHRTYPE  = '3',            /* character special */
+       BLKTYPE  = '4',            /* block special */
+       DIRTYPE  = '5',            /* directory */
+       FIFOTYPE = '6',            /* FIFO special */
+       CONTTYPE = '7',            /* reserved */
+};
+typedef enum TarFileType TarFileType;
+
+/* This struct ignores magic, non-numeric user name, 
+ * non-numeric group name, and the checksum, since
+ * these are all ignored by BusyBox tar. */ 
+struct TarInfo
+{
+       int              tarFd;          /* An open file descriptor for reading from the tarball */
+       char *           name;           /* File name */
+       mode_t           mode;           /* Unix mode, including device bits. */
+       uid_t            uid;            /* Numeric UID */
+       gid_t            gid;            /* Numeric GID */
+       size_t           size;           /* Size of file */
+       time_t           mtime;          /* Last-modified time */
+       enum TarFileType type;           /* Regular, directory, link, etc */
+       char *           linkname;       /* Name for symbolic and hard links */
+       dev_t            device;         /* Special device for mknod() */
+};
+typedef struct TarInfo TarInfo;
+
+/* Static data  */
+static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum);
 
 
 /*
  * Static data.
  */
-static int listFlag;
-static int extractFlag;
-static int createFlag;
-static int verboseFlag;
-static int tostdoutFlag;
-
 static int inHeader;                   // <- check me
 static int badHeader;
-static int errorFlag;
 static int skipFileFlag;
 static int warnedRoot;
 static int eofFlag;
@@ -134,7 +161,6 @@ static time_t mtime;
 /*
  * Static data associated with the tar file.
  */
-static const char *tarName;
 static int tarFd;
 static dev_t tarDev;
 static ino_t tarInode;
@@ -143,35 +169,25 @@ static ino_t tarInode;
 /*
  * Local procedures to restore files from a tar file.
  */
-static void readTarFile(int fileCount, char **fileTable);
+static int readTarFile(const char* tarName, int extractFlag, int listFlag, 
+               int tostdoutFlag, int verboseFlag);
 static void readData(const char *cp, int count);
 static long getOctal(const char *cp, int len);
-
-static void readHeader(const TarHeader * hp,
-
-                                          int fileCount, char **fileTable);
-
+static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header);
 static int wantFileName(const char *fileName,
-
-                                               int fileCount, char **fileTable);
+                                               int argc, char **argv);
 
 #ifdef BB_FEATURE_TAR_CREATE
 /*
  * Local procedures to save files into a tar file.
  */
 static void saveFile(const char *fileName, int seeLinks);
-
 static void saveRegularFile(const char *fileName,
-
                                                        const struct stat *statbuf);
-
 static void saveDirectory(const char *fileName,
-
                                                  const struct stat *statbuf);
-
 static void writeHeader(const char *fileName, const struct stat *statbuf);
-
-static void writeTarFile(int fileCount, char **fileTable);
+static void writeTarFile(int argc, char **argv);
 static void writeTarBlock(const char *buf, int len);
 static int putOctal(char *cp, int len, long value);
 
@@ -180,7 +196,13 @@ static int putOctal(char *cp, int len, long value);
 
 extern int tar_main(int argc, char **argv)
 {
+       const char *tarName=NULL;
        const char *options;
+       int listFlag     = FALSE;
+       int extractFlag  = FALSE;
+       int createFlag   = FALSE;
+       int verboseFlag  = FALSE;
+       int tostdoutFlag = FALSE;
 
        argc--;
        argv++;
@@ -188,21 +210,7 @@ extern int tar_main(int argc, char **argv)
        if (argc < 1)
                usage(tar_usage);
 
-
-       errorFlag = FALSE;
-       extractFlag = FALSE;
-       createFlag = FALSE;
-       listFlag = FALSE;
-       verboseFlag = FALSE;
-       tostdoutFlag = FALSE;
-       tarName = NULL;
-       tarDev = 0;
-       tarInode = 0;
-       tarFd = -1;
-
-       /* 
-        * Parse the options.
-        */
+       /* Parse options  */
        if (**argv == '-')
                options = (*argv++) + 1;
        else
@@ -212,13 +220,12 @@ extern int tar_main(int argc, char **argv)
        for (; *options; options++) {
                switch (*options) {
                case 'f':
-                       if (tarName != NULL) {
-                               fprintf(stderr, "Only one 'f' option allowed\n");
-
-                               exit(FALSE);
-                       }
+                       if (tarName != NULL)
+                               fatalError( "Only one 'f' option allowed\n");
 
                        tarName = *argv++;
+                       if (tarName == NULL)
+                               fatalError( "Option requires an argument: No file specified\n");
                        argc--;
 
                        break;
@@ -253,9 +260,8 @@ extern int tar_main(int argc, char **argv)
                        break;
 
                default:
-                       fprintf(stderr, "Unknown tar flag '%c'\n"
+                       fatalError( "Unknown tar flag '%c'\n" 
                                        "Try `tar --help' for more information\n", *options);
-                       exit(FALSE);
                }
        }
 
@@ -265,23 +271,22 @@ extern int tar_main(int argc, char **argv)
         */
        if (createFlag == TRUE) {
 #ifndef BB_FEATURE_TAR_CREATE
-               fprintf(stderr,
-                               "This version of tar was not compiled with tar creation support.\n");
-               exit(FALSE);
+               fatalError( "This version of tar was not compiled with tar creation support.\n");
 #else
-               writeTarFile(argc, argv);
+               exit(writeTarFile(argc, argv));
 #endif
        } else {
-               readTarFile(argc, argv);
+               exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag));
        }
-       if (errorFlag == TRUE) {
-               fprintf(stderr, "\n");
-       }
-       exit(!errorFlag);
 
   flagError:
-       fprintf(stderr, "Exactly one of 'c', 'x' or 't' must be specified\n");
-       exit(FALSE);
+       fatalError( "Exactly one of 'c', 'x' or 't' must be specified\n");
+}
+                                       
+static void
+tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
+{
+
 }
 
 
@@ -289,178 +294,148 @@ extern int tar_main(int argc, char **argv)
  * Read a tar file and extract or list the specified files within it.
  * If the list is empty than all files are extracted or listed.
  */
-static void readTarFile(int fileCount, char **fileTable)
+static int readTarFile(const char* tarName, int extractFlag, int listFlag, 
+               int tostdoutFlag, int verboseFlag)
 {
-       const char *cp;
-       int cc;
-       int inCc;
-       int blockSize;
-       char buf[BUF_SIZE];
-
-       skipFileFlag = FALSE;
-       badHeader = FALSE;
-       warnedRoot = FALSE;
-       eofFlag = FALSE;
-       inHeader = TRUE;
-       inCc = 0;
-       dataCc = 0;
-       outFd = -1;
-       blockSize = sizeof(buf);
-       cp = buf;
+       int status, tarFd=0;
+       int errorFlag=FALSE;
+       TarHeader rawHeader;
+       TarInfo header;
 
-       /* 
-        * Open the tar file for reading.
-        */
-       if ((tarName == NULL) || !strcmp(tarName, "-")) {
+       /* Open the tar file for reading.  */
+       if (!strcmp(tarName, "-"))
                tarFd = fileno(stdin);
-       else
+       else
                tarFd = open(tarName, O_RDONLY);
-
        if (tarFd < 0) {
-               perror(tarName);
-               errorFlag = TRUE;
-               return;
+               errorMsg( "Error opening '%s': %s", tarName, strerror(errno));
+               return ( FALSE);
        }
 
-       /* 
-        * Read blocks from the file until an end of file header block
-        * has been seen.  (A real end of file from a read is an error.)
-        */
-       while (eofFlag == FALSE) {
-               /* 
-                * Read the next block of data if necessary.
-                * This will be a large block if possible, which we will
-                * then process in the small tar blocks.
-                */
-               if (inCc <= 0) {
-                       cp = buf;
-                       inCc = fullRead(tarFd, buf, blockSize);
-
-                       if (inCc < 0) {
-                               perror(tarName);
-                               errorFlag = TRUE;
-                               goto done;
-                       }
-
-                       if (inCc == 0) {
-                               fprintf(stderr,
-                                               "Unexpected end of file from \"%s\"", tarName);
-                               errorFlag = TRUE;
-                               goto done;
+       /* Read the tar file */
+       while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
+               /* Now see if the header looks ok */
+               if ( parseTarHeader(&rawHeader, &header) == FALSE ) {
+                       close( tarFd);
+                       if ( *(header.name) == '\0' ) {
+                               goto endgame;
+                       } else {
+                               errorFlag=TRUE;
+                               errorMsg("Bad tar header, skipping\n");
+                               continue;
                        }
                }
-
-               /* 
-                * If we are expecting a header block then examine it.
-                */
-               if (inHeader == TRUE) {
-                       readHeader((const TarHeader *) cp, fileCount, fileTable);
-
-                       cp += TAR_BLOCK_SIZE;
-                       inCc -= TAR_BLOCK_SIZE;
-
-                       continue;
+               if ( *(header.name) == '\0' )
+                               goto endgame;
+
+               /* If we got here, we can be certain we have a legitimate 
+                * header to work with.  So work with it.  */
+               switch ( header.type ) {
+                       case REGTYPE:
+                       case REGTYPE0:
+                               /* If the name ends in a '/' then assume it is
+                                * supposed to be a directory, and fall through */
+                               if (header.name[strlen(header.name)-1] != '/') {
+                                       tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                                       break;
+                               }
+#if 0
+                       case Directory:
+                               tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case HardLink:
+                               tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case SymbolicLink:
+                               tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+                       case CharacterDevice:
+                       case BlockDevice:
+                       case FIFO:
+                               tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
+                               break;
+#endif
+                       default:
+                               close( tarFd);
+                               return( FALSE);
                }
-
-               /* 
-                * We are currently handling the data for a file.
-                * Process the minimum of the amount of data we have available
-                * and the amount left to be processed for the file.
-                */
-               cc = inCc;
-
-               if (cc > dataCc)
-                       cc = dataCc;
-
-               readData(cp, cc);
-
-               /* 
-                * If the amount left isn't an exact multiple of the tar block
-                * size then round it up to the next block boundary since there
-                * is padding at the end of the file.
-                */
-               if (cc % TAR_BLOCK_SIZE)
-                       cc += TAR_BLOCK_SIZE - (cc % TAR_BLOCK_SIZE);
-
-               cp += cc;
-               inCc -= cc;
        }
 
-  done:
-       /* 
-        * Close the tar file if needed.
-        */
-       if ((tarFd >= 0) && (close(tarFd) < 0))
-               perror(tarName);
-
-       /* 
-        * Close the output file if needed.
-        * This is only done here on a previous error and so no
-        * message is required on errors.
-        */
-       if (tostdoutFlag == FALSE) {
-               if (outFd >= 0) {
-                       close(outFd);
-               }
+       close(tarFd);
+       if (status > 0) {
+               /* Bummer - we read a partial header */
+               errorMsg( "Error reading '%s': %s", tarName, strerror(errno));
+               return ( FALSE);
        }
+       else 
+               return( status);
+
+       /* Stuff we do when we know we are done with the file */
+endgame:
+       close( tarFd);
+       if ( *(header.name) == '\0' ) {
+               if (errorFlag==FALSE)
+                       return( TRUE);
+       } 
+       return( FALSE);
 }
 
-
 /*
- * Examine the header block that was just read.
- * This can specify the information for another file, or it can mark
- * the end of the tar file.
+ * Read an octal value in a field of the specified width, with optional
+ * spaces on both sides of the number and with an optional null character
+ * at the end.  Returns -1 on an illegal format.
  */
-static void
-readHeader(const TarHeader * hp, int fileCount, char **fileTable)
+static long getOctal(const char *cp, int size)
 {
-       int checkSum;
-       int cc;
-       int hardLink;
-       int softLink;
-       int devFileFlag;
-       unsigned int major;
-       unsigned int minor;
-       long size;
-       struct utimbuf utb;
-
-       /* 
-        * If the block is completely empty, then this is the end of the
-        * archive file.  If the name is null, then just skip this header.
-        */
-       outName = hp->name;
-
-       if (*outName == '\0') {
-               for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) {
-                       if (*outName++)
-                               return;
-               }
+       long val = 0;
 
-               eofFlag = TRUE;
-
-               return;
+       for(;(size > 0) && (*cp == ' '); cp++, size--);
+       if ((size == 0) || !isOctal(*cp))
+               return -1;
+       for(; (size > 0) && isOctal(*cp); size--) {
+               val = val * 8 + *cp++ - '0';
        }
+       for (;(size > 0) && (*cp == ' '); cp++, size--);
+       if ((size > 0) && *cp)
+               return -1;
+       return val;
+}
 
-       /* 
-        * There is another file in the archive to examine.
-        * Extract the encoded information and check it.
-        */
-       mode = getOctal(hp->mode, sizeof(hp->mode));
-       uid = getOctal(hp->uid, sizeof(hp->uid));
-       gid = getOctal(hp->gid, sizeof(hp->gid));
-       size = getOctal(hp->size, sizeof(hp->size));
-       mtime = getOctal(hp->mtime, sizeof(hp->mtime));
-       checkSum = getOctal(hp->checkSum, sizeof(hp->checkSum));
-       major = getOctal(hp->devMajor, sizeof(hp->devMajor));
-       minor = getOctal(hp->devMinor, sizeof(hp->devMinor));
-
-       if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
-               if (badHeader == FALSE)
-                       fprintf(stderr, "Bad tar header, skipping\n");
-
-               badHeader = TRUE;
+/* Parse the tar header and fill in the nice struct with the details */
+static int
+parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
+{
+       long major, minor, chksum, sum;
+
+       header->name  = rawHeader->name;
+       header->mode  = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
+       header->uid   =  getOctal(rawHeader->uid, sizeof(rawHeader->uid));
+       header->gid   =  getOctal(rawHeader->gid, sizeof(rawHeader->gid));
+       header->size  = getOctal(rawHeader->size, sizeof(rawHeader->size));
+       header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime));
+       chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
+       header->type  = rawHeader->typeflag;
+       header->linkname  = rawHeader->linkname;
+       header->device  = MAJOR(getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor))) |
+               MINOR(getOctal(rawHeader->devminor, sizeof(rawHeader->devminor)));
+
+       /* Check the checksum */
+       sum = ' ' * sizeof(rawHeader->chksum);
+       for ( i = TarChecksumOffset; i > 0; i-- )
+               sum += *s++;
+       s += sizeof(h->chksum);       
+       for ( i = (512 - TarChecksumOffset - sizeof(h->chksum)); i > 0; i-- )
+               sum += *s++;
+       if (sum == checksum )
+               return ( TRUE);
+       return( FALSE);
+}
 
-               return;
+#if 0
+       if ((header->mode < 0) || (header->uid < 0) || 
+                       (header->gid < 0) || (header->size < 0)) {
+               errorMsg(stderr, "Bad tar header, skipping\n");
+               return( FALSE);
        }
 
        badHeader = FALSE;
@@ -502,7 +477,7 @@ readHeader(const TarHeader * hp, int fileCount, char **fileTable)
         * See if we want this file to be restored.
         * If not, then set up to skip it.
         */
-       if (wantFileName(outName, fileCount, fileTable) == FALSE) {
+       if (wantFileName(outName, argc, argv) == FALSE) {
                if (!hardLink && !softLink && (S_ISREG(mode) || S_ISCHR(mode)
                                                                           || S_ISBLK(mode) || S_ISSOCK(mode)
                                                                           || S_ISFIFO(mode))) {
@@ -726,7 +701,7 @@ static void readData(const char *cp, int count)
  * Returns TRUE if the file is selected.
  */
 static int
-wantFileName(const char *fileName, int fileCount, char **fileTable)
+wantFileName(const char *fileName, int argc, char **argv)
 {
        const char *pathName;
        int fileLength;
@@ -735,7 +710,7 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        /* 
         * If there are no files in the list, then the file is wanted.
         */
-       if (fileCount == 0)
+       if (argc == 0)
                return TRUE;
 
        fileLength = strlen(fileName);
@@ -743,8 +718,8 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        /* 
         * Check each of the test paths.
         */
-       while (fileCount-- > 0) {
-               pathName = *fileTable++;
+       while (argc-- > 0) {
+               pathName = *argv++;
 
                pathLength = strlen(pathName);
 
@@ -762,43 +737,6 @@ wantFileName(const char *fileName, int fileCount, char **fileTable)
        return FALSE;
 }
 
-/*
- * Read an octal value in a field of the specified width, with optional
- * spaces on both sides of the number and with an optional null character
- * at the end.  Returns -1 on an illegal format.
- */
-static long getOctal(const char *cp, int len)
-{
-       long val;
-
-       while ((len > 0) && (*cp == ' ')) {
-               cp++;
-               len--;
-       }
-
-       if ((len == 0) || !isOctal(*cp))
-               return -1;
-
-       val = 0;
-
-       while ((len > 0) && isOctal(*cp)) {
-               val = val * 8 + *cp++ - '0';
-               len--;
-       }
-
-       while ((len > 0) && (*cp == ' ')) {
-               cp++;
-               len--;
-       }
-
-       if ((len > 0) && *cp)
-               return -1;
-
-       return val;
-}
-
-
-
 
 /* From here to the end of the file is the tar writing stuff.
  * If you do not have BB_FEATURE_TAR_CREATE defined, this will
@@ -809,14 +747,14 @@ static long getOctal(const char *cp, int len)
 /*
  * Write a tar file containing the specified files.
  */
-static void writeTarFile(int fileCount, char **fileTable)
+static void writeTarFile(int argc, char **argv)
 {
        struct stat statbuf;
 
        /* 
         * Make sure there is at least one file specified.
         */
-       if (fileCount <= 0) {
+       if (argc <= 0) {
                fprintf(stderr, "No files specified to be saved\n");
                errorFlag = TRUE;
        }
@@ -852,8 +790,8 @@ static void writeTarFile(int fileCount, char **fileTable)
         * Append each file name into the archive file.
         * Follow symbolic links for these top level file names.
         */
-       while (errorFlag == FALSE && (fileCount-- > 0)) {
-               saveFile(*fileTable++, FALSE);
+       while (errorFlag == FALSE && (argc-- > 0)) {
+               saveFile(*argv++, FALSE);
        }
 
        /* 
@@ -1284,3 +1222,4 @@ static int putOctal(char *cp, int len, long value)
 #endif
 
 /* END CODE */
+#endif
diff --git a/tee.c b/tee.c
index a3a1c8132b962f9b5e8e78a0433547875e8c1e6c..018fe117bed77627a57df69cefcd4d5315c455de 100644 (file)
--- a/tee.c
+++ b/tee.c
@@ -125,8 +125,10 @@ int tee_main(int argc, char **argv)
 
        /* clean up */
        FL_apply(tee_fclose, 0);
-       free(FileList);
+       /* Don't bother to close files  Exit does that 
+        * automagically, so we can save a few bytes */
+       /* free(FileList); */
        exit(0);
 }
 
-/* $Id: tee.c,v 1.7 2000/03/08 00:14:35 beppu Exp $ */
+/* $Id: tee.c,v 1.8 2000/03/23 01:09:18 erik Exp $ */
index c34bf5fc3f2c778a1cae0a95dd36e38e39de8ebf..23973fc855ca21aeb2e7fd112410fb22ba2f66a4 100644 (file)
--- a/umount.c
+++ b/umount.c
@@ -145,6 +145,9 @@ char *mtab_next(void **iter)
        return mp;
 }
 
+/* Don't bother to clean up, since exit() does that 
+ * automagically, so we can save a few bytes */
+#if 0
 void mtab_free(void)
 {
        struct _mtab_entry_t *this, *next;
@@ -160,6 +163,7 @@ void mtab_free(void)
                this = next;
        }
 }
+#endif
 
 static int do_umount(const char *name, int useMtab)
 {
index a75e431db011b15e8292bfc7ec3c96020603fa46..7ca41733b36edc8b54e72b49186f96e2c6fb17c9 100644 (file)
@@ -62,7 +62,7 @@
 #define CMD_ALL         11
 #define CMD_INFO        12
 
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
 #define CMD_XRES       13
 #define CMD_YRES       14
 #define CMD_VXRES      15
@@ -105,7 +105,7 @@ struct cmdoptions_t {
        "-vsync", 1, CMD_VSYNC}, {
        "-laced", 1, CMD_LACED}, {
        "-double", 1, CMD_DOUBLE},
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
        {
        "--help", 0, CMD_HELP}, {
        "-all", 0, CMD_ALL}, {
@@ -164,8 +164,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
                }
        }
 #else
-       fprintf(stderr,
-                       "W: mode reading was disabled on this copy of fbset; ignoring request\n");
+       errorMsg( "mode reading not compiled in\n");
 #endif
        return 0;
 }
@@ -199,7 +198,7 @@ static void showmode(struct fb_var_screeninfo *v)
                                         v->vsync_len);
        }
        printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
        printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
                   hrate / 1e3, vrate);
 #endif
@@ -283,7 +282,7 @@ extern int fbset_main(int argc, char **argv)
                                        varset.hsync_len = strtoul(argv[6], 0, 0);
                                        varset.vsync_len = strtoul(argv[7], 0, 0);
                                        break;
-#ifdef BB_FBSET_FANCY
+#ifdef BB_FEATURE_FBSET_FANCY
                                case CMD_XRES:
                                        varset.xres = strtoul(argv[1], 0, 0);
                                        break;
@@ -323,7 +322,8 @@ extern int fbset_main(int argc, char **argv)
                if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
                        PERROR("fbset(ioctl)");
        showmode(&var);
-       close(fh);
+       /* Don't close the file, as exiting will take care of that */
+       /* close(fh); */
 
-       return (TRUE);
+       exit (TRUE);
 }
index 0b154c8a605fefc13577ff4668a3a8257675f32d..201cea89879141702cce973cd4aeef4d57711522 100644 (file)
@@ -44,7 +44,9 @@ extern int fdflush_main(int argc, char **argv)
        }
 
        value = ioctl(fd, FDFLUSH, 0);
-       close(fd);
+       /* Don't bother closing.  Exit does
+        * that, so we can save a few bytes */
+       /* close(fd); */
 
        if (value) {
                perror(*argv);
index 43d42d424fb8c84a2949d31d674bfe88aadbc3ca..06937a70ff2b1ff5f5a7254738a8ccb3f2f5213f 100644 (file)
@@ -55,7 +55,9 @@ freeramdisk_main(int argc, char **argv)
        if (ioctl(f, BLKFLSBUF) < 0) {
                fatalError( "freeramdisk: failed ioctl on %s: %s", rname, strerror(errno));
        }
-       close(f);
+       /* Don't bother closing.  Exit does
+        * that, so we can save a few bytes */
+       /* close(f); */
        exit(TRUE);
 }
 
index 47e81ce421a4417d73ffa3d03d3ecbe313ac8e22..aa0a82432c6a85c3717955876a1746abcc84bb2f 100644 (file)
@@ -1242,6 +1242,7 @@ static void alloc_name_list(void)
                name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
 }
 
+#if 0
 /* execute this atexit() to deallocate name_list[] */
 /* piptigger was here */
 static void free_name_list(void)
@@ -1257,6 +1258,7 @@ static void free_name_list(void)
                free(name_list);
        }
 }
+#endif
 
 extern int fsck_minix_main(int argc, char **argv)
 {
@@ -1265,7 +1267,9 @@ extern int fsck_minix_main(int argc, char **argv)
        int retcode = 0;
 
        alloc_name_list();
-       atexit(free_name_list);
+       /* Don't bother to free memory.  Exit does
+        * that automagically, so we can save a few bytes */
+       //atexit(free_name_list);
 
        if (argc && *argv)
                program_name = *argv;
index 03891371aa2ccd3d3a6bc2a30aa3234a9fe73052..30a060fc1e006a72d96835211089d554ba2bb27a 100644 (file)
@@ -348,8 +348,12 @@ extern int mount_main(int argc, char **argv)
                                        mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, 
                                        mntentlist[i].mnt_passno);
                }
+               /* Don't bother to close files or free memory.  Exit 
+                * does that automagically, so we can save a few bytes */
+#if 0
                free( mntentlist);
                close(fd);
+#endif
                exit(TRUE);
        }
 #else
index c34bf5fc3f2c778a1cae0a95dd36e38e39de8ebf..23973fc855ca21aeb2e7fd112410fb22ba2f66a4 100644 (file)
@@ -145,6 +145,9 @@ char *mtab_next(void **iter)
        return mp;
 }
 
+/* Don't bother to clean up, since exit() does that 
+ * automagically, so we can save a few bytes */
+#if 0
 void mtab_free(void)
 {
        struct _mtab_entry_t *this, *next;
@@ -160,6 +163,7 @@ void mtab_free(void)
                this = next;
        }
 }
+#endif
 
 static int do_umount(const char *name, int useMtab)
 {
index c779cc6badb588c2f57f65278a2fd9ee761c0ffc..a39ecd935e7abf48e5676bd1167d6fdf3ccd27b9 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -112,10 +112,10 @@ extern void fatalError(char *s, ...)
        exit( FALSE);
 }
 
-#if defined (BB_INIT) || defined (BB_PS)
+#if defined BB_INIT
 /* Returns kernel version encoded as major*65536 + minor*256 + patch,
  * so, for example,  to check if the kernel is greater than 2.2.11:
- *     if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
+ *     if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
  */
 int get_kernel_revision()
 {
@@ -129,7 +129,7 @@ int get_kernel_revision()
        sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
        return major * 65536 + minor * 256 + patch;
 }
-#endif                                                 /* BB_INIT || BB_PS */
+#endif                                                 /* BB_INIT */
 
 #if defined (BB_CP_MV) || defined (BB_DU)