Compare commits

...
150 Commits
Author SHA1 Message Date
Eric Andersen 59248bad97 Set version to 0.39
-Erik
1999-12-11 04:21:50 +00:00
Eric Andersen 84b009256f Minor updates 1999-12-11 04:16:51 +00:00
John Beppu b52a218c95 Removed a redundant call du(); Save cpu cycles. 1999-12-10 15:23:47 +00:00
John Beppu 59017e80da damnit.
removed mkfifo from the TODO list.

    I didn't implement it, because I realized (too late) that
    mknod already existed, and it can do anything that mkfifo
    would have done.
1999-12-10 08:44:54 +00:00
Eric Andersen cf53687376 Fixed John's email address again.
John.  Your email address is "john@lineo.com" not @line.com. :)
 -Erik
1999-12-10 08:29:20 +00:00
Eric Andersen 2cb55077e2 Added poweroff (and adjusted init to use it). Inlined function
calls to code only called once in tee.  Made BB_KLOGD and option.
 -Erik
1999-12-10 08:25:07 +00:00
John Beppu c5ff0165ad less TODO 1999-12-10 07:48:34 +00:00
John Beppu 3157b1fba9 Implemented head(1).
tried to mimic GNU behaviour.
1999-12-10 07:42:50 +00:00
John Beppu a3e0d7928b changed tee_usage from being a function to a char[]
that gets used be usage();
1999-12-10 07:41:03 +00:00
John Beppu 9835541c54 Fixed bug when dealing with files specified
on the command line that didn't exist.
1999-12-10 07:40:08 +00:00
Eric Andersen 21818c8a80 Make sure the world knows who "beppu" is.
-Erik
1999-12-10 06:48:10 +00:00
Eric Andersen 70e2f0b111 Fix beppu's email address.
BTW, John, go to sleep.  It is late. :)
 -Erik
1999-12-10 06:45:42 +00:00
John Beppu 14c82b64c9 Fleshed out du_main().
I'm not sure which options to support.
1999-12-10 06:15:27 +00:00
John Beppu 2ad2afd05c less TODO 1999-12-10 06:14:28 +00:00
John Beppu 059f152a7a Implemented tee(1). 1999-12-10 05:27:16 +00:00
John Beppu 29fcc90f3e minor changelog update 1999-12-09 23:33:04 +00:00
Eric Andersen 6805d5d69e Adjustments for Johns init stuff,
-Erik
1999-12-09 22:39:55 +00:00
John Beppu f95ca97d1b findInitPid() has been implemented and it seems to work.
reboot has been changed to take advantage of findInitPid();
1999-12-09 22:10:18 +00:00
John Beppu 395b216a2e du is done 1999-12-09 18:37:56 +00:00
John Beppu 7a98606d85 Modified to include du 1999-12-09 18:29:29 +00:00
John Beppu 0f5e1ab949 This is my preliminary
du implementation.  It
    was written from scratch
    (doesn't use recursiveAction).
    I still need to flesh out
    du_main().
1999-12-09 18:23:54 +00:00
Eric Andersen f0758dd6ba * Fixed rebooting from init. I'd left some debugging code in
which blocked reboots.  Oops.
 -Erik
1999-12-09 07:57:58 +00:00
Eric Andersen 1792f8c489 Tail now works (costs 6k). Several other updates.
-Erik
1999-12-09 06:11:36 +00:00
Eric Andersen c24db7b591 Added an empty line for no reason.
-Erik
1999-12-09 01:29:12 +00:00
Eric Andersen 8cd6a1f9a2 Fixed spelling error
-Erik
1999-12-09 01:26:38 +00:00
Eric Andersen 48091fb3d3 * my_getid was leaking file descriptors, causing 'ls -l' on long
directories to fail
 -Erik
1999-12-09 01:15:52 +00:00
Eric Andersen abc0f4f8f9 Latest and greatest 1999-12-08 23:19:36 +00:00
Eric Andersen 2285f367e2 Stuf 1999-12-08 04:23:30 +00:00
Eric Andersen fcdb57a0fc Fixes 1999-12-08 04:13:59 +00:00
Eric Andersen d29edf34d6 Stuf 1999-12-08 04:13:44 +00:00
Eric Andersen 485b9550fd Stuf 1999-12-07 23:14:59 +00:00
Eric Andersen d00c262847 Stuf 1999-12-07 08:37:31 +00:00
Eric Andersen 0ecb54a0f3 Stuf 1999-12-05 23:24:55 +00:00
Eric Andersen 14ec6cf3c2 syslogd and klogd work now.
-Erik
1999-12-05 22:17:02 +00:00
Eric Andersen de1d61268e Fixes 1999-12-03 15:14:25 +00:00
Eric Andersen b186d980d6 Stuf 1999-12-03 09:19:54 +00:00
Eric Andersen 77619b9dda Sqtuf 1999-11-29 04:31:50 +00:00
Eric Andersen bb58702833 Fix up changelog 1999-11-29 04:30:12 +00:00
Eric Andersen 03018f7551 Fixed tar so uid/gud/permissions on extracted tarballs will be correct.
-Erik
1999-11-29 04:29:13 +00:00
Eric Andersen 1667fb4b63 Fixes 1999-11-27 20:34:28 +00:00
Eric Andersen c054b21f7d Stuf 1999-11-27 17:41:29 +00:00
Eric Andersen 4c78147755 Changes 1999-11-26 08:12:56 +00:00
Eric Andersen ec33d45e89 Stuf 1999-11-26 01:51:02 +00:00
Eric Andersen befda6e4ed Stuf 1999-11-25 08:06:22 +00:00
Eric Andersen 3843e96252 Stuf 1999-11-25 07:30:46 +00:00
Eric Andersen b99df0fd65 First draft 1999-11-24 09:04:33 +00:00
Eric Andersen 394f764e7d Stuf 1999-11-23 21:38:12 +00:00
Eric Andersen cb41c2e83b Bug fixes 1999-11-22 07:41:00 +00:00
Eric Andersen 5d44d1fda5 Stuf 1999-11-22 06:01:01 +00:00
Eric Andersen 0f4c0848c7 Fix bugs 1999-11-22 05:57:09 +00:00
Eric Andersen 0727458a97 Stuf 1999-11-21 21:50:07 +00:00
Eric Andersen fa213cd71e Latest n greatest 1999-11-19 06:24:35 +00:00
Eric Andersen e1850ddde4 Stuf 1999-11-19 05:42:32 +00:00
Eric Andersen 6a76e652aa Stuf 1999-11-19 05:31:45 +00:00
Eric Andersen 08b1034f4f Stuf 1999-11-19 02:38:58 +00:00
Eric Andersen ab746abfc0 Stuf 1999-11-18 20:33:45 +00:00
Eric Andersen 1c43d0c5af Stuff 1999-11-18 07:58:07 +00:00
Eric Andersen b052b47722 Forgot this. 1999-11-18 00:21:59 +00:00
Eric Andersen ded6259f62 Latest and greatest 1999-11-18 00:19:26 +00:00
Eric Andersen d80e851dc0 Stuf 1999-11-16 00:46:00 +00:00
Eric Andersen a9c95ea655 Updates 1999-11-15 17:33:30 +00:00
Eric Andersen 80974fad03 Fix makefile 1999-11-13 04:51:47 +00:00
Eric Andersen b6a44b8d39 updates for the day 1999-11-13 04:47:09 +00:00
Eric Andersen eded54bd96 Adjust install a bit... 1999-11-12 08:03:23 +00:00
Eric Andersen 96bcfd346b Latest and greatest
-Erik
1999-11-12 01:30:18 +00:00
Eric Andersen 0dfac6b9ce Stuff 1999-11-11 05:46:32 +00:00
Eric Andersen c296b54827 Stuf 1999-11-11 01:36:55 +00:00
Eric Andersen d73dc5b073 Updates to usage, and made tar work.
-Erik
1999-11-10 23:13:02 +00:00
Eric Andersen 84d8568071 spelling fixes 1999-11-10 20:17:47 +00:00
Eric Andersen 5556c1874b Maybe works now...
-Erik
1999-11-10 19:27:58 +00:00
Eric Andersen 3e2bb288da Stuf 1999-11-09 03:12:29 +00:00
Eric Andersen add0158554 LAtest and greatest 1999-11-09 03:10:26 +00:00
Eric Andersen 3d8dbe1ca0 Stuf 1999-11-09 01:51:02 +00:00
Eric Andersen 50d6360771 Stuff 1999-11-09 01:47:36 +00:00
Eric Andersen fbb39c83b6 Stuff
-Erik
1999-11-08 17:00:52 +00:00
Eric Andersen 07e5297ca7 init and ls -l fixes 1999-11-07 07:38:08 +00:00
Eric Andersen dc6301e7ca Stuf 1999-11-06 07:34:50 +00:00
Eric Andersen 350577c5a0 Minor stuf 1999-11-06 06:34:20 +00:00
Eric Andersen 29d2e362de Fixed ln, df, and removed redundant stuff from mtab. 1999-11-06 06:07:27 +00:00
Eric Andersen bc34190694 Forgot this file... 1999-11-06 04:56:00 +00:00
Eric Andersen f14937d177 Update 1999-11-06 03:02:42 +00:00
Eric Andersen e18c75a563 Fixed init so it won't hang on reboot... 1999-11-05 04:23:05 +00:00
Eric Andersen 9997685953 Changelog fix 1999-11-05 01:21:49 +00:00
Eric Andersen cf8c9cf7b9 More stuff -- ready for release.
-Erik
1999-11-05 00:31:46 +00:00
Eric Andersen d0246fb72b More stuff. 1999-11-04 21:18:07 +00:00
Eric Andersen 3ae0c78962 Stuf 1999-11-04 01:13:21 +00:00
Eric Andersen be971d6b69 More init fixes. Fixed sync segfault.
-Erik
1999-11-03 16:52:50 +00:00
Eric Andersen 219d6f5e0c Stuf 1999-11-02 19:43:01 +00:00
Eric Andersen 2f6c04f63c Ha! Got init working.
-Erik
1999-11-01 23:59:44 +00:00
Eric Andersen ff719d663e Stuf 1999-10-29 23:36:31 +00:00
Eric Andersen 04579780b7 Fixed it. 1999-10-29 23:12:50 +00:00
Eric Andersen 7f1acfdb89 More stuf. sed works. 1999-10-29 23:09:13 +00:00
Eric Andersen 24d8e7d787 Stuf 1999-10-29 06:50:17 +00:00
Eric Andersen c1525e84dd Stuff 1999-10-29 00:07:31 +00:00
Eric Andersen 6b6b3f6ef2 Stuf 1999-10-28 16:06:25 +00:00
Eric Andersen c7c41d306b Cleanup of init 1999-10-28 00:24:35 +00:00
Eric Andersen a745606df3 Stuf 1999-10-27 02:31:32 +00:00
Eric Andersen c8fdb56389 Stuf 1999-10-26 05:21:02 +00:00
Eric Andersen 8a8fbb87f7 Foo 1999-10-26 00:18:56 +00:00
Eric Andersen 0460ff2e5d Stuf 1999-10-25 23:32:44 +00:00
Eric Andersen d143e8f2bd Stuf 1999-10-23 07:09:58 +00:00
Eric Andersen a709317cea More stuff 1999-10-23 05:42:08 +00:00
Eric Andersen a07f0b0408 More stuff. 1999-10-22 19:49:09 +00:00
Eric Andersen 9922c833ca Removed cruft 1999-10-22 18:22:02 +00:00
Eric Andersen fa0540fb09 Make mkdir -m work 1999-10-22 18:18:31 +00:00
Eric Andersen 8eefd021ca Fixed version number 1999-10-22 05:18:28 +00:00
Eric Andersen 51f8c89040 Stuf 1999-10-22 05:14:44 +00:00
Eric Andersen 63a0e530bd Cosmetic adjustments. 1999-10-22 05:12:14 +00:00
Eric Andersen aa0765e11b Added regexp support, fixed Changelog. 1999-10-22 04:30:20 +00:00
Eric Andersen c49960189a Fixed up copyright notices and such 1999-10-20 22:08:37 +00:00
Eric Andersen 887991c78a Fixed 1999-10-20 20:09:47 +00:00
Eric Andersen d23f9ba0f6 Made ps work. Fixed some stuff. 1999-10-20 19:18:15 +00:00
Eric Andersen ef8b6c757d Add a trivial ps command. 1999-10-20 08:05:35 +00:00
Eric Andersen ce8f3b9933 Fixed chmod and friends. 1999-10-20 07:03:36 +00:00
Eric Andersen b9b421c186 Stuf 1999-10-19 23:41:03 +00:00
Eric Andersen b7a1a75261 *** empty log message *** 1999-10-19 23:37:14 +00:00
Eric Andersen f8d650c4e5 More stuff 1999-10-19 23:27:54 +00:00
Eric Andersen f5a3838e2f More stuff 1999-10-19 22:26:25 +00:00
Eric Andersen e674eb78e4 Made em work. 1999-10-19 20:52:57 +00:00
Eric Andersen e494fdd2c7 More stuff 1999-10-19 20:23:03 +00:00
Eric Andersen e77ae3a2c0 Added sfdisk. Ststic-ified a bunch of stuff. 1999-10-19 20:03:34 +00:00
Eric Andersen a3f09076ef More stuff 1999-10-19 16:39:10 +00:00
Eric Andersen 3e0fbae15e fixes grep, added loadfont from debian bootfloppies.
-Erik
1999-10-19 06:02:44 +00:00
Eric Andersen abc7d597cb More stuff 1999-10-19 00:27:50 +00:00
Eric Andersen b0e9a709ba More stuff.
-Erik
1999-10-18 22:28:26 +00:00
Eric Andersen 703c62da63 More stuff 1999-10-18 21:31:00 +00:00
Eric Andersen 8759006b55 More fixes 1999-10-18 21:22:59 +00:00
Eric Andersen 7f04b5e320 Fixed include 1999-10-18 20:41:33 +00:00
Eric Andersen bed30e9700 More fixes 1999-10-18 19:02:32 +00:00
Eric Andersen 9b58718889 Some fixes and such 1999-10-17 05:43:39 +00:00
Eric Andersen cb6e25655f More stuff 1999-10-16 15:48:40 +00:00
Eric Andersen 3c163822d8 Fixed cp -[aR] and some other stuf. 1999-10-14 22:16:57 +00:00
Eric Andersen 2c1030177e More stuff 1999-10-13 22:56:11 +00:00
Eric Andersen f6be944a6a More stuff 1999-10-13 21:12:06 +00:00
Eric Andersen 305a73f5ea Combined stuff 1999-10-13 19:03:24 +00:00
Eric Andersen 1b61f41f57 More stuff 1999-10-13 18:56:42 +00:00
Eric Andersen 21943ce641 More fixes 1999-10-13 18:04:51 +00:00
Eric Andersen c6cb79dedf More stuff 1999-10-13 18:01:10 +00:00
Eric Andersen 5de3065f58 Fixed dd 1999-10-13 00:53:55 +00:00
Eric Andersen 3cf52d1958 More stuff... 1999-10-12 22:26:06 +00:00
Eric Andersen 2ce1edcf54 Latest and greatest.
-Erik
1999-10-12 15:42:48 +00:00
Eric Andersen f811e07b07 More stuff. 1999-10-09 00:25:00 +00:00
Eric Andersen 8341a15653 Finally mount works properly. Made debugging work (no more -s ld flag
when debugging is on).
1999-10-08 17:14:14 +00:00
Eric Andersen 596e5469d0 more stuff 1999-10-07 08:30:23 +00:00
Eric Andersen 5c3199e0a5 Made df work 1999-10-06 22:06:29 +00:00
Eric Andersen 17d49efd8c More stuff. 1999-10-06 20:25:32 +00:00
Eric Andersen 9d3aba7b37 more stuff 1999-10-06 09:04:55 +00:00
Eric Andersen b09c6b5d4a Forgot this file. 1999-10-06 05:21:54 +00:00
Eric Andersen 4bea32abb5 latest and greatest. 1999-10-06 00:30:51 +00:00
Eric Andersen 2b69c40e80 More stuff works.
-Erik
1999-10-05 22:58:32 +00:00
166 changed files with 31906 additions and 10186 deletions

No files matched your search

+1
View File
@@ -1 +1,2 @@
busybox
busybox.links
+268 -1
View File
@@ -1,3 +1,270 @@
0.39
* New Apps: ping and hostname contributed by Randolph Chung
<tausq@debian.org>. 2 items off the TODO list!
* I wrote free (just calls "cat /proc/meminfo").
* Added tail, based on tail from GNU textutils-1.19, but adjusted
to suit my evil purposes. Costs 6k. I'll make it smaller sometime.
* on reboot, init called 'umount -a -n', which caused errors
when BB_MTAB was not enabled. Changed to 'umount -a',
which does the right thing.
* init will now try to run /sbin/getty if it is present (for easy
integration with the about-to-be-released tinylogin.)
* kill now behaves itself properly, added 'kill -l' to list signals
* 'ls -l' was failing on long directories, since my_getid was leaking
one file descriptor per file. Oops.
* Fixed rebooting from init. I'd accidently left some debugging code in
which blocked reboots.
* Fixed reboot, halt (and added poweroff) such that they handle it when
init is not at PID 1 (like when running in an initrd).
* Added a prelinary du implementation. Some parameter parsing
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>)
* Implemented tee. -beppu
* Implemented head. -beppu
-Erik Andrsen, Dec 10, 1999
0.38
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
file existed.
* df will not exit on error, but will stat all mounted filesystems.
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
* Fixed find -name so it properly uses shell wildcard patterns
(i.e. `*', `?', and `[]') instead of regular expressions, which
was causing some confusing and unexpected behavior.
* Added klogd to syslogd, so now the log will contain both system and
kernel messages.
* syslogd now creates the /dev/log socket to make sure it is there, and
is actually a socket with the right permissions.
* I've taken a first step to making busybox not need the /proc
filesystem. Most apps don't need it. Those that _require_ it,
will complain if you enable them when you disable
BB_FEATURE_USE_PROCFS.
-Erik Andrsen, Dec 5, 1999
0.37
* Wrote a micro syslogd, and a logger util (to log things to the syslog
from the command line or scripts) With both compiled in, costs 4k.
* Fixed 'make install' so symlinks are installed in their proper locations.
* Changed the build system slightly so that features can now be enabled
or disabled from the busybox.defs.h header file, without trying to
compile in a source file named after that featue (unless that file exists).
* Several options are now moved into busybox.defs.h
* Now 'rm -R' and 'rm -r' both work.
* dd now properly handles input beyond 1 block from stdin.
* Fixed a bug where tar unpacked everything a directories. Moved some code
from createPath into mkdir where it belonged, thereby making tar work properly.
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat out the
last file in the list.
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed 'ls -l'
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid are
presented properly.
* Also added a TODO.
-Erik Andrsen, Nov 25, 1999
0.36
* fixed dd so it properly defaults to stdin and stdout when no
if= and of= are set (fix thanks to Eric Delaunay).
* Don't try to close the file descriptor of a pipein tar. (fix also from
Eric Delaunay).
* Made createPath be quiet (again thanks to Eric Delaunay).
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
command you define it as will be run if the init script exits.
* Updated install.sh to make it more robust (thanks to Adam Di Carlo)
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled
in, but that is still a big win for those that use NFS.
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay).
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise
and acts as god intended gunzip and zcat to act. They answer --help and
obey the '-c' flag.
* Fixed a bug in mv which caused it to not move files when the destination
was a directory.
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories
with very wrong permissions.
* chmod would overwrite file permissions instead of modifying them.
Now it properly modifies permissions.
* Init now sends warnings destined for the console to /dev/console to ensure
they show up on whatever the active console it. Otherwise important
messages (for example that the system is rebooting) were not seen when
switched to a different VT.
-Erik Andersen, Nov 17, 1999
0.35
* gzip now obeys the principle of least surprise and acts like god intended
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag
and only then outputs to stdout).
* Fixed more.c to compile autowidth on sparc and set initial winsize
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay.
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
* tar now accepts --help
* chmod, chown, and chgrp usage now works
* General usage (i.e. --help) cleanups for most apps
* umount now parses options correctly
* tar can now unpack tarballs containing device special files,
sockets, and fifos (though it can't pack them up) thanks
to Matt Porter. Creating archives containing these is still
left to the interested student.
* fixed up the license in more.c to properly point to Bruce Perens.
-Erik Andersen, Nov 11, 1999
0.34
* ls -l now displays link names outside the current directory,
Patch thanks to Eric Delaunay
* init now properly handles sparc serial consoles and does a
better job of finding the real console device rather than using
/dev/console which doesn't support job control. Patch also
thanks to Eric Delaunay.
* more started to read from stdin after the last file was finished, and
options were not parsed correctly (fix thanks to Eric Delaunay).
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
* rm wouldn't remove a symlink unless the symlink was valid. This was
a side effect of the busybox 0.32 recursiveAction() fix. Things
should now work correctly.
* grep wouldn't grep stdin. Now it does.
* sed wouldn't sed stdin. Now it does.
* sed was appending a \n to the end of lines with replacements.
Now it doesn't do that.
* ls -l now bypasses libc6 nss when displaying user/group names.
Now uses my_getpwuid and my_getgrgid.
-Erik Andersen, Nov 8, 1999
0.33
* Fixed a bug where init could hang instead of rebooting.
* Removed some debugging noise from init.c
* Fixed ln so it works now (it was very broken).
* Fixed df so it won't segfault when there is no /etc/fstab,
* If BB_MTAB is not defined, df and mount will whine if /etc/fstab
is not installed (since they cannot fixup "/dev/root" to
state the real root device name)
* merged some redundant code from mtab.c/df.c into utility.c
-Erik Andersen, Nov 5, 1999
0.32
* More changes -- many thanks to Lineo for paying me to work on
busybox. If you have any problems please let me know ASAP
at andersen@lineo.com or andersee@debian.org
* usage() now prints the BusyBox version. This will help folks
realize that they are not in Kansas anymore.
* Fixed mkdir -m option so that it works.
* kill segfaulted w/o any arguments. Now it doesn't do that.
* kill wasn't properly accepting signal names. It does now.
* Added new apps chvt and deallocvt (I should probably add open)
* Major rewrite of init.c. Code is now readable by mere mortals IMHO.
* Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!).
* Fixed a stupid seg-fault in sync
* Fixed mount -- mount -a failed to parse and apply mount options
* Fixed umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
* umount -a no longer umounts /proc
* Added BB_MTAB, allowing (at the cost of ~1.5k and the need for a rw /etc)
folks to use a real /etc/mtab file instead of a symlink to /proc/mounts.
mount, and umount will add/remove entries and df will now use /etc/mtab
if BB_MTAB is defined.
* Fixed a nice bug in recursiveAction() which caused it to infinitely
hunt through /proc/../fd/* creating new file descriptors if it
followed the /dev/fd link over to /proc. recursiveAction() now
lstat's the file when followLinks==FALSE so it won't follow links
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>.
-Erik Andersen, Nov 4, 1999
0.31
* I added a changelog for version 0.30.
* adjusted find internals to make it smaller, and removed
some redundancy.
* Fixed a segfault in ps when /etc/passwd or /etc/group
are absent. Now will warn you and carry on.
* Added in optional _real_ regular expression support (to be
the basis for a future sed utility). When compiled in
it adds 3.9k, but makes grep much more capable.
* Checked out using nftw(3) for recursive stuff, but unfortunatly
it wasn't supported before GNU libc 2.1, and some folks use
glibc 2.0.7 since it is much smaller than that latest and greatest.
-Erik Andersen, Oct 21, 1999
0.30
Major changes -- lots of stuff rewritten. Many thanks to Lineo for
paying me to make these updates. If you have any problems with busybox,
or notice any bugs -- please let me know so I can fix it. These
changes include:
Core Changes:
* busybox can now invoke apps in two ways: via symlinks to the
busybox binary, and as 'busybox [function] [arguments]...'
* When invoked as busybox, the list of currently compiled in
functions is printed out (no this is not bloat -- the list
has to be there anyway to map invocation name to function).
* busybox no longer parses command lines for apps or displays their
usage info. Each app gets to handle (or not handle) this for
itself.
* Eliminated monadic, dyadic, descend, block_device, and
postprocess. It was cumbersome to have so many programs
cobbled together in this way. Without them, the app is much
more granular.
* All shared code now lives in utility.c, and is properly
ifdef'ed to be only included for those apps requiring it.
* Eliminated struct FileInfo (the basis of monadic, dyadic, etc)
so now each app has the function prototype of (da-dum):
extern int foo_main(int argc, char** argv);
which speeds integration of new apps.
* Adjusted the Makefile to make it easier to
{en|dis}able debugging.
* Changed default compiler optimization to -Os
(optimize for smaller binaries).
App Changes:
* To cope with the new app function prototype and the removal of
monadic, dyadic, etc, the following apps were re-written:
* cat - Works same as always.
* chgrp, chmod, chown - rewrite. Combined into a single
source file. Absorbed patches from Enrique Zanardi <ezanard@debian.org>
that removes the dependency on libc6 libnss* libraries.
* cp - Can now do 'cp -a' can can copy devices,
pipes, symlinks, as well as recursive or non-recursive dir copies.
* fdflush - adjusted to remove dependancy on struct FileInfo.
* find - Now includes some basic regexp matching
which will be the basic of a future mini-sed.
* ln - Same functionality.
* mkdir - Added -p flag to feature set.
* mv - rewrite.
* rm - Added -f flag to feature set.
* rmdir - Same functionality.
* swapon, swapoff - Combined into a single binary. No longer
uses /etc/swaps. swap{on|off} -a uses /etc/fstab instead.
* touch - Same functionality.
* date - adjusted with a patch from Matthew Grant <grantma@anathoth.gen.nz>
to accomodate glibc timezone support. I then ripped out GNU getopt.
* mkswap -- new version merged from util-linux. Can now make >128Meg swaps.
* Replaced the old and star, unstar, and tarcat with the tar
implementation from sash. Now tar behaves as god intended
it to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
* dd -- rewritten. Can with with files, stdin, stdout.
* Added the following new apps:
* loadfont -- added from debian boot floppies
* chroot -- added based on a patch from Paolo Molaro <lupus@lettere.unipd.it>
* grep -- I just wrote it. Only matches simple strings
* ps -- I just wrote it. Has _no_ options at all, but works.
* fsck_minix, mkfs_minix -- added from util-linux, but I ripped out
internationalization and such to make them smaller.
* sfdisk -- Added from util-linux (minus internationalization and such).
* Probably some other changes that I forgot to document...
-Erik Andersen, Oct 20, 1999
0.29
This version was a messy pre-alpha. stay away or it will bite you.
-Erik Andersen, Sep 24, 1999
0.28
mini-netcat (mnc) rewritten.
0.27
Mount now supports -a, and -t auto.
Mount now updates mtab correctly for 'ro'.
@@ -5,4 +272,4 @@
Printf added as module.
0.26
Touch now creates files. -c option for no create.
+357 -3
View File
@@ -17,8 +17,362 @@ Copyright 1998 Dave Cinege <dcinege@psychosis.com>
mini-gzip(gzip), mini-netcat(mnc)
Copyright 1998 Charles P. Wright <cpwright@villagenet.com>
Tons of new stuff as noted in header files
Copyright (C) 1999 by Lineo, inc. and written by
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
Please see the top of the source files for more precise indivigual
copyright and license info.
This program suite may be distributed under the GNU General Public License.
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
Busybox may be used and distributed under the GNU General Public License.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
+93 -18
View File
@@ -1,38 +1,113 @@
# Makefile for busybox
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
VERSION=0.29alpha1
PROG=busybox
VERSION=0.39
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
# Comment out the following to make a debuggable build
# Leave this off for production use.
DODEBUG=false
# If you want a static binary, turn this on. I can't think
# of many situations where anybody would ever want it static,
# but...
DOSTATIC=false
#This will choke on a non-debian system
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
GCCMAJVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\1/p"`
GCCMINVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\2/p"`
STRIP= strip --remove-section=.note --remove-section=.comment busybox
LDFLAGS= -s
GCCSUPPORTSOPTSIZE=$(shell \
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
if ( test $(GCCMINVERSION) -ge 91 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
else \
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
fi; )
ifeq ($(GCCSUPPORTSOPTSIZE), true)
OPTIMIZATION=-Os
else
OPTIMIZATION=-O2
endif
# -D_GNU_SOURCE is needed because environ is used in init.c
CFLAGS=-Wall -O2 -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
# For debugging only
#CFLAGS=-Wall -g -D_GNU_SOURCE
LIBRARIES=-lc
OBJECTS=$(shell ./busybox.obj) utility.o
ifeq ($(DODEBUG),true)
CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
STRIP=
LDFLAGS=
else
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS= -s
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
#Only staticly link when _not_ debugging
ifeq ($(DOSTATIC),true)
LDFLAGS+= --static
endif
endif
ifndef $(PREFIX)
PREFIX=`pwd`/_install
endif
LIBRARIES=
OBJECTS=$(shell ./busybox.sh)
CFLAGS+= -DBB_VER='"$(VERSION)"'
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
ifdef BB_INIT_RC_EXIT_CMD
CFLAGS += -DBB_INIT_CMD_IF_RC_SCRIPT_EXITS=${BB_INIT_RC_EXIT_CMD}
endif
#all: busybox links
all: busybox
all: busybox busybox.links
busybox: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o busybox $(OBJECTS) $(LIBRARIES)
#$(STRIP)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
$(STRIP)
busybox.links:
- ./busybox.mkll | sort >$@
links:
- ./busybox.mkll | sort >busybox.links
clean:
- rm -f busybox busybox.links *~ *.o
- rm -f $(PROG) busybox.links *~ *.o core
- rm -rf _install
distclean: clean
- rm -f busybox
- rm -f $(PROG)
$(OBJECTS): busybox.def.h internal.h Makefile
install: busybox busybox.links
./install.sh $(PREFIX)
dist: release
release: distclean
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
force:
+23 -20
View File
@@ -1,27 +1,30 @@
Please see the LICENSE file for copyright information.
Busybox is a multicall binary used to provide a minimal subset of
POSIX style commands and specialized functions.
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a working system.
Busybox was begun to support the Debian Rescue/Install disks, but it
also makes an excellent environment for any small or embedded system.
It is geared toward 'mini-systems' like boot floppies. Specifically
it is used in the Debian Rescue/Install system (which caused the
original busybox to be made), the Linux Router Project, and others.
As of version 0.20 there is a version number. : ) Also as of version
0.20, BB is now modularized to easily allow you to build of only the
BB parts you need, thereby reducing binary size. To turn off unwanted
Busybox components, simply edit the file busybox.def.h and comment out
the parts you do not need using C++ style (//) comments.
As of version 0.20 there is a version number. : )
Also as of version 0.20, BB is modularized to allow an easy build of
only the BB parts you need, to reduce binary size.
After the build is complete a busybox.links file is generated which is
then used by 'make install' to create symlinks to the busybox binary
for all compiled in functions. By default, 'make install' will place
the symlink forest into `pwd`/_install unless you have defined the
PREFIX environment variable.
Edit the file busybox.def.h and comment out the parts you do not need
using C++ comments (//)
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
After the build is complete a busybox.links file is generated to allow
you to easily make the sym/hard links to the busybox binary.
<blatent plug>
Many thanks to go to Lineo for paying me to work on busybox.
</blatent plug>
Note the modular system is Makefile based, and purposly very
simplistic. It does no dependency checking. That is left for you
to figure out by trial and error.
Please feed patches back to:
Dave Cinege <dcinege@psychosis.com>
and:
Enrique Zanardi <ezanardi@ull.es>
+27
View File
@@ -0,0 +1,27 @@
TODO list for busybox in no particular order. Just because something
is listed here doesn't mean that it is going to be added to busybox,
or that doing so is even a good idea. It just means that I _might_ get
around to it some time. If you have any good ideas, please let me know.
-Erik
-----------
* Allow tar to create archives with sockets, devices, and other special files
* Add in a mini insmod, rmmod, lsmod
* init clearly needs to support some type of minimalist /etc/inittab. I
currently have _way_ too much policy hardcoded in the source. Adding
support for getty has made me realize how much that sucks.
* dnsdomainname
* traceroute/nslookup/netstat
* rdate
* hwclock
* killall
* stty
* sort/uniq
* wc
* tr
* expr (maybe?) (ash builtin?)
* login/sulogin/passwd/getty (These are actully now part of tinylogin, which
I've just started to maintain).
+104 -55
View File
@@ -14,16 +14,12 @@ static const struct Applet applets[] = {
{"block_device", block_device_main},
#endif
#ifdef BB_CAT //bin
{"cat", cat_more_main},
{"cat", cat_main},
#endif
#ifdef BB_CHGRP //bin
{"chgrp", chgrp_main},
#endif
#ifdef BB_CHMOD //bin
{"chmod", chmod_main},
#endif
#ifdef BB_CHOWN //bin
{"chown", chown_main},
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
{"chmod", chmod_chown_chgrp_main},
{"chown", chmod_chown_chgrp_main},
{"chgrp", chmod_chown_chgrp_main},
#endif
#ifdef BB_CHROOT //sbin
{"chroot", chroot_main},
@@ -31,8 +27,11 @@ static const struct Applet applets[] = {
#ifdef BB_CLEAR //usr/bin
{"clear", clear_main},
#endif
#ifdef BB_CHVT //usr/bin
{"chvt", chvt_main},
#endif
#ifdef BB_CP //bin
{"cp", dyadic_main},
{"cp", cp_main},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
@@ -46,27 +45,48 @@ static const struct Applet applets[] = {
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", cat_more_main},
#ifdef BB_DU //bin
{"du", du_main},
#endif
#ifdef BB_FALSE //bin
{"false", false_main},
#ifdef BB_DUTMP //usr/sbin
{"dutmp", dutmp_main},
#endif
#ifdef BB_FDFLUSH //bin
{"fdflush", monadic_main},
{"fdflush", fdflush_main},
#endif
#ifdef BB_FIND //usr/bin
{"find", find_main},
#endif
#ifdef BB_FREE //usr/bin
{"free", free_main},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#endif
#ifdef BB_FSCK_MINIX //sbin
{"fsck.minix", fsck_minix_main},
#endif
#ifdef BB_MKFS_MINIX //sbin
{"mkfs.minix", mkfs_minix_main},
#endif
#ifdef BB_GREP //bin
{"grep", grep_main},
#endif
#ifdef BB_HALT //sbin
{"halt", halt_main},
#endif
#ifdef BB_HEAD //bin
{"head", head_main},
#endif
#ifdef BB_HOSTNAME //bin
{"hostname", hostname_main},
#endif
#ifdef BB_INIT //sbin
{"init", init_main},
#endif
#ifdef BB_FEATURE_LINUXRC //
{"linuxrc", init_main},
#endif
#ifdef BB_KILL //bin
{"kill", kill_main},
#endif
@@ -74,14 +94,14 @@ static const struct Applet applets[] = {
{"length", length_main},
#endif
#ifdef BB_LN //bin
{"ln", dyadic_main},
{"ln", ln_main},
#endif
#ifdef BB_LOADFONT //usr/bin
{"loadfont", loadfont_main},
#endif
#ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main},
#endif
#ifdef BB_LOSETUP //sbin
{"losetup", losetup_main},
#endif
#ifdef BB_LS //bin
{"ls", ls_main},
#endif
@@ -92,7 +112,7 @@ static const struct Applet applets[] = {
{"math", math_main},
#endif
#ifdef BB_MKDIR //bin
{"mkdir", monadic_main},
{"mkdir", mkdir_main},
#endif
#ifdef BB_MKNOD //bin
{"mknod", mknod_main},
@@ -104,7 +124,7 @@ static const struct Applet applets[] = {
{"mnc", mnc_main},
#endif
#ifdef BB_MORE //bin
{"more", cat_more_main},
{"more", more_main},
#endif
#ifdef BB_MOUNT //bin
{"mount", mount_main},
@@ -113,11 +133,20 @@ static const struct Applet applets[] = {
{"mt", mt_main},
#endif
#ifdef BB_MV //bin
{"mv", dyadic_main},
{"mv", mv_main},
#endif
#ifdef BB_PING //bin
{"ping", ping_main},
#endif
#ifdef BB_POWEROFF //sbin
{"poweroff", poweroff_main},
#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#endif
#ifdef BB_PS //bin
{"ps", ps_main},
#endif
#ifdef BB_PWD //bin
{"pwd", pwd_main},
#endif
@@ -128,38 +157,59 @@ static const struct Applet applets[] = {
{"rm", rm_main},
#endif
#ifdef BB_RMDIR //bin
{"rmdir", monadic_main},
{"rmdir", rmdir_main},
#endif
#ifdef BB_SFDISK //sbin
{"fdisk", sfdisk_main},
{"sfdisk", sfdisk_main},
#endif
#ifdef BB_SED //bin
{"sed", sed_main},
#endif
#ifdef BB_SLEEP //bin
{"sleep", sleep_main},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_SWAPOFF //sbin
{"swapoff", monadic_main},
#endif
#ifdef BB_SWAPON //sbin
{"swapon", monadic_main},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", monadic_main},
#ifdef BB_SYSLOGD //sbin
{"syslogd", syslogd_main},
#endif
#ifdef BB_TRUE //bin
#ifdef BB_LOGGER //usr/bin
{"logger", logger_main},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#endif
#ifdef BB_TAIL //usr/bin
{"tail", tail_main},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_TEE //bin
{"tee", tee_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
{"umount", umount_main},
#endif
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_ZCAT //bin
{"zcat", zcat_main},
{"gunzip", zcat_main},
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
@@ -191,40 +241,39 @@ int main(int argc, char **argv)
}
a++;
}
return (busybox_main(argc, argv));
exit (busybox_main(argc, argv));
}
int busybox_main(int argc, char **argv)
{
int col=0;
argc--;
argv++;
/* If we've already been here once, exit now */
if (been_there_done_that == 1)
return -1;
been_there_done_that = 1;
if (argc < 1) {
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
if (a->name != 0) {
fprintf(stderr, "%s", a->name);
a++;
}
while (a->name != 0) {
fprintf(stderr, ", %s", a->name);
a++;
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;
}
}
fprintf(stderr, "\n\n");
exit(-1);
} else
} else {
/* If we've already been here once, exit now */
been_there_done_that = 1;
return (main(argc, argv));
}
}
+7 -9
View File
@@ -2,16 +2,14 @@
#Make busybox links list file
DF="busybox.def.h"
MF="main.c"
MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
for def in ${LIST}; do
set -- $(sed -n '/^#ifdef '$def'[ +| +].*/,/^#endif/{s/.*\/\///p; /^{ /{ s/^{ "//; s/",.*$//p;}; }' $MF)
path=$1; shift
for n in $@; do
echo "$path/$n"
done
for def in ${LIST}; do
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
for k in $j; do
echo $i$k
done
done
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
set -e
if [ "$1" == "" ]; then
echo "No installation directory, aborting."
exit 1;
fi
h=`sort busybox.links | uniq`
for i in $h ; do
echo " $1$i -> /bin/busybox"
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
ln -fs /bin/busybox $1$i
done
rm -f $1/bin/busybox
install -m 755 busybox $1/bin/busybox
exit 0
+125 -57
View File
@@ -4,11 +4,11 @@
#include "internal.h"
const char zcat_usage[] = "zcat\n"
"\n"
"\tuncompress gzipped data from stdin to stdout\n";
static const char gunzip_usage[] =
"gunzip [OPTION]... FILE\n\n"
"Uncompress FILE (or standard input if FILE is '-').\n\n"
"Options:\n"
"\t-c\tWrite output to standard output\n";
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
* Copyright (C) 1992-1993 Jean-loup Gailly
@@ -58,10 +58,6 @@ static char *license_msg[] = {
* For the meaning of all compilation flags, see comments in Makefile.in.
*/
#ifdef RCSID
static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <sys/types.h>
#include <signal.h>
@@ -80,8 +76,6 @@ static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
#define RECORD_IO 0
#define get_char() get_byte()
@@ -226,9 +220,6 @@ extern long bytes_in; /* number of input bytes */
extern long bytes_out; /* number of output bytes */
extern long header_bytes;/* number of bytes in gzip header */
extern int ifd; /* input file descriptor */
extern int ofd; /* output file descriptor */
extern long ifile_size; /* input file size, -1 for devices (debug only) */
typedef int file_t; /* Do not use stdio */
@@ -268,7 +259,6 @@ extern int exit_code; /* program exit code */
extern int verbose; /* be verbose (-v) */
extern int level; /* compression level */
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -436,8 +426,6 @@ extern int unlzw OF((int in, int out));
# undef LZW
#endif
/* $Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
/* #include "getopt.h" */
/* Declarations for getopt.
@@ -689,18 +677,48 @@ long header_bytes; /* number of bytes in gzip header */
/* local functions */
local void treat_stdin OF((void));
local int get_method OF((int in));
local void do_exit OF((int exitcode));
int main OF((int argc, char **argv));
int (*work) OF((int infile, int outfile)) = unzip; /* function to call */
local void do_exit(int exitcode) __attribute__ ((noreturn));
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
int zcat_main (struct FileInfo * i, int argc, char * * argv)
int gunzip_main (int argc, char** argv)
{
int file_count; /* number of files to precess */
int to_stdout = 0;
int fromstdin = 0;
int result;
int inFileNum;
int outFileNum;
int delInputFile=0;
struct stat statBuf;
char* delFileName;
char ifname[MAX_PATH_LEN]; /* input file name */
char ofname[MAX_PATH_LEN]; /* output file name */
if (argc==1)
usage(gunzip_usage);
if (strcmp(*argv, "zcat")==0)
to_stdout = 1;
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromstdin = 1;
to_stdout = 1;
}
while (*(++(*argv))) {
switch (**argv) {
case 'c':
to_stdout = 1;
break;
default:
usage(gunzip_usage);
}
}
}
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
@@ -731,31 +749,90 @@ int zcat_main (struct FileInfo * i, int argc, char * * argv)
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
/* And get to work */
treat_stdin();
if (fromstdin==1) {
strcpy(ofname, "stdin");
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
inFileNum=fileno(stdin);
ifile_size = -1L; /* convention for unknown size */
} else {
/* Open up the input file */
if (*argv=='\0')
usage(gunzip_usage);
strncpy(ifname, *argv, MAX_PATH_LEN);
/* ========================================================================
* Compress or decompress stdin
*/
local void treat_stdin()
{
ifile_size = -1L; /* convention for unknown size */
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
method = get_method(ifd);
if (method < 0) {
do_exit(exit_code); /* error message already emitted */
/* Open input fille */
inFileNum=open( ifname, O_RDONLY);
if (inFileNum < 0) {
perror(ifname);
do_exit(WARNING);
}
/* Get the time stamp on the input file. */
result = stat(ifname, &statBuf);
if (result < 0) {
perror(ifname);
do_exit(WARNING);
}
ifile_size = statBuf.st_size;
}
(*work)(fileno(stdin), fileno(stdout));
if (to_stdout==1) {
/* And get to work */
strcpy(ofname, "stdout");
outFileNum=fileno(stdout);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
unzip(inFileNum, outFileNum);
} else {
char* pos;
/* And get to work */
strncpy(ofname, ifname, MAX_PATH_LEN-4);
pos=strstr(ofname, ".gz");
if (pos != NULL) {
*pos='\0';
delInputFile=1;
} else {
pos=strstr(ofname, ".tgz");
if (pos != NULL) {
*pos='\0';
strcat( pos, ".tar");
delInputFile=1;
}
}
/* Open output fille */
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
if (outFileNum < 0) {
perror(ofname);
do_exit(WARNING);
}
/* Set permissions on the file */
fchmod(outFileNum, statBuf.st_mode);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
result=unzip(inFileNum, outFileNum);
close( outFileNum);
close( inFileNum);
/* Delete the original file */
if (result == OK)
delFileName=ifname;
else
delFileName=ofname;
if (delInputFile == 1 && unlink (delFileName) < 0) {
perror (delFileName);
exit( FALSE);
}
}
do_exit(exit_code);
}
@@ -803,7 +880,6 @@ local int get_method(in)
exit_code = ERROR;
return -1;
}
work = unzip;
flags = (uch)get_byte();
(ulg)get_byte(); /* Ignore time stamp */
@@ -894,10 +970,6 @@ RETSIGTYPE abort_gzip()
either deflated or stored.
*/
#ifdef RCSID
static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* #include "crypt.h" */
/* crypt.h (dummy version) -- do not perform encryption
@@ -952,6 +1024,10 @@ int unzip(in, out)
ifd = in;
ofd = out;
method = get_method(ifd);
if (method < 0) {
do_exit(exit_code); /* error message already emitted */
}
updcrc(NULL, 0); /* initialize crc */
@@ -1020,10 +1096,6 @@ int unzip(in, out)
* terms of the GNU General Public License, see the file COPYING.
*/
#ifdef RCSID
static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
@@ -1041,7 +1113,7 @@ static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
extern int errno;
#endif
extern ulg crc_32_tab[]; /* crc table, defined below */
static const ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
* Run a set of bytes through the crc shift register. If s is a NULL
@@ -1255,7 +1327,7 @@ voidp xmalloc (size)
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by makecrc.c)
*/
ulg crc_32_tab[] = {
static const ulg crc_32_tab[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
@@ -1407,10 +1479,6 @@ ulg crc_32_tab[] = {
the two sets of lengths.
*/
#ifdef RCSID
static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <sys/types.h>
#if defined(STDC_HEADERS) || !defined(NO_STDLIB_H)
+113 -62
View File
@@ -7,11 +7,17 @@
#include "internal.h"
#ifdef BB_GZIP
#ifndef BB_ZCAT
error: you need zcat to have gzip support!
#endif
//#ifndef BB_ZCAT
//#error you need zcat to have gzip support!
//#endif
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"When FILE is -, reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
/* gzip.h -- common declarations for all gzip modules
* Copyright (C) 1992-1993 Jean-loup Gailly.
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
extern int verbose; /* be verbose (-v) */
extern int quiet; /* be quiet (-q) */
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
#define WARN(msg) {if (!quiet) fprintf msg ; \
if (exit_code == OK) exit_code = WARNING;}
local void do_exit(int exitcode);
local void do_exit(int exitcode) __attribute__ ((noreturn));
/* in zip.c: */
extern int zip OF((int in, int out));
@@ -380,7 +385,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# undef LZW
#endif
/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
/* tailor.h -- target dependent definitions
* Copyright (C) 1992-1993 Jean-loup Gailly.
* This is free software; you can redistribute it and/or modify it under the
@@ -391,7 +395,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -766,10 +769,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# include <stdio.h>
#endif
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Local data used by the "bit string" routines.
*/
@@ -975,10 +974,6 @@ void copy_block(buf, len, header)
#include <stdio.h>
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Configuration parameters
*/
@@ -1591,10 +1586,6 @@ ulg deflate()
* For the meaning of all compilation flags, see comments in Makefile.in.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <sys/types.h>
#include <signal.h>
@@ -1740,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
/* local variables */
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
int decompress = 0; /* decompress (-d) */
int no_name = -1; /* don't save or restore the original file name */
int no_time = -1; /* don't save or restore the original file time */
@@ -1772,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
/* local functions */
local void treat_stdin OF((void));
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
// int main (argc, argv)
// int argc;
// char **argv;
int gzip_main(struct FileInfo * i, int argc, char * * argv)
int gzip_main(int argc, char ** argv)
{
int result;
int inFileNum;
int outFileNum;
struct stat statBuf;
char* delFileName;
int tostdout = 0;
int fromstdin = 0;
if (argc==1)
usage(gzip_usage);
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromstdin = 1;
tostdout = 1;
}
while (*(++(*argv))) {
switch (**argv) {
case 'c':
tostdout = 1;
break;
default:
usage(gzip_usage);
}
}
}
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
(void) signal (SIGINT, (sig_type)abort_gzip);
@@ -1801,8 +1816,6 @@ int gzip_main(struct FileInfo * i, int argc, char * * argv)
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
z_len = strlen(z_suffix);
to_stdout = 1;
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
@@ -1815,33 +1828,84 @@ int gzip_main(struct FileInfo * i, int argc, char * * argv)
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
/* And get to work */
treat_stdin();
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
if (fromstdin==1) {
strcpy(ofname, "stdin");
/* ========================================================================
* Compress or decompress stdin
*/
local void treat_stdin()
{
inFileNum=fileno(stdin);
time_stamp = 0; /* time unknown by default */
ifile_size = -1L; /* convention for unknown size */
} else {
/* Open up the input file */
if (*argv=='\0')
usage(gzip_usage);
strncpy(ifname, *argv, MAX_PATH_LEN);
/* Open input fille */
inFileNum=open( ifname, O_RDONLY);
if (inFileNum < 0) {
perror(ifname);
do_exit(WARNING);
}
/* Get the time stamp on the input file. */
result = stat(ifname, &statBuf);
if (result < 0) {
perror(ifname);
do_exit(WARNING);
}
time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size;
}
if (tostdout==1) {
/* And get to work */
strcpy(ofname, "stdout");
outFileNum=fileno(stdout);
SET_BINARY_MODE(fileno(stdout));
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
/* Get the time stamp on the input file. */
time_stamp = 0; /* time unknown by default */
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
ifile_size = -1L; /* convention for unknown size */
/* Actually do the compression/decompression. */
zip(inFileNum, outFileNum);
clear_bufs(); /* clear input and output buffers */
to_stdout = 1;
part_nb = 0;
} else {
/* Actually do the compression/decompression. Loop over zipped members.
*/
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
/* And get to work */
strncpy(ofname, ifname, MAX_PATH_LEN-4);
strcat(ofname, ".gz");
/* Open output fille */
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
if (outFileNum < 0) {
perror(ofname);
do_exit(WARNING);
}
SET_BINARY_MODE(outFileNum);
/* Set permissions on the file */
fchmod(outFileNum, statBuf.st_mode);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
result=zip(inFileNum, outFileNum);
close( outFileNum);
close( inFileNum);
/* Delete the original file */
if (result == OK)
delFileName=ifname;
else
delFileName=ofname;
if (unlink (delFileName) < 0) {
perror (delFileName);
exit( FALSE);
}
}
do_exit(exit_code);
}
/* ========================================================================
@@ -1924,10 +1988,6 @@ local void do_exit(int exitcode)
#include <ctype.h>
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Constants
*/
@@ -2942,10 +3002,6 @@ local void set_file_type()
* terms of the GNU General Public License, see the file COPYING.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
@@ -2963,8 +3019,6 @@ static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
extern int errno;
#endif
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
* Copy input to output unchanged: zcat == cat with --force.
* IN assertion: insize bytes have already been read in inbuf.
@@ -3141,10 +3195,6 @@ void display_ratio(num, den, file)
* terms of the GNU General Public License, see the file COPYING.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <sys/types.h>
@@ -3176,6 +3226,7 @@ int zip(in, out)
/* Write the header to the gzip file. See algorithm.doc for the format */
method = DEFLATED;
put_byte(GZIP_MAGIC[0]); /* magic header */
put_byte(GZIP_MAGIC[1]);
+883 -1098
View File
File diff suppressed because it is too large. Load diff
-64
View File
@@ -1,64 +0,0 @@
#include "internal.h"
#include <dirent.h>
#include <string.h>
#include <stdio.h>
const char block_device_usage[] = "block_device mount-point";
static dev_t *my_device;
static char *my_device_name;
int
match_mount(const struct FileInfo * i) {
if ( S_ISBLK(i->stat.st_mode)
&& (i->stat.st_rdev == *my_device)) {
my_device_name=strdup(i->source);
return 1;
} else
return 0;
}
extern int
block_device_main(struct FileInfo * i, int argc, char * * argv)
{
char *device_name = block_device(argv[1],i);
if ( device_name == NULL )
return -1;
printf("%s\n", device_name);
exit(0);
}
char * block_device(const char *name, struct FileInfo *i)
{
struct stat s;
char *buf;
int dinam=0;
if ( stat(name, &s) ) return (char *) NULL;
if (!i) {
i=(struct FileInfo*)malloc(sizeof(struct FileInfo));
dinam = 1;
}
memset((void *)i, 0, sizeof(struct FileInfo));
my_device=(dev_t *)malloc(sizeof(dev_t));
*my_device = s.st_dev;
my_device_name = NULL;
i->source = "/dev";
i->stat = s;
i->processDirectoriesAfterTheirContents=1;
descend(i, match_mount);
if (dinam) free(i);
if ( my_device_name ) {
buf = strdup(my_device_name);
free(my_device);
free(my_device_name);
return buf;
} else {
fprintf( stderr
,"Can't find special file for block device %d, %d.\n"
,(int) *my_device >> 8 & 0xff
,(int) *my_device & 0xff);
free(my_device);
return (char *) NULL;
}
}
+104 -55
View File
@@ -14,16 +14,12 @@ static const struct Applet applets[] = {
{"block_device", block_device_main},
#endif
#ifdef BB_CAT //bin
{"cat", cat_more_main},
{"cat", cat_main},
#endif
#ifdef BB_CHGRP //bin
{"chgrp", chgrp_main},
#endif
#ifdef BB_CHMOD //bin
{"chmod", chmod_main},
#endif
#ifdef BB_CHOWN //bin
{"chown", chown_main},
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
{"chmod", chmod_chown_chgrp_main},
{"chown", chmod_chown_chgrp_main},
{"chgrp", chmod_chown_chgrp_main},
#endif
#ifdef BB_CHROOT //sbin
{"chroot", chroot_main},
@@ -31,8 +27,11 @@ static const struct Applet applets[] = {
#ifdef BB_CLEAR //usr/bin
{"clear", clear_main},
#endif
#ifdef BB_CHVT //usr/bin
{"chvt", chvt_main},
#endif
#ifdef BB_CP //bin
{"cp", dyadic_main},
{"cp", cp_main},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
@@ -46,27 +45,48 @@ static const struct Applet applets[] = {
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", cat_more_main},
#ifdef BB_DU //bin
{"du", du_main},
#endif
#ifdef BB_FALSE //bin
{"false", false_main},
#ifdef BB_DUTMP //usr/sbin
{"dutmp", dutmp_main},
#endif
#ifdef BB_FDFLUSH //bin
{"fdflush", monadic_main},
{"fdflush", fdflush_main},
#endif
#ifdef BB_FIND //usr/bin
{"find", find_main},
#endif
#ifdef BB_FREE //usr/bin
{"free", free_main},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#endif
#ifdef BB_FSCK_MINIX //sbin
{"fsck.minix", fsck_minix_main},
#endif
#ifdef BB_MKFS_MINIX //sbin
{"mkfs.minix", mkfs_minix_main},
#endif
#ifdef BB_GREP //bin
{"grep", grep_main},
#endif
#ifdef BB_HALT //sbin
{"halt", halt_main},
#endif
#ifdef BB_HEAD //bin
{"head", head_main},
#endif
#ifdef BB_HOSTNAME //bin
{"hostname", hostname_main},
#endif
#ifdef BB_INIT //sbin
{"init", init_main},
#endif
#ifdef BB_FEATURE_LINUXRC //
{"linuxrc", init_main},
#endif
#ifdef BB_KILL //bin
{"kill", kill_main},
#endif
@@ -74,14 +94,14 @@ static const struct Applet applets[] = {
{"length", length_main},
#endif
#ifdef BB_LN //bin
{"ln", dyadic_main},
{"ln", ln_main},
#endif
#ifdef BB_LOADFONT //usr/bin
{"loadfont", loadfont_main},
#endif
#ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main},
#endif
#ifdef BB_LOSETUP //sbin
{"losetup", losetup_main},
#endif
#ifdef BB_LS //bin
{"ls", ls_main},
#endif
@@ -92,7 +112,7 @@ static const struct Applet applets[] = {
{"math", math_main},
#endif
#ifdef BB_MKDIR //bin
{"mkdir", monadic_main},
{"mkdir", mkdir_main},
#endif
#ifdef BB_MKNOD //bin
{"mknod", mknod_main},
@@ -104,7 +124,7 @@ static const struct Applet applets[] = {
{"mnc", mnc_main},
#endif
#ifdef BB_MORE //bin
{"more", cat_more_main},
{"more", more_main},
#endif
#ifdef BB_MOUNT //bin
{"mount", mount_main},
@@ -113,11 +133,20 @@ static const struct Applet applets[] = {
{"mt", mt_main},
#endif
#ifdef BB_MV //bin
{"mv", dyadic_main},
{"mv", mv_main},
#endif
#ifdef BB_PING //bin
{"ping", ping_main},
#endif
#ifdef BB_POWEROFF //sbin
{"poweroff", poweroff_main},
#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#endif
#ifdef BB_PS //bin
{"ps", ps_main},
#endif
#ifdef BB_PWD //bin
{"pwd", pwd_main},
#endif
@@ -128,38 +157,59 @@ static const struct Applet applets[] = {
{"rm", rm_main},
#endif
#ifdef BB_RMDIR //bin
{"rmdir", monadic_main},
{"rmdir", rmdir_main},
#endif
#ifdef BB_SFDISK //sbin
{"fdisk", sfdisk_main},
{"sfdisk", sfdisk_main},
#endif
#ifdef BB_SED //bin
{"sed", sed_main},
#endif
#ifdef BB_SLEEP //bin
{"sleep", sleep_main},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_SWAPOFF //sbin
{"swapoff", monadic_main},
#endif
#ifdef BB_SWAPON //sbin
{"swapon", monadic_main},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", monadic_main},
#ifdef BB_SYSLOGD //sbin
{"syslogd", syslogd_main},
#endif
#ifdef BB_TRUE //bin
#ifdef BB_LOGGER //usr/bin
{"logger", logger_main},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#endif
#ifdef BB_TAIL //usr/bin
{"tail", tail_main},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_TEE //bin
{"tee", tee_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
{"umount", umount_main},
#endif
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_ZCAT //bin
{"zcat", zcat_main},
{"gunzip", zcat_main},
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
@@ -191,40 +241,39 @@ int main(int argc, char **argv)
}
a++;
}
return (busybox_main(argc, argv));
exit (busybox_main(argc, argv));
}
int busybox_main(int argc, char **argv)
{
int col=0;
argc--;
argv++;
/* If we've already been here once, exit now */
if (been_there_done_that == 1)
return -1;
been_there_done_that = 1;
if (argc < 1) {
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
if (a->name != 0) {
fprintf(stderr, "%s", a->name);
a++;
}
while (a->name != 0) {
fprintf(stderr, ", %s", a->name);
a++;
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;
}
}
fprintf(stderr, "\n\n");
exit(-1);
} else
} else {
/* If we've already been here once, exit now */
been_there_done_that = 1;
return (main(argc, argv));
}
}
+89 -52
View File
@@ -3,62 +3,99 @@
* IE //#define BB_BLAH
*/
//#define BB_BLOCK_DEVICE
#define BB_BUSYBOX
#define BB_CAT
#define BB_CHGRP
//#define BB_CHMOD
//#define BB_CHOWN
//#define BB_CHROOT
//#define BB_CLEAR
//#define BB_CP
//#define BB_DATE
//#define BB_DD
//#define BB_DESCEND
//#define BB_DF
//#define BB_DMESG
#define BB_CHMOD_CHOWN_CHGRP
#define BB_CHROOT
#define BB_CLEAR
#define BB_CP
#define BB_DATE
#define BB_DD
#define BB_DF
#define BB_DMESG
//#define BB_DUTMP
//#define BB_DYADIC
//#define BB_FALSE
#define BB_DU
//#define BB_FDFLUSH
//#define BB_FIND
//#define BB_FINDMOUNT
//#define BB_GREP
////#define BB_HALT
//#define BB_INIT
//#define BB_KILL
////#define BB_LENGTH
//#define BB_LN
//#define BB_LOADKMAP
////#define BB_LOSETUP
//#define BB_LS
//#define BB_MAIN
#define BB_FIND
#define BB_FREE
#define BB_FSCK_MINIX
#define BB_MKFS_MINIX
#define BB_CHVT
#define BB_DEALLOCVT
#define BB_GREP
//#define BB_HALT
#define BB_HEAD
#define BB_HOSTNAME
#define BB_INIT
#define BB_KILL
#define BB_KLOGD
//#define BB_LENGTH
#define BB_LN
#define BB_LOADFONT
#define BB_LOADKMAP
#define BB_LOGGER
#define BB_LS
//#define BB_MAKEDEVS
////#define BB_MATH
//#define BB_MKDIR
//#define BB_MKNOD
////#define BB_MKSWAP
//#define BB_MATH
#define BB_MKDIR
#define BB_MKNOD
#define BB_MKSWAP
//#define BB_MNC
//#define BB_MONADIC
//#define BB_MORE
//#define BB_MOUNT
////#define BB_MT
//#define BB_MV
//#define BB_POSTPROCESS
#define BB_MORE
#define BB_MOUNT
#define BB_NFSMOUNT
//#define BB_MT
//#define BB_MTAB
#define BB_MV
#define BB_PING
#define BB_POWEROFF
//#define BB_PRINTF
//#define BB_PWD
//#define BB_REBOOT
//#define BB_RM
//#define BB_RMDIR
//#define BB_SLEEP
////#define BB_SWAPOFF
//#define BB_SWAPON
//#define BB_SYNC
//#define BB_TAR
//#define BB_TOUCH
//#define BB_TRUE
//#define BB_UMOUNT
//#define BB_UPDATE
//#define BB_UTILITY
//#define BB_ZCAT
//#define BB_GZIP
#define BB_PS
#define BB_PWD
#define BB_REGEXP
#define BB_REBOOT
#define BB_RM
#define BB_RMDIR
//#define BB_SFDISK
#define BB_SED
#define BB_SLEEP
#define BB_SWAPONOFF
#define BB_SYNC
#define BB_SYSLOGD
#define BB_TAIL
#define BB_TAR
#define BB_TEE
#define BB_TOUCH
#define BB_TRUE_FALSE
#define BB_UMOUNT
#define BB_UPDATE
#define BB_UNAME
#define BB_GZIP
#define BB_GUNZIP
// Don't turn BB_UTILITY off. It contains support code
// that compiles to 0 if everything else if turned off.
#define BB_UTILITY
//
//
//
// This is where feature definitions go. Generally speaking,
// turning this stuff off makes things a bit smaller (and less
// pretty/useful).
//
//
// enable a second console on TTY2 in init
#define BB_FEATURE_INIT_SECOND_CONSOLE
// enable features that use the /proc filesystem
#define BB_FEATURE_USE_PROCFS
//Enable init being called as /linuxrc
#define BB_FEATURE_LINUXRC
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
// calculate terminal & column widths
#define BB_FEATURE_AUTOWIDTH
// show username/groupnames (bypasses libc6 NSS)
#define BB_FEATURE_LS_USERNAME
// show file timestamps
#define BB_FEATURE_LS_TIMESTAMPS
// enable ls -p and -F
#define BB_FEATURE_LS_FILETYPES
+7 -9
View File
@@ -2,16 +2,14 @@
#Make busybox links list file
DF="busybox.def.h"
MF="main.c"
MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
for def in ${LIST}; do
set -- $(sed -n '/^#ifdef '$def'[ +| +].*/,/^#endif/{s/.*\/\///p; /^{ /{ s/^{ "//; s/",.*$//p;}; }' $MF)
path=$1; shift
for n in $@; do
echo "$path/$n"
done
for def in ${LIST}; do
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
for k in $j; do
echo $i$k
done
done
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
+9 -17
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.29alpha
Version: 0.39
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,33 +7,25 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.29a1.tar.gz
Source: %{Name}-%{Version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete environment that fits on a floppy or in a
ROM. Just add "ash" (Keith Almquists tiny Bourne shell clone) and "ae",
and a kernel and you have a full system. This is used on the Debian
install disk and in an internet router, and it makes a good environment
for a "rescue" disk or any small or embedded system.
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a full system. This
is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
%setup -q -n busybox
%setup -q -n %{Name}-%{Version}
%Build
make
%Install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/bin
h=`cat busybox.links`
for i in $h ; do
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
(cd $RPM_BUILD_ROOT/bin ; ln -s ln `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/ln
install -m 755 busybox $RPM_BUILD_ROOT/bin/ln
make PREFIX=$RPM_BUILD_ROOT install
%Clean
rm -rf $RPM_BUILD_ROOT
+24 -19
View File
@@ -1,7 +1,8 @@
/*
* Mini Cat implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,33 +23,37 @@
#include "internal.h"
#include <stdio.h>
const char cat_usage[] = "[file ...]";
extern int cat_more_main(int argc, char **argv)
static void print_file( FILE *file)
{
int c;
FILE *file = stdin;
while ((c = getc(file)) != EOF)
putc(c, stdout);
fclose(file);
fflush(stdout);
}
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv, cat_usage);
return 1;
extern int cat_main(int argc, char **argv)
{
FILE *file;
if (argc==1) {
print_file( stdin);
exit( TRUE);
}
if ( **(argv+1) == '-' ) {
usage ("cat [file ...]\n");
}
argc--;
argv++;
while (argc-- > 0) {
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
file = fopen(*argv, "r");
if (file == NULL) {
name_and_error(*argv);
return 1;
perror(*argv);
exit(FALSE);
}
while ((c = getc(file)) != EOF)
putc(c, stdout);
fclose(file);
fflush(stdout);
argc--;
argv++;
print_file( file);
}
return 0;
exit(TRUE);
}
-89
View File
@@ -1,89 +0,0 @@
/*
* Mini chgrp implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <grp.h>
#include <stdio.h>
const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n"
"Change the group membership of each FILE to GROUP.\n"
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
int chgrp_main(int argc, char **argv)
{
const char *cp;
int gid;
struct group *grp;
struct stat statBuf;
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv, chgrp_usage);
return 1;
}
argc--;
argv++;
cp = argv[1];
if (isDecimal(*cp)) {
gid = 0;
while (isDecimal(*cp))
gid = gid * 10 + (*cp++ - '0');
if (*cp) {
fprintf(stderr, "Bad gid value\n");
return -1;
}
} else {
grp = getgrnam(cp);
if (grp == NULL) {
fprintf(stderr, "Unknown group name\n");
return -1;
}
gid = grp->gr_gid;
}
argc--;
argv++;
while (argc-- > 1) {
argv++;
if ((stat(*argv, &statBuf) < 0) ||
(chown(*argv, statBuf.st_uid, gid) < 0)) {
perror(*argv);
}
}
return 1;
}
#if 0
int
recursive(const char *fileName, BOOL followLinks, const char *pattern,
int (*fileAction) (const char *fileName,
const struct stat * statbuf),
int (*dirAction) (const char *fileName,
const struct stat * statbuf))
#endif
-163
View File
@@ -1,163 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "internal.h"
const char chmod_usage[] = "chmod [-R] mode file [file ...]\n"
"\nmode may be an octal integer representing the bit pattern for the\n"
"\tnew mode, or a symbolic value matching the pattern\n"
"\t[ugoa]{+|-|=}[rwxst] .\n"
"\t\tu:\tUser\n"
"\t\tg:\tGroup\n"
"\t\to:\tOthers\n"
"\t\ta:\tAll\n"
"\n"
"\n+:\tAdd privilege\n"
"\n-:\tRemove privilege\n"
"\n=:\tSet privilege\n"
"\n"
"\t\tr:\tRead\n"
"\t\tw:\tWrite\n"
"\t\tx:\tExecute\n"
"\t\ts:\tSet User ID\n"
"\t\tt:\t\"Sticky\" Text\n"
"\n"
"\tModes may be concatenated, as in \"u=rwx,g=rx,o=rx,-t,-s\n"
"\n"
"\t-R:\tRecursively change the mode of all files and directories\n"
"\t\tunder the argument directory.";
int
parse_mode(
const char * s
,mode_t * or
,mode_t * and
,int * group_execute)
{
/* [ugoa]{+|-|=}[rwxstl] */
mode_t mode = 0;
mode_t groups = S_ISVTX;
char type;
char c;
do {
for ( ; ; ) {
switch ( c = *s++ ) {
case '\0':
return -1;
case 'u':
groups |= S_ISUID|S_IRWXU;
continue;
case 'g':
groups |= S_ISGID|S_IRWXG;
continue;
case 'o':
groups |= S_IRWXO;
continue;
case 'a':
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
continue;
case '+':
case '=':
case '-':
type = c;
if ( groups == S_ISVTX ) /* The default is "all" */
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
break;
default:
if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
*and = 0;
*or = strtol(--s, 0, 010);
return 0;
}
else
return -1;
}
break;
}
while ( (c = *s++) != '\0' ) {
switch ( c ) {
case ',':
break;
case 'r':
mode |= S_IRUSR|S_IRGRP|S_IROTH;
continue;
case 'w':
mode |= S_IWUSR|S_IWGRP|S_IWOTH;
continue;
case 'x':
mode |= S_IXUSR|S_IXGRP|S_IXOTH;
continue;
case 's':
if ( group_execute != 0 && (groups & S_IRWXG) ) {
if ( *group_execute < 0 )
return -1;
if ( type != '-' ) {
mode |= S_IXGRP;
*group_execute = 1;
}
}
mode |= S_ISUID|S_ISGID;
continue;
case 'l':
if ( *group_execute > 0 )
return -1;
if ( type != '-' ) {
*and &= ~S_IXGRP;
*group_execute = -1;
}
mode |= S_ISGID;
groups |= S_ISGID;
continue;
case 't':
mode |= S_ISVTX;
continue;
default:
return -1;
}
break;
}
switch ( type ) {
case '=':
*and &= ~(groups);
/* fall through */
case '+':
*or |= mode & groups;
break;
case '-':
*and &= ~(mode & groups);
*or &= *and;
break;
}
} while ( c == ',' );
return 0;
}
extern int
chmod_main(struct FileInfo * i, int argc, char * * argv)
{
i->andWithMode = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
i->orWithMode = 0;
while ( argc >= 3 ) {
if ( parse_mode(argv[1], &i->orWithMode, &i->andWithMode, 0)
== 0 ) {
argc--;
argv++;
}
else if ( strcmp(argv[1], "-R") == 0 ) {
i->recursive = 1;
argc--;
argv++;
}
else
break;
}
i->changeMode = 1;
i->complainInPostProcess = 1;
return monadic_main(i, argc, argv);
}
+155
View File
@@ -0,0 +1,155 @@
/*
* Mini chown/chmod/chgrp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <grp.h>
#include <pwd.h>
#include "internal.h"
static uid_t uid=-1;
static gid_t gid=-1;
static int whichApp;
static char* invocationName=NULL;
static char* theMode=NULL;
#define CHGRP_APP 1
#define CHOWN_APP 2
#define CHMOD_APP 3
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
"Change the group membership of each FILE to GROUP.\n"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
"one or more of the letters rwxst.\n\n"
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
static int fileAction(const char *fileName, struct stat* statbuf)
{
switch (whichApp) {
case CHGRP_APP:
case CHOWN_APP:
if (chown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid,
(gid==-1)? statbuf->st_gid : gid) == 0) {
return( TRUE);
}
break;
case CHMOD_APP:
/* Parse the specified modes */
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
exit( FALSE);
}
if (chmod(fileName, statbuf->st_mode) == 0)
return( TRUE);
break;
}
perror(fileName);
return( FALSE);
}
int chmod_chown_chgrp_main(int argc, char **argv)
{
int recursiveFlag=FALSE;
char *groupName;
const char *appUsage;
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
if (argc < 2)
usage( appUsage);
invocationName=*argv;
argc--;
argv++;
/* Parse options */
while (**argv == '-') {
while (*++(*argv)) switch (**argv) {
case 'R':
recursiveFlag = TRUE;
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
usage( appUsage);
}
argc--;
argv++;
}
if ( whichApp == CHMOD_APP ) {
theMode=*argv;
} else {
/* Find the selected group */
if ( whichApp==CHGRP_APP ) {
groupName = *argv;
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else {
groupName = strchr(*argv, '.');
if (groupName) {
*groupName++ = '\0';
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else
gid = -1;
}
/* Find the selected user (if appropriate) */
if (whichApp==CHOWN_APP) {
uid = my_getpwnam(*argv);
if (uid == -1) {
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
exit( FALSE);
}
}
}
/* Ok, ready to do the deed now */
if (argc <= 1) {
fprintf(stderr, "%s: too few arguments", invocationName);
exit( FALSE);
}
while (argc-- > 1) {
if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
exit( FALSE);
}
exit(TRUE);
bad_group:
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
exit( FALSE);
}
-63
View File
@@ -1,63 +0,0 @@
#include "internal.h"
#include <pwd.h>
#include <grp.h>
#include <string.h>
#include <stdio.h>
const char chown_usage[] = "chown [-R] user-name file [file ...]\n"
"\n\tThe group list is kept in the file /etc/groups.\n\n"
"\t-R:\tRecursively change the mode of all files and directories\n"
"\t\tunder the argument directory.";
int
parse_user_name(const char * s, struct FileInfo * i)
{
struct passwd * p;
char * dot = strchr(s, '.');
if (! dot )
dot = strchr(s, ':');
if ( dot )
*dot = '\0';
if ( (p = getpwnam(s)) == 0 ) {
fprintf(stderr, "%s: no such user.\n", s);
return 1;
}
i->userID = p->pw_uid;
if ( dot ) {
struct group * g = getgrnam(++dot);
if ( g == 0 ) {
fprintf(stderr, "%s: no such group.\n", dot);
return 1;
}
i->groupID = g->gr_gid;
i->changeGroupID = 1;
}
return 0;
}
extern int
chown_main(struct FileInfo * i, int argc, char * * argv)
{
int status;
while ( argc >= 3 && strcmp("-R", argv[1]) == 0 ) {
i->recursive = 1;
argc--;
argv++;
}
if ( (status = parse_user_name(argv[1], i)) != 0 )
return status;
argv++;
argc--;
i->changeUserID = 1;
i->complainInPostProcess = 1;
return monadic_main(i, argc, argv);
}
+55 -21
View File
@@ -1,32 +1,66 @@
/*
* Mini chroot implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
const char chroot_usage[] = "chroot directory [command]\n"
"Run a command with special root directory.\n";
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
extern int
chroot_main (struct FileInfo *i, int argc, char **argv)
int chroot_main(int argc, char **argv)
{
char *prog;
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( chroot_usage);
}
argc--;
argv++;
if (chroot (argv[1]))
{
name_and_error ("cannot chroot to that directory");
return 1;
if (chroot (*argv) || (chdir ("/"))) {
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
if (argc > 2)
{
execvp (argv[2], argv + 2);
argc--;
argv++;
if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv);
execvp (*argv, argv);
}
else
{
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
else {
char *prog;
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
}
name_and_error ("cannot exec");
return 1;
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* chvt.c - aeb - 940227 - Change virtual terminal
*
* busyboxed by Erik Andersen
*/
#include "internal.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
extern int getfd(void);
int
chvt_main(int argc, char** argv)
{
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd,VT_WAITACTIVE,num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit( TRUE);
}
+25 -5
View File
@@ -1,13 +1,33 @@
/*
* Mini clear implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
const char clear_usage[] = "clear\n"
"\n"
"\tClears the screen.\n";
extern int
clear_main(struct FileInfo * i, int argc, char * * argv)
clear_main(int argc, char** argv)
{
printf("\033[H\033[J");
return 0;
exit( TRUE);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* chvt.c - aeb - 940227 - Change virtual terminal
*
* busyboxed by Erik Andersen
*/
#include "internal.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
extern int getfd(void);
int
chvt_main(int argc, char** argv)
{
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd,VT_WAITACTIVE,num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit( TRUE);
}
+25 -5
View File
@@ -1,13 +1,33 @@
/*
* Mini clear implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
const char clear_usage[] = "clear\n"
"\n"
"\tClears the screen.\n";
extern int
clear_main(struct FileInfo * i, int argc, char * * argv)
clear_main(int argc, char** argv)
{
printf("\033[H\033[J");
return 0;
exit( TRUE);
}
+50
View File
@@ -0,0 +1,50 @@
/*
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
* Renamed deallocvt.
*/
#include "internal.h"
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
progname = argv[0];
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd,VT_DISALLOCATE,0)) {
perror("VT_DISALLOCATE");
exit(1);
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
else
if (ioctl(fd,VT_DISALLOCATE,num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
}
+234
View File
@@ -0,0 +1,234 @@
/*
* loadfont.c - Eugene Crosser & Andries Brouwer
*
* Version 0.96bb
*
* Loads the console font, and possibly the corresponding screen map(s).
* (Adapted for busybox by Matej Vela.)
*/
#include "internal.h"
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <memory.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <endian.h>
#define PSF_MAGIC1 0x36
#define PSF_MAGIC2 0x04
#define PSF_MODE512 0x01
#define PSF_MODEHASTAB 0x02
#define PSF_MAXMODE 0x03
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n"
"\n"
"\tLoad a console font from standard input.\n"
"\n";
struct psf_header
{
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void loadnewfont(int fd);
extern int
loadfont_main(int argc, char **argv)
{
int fd;
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
loadnewfont(fd);
return 0;
}
static void
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
char buf[16384];
int i;
memset(buf,0,sizeof(buf));
if (unit < 1 || unit > 32) {
fprintf(stderr, "Bad character size %d\n", unit);
exit(1);
}
for (i = 0; i < fontsize; i++)
memcpy(buf+(32*i), inbuf+(unit*i), unit);
#if defined( PIO_FONTX ) && !defined( __sparc__ )
{
struct consolefontdesc cfd;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
}
#endif
if (ioctl(fd, PIO_FONT, buf)) {
perror("PIO_FONT ioctl error");
exit(1);
}
}
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
struct unimapinit advice;
struct unimapdesc ud;
struct unipair *up;
int ct = 0, maxct;
int glyph;
u_short unicode;
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
if (!up) {
fprintf(stderr, "Out of memory?\n");
exit(1);
}
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
}
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
this printf did not work on many kernels */
advice.advised_hashsize = 0;
advice.advised_hashstep = 0;
advice.advised_hashlevel = 0;
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
#ifdef ENOIOCTLCMD
if (errno == ENOIOCTLCMD) {
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
fprintf(stderr, "No Unicode mapping table loaded.\n");
} else
#endif
perror("PIO_UNIMAPCLR");
exit(1);
}
ud.entry_ct = ct;
ud.entries = up;
if(ioctl(fd, PIO_UNIMAP, &ud)) {
#if 0
if (errno == ENOMEM) {
/* change advice parameters */
}
#endif
perror("PIO_UNIMAP");
exit(1);
}
}
static void
loadnewfont(int fd) {
int unit;
char inbuf[32768]; /* primitive */
int inputlth, offset;
/*
* We used to look at the length of the input file
* with stat(); now that we accept compressed files,
* just read the entire file.
*/
inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
if (ferror(stdin)) {
perror("Error reading input font");
exit(1);
}
/* use malloc/realloc in case of giant files;
maybe these do not occur: 16kB for the font,
and 16kB for the map leaves 32 unicode values
for each font position */
if (!feof(stdin)) {
perror("Font too large");
exit(1);
}
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
int head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = * (struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (psfhdr.mode > PSF_MAXMODE) {
fprintf(stderr, "Unsupported psf file mode\n");
exit(1);
}
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
#if !defined( PIO_FONTX ) || defined( __sparc__ )
if (fontsize != 256) {
fprintf(stderr, "Only fontsize 256 supported\n");
exit(1);
}
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize*unit;
if (head > inputlth || (!hastable && head != inputlth)) {
fprintf(stderr, "Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
return;
}
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377) {
fprintf(stderr, "Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth/256;
}
do_loadfont(fd, inbuf+offset, unit, 256);
}
+24 -3
View File
@@ -1,3 +1,24 @@
/*
* Mini loadkmap implementation for busybox
*
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include <fcntl.h>
@@ -7,14 +28,14 @@
#include <sys/ioctl.h>
const char loadkmap_usage[] = "loadkmap\n"
static const char loadkmap_usage[] = "loadkmap\n"
"\n"
"\tLoad a binary keyboard translation table from standard input.\n"
"\n";
int
loadkmap_main(struct FileInfo * info, int argc, char * * argv)
loadkmap_main(int argc, char * * argv)
{
struct kbentry ke;
u_short *ibuff;
@@ -48,7 +69,7 @@ loadkmap_main(struct FileInfo * info, int argc, char * * argv)
if (flags[i]==1){
pos=0;
while (pos < ibuffsz) {
if ( (readsz = read(0,ibuff+pos,ibuffsz-pos)) < 0 ) {
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
fprintf(stderr, "Error reading keymap: %s\n",
strerror(errno));
return 1;
+24 -19
View File
@@ -1,7 +1,8 @@
/*
* Mini Cat implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,33 +23,37 @@
#include "internal.h"
#include <stdio.h>
const char cat_usage[] = "[file ...]";
extern int cat_more_main(int argc, char **argv)
static void print_file( FILE *file)
{
int c;
FILE *file = stdin;
while ((c = getc(file)) != EOF)
putc(c, stdout);
fclose(file);
fflush(stdout);
}
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv, cat_usage);
return 1;
extern int cat_main(int argc, char **argv)
{
FILE *file;
if (argc==1) {
print_file( stdin);
exit( TRUE);
}
if ( **(argv+1) == '-' ) {
usage ("cat [file ...]\n");
}
argc--;
argv++;
while (argc-- > 0) {
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
file = fopen(*argv, "r");
if (file == NULL) {
name_and_error(*argv);
return 1;
perror(*argv);
exit(FALSE);
}
while ((c = getc(file)) != EOF)
putc(c, stdout);
fclose(file);
fflush(stdout);
argc--;
argv++;
print_file( file);
}
return 0;
exit(TRUE);
}
-89
View File
@@ -1,89 +0,0 @@
/*
* Mini chgrp implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <grp.h>
#include <stdio.h>
const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n"
"Change the group membership of each FILE to GROUP.\n"
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
int chgrp_main(int argc, char **argv)
{
const char *cp;
int gid;
struct group *grp;
struct stat statBuf;
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv, chgrp_usage);
return 1;
}
argc--;
argv++;
cp = argv[1];
if (isDecimal(*cp)) {
gid = 0;
while (isDecimal(*cp))
gid = gid * 10 + (*cp++ - '0');
if (*cp) {
fprintf(stderr, "Bad gid value\n");
return -1;
}
} else {
grp = getgrnam(cp);
if (grp == NULL) {
fprintf(stderr, "Unknown group name\n");
return -1;
}
gid = grp->gr_gid;
}
argc--;
argv++;
while (argc-- > 1) {
argv++;
if ((stat(*argv, &statBuf) < 0) ||
(chown(*argv, statBuf.st_uid, gid) < 0)) {
perror(*argv);
}
}
return 1;
}
#if 0
int
recursive(const char *fileName, BOOL followLinks, const char *pattern,
int (*fileAction) (const char *fileName,
const struct stat * statbuf),
int (*dirAction) (const char *fileName,
const struct stat * statbuf))
#endif
-163
View File
@@ -1,163 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "internal.h"
const char chmod_usage[] = "chmod [-R] mode file [file ...]\n"
"\nmode may be an octal integer representing the bit pattern for the\n"
"\tnew mode, or a symbolic value matching the pattern\n"
"\t[ugoa]{+|-|=}[rwxst] .\n"
"\t\tu:\tUser\n"
"\t\tg:\tGroup\n"
"\t\to:\tOthers\n"
"\t\ta:\tAll\n"
"\n"
"\n+:\tAdd privilege\n"
"\n-:\tRemove privilege\n"
"\n=:\tSet privilege\n"
"\n"
"\t\tr:\tRead\n"
"\t\tw:\tWrite\n"
"\t\tx:\tExecute\n"
"\t\ts:\tSet User ID\n"
"\t\tt:\t\"Sticky\" Text\n"
"\n"
"\tModes may be concatenated, as in \"u=rwx,g=rx,o=rx,-t,-s\n"
"\n"
"\t-R:\tRecursively change the mode of all files and directories\n"
"\t\tunder the argument directory.";
int
parse_mode(
const char * s
,mode_t * or
,mode_t * and
,int * group_execute)
{
/* [ugoa]{+|-|=}[rwxstl] */
mode_t mode = 0;
mode_t groups = S_ISVTX;
char type;
char c;
do {
for ( ; ; ) {
switch ( c = *s++ ) {
case '\0':
return -1;
case 'u':
groups |= S_ISUID|S_IRWXU;
continue;
case 'g':
groups |= S_ISGID|S_IRWXG;
continue;
case 'o':
groups |= S_IRWXO;
continue;
case 'a':
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
continue;
case '+':
case '=':
case '-':
type = c;
if ( groups == S_ISVTX ) /* The default is "all" */
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
break;
default:
if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
*and = 0;
*or = strtol(--s, 0, 010);
return 0;
}
else
return -1;
}
break;
}
while ( (c = *s++) != '\0' ) {
switch ( c ) {
case ',':
break;
case 'r':
mode |= S_IRUSR|S_IRGRP|S_IROTH;
continue;
case 'w':
mode |= S_IWUSR|S_IWGRP|S_IWOTH;
continue;
case 'x':
mode |= S_IXUSR|S_IXGRP|S_IXOTH;
continue;
case 's':
if ( group_execute != 0 && (groups & S_IRWXG) ) {
if ( *group_execute < 0 )
return -1;
if ( type != '-' ) {
mode |= S_IXGRP;
*group_execute = 1;
}
}
mode |= S_ISUID|S_ISGID;
continue;
case 'l':
if ( *group_execute > 0 )
return -1;
if ( type != '-' ) {
*and &= ~S_IXGRP;
*group_execute = -1;
}
mode |= S_ISGID;
groups |= S_ISGID;
continue;
case 't':
mode |= S_ISVTX;
continue;
default:
return -1;
}
break;
}
switch ( type ) {
case '=':
*and &= ~(groups);
/* fall through */
case '+':
*or |= mode & groups;
break;
case '-':
*and &= ~(mode & groups);
*or &= *and;
break;
}
} while ( c == ',' );
return 0;
}
extern int
chmod_main(struct FileInfo * i, int argc, char * * argv)
{
i->andWithMode = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
i->orWithMode = 0;
while ( argc >= 3 ) {
if ( parse_mode(argv[1], &i->orWithMode, &i->andWithMode, 0)
== 0 ) {
argc--;
argv++;
}
else if ( strcmp(argv[1], "-R") == 0 ) {
i->recursive = 1;
argc--;
argv++;
}
else
break;
}
i->changeMode = 1;
i->complainInPostProcess = 1;
return monadic_main(i, argc, argv);
}
-63
View File
@@ -1,63 +0,0 @@
#include "internal.h"
#include <pwd.h>
#include <grp.h>
#include <string.h>
#include <stdio.h>
const char chown_usage[] = "chown [-R] user-name file [file ...]\n"
"\n\tThe group list is kept in the file /etc/groups.\n\n"
"\t-R:\tRecursively change the mode of all files and directories\n"
"\t\tunder the argument directory.";
int
parse_user_name(const char * s, struct FileInfo * i)
{
struct passwd * p;
char * dot = strchr(s, '.');
if (! dot )
dot = strchr(s, ':');
if ( dot )
*dot = '\0';
if ( (p = getpwnam(s)) == 0 ) {
fprintf(stderr, "%s: no such user.\n", s);
return 1;
}
i->userID = p->pw_uid;
if ( dot ) {
struct group * g = getgrnam(++dot);
if ( g == 0 ) {
fprintf(stderr, "%s: no such group.\n", dot);
return 1;
}
i->groupID = g->gr_gid;
i->changeGroupID = 1;
}
return 0;
}
extern int
chown_main(struct FileInfo * i, int argc, char * * argv)
{
int status;
while ( argc >= 3 && strcmp("-R", argv[1]) == 0 ) {
i->recursive = 1;
argc--;
argv++;
}
if ( (status = parse_user_name(argv[1], i)) != 0 )
return status;
argv++;
argc--;
i->changeUserID = 1;
i->complainInPostProcess = 1;
return monadic_main(i, argc, argv);
}
+55 -21
View File
@@ -1,32 +1,66 @@
/*
* Mini chroot implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
const char chroot_usage[] = "chroot directory [command]\n"
"Run a command with special root directory.\n";
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
extern int
chroot_main (struct FileInfo *i, int argc, char **argv)
int chroot_main(int argc, char **argv)
{
char *prog;
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( chroot_usage);
}
argc--;
argv++;
if (chroot (argv[1]))
{
name_and_error ("cannot chroot to that directory");
return 1;
if (chroot (*argv) || (chdir ("/"))) {
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
if (argc > 2)
{
execvp (argv[2], argv + 2);
argc--;
argv++;
if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv);
execvp (*argv, argv);
}
else
{
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
else {
char *prog;
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
}
name_and_error ("cannot exec");
return 1;
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
+103 -75
View File
@@ -1,89 +1,117 @@
/*
* Mini cp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/param.h>
#include <errno.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
const char cp_usage[] = "cp [-r] source-file destination-file\n"
"\t\tcp [-r] source-file [source-file ...] destination-directory\n"
"\n"
"\tCopy the source files to the destination.\n"
"\n"
"\t-r:\tRecursively copy all files and directories\n"
"\t\tunder the argument directory.";
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
"\t-d\tpreserve links\n"
"\t-p\tpreserve file attributes if possable\n"
"\t-R\tcopy directories recursively\n";
extern int
cp_fn(const struct FileInfo * i)
static int recursiveFlag = FALSE;
static int followLinks = FALSE;
static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
int sourceFd;
int destinationFd;
const char * destination = i->destination;
struct stat destination_stat;
int status;
char buf[8192];
char d[PATH_MAX];
if ( (i->stat.st_mode & S_IFMT) == S_IFDIR ) {
if ( mkdir(destination, i->stat.st_mode & ~S_IFMT)
!= 0 && errno != EEXIST ) {
name_and_error(destination);
return 1;
}
return 0;
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
if ( (sourceFd = open(i->source, O_RDONLY)) < 0 ) {
name_and_error(i->source);
return 1;
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
if (argc < 3) {
usage (cp_usage);
}
if ( stat(destination, &destination_stat) == 0 ) {
if ( i->stat.st_ino == destination_stat.st_ino
&& i->stat.st_dev == destination_stat.st_dev ) {
fprintf(stderr
,"copy of %s to %s would copy file to itself.\n"
,i->source
,destination);
close(sourceFd);
return 1;
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'a':
followLinks = TRUE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = TRUE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
default:
usage (cp_usage);
}
argc--;
argv++;
}
/*
* If the destination is a directory, create a file within it.
*/
if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) {
destination = join_paths(
d
,i->destination
,&i->source[i->directoryLength]);
if ( stat(destination, &destination_stat) == 0 ) {
if ( i->stat.st_ino == destination_stat.st_ino
&& i->stat.st_dev == destination_stat.st_dev ) {
fprintf(stderr
,"copy of %s to %s would copy file to itself.\n"
,i->source
,destination);
close(sourceFd);
return 1;
}
}
}
destinationFd = creat(destination, i->stat.st_mode & 07777);
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
while ( (status = read(sourceFd, buf, sizeof(buf))) > 0 ) {
if ( write(destinationFd, buf, status) != status ) {
name_and_error(destination);
close(sourceFd);
close(destinationFd);
return 1;
}
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
close(sourceFd);
close(destinationFd);
if ( status < 0 ) {
name_and_error(i->source);
return 1;
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
return 0;
exit( TRUE);
}
+76 -94
View File
@@ -1,3 +1,24 @@
/*
* Mini date implementation for busybox
*
* by Matthew Grant <grantma@anathoth.gen.nz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdlib.h>
#include <errno.h>
@@ -5,7 +26,6 @@
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@@ -14,19 +34,12 @@
an RFC 822 complient date output for shell scripting
mail commands */
const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n | [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]";
static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
/* {"rfc-822", no_argument, NULL, 'R'},
{"set", required_argument, NULL, 's'},
{"uct", no_argument, NULL, 'u'},
{"utc", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'}, */
{NULL, 0, NULL, 0}
};
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
@@ -47,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
/* correct for century - minor Y2K problem here? */
@@ -141,99 +154,67 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
void
date_err(void) {
fprintf(stderr, "date: only one date argument can be given at a time.\n");
exit(1);
}
int
date_main(struct FileInfo * i, int argc, char * * argv)
date_main(int argc, char * * argv)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
int n_args;
time_t tm;
struct tm tm_time;
char optc;
/* Interpret command line args */
while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL))
!= EOF) {
switch (optc) {
case 0:
break;
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
return(1);
}
#if LOCALTIME_CACHE
tzset ();
#endif break;
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
default:
usage(date_usage);
break;
i = --argc;
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case '-':
usage ( date_usage);
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
usage ( date_usage);
}
}
i--;
argv++;
}
}
n_args = argc - optind;
while (n_args--){
switch(argv[optind][0]) {
case '+':
/* Date format strings */
if(date_fmt != NULL) {
fprintf(stderr, "date: only one date format can be given.\n");
return(1);
}
date_fmt = &argv[optind][1];
break;
case '\0':
break;
default:
/* Anything left over must be a date string to set the time */
set_time = 1;
if(date_str != NULL) date_err();
date_str = argv[optind];
break;
}
optind++;
}
/* Now we have parsed all the information except the date format
@@ -261,14 +242,14 @@ date_main(struct FileInfo * i, int argc, char * * argv)
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit(1);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit(1);
exit( FALSE);
}
}
}
@@ -286,7 +267,7 @@ date_main(struct FileInfo * i, int argc, char * * argv)
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
return(0);
exit( TRUE);
}
/* Handle special conversions */
@@ -300,6 +281,7 @@ date_main(struct FileInfo * i, int argc, char * * argv)
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(0);
exit( TRUE);
}
+181 -294
View File
@@ -1,307 +1,194 @@
/*
* Mini dd implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based in part on code taken from sash.
*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
* The "dd" command, originally taken from sash.
*
* Permission to distribute this code under the GPL has been granted.
* Majorly modified, and bugs fixed for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#ifdef BB_DD
const char dd_usage[] =
"Copy a file, converting and formatting according to options\n\
\n\
usage: [if=name] [of=name] [bs=n] [count=n]\n\
\tif=FILE\tread from FILE instead of stdin\n\
\tof=FILE\twrite to FILE instead of stout\n\
\tbs=n\tread and write N bytes at a time\n\
\tcount=n\tcopy only n input blocks\n\
\n\
BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
#include <features.h>
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#define PAR_NONE 0
#define PAR_IF 1
#define PAR_OF 2
#define PAR_BS 3
#define PAR_COUNT 4
typedef struct
{
const char * name;
int value;
} PARAM;
static const PARAM params[] =
{
{"if", PAR_IF},
{"of", PAR_OF},
{"bs", PAR_BS},
{"count", PAR_COUNT},
{NULL, PAR_NONE}
};
static long getNum(const char * cp);
extern int
dd_main (struct FileInfo *unused, int argc, char **argv)
{
const char * str;
const PARAM * par;
const char * inFile;
const char * outFile;
char * cp;
int inFd;
int outFd;
int inCc=0;
int outCc;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char* buf;
unsigned char localBuf[BUF_SIZE];
inFile = NULL;
outFile = NULL;
blockSize = 512;
count = 1;
while (--argc > 0)
{
str = *++argv;
cp = strchr(str, '=');
if (cp == NULL)
{
fprintf(stderr, "Bad dd argument\n");
goto usage;
}
*cp++ = '\0';
for (par = params; par->name; par++)
{
if (strcmp(str, par->name) == 0)
break;
}
switch (par->value)
{
case PAR_IF:
if (inFile)
{
fprintf(stderr, "Multiple input files illegal\n");
goto usage;
}
//fprintf(stderr, "if=%s\n", cp);
inFile = cp;
break;
case PAR_OF:
if (outFile)
{
fprintf(stderr, "Multiple output files illegal\n");
goto usage;
}
//fprintf(stderr, "of=%s\n", cp);
outFile = cp;
break;
case PAR_BS:
blockSize = getNum(cp);
//fprintf(stderr, "bs=%d\n", blockSize);
if (blockSize <= 0)
{
fprintf(stderr, "Bad block size value\n");
goto usage;
}
break;
case PAR_COUNT:
count = getNum(cp);
//fprintf(stderr, "count=%ld\n", count);
if (count < 0)
{
fprintf(stderr, "Bad count value\n");
goto usage;
}
break;
default:
goto usage;
}
}
buf = localBuf;
if (blockSize > sizeof(localBuf))
{
buf = malloc(blockSize);
if (buf == NULL)
{
fprintf(stderr, "Cannot allocate buffer\n");
return 1;
}
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open(inFile, 0);
if (inFd < 0)
{
perror(inFile);
if (buf != localBuf)
free(buf);
return 1;
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat(outFile, 0666);
if (outFd < 0)
{
perror(outFile);
close(inFd);
if (buf != localBuf)
free(buf);
return 1;
}
while ( outTotal < count*blockSize )
{
inCc = read(inFd, buf, blockSize);
if (inCc < 0) {
perror(inFile);
goto cleanup;
}
//fprintf(stderr, "read in =%d\n", inCc);
intotal += inCc;
cp = buf;
while ( intotal > outTotal )
{
if (outTotal+inCc > count*blockSize)
inCc=count*blockSize-outTotal;
outCc = write(outFd, cp, inCc);
if (outCc < 0)
{
perror(outFile);
goto cleanup;
}
//fprintf(stderr, "wrote out =%d\n", outCc);
inCc -= outCc;
cp += outCc;
outTotal += outCc;
//fprintf(stderr, "outTotal=%ld\n", outTotal);
}
}
if (inCc < 0)
perror(inFile);
cleanup:
close(inFd);
if (close(outFd) < 0)
perror(outFile);
if (buf != localBuf)
free(buf);
printf("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
return 0;
usage:
fprintf(stderr, "%s", dd_usage);
return 1;
}
/*
* Read a number with a possible multiplier.
* Returns -1 if the number format is illegal.
*/
static long
getNum(const char * cp)
{
long value;
if (!isDecimal(*cp))
return -1;
value = 0;
while (isDecimal(*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++)
{
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
#include <errno.h>
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
#include <inttypes.h>
#else
typedef unsigned long long int uintmax_t;
#endif
/* END CODE */
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
"\tof=FILE\twrite to FILE instead of stout\n"
"\tbs=n\tread and write N BYTES at a time\n"
"\tcount=n\tcopy only n input blocks\n"
//"\tskip=n\tskip n input blocks\n"
"\n"
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
extern int dd_main (int argc, char **argv)
{
const char *inFile = NULL;
const char *outFile = NULL;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
size_t blockSize = 512;
//uintmax_t skipBlocks = 0;
uintmax_t count = (uintmax_t)-1;
uintmax_t intotal;
uintmax_t outTotal;
unsigned char *buf;
argc--;
argv++;
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile=((strchr(*argv, '='))+1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile=((strchr(*argv, '='))+1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum ((strchr(*argv, '='))+1);
if (count <= 0) {
fprintf (stderr, "Bad count value %s\n", *argv);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %s\n", *argv);
goto usage;
}
}
#if 0
else if (strncmp(*argv, "skip", 4) == 0) {
skipBlocks = atoi( *argv);
if (skipBlocks <= 0) {
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
goto usage;
}
}
#endif
else {
goto usage;
}
argc--;
argv++;
}
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = fileno(stdin);
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
//
//TODO: Convert to using fullRead & fullWrite
// from utilitity.c
// -Erik
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
goto cleanup;
} else if (inCc == 0) {
goto cleanup;
}
intotal += inCc;
cp = buf;
while (intotal > outTotal) {
if (outTotal + inCc > count * blockSize)
inCc = count * blockSize - outTotal;
outCc = write (outFd, cp, inCc);
if (outCc < 0) {
perror (outFile);
goto cleanup;
} else if (outCc == 0) {
goto cleanup;
}
inCc -= outCc;
cp += outCc;
outTotal += outCc;
}
}
if (inCc < 0)
perror (inFile);
cleanup:
close (inFd);
close (outFd);
free (buf);
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
(outTotal % blockSize) != 0);
exit( TRUE);
usage:
usage( dd_usage);
}
+90 -81
View File
@@ -1,103 +1,112 @@
/*
* Mini df implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <fstab.h>
const char df_usage[] = "df [filesystem ...]\n"
"\n"
"\tPrint the filesystem space used and space available.\n";
static const char df_usage[] = "df [filesystem ...]\n"
"\n" "\tPrint the filesystem space used and space available.\n";
extern const char mtab_file[]; /* Defined in utility.c */
static int
df(const char * device, const char * mountPoint)
static int df(char *device, const char *mountPoint)
{
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct fstab* fstabItem;
if ( statfs(mountPoint, &s) != 0 ) {
name_and_error(mountPoint);
return 1;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return FALSE;
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (device, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
device = fstabItem->fs_spec;
}
if ( s.f_blocks > 0 ) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used, mountPoint);
/*
printf(
"%-20s %7ld %7ld %7ld %5ld%% %s\n"
,device
,s.f_blocks
,s.f_blocks - s.f_bfree
,s.f_bavail
,blocks_percent_used
,mountPoint);
*/
}
printf(
"%-20s %7.0f %7.0f %7.0f %5ld%% %s\n"
,device
,s.f_blocks * (s.f_bsize / 1024.0)
,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
,s.f_bavail * (s.f_bsize / 1024.0)
,blocks_percent_used
,mountPoint);
}
return 0;
return TRUE;
}
extern int
df_main(struct FileInfo * i, int argc, char * * argv)
extern int df_main(int argc, char **argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
if ( argc > 1 ) {
struct mntent * mountEntry;
int status;
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
while ( argc > 1 ) {
if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0
&& (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
{
fprintf(stderr, "%s: can't find mount point.\n"
,argv[1]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if ( status != 0 )
return status;
argc--;
argv++;
}
return 0;
if (argc > 1) {
struct mntent *mountEntry;
int status;
while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
0) {
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
exit( FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
exit( status);
argc--;
argv++;
}
else {
FILE * mountTable;
struct mntent * mountEntry;
exit( TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
if ( (mountTable = setmntent("/etc/mtab", "r")) == 0
&& (mountTable = setmntent("/proc/mounts", "r")) == 0
) {
name_and_error("/etc/mtab");
return 1;
}
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
int status = df(
mountEntry->mnt_fsname
,mountEntry->mnt_dir);
if ( status != 0 )
return status;
}
endmntent(mountTable);
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
}
return 0;
while ((mountEntry = getmntent(mountTable))) {
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
}
endmntent(mountTable);
}
exit( TRUE);
}
+121
View File
@@ -0,0 +1,121 @@
/*
* Mini du implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#if 0
#include <unistd.h>
#include <sys/stat.h>
#endif
static const char du_usage[] =
"Usage: du [OPTION]... [FILE]...\n";
typedef void (Display)(size_t, char *);
static void
print(size_t size, char *filename)
{
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
}
/* tiny recursive du */
static size_t
du(char *filename)
{
struct stat statbuf;
size_t sum;
if ((lstat(filename, &statbuf)) != 0) {
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
return 0;
}
sum = statbuf.st_blocks;
if (S_ISDIR(statbuf.st_mode)) {
DIR *dir;
struct dirent *entry;
dir = opendir(filename);
if (!dir) { return 0; }
while ((entry = readdir(dir))) {
char newfile[512];
char *name = entry->d_name;
if ( (strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0))
{ continue; }
sprintf(newfile, "%s/%s", filename, name);
sum += du(newfile);
}
closedir(dir);
print(sum, filename);
}
return sum;
}
int
du_main(int argc, char **argv)
{
int i;
char opt;
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 's':
break;
case 'h':
usage(du_usage);
break;
default:
fprintf(stderr, "du: invalid option -- %c\n", opt);
usage(du_usage);
}
} else {
break;
}
}
/* go through remaining args (if any) */
if (i >= argc) {
du(".");
} else {
int sum;
for ( ; i < argc; i++) {
sum = du(argv[i]) >> 1;
if (sum) printf("%-7d %s\n", sum, argv[i]);
}
}
exit(0);
}
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
+106
View File
@@ -0,0 +1,106 @@
/*
* Mini head implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include <stdio.h>
const char head_usage[] =
"Usage: head [FILE]...\n\n"
"Print first 10 lines of each FILE to standard output.\n"
"With more than one FILE, precede each with a header giving the\n"
"file name. With no FILE, or when FILE is -, read standard input.\n";
int
head(int len, FILE *src)
{
int i;
char buffer[1024];
for (i = 0; i < len; i++) {
fgets(buffer, 1024, src);
if (feof(src)) { break; }
fputs(buffer, stdout);
}
return 0;
}
/* BusyBoxed head(1) */
int
head_main(int argc, char **argv)
{
int i = 1;
char opt;
int len = 10;
/* 1st option is potentially special */
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
int tmplen = atoi(&argv[1][1]);
if (tmplen) { len = tmplen; }
i = 2;
}
/* parse argv[] */
for ( ; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case '-':
case 'h':
usage(head_usage);
default:
fprintf(stderr, "head: invalid option -- %c\n", opt);
usage(head_usage);
}
} else {
break;
}
}
/* get rest of argv[] or stdin if nothing's left */
if (i >= argc) {
head(len, stdin);
} else {
int need_headers = ((argc - i) > 1);
for ( ; i < argc; i++) {
FILE *src;
src = fopen(argv[i], "r");
if (!src) {
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
} else {
/* emulating GNU behaviour */
if (need_headers) {
fprintf(stdout, "==> %s <==\n", argv[i]);
}
head(len, src);
if (i < argc - 1) {
fprintf(stdout, "\n");
}
}
}
}
exit(0);
}
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
+7 -6
View File
@@ -3,11 +3,12 @@
#include <string.h>
#include <stdio.h>
const char length_usage[] = "length string";
int
length_main(struct FileInfo * i, int argc, char * * argv)
extern int
length_main(int argc, char * * argv)
{
printf("%d\n", strlen(argv[1]));
return 0;
if ( **(argv+1) == '-' ) {
usage("length string\n");
}
printf("%d\n", strlen(argv[1]));
return( TRUE);
}
+81 -38
View File
@@ -1,52 +1,95 @@
/*
* Mini ln implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <dirent.h>
#include <errno.h>
const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
"\n"
"\tAdd a new name that refers to the same file as \"original-name\"\n"
"\n"
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
"\t-f:\tRemove existing destination files.\n";
int
ln_fn(const struct FileInfo * i)
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
extern int ln_main(int argc, char **argv)
{
int status = 0;
char d[PATH_MAX];
const char * destination = i->destination;
int status;
static char* linkName;
if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) {
fprintf(stderr, "Please use \"ln -s\" to link directories.\n");
return 1;
}
if (argc < 3) {
usage (ln_usage);
}
argc--;
argv++;
/*
* If the destination is a directory, create a file within it.
*/
if ( is_a_directory(i->destination) ) {
destination = join_paths(
d
,i->destination
,&i->source[i->directoryLength]);
}
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 's':
symlinkFlag = TRUE;
break;
case 'f':
removeoldFlag = TRUE;
break;
default:
usage (ln_usage);
}
argc--;
argv++;
}
if ( i->force )
status = ( unlink(destination) && errno != ENOENT );
if ( status == 0 ) {
if ( i->makeSymbolicLink )
status = symlink(i->source, destination);
else
status = link(i->source, destination);
}
linkName = argv[argc - 1];
if ( status != 0 ) {
name_and_error(destination);
return 1;
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
if (removeoldFlag==TRUE ) {
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, linkName);
else
return 0;
status = link(*argv, linkName);
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
}
}
exit( TRUE);
}
+68 -103
View File
@@ -1,4 +1,3 @@
#include "internal.h"
/*
* tiny-ls.c version 0.1.0: A minimalist 'ls'
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
@@ -41,22 +40,15 @@
* 1. requires lstat (BSD) - how do you do it without?
*/
#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
#define FEATURE_TIMESTAMPS /* show file timestamps */
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
#define FEATURE_FILETYPECHAR /* enable -p and -F */
#undef OP_BUF_SIZE 1024 /* leave undefined for unbuffered output */
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
#define COLUMN_GAP 2 /* includes the file type char, if present */
#define HAS_REWINDDIR
/************************************************************************/
#define HAS_REWINDDIR
#if 1 /* FIXME libc 6 */
#include "internal.h"
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
# include <linux/types.h>
#else
# include <sys/types.h>
@@ -67,17 +59,13 @@
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#ifdef FEATURE_USERNAME
#include <pwd.h>
#include <grp.h>
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
#include <time.h>
#endif
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
#endif
@@ -86,27 +74,6 @@
#define MINOR(dev) ((dev)&0xff)
#endif
#define MODE1 "rwxrwxrwx"
#define MODE0 "---------"
#define SMODE1 "..s..s..t"
#define SMODE0 "..S..S..T"
/* The 9 mode bits to test */
static const umode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const umode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
};
#define FMT_AUTO 0
#define FMT_LONG 1 /* one record per line, extended info */
#define FMT_SINGLE 2 /* one record per line */
@@ -131,14 +98,14 @@ static unsigned char display_fmt = FMT_AUTO;
static unsigned short opts = 0;
static unsigned short column = 0;
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
static unsigned char time_fmt = TIME_MOD;
#endif
@@ -146,7 +113,7 @@ static unsigned char time_fmt = TIME_MOD;
static void writenum(long val, short minwidth)
{
char scratch[20];
char scratch[128];
char *p = scratch + sizeof(scratch);
short len = 0;
@@ -191,8 +158,8 @@ static void tab(short col)
#undef nspaces
}
#ifdef FEATURE_FILETYPECHAR
static char append_char(umode_t mode)
#ifdef BB_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
return '\0';
@@ -209,55 +176,52 @@ static char append_char(umode_t mode)
**
**/
static void list_single(const char *name, struct stat *info)
static void list_single(const char *name, struct stat *info, const char *fullname)
{
char scratch[20];
char scratch[PATH_MAX];
short len = strlen(name);
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
char append = append_char(info->st_mode);
#endif
if (display_fmt == FMT_LONG) {
umode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
for (i=0; i<9; i++)
if (mode & SBIT[i])
scratch[i+1] = (mode & MBIT[i])
? SMODE1[i]
: SMODE0[i];
else
scratch[i+1] = (mode & MBIT[i])
? MODE1[i]
: MODE0[i];
mode_t mode = info->st_mode;
newline();
wr(scratch, 10);
wr(modeString(mode), 10);
column=10;
writenum((long)info->st_nlink,(short)4);
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
#ifdef FEATURE_USERNAME
#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct passwd *pw = getpwuid(info->st_uid);
if (pw)
fputs(pw->pw_name, stdout);
else
writenum((long)info->st_uid,(short)0);
scratch[0]='\0';
my_getpwuid( scratch, info->st_uid);
scratch[8]='\0';
if (*scratch)
wr(scratch,8);
else {
writenum((long) info->st_uid,(short)8);
fputs(" ", stdout);
}
} else
#endif
writenum((long)info->st_uid,(short)0);
tab(24);
#ifdef FEATURE_USERNAME
{
writenum((long) info->st_uid,(short)8);
fputs(" ", stdout);
}
tab(16);
#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct group *gr = getgrgid(info->st_gid);
if (gr)
fputs(gr->gr_name, stdout);
else
writenum((long)info->st_gid,(short)0);
scratch[0]='\0';
my_getgrgid( scratch, info->st_gid);
scratch[8]='\0';
if (*scratch)
wr(scratch,8);
else
writenum((long) info->st_gid,(short)8);
} else
#endif
writenum((long)info->st_gid,(short)0);
tab(33);
writenum((long) info->st_gid,(short)8);
tab(17);
if (S_ISBLK(mode) || S_ISCHR(mode)) {
writenum((long)MAJOR(info->st_rdev),(short)3);
fputs(", ", stdout);
@@ -266,7 +230,7 @@ static void list_single(const char *name, struct stat *info)
else
writenum((long)info->st_size,(short)8);
fputs(" ", stdout);
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
{
time_t cal;
char *string;
@@ -300,12 +264,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len);
if (S_ISLNK(mode)) {
wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(name, info)) {
if (!stat(fullname, info)) {
append = append_char(info->st_mode);
if (append)
fputc(append, stdout);
@@ -313,7 +277,7 @@ static void list_single(const char *name, struct stat *info)
}
#endif
}
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
else if (append)
wr(&append, 1);
#endif
@@ -327,7 +291,7 @@ static void list_single(const char *name, struct stat *info)
newline();
else {
if (nexttab + column_width > terminal_width
#ifndef FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_AUTOWIDTH
|| nexttab + len >= terminal_width
#endif
)
@@ -336,7 +300,7 @@ static void list_single(const char *name, struct stat *info)
tab(nexttab);
}
/* work out where next column starts */
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
/* we know the calculated width is big enough */
nexttab = column + column_width + COLUMN_GAP;
#else
@@ -349,7 +313,7 @@ static void list_single(const char *name, struct stat *info)
/* now write the data */
wr(name, len);
column = column + len;
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
if (append)
wr(&append, 1), column++;
#endif
@@ -375,7 +339,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) {
list_single(name, &info);
list_single(name, &info, name);
return 0;
}
@@ -390,7 +354,7 @@ static int list_item(const char *name)
dir = opendir(name);
if (!dir) goto listerr;
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
column_width = 0;
while ((entry = readdir(dir)) != NULL) {
short w = strlen(entry->d_name);
@@ -427,7 +391,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name);
if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info);
list_single(entry->d_name, &info, fullname);
}
closedir(dir);
return 0;
@@ -436,27 +400,27 @@ direrr:
closedir(dir);
listerr:
newline();
name_and_error(name);
perror(name);
return 1;
}
const char ls_usage[] = "Usage: ls [-1a"
#ifdef FEATURE_TIMESTAMPS
static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_TIMESTAMPS
"c"
#endif
"d"
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
"e"
#endif
"ln"
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
"p"
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
"u"
#endif
"xAC"
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
#ifdef FEATURE_RECURSIVE
@@ -465,7 +429,7 @@ const char ls_usage[] = "Usage: ls [-1a"
"] [filenames...]\n";
extern int
ls_main(struct FileInfo * not_used, int argc, char * * argv)
ls_main(int argc, char * * argv)
{
int argi=1, i;
@@ -489,7 +453,7 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
case '1': display_fmt = FMT_SINGLE; break;
case 'x': display_fmt = FMT_ROWS; break;
case 'C': display_fmt = FMT_COLUMNS; break;
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
case 'p': opts |= DISP_FTYPE; break;
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
#endif
@@ -500,7 +464,7 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
#ifdef FEATURE_RECURSIVE
case 'R': opts |= DIR_RECURSE; break;
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
case 'u': time_fmt = TIME_ACCESS; break;
case 'c': time_fmt = TIME_CHANGE; break;
case 'e': opts |= DISP_FULLTIME; break;
@@ -513,10 +477,10 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
/* choose a display format */
if (display_fmt == FMT_AUTO)
display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
/* could add a -w option and/or TIOCGWINSZ call */
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
@@ -534,9 +498,10 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
while (argi < argc)
i |= list_item(argv[argi++]);
newline();
return i;
exit( i);
print_usage_message:
usage(ls_usage);
return 1;
usage (ls_usage);
exit( FALSE);
}
+95 -46
View File
@@ -1,58 +1,107 @@
/*
* Mini mkdir implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <sys/param.h>
const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n"
"\tCreate directories.\n"
"\n"
"\t-m mode:\tSpecifiy the mode for the new directory\n"
"\t\tunder the argument directory.";
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
"Options:\n"
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-p\tno error if existing, make parent directories as needed\n";
/*make directories skipping the last part of the path. Used here and by untar*/
int mkdir_until(const char *fpath, const struct FileInfo * fi)
static int parentFlag = FALSE;
static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
{
char path[PATH_MAX];
char * s = path;
strcpy(path, fpath);
if ( s[0] == '\0' && s[1] == '\0' ) {
usage(mkdir_usage);
return 1;
}
s++;
while ( *s != '\0' ) {
if ( *s == '/' ) {
int status;
*s = '\0';
status = mkdir(path, (fi?fi->orWithMode:0700) );
*s = '/';
if ( status != 0 ) {
if ( errno != EEXIST ) {
name_and_error(fpath);
return 1;
}
}
int i=FALSE;
argc--;
argv++;
/* Parse any options */
while (argc > 0 && **argv == '-') {
while (i==FALSE && *++(*argv)) {
switch (**argv) {
case 'm':
if (--argc == 0)
usage( mkdir_usage);
/* Find the specified modes */
mode = 0;
if ( parse_mode(*(++argv), &mode) == FALSE ) {
fprintf(stderr, "Unknown mode: %s\n", *argv);
exit( FALSE);
}
s++;
/* Set the umask for this process so it doesn't
* screw up whatever the user just entered. */
umask(0);
i=TRUE;
break;
case 'p':
parentFlag = TRUE;
break;
default:
usage( mkdir_usage);
}
}
return 0;
argc--;
argv++;
}
if (argc < 1) {
usage( mkdir_usage);
}
while (argc > 0) {
int status;
struct stat statBuf;
char buf[NAME_MAX];
strcpy (buf, *argv);
status=stat(buf, &statBuf);
if (status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", buf);
exit( FALSE);
}
if (parentFlag == TRUE) {
strcat( buf, "/");
createPath(buf, mode);
}
else {
if (mkdir (buf, mode) != 0) {
perror(buf);
exit( FALSE);
}
}
argc--;
argv++;
}
exit( TRUE);
}
int
mkdir_fn(const struct FileInfo * i)
{
if ( i->makeParentDirectories ) {
if(mkdir_until(i->source, i)) return 1;
}
if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) {
name_and_error(i->source);
return 1;
}
else
return 0;
}
+31 -11
View File
@@ -1,19 +1,41 @@
/*
* Mini mknod implementation for busybox
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
"\tMake special files.\n"
"\n"
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
"Make block or character special files.\n\n"
"Options:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
int
mknod_main(struct FileInfo * i, int argc, char * * argv)
mknod_main(int argc, char** argv)
{
mode_t mode = 0;
dev_t dev = 0;
@@ -30,23 +52,21 @@ mknod_main(struct FileInfo * i, int argc, char * * argv)
mode = S_IFIFO;
break;
default:
usage(mknod_usage);
return 1;
usage (mknod_usage);
}
if ( mode == S_IFCHR || mode == S_IFBLK ) {
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
if ( argc != 5 ) {
usage(mknod_usage);
return 1;
usage (mknod_usage);
}
}
mode |= 0666;
if ( mknod(argv[1], mode, dev) != 0 ) {
name_and_error(argv[1]);
return 1;
perror(argv[1]);
return( FALSE);
}
return 0;
return( TRUE);
}
+75 -28
View File
@@ -1,38 +1,85 @@
/*
* Mini mv implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
const char mv_usage[] = "mv source-file destination-file\n"
"\t\tmv source-file [source-file ...] destination-directory\n"
"\n"
"\tMove the source files to the destination.\n"
"\n";
extern int
mv_fn(const struct FileInfo * i)
static const char mv_usage[] = "mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
extern int mv_main(int argc, char **argv)
{
struct stat destination_stat;
char d[1024];
struct FileInfo n;
char newdestName[NAME_MAX];
if ( stat(i->destination, &destination_stat) == 0 ) {
if ( i->stat.st_ino == destination_stat.st_ino
&& i->stat.st_dev == destination_stat.st_dev )
return 0; /* Move file to itself. */
if (argc < 3) {
usage (mv_usage);
}
argc--;
argv++;
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(srcName, skipName));
else
strcat(newdestName, srcName);
fprintf(stderr, "srcName='%s'\n", srcName);
fprintf(stderr, "skipName='%s'\n", skipName);
fprintf(stderr, "newdestName='%s'\n", newdestName);
}
if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) {
n = *i;
n.destination = join_paths(d, i->destination, basename(i->source));
i = &n;
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
exit( FALSE);
}
if ( rename(i->source, i->destination) == 0 )
return 0;
else if ( errno == EXDEV && is_a_directory(i->source) ) {
fprintf(stderr
,"%s: Can't move directory across filesystems.\n"
,i->source);
return 1;
if (unlink (srcName) < 0) {
perror (srcName);
exit( FALSE);
}
else
return cp_fn(i);
}
exit( TRUE);
}
+6 -8
View File
@@ -1,8 +1,3 @@
// I may still need some more cleaning...fix my error checking
#include "internal.h"
#ifdef BB_PRINTF
/* printf - format and print data
Copyright (C) 90, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
@@ -51,6 +46,7 @@
// 19990508 Busy Boxed! Dave Cinege
#include "internal.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
@@ -140,15 +136,18 @@ static void verify __P ((char *s, char *end));
/* The value to return to the calling program. */
static int exit_status;
const char printf_usage[] = "Usage: printf format [argument...]\n";
static const char printf_usage[] = "printf format [argument...]\n";
int
printf_main(struct FileInfo * i, int argc, char * * argv)
printf_main(int argc, char** argv)
{
char *format;
int args_used;
exit_status = 0;
if ( **(argv+1) == '-' ) {
usage (printf_usage);
}
format = argv[1];
argc -= 2;
@@ -528,4 +527,3 @@ verify (char *s, char *end)
}
}
#endif
+28 -7
View File
@@ -1,18 +1,39 @@
/*
* Mini pwd implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
const char pwd_usage[] = "Print the current directory.\n";
#include <dirent.h>
extern int
pwd_main(struct FileInfo * i, int argc, char * * argv)
pwd_main(int argc, char * * argv)
{
char buf[1024];
char buf[NAME_MAX];
if ( getcwd(buf, sizeof(buf)) == NULL ) {
name_and_error("get working directory");
return 1;
perror("get working directory");
exit( FALSE);
}
printf("%s\n", buf);
return 0;
exit( TRUE);
}
+92 -20
View File
@@ -1,30 +1,102 @@
/*
* Mini rm implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
#include <errno.h>
const char rm_usage[] = "rm [-r] file [file ...]\n"
"\n"
"\tDelete files.\n"
"\n"
"\t-r:\tRecursively remove files and directories.\n";
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\t\tremove existing destinations, never prompt\n"
"\t-r or -R\tremove the contents of directories recursively\n";
extern int
rm_main(struct FileInfo * i, int argc, char * * argv)
static int recursiveFlag = FALSE;
static int forceFlag = FALSE;
static const char *srcName;
static int fileAction(const char *fileName, struct stat* statbuf)
{
i->processDirectoriesAfterTheirContents = 1;
return monadic_main(i, argc, argv);
if (unlink( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
extern int
rm_fn(const struct FileInfo * i)
static int dirAction(const char *fileName, struct stat* statbuf)
{
if ( i->recursive
&& !i->isSymbolicLink
&& (i->stat.st_mode & S_IFMT) == S_IFDIR )
return rmdir_fn(i);
else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) {
name_and_error(i->source);
return 1;
if (rmdir( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
extern int rm_main(int argc, char **argv)
{
struct stat statbuf;
if (argc < 2) {
usage( rm_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'R':
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
default:
usage( rm_usage);
}
argc--;
argv++;
}
while (argc-- > 0) {
srcName = *(argv++);
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
}
else
return 0;
else {
if (recursiveAction( srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction) == FALSE) {
exit( FALSE);
}
}
}
exit( TRUE);
}
+35 -10
View File
@@ -1,17 +1,42 @@
/*
* Mini rmdir implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <errno.h>
const char rmdir_usage[] = "rmdir directory [directory ...]\n"
"\n"
"\tDelete directories.\n";
extern int
rmdir_fn(const struct FileInfo * i)
extern int rmdir_main(int argc, char **argv)
{
if ( rmdir(i->source) != 0 && errno != ENOENT && !i->force ) {
name_and_error(i->source);
return 1;
if ( argc==1 || **(argv+1) == '-' ) {
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
}
while (--argc > 0) {
if ( rmdir(*(++argv)) == -1 ) {
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
exit(FALSE);
}
else
return 0;
}
exit(TRUE);
}
+34 -8
View File
@@ -1,15 +1,41 @@
/*
* Mini sleep implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
const char sleep_usage[] = "sleep seconds\n"
"\n"
"\tPause program execution for the given number of seconds.\n";
const char sleep_usage[] = "sleep N\n\n"
"Pause for N seconds.\n";
extern int
sleep_main(struct FileInfo * i, int argc, char * * argv)
sleep_main(int argc, char * * argv)
{
if ( sleep(atoi(argv[1])) != 0 )
return -1;
else
return 0;
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( sleep_usage );
}
if ( sleep(atoi(*(++argv))) != 0 ) {
perror( "sleep");
exit (FALSE);
} else
exit (TRUE);
}
+29 -6
View File
@@ -1,11 +1,34 @@
#include "internal.h"
/*
* Mini sync implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
const char sync_usage[] = "sync\n"
"\n"
"\tWrite all buffered filesystem blocks to disk.\n";
#include "internal.h"
#include <stdio.h>
extern int
sync_main(struct FileInfo * i, int argc, char * * argv)
sync_main(int argc, char * * argv)
{
return sync();
if ( argc>1 && **(argv+1) == '-' ) {
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
}
exit( sync());
}
+909
View File
@@ -0,0 +1,909 @@
/* tail -- output the last part of file(s)
Copyright (C) 89, 90, 91, 95, 1996 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Original version by Paul Rubin <phr@ocf.berkeley.edu>.
Extensions by David MacKenzie <djm@gnu.ai.mit.edu>.
tail -f for multiple files by Ian Lance Taylor <ian@airs.com>.
Rewrote the option parser, removed locales support,
and generally busyboxed, Erik Andersen <andersen@lineo.com>
*/
#include "internal.h"
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
/* Disable assertions. Some systems have broken assert macros. */
#define NDEBUG 1
static void error(int i, int errnum, char* fmt, ...)
{
va_list arguments;
va_start(arguments, fmt);
vfprintf(stderr, fmt, arguments);
fprintf(stderr, "\n%s\n", strerror( errnum));
va_end(arguments);
exit(i);
}
#define XWRITE(fd, buffer, n_bytes) \
do \
{ \
assert ((fd) == 1); \
assert ((n_bytes) >= 0); \
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
error (EXIT_FAILURE, errno, "write error"); \
} \
while (0)
/* Number of items to tail. */
#define DEFAULT_N_LINES 10
/* Size of atomic reads. */
#ifndef BUFSIZ
#define BUFSIZ (512 * 8)
#endif
/* If nonzero, interpret the numeric argument as the number of lines.
Otherwise, interpret it as the number of bytes. */
static int count_lines;
/* If nonzero, read from the end of one file until killed. */
static int forever;
/* If nonzero, read from the end of multiple files until killed. */
static int forever_multiple;
/* Array of file descriptors if forever_multiple is 1. */
static int *file_descs;
/* Array of file sizes if forever_multiple is 1. */
static off_t *file_sizes;
/* If nonzero, count from start of file instead of end. */
static int from_start;
/* If nonzero, print filename headers. */
static int print_headers;
/* When to print the filename banners. */
enum header_mode
{
multiple_files, always, never
};
char *xmalloc ();
/* The name this program was run with. */
char *program_name;
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
static const char tail_usage[] =
"tail [OPTION]... [FILE]...\n\
\n\
Print last 10 lines of each FILE to standard output.\n\
With more than one FILE, precede each with a header giving the file name.\n\
With no FILE, or when FILE is -, read standard input.\n\
\n\
-c=N[kbm] output the last N bytes\n\
-f output appended data as the file grows\n\
-n=N output the last N lines, instead of last 10\n\
-q never output headers giving file names\n\
-v always output headers giving file names\n\
--help display this help and exit\n\
\n\
If the first character of N (bytes or lines) is a `+', output begins with \n\
the Nth item from the start of each file, otherwise, print the last N items\n\
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n\n";
static void
write_header (const char *filename, const char *comment)
{
static int first_file = 1;
printf ("%s==> %s%s%s <==\n", (first_file ? "" : "\n"), filename,
(comment ? ": " : ""),
(comment ? comment : ""));
first_file = 0;
}
/* Print the last N_LINES lines from the end of file FD.
Go backward through the file, reading `BUFSIZ' bytes at a time (except
probably the first), until we hit the start of the file or have
read NUMBER newlines.
POS starts out as the length of the file (the offset of the last
byte of the file + 1).
Return 0 if successful, 1 if an error occurred. */
static int
file_lines (const char *filename, int fd, long int n_lines, off_t pos)
{
char buffer[BUFSIZ];
int bytes_read;
int i; /* Index into `buffer' for scanning. */
if (n_lines == 0)
return 0;
/* Set `bytes_read' to the size of the last, probably partial, buffer;
0 < `bytes_read' <= `BUFSIZ'. */
bytes_read = pos % BUFSIZ;
if (bytes_read == 0)
bytes_read = BUFSIZ;
/* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all
reads will be on block boundaries, which might increase efficiency. */
pos -= bytes_read;
lseek (fd, pos, SEEK_SET);
bytes_read = fullRead (fd, buffer, bytes_read);
if (bytes_read == -1)
{
error (0, errno, "%s", filename);
return 1;
}
/* Count the incomplete line on files that don't end with a newline. */
if (bytes_read && buffer[bytes_read - 1] != '\n')
--n_lines;
do
{
/* Scan backward, counting the newlines in this bufferfull. */
for (i = bytes_read - 1; i >= 0; i--)
{
/* Have we counted the requested number of newlines yet? */
if (buffer[i] == '\n' && n_lines-- == 0)
{
/* If this newline wasn't the last character in the buffer,
print the text after it. */
if (i != bytes_read - 1)
XWRITE (STDOUT_FILENO, &buffer[i + 1], bytes_read - (i + 1));
return 0;
}
}
/* Not enough newlines in that bufferfull. */
if (pos == 0)
{
/* Not enough lines in the file; print the entire file. */
lseek (fd, (off_t) 0, SEEK_SET);
return 0;
}
pos -= BUFSIZ;
lseek (fd, pos, SEEK_SET);
}
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0);
if (bytes_read == -1)
{
error (0, errno, "%s", filename);
return 1;
}
return 0;
}
/* Print the last N_LINES lines from the end of the standard input,
open for reading as pipe FD.
Buffer the text as a linked list of LBUFFERs, adding them as needed.
Return 0 if successful, 1 if an error occured. */
static int
pipe_lines (const char *filename, int fd, long int n_lines)
{
struct linebuffer
{
int nbytes, nlines;
char buffer[BUFSIZ];
struct linebuffer *next;
};
typedef struct linebuffer LBUFFER;
LBUFFER *first, *last, *tmp;
int i; /* Index into buffers. */
int total_lines = 0; /* Total number of newlines in all buffers. */
int errors = 0;
first = last = (LBUFFER *) xmalloc (sizeof (LBUFFER));
first->nbytes = first->nlines = 0;
first->next = NULL;
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
/* Input is always read into a fresh buffer. */
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
{
tmp->nlines = 0;
tmp->next = NULL;
/* Count the number of newlines just read. */
for (i = 0; i < tmp->nbytes; i++)
if (tmp->buffer[i] == '\n')
++tmp->nlines;
total_lines += tmp->nlines;
/* If there is enough room in the last buffer read, just append the new
one to it. This is because when reading from a pipe, `nbytes' can
often be very small. */
if (tmp->nbytes + last->nbytes < BUFSIZ)
{
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
last->nbytes += tmp->nbytes;
last->nlines += tmp->nlines;
}
else
{
/* If there's not enough room, link the new buffer onto the end of
the list, then either free up the oldest buffer for the next
read if that would leave enough lines, or else malloc a new one.
Some compaction mechanism is possible but probably not
worthwhile. */
last = last->next = tmp;
if (total_lines - first->nlines > n_lines)
{
tmp = first;
total_lines -= first->nlines;
first = first->next;
}
else
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
}
}
if (tmp->nbytes == -1)
{
error (0, errno, "%s", filename);
errors = 1;
free ((char *) tmp);
goto free_lbuffers;
}
free ((char *) tmp);
/* This prevents a core dump when the pipe contains no newlines. */
if (n_lines == 0)
goto free_lbuffers;
/* Count the incomplete line on files that don't end with a newline. */
if (last->buffer[last->nbytes - 1] != '\n')
{
++last->nlines;
++total_lines;
}
/* Run through the list, printing lines. First, skip over unneeded
buffers. */
for (tmp = first; total_lines - tmp->nlines > n_lines; tmp = tmp->next)
total_lines -= tmp->nlines;
/* Find the correct beginning, then print the rest of the file. */
if (total_lines > n_lines)
{
char *cp;
/* Skip `total_lines' - `n_lines' newlines. We made sure that
`total_lines' - `n_lines' <= `tmp->nlines'. */
cp = tmp->buffer;
for (i = total_lines - n_lines; i; --i)
while (*cp++ != '\n')
/* Do nothing. */ ;
i = cp - tmp->buffer;
}
else
i = 0;
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
for (tmp = tmp->next; tmp; tmp = tmp->next)
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
free_lbuffers:
while (first)
{
tmp = first->next;
free ((char *) first);
first = tmp;
}
return errors;
}
/* Print the last N_BYTES characters from the end of pipe FD.
This is a stripped down version of pipe_lines.
Return 0 if successful, 1 if an error occurred. */
static int
pipe_bytes (const char *filename, int fd, off_t n_bytes)
{
struct charbuffer
{
int nbytes;
char buffer[BUFSIZ];
struct charbuffer *next;
};
typedef struct charbuffer CBUFFER;
CBUFFER *first, *last, *tmp;
int i; /* Index into buffers. */
int total_bytes = 0; /* Total characters in all buffers. */
int errors = 0;
first = last = (CBUFFER *) xmalloc (sizeof (CBUFFER));
first->nbytes = 0;
first->next = NULL;
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
/* Input is always read into a fresh buffer. */
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
{
tmp->next = NULL;
total_bytes += tmp->nbytes;
/* If there is enough room in the last buffer read, just append the new
one to it. This is because when reading from a pipe, `nbytes' can
often be very small. */
if (tmp->nbytes + last->nbytes < BUFSIZ)
{
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
last->nbytes += tmp->nbytes;
}
else
{
/* If there's not enough room, link the new buffer onto the end of
the list, then either free up the oldest buffer for the next
read if that would leave enough characters, or else malloc a new
one. Some compaction mechanism is possible but probably not
worthwhile. */
last = last->next = tmp;
if (total_bytes - first->nbytes > n_bytes)
{
tmp = first;
total_bytes -= first->nbytes;
first = first->next;
}
else
{
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
}
}
}
if (tmp->nbytes == -1)
{
error (0, errno, "%s", filename);
errors = 1;
free ((char *) tmp);
goto free_cbuffers;
}
free ((char *) tmp);
/* Run through the list, printing characters. First, skip over unneeded
buffers. */
for (tmp = first; total_bytes - tmp->nbytes > n_bytes; tmp = tmp->next)
total_bytes -= tmp->nbytes;
/* Find the correct beginning, then print the rest of the file.
We made sure that `total_bytes' - `n_bytes' <= `tmp->nbytes'. */
if (total_bytes > n_bytes)
i = total_bytes - n_bytes;
else
i = 0;
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
for (tmp = tmp->next; tmp; tmp = tmp->next)
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
free_cbuffers:
while (first)
{
tmp = first->next;
free ((char *) first);
first = tmp;
}
return errors;
}
/* Skip N_BYTES characters from the start of pipe FD, and print
any extra characters that were read beyond that.
Return 1 on error, 0 if ok. */
static int
start_bytes (const char *filename, int fd, off_t n_bytes)
{
char buffer[BUFSIZ];
int bytes_read = 0;
while (n_bytes > 0 && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
n_bytes -= bytes_read;
if (bytes_read == -1)
{
error (0, errno, "%s", filename);
return 1;
}
else if (n_bytes < 0)
XWRITE (STDOUT_FILENO, &buffer[bytes_read + n_bytes], -n_bytes);
return 0;
}
/* Skip N_LINES lines at the start of file or pipe FD, and print
any extra characters that were read beyond that.
Return 1 on error, 0 if ok. */
static int
start_lines (const char *filename, int fd, long int n_lines)
{
char buffer[BUFSIZ];
int bytes_read = 0;
int bytes_to_skip = 0;
while (n_lines && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
{
bytes_to_skip = 0;
while (bytes_to_skip < bytes_read)
if (buffer[bytes_to_skip++] == '\n' && --n_lines == 0)
break;
}
if (bytes_read == -1)
{
error (0, errno, "%s", filename);
return 1;
}
else if (bytes_to_skip < bytes_read)
{
XWRITE (STDOUT_FILENO, &buffer[bytes_to_skip],
bytes_read - bytes_to_skip);
}
return 0;
}
/* Display file FILENAME from the current position in FD to the end.
If `forever' is nonzero, keep reading from the end of the file
until killed. Return the number of bytes read from the file. */
static long
dump_remainder (const char *filename, int fd)
{
char buffer[BUFSIZ];
int bytes_read;
long total;
total = 0;
output:
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
{
XWRITE (STDOUT_FILENO, buffer, bytes_read);
total += bytes_read;
}
if (bytes_read == -1)
error (EXIT_FAILURE, errno, "%s", filename);
if (forever)
{
fflush (stdout);
sleep (1);
goto output;
}
else
{
if (forever_multiple)
fflush (stdout);
}
return total;
}
/* Tail NFILES (>1) files forever until killed. The file names are in
NAMES. The open file descriptors are in `file_descs', and the size
at which we stopped tailing them is in `file_sizes'. We loop over
each of them, doing an fstat to see if they have changed size. If
none of them have changed size in one iteration, we sleep for a
second and try again. We do this until the user interrupts us. */
static void
tail_forever (char **names, int nfiles)
{
int last;
last = -1;
while (1)
{
int i;
int changed;
changed = 0;
for (i = 0; i < nfiles; i++)
{
struct stat stats;
if (file_descs[i] < 0)
continue;
if (fstat (file_descs[i], &stats) < 0)
{
error (0, errno, "%s", names[i]);
file_descs[i] = -1;
continue;
}
if (stats.st_size == file_sizes[i])
continue;
/* This file has changed size. Print out what we can, and
then keep looping. */
changed = 1;
if (stats.st_size < file_sizes[i])
{
write_header (names[i], "file truncated");
last = i;
lseek (file_descs[i], stats.st_size, SEEK_SET);
file_sizes[i] = stats.st_size;
continue;
}
if (i != last)
{
if (print_headers)
write_header (names[i], NULL);
last = i;
}
file_sizes[i] += dump_remainder (names[i], file_descs[i]);
}
/* If none of the files changed size, sleep. */
if (! changed)
sleep (1);
}
}
/* Output the last N_BYTES bytes of file FILENAME open for reading in FD.
Return 0 if successful, 1 if an error occurred. */
static int
tail_bytes (const char *filename, int fd, off_t n_bytes)
{
struct stat stats;
/* FIXME: resolve this like in dd.c. */
/* Use fstat instead of checking for errno == ESPIPE because
lseek doesn't work on some special files but doesn't return an
error, either. */
if (fstat (fd, &stats))
{
error (0, errno, "%s", filename);
return 1;
}
if (from_start)
{
if (S_ISREG (stats.st_mode))
lseek (fd, n_bytes, SEEK_CUR);
else if (start_bytes (filename, fd, n_bytes))
return 1;
dump_remainder (filename, fd);
}
else
{
if (S_ISREG (stats.st_mode))
{
off_t current_pos, end_pos;
size_t bytes_remaining;
if ((current_pos = lseek (fd, (off_t) 0, SEEK_CUR)) != -1
&& (end_pos = lseek (fd, (off_t) 0, SEEK_END)) != -1)
{
off_t diff;
/* Be careful here. The current position may actually be
beyond the end of the file. */
bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff;
}
else
{
error (0, errno, "%s", filename);
return 1;
}
if (bytes_remaining <= n_bytes)
{
/* From the current position to end of file, there are no
more bytes than have been requested. So reposition the
file pointer to the incoming current position and print
everything after that. */
lseek (fd, current_pos, SEEK_SET);
}
else
{
/* There are more bytes remaining than were requested.
Back up. */
lseek (fd, -n_bytes, SEEK_END);
}
dump_remainder (filename, fd);
}
else
return pipe_bytes (filename, fd, n_bytes);
}
return 0;
}
/* Output the last N_LINES lines of file FILENAME open for reading in FD.
Return 0 if successful, 1 if an error occurred. */
static int
tail_lines (const char *filename, int fd, long int n_lines)
{
struct stat stats;
off_t length;
if (fstat (fd, &stats))
{
error (0, errno, "%s", filename);
return 1;
}
if (from_start)
{
if (start_lines (filename, fd, n_lines))
return 1;
dump_remainder (filename, fd);
}
else
{
/* Use file_lines only if FD refers to a regular file with
its file pointer positioned at beginning of file. */
/* FIXME: adding the lseek conjunct is a kludge.
Once there's a reasonable test suite, fix the true culprit:
file_lines. file_lines shouldn't presume that the input
file pointer is initially positioned to beginning of file. */
if (S_ISREG (stats.st_mode)
&& lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0)
{
length = lseek (fd, (off_t) 0, SEEK_END);
if (length != 0 && file_lines (filename, fd, n_lines, length))
return 1;
dump_remainder (filename, fd);
}
else
return pipe_lines (filename, fd, n_lines);
}
return 0;
}
/* Display the last N_UNITS units of file FILENAME, open for reading
in FD.
Return 0 if successful, 1 if an error occurred. */
static int
tail (const char *filename, int fd, off_t n_units)
{
if (count_lines)
return tail_lines (filename, fd, (long) n_units);
else
return tail_bytes (filename, fd, n_units);
}
/* Display the last N_UNITS units of file FILENAME.
"-" for FILENAME means the standard input.
FILENUM is this file's index in the list of files the user gave.
Return 0 if successful, 1 if an error occurred. */
static int
tail_file (const char *filename, off_t n_units, int filenum)
{
int fd, errors;
struct stat stats;
if (!strcmp (filename, "-"))
{
have_read_stdin = 1;
filename = "standard input";
if (print_headers)
write_header (filename, NULL);
errors = tail (filename, 0, n_units);
if (forever_multiple)
{
if (fstat (0, &stats) < 0)
{
error (0, errno, "standard input");
errors = 1;
}
else if (!S_ISREG (stats.st_mode))
{
error (0, 0,
"standard input: cannot follow end of non-regular file");
errors = 1;
}
if (errors)
file_descs[filenum] = -1;
else
{
file_descs[filenum] = 0;
file_sizes[filenum] = stats.st_size;
}
}
}
else
{
/* Not standard input. */
fd = open (filename, O_RDONLY);
if (fd == -1)
{
if (forever_multiple)
file_descs[filenum] = -1;
error (0, errno, "%s", filename);
errors = 1;
}
else
{
if (print_headers)
write_header (filename, NULL);
errors = tail (filename, fd, n_units);
if (forever_multiple)
{
if (fstat (fd, &stats) < 0)
{
error (0, errno, "%s", filename);
errors = 1;
}
else if (!S_ISREG (stats.st_mode))
{
error (0, 0, "%s: cannot follow end of non-regular file",
filename);
errors = 1;
}
if (errors)
{
close (fd);
file_descs[filenum] = -1;
}
else
{
file_descs[filenum] = fd;
file_sizes[filenum] = stats.st_size;
}
}
else
{
if (close (fd))
{
error (0, errno, "%s", filename);
errors = 1;
}
}
}
}
return errors;
}
extern int
tail_main (int argc, char **argv)
{
int stopit = 0;
enum header_mode header_mode = multiple_files;
int exit_status = 0;
/* If from_start, the number of items to skip before printing; otherwise,
the number of items at the end of the file to print. Initially, -1
means the value has not been set. */
off_t n_units = -1;
int n_files;
char **file;
program_name = argv[0];
have_read_stdin = 0;
count_lines = 1;
forever = forever_multiple = from_start = print_headers = 0;
/* Parse any options */
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
while (--argc > 0 && ( **(++argv) == '-' || **argv == '+' )) {
if (**argv == '+') {
from_start = 1;
}
stopit = 0;
while (stopit == 0 && *(++(*argv))) {
switch (**argv) {
case 'c':
count_lines = 0;
if (--argc < 1) {
usage(tail_usage);
}
n_units = getNum(*(++argv));
stopit = 1;
break;
case 'f':
forever = 1;
break;
case 'n':
count_lines = 1;
if (--argc < 1) {
usage(tail_usage);
}
n_units = atol(*(++argv));
stopit = 1;
break;
case 'q':
header_mode = never;
break;
case 'v':
header_mode = always;
break;
default:
usage (tail_usage);
}
}
}
if (n_units == -1)
n_units = DEFAULT_N_LINES;
/* To start printing with item N_UNITS from the start of the file, skip
N_UNITS - 1 items. `tail +0' is actually meaningless, but for Unix
compatibility it's treated the same as `tail +1'. */
if (from_start)
{
if (n_units)
--n_units;
}
n_files = argc;
file = argv;
if (n_files > 1 && forever)
{
forever_multiple = 1;
forever = 0;
file_descs = (int *) xmalloc (n_files * sizeof (int));
file_sizes = (off_t *) xmalloc (n_files * sizeof (off_t));
}
if (header_mode == always
|| (header_mode == multiple_files && n_files > 1))
print_headers = 1;
if (n_files == 0)
{
exit_status |= tail_file ("-", n_units, 0);
}
else
{
int i;
for (i = 0; i < n_files; i++)
exit_status |= tail_file (file[i], n_units, i);
if (forever_multiple)
tail_forever (file, n_files);
}
if (have_read_stdin && close (0) < 0)
error (EXIT_FAILURE, errno, "-");
if (fclose (stdout) == EOF)
error (EXIT_FAILURE, errno, "write error");
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
+126
View File
@@ -0,0 +1,126 @@
/*
* Mini tee implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
static const char tee_usage[] =
"tee [OPTION]... [FILE]...\n\n"
"Copy standard input to each FILE, and also to standard output.\n\n"
"Options:\n"
"\t-a\tappend to the given FILEs, do not overwrite\n"
#if 0
"\t-i\tignore interrupt signals\n"
#endif
;
/* FileList _______________________________________________________________ */
#define FL_MAX 1024
static FILE *FileList[FL_MAX];
static int FL_end;
typedef void (FL_Function)(FILE *file, char c);
/* apply a function to everything in FileList */
static void
FL_apply(FL_Function *f, char c)
{
int i;
for (i = 0; i <= FL_end; i++) {
f(FileList[i], c);
}
}
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
{
fputc(c, file);
}
/* FL_Function for closing files */
static void
tee_fclose(FILE *file, char c)
{
fclose(file);
}
/* ________________________________________________________________________ */
/* BusyBoxed tee(1) */
int
tee_main(int argc, char **argv)
{
int i;
char c;
char opt;
char opt_fopen[2] = "w";
FILE *file;
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'a':
opt_fopen[0] = 'a';
break;
#if 0
case 'i':
fprintf(stderr, "ignore interrupt not implemented\n");
break;
#endif
default:
usage(tee_usage);
}
} else {
break;
}
}
/* init FILE pointers */
FL_end = 0;
FileList[0] = stdout;
for ( ; i < argc; i++) {
/* add a file to FileList */
file = fopen(argv[i], opt_fopen);
if (!file) { continue; }
if (FL_end < FL_MAX) {
FileList[++FL_end] = file;
}
}
/* read and redirect */
while ((c = (char) getchar()) && (!feof(stdin))) {
FL_apply(tee_fwrite, c);
}
/* clean up */
FL_apply(tee_fclose, 0);
exit(0);
}
/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
+78 -12
View File
@@ -1,20 +1,86 @@
/*
* Mini touch implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <sys/types.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utime.h>
#include <errno.h>
const char touch_usage[] = "touch [-c] file [file ...]\n"
"\n"
"\tUpdate the last-modified date on the given file[s].\n";
extern int
touch_fn(const struct FileInfo * i)
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
"Update the last-modified date on the given file[s].\n";
extern int
touch_main(int argc, char **argv)
{
if ( (utime(i->source, 0) != 0) && (i->create != 1) ) {
if ( fopen(i->source, "w") == NULL ) {
name_and_error(i->source);
return 1;
}
int fd;
int create=TRUE;
if (argc < 2) {
usage( touch_usage);
}
argc--;
argv++;
/* Parse options */
while (**argv == '-') {
while (*++(*argv)) switch (**argv) {
case 'c':
create = FALSE;
break;
default:
usage( touch_usage);
exit( FALSE);
}
return 0;
argc--;
argv++;
}
fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644);
if (fd < 0 ) {
if (create==FALSE && errno == ENOENT)
exit( TRUE);
else {
perror("touch");
exit( FALSE);
}
}
close( fd);
if (utime (*argv, NULL)) {
perror("touch");
exit( FALSE);
}
else
exit( TRUE);
}
+166
View File
@@ -0,0 +1,166 @@
/* uname -- print system information
Copyright (C) 1989-1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Option Example
-s, --sysname SunOS
-n, --nodename rocky8
-r, --release 4.0
-v, --version
-m, --machine sun
-a, --all SunOS rocky8 4.0 sun
The default behavior is equivalent to `-s'.
David MacKenzie <djm@gnu.ai.mit.edu> */
/* Busyboxed by Erik Andersen */
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/utsname.h>
#if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
# include <sys/systeminfo.h>
#endif
static const char uname_usage[] =
"uname [OPTION]...\n\n"
"Print certain system information. With no OPTION, same as -s.\n\n"
"Options:\n"
"\t-a\tprint all information\n"
"\t-m\tthe machine (hardware) type\n"
"\t-n\tprint the machine's network node hostname\n"
"\t-r\tprint the operating system release\n"
"\t-s\tprint the operating system name\n"
"\t-p\tprint the host processor type\n"
"\t-v\tprint the operating system version\n";
static void print_element(unsigned int mask, char *element);
/* Values that are bitwise or'd into `toprint'. */
/* Operating system name. */
#define PRINT_SYSNAME 1
/* Node name on a communications network. */
#define PRINT_NODENAME 2
/* Operating system release. */
#define PRINT_RELEASE 4
/* Operating system version. */
#define PRINT_VERSION 8
/* Machine hardware name. */
#define PRINT_MACHINE 16
/* Host processor type. */
#define PRINT_PROCESSOR 32
/* Mask indicating which elements of the name to print. */
static unsigned char toprint;
int uname_main(int argc, char **argv)
{
struct utsname name;
char processor[256];
#if defined(__sparc__) && defined(__linux__)
char *fake_sparc = getenv("FAKE_SPARC");
#endif
toprint = 0;
/* Parse any options */
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
while (--argc > 0 && **(++argv) == '-') {
while (*(++(*argv))) {
switch (**argv) {
case 's':
toprint |= PRINT_SYSNAME;
break;
case 'n':
toprint |= PRINT_NODENAME;
break;
case 'r':
toprint |= PRINT_RELEASE;
break;
case 'v':
toprint |= PRINT_VERSION;
break;
case 'm':
toprint |= PRINT_MACHINE;
break;
case 'p':
toprint |= PRINT_PROCESSOR;
break;
case 'a':
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
PRINT_PROCESSOR | PRINT_VERSION |
PRINT_MACHINE);
break;
default:
usage(uname_usage);
}
}
}
if (toprint == 0)
toprint = PRINT_SYSNAME;
if (uname(&name) == -1)
perror("cannot get system name");
#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
perror("cannot get processor type");
}
#else
strcpy(processor, "unknown");
#endif
#if defined(__sparc__) && defined(__linux__)
if (fake_sparc != NULL
&& (fake_sparc[0] == 'y'
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
#endif
print_element(PRINT_SYSNAME, name.sysname);
print_element(PRINT_NODENAME, name.nodename);
print_element(PRINT_RELEASE, name.release);
print_element(PRINT_VERSION, name.version);
print_element(PRINT_MACHINE, name.machine);
print_element(PRINT_PROCESSOR, processor);
exit(TRUE);
}
/* If the name element set in MASK is selected for printing in `toprint',
print ELEMENT; then print a space unless it is the last element to
be printed, in which case print a newline. */
static void print_element(unsigned int mask, char *element)
{
if (toprint & mask) {
toprint &= ~mask;
printf("%s%c", element, toprint ? ' ' : '\n');
}
}
+103 -75
View File
@@ -1,89 +1,117 @@
/*
* Mini cp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/param.h>
#include <errno.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
const char cp_usage[] = "cp [-r] source-file destination-file\n"
"\t\tcp [-r] source-file [source-file ...] destination-directory\n"
"\n"
"\tCopy the source files to the destination.\n"
"\n"
"\t-r:\tRecursively copy all files and directories\n"
"\t\tunder the argument directory.";
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
"\t-d\tpreserve links\n"
"\t-p\tpreserve file attributes if possable\n"
"\t-R\tcopy directories recursively\n";
extern int
cp_fn(const struct FileInfo * i)
static int recursiveFlag = FALSE;
static int followLinks = FALSE;
static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
int sourceFd;
int destinationFd;
const char * destination = i->destination;
struct stat destination_stat;
int status;
char buf[8192];
char d[PATH_MAX];
if ( (i->stat.st_mode & S_IFMT) == S_IFDIR ) {
if ( mkdir(destination, i->stat.st_mode & ~S_IFMT)
!= 0 && errno != EEXIST ) {
name_and_error(destination);
return 1;
}
return 0;
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
if ( (sourceFd = open(i->source, O_RDONLY)) < 0 ) {
name_and_error(i->source);
return 1;
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
if (argc < 3) {
usage (cp_usage);
}
if ( stat(destination, &destination_stat) == 0 ) {
if ( i->stat.st_ino == destination_stat.st_ino
&& i->stat.st_dev == destination_stat.st_dev ) {
fprintf(stderr
,"copy of %s to %s would copy file to itself.\n"
,i->source
,destination);
close(sourceFd);
return 1;
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'a':
followLinks = TRUE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = TRUE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
default:
usage (cp_usage);
}
argc--;
argv++;
}
/*
* If the destination is a directory, create a file within it.
*/
if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) {
destination = join_paths(
d
,i->destination
,&i->source[i->directoryLength]);
if ( stat(destination, &destination_stat) == 0 ) {
if ( i->stat.st_ino == destination_stat.st_ino
&& i->stat.st_dev == destination_stat.st_dev ) {
fprintf(stderr
,"copy of %s to %s would copy file to itself.\n"
,i->source
,destination);
close(sourceFd);
return 1;
}
}
}
destinationFd = creat(destination, i->stat.st_mode & 07777);
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
while ( (status = read(sourceFd, buf, sizeof(buf))) > 0 ) {
if ( write(destinationFd, buf, status) != status ) {
name_and_error(destination);
close(sourceFd);
close(destinationFd);
return 1;
}
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
close(sourceFd);
close(destinationFd);
if ( status < 0 ) {
name_and_error(i->source);
return 1;
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
return 0;
exit( TRUE);
}
+76 -94
View File
@@ -1,3 +1,24 @@
/*
* Mini date implementation for busybox
*
* by Matthew Grant <grantma@anathoth.gen.nz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdlib.h>
#include <errno.h>
@@ -5,7 +26,6 @@
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@@ -14,19 +34,12 @@
an RFC 822 complient date output for shell scripting
mail commands */
const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n | [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]";
static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
/* {"rfc-822", no_argument, NULL, 'R'},
{"set", required_argument, NULL, 's'},
{"uct", no_argument, NULL, 'u'},
{"utc", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'}, */
{NULL, 0, NULL, 0}
};
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
@@ -47,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
/* correct for century - minor Y2K problem here? */
@@ -141,99 +154,67 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
void
date_err(void) {
fprintf(stderr, "date: only one date argument can be given at a time.\n");
exit(1);
}
int
date_main(struct FileInfo * i, int argc, char * * argv)
date_main(int argc, char * * argv)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
int n_args;
time_t tm;
struct tm tm_time;
char optc;
/* Interpret command line args */
while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL))
!= EOF) {
switch (optc) {
case 0:
break;
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
return(1);
}
#if LOCALTIME_CACHE
tzset ();
#endif break;
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
default:
usage(date_usage);
break;
i = --argc;
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case '-':
usage ( date_usage);
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
usage ( date_usage);
}
}
i--;
argv++;
}
}
n_args = argc - optind;
while (n_args--){
switch(argv[optind][0]) {
case '+':
/* Date format strings */
if(date_fmt != NULL) {
fprintf(stderr, "date: only one date format can be given.\n");
return(1);
}
date_fmt = &argv[optind][1];
break;
case '\0':
break;
default:
/* Anything left over must be a date string to set the time */
set_time = 1;
if(date_str != NULL) date_err();
date_str = argv[optind];
break;
}
optind++;
}
/* Now we have parsed all the information except the date format
@@ -261,14 +242,14 @@ date_main(struct FileInfo * i, int argc, char * * argv)
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit(1);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit(1);
exit( FALSE);
}
}
}
@@ -286,7 +267,7 @@ date_main(struct FileInfo * i, int argc, char * * argv)
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
return(0);
exit( TRUE);
}
/* Handle special conversions */
@@ -300,6 +281,7 @@ date_main(struct FileInfo * i, int argc, char * * argv)
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(0);
exit( TRUE);
}
+181 -294
View File
@@ -1,307 +1,194 @@
/*
* Mini dd implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based in part on code taken from sash.
*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
* The "dd" command, originally taken from sash.
*
* Permission to distribute this code under the GPL has been granted.
* Majorly modified, and bugs fixed for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#ifdef BB_DD
const char dd_usage[] =
"Copy a file, converting and formatting according to options\n\
\n\
usage: [if=name] [of=name] [bs=n] [count=n]\n\
\tif=FILE\tread from FILE instead of stdin\n\
\tof=FILE\twrite to FILE instead of stout\n\
\tbs=n\tread and write N bytes at a time\n\
\tcount=n\tcopy only n input blocks\n\
\n\
BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
#include <features.h>
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#define PAR_NONE 0
#define PAR_IF 1
#define PAR_OF 2
#define PAR_BS 3
#define PAR_COUNT 4
typedef struct
{
const char * name;
int value;
} PARAM;
static const PARAM params[] =
{
{"if", PAR_IF},
{"of", PAR_OF},
{"bs", PAR_BS},
{"count", PAR_COUNT},
{NULL, PAR_NONE}
};
static long getNum(const char * cp);
extern int
dd_main (struct FileInfo *unused, int argc, char **argv)
{
const char * str;
const PARAM * par;
const char * inFile;
const char * outFile;
char * cp;
int inFd;
int outFd;
int inCc=0;
int outCc;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char* buf;
unsigned char localBuf[BUF_SIZE];
inFile = NULL;
outFile = NULL;
blockSize = 512;
count = 1;
while (--argc > 0)
{
str = *++argv;
cp = strchr(str, '=');
if (cp == NULL)
{
fprintf(stderr, "Bad dd argument\n");
goto usage;
}
*cp++ = '\0';
for (par = params; par->name; par++)
{
if (strcmp(str, par->name) == 0)
break;
}
switch (par->value)
{
case PAR_IF:
if (inFile)
{
fprintf(stderr, "Multiple input files illegal\n");
goto usage;
}
//fprintf(stderr, "if=%s\n", cp);
inFile = cp;
break;
case PAR_OF:
if (outFile)
{
fprintf(stderr, "Multiple output files illegal\n");
goto usage;
}
//fprintf(stderr, "of=%s\n", cp);
outFile = cp;
break;
case PAR_BS:
blockSize = getNum(cp);
//fprintf(stderr, "bs=%d\n", blockSize);
if (blockSize <= 0)
{
fprintf(stderr, "Bad block size value\n");
goto usage;
}
break;
case PAR_COUNT:
count = getNum(cp);
//fprintf(stderr, "count=%ld\n", count);
if (count < 0)
{
fprintf(stderr, "Bad count value\n");
goto usage;
}
break;
default:
goto usage;
}
}
buf = localBuf;
if (blockSize > sizeof(localBuf))
{
buf = malloc(blockSize);
if (buf == NULL)
{
fprintf(stderr, "Cannot allocate buffer\n");
return 1;
}
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open(inFile, 0);
if (inFd < 0)
{
perror(inFile);
if (buf != localBuf)
free(buf);
return 1;
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat(outFile, 0666);
if (outFd < 0)
{
perror(outFile);
close(inFd);
if (buf != localBuf)
free(buf);
return 1;
}
while ( outTotal < count*blockSize )
{
inCc = read(inFd, buf, blockSize);
if (inCc < 0) {
perror(inFile);
goto cleanup;
}
//fprintf(stderr, "read in =%d\n", inCc);
intotal += inCc;
cp = buf;
while ( intotal > outTotal )
{
if (outTotal+inCc > count*blockSize)
inCc=count*blockSize-outTotal;
outCc = write(outFd, cp, inCc);
if (outCc < 0)
{
perror(outFile);
goto cleanup;
}
//fprintf(stderr, "wrote out =%d\n", outCc);
inCc -= outCc;
cp += outCc;
outTotal += outCc;
//fprintf(stderr, "outTotal=%ld\n", outTotal);
}
}
if (inCc < 0)
perror(inFile);
cleanup:
close(inFd);
if (close(outFd) < 0)
perror(outFile);
if (buf != localBuf)
free(buf);
printf("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
return 0;
usage:
fprintf(stderr, "%s", dd_usage);
return 1;
}
/*
* Read a number with a possible multiplier.
* Returns -1 if the number format is illegal.
*/
static long
getNum(const char * cp)
{
long value;
if (!isDecimal(*cp))
return -1;
value = 0;
while (isDecimal(*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++)
{
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
#include <errno.h>
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
#include <inttypes.h>
#else
typedef unsigned long long int uintmax_t;
#endif
/* END CODE */
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
"\tof=FILE\twrite to FILE instead of stout\n"
"\tbs=n\tread and write N BYTES at a time\n"
"\tcount=n\tcopy only n input blocks\n"
//"\tskip=n\tskip n input blocks\n"
"\n"
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
extern int dd_main (int argc, char **argv)
{
const char *inFile = NULL;
const char *outFile = NULL;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
size_t blockSize = 512;
//uintmax_t skipBlocks = 0;
uintmax_t count = (uintmax_t)-1;
uintmax_t intotal;
uintmax_t outTotal;
unsigned char *buf;
argc--;
argv++;
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile=((strchr(*argv, '='))+1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile=((strchr(*argv, '='))+1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum ((strchr(*argv, '='))+1);
if (count <= 0) {
fprintf (stderr, "Bad count value %s\n", *argv);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %s\n", *argv);
goto usage;
}
}
#if 0
else if (strncmp(*argv, "skip", 4) == 0) {
skipBlocks = atoi( *argv);
if (skipBlocks <= 0) {
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
goto usage;
}
}
#endif
else {
goto usage;
}
argc--;
argv++;
}
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = fileno(stdin);
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
//
//TODO: Convert to using fullRead & fullWrite
// from utilitity.c
// -Erik
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
goto cleanup;
} else if (inCc == 0) {
goto cleanup;
}
intotal += inCc;
cp = buf;
while (intotal > outTotal) {
if (outTotal + inCc > count * blockSize)
inCc = count * blockSize - outTotal;
outCc = write (outFd, cp, inCc);
if (outCc < 0) {
perror (outFile);
goto cleanup;
} else if (outCc == 0) {
goto cleanup;
}
inCc -= outCc;
cp += outCc;
outTotal += outCc;
}
}
if (inCc < 0)
perror (inFile);
cleanup:
close (inFd);
close (outFd);
free (buf);
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
(outTotal % blockSize) != 0);
exit( TRUE);
usage:
usage( dd_usage);
}
+50
View File
@@ -0,0 +1,50 @@
/*
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
* Renamed deallocvt.
*/
#include "internal.h"
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
progname = argv[0];
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd,VT_DISALLOCATE,0)) {
perror("VT_DISALLOCATE");
exit(1);
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
else
if (ioctl(fd,VT_DISALLOCATE,num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
}
-124
View File
@@ -1,124 +0,0 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
static int
noDots(const struct dirent * e)
{
if ( e->d_name[0] == '.'
&& (e->d_name[1] == '\0'
|| (e->d_name[1] == '.' && e->d_name[2] == '\0')) )
return 0;
else
return 1;
}
extern int
descend(
struct FileInfo *oldInfo
,int (*function)(const struct FileInfo * i))
{
char pathname[1024];
struct dirent * * names;
struct dirent * * n;
int length;
char * filename;
int status = 0;
int count;
if ( *oldInfo->source == '\0' ) {
errno = EINVAL;
return -1;
}
if ( oldInfo->stat.st_dev == 0
&& oldInfo->stat.st_ino == 0
&& oldInfo->stat.st_mode == 0 ) {
if ( lstat(oldInfo->source, &oldInfo->stat) != 0 )
return -1;
oldInfo->isSymbolicLink = ((oldInfo->stat.st_mode & S_IFMT) == S_IFLNK);
if ( oldInfo->isSymbolicLink )
if ( stat(oldInfo->source, &oldInfo->stat) != 0 )
memset((void *)&oldInfo->stat, 0, sizeof(oldInfo->stat));
}
if ( !oldInfo->processDirectoriesAfterTheirContents ) {
if ( function )
status = (*function)(oldInfo);
if ( status == 0 )
status = post_process(oldInfo);
}
if ( (count = scandir(oldInfo->source, &names, noDots, alphasort)) < 0 )
return -1;
length = strlen(oldInfo->source);
if ( oldInfo->source[length-1] == '/' )
length--;
memcpy(pathname, oldInfo->source, length+1);
pathname[length] = '/';
filename = &pathname[length+1];
n = names;
while ( count-- > 0 ) {
struct FileInfo i = *oldInfo;
strcpy(filename, (*n)->d_name);
free(*n++);
if ( lstat(pathname, &i.stat) != 0 && errno != ENOENT ) {
fprintf(stderr, "Can't stat %s: %s\n", pathname, strerror(errno));
return -1;
}
i.isSymbolicLink = ((i.stat.st_mode & S_IFMT) == S_IFLNK);
if ( i.isSymbolicLink )
if ( stat(pathname, &i.stat) != 0 )
memset((void *)&i.stat, 0, sizeof(i.stat));
i.source = pathname;
if ( i.dyadic ) {
char d[1024];
i.destination = join_paths(d, i.destination, &i.source[i.directoryLength]);
}
else
i.destination = i.source;
if ( !i.isSymbolicLink && (i.stat.st_mode & S_IFMT) == S_IFDIR )
status = descend(&i, function);
else {
if ( function )
status = (*function)(&i);
if ( status == 0 )
status = post_process(&i);
}
if ( !i.processDirectoriesAfterTheirContents
&& status == 0
&& (i.stat.st_mode & S_IFMT) == S_IFDIR )
descend(&i, function);
if ( status != 0 && !i.force ) {
while ( count-- > 0 )
free(*n++);
break;
}
}
free(names);
if ( oldInfo->processDirectoriesAfterTheirContents ) {
if ( function )
status = (*function)(oldInfo);
if ( status == 0 )
status = post_process(oldInfo);
}
return status;
}
+90 -81
View File
@@ -1,103 +1,112 @@
/*
* Mini df implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <fstab.h>
const char df_usage[] = "df [filesystem ...]\n"
"\n"
"\tPrint the filesystem space used and space available.\n";
static const char df_usage[] = "df [filesystem ...]\n"
"\n" "\tPrint the filesystem space used and space available.\n";
extern const char mtab_file[]; /* Defined in utility.c */
static int
df(const char * device, const char * mountPoint)
static int df(char *device, const char *mountPoint)
{
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct fstab* fstabItem;
if ( statfs(mountPoint, &s) != 0 ) {
name_and_error(mountPoint);
return 1;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return FALSE;
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (device, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
device = fstabItem->fs_spec;
}
if ( s.f_blocks > 0 ) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used, mountPoint);
/*
printf(
"%-20s %7ld %7ld %7ld %5ld%% %s\n"
,device
,s.f_blocks
,s.f_blocks - s.f_bfree
,s.f_bavail
,blocks_percent_used
,mountPoint);
*/
}
printf(
"%-20s %7.0f %7.0f %7.0f %5ld%% %s\n"
,device
,s.f_blocks * (s.f_bsize / 1024.0)
,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
,s.f_bavail * (s.f_bsize / 1024.0)
,blocks_percent_used
,mountPoint);
}
return 0;
return TRUE;
}
extern int
df_main(struct FileInfo * i, int argc, char * * argv)
extern int df_main(int argc, char **argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
if ( argc > 1 ) {
struct mntent * mountEntry;
int status;
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
while ( argc > 1 ) {
if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0
&& (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
{
fprintf(stderr, "%s: can't find mount point.\n"
,argv[1]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if ( status != 0 )
return status;
argc--;
argv++;
}
return 0;
if (argc > 1) {
struct mntent *mountEntry;
int status;
while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
0) {
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
exit( FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
exit( status);
argc--;
argv++;
}
else {
FILE * mountTable;
struct mntent * mountEntry;
exit( TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
if ( (mountTable = setmntent("/etc/mtab", "r")) == 0
&& (mountTable = setmntent("/proc/mounts", "r")) == 0
) {
name_and_error("/etc/mtab");
return 1;
}
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
int status = df(
mountEntry->mnt_fsname
,mountEntry->mnt_dir);
if ( status != 0 )
return status;
}
endmntent(mountTable);
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
}
return 0;
while ((mountEntry = getmntent(mountTable))) {
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
}
endmntent(mountTable);
}
exit( TRUE);
}
+66 -45
View File
@@ -1,80 +1,94 @@
#include "internal.h"
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
/* dmesg.c -- Print out the contents of the kernel ring buffer
* Created: Sat Oct 9 16:19:47 1993
* Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
* Copyright 1993 Theodore Ts'o (tytso@athena.mit.edu)
* This program comes with ABSOLUTELY NO WARRANTY.
* Modifications by Rick Sladkey (jrs@world.std.com)
* from util-linux; adapted for busybox
* Larger buffersize 3 June 1998 by Nicolai Langfeldt, based on a patch
* by Peeter Joot. This was also suggested by John Hudson.
* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
* - added Native Language Support
*
* from util-linux -- adapted for busybox by
* Erik Andersen <andersee@debian.org>. I ripped out Native Language
* Support, replaced getopt, added some gotos for redundant stuff.
*/
#include "internal.h"
#include <linux/unistd.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#define __NR_klog __NR_syslog
#if __GNU_LIBRARY__ < 5
#ifndef __alpha__
# define __NR_klogctl __NR_syslog
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
#else /* __alpha__ */
#define klogctl syslog
#endif
#if defined(__GLIBC__)
#include <sys/klog.h>
#define klog klogctl
#else
static inline _syscall3(int,klog,int,type,char *,b,int,len)
#endif /* __GLIBC__ */
# include <sys/klog.h>
#endif
const char dmesg_usage[] = "dmesg";
static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
int
dmesg_main(struct FileInfo * info, int argc, char * * argv)
int dmesg_main( int argc, char** argv )
{
char buf[4096];
char *buf;
int bufsize=8196;
int i;
int n;
int c;
int level = 0;
int lastc;
int cmd = 3;
while ((c = getopt( argc, argv, "cn:" )) != EOF) {
switch (c) {
case 'c':
cmd = 4;
break;
case 'n':
cmd = 8;
level = atoi(optarg);
break;
case '?':
default:
usage(dmesg_usage);
exit(1);
}
}
argc -= optind;
argv += optind;
/* Parse any options */
while (argc && **argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'c':
cmd = 4;
break;
case 'n':
cmd = 8;
if (--argc == 0)
goto end;
level = atoi (*(++argv));
--argc;
++argv;
break;
case 's':
if (--argc == 0)
goto end;
bufsize = atoi (*(++argv));
--argc;
++argv;
break;
default:
goto end;
}
}
if (argc > 1) {
usage(dmesg_usage);
exit(1);
goto end;
}
if (cmd == 8) {
n = klog( cmd, NULL, level );
n = klogctl( cmd, NULL, level );
if (n < 0) {
perror( "klog" );
exit( 1 );
goto klogctl_error;
}
exit( 0 );
exit( TRUE );
}
n = klog( cmd, buf, sizeof( buf ) );
if (bufsize < 4096) bufsize = 4096;
buf = (char*)malloc(bufsize);
n = klogctl( cmd, buf, bufsize );
if (n < 0) {
perror( "klog" );
exit( 1 );
goto klogctl_error;
}
lastc = '\n';
@@ -91,5 +105,12 @@ dmesg_main(struct FileInfo * info, int argc, char * * argv)
}
if (lastc != '\n')
putchar( '\n' );
return 0;
exit( TRUE);
end:
usage( dmesg_usage);
exit (FALSE);
klogctl_error:
perror( "klogctl" );
exit( FALSE );
}
+121
View File
@@ -0,0 +1,121 @@
/*
* Mini du implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#if 0
#include <unistd.h>
#include <sys/stat.h>
#endif
static const char du_usage[] =
"Usage: du [OPTION]... [FILE]...\n";
typedef void (Display)(size_t, char *);
static void
print(size_t size, char *filename)
{
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
}
/* tiny recursive du */
static size_t
du(char *filename)
{
struct stat statbuf;
size_t sum;
if ((lstat(filename, &statbuf)) != 0) {
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
return 0;
}
sum = statbuf.st_blocks;
if (S_ISDIR(statbuf.st_mode)) {
DIR *dir;
struct dirent *entry;
dir = opendir(filename);
if (!dir) { return 0; }
while ((entry = readdir(dir))) {
char newfile[512];
char *name = entry->d_name;
if ( (strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0))
{ continue; }
sprintf(newfile, "%s/%s", filename, name);
sum += du(newfile);
}
closedir(dir);
print(sum, filename);
}
return sum;
}
int
du_main(int argc, char **argv)
{
int i;
char opt;
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 's':
break;
case 'h':
usage(du_usage);
break;
default:
fprintf(stderr, "du: invalid option -- %c\n", opt);
usage(du_usage);
}
} else {
break;
}
}
/* go through remaining args (if any) */
if (i >= argc) {
du(".");
} else {
int sum;
for ( ; i < argc; i++) {
sum = du(argv[i]) >> 1;
if (sum) printf("%-7d %s\n", sum, argv[i]);
}
}
exit(0);
}
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
+29 -25
View File
@@ -9,39 +9,43 @@
*
* made against libc6
*/
#include "internal.h"
#include <stdio.h>
#include <utmp.h>
const char dutmp_usage[] = "dutmp\n"
"\n"
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
"\tdutmp /var/run/utmp\n";
static const char dutmp_usage[] = "dutmp\n"
"\n"
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
"\tdutmp /var/run/utmp\n";
extern int
dutmp_fn(const struct FileInfo * i)
extern int dutmp_main (int argc, char **argv)
{
FILE * f = stdin;
struct utmp * ut = (struct utmp *) malloc(sizeof(struct utmp) );
FILE *f = stdin;
struct utmp ut;
if ( i )
if (! (f = fopen(i->source, "r"))) {
name_and_error(i->source);
return 1;
}
if ((argc < 2) || (**(argv + 1) == '-')) {
usage( dutmp_usage);
}
while (fread (ut, 1, sizeof(struct utmp), f)) {
//printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
ut->ut_type, ut->ut_pid, ut->ut_line,
ut->ut_id, ut->ut_user, ut->ut_host,
ut->ut_exit.e_termination, ut->ut_exit.e_exit,
ut->ut_session,
ut->ut_tv.tv_sec, ut->ut_tv.tv_usec,
ut->ut_addr);
}
if ( **(++argv) == 0 ) {
f = fopen (*(++argv), "r");
if (f < 0 ) {
perror (*argv);
exit (FALSE);
}
}
return 0;
while (fread (&ut, 1, sizeof (struct utmp), f)) {
// printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
ut.ut_type, ut.ut_pid, ut.ut_line,
ut.ut_id, ut.ut_user, ut.ut_host,
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
ut.ut_session,
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
}
exit (TRUE);
}
-28
View File
@@ -1,28 +0,0 @@
#include "internal.h"
#include <stdio.h>
extern int
dyadic_main(
struct FileInfo * i
,int argc
,char * * argv)
{
int flags;
i->dyadic = 1;
i->destination = argv[argc - 1];
for ( flags = 0; flags < (argc - 1) && argv[flags + 1][0] == '-' ; flags++ )
;
if ( argc - flags < 3 ) {
usage(i->applet->usage);
return 1;
}
else if ( argc - flags > 3 ) {
if ( !is_a_directory(i->destination) ) {
fprintf(stderr, "%s: not a directory.\n", i->destination);
return 1;
}
}
return monadic_main(i, argc - 1, argv);
}
+182
View File
@@ -0,0 +1,182 @@
/*
* Mini sed implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include "regexp.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <ctype.h>
static const char sed_usage[] =
"sed [-n] [-e script] [file...]\n\n"
"Allowed sed scripts come in the following form:\n"
"\t's/regexp/replacement/[gp]'\n"
"which attempt to match regexp against the pattern space\n"
"and if successful replaces the matched portion with replacement.\n\n"
"Options:\n"
"-e\tadd the script to the commands to be executed\n"
"-n\tsuppress automatic printing of pattern space\n\n"
#if defined BB_REGEXP
"This version of sed matches full regular expresions.\n";
#else
"This version of sed matches strings (not full regular expresions).\n";
#endif
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
{
int foundOne=FALSE;
char haystack[1024];
while (fgets (haystack, 1023, fp)) {
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
if (foundOne==TRUE && printFlag==TRUE) {
fprintf(stdout, haystack);
}
if (quietFlag==FALSE) {
fprintf(stdout, haystack);
}
}
}
extern int sed_main (int argc, char **argv)
{
FILE *fp;
char *needle=NULL, *newNeedle=NULL;
char *name;
char *cp;
int ignoreCase=FALSE;
int printFlag=FALSE;
int quietFlag=FALSE;
int stopNow;
argc--;
argv++;
if (argc < 1) {
usage(sed_usage);
}
if (**argv == '-') {
argc--;
cp = *argv++;
stopNow=FALSE;
while (*++cp && stopNow==FALSE) {
switch (*cp) {
case 'n':
quietFlag = TRUE;
break;
case 'e':
if (*(cp+1)==0 && --argc < 0) {
usage( sed_usage);
}
if ( *++cp != 's')
cp = *argv++;
while( *cp ) {
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
char* pos=needle=cp+2;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
usage( sed_usage);
}
if (*(pos-1) == '\\') {
pos++;
continue;
}
break;
}
*pos=0;
newNeedle=++pos;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
usage( sed_usage);
}
if (*(pos-1) == '\\') {
pos++;
continue;
}
break;
}
*pos=0;
if (pos+2 != 0) {
while (*++pos) {
switch (*pos) {
case 'i':
ignoreCase=TRUE;
break;
case 'p':
printFlag=TRUE;
break;
case 'g':
break;
default:
usage( sed_usage);
}
}
}
}
cp++;
}
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
stopNow=TRUE;
break;
default:
usage(sed_usage);
}
}
}
if (argc==0) {
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
} else {
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
if (ferror (fp))
perror (name);
fclose (fp);
}
}
exit( TRUE);
}
/* END CODE */
+9 -17
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.29alpha
Version: 0.39
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,33 +7,25 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.29a1.tar.gz
Source: %{Name}-%{Version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete environment that fits on a floppy or in a
ROM. Just add "ash" (Keith Almquists tiny Bourne shell clone) and "ae",
and a kernel and you have a full system. This is used on the Debian
install disk and in an internet router, and it makes a good environment
for a "rescue" disk or any small or embedded system.
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a full system. This
is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
%setup -q -n busybox
%setup -q -n %{Name}-%{Version}
%Build
make
%Install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/bin
h=`cat busybox.links`
for i in $h ; do
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
(cd $RPM_BUILD_ROOT/bin ; ln -s ln `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/ln
install -m 755 busybox $RPM_BUILD_ROOT/bin/ln
make PREFIX=$RPM_BUILD_ROOT install
%Clean
rm -rf $RPM_BUILD_ROOT
+41 -25
View File
@@ -1,36 +1,52 @@
/*
* Mini fdflush implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
const char fdflush_usage[] = "fdflush device";
int
fdflush(const char *filename)
extern int fdflush_main(int argc, char **argv)
{
int status;
int fd = open(filename, 0);
int value;
int fd;
if ( **(argv+1) == '-' ) {
usage( "fdflush device\n");
}
if ( fd < 0 ) {
name_and_error(filename);
return 1;
}
fd = open(*argv, 0);
if ( fd < 0 ) {
perror(*argv);
exit(FALSE);
}
status = ioctl(fd, FDFLUSH, 0);
close(fd);
value = ioctl(fd, FDFLUSH, 0);
close(fd);
if ( status != 0 ) {
name_and_error(filename);
return 1;
}
return 0;
}
int
fdflush_fn(const struct FileInfo * i)
{
return fdflush(i->source);
if ( value ) {
perror(*argv);
exit(FALSE);
}
exit (TRUE);
}
+109 -13
View File
@@ -1,23 +1,119 @@
/*
* Mini find implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include "regexp.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
const char find_usage[] = "find dir [pattern]\n"
"\n"
"\tFind files.\n";
extern int
find_main(struct FileInfo * i, int argc, char * * argv)
static char* pattern=NULL;
static char* directory=".";
static int dereferenceFlag=FALSE;
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\n\t\tDereference symbolic links.\n"
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
#if defined BB_REGEXP
"This version of find matches full regular expresions.\n";
#else
"This version of find matches strings (not regular expresions).\n";
#endif
static int fileAction(const char *fileName, struct stat* statbuf)
{
i->recursive=1;
i->processDirectoriesAfterTheirContents=1;
return monadic_main(i, argc, argv);
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
else {
char* tmp = strrchr( fileName, '/');
if (tmp == NULL)
tmp = (char*)fileName;
else
tmp++;
if (check_wildcard_match(tmp, pattern) == TRUE)
fprintf(stdout, "%s\n", fileName);
}
return( TRUE);
}
extern int
find_fn(const struct FileInfo * i)
int find_main(int argc, char **argv)
{
printf("%s\n",i->source);
/* peel off the "find" */
argc--;
argv++;
return(0);
if ( argc > 0 && **argv != '-') {
directory=*argv;
argc--;
argv++;
}
/* Parse any options */
while (argc > 0 && **argv == '-') {
int stopit=FALSE;
while (*++(*argv) && stopit==FALSE) switch (**argv) {
case 'f':
if (strcmp(*argv, "follow")==0) {
argc--;
argv++;
dereferenceFlag=TRUE;
}
break;
case 'n':
if (strcmp(*argv, "name")==0) {
if (argc-- > 1) {
pattern=*(++argv);
stopit=-TRUE;
} else {
usage (find_usage);
}
}
break;
case '-':
/* Ignore all long options */
break;
default:
usage (find_usage);
}
if (argc-- > 1)
argv++;
if (**argv != '-')
break;
else
break;
}
if (recursiveAction(directory, TRUE, FALSE, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
exit(TRUE);
}
-46
View File
@@ -1,46 +0,0 @@
#include "internal.h"
#include <stdio.h>
#include <mntent.h>
#include <sys/stat.h>
/*
* Given a block device, find the mount table entry if that block device
* is mounted.
*
* Given any other file (or directory), find the mount table entry for its
* filesystem.
*/
extern struct mntent *
findMountPoint(const char * name, const char * table)
{
struct stat s;
dev_t mountDevice;
FILE * mountTable;
struct mntent * mountEntry;
if ( stat(name, &s) != 0 )
return 0;
if ( (s.st_mode & S_IFMT) == S_IFBLK )
mountDevice = s.st_rdev;
else
mountDevice = s.st_dev;
if ( (mountTable = setmntent(table, "r")) == 0 )
return 0;
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
if ( strcmp(name, mountEntry->mnt_dir) == 0
|| strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
break;
if ( stat(mountEntry->mnt_fsname, &s) == 0
&& s.st_rdev == mountDevice ) /* Match the device. */
break;
if ( stat(mountEntry->mnt_dir, &s) == 0
&& s.st_dev == mountDevice ) /* Match the directory's mount point. */
break;
}
endmntent(mountTable);
return mountEntry;
}
+109 -13
View File
@@ -1,23 +1,119 @@
/*
* Mini find implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include "regexp.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
const char find_usage[] = "find dir [pattern]\n"
"\n"
"\tFind files.\n";
extern int
find_main(struct FileInfo * i, int argc, char * * argv)
static char* pattern=NULL;
static char* directory=".";
static int dereferenceFlag=FALSE;
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\n\t\tDereference symbolic links.\n"
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
#if defined BB_REGEXP
"This version of find matches full regular expresions.\n";
#else
"This version of find matches strings (not regular expresions).\n";
#endif
static int fileAction(const char *fileName, struct stat* statbuf)
{
i->recursive=1;
i->processDirectoriesAfterTheirContents=1;
return monadic_main(i, argc, argv);
if (pattern==NULL)
fprintf(stdout, "%s\n", fileName);
else {
char* tmp = strrchr( fileName, '/');
if (tmp == NULL)
tmp = (char*)fileName;
else
tmp++;
if (check_wildcard_match(tmp, pattern) == TRUE)
fprintf(stdout, "%s\n", fileName);
}
return( TRUE);
}
extern int
find_fn(const struct FileInfo * i)
int find_main(int argc, char **argv)
{
printf("%s\n",i->source);
/* peel off the "find" */
argc--;
argv++;
return(0);
if ( argc > 0 && **argv != '-') {
directory=*argv;
argc--;
argv++;
}
/* Parse any options */
while (argc > 0 && **argv == '-') {
int stopit=FALSE;
while (*++(*argv) && stopit==FALSE) switch (**argv) {
case 'f':
if (strcmp(*argv, "follow")==0) {
argc--;
argv++;
dereferenceFlag=TRUE;
}
break;
case 'n':
if (strcmp(*argv, "name")==0) {
if (argc-- > 1) {
pattern=*(++argv);
stopit=-TRUE;
} else {
usage (find_usage);
}
}
break;
case '-':
/* Ignore all long options */
break;
default:
usage (find_usage);
}
if (argc-- > 1)
argv++;
if (**argv != '-')
break;
else
break;
}
if (recursiveAction(directory, TRUE, FALSE, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
exit(TRUE);
}
+129 -194
View File
@@ -1,18 +1,28 @@
/*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Mini grep implementation for busybox
*
* The "grep" command, taken from sash.
* This provides basic file searching.
*
* Permission to distribute this code under the GPL has been granted.
* Modified for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com>
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#ifdef BB_GREP
#include "regexp.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
@@ -21,190 +31,115 @@
#include <time.h>
#include <ctype.h>
const char grep_usage[] =
"Search the input file(s) for lines matching the given pattern.\n"
"\tI search stdin if no files are given.\n"
"\tI can't grok full regular expressions.\n"
"usage: grep [in] PATTERN [FILES]...\n"
"\ti=ignore case, n=list line numbers\n";
static BOOL search
(const char * string, const char * word, BOOL ignoreCase);
extern int
grep_main(struct FileInfo * unused, int argc, char ** argv)
{
FILE * fp;
const char * word;
const char * name;
const char * cp;
BOOL tellName;
BOOL ignoreCase;
BOOL tellLine;
long line;
char buf[BUF_SIZE];
ignoreCase = FALSE;
tellLine = FALSE;
argc--;
argv++;
if (argc < 1)
{
fprintf(stderr, "%s", grep_usage);
return 1;
}
if (**argv == '-')
{
argc--;
cp = *argv++;
while (*++cp) switch (*cp)
{
case 'i':
ignoreCase = TRUE;
break;
case 'n':
tellLine = TRUE;
break;
default:
fprintf(stderr, "Unknown option\n");
return 1;
}
}
word = *argv++;
argc--;
tellName = (argc > 1);
while (argc-- > 0)
{
name = *argv++;
fp = fopen(name, "r");
if (fp == NULL)
{
perror(name);
continue;
}
line = 0;
while (fgets(buf, sizeof(buf), fp))
{
line++;
cp = &buf[strlen(buf) - 1];
if (*cp != '\n')
fprintf(stderr, "%s: Line too long\n", name);
if (search(buf, word, ignoreCase))
{
if (tellName)
printf("%s: ", name);
if (tellLine)
printf("%ld: ", line);
fputs(buf, stdout);
}
}
if (ferror(fp))
perror(name);
fclose(fp);
}
return 0;
}
/*
* See if the specified word is found in the specified string.
*/
static BOOL
search(const char * string, const char * word, BOOL ignoreCase)
{
const char * cp1;
const char * cp2;
int len;
int lowFirst;
int ch1;
int ch2;
len = strlen(word);
if (!ignoreCase)
{
while (TRUE)
{
string = strchr(string, word[0]);
if (string == NULL)
return FALSE;
if (memcmp(string, word, len) == 0)
return TRUE;
string++;
}
}
/*
* Here if we need to check case independence.
* Do the search by lower casing both strings.
*/
lowFirst = *word;
if (isupper(lowFirst))
lowFirst = tolower(lowFirst);
while (TRUE)
{
while (*string && (*string != lowFirst) &&
(!isupper(*string) || (tolower(*string) != lowFirst)))
{
string++;
}
if (*string == '\0')
return FALSE;
cp1 = string;
cp2 = word;
do
{
if (*cp2 == '\0')
return TRUE;
ch1 = *cp1++;
if (isupper(ch1))
ch1 = tolower(ch1);
ch2 = *cp2++;
if (isupper(ch2))
ch2 = tolower(ch2);
}
while (ch1 == ch2);
string++;
}
}
static const char grep_usage[] =
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
"\t-n\tprint line number with output lines\n\n"
#if defined BB_REGEXP
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not regular expresions).\n";
#endif
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
{
char *cp;
long line = 0;
char haystack[BUF_SIZE];
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", fileName);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s:", fileName);
if (tellLine==TRUE)
printf ("%ld:", line);
fputs (haystack, stdout);
}
}
}
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *cp;
char *needle;
char *fileName;
int tellName=FALSE;
int ignoreCase=FALSE;
int tellLine=FALSE;
ignoreCase = FALSE;
tellLine = FALSE;
argc--;
argv++;
if (argc < 1) {
usage(grep_usage);
}
if (**argv == '-') {
argc--;
cp = *argv++;
while (*++cp)
switch (*cp) {
case 'i':
ignoreCase = TRUE;
break;
case 'h':
tellName = TRUE;
break;
case 'n':
tellLine = TRUE;
break;
default:
usage(grep_usage);
}
}
needle = *argv++;
argc--;
if (argc==0) {
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
} else {
while (argc-- > 0) {
fileName = *argv++;
fp = fopen (fileName, "r");
if (fp == NULL) {
perror (fileName);
continue;
}
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
if (ferror (fp))
perror (fileName);
fclose (fp);
}
}
exit( TRUE);
}
/* END CODE */
+35
View File
@@ -0,0 +1,35 @@
/*
* Mini free implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#if ! defined BB_FEATURE_USE_PROCFS
#error Sorry, I depend on the /proc filesystem right now.
#endif
extern int free_main(int argc, char **argv)
{
char* cmd[] = { "cat", "/proc/meminfo", "\0" };
exit(cat_main( 3, cmd));
}
+1375
View File
File diff suppressed because it is too large. Load diff
+129 -194
View File
@@ -1,18 +1,28 @@
/*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Mini grep implementation for busybox
*
* The "grep" command, taken from sash.
* This provides basic file searching.
*
* Permission to distribute this code under the GPL has been granted.
* Modified for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com>
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#ifdef BB_GREP
#include "regexp.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
@@ -21,190 +31,115 @@
#include <time.h>
#include <ctype.h>
const char grep_usage[] =
"Search the input file(s) for lines matching the given pattern.\n"
"\tI search stdin if no files are given.\n"
"\tI can't grok full regular expressions.\n"
"usage: grep [in] PATTERN [FILES]...\n"
"\ti=ignore case, n=list line numbers\n";
static BOOL search
(const char * string, const char * word, BOOL ignoreCase);
extern int
grep_main(struct FileInfo * unused, int argc, char ** argv)
{
FILE * fp;
const char * word;
const char * name;
const char * cp;
BOOL tellName;
BOOL ignoreCase;
BOOL tellLine;
long line;
char buf[BUF_SIZE];
ignoreCase = FALSE;
tellLine = FALSE;
argc--;
argv++;
if (argc < 1)
{
fprintf(stderr, "%s", grep_usage);
return 1;
}
if (**argv == '-')
{
argc--;
cp = *argv++;
while (*++cp) switch (*cp)
{
case 'i':
ignoreCase = TRUE;
break;
case 'n':
tellLine = TRUE;
break;
default:
fprintf(stderr, "Unknown option\n");
return 1;
}
}
word = *argv++;
argc--;
tellName = (argc > 1);
while (argc-- > 0)
{
name = *argv++;
fp = fopen(name, "r");
if (fp == NULL)
{
perror(name);
continue;
}
line = 0;
while (fgets(buf, sizeof(buf), fp))
{
line++;
cp = &buf[strlen(buf) - 1];
if (*cp != '\n')
fprintf(stderr, "%s: Line too long\n", name);
if (search(buf, word, ignoreCase))
{
if (tellName)
printf("%s: ", name);
if (tellLine)
printf("%ld: ", line);
fputs(buf, stdout);
}
}
if (ferror(fp))
perror(name);
fclose(fp);
}
return 0;
}
/*
* See if the specified word is found in the specified string.
*/
static BOOL
search(const char * string, const char * word, BOOL ignoreCase)
{
const char * cp1;
const char * cp2;
int len;
int lowFirst;
int ch1;
int ch2;
len = strlen(word);
if (!ignoreCase)
{
while (TRUE)
{
string = strchr(string, word[0]);
if (string == NULL)
return FALSE;
if (memcmp(string, word, len) == 0)
return TRUE;
string++;
}
}
/*
* Here if we need to check case independence.
* Do the search by lower casing both strings.
*/
lowFirst = *word;
if (isupper(lowFirst))
lowFirst = tolower(lowFirst);
while (TRUE)
{
while (*string && (*string != lowFirst) &&
(!isupper(*string) || (tolower(*string) != lowFirst)))
{
string++;
}
if (*string == '\0')
return FALSE;
cp1 = string;
cp2 = word;
do
{
if (*cp2 == '\0')
return TRUE;
ch1 = *cp1++;
if (isupper(ch1))
ch1 = tolower(ch1);
ch2 = *cp2++;
if (isupper(ch2))
ch2 = tolower(ch2);
}
while (ch1 == ch2);
string++;
}
}
static const char grep_usage[] =
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
"\t-n\tprint line number with output lines\n\n"
#if defined BB_REGEXP
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not regular expresions).\n";
#endif
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
{
char *cp;
long line = 0;
char haystack[BUF_SIZE];
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", fileName);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s:", fileName);
if (tellLine==TRUE)
printf ("%ld:", line);
fputs (haystack, stdout);
}
}
}
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *cp;
char *needle;
char *fileName;
int tellName=FALSE;
int ignoreCase=FALSE;
int tellLine=FALSE;
ignoreCase = FALSE;
tellLine = FALSE;
argc--;
argv++;
if (argc < 1) {
usage(grep_usage);
}
if (**argv == '-') {
argc--;
cp = *argv++;
while (*++cp)
switch (*cp) {
case 'i':
ignoreCase = TRUE;
break;
case 'h':
tellName = TRUE;
break;
case 'n':
tellLine = TRUE;
break;
default:
usage(grep_usage);
}
}
needle = *argv++;
argc--;
if (argc==0) {
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
} else {
while (argc-- > 0) {
fileName = *argv++;
fp = fopen (fileName, "r");
if (fp == NULL) {
perror (fileName);
continue;
}
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
if (ferror (fp))
perror (fileName);
fclose (fp);
}
}
exit( TRUE);
}
/* END CODE */
+2330
View File
File diff suppressed because it is too large. Load diff
+113 -62
View File
@@ -7,11 +7,17 @@
#include "internal.h"
#ifdef BB_GZIP
#ifndef BB_ZCAT
error: you need zcat to have gzip support!
#endif
//#ifndef BB_ZCAT
//#error you need zcat to have gzip support!
//#endif
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"When FILE is -, reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
/* gzip.h -- common declarations for all gzip modules
* Copyright (C) 1992-1993 Jean-loup Gailly.
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
extern int verbose; /* be verbose (-v) */
extern int quiet; /* be quiet (-q) */
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
#define WARN(msg) {if (!quiet) fprintf msg ; \
if (exit_code == OK) exit_code = WARNING;}
local void do_exit(int exitcode);
local void do_exit(int exitcode) __attribute__ ((noreturn));
/* in zip.c: */
extern int zip OF((int in, int out));
@@ -380,7 +385,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# undef LZW
#endif
/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
/* tailor.h -- target dependent definitions
* Copyright (C) 1992-1993 Jean-loup Gailly.
* This is free software; you can redistribute it and/or modify it under the
@@ -391,7 +395,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -766,10 +769,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# include <stdio.h>
#endif
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Local data used by the "bit string" routines.
*/
@@ -975,10 +974,6 @@ void copy_block(buf, len, header)
#include <stdio.h>
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Configuration parameters
*/
@@ -1591,10 +1586,6 @@ ulg deflate()
* For the meaning of all compilation flags, see comments in Makefile.in.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <sys/types.h>
#include <signal.h>
@@ -1740,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
/* local variables */
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
int decompress = 0; /* decompress (-d) */
int no_name = -1; /* don't save or restore the original file name */
int no_time = -1; /* don't save or restore the original file time */
@@ -1772,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
/* local functions */
local void treat_stdin OF((void));
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
// int main (argc, argv)
// int argc;
// char **argv;
int gzip_main(struct FileInfo * i, int argc, char * * argv)
int gzip_main(int argc, char ** argv)
{
int result;
int inFileNum;
int outFileNum;
struct stat statBuf;
char* delFileName;
int tostdout = 0;
int fromstdin = 0;
if (argc==1)
usage(gzip_usage);
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromstdin = 1;
tostdout = 1;
}
while (*(++(*argv))) {
switch (**argv) {
case 'c':
tostdout = 1;
break;
default:
usage(gzip_usage);
}
}
}
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
(void) signal (SIGINT, (sig_type)abort_gzip);
@@ -1801,8 +1816,6 @@ int gzip_main(struct FileInfo * i, int argc, char * * argv)
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
z_len = strlen(z_suffix);
to_stdout = 1;
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
@@ -1815,33 +1828,84 @@ int gzip_main(struct FileInfo * i, int argc, char * * argv)
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
/* And get to work */
treat_stdin();
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
if (fromstdin==1) {
strcpy(ofname, "stdin");
/* ========================================================================
* Compress or decompress stdin
*/
local void treat_stdin()
{
inFileNum=fileno(stdin);
time_stamp = 0; /* time unknown by default */
ifile_size = -1L; /* convention for unknown size */
} else {
/* Open up the input file */
if (*argv=='\0')
usage(gzip_usage);
strncpy(ifname, *argv, MAX_PATH_LEN);
/* Open input fille */
inFileNum=open( ifname, O_RDONLY);
if (inFileNum < 0) {
perror(ifname);
do_exit(WARNING);
}
/* Get the time stamp on the input file. */
result = stat(ifname, &statBuf);
if (result < 0) {
perror(ifname);
do_exit(WARNING);
}
time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size;
}
if (tostdout==1) {
/* And get to work */
strcpy(ofname, "stdout");
outFileNum=fileno(stdout);
SET_BINARY_MODE(fileno(stdout));
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
/* Get the time stamp on the input file. */
time_stamp = 0; /* time unknown by default */
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
ifile_size = -1L; /* convention for unknown size */
/* Actually do the compression/decompression. */
zip(inFileNum, outFileNum);
clear_bufs(); /* clear input and output buffers */
to_stdout = 1;
part_nb = 0;
} else {
/* Actually do the compression/decompression. Loop over zipped members.
*/
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
/* And get to work */
strncpy(ofname, ifname, MAX_PATH_LEN-4);
strcat(ofname, ".gz");
/* Open output fille */
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
if (outFileNum < 0) {
perror(ofname);
do_exit(WARNING);
}
SET_BINARY_MODE(outFileNum);
/* Set permissions on the file */
fchmod(outFileNum, statBuf.st_mode);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
result=zip(inFileNum, outFileNum);
close( outFileNum);
close( inFileNum);
/* Delete the original file */
if (result == OK)
delFileName=ifname;
else
delFileName=ofname;
if (unlink (delFileName) < 0) {
perror (delFileName);
exit( FALSE);
}
}
do_exit(exit_code);
}
/* ========================================================================
@@ -1924,10 +1988,6 @@ local void do_exit(int exitcode)
#include <ctype.h>
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
/* ===========================================================================
* Constants
*/
@@ -2942,10 +3002,6 @@ local void set_file_type()
* terms of the GNU General Public License, see the file COPYING.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
@@ -2963,8 +3019,6 @@ static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
extern int errno;
#endif
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
* Copy input to output unchanged: zcat == cat with --force.
* IN assertion: insize bytes have already been read in inbuf.
@@ -3141,10 +3195,6 @@ void display_ratio(num, den, file)
* terms of the GNU General Public License, see the file COPYING.
*/
#ifdef RCSID
static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
#endif
#include <ctype.h>
#include <sys/types.h>
@@ -3176,6 +3226,7 @@ int zip(in, out)
/* Write the header to the gzip file. See algorithm.doc for the format */
method = DEFLATED;
put_byte(GZIP_MAGIC[0]); /* magic header */
put_byte(GZIP_MAGIC[1]);
+26 -6
View File
@@ -1,12 +1,32 @@
/*
* Mini halt implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <signal.h>
const char halt_usage[] = "halt\n"
"\n\t"
"\thalt the system.\n";
extern int
halt_main(struct FileInfo * i, int argc, char * * argv)
halt_main(int argc, char ** argv)
{
return kill(1, SIGUSR1);
/* don't assume init's pid == 1 */
exit( kill(findInitPid(), SIGUSR1));
}
+106
View File
@@ -0,0 +1,106 @@
/*
* Mini head implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include <stdio.h>
const char head_usage[] =
"Usage: head [FILE]...\n\n"
"Print first 10 lines of each FILE to standard output.\n"
"With more than one FILE, precede each with a header giving the\n"
"file name. With no FILE, or when FILE is -, read standard input.\n";
int
head(int len, FILE *src)
{
int i;
char buffer[1024];
for (i = 0; i < len; i++) {
fgets(buffer, 1024, src);
if (feof(src)) { break; }
fputs(buffer, stdout);
}
return 0;
}
/* BusyBoxed head(1) */
int
head_main(int argc, char **argv)
{
int i = 1;
char opt;
int len = 10;
/* 1st option is potentially special */
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
int tmplen = atoi(&argv[1][1]);
if (tmplen) { len = tmplen; }
i = 2;
}
/* parse argv[] */
for ( ; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case '-':
case 'h':
usage(head_usage);
default:
fprintf(stderr, "head: invalid option -- %c\n", opt);
usage(head_usage);
}
} else {
break;
}
}
/* get rest of argv[] or stdin if nothing's left */
if (i >= argc) {
head(len, stdin);
} else {
int need_headers = ((argc - i) > 1);
for ( ; i < argc; i++) {
FILE *src;
src = fopen(argv[i], "r");
if (!src) {
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
} else {
/* emulating GNU behaviour */
if (need_headers) {
fprintf(stdout, "==> %s <==\n", argv[i]);
}
head(len, src);
if (i < argc - 1) {
fprintf(stdout, "\n");
}
}
}
}
exit(0);
}
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
+138
View File
@@ -0,0 +1,138 @@
/*
* $Id: hostname.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
*
* adjusted by Erik Andersen <andersee@debian.org> to remove
* use of long options and GNU getopt. Improved the usage info.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "internal.h"
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
static const char* hostname_usage =
"hostname [OPTION] {hostname | -F file}\n\n"
"Get or set the hostname or DNS domain name. If a hostname is given\n"
"(or a file with the -F parameter), the host name will be set.\n\n"
"Options:\n"
"\t-s\t\tShort\n"
"\t-i\t\tAddresses for the hostname\n"
"\t-d\t\tDNS domain name\n"
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n";
void do_sethostname(char *s, int isfile)
{
FILE *f;
char buf[255];
if (!s) return;
if (!isfile) {
if (sethostname(s, strlen(s)) < 0) {
if (errno == EPERM)
fprintf(stderr, "hostname: you must be root to change the hostname\n");
else
perror("sethostname");
exit(1);
}
} else {
if ((f = fopen(s, "r")) == NULL) {
perror(s);
exit(1);
} else {
fgets(buf, 255, f);
fclose(f);
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
if (sethostname(buf, strlen(buf)) < 0) {
perror("sethostname");
exit(1);
}
}
}
}
int hostname_main(int argc, char **argv)
{
int opt_short = 0;
int opt_domain = 0;
int opt_ip = 0;
struct hostent *h;
char *filename = NULL;
char buf[255];
char *s = NULL;
if (argc < 1) usage(hostname_usage);
while (--argc > 0 && **(++argv) == '-') {
while (*(++(*argv))) {
switch (**argv) {
case 's':
opt_short = 1;
break;
case 'i':
opt_ip = 1;
break;
case 'd':
opt_domain = 1;
break;
case 'F':
filename = optarg;
if (--argc == 0) {
usage(hostname_usage);
}
filename = *(++argv);
break;
default:
usage(hostname_usage);
}
if (filename!=NULL)
break;
}
}
if (argc >= 1) {
do_sethostname(*argv, 0);
} else if (filename!=NULL) {
do_sethostname(filename, 1);
} else {
gethostname(buf, 255);
if (opt_short) {
s = strchr(buf, '.');
if (!s) s = buf; *s = 0;
printf("%s\n", buf);
} else if (opt_domain) {
s = strchr(buf, '.');
printf("%s\n", (s ? s+1 : ""));
} else if (opt_ip) {
h = gethostbyname(buf);
if (!h) {
printf("Host not found\n");
exit(1);
}
printf("%s\n", inet_ntoa(*(struct in_addr *)(h->h_addr)));
} else {
printf("%s\n", buf);
}
}
exit( 0);
}
+570 -406
View File
File diff suppressed because it is too large. Load diff
+26 -6
View File
@@ -1,12 +1,32 @@
/*
* Mini halt implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <signal.h>
const char halt_usage[] = "halt\n"
"\n\t"
"\thalt the system.\n";
extern int
halt_main(struct FileInfo * i, int argc, char * * argv)
halt_main(int argc, char ** argv)
{
return kill(1, SIGUSR1);
/* don't assume init's pid == 1 */
exit( kill(findInitPid(), SIGUSR1));
}
+570 -406
View File
File diff suppressed because it is too large. Load diff
+31
View File
@@ -0,0 +1,31 @@
/*
* Mini poweroff implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <signal.h>
extern int
poweroff_main(int argc, char ** argv)
{
/* don't assume init's pid == 1 */
exit( kill(findInitPid(), SIGUSR2));
}
+25 -6
View File
@@ -1,12 +1,31 @@
/*
* Mini reboot implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <signal.h>
const char reboot_usage[] = "reboot\n"
"\n\t"
"\treboot the system.\n";
extern int
reboot_main(struct FileInfo * i, int argc, char * * argv)
reboot_main(int argc, char ** argv)
{
return kill(1, SIGUSR2);
/* don't assume init's pid == 1 */
exit( kill(findInitPid(), SIGINT));
}
Executable
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
set -e
if [ "$1" == "" ]; then
echo "No installation directory, aborting."
exit 1;
fi
h=`sort busybox.links | uniq`
for i in $h ; do
echo " $1$i -> /bin/busybox"
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
ln -fs /bin/busybox $1$i
done
rm -f $1/bin/busybox
install -m 755 busybox $1/bin/busybox
exit 0
+127 -113
View File
@@ -1,3 +1,25 @@
/*
* Busybox main internal header file
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#ifndef _INTERNAL_H_
#define _INTERNAL_H_
@@ -7,14 +29,12 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <mntent.h>
/* Some useful definitions */
typedef int BOOL;
#define STDIN 0
#define STDOUT 1
#define FALSE ((BOOL) 0)
#define TRUE ((BOOL) 1)
#define FALSE ((int) 1)
#define TRUE ((int) 0)
#define PATH_LEN 1024
#define BUF_SIZE 8192
@@ -26,164 +46,158 @@ typedef int BOOL;
#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
struct FileInfo {
unsigned int complainInPostProcess:1;
unsigned int changeUserID:1;
unsigned int changeGroupID:1;
unsigned int changeMode:1;
unsigned int create:1;
unsigned int force:1;
unsigned int recursive:1;
unsigned int processDirectoriesAfterTheirContents;
unsigned int makeParentDirectories:1;
unsigned int didOperation:1;
unsigned int isSymbolicLink:1;
unsigned int makeSymbolicLink:1;
unsigned int dyadic:1;
const char* source;
const char* destination;
int directoryLength;
uid_t userID;
gid_t groupID;
mode_t andWithMode;
mode_t orWithMode;
struct stat stat;
const struct Applet *
applet;
};
struct Applet {
const char* name;
int (*main)(int argc, char** argv);
};
extern void name_and_error(const char*);
extern int is_a_directory(const char*);
extern char* join_paths(char *, const char *, const char *);
extern int descend(
struct FileInfo *o
,int (*function)(const struct FileInfo * i));
extern struct mntent *
findMountPoint(const char*, const char *);
extern void usage(const char*);
extern int busybox_main(int argc, char** argv);
extern int block_device_main(int argc, char** argv);
extern int cat_more_main(int argc, char** argv);
extern int chgrp_main(int argc, char** argv);
extern int chmod_main(int argc, char** argv);
extern int chown_main(int argc, char** argv);
extern int cat_main(int argc, char** argv);
extern int more_main(int argc, char** argv);
extern int cp_main(int argc, char** argv);
extern int chmod_chown_chgrp_main(int argc, char** argv);
extern int chroot_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
extern int dd_main(int argc, char** argv);
extern int df_main(int argc, char** argv);
extern int dmesg_main(int argc, char** argv);
extern int dyadic_main(int argc, char** argv);
extern int du_main(int argc, char** argv);
extern int dutmp_main(int argc, char** argv);
extern int false_main(int argc, char** argv);
extern int fdisk_main(int argc, char** argv);
extern int fdflush_main(int argc, char **argv);
extern int fsck_minix_main(int argc, char **argv);
extern int mkfs_minix_main(int argc, char **argv);
extern int find_main(int argc, char** argv);
extern int free_main(int argc, char** argv);
extern int grep_main(int argc, char** argv);
extern int halt_main(int argc, char** argv);
extern int head_main(int argc, char** argv);
extern int hostname_main(int argc, char** argv);
extern int init_main(int argc, char** argv);
extern int kill_main(int argc, char** argv);
extern int length_main(int argc, char** argv);
extern int ln_main(int argc, char** argv);
extern int loadfont_main(int argc, char** argv);
extern int loadkmap_main(int argc, char** argv);
extern int losetup_main(int argc, char** argv);
extern int ls_main(int argc, char** argv);
extern int chvt_main(int argc, char** argv);
extern int deallocvt_main(int argc, char** argv);
extern int makedevs_main(int argc, char** argv);
extern int math_main(int argc, char** argv);
extern int mkdir_main(int argc, char** argv);
extern int mknod_main(int argc, char** argv);
extern int mkswap_main(int argc, char** argv);
extern int mnc_main(int argc, char** argv);
extern int monadic_main(int argc, char** argv);
extern int mount_main(int argc, char** argv);
extern int mt_main(int argc, char** argv);
extern int mv_main(int argc, char** argv);
extern int ping_main(int argc, char **argv);
extern int poweroff_main(int argc, char **argv);
extern int printf_main(int argc, char** argv);
extern int ps_main(int argc, char** argv);
extern int pwd_main(int argc, char** argv);
extern int reboot_main(int argc, char** argv);
extern int rmdir_main(int argc, char **argv);
extern int rm_main(int argc, char** argv);
extern int scan_partitions_main(int argc, char** argv);
extern int sh_main(int argc, char** argv);
extern int sfdisk_main(int argc, char** argv);
extern int sed_main(int argc, char** argv);
extern int sleep_main(int argc, char** argv);
extern int tar_main(int argc, char** argv);
extern int swap_on_off_main(int argc, char** argv);
extern int sync_main(int argc, char** argv);
extern int syslogd_main(int argc, char **argv);
extern int logger_main(int argc, char **argv);
extern int tar_main(int argc, char** argv);
extern int tail_main(int argc, char** argv);
extern int tee_main(int argc, char** argv);
extern int touch_main(int argc, char** argv);
extern int tput_main(int argc, char** argv);
extern int true_main(int argc, char** argv);
extern int tryopen_main(int argc, char** argv);
extern int umount_main(int argc, char** argv);
extern int update_main(int argc, char** argv);
extern int zcat_main(int argc, char** argv);
extern int uname_main(int argc, char** argv);
extern int gunzip_main (int argc, char** argv);
extern int gzip_main(int argc, char** argv);
extern int
parse_mode(
const char* s
,mode_t * or
,mode_t * and
,int * group_execute);
extern int parse_user_name(const char* string, struct FileInfo * i);
extern const char block_device_usage[];
extern const char chgrp_usage[];
extern const char chmod_usage[];
extern const char chown_usage[];
extern const char chroot_usage[];
extern const char clear_usage[];
extern const char cp_usage[];
extern const char date_usage[];
extern const char dd_usage[];
extern const char df_usage[];
extern const char dmesg_usage[];
extern const char dutmp_usage[];
extern const char false_usage[];
extern const char fdflush_usage[];
extern const char find_usage[];
extern const char grep_usage[];
extern const char halt_usage[];
extern const char init_usage[];
extern const char kill_usage[];
extern const char length_usage[];
extern const char ln_usage[];
extern const char loadkmap_usage[];
extern const char losetup_usage[];
extern const char ls_usage[];
extern const char math_usage[];
extern const char makedevs_usage[];
extern const char mkdir_usage[];
extern const char mknod_usage[];
extern const char mkswap_usage[];
extern const char mnc_usage[];
extern const char more_usage[];
extern const char mount_usage[];
extern const char mt_usage[];
extern const char mv_usage[];
extern const char printf_usage[];
extern const char pwd_usage[];
extern const char reboot_usage[];
extern const char rm_usage[];
extern const char rmdir_usage[];
extern const char scan_partitions_usage[];
extern const char sleep_usage[];
extern const char tar_usage[];
extern const char swapoff_usage[];
extern const char swapon_usage[];
extern const char sync_usage[];
extern const char touch_usage[];
extern const char tput_usage[];
extern const char true_usage[];
extern const char tryopen_usage[];
extern const char umount_usage[];
extern const char update_usage[];
extern const char zcat_usage[];
extern const char gzip_usage[];
const char *modeString(int mode);
const char *timeString(time_t timeVal);
int isDirectory(const char *name);
int isDevice(const char *name);
int copyFile(const char *srcName, const char *destName, int setModes,
int followLinks);
char *buildName(const char *dirName, const char *fileName);
int makeString(int argc, const char **argv, char *buf, int bufLen);
char *getChunk(int size);
char *chunkstrdup(const char *str);
void freeChunks(void);
int fullWrite(int fd, const char *buf, int len);
int fullRead(int fd, char *buf, int len);
int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf),
int (*dirAction) (const char *fileName, struct stat* statbuf));
const char* timeString(time_t timeVal);
extern void createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern void usage(const char *usage) __attribute__ ((noreturn));
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 int check_wildcard_match(const char* text, const char* pattern);
extern long getNum (const char *cp);
extern pid_t findInitPid();
#if defined BB_MTAB
#define whine_if_fstab_is_missing() {}
#else
extern void whine_if_fstab_is_missing();
#endif
#if defined BB_NFSMOUNT
int nfsmount(const char *spec, const char *node, unsigned long *flags,
char **extra_opts, char **mount_opts, int running_bg);
#endif
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
static inline int bit(char * addr,unsigned int nr)
{
return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
}
static inline int setbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] |= (1<<(nr & 7));
return __res != 0; \
}
static inline int clrbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] &= ~(1<<(nr & 7));
return __res != 0;
}
#endif /* inline bitops junk */
#endif /* _INTERNAL_H_ */
+181 -106
View File
@@ -1,140 +1,215 @@
/*
* Mini kill implementation for busybox
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n"
"\t-l\tList all signal names and numbers.\n\n";
const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n";
struct signal_name {
const char * name;
int number;
const char *name;
int number;
};
const struct signal_name signames[] = {
{ "HUP", SIGHUP },
{ "INT", SIGINT },
{ "QUIT", SIGQUIT },
{ "ILL", SIGILL },
{ "TRAP", SIGTRAP },
{ "ABRT", SIGABRT },
{"HUP", SIGHUP},
{"INT", SIGINT},
{"QUIT", SIGQUIT},
{"ILL", SIGILL},
{"TRAP", SIGTRAP},
{"ABRT", SIGABRT},
#ifndef __alpha__
{ "IOT", SIGIOT },
{"IOT", SIGIOT},
#endif
#if defined(sparc) || defined(__alpha__)
{ "EMT", SIGEMT },
#if defined(__sparc__) || defined(__alpha__)
{"EMT", SIGEMT},
#else
{ "BUS", SIGBUS },
{"BUS", SIGBUS},
#endif
{ "FPE", SIGFPE },
{ "KILL", SIGKILL },
#if defined(sparc) || defined(__alpha__)
{ "BUS", SIGBUS },
{"FPE", SIGFPE},
{"KILL", SIGKILL},
#if defined(__sparc__) || defined(__alpha__)
{"BUS", SIGBUS},
#else
{ "USR1", SIGUSR1 },
{"USR1", SIGUSR1},
#endif
{ "SEGV", SIGSEGV },
#if defined(sparc) || defined(__alpha__)
{ "SYS", SIGSYS },
{"SEGV", SIGSEGV},
#if defined(__sparc__) || defined(__alpha__)
{"SYS", SIGSYS},
#else
{ "USR2", SIGUSR2 },
{"USR2", SIGUSR2},
#endif
{ "PIPE", SIGPIPE },
{ "ALRM", SIGALRM },
{ "TERM", SIGTERM },
#if defined(sparc) || defined(__alpha__)
{ "URG", SIGURG },
{ "STOP", SIGSTOP },
{ "TSTP", SIGTSTP },
{ "CONT", SIGCONT },
{ "CHLD", SIGCHLD },
{ "TTIN", SIGTTIN },
{ "TTOU", SIGTTOU },
{ "IO", SIGIO },
{"PIPE", SIGPIPE},
{"ALRM", SIGALRM},
{"TERM", SIGTERM},
#if defined(__sparc__) || defined(__alpha__)
{"URG", SIGURG},
{"STOP", SIGSTOP},
{"TSTP", SIGTSTP},
{"CONT", SIGCONT},
{"CHLD", SIGCHLD},
{"TTIN", SIGTTIN},
{"TTOU", SIGTTOU},
{"IO", SIGIO},
# ifndef __alpha__
{ "POLL", SIGIO },
{"POLL", SIGIO},
# endif
{ "XCPU", SIGXCPU },
{ "XFSZ", SIGXFSZ },
{ "VTALRM", SIGVTALRM },
{ "PROF", SIGPROF },
{ "WINCH", SIGWINCH },
{"XCPU", SIGXCPU},
{"XFSZ", SIGXFSZ},
{"VTALRM", SIGVTALRM},
{"PROF", SIGPROF},
{"WINCH", SIGWINCH},
# ifdef __alpha__
{ "INFO", SIGINFO },
{"INFO", SIGINFO},
# else
{ "LOST", SIGLOST },
{"LOST", SIGLOST},
# endif
{ "USR1", SIGUSR1 },
{ "USR2", SIGUSR2 },
{"USR1", SIGUSR1},
{"USR2", SIGUSR2},
#else
{ "STKFLT", SIGSTKFLT },
{ "CHLD", SIGCHLD },
{ "CONT", SIGCONT },
{ "STOP", SIGSTOP },
{ "TSTP", SIGTSTP },
{ "TTIN", SIGTTIN },
{ "TTOU", SIGTTOU },
{ "URG", SIGURG },
{ "XCPU", SIGXCPU },
{ "XFSZ", SIGXFSZ },
{ "VTALRM", SIGVTALRM },
{ "PROF", SIGPROF },
{ "WINCH", SIGWINCH },
{ "IO", SIGIO },
{ "POLL", SIGPOLL },
{ "PWR", SIGPWR },
{ "UNUSED", SIGUNUSED },
{"STKFLT", SIGSTKFLT},
{"CHLD", SIGCHLD},
{"CONT", SIGCONT},
{"STOP", SIGSTOP},
{"TSTP", SIGTSTP},
{"TTIN", SIGTTIN},
{"TTOU", SIGTTOU},
{"URG", SIGURG},
{"XCPU", SIGXCPU},
{"XFSZ", SIGXFSZ},
{"VTALRM", SIGVTALRM},
{"PROF", SIGPROF},
{"WINCH", SIGWINCH},
{"IO", SIGIO},
{"POLL", SIGPOLL},
{"PWR", SIGPWR},
{"UNUSED", SIGUNUSED},
#endif
{ 0, 0 }
{0, 0}
};
extern int
kill_main(struct FileInfo * i, int argc, char * * argv)
extern int kill_main (int argc, char **argv)
{
int had_error = 0;
int sig = SIGTERM;
if ( argv[1][0] == '-' ) {
if ( argv[1][1] >= '0' && argv[1][1] <= '9' ) {
sig = atoi(&argv[1][1]);
if ( sig < 0 || sig >= NSIG ) {
usage(kill_usage);
exit(-1);
}
}
else {
const struct signal_name * s = signames;
for ( ; ; ) {
if ( strcmp(s->name, &argv[1][1]) == 0 ) {
sig = s->number;
break;
}
s++;
if ( s->name == 0 ) {
usage(kill_usage);
exit(-1);
}
}
}
argv++;
argc--;
int sig = SIGTERM;
argc--;
argv++;
/* Parse any options */
if (argc < 1)
usage(kill_usage);
}
while ( argc > 1 ) {
int pid;
if ( argv[1][0] < '0' || argv[1][0] > '9' ) {
usage(kill_usage);
exit(-1);
while (argc > 0 && **argv == '-') {
while (*++(*argv)) {
switch (**argv) {
case 'l':
{
int col=0;
const struct signal_name *s = signames;
while (s->name != 0) {
col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
if (col>60) {
fprintf(stderr, "\n");
col=0;
}
}
fprintf(stderr, "\n\n");
exit( TRUE);
}
pid = atoi(argv[1]);
if ( kill(pid, sig) != 0 ) {
had_error = 1;
perror(argv[1]);
break;
case '-':
usage(kill_usage);
default:
{
if (isdigit( **argv)) {
sig = atoi (*argv);
if (sig < 0 || sig >= NSIG)
goto end;
else {
argc--;
argv++;
goto do_it_now;
}
}
else {
const struct signal_name *s = signames;
while (s->name != 0) {
if (strcasecmp (s->name, *argv) == 0) {
sig = s->number;
argc--;
argv++;
goto do_it_now;
}
s++;
}
if (s->name == 0)
goto end;
}
}
argv++;
argc--;
}
argc--;
argv++;
}
if ( had_error )
return -1;
else
return 0;
}
do_it_now:
while (argc >= 1) {
int pid;
struct stat statbuf;
char pidpath[20]="/proc/";
if (! isdigit( **argv)) {
fprintf(stderr, "bad PID: %s\n", *argv);
exit( FALSE);
}
pid = atoi (*argv);
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
if (stat( pidpath, &statbuf)!=0) {
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
exit( FALSE);
}
if (kill (pid, sig) != 0) {
perror (*argv);
exit ( FALSE);
}
argv++;
}
exit ( TRUE);
end:
fprintf(stderr, "bad signal name: %s\n", *argv);
exit (TRUE);
}
+7 -6
View File
@@ -3,11 +3,12 @@
#include <string.h>
#include <stdio.h>
const char length_usage[] = "length string";
int
length_main(struct FileInfo * i, int argc, char * * argv)
extern int
length_main(int argc, char * * argv)
{
printf("%d\n", strlen(argv[1]));
return 0;
if ( **(argv+1) == '-' ) {
usage("length string\n");
}
printf("%d\n", strlen(argv[1]));
return( TRUE);
}
+81 -38
View File
@@ -1,52 +1,95 @@
/*
* Mini ln implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <dirent.h>
#include <errno.h>
const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
"\n"
"\tAdd a new name that refers to the same file as \"original-name\"\n"
"\n"
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
"\t-f:\tRemove existing destination files.\n";
int
ln_fn(const struct FileInfo * i)
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
extern int ln_main(int argc, char **argv)
{
int status = 0;
char d[PATH_MAX];
const char * destination = i->destination;
int status;
static char* linkName;
if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) {
fprintf(stderr, "Please use \"ln -s\" to link directories.\n");
return 1;
}
if (argc < 3) {
usage (ln_usage);
}
argc--;
argv++;
/*
* If the destination is a directory, create a file within it.
*/
if ( is_a_directory(i->destination) ) {
destination = join_paths(
d
,i->destination
,&i->source[i->directoryLength]);
}
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 's':
symlinkFlag = TRUE;
break;
case 'f':
removeoldFlag = TRUE;
break;
default:
usage (ln_usage);
}
argc--;
argv++;
}
if ( i->force )
status = ( unlink(destination) && errno != ENOENT );
if ( status == 0 ) {
if ( i->makeSymbolicLink )
status = symlink(i->source, destination);
else
status = link(i->source, destination);
}
linkName = argv[argc - 1];
if ( status != 0 ) {
name_and_error(destination);
return 1;
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
if (removeoldFlag==TRUE ) {
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, linkName);
else
return 0;
status = link(*argv, linkName);
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
}
}
exit( TRUE);
}
+234
View File
@@ -0,0 +1,234 @@
/*
* loadfont.c - Eugene Crosser & Andries Brouwer
*
* Version 0.96bb
*
* Loads the console font, and possibly the corresponding screen map(s).
* (Adapted for busybox by Matej Vela.)
*/
#include "internal.h"
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <memory.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <endian.h>
#define PSF_MAGIC1 0x36
#define PSF_MAGIC2 0x04
#define PSF_MODE512 0x01
#define PSF_MODEHASTAB 0x02
#define PSF_MAXMODE 0x03
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n"
"\n"
"\tLoad a console font from standard input.\n"
"\n";
struct psf_header
{
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void loadnewfont(int fd);
extern int
loadfont_main(int argc, char **argv)
{
int fd;
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
loadnewfont(fd);
return 0;
}
static void
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
char buf[16384];
int i;
memset(buf,0,sizeof(buf));
if (unit < 1 || unit > 32) {
fprintf(stderr, "Bad character size %d\n", unit);
exit(1);
}
for (i = 0; i < fontsize; i++)
memcpy(buf+(32*i), inbuf+(unit*i), unit);
#if defined( PIO_FONTX ) && !defined( __sparc__ )
{
struct consolefontdesc cfd;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
}
#endif
if (ioctl(fd, PIO_FONT, buf)) {
perror("PIO_FONT ioctl error");
exit(1);
}
}
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
struct unimapinit advice;
struct unimapdesc ud;
struct unipair *up;
int ct = 0, maxct;
int glyph;
u_short unicode;
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
if (!up) {
fprintf(stderr, "Out of memory?\n");
exit(1);
}
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
}
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
this printf did not work on many kernels */
advice.advised_hashsize = 0;
advice.advised_hashstep = 0;
advice.advised_hashlevel = 0;
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
#ifdef ENOIOCTLCMD
if (errno == ENOIOCTLCMD) {
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
fprintf(stderr, "No Unicode mapping table loaded.\n");
} else
#endif
perror("PIO_UNIMAPCLR");
exit(1);
}
ud.entry_ct = ct;
ud.entries = up;
if(ioctl(fd, PIO_UNIMAP, &ud)) {
#if 0
if (errno == ENOMEM) {
/* change advice parameters */
}
#endif
perror("PIO_UNIMAP");
exit(1);
}
}
static void
loadnewfont(int fd) {
int unit;
char inbuf[32768]; /* primitive */
int inputlth, offset;
/*
* We used to look at the length of the input file
* with stat(); now that we accept compressed files,
* just read the entire file.
*/
inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
if (ferror(stdin)) {
perror("Error reading input font");
exit(1);
}
/* use malloc/realloc in case of giant files;
maybe these do not occur: 16kB for the font,
and 16kB for the map leaves 32 unicode values
for each font position */
if (!feof(stdin)) {
perror("Font too large");
exit(1);
}
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
int head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = * (struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (psfhdr.mode > PSF_MAXMODE) {
fprintf(stderr, "Unsupported psf file mode\n");
exit(1);
}
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
#if !defined( PIO_FONTX ) || defined( __sparc__ )
if (fontsize != 256) {
fprintf(stderr, "Only fontsize 256 supported\n");
exit(1);
}
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize*unit;
if (head > inputlth || (!hastable && head != inputlth)) {
fprintf(stderr, "Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
return;
}
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377) {
fprintf(stderr, "Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth/256;
}
do_loadfont(fd, inbuf+offset, unit, 256);
}
+24 -3
View File
@@ -1,3 +1,24 @@
/*
* Mini loadkmap implementation for busybox
*
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <errno.h>
#include <fcntl.h>
@@ -7,14 +28,14 @@
#include <sys/ioctl.h>
const char loadkmap_usage[] = "loadkmap\n"
static const char loadkmap_usage[] = "loadkmap\n"
"\n"
"\tLoad a binary keyboard translation table from standard input.\n"
"\n";
int
loadkmap_main(struct FileInfo * info, int argc, char * * argv)
loadkmap_main(int argc, char * * argv)
{
struct kbentry ke;
u_short *ibuff;
@@ -48,7 +69,7 @@ loadkmap_main(struct FileInfo * info, int argc, char * * argv)
if (flags[i]==1){
pos=0;
while (pos < ibuffsz) {
if ( (readsz = read(0,ibuff+pos,ibuffsz-pos)) < 0 ) {
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
fprintf(stderr, "Error reading keymap: %s\n",
strerror(errno));
return 1;
+196
View File
@@ -0,0 +1,196 @@
/*
* Mini logger implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <ctype.h>
#include <netdb.h>
#if !defined BB_SYSLOGD
#define SYSLOG_NAMES
#include <sys/syslog.h>
#else
/* We have to do this since the header file defines static
* structues. Argh.... bad libc, bad, bad...
*/
#include <sys/syslog.h>
typedef struct _code {
char *c_name;
int c_val;
} CODE;
extern CODE prioritynames[];
extern CODE facilitynames[];
#endif
static const char logger_usage[] =
"logger [OPTION]... [MESSAGE]\n\n"
"Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n"
"Options:\n"
"\t-s\tLog to stderr as well as the system log.\n"
"\t-p\tEnter the message with the specified priority.\n"
"\t\tThis may be numerical or a ``facility.level'' pair.\n";
/* Decode a symbolic name to a numeric value
* this function is based on code
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*/
static int
decode(char* name, CODE* codetab)
{
CODE *c;
if (isdigit(*name))
return (atoi(name));
for (c = codetab; c->c_name; c++) {
if (!strcasecmp(name, c->c_name)) {
return (c->c_val);
}
}
return (-1);
}
/* Decode a symbolic name to a numeric value
* this function is based on code
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*/
static int
pencode(char* s)
{
char *save;
int lev, fac=LOG_USER;
for (save = s; *s && *s != '.'; ++s);
if (*s) {
*s = '\0';
fac = decode(save, facilitynames);
if (fac < 0) {
fprintf(stderr, "unknown facility name: %s\n", save);
exit( FALSE);
}
*s++ = '.';
}
else {
s = save;
}
lev = decode(s, prioritynames);
if (lev < 0) {
fprintf(stderr, "unknown priority name: %s\n", save);
exit( FALSE);
}
return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
}
extern int logger_main(int argc, char **argv)
{
struct sockaddr_un sunx;
int fd, pri = LOG_USER|LOG_NOTICE;
int fromStdinFlag=FALSE;
int toStdErrFlag=FALSE;
char *message, buf[1024], buf1[1024];
time_t now;
size_t addrLength;
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromStdinFlag=TRUE;
}
while (*(++(*argv))) {
switch (**argv) {
case 's':
toStdErrFlag = TRUE;
break;
case 'p':
if (--argc == 0) {
usage(logger_usage);
}
pri = pencode(*(++argv));
if (--argc == 0) {
usage(logger_usage);
}
++argv;
break;
default:
usage(logger_usage);
}
}
}
if (fromStdinFlag==TRUE) {
/* read from stdin */
int i=0;
char c;
while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) {
buf1[i++]=c;
}
message=buf1;
} else {
if (argc>=1) {
message=*argv;
} else {
fprintf(stderr, "No message\n");
exit( FALSE);
}
}
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX; /* Unix domain socket */
strncpy(sunx.sun_path, _PATH_LOG, sizeof(sunx.sun_path));
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) {
perror("Couldn't obtain descriptor for socket " _PATH_LOG);
exit( FALSE);
}
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
if (connect(fd, (struct sockaddr *) &sunx, addrLength)) {
perror("Could not connect to socket " _PATH_LOG);
exit( FALSE);
}
time(&now);
snprintf (buf, sizeof(buf), "<%d>%.15s %s", pri, ctime(&now)+4, message);
if (toStdErrFlag==TRUE)
fprintf(stderr, "%s\n", buf);
write( fd, buf, sizeof(buf));
close(fd);
exit( TRUE);
}
-190
View File
@@ -1,190 +0,0 @@
/*
* losetup.c - setup and control loop devices
*/
#include "internal.h"
const char losetup_usage[] = "losetup\n"
"\n"
"\tlosetup loop_device give info\n"
"\tlosetup -d loop_device delete\n"
"\tlosetup [ -o offset ] loop_device file setup\n";
/* from mount-2.6d */
/*
* losetup.c - setup and control loop devices
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
/* #include "loop.h" */
/*
* include/linux/loop.h
*
* Written by Theodore Ts'o, 3/29/93.
*
* Copyright 1993 by Theodore Ts'o. Redistribution of this file is
* permitted under the GNU Public License.
*/
#define LO_NAME_SIZE 64
#define LO_KEY_SIZE 32
struct loop_info {
int lo_number; /* ioctl r/o */
dev_t lo_device; /* ioctl r/o */
unsigned long lo_inode; /* ioctl r/o */
dev_t lo_rdevice; /* ioctl r/o */
int lo_offset;
int lo_encrypt_type;
int lo_encrypt_key_size; /* ioctl w/o */
int lo_flags; /* ioctl r/o */
char lo_name[LO_NAME_SIZE];
unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
unsigned long lo_init[2];
char reserved[4];
};
/*
* IOCTL commands --- we will commandeer 0x4C ('L')
*/
#define LOOP_SET_FD 0x4C00
#define LOOP_CLR_FD 0x4C01
#define LOOP_SET_STATUS 0x4C02
#define LOOP_GET_STATUS 0x4C03
/* #include "lomount.h" */
extern int set_loop (const char *, const char *, int, int *);
extern int del_loop (const char *);
static void show_loop(const char *device)
{
struct loop_info loopinfo;
int fd;
if ((fd = open(device, O_RDWR)) < 0) {
perror(device);
return;
}
if (ioctl(fd, LOOP_GET_STATUS, &loopinfo) < 0) {
perror("Cannot get loop info");
close(fd);
return;
}
printf("%s: [%04x]:%ld (%s) offset %d\n",
device, (unsigned int)loopinfo.lo_device, loopinfo.lo_inode,
loopinfo.lo_name, loopinfo.lo_offset);
close(fd);
}
int set_loop(const char *device, const char *file, int offset, int *loopro)
{
struct loop_info loopinfo;
int fd, ffd, mode;
mode = *loopro ? O_RDONLY : O_RDWR;
if ((ffd = open (file, mode)) < 0 && !*loopro
&& (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
perror (file);
return 1;
}
if ((fd = open (device, mode)) < 0) {
close(ffd);
perror (device);
return 1;
}
*loopro = (mode == O_RDONLY);
memset(&loopinfo, 0, sizeof(loopinfo));
strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
loopinfo.lo_offset = offset;
loopinfo.lo_encrypt_key_size = 0;
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
perror("ioctl: LOOP_SET_FD");
exit(1);
}
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
(void) ioctl(fd, LOOP_CLR_FD, 0);
perror("ioctl: LOOP_SET_STATUS");
exit(1);
}
close(fd);
close(ffd);
return 0;
}
int del_loop(const char *device)
{
int fd;
if ((fd = open(device, O_RDONLY)) < 0) {
perror(device);
exit(1);
}
if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
perror("ioctl: LOOP_CLR_FD");
exit(1);
}
close(fd);
return(0);
}
static int losetup_usage_fn(void)
{
fprintf(stderr, losetup_usage);
exit(1);
}
int losetup_main(struct FileInfo * i, int argc, char * * argv)
{
char *offset;
int delete,off,c;
int ro = 0;
delete = off = 0;
offset = NULL;
while ((c = getopt(argc,argv,"do:")) != EOF) {
switch (c) {
case 'd':
delete = 1;
break;
case 'o':
offset = optarg;
break;
default:
losetup_usage_fn();
}
}
if (argc == 1) losetup_usage_fn();
if ((delete && (argc != optind+1 || offset)) ||
(!delete && (argc < optind+1 || argc > optind+2)))
losetup_usage_fn();
if (argc == optind+1)
if (delete)
del_loop(argv[optind]);
else
show_loop(argv[optind]);
else {
if (offset && sscanf(offset,"%d",&off) != 1)
losetup_usage_fn();
set_loop(argv[optind],argv[optind+1],off,&ro);
}
return 0;
}
+68 -103
View File
@@ -1,4 +1,3 @@
#include "internal.h"
/*
* tiny-ls.c version 0.1.0: A minimalist 'ls'
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
@@ -41,22 +40,15 @@
* 1. requires lstat (BSD) - how do you do it without?
*/
#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
#define FEATURE_TIMESTAMPS /* show file timestamps */
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
#define FEATURE_FILETYPECHAR /* enable -p and -F */
#undef OP_BUF_SIZE 1024 /* leave undefined for unbuffered output */
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
#define COLUMN_GAP 2 /* includes the file type char, if present */
#define HAS_REWINDDIR
/************************************************************************/
#define HAS_REWINDDIR
#if 1 /* FIXME libc 6 */
#include "internal.h"
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
# include <linux/types.h>
#else
# include <sys/types.h>
@@ -67,17 +59,13 @@
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#ifdef FEATURE_USERNAME
#include <pwd.h>
#include <grp.h>
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
#include <time.h>
#endif
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
#endif
@@ -86,27 +74,6 @@
#define MINOR(dev) ((dev)&0xff)
#endif
#define MODE1 "rwxrwxrwx"
#define MODE0 "---------"
#define SMODE1 "..s..s..t"
#define SMODE0 "..S..S..T"
/* The 9 mode bits to test */
static const umode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const umode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
};
#define FMT_AUTO 0
#define FMT_LONG 1 /* one record per line, extended info */
#define FMT_SINGLE 2 /* one record per line */
@@ -131,14 +98,14 @@ static unsigned char display_fmt = FMT_AUTO;
static unsigned short opts = 0;
static unsigned short column = 0;
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
static unsigned char time_fmt = TIME_MOD;
#endif
@@ -146,7 +113,7 @@ static unsigned char time_fmt = TIME_MOD;
static void writenum(long val, short minwidth)
{
char scratch[20];
char scratch[128];
char *p = scratch + sizeof(scratch);
short len = 0;
@@ -191,8 +158,8 @@ static void tab(short col)
#undef nspaces
}
#ifdef FEATURE_FILETYPECHAR
static char append_char(umode_t mode)
#ifdef BB_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
return '\0';
@@ -209,55 +176,52 @@ static char append_char(umode_t mode)
**
**/
static void list_single(const char *name, struct stat *info)
static void list_single(const char *name, struct stat *info, const char *fullname)
{
char scratch[20];
char scratch[PATH_MAX];
short len = strlen(name);
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
char append = append_char(info->st_mode);
#endif
if (display_fmt == FMT_LONG) {
umode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
for (i=0; i<9; i++)
if (mode & SBIT[i])
scratch[i+1] = (mode & MBIT[i])
? SMODE1[i]
: SMODE0[i];
else
scratch[i+1] = (mode & MBIT[i])
? MODE1[i]
: MODE0[i];
mode_t mode = info->st_mode;
newline();
wr(scratch, 10);
wr(modeString(mode), 10);
column=10;
writenum((long)info->st_nlink,(short)4);
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
#ifdef FEATURE_USERNAME
#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct passwd *pw = getpwuid(info->st_uid);
if (pw)
fputs(pw->pw_name, stdout);
else
writenum((long)info->st_uid,(short)0);
scratch[0]='\0';
my_getpwuid( scratch, info->st_uid);
scratch[8]='\0';
if (*scratch)
wr(scratch,8);
else {
writenum((long) info->st_uid,(short)8);
fputs(" ", stdout);
}
} else
#endif
writenum((long)info->st_uid,(short)0);
tab(24);
#ifdef FEATURE_USERNAME
{
writenum((long) info->st_uid,(short)8);
fputs(" ", stdout);
}
tab(16);
#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct group *gr = getgrgid(info->st_gid);
if (gr)
fputs(gr->gr_name, stdout);
else
writenum((long)info->st_gid,(short)0);
scratch[0]='\0';
my_getgrgid( scratch, info->st_gid);
scratch[8]='\0';
if (*scratch)
wr(scratch,8);
else
writenum((long) info->st_gid,(short)8);
} else
#endif
writenum((long)info->st_gid,(short)0);
tab(33);
writenum((long) info->st_gid,(short)8);
tab(17);
if (S_ISBLK(mode) || S_ISCHR(mode)) {
writenum((long)MAJOR(info->st_rdev),(short)3);
fputs(", ", stdout);
@@ -266,7 +230,7 @@ static void list_single(const char *name, struct stat *info)
else
writenum((long)info->st_size,(short)8);
fputs(" ", stdout);
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
{
time_t cal;
char *string;
@@ -300,12 +264,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len);
if (S_ISLNK(mode)) {
wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(name, info)) {
if (!stat(fullname, info)) {
append = append_char(info->st_mode);
if (append)
fputc(append, stdout);
@@ -313,7 +277,7 @@ static void list_single(const char *name, struct stat *info)
}
#endif
}
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
else if (append)
wr(&append, 1);
#endif
@@ -327,7 +291,7 @@ static void list_single(const char *name, struct stat *info)
newline();
else {
if (nexttab + column_width > terminal_width
#ifndef FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_AUTOWIDTH
|| nexttab + len >= terminal_width
#endif
)
@@ -336,7 +300,7 @@ static void list_single(const char *name, struct stat *info)
tab(nexttab);
}
/* work out where next column starts */
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
/* we know the calculated width is big enough */
nexttab = column + column_width + COLUMN_GAP;
#else
@@ -349,7 +313,7 @@ static void list_single(const char *name, struct stat *info)
/* now write the data */
wr(name, len);
column = column + len;
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
if (append)
wr(&append, 1), column++;
#endif
@@ -375,7 +339,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) {
list_single(name, &info);
list_single(name, &info, name);
return 0;
}
@@ -390,7 +354,7 @@ static int list_item(const char *name)
dir = opendir(name);
if (!dir) goto listerr;
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
column_width = 0;
while ((entry = readdir(dir)) != NULL) {
short w = strlen(entry->d_name);
@@ -427,7 +391,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name);
if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info);
list_single(entry->d_name, &info, fullname);
}
closedir(dir);
return 0;
@@ -436,27 +400,27 @@ direrr:
closedir(dir);
listerr:
newline();
name_and_error(name);
perror(name);
return 1;
}
const char ls_usage[] = "Usage: ls [-1a"
#ifdef FEATURE_TIMESTAMPS
static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_TIMESTAMPS
"c"
#endif
"d"
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
"e"
#endif
"ln"
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
"p"
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
"u"
#endif
"xAC"
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
#ifdef FEATURE_RECURSIVE
@@ -465,7 +429,7 @@ const char ls_usage[] = "Usage: ls [-1a"
"] [filenames...]\n";
extern int
ls_main(struct FileInfo * not_used, int argc, char * * argv)
ls_main(int argc, char * * argv)
{
int argi=1, i;
@@ -489,7 +453,7 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
case '1': display_fmt = FMT_SINGLE; break;
case 'x': display_fmt = FMT_ROWS; break;
case 'C': display_fmt = FMT_COLUMNS; break;
#ifdef FEATURE_FILETYPECHAR
#ifdef BB_FEATURE_LS_FILETYPES
case 'p': opts |= DISP_FTYPE; break;
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
#endif
@@ -500,7 +464,7 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
#ifdef FEATURE_RECURSIVE
case 'R': opts |= DIR_RECURSE; break;
#endif
#ifdef FEATURE_TIMESTAMPS
#ifdef BB_FEATURE_LS_TIMESTAMPS
case 'u': time_fmt = TIME_ACCESS; break;
case 'c': time_fmt = TIME_CHANGE; break;
case 'e': opts |= DISP_FULLTIME; break;
@@ -513,10 +477,10 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
/* choose a display format */
if (display_fmt == FMT_AUTO)
display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
#ifdef FEATURE_AUTOWIDTH
#ifdef BB_FEATURE_AUTOWIDTH
/* could add a -w option and/or TIOCGWINSZ call */
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
@@ -534,9 +498,10 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
while (argi < argc)
i |= list_item(argv[argi++]);
newline();
return i;
exit( i);
print_usage_message:
usage(ls_usage);
return 1;
usage (ls_usage);
exit( FALSE);
}
+3 -4
View File
@@ -15,13 +15,13 @@
#include <sys/types.h>
#include <sys/stat.h>
const char makedevs_usage[] =
static const char makedevs_usage[] =
"makedevs 0.01 -- Create an entire range of device files\n\n"
"\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n"
"\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n";
int
makedevs_main(struct FileInfo * i, int argc, char * * argv)
makedevs_main(int argc, char * * argv)
{
const char *basedev = argv[1];
@@ -45,8 +45,7 @@ char buf[255];
case 'f':
mode = S_IFIFO; break;
default:
usage(makedevs_usage);
return 2;
usage( makedevs_usage);
}
mode |= 0660;
Loaded 100 of 166 files, more files were not shown because too many files have changed in this diff. Show more