Compare commits

..
67 Commits
Author SHA1 Message Date
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
137 changed files with 19303 additions and 9752 deletions

No files matched your search

+1
View File
@@ -1 +1,2 @@
busybox
busybox.links
+114 -1
View File
@@ -1,3 +1,116 @@
0.32
* usage() now printf 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
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
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
0.28
mini-netcat (mnc) rewritten.
0.27
Mount now supports -a, and -t auto.
Mount now updates mtab correctly for 'ro'.
@@ -5,4 +118,4 @@
Printf added as module.
0.26
Touch now creates files. -c option for no create.
+8 -1
View File
@@ -18,7 +18,14 @@ mini-gzip(gzip), mini-netcat(mnc)
Copyright 1998 Charles P. Wright <cpwright@villagenet.com>
Please see the top of the source files for more precise indivigual
bunches of stuff as noted in header files
Copyright (C) 1999 by Lineo, inc. and written by
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
copyright and license info.
This program suite may be distributed under the GNU General Public License.
Please send patches, suggestions, insults, and bribes to <andersee@debian.org>.
+59 -15
View File
@@ -1,38 +1,82 @@
# 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.32
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/'`
STRIP= strip --remove-section=.note --remove-section=.comment busybox
LDFLAGS= -s
# -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 -Os -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`
endif
BINDIR=$(prefix)
LIBRARIES=
OBJECTS=$(shell ./busybox.sh)
CFLAGS+= -DBB_VER='"$(VERSION)"'
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
#all: busybox links
all: busybox
all: busybox links
busybox: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o busybox $(OBJECTS) $(LIBRARIES)
#$(STRIP)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
$(STRIP)
links:
- ./busybox.mkll | sort >busybox.links
clean:
- rm -f busybox busybox.links *~ *.o
- rm -f $(PROG) busybox.links *~ *.o core
distclean: clean
- rm -f busybox
- rm -f $(PROG)
force:
$(OBJECTS): busybox.def.h internal.h Makefile
install: $(PROG)
install.sh $(BINDIR)
+6 -7
View File
@@ -3,9 +3,10 @@ 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.
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.
It is geared toward the very small, i.e. boot floppies, embedded-
systems, etc. 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 modularized to allow an easy build of
@@ -17,11 +18,9 @@ using C++ comments (//)
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.
Note the modular system is Makefile based, and purposly very
Note the modular system is Makefile based, and purposely 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>
Erik Andersen <andersee@deban.org>
+62 -46
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},
@@ -32,7 +28,7 @@ static const struct Applet applets[] = {
{"clear", clear_main},
#endif
#ifdef BB_CP //bin
{"cp", dyadic_main},
{"cp", cp_main},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
@@ -47,17 +43,26 @@ static const struct Applet applets[] = {
{"dmesg", dmesg_main},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", cat_more_main},
#endif
#ifdef BB_FALSE //bin
{"false", false_main},
{"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_CHVT //usr/bin
{"chvt", chvt_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
@@ -74,14 +79,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 +97,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 +109,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 +118,14 @@ static const struct Applet applets[] = {
{"mt", mt_main},
#endif
#ifdef BB_MV //bin
{"mv", dyadic_main},
{"mv", mv_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,7 +136,14 @@ 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},
@@ -136,23 +151,25 @@ static const struct Applet applets[] = {
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_SWAPOFF //sbin
{"swapoff", monadic_main},
#endif
#ifdef BB_SWAPON //sbin
{"swapon", monadic_main},
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", monadic_main},
{"touch", touch_main},
#endif
#ifdef BB_TRUE //bin
#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},
@@ -191,40 +208,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",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
fprintf(stderr,
"\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
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
tr [:upper:] [:lower:]
+5 -29
View File
@@ -8,10 +8,10 @@
#ifdef BB_GZIP
#ifndef BB_ZCAT
error: you need zcat to have gzip support!
#error you need zcat to have gzip support!
#endif
const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
static 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.
@@ -380,7 +380,7 @@ 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 $ */
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 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 +391,7 @@ 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 $ */
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -766,10 +766,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 +971,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 +1583,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>
@@ -1781,7 +1769,7 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
// 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)
{
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
@@ -1924,10 +1912,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 +2926,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>
@@ -3141,10 +3121,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>
+831 -1090
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;
}
}
+62 -46
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},
@@ -32,7 +28,7 @@ static const struct Applet applets[] = {
{"clear", clear_main},
#endif
#ifdef BB_CP //bin
{"cp", dyadic_main},
{"cp", cp_main},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
@@ -47,17 +43,26 @@ static const struct Applet applets[] = {
{"dmesg", dmesg_main},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", cat_more_main},
#endif
#ifdef BB_FALSE //bin
{"false", false_main},
{"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_CHVT //usr/bin
{"chvt", chvt_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
@@ -74,14 +79,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 +97,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 +109,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 +118,14 @@ static const struct Applet applets[] = {
{"mt", mt_main},
#endif
#ifdef BB_MV //bin
{"mv", dyadic_main},
{"mv", mv_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,7 +136,14 @@ 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},
@@ -136,23 +151,25 @@ static const struct Applet applets[] = {
#ifdef BB_TAR //bin
{"tar", tar_main},
#endif
#ifdef BB_SWAPOFF //sbin
{"swapoff", monadic_main},
#endif
#ifdef BB_SWAPON //sbin
{"swapon", monadic_main},
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", monadic_main},
{"touch", touch_main},
#endif
#ifdef BB_TRUE //bin
#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},
@@ -191,40 +208,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",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
fprintf(stderr,
"\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));
}
}
+52 -51
View File
@@ -3,62 +3,63 @@
* 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_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_FSCK_MINIX
#define BB_MKFS_MINIX
#define BB_CHVT
#define BB_DEALLOCVT
#define BB_GREP
//#define BB_HALT
#define BB_INIT
#define BB_KILL
//#define BB_LENGTH
#define BB_LN
#define BB_LOADFONT
#define BB_LOADKMAP
#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_MT
//#define BB_MTAB
#define BB_MV
//#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_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_TAR
#define BB_TOUCH
//#define BB_TRUE_FALSE // Supplied by ash
#define BB_UMOUNT
#define BB_UPDATE
#define BB_UNAME
#define BB_ZCAT
//#define BB_GZIP
// Don't turn BB_UTILITY off. It contains support code
// that compiles to 0 if everything else if turned off.
#define BB_UTILITY
+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
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
tr [:upper:] [:lower:]
+10 -10
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.29alpha
Version: 0.32
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,15 +7,15 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.29a1.tar.gz
Source: busybox-0.32.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
@@ -30,10 +30,10 @@ 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' ` );
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/ln
install -m 755 busybox $RPM_BUILD_ROOT/bin/ln
rm -f $RPM_BUILD_ROOT/bin/busybox
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
%Clean
rm -rf $RPM_BUILD_ROOT
+23 -15
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,16 +23,27 @@
#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++;
@@ -39,16 +51,12 @@ extern int cat_more_main(int argc, char **argv)
while (argc-- > 0) {
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);
print_file( file);
argc--;
argv++;
}
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 mode_t mode=0644;
#define CHGRP_APP 1
#define CHOWN_APP 2
#define CHMOD_APP 3
static const char chgrp_usage[] = "[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";
static const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n"
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
static const char chmod_usage[] = "[-R] MODE[,MODE]... FILE...\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"
"\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:
if (chmod(fileName, mode) == 0)
return( TRUE);
break;
}
perror(fileName);
return( FALSE);
}
int chmod_chown_chgrp_main(int argc, char **argv)
{
int recursiveFlag=FALSE;
char *groupName;
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv,
(whichApp==TRUE)? chown_usage : chgrp_usage);
exit( FALSE);
}
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);
exit( FALSE);
}
argc--;
argv++;
}
if ( whichApp == CHMOD_APP ) {
/* Find the specified modes */
mode = 0;
if ( parse_mode(*argv, &mode) == FALSE ) {
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv);
exit( FALSE);
}
} 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[] = "NEWROOT [COMMAND...]\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 </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 </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);
}
+48
View File
@@ -0,0 +1,48 @@
/*
* 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 < 1) /* unlikely */
exit(1);
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;
+23 -15
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,16 +23,27 @@
#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++;
@@ -39,16 +51,12 @@ extern int cat_more_main(int argc, char **argv)
while (argc-- > 0) {
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);
print_file( file);
argc--;
argv++;
}
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[] = "NEWROOT [COMMAND...]\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);
}
+101 -75
View File
@@ -1,89 +1,115 @@
/*
* 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"
"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));
}
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"
"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);
}
+203 -276
View File
@@ -1,307 +1,234 @@
/*
* 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 <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=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 k for x1024, b for x512, and w for x2.\n";
#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)
static long getNum (const char *cp)
{
long value;
long value;
if (!isDecimal(*cp))
return -1;
if (!isDecimal (*cp))
return -1;
value = 0;
value = 0;
while (isDecimal(*cp))
value = value * 10 + *cp++ - '0';
while (isDecimal (*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++)
{
case 'k':
value *= 1024;
break;
switch (*cp++) {
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
extern int dd_main (int argc, char **argv)
{
const char *inFile;
const char *outFile;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
int skipBlocks;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char *buf;
inFile = NULL;
outFile = NULL;
blockSize = 512;
skipBlocks = 0;
count = 1;
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 %ld\n", count);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %d\n", blockSize);
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++;
}
if ( inFile == NULL || outFile == NULL)
goto usage;
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
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;
}
inCc -= outCc;
cp += outCc;
outTotal += outCc;
}
}
if (inCc < 0)
perror (inFile);
cleanup:
close (inFd);
close (outFd);
free (buf);
printf ("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
exit( TRUE);
usage:
fprintf (stderr, "%s", dd_usage);
exit( FALSE);
}
#endif
/* END CODE */
+132 -87
View File
@@ -1,103 +1,148 @@
/*
* 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;
if ( statfs(mountPoint, &s) != 0 ) {
name_and_error(mountPoint);
return 1;
}
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);
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return 1;
}
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);
if (strcmp(device, "/dev/root") == 0)
device = (getfsfile("/"))->fs_spec;
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);
}
return 0;
}
/*
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;
}
extern int
df_main(struct FileInfo * i, int argc, char * * argv)
* 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)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
struct stat s;
dev_t mountDevice;
FILE *mountTable;
struct mntent *mountEntry;
if ( argc > 1 ) {
struct mntent * mountEntry;
int status;
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;
}
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);
}
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;
}
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
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]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
return status;
argc--;
argv++;
}
return 0;
} else {
FILE *mountTable;
struct mntent *mountEntry;
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
}
while ((mountEntry = getmntent(mountTable))) {
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status)
return status;
}
endmntent(mountTable);
}
return 0;
}
+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 -33
View File
@@ -1,52 +1,100 @@
/*
* 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"
static 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 int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{
int status = 0;
char d[PATH_MAX];
const char * destination = i->destination;
int status;
char newdestName[NAME_MAX];
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);
}
destName = argv[argc - 1];
if ( status != 0 ) {
name_and_error(destination);
return 1;
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
else
return 0;
status = link(*argv, newdestName);
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
}
exit( TRUE);
}
+17 -19
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,20 @@
* 1. requires lstat (BSD) - how do you do it without?
*/
#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
//#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>
@@ -93,7 +90,7 @@
/* The 9 mode bits to test */
static const umode_t MBIT[] = {
static const mode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
@@ -101,7 +98,7 @@ static const umode_t MBIT[] = {
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const umode_t SBIT[] = {
static const mode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
@@ -146,7 +143,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;
@@ -192,7 +189,7 @@ static void tab(short col)
}
#ifdef FEATURE_FILETYPECHAR
static char append_char(umode_t mode)
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
return '\0';
@@ -211,14 +208,14 @@ static char append_char(umode_t mode)
static void list_single(const char *name, struct stat *info)
{
char scratch[20];
char scratch[PATH_MAX];
short len = strlen(name);
#ifdef FEATURE_FILETYPECHAR
char append = append_char(info->st_mode);
#endif
if (display_fmt == FMT_LONG) {
umode_t mode = info->st_mode;
mode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
@@ -436,11 +433,11 @@ direrr:
closedir(dir);
listerr:
newline();
name_and_error(name);
perror(name);
return 1;
}
const char ls_usage[] = "Usage: ls [-1a"
static const char ls_usage[] = "ls [-1a"
#ifdef FEATURE_TIMESTAMPS
"c"
#endif
@@ -465,7 +462,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;
@@ -534,9 +531,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);
}
+89 -46
View File
@@ -1,58 +1,101 @@
/*
* 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"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"-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 = 777;
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;
status=stat(*argv, &statBuf);
if (status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", *argv);
exit( FALSE);
}
if (parentFlag == TRUE)
createPath(*argv, mode);
else {
if (mkdir (*argv, mode) != 0) {
perror(*argv);
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;
}
+29 -9
View File
@@ -1,11 +1,33 @@
/*
* 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"
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
"\tMake special files.\n"
"\n"
"\tb:\tMake a block (buffered) device.\n"
@@ -13,7 +35,7 @@ const char mknod_usage[] = "mknod file b|c|u|p major minor\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);
}
+70 -28
View File
@@ -1,38 +1,80 @@
/*
* 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"
"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));
}
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);
}
+84 -21
View File
@@ -1,30 +1,93 @@
/*
* 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 <errno.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.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"
"Remove (unlink) the FILE(s).\n\n"
"\t-f\tremove existing destinations, never prompt\n"
"\t-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)
{
if (argc < 2) {
usage( rm_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
default:
usage( rm_usage);
}
argc--;
argv++;
}
while (argc-- > 0) {
srcName = *(argv++);
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
fileAction, dirAction) == FALSE) {
exit( FALSE);
}
else
return 0;
}
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...\nRemove the DIRECTORY(ies), if they are empty.");
}
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[] = " NUMBER\n"
"Pause for NUMBER 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\nWrite all buffered filesystem blocks to disk.\n");
}
exit( sync());
}
+80 -14
View File
@@ -1,20 +1,86 @@
#include "internal.h"
#include <sys/types.h>
#include <stdio.h>
#include <utime.h>
/*
* 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
*
*/
const char touch_usage[] = "touch [-c] file [file ...]\n"
"\n"
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utime.h>
#include <errno.h>
static 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)
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:
fprintf(stderr, "Unknown option: %c\n", **argv);
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);
}
+165
View File
@@ -0,0 +1,165 @@
/* 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"
"Print certain system information. With no OPTION, same as -s.\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');
}
}
+101 -75
View File
@@ -1,89 +1,115 @@
/*
* 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"
"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));
}
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"
"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);
}
+203 -276
View File
@@ -1,307 +1,234 @@
/*
* 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 <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=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 k for x1024, b for x512, and w for x2.\n";
#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)
static long getNum (const char *cp)
{
long value;
long value;
if (!isDecimal(*cp))
return -1;
if (!isDecimal (*cp))
return -1;
value = 0;
value = 0;
while (isDecimal(*cp))
value = value * 10 + *cp++ - '0';
while (isDecimal (*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++)
{
case 'k':
value *= 1024;
break;
switch (*cp++) {
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
extern int dd_main (int argc, char **argv)
{
const char *inFile;
const char *outFile;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
int skipBlocks;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char *buf;
inFile = NULL;
outFile = NULL;
blockSize = 512;
skipBlocks = 0;
count = 1;
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 %ld\n", count);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %d\n", blockSize);
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++;
}
if ( inFile == NULL || outFile == NULL)
goto usage;
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
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;
}
inCc -= outCc;
cp += outCc;
outTotal += outCc;
}
}
if (inCc < 0)
perror (inFile);
cleanup:
close (inFd);
close (outFd);
free (buf);
printf ("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
exit( TRUE);
usage:
fprintf (stderr, "%s", dd_usage);
exit( FALSE);
}
#endif
/* END CODE */
+48
View File
@@ -0,0 +1,48 @@
/*
* 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 < 1) /* unlikely */
exit(1);
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;
}
+132 -87
View File
@@ -1,103 +1,148 @@
/*
* 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;
if ( statfs(mountPoint, &s) != 0 ) {
name_and_error(mountPoint);
return 1;
}
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);
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return 1;
}
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);
if (strcmp(device, "/dev/root") == 0)
device = (getfsfile("/"))->fs_spec;
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);
}
return 0;
}
/*
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;
}
extern int
df_main(struct FileInfo * i, int argc, char * * argv)
* 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)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
printf(header);
struct stat s;
dev_t mountDevice;
FILE *mountTable;
struct mntent *mountEntry;
if ( argc > 1 ) {
struct mntent * mountEntry;
int status;
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;
}
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);
}
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;
}
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
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]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
return status;
argc--;
argv++;
}
return 0;
} else {
FILE *mountTable;
struct mntent *mountEntry;
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
}
while ((mountEntry = getmntent(mountTable))) {
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status)
return status;
}
endmntent(mountTable);
}
return 0;
}
+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 );
}
+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)
static 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);
}
+180
View File
@@ -0,0 +1,180 @@
/*
* 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"
"Allowed scripts come in the following form:\n\n"
"'s/regexp/replacement/[gp]'\n"
"\tattempt to match regexp against the pattern space\n"
"\tand 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 regexps.\n";
#else
"This version of sed matches strings (not full regexps).\n";
#endif
extern int sed_main (int argc, char **argv)
{
FILE *fp;
char *needle=NULL, *newNeedle=NULL;
char *name;
char *cp;
int ignoreCase=FALSE;
int foundOne=FALSE;
int printFlag=FALSE;
int quietFlag=FALSE;
int stopNow;
char *haystack;
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) {
fprintf(stderr, "A\n");
usage( sed_usage);
}
cp = *argv++;
while( *cp ) {
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
char* pos=needle=cp+2;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "B\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
pos++;
continue;
}
break;
}
*pos=0;
newNeedle=++pos;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "C\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
pos++;
continue;
}
break;
}
*pos=0;
if (pos+2 != 0) {
while (*++pos) {
fprintf(stderr, "pos='%s'\n", 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:
fprintf(stderr, "D\n");
usage(sed_usage);
}
}
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
haystack = (char*)malloc( 1024);
while (fgets (haystack, 1023, fp)) {
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
if (foundOne==TRUE && printFlag==TRUE)
fputs (haystack, stdout);
if (quietFlag==FALSE)
fputs (haystack, stdout);
/* Avoid any mem leaks */
free(haystack);
haystack = (char*)malloc( BUF_SIZE);
}
if (ferror (fp))
perror (name);
fclose (fp);
}
exit( TRUE);
}
/* END CODE */
+10 -10
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.29alpha
Version: 0.32
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,15 +7,15 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.29a1.tar.gz
Source: busybox-0.32.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
@@ -30,10 +30,10 @@ 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' ` );
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/ln
install -m 755 busybox $RPM_BUILD_ROOT/bin/ln
rm -f $RPM_BUILD_ROOT/bin/busybox
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
%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);
}
+93 -13
View File
@@ -1,23 +1,103 @@
/*
* 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"
"default path is the current directory; default expression is -print\n"
"expression may consist of:\n";
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 if (find_match((char*)fileName, pattern, TRUE) == 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;
}
+93 -13
View File
@@ -1,23 +1,103 @@
/*
* 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"
"default path is the current directory; default expression is -print\n"
"expression may consist of:\n";
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 if (find_match((char*)fileName, pattern, TRUE) == 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);
}
+118 -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,104 @@
#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 [-ihn]... PATTERN [FILE]...\n"
"Search for PATTERN in each FILE or standard input.\n\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 regexps.\n";
#else
"This version of grep matches strings (not full regexps).\n";
#endif
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *needle;
char *name;
char *cp;
int tellName=TRUE;
int ignoreCase=FALSE;
int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
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 = FALSE;
break;
case 'n':
tellLine = TRUE;
break;
default:
usage(grep_usage);
}
}
needle = *argv++;
argc--;
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
line = 0;
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", name);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s: ", name);
if (tellLine==TRUE)
printf ("%ld: ", line);
fputs (haystack, stdout);
}
}
if (ferror (fp))
perror (name);
fclose (fp);
}
exit( TRUE);
}
/* END CODE */
+1367
View File
File diff suppressed because it is too large. Load diff
+118 -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,104 @@
#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 [-ihn]... PATTERN [FILE]...\n"
"Search for PATTERN in each FILE or standard input.\n\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 regexps.\n";
#else
"This version of grep matches strings (not full regexps).\n";
#endif
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *needle;
char *name;
char *cp;
int tellName=TRUE;
int ignoreCase=FALSE;
int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
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 = FALSE;
break;
case 'n':
tellLine = TRUE;
break;
default:
usage(grep_usage);
}
}
needle = *argv++;
argc--;
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
line = 0;
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", name);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s: ", name);
if (tellLine==TRUE)
printf ("%ld: ", line);
fputs (haystack, stdout);
}
}
if (ferror (fp))
perror (name);
fclose (fp);
}
exit( TRUE);
}
/* END CODE */
+5 -29
View File
@@ -8,10 +8,10 @@
#ifdef BB_GZIP
#ifndef BB_ZCAT
error: you need zcat to have gzip support!
#error you need zcat to have gzip support!
#endif
const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
static 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.
@@ -380,7 +380,7 @@ 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 $ */
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 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 +391,7 @@ 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 $ */
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -766,10 +766,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 +971,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 +1583,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>
@@ -1781,7 +1769,7 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
// 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)
{
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
@@ -1924,10 +1912,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 +2926,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>
@@ -3141,10 +3121,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>
+25 -6
View File
@@ -1,12 +1,31 @@
/*
* 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);
exit( kill(1, SIGUSR1));
}
+447 -385
View File
@@ -1,3 +1,26 @@
/*
* Mini init implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Adjusted by so many folks, it's impossible to keep track.
*
* 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>
@@ -13,426 +36,465 @@
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/kdaemon.h>
#include <sys/swap.h>
#include <sys/sysmacros.h>
#include <linux/serial.h> /* for serial_struct */
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
const char init_usage[] = "Used internally by the system.";
char console[16] = "";
const char * default_console = "/dev/tty1";
char * first_terminal = NULL;
const char * second_terminal = "/dev/tty2";
const char log[] = "/dev/tty3";
char * term_ptr = NULL;
#define VT_CONSOLE "/dev/console" /* Logical system console */
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
#define VT_LOG "/dev/tty3" /* Virtual console */
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
#define SHELL "/bin/sh" /* Default shell */
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
static void
message(const char * terminal, const char * pattern, ...)
#define LOG 0x1
#define CONSOLE 0x2
static char *console = VT_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
/* try to open up the specified device */
int device_open(char *device, int mode)
{
int fd;
FILE * con = 0;
va_list arguments;
int m, f, fd = -1;
/*
* Open the console device each time a message is printed. If the user
* has switched consoles, the open will get the new console. If we kept
* the console open, we'd always print to the same one.
*/
if ( ((fd = open(terminal, O_WRONLY|O_NOCTTY)) < 0)
|| ((con = fdopen(fd, "w")) == NULL) )
return;
m = mode | O_NONBLOCK;
va_start(arguments, pattern);
vfprintf(con, pattern, arguments);
va_end(arguments);
fclose(con);
/* Retry up to 5 times */
for (f = 0; f < 5; f++)
if ((fd = open(device, m)) >= 0)
break;
if (fd < 0)
return fd;
/* Reset original flags. */
if (m != mode)
fcntl(fd, F_SETFL, mode);
return fd;
}
static int
waitfor(int pid)
/* print a message to the specified device:
* device may be bitwise-or'd from LOG | CONSOLE */
void message(int device, char *fmt, ...)
{
int status;
int wpid;
message(log, "Waiting for process %d.\n", pid);
while ( (wpid = wait(&status)) != pid ) {
if ( wpid > 0 ) {
message(
log
,"pid %d exited, status=%x.\n"
,wpid
,status);
}
int fd;
static int log_fd=-1;
va_list arguments;
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
if (log_fd==-1) {
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
log_fd=-1;
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
fflush(stderr);
return;
}
}
if ( (device & LOG) && (log_fd != -1) ) {
va_start(arguments, fmt);
vdprintf(log_fd, fmt, arguments);
va_end(arguments);
}
if (device & CONSOLE) {
if ((fd = device_open(console, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
va_start(arguments, fmt);
vdprintf(fd, fmt, arguments);
va_end(arguments);
close(fd);
} else {
fprintf(stderr, "Bummer, can't print: ");
va_start(arguments, fmt);
vfprintf(stderr, fmt, arguments);
fflush(stderr);
va_end(arguments);
}
return wpid;
}
static int
run(
const char * program
,const char * const * arguments
,const char * terminal
,int get_enter)
{
static const char control_characters[] = {
'\003',
'\034',
'\177',
'\025',
'\004',
'\0',
'\1',
'\0',
'\021',
'\023',
'\032',
'\0',
'\022',
'\017',
'\027',
'\026',
'\0'
};
static char * environment[] = {
"HOME=/",
"PATH=/bin:/sbin:/usr/bin:/usr/sbin",
"SHELL=/bin/sh",
0,
"USER=root",
0
};
static const char press_enter[] =
"Please press Enter to activate this console. ";
int pid;
environment[3]=term_ptr;
pid = fork();
if ( pid == 0 ) {
struct termios t;
const char * const * arg;
close(0);
close(1);
close(2);
setsid();
open(terminal, O_RDWR);
dup(0);
dup(0);
tcsetpgrp(0, getpgrp());
tcgetattr(0, &t);
memcpy(t.c_cc, control_characters, sizeof(control_characters));
t.c_line = 0;
t.c_iflag = ICRNL|IXON|IXOFF;
t.c_oflag = OPOST|ONLCR;
t.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
tcsetattr(0, TCSANOW, &t);
if ( get_enter ) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or the installation system.
*/
char c;
write(1, press_enter, sizeof(press_enter) - 1);
read(0, &c, 1);
}
message(log, "Executing ");
arg = arguments;
while ( *arg != 0 )
message(log, "%s ", *arg++);
message(log, "\n");
execve(program, (char * *)arguments, (char * *)environment);
message(log, "%s: could not execute: %s.\r\n", program, strerror(errno));
exit(-1);
}
return pid;
}
static int
mem_total()
{
char s[80];
char *p;
FILE *f;
const char pattern[]="MemTotal:";
f=fopen("/proc/meminfo","r");
while (NULL != fgets(s,79,f)) {
p=strstr(s, pattern);
if (NULL != p) {
fclose(f);
return(atoi(p+strlen(pattern)));
}
}
return -1;
}
static void
set_free_pages()
{
char s[80];
FILE *f;
f=fopen("/proc/sys/vm/freepages","r");
fgets(s,79,f);
if (atoi(s) < 32) {
fclose(f);
f=fopen("/proc/sys/vm/freepages","w");
fprintf(f,"30\t40\t50\n");
printf("\nIncreased /proc/sys/vm/freepages values to 30/40/50\n");
}
fclose(f);
/* Set terminal settings to reasonable defaults */
void set_term( int fd)
{
struct termios tty;
static const char control_characters[] = {
'\003', '\034', '\177', '\030', '\004', '\0',
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
'\017', '\027', '\026', '\0'
};
tcgetattr(fd, &tty);
/* Make it be sane */
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
tty.c_cflag |= HUPCL|CLOCAL;
/* input modes */
tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
/* use line dicipline 0 */
tty.c_line = 0;
/* output modes */
tty.c_oflag = OPOST|ONLCR;
/* local modes */
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
/* control chars */
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
tcsetattr(fd, TCSANOW, &tty);
}
static void
shutdown_system(int do_reboot)
/* How much memory does this machine have? */
static int mem_total()
{
static const char * const umount_args[] = {"/bin/umount", "-a", "-n", 0};
char s[80];
char *p = "/proc/meminfo";
FILE *f;
const char pattern[] = "MemTotal:";
sync();
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
/* Send signals to every process _except_ pid 1 */
message(console, "Sending SIGHUP to all processes.\r\n");
kill(-1, SIGHUP);
sleep(2);
sync();
message(console, "Sending SIGKILL to all processes.\r\n");
kill(-1, SIGKILL);
sleep(1);
waitfor(run("/bin/umount", umount_args, console, 0));
sync();
bdflush(1, 0);
sync();
reboot(do_reboot ?RB_AUTOBOOT : RB_HALT_SYSTEM);
exit(0);
if ((f = fopen(p, "r")) < 0) {
message(LOG, "Error opening %s: %s\n", p, strerror( errno));
return -1;
}
while (NULL != fgets(s, 79, f)) {
p = strstr(s, pattern);
if (NULL != p) {
fclose(f);
return (atoi(p + strlen(pattern)));
}
}
return -1;
}
static void
halt_signal(int sig)
static void console_init()
{
shutdown_system(0);
}
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
char *s;
static void
reboot_signal(int sig)
{
shutdown_system(1);
}
static void
exit_signal(int sig)
{
/* initrd doesn't work anyway */
shutdown_system(1);
/* This is used on the initial ramdisk */
/* message(log, "Init exiting.");
exit(0);
*/
}
void
configure_terminals( int serial_cons );
extern int
init_main(struct FileInfo * i, int argc, char * * argv)
{
static const char * const rc = "etc/rc";
const char * arguments[100];
int run_rc = 1;
int j;
int pid1 = 0;
int pid2 = 0;
int create_swap= -1;
struct stat statbuf;
#ifndef INCLUDE_DINSTALL
const char * tty_commands[2] = { "bin/sh", "bin/sh"};
#else
const char * tty_commands[2] = { "sbin/dinstall", "bin/sh"};
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
/* Apparently the sparc does wierd things... */
#if defined (__sparc__)
if (strncmp( s, "/dev/tty", 8 )==0) {
switch( s[8]) {
case 'a':
s=SERIAL_CON0;
break;
case 'b':
s=SERIAL_CON1;
}
}
#endif
char swap[20];
int serial_console = 0;
} else {
console = VT_CONSOLE;
tried_devcons++;
}
/*
* If I am started as /linuxrc instead of /sbin/init, I don't have the
* environment that init expects. I can't fix the signal behavior. Try
* to divorce from the controlling terminal with setsid(). This won't work
* if I am the process group leader.
*/
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
/* Can't open selected console -- try /dev/console */
if (!tried_devcons) {
tried_devcons++;
console = VT_CONSOLE;
continue;
}
/* Can't open selected console -- try vt1 */
if (!tried_vtprimary) {
tried_vtprimary++;
console = VT_PRIMARY;
continue;
}
break;
}
if (fd < 0)
/* Perhaps we should panic here? */
console = "/dev/null";
else
close(fd);
message(LOG, "console=%s\n", console );
}
static int waitfor(int pid)
{
int status, wpid;
message(LOG, "Waiting for process %d.\n", pid);
while ((wpid = wait(&status)) != pid) {
if (wpid > 0)
message(LOG, "pid %d exited, status=0x%x.\n", wpid, status);
}
return wpid;
}
static pid_t run(const char * const* command,
char *terminal, int get_enter)
{
int fd;
pid_t pid;
const char * const* cmd = command+1;
static const char press_enter[] =
"\nPlease press Enter to activate this console. ";
if ((pid = fork()) == 0) {
/* Clean up */
close(0);
close(1);
close(2);
setsid();
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
signal(SIGTERM, exit_signal);
/* Reset signal handlers set for parent process */
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
reboot(RB_DISABLE_CAD);
message(log, "%s: started. ", argv[0]);
for ( j = 1; j < argc; j++ ) {
if ( strcmp(argv[j], "single") == 0 ) {
run_rc = 0;
tty_commands[0] = "bin/sh";
tty_commands[1] = 0;
}
if ((fd = device_open(terminal, O_RDWR)) < 0) {
message(LOG, "Bummer, can't open %s\r\n", terminal);
exit(-1);
}
for ( j = 0; __environ[j] != 0; j++ ) {
if ( strncmp(__environ[j], "tty", 3) == 0
&& __environ[j][3] >= '1'
&& __environ[j][3] <= '2'
&& __environ[j][4] == '=' ) {
const char * s = &__environ[j][5];
dup(fd);
dup(fd);
tcsetpgrp(0, getpgrp());
set_term(0);
if ( *s == 0 || strcmp(s, "off") == 0 )
s = 0;
tty_commands[__environ[j][3] - '1'] = s;
}
/* Should catch the syntax of Sparc kernel console setting. */
/* The kernel does not recognize a serial console when getting*/
/* console=/dev/ttySX !! */
else if ( strcmp(__environ[j], "console=ttya") == 0 ) {
serial_console=1;
}
else if ( strcmp(__environ[j], "console=ttyb") == 0 ) {
serial_console=2;
}
/* standard console settings */
else if ( strncmp(__environ[j], "console=", 8) == 0 ) {
first_terminal=&(__environ[j][8]);
}
else if ( strncmp(__environ[j], "TERM=", 5) == 0) {
term_ptr=__environ[j];
}
}
configure_terminals( serial_console );
printf("mounting /proc ...\n");
if (mount("/proc","/proc","proc",0,0)) {
perror("mounting /proc failed\n");
}
printf("\tdone.\n");
set_free_pages();
if (mem_total() < 3500) { /* not enough memory for standard install */
int retval;
retval= stat("/etc/swappartition",&statbuf);
if (retval) {
printf("
You do not have enough RAM, hence you must boot using the Boot Disk
for Low Memory systems.
Read the instructions in the install.html file.
");
while (1) {;}
} else { /* everything OK */
FILE *f;
f=fopen("/etc/swappartition","r");
fgets(swap,19,f);
fclose(f);
*(strstr(swap,"\n"))='\0';
if (swapon(swap,0)) {
perror("swapon failed\n");
} else {
f=fopen("/etc/swaps","w");
fprintf(f,"%s none swap rw 0 0",swap);
fclose(f);
create_swap = 0;
}
}
if (get_enter==TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
char c;
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
*cmd, getpid(), terminal );
write(1, press_enter, sizeof(press_enter) - 1);
read(0, &c, 1);
}
/*
* Don't modify **argv directly, it would show up in the "ps" display.
* I don't want "init" to look like "rc".
*/
arguments[0] = rc;
for ( j = 1; j < argc; j++ ) {
arguments[j] = argv[j];
}
arguments[j] = 0;
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
while ( *cmd) message(LOG, "%s ", *cmd++);
message(LOG, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execvp(*command, (char**)command+1);
if ( run_rc )
waitfor(run(rc, arguments, console, 0));
if ( 0 == create_swap) {
if (unlink("/etc/swappartition")) {
perror("unlinking /etc/swappartition");
}
}
arguments[0] = "-sh";
arguments[1] = 0;
for ( ; ; ) {
int wpid;
int status;
if ( pid1 == 0 && tty_commands[0] ) {
/* Ask before starting a shell */
/*
arguments[0] = tty_commands[0];
*/
pid1 = run(tty_commands[0], arguments, first_terminal, 0);
}
if ( pid2 == 0 && tty_commands[1] )
pid2 = run(tty_commands[1], arguments, second_terminal, 1);
wpid = wait(&status);
if ( wpid > 0 ) {
/* DEBUGGING */
message(log, "pid %d exited, status=%x.\n", wpid, status);
}
if ( wpid == pid1 ) {
pid1 = 0;
}
if ( wpid == pid2 )
pid2 = 0;
}
message(LOG, "Bummer, could not run '%s'\n", command);
exit(-1);
}
return pid;
}
void
configure_terminals( int serial_cons )
/* Make sure there is enough memory to do something useful. *
* Calls swapon if needed so be sure /proc is mounted. */
static void check_memory()
{
//struct stat statbuf;
char *tty;
struct stat statbuf;
const char* const swap_on_cmd[] =
{ "/bin/swapon", "swapon", "-a", 0};
switch (serial_cons) {
case 1:
strcpy( console, "/dev/ttyS0" );
break;
case 2:
strcpy( console, "/dev/ttyS1" );
break;
default:
tty = ttyname(0);
if (tty) {
strcpy( console, tty );
if (!strncmp( tty, "/dev/ttyS", 9 ))
serial_cons=1;
}
else
/* falls back to /dev/tty1 if an error occurs */
strcpy( console, default_console );
if (mem_total() > 3500)
return;
if (stat("/etc/fstab", &statbuf) == 0) {
/* Try to turn on swap */
waitfor(run(swap_on_cmd, log, FALSE));
if (mem_total() < 3500)
goto goodnight;
} else
goto goodnight;
return;
goodnight:
message(CONSOLE, "Sorry, your computer does not have enough memory.\r\n");
while (1) sleep(1);
}
static void shutdown_system(void)
{
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
#ifndef DEBUG_INIT
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
#endif
message(CONSOLE, "The system is going down NOW !!\r\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
#ifndef DEBUG_INIT
kill(-1, SIGHUP);
#endif
sleep(2);
sync();
message(CONSOLE, "Sending SIGKILL to all processes.\r\n");
#ifndef DEBUG_INIT
kill(-1, SIGKILL);
#endif
sleep(1);
waitfor(run( swap_off_cmd, console, FALSE));
waitfor(run( umount_cmd, console, FALSE));
sync();
message(CONSOLE, "Skipping bdflush\r\n");
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
}
}
static void halt_signal(int sig)
{
shutdown_system();
message(CONSOLE,
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync();
#ifndef DEBUG_INIT
reboot(RB_HALT_SYSTEM);
//reboot(RB_POWER_OFF);
#endif
exit(0);
}
static void reboot_signal(int sig)
{
shutdown_system();
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
sync();
#ifndef DEBUG_INIT
reboot(RB_AUTOBOOT);
#endif
exit(0);
}
extern int init_main(int argc, char **argv)
{
int run_rc = TRUE;
int wait_for_enter = TRUE;
pid_t pid1 = 0;
pid_t pid2 = 0;
struct stat statbuf;
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
const char* const* tty0_commands = shell_commands;
const char* const* tty1_commands = shell_commands;
#ifdef DEBUG_INIT
char *hello_msg_format =
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
#else
char *hello_msg_format =
"init started: BusyBox v%s (%s) multi-call binary\r\n";
#endif
/* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") ||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
run_rc = FALSE;
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
#ifndef DEBUG_INIT
reboot(RB_DISABLE_CAD);
#endif
/* Figure out where the default console should be */
console_init();
/* Close whatever files are open, and reset the console. */
close(0);
close(1);
close(2);
set_term(0);
setsid();
/* Make sure PATH is set to something sane */
putenv(PATH_DEFAULT);
/* Hello world */
#ifndef DEBUG_INIT
message(CONSOLE|LOG, hello_msg_format, BB_VER, BB_BT);
#else
message(CONSOLE|LOG, hello_msg_format, getpid(), BB_VER, BB_BT);
#endif
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0)
message(CONSOLE|LOG, "Mounting /proc: done.\n");
else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
check_memory();
/* Make sure an init script exists before trying to run it */
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) {
wait_for_enter = FALSE;
tty0_commands = init_commands;
}
/* Ok, now launch the rc script and/or prepare to
* start up some VTs if somebody hits enter...
*/
for (;;) {
pid_t wpid;
int status;
if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter);
}
if (!first_terminal)
first_terminal = console;
if (serial_cons && !strncmp(term_ptr,"TERM=linux",10))
term_ptr = "TERM=vt100";
if (pid2 == 0 && tty1_commands) {
pid2 = run(tty1_commands, second_console, TRUE);
}
wpid = wait(&status);
if (wpid > 0 ) {
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
}
/* Don't respawn init script if it exits */
if (wpid == pid1) {
if (run_rc == FALSE) {
pid1 = 0;
}
#if 0
/* Turn this on to start a shell on the console if the init script exits.... */
else {
run_rc=FALSE;
wait_for_enter=TRUE;
tty0_commands=shell_commands;
}
#endif
}
if (wpid == pid2) {
pid2 = 0;
}
sleep(1);
}
}
+25 -6
View File
@@ -1,12 +1,31 @@
/*
* 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);
exit( kill(1, SIGUSR1));
}
+447 -385
View File
@@ -1,3 +1,26 @@
/*
* Mini init implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
* Adjusted by so many folks, it's impossible to keep track.
*
* 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>
@@ -13,426 +36,465 @@
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/kdaemon.h>
#include <sys/swap.h>
#include <sys/sysmacros.h>
#include <linux/serial.h> /* for serial_struct */
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
const char init_usage[] = "Used internally by the system.";
char console[16] = "";
const char * default_console = "/dev/tty1";
char * first_terminal = NULL;
const char * second_terminal = "/dev/tty2";
const char log[] = "/dev/tty3";
char * term_ptr = NULL;
#define VT_CONSOLE "/dev/console" /* Logical system console */
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
#define VT_LOG "/dev/tty3" /* Virtual console */
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
#define SHELL "/bin/sh" /* Default shell */
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
static void
message(const char * terminal, const char * pattern, ...)
#define LOG 0x1
#define CONSOLE 0x2
static char *console = VT_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
/* try to open up the specified device */
int device_open(char *device, int mode)
{
int fd;
FILE * con = 0;
va_list arguments;
int m, f, fd = -1;
/*
* Open the console device each time a message is printed. If the user
* has switched consoles, the open will get the new console. If we kept
* the console open, we'd always print to the same one.
*/
if ( ((fd = open(terminal, O_WRONLY|O_NOCTTY)) < 0)
|| ((con = fdopen(fd, "w")) == NULL) )
return;
m = mode | O_NONBLOCK;
va_start(arguments, pattern);
vfprintf(con, pattern, arguments);
va_end(arguments);
fclose(con);
/* Retry up to 5 times */
for (f = 0; f < 5; f++)
if ((fd = open(device, m)) >= 0)
break;
if (fd < 0)
return fd;
/* Reset original flags. */
if (m != mode)
fcntl(fd, F_SETFL, mode);
return fd;
}
static int
waitfor(int pid)
/* print a message to the specified device:
* device may be bitwise-or'd from LOG | CONSOLE */
void message(int device, char *fmt, ...)
{
int status;
int wpid;
message(log, "Waiting for process %d.\n", pid);
while ( (wpid = wait(&status)) != pid ) {
if ( wpid > 0 ) {
message(
log
,"pid %d exited, status=%x.\n"
,wpid
,status);
}
int fd;
static int log_fd=-1;
va_list arguments;
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
if (log_fd==-1) {
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
log_fd=-1;
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
fflush(stderr);
return;
}
}
if ( (device & LOG) && (log_fd != -1) ) {
va_start(arguments, fmt);
vdprintf(log_fd, fmt, arguments);
va_end(arguments);
}
if (device & CONSOLE) {
if ((fd = device_open(console, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
va_start(arguments, fmt);
vdprintf(fd, fmt, arguments);
va_end(arguments);
close(fd);
} else {
fprintf(stderr, "Bummer, can't print: ");
va_start(arguments, fmt);
vfprintf(stderr, fmt, arguments);
fflush(stderr);
va_end(arguments);
}
return wpid;
}
static int
run(
const char * program
,const char * const * arguments
,const char * terminal
,int get_enter)
{
static const char control_characters[] = {
'\003',
'\034',
'\177',
'\025',
'\004',
'\0',
'\1',
'\0',
'\021',
'\023',
'\032',
'\0',
'\022',
'\017',
'\027',
'\026',
'\0'
};
static char * environment[] = {
"HOME=/",
"PATH=/bin:/sbin:/usr/bin:/usr/sbin",
"SHELL=/bin/sh",
0,
"USER=root",
0
};
static const char press_enter[] =
"Please press Enter to activate this console. ";
int pid;
environment[3]=term_ptr;
pid = fork();
if ( pid == 0 ) {
struct termios t;
const char * const * arg;
close(0);
close(1);
close(2);
setsid();
open(terminal, O_RDWR);
dup(0);
dup(0);
tcsetpgrp(0, getpgrp());
tcgetattr(0, &t);
memcpy(t.c_cc, control_characters, sizeof(control_characters));
t.c_line = 0;
t.c_iflag = ICRNL|IXON|IXOFF;
t.c_oflag = OPOST|ONLCR;
t.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
tcsetattr(0, TCSANOW, &t);
if ( get_enter ) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or the installation system.
*/
char c;
write(1, press_enter, sizeof(press_enter) - 1);
read(0, &c, 1);
}
message(log, "Executing ");
arg = arguments;
while ( *arg != 0 )
message(log, "%s ", *arg++);
message(log, "\n");
execve(program, (char * *)arguments, (char * *)environment);
message(log, "%s: could not execute: %s.\r\n", program, strerror(errno));
exit(-1);
}
return pid;
}
static int
mem_total()
{
char s[80];
char *p;
FILE *f;
const char pattern[]="MemTotal:";
f=fopen("/proc/meminfo","r");
while (NULL != fgets(s,79,f)) {
p=strstr(s, pattern);
if (NULL != p) {
fclose(f);
return(atoi(p+strlen(pattern)));
}
}
return -1;
}
static void
set_free_pages()
{
char s[80];
FILE *f;
f=fopen("/proc/sys/vm/freepages","r");
fgets(s,79,f);
if (atoi(s) < 32) {
fclose(f);
f=fopen("/proc/sys/vm/freepages","w");
fprintf(f,"30\t40\t50\n");
printf("\nIncreased /proc/sys/vm/freepages values to 30/40/50\n");
}
fclose(f);
/* Set terminal settings to reasonable defaults */
void set_term( int fd)
{
struct termios tty;
static const char control_characters[] = {
'\003', '\034', '\177', '\030', '\004', '\0',
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
'\017', '\027', '\026', '\0'
};
tcgetattr(fd, &tty);
/* Make it be sane */
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
tty.c_cflag |= HUPCL|CLOCAL;
/* input modes */
tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
/* use line dicipline 0 */
tty.c_line = 0;
/* output modes */
tty.c_oflag = OPOST|ONLCR;
/* local modes */
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
/* control chars */
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
tcsetattr(fd, TCSANOW, &tty);
}
static void
shutdown_system(int do_reboot)
/* How much memory does this machine have? */
static int mem_total()
{
static const char * const umount_args[] = {"/bin/umount", "-a", "-n", 0};
char s[80];
char *p = "/proc/meminfo";
FILE *f;
const char pattern[] = "MemTotal:";
sync();
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
/* Send signals to every process _except_ pid 1 */
message(console, "Sending SIGHUP to all processes.\r\n");
kill(-1, SIGHUP);
sleep(2);
sync();
message(console, "Sending SIGKILL to all processes.\r\n");
kill(-1, SIGKILL);
sleep(1);
waitfor(run("/bin/umount", umount_args, console, 0));
sync();
bdflush(1, 0);
sync();
reboot(do_reboot ?RB_AUTOBOOT : RB_HALT_SYSTEM);
exit(0);
if ((f = fopen(p, "r")) < 0) {
message(LOG, "Error opening %s: %s\n", p, strerror( errno));
return -1;
}
while (NULL != fgets(s, 79, f)) {
p = strstr(s, pattern);
if (NULL != p) {
fclose(f);
return (atoi(p + strlen(pattern)));
}
}
return -1;
}
static void
halt_signal(int sig)
static void console_init()
{
shutdown_system(0);
}
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
char *s;
static void
reboot_signal(int sig)
{
shutdown_system(1);
}
static void
exit_signal(int sig)
{
/* initrd doesn't work anyway */
shutdown_system(1);
/* This is used on the initial ramdisk */
/* message(log, "Init exiting.");
exit(0);
*/
}
void
configure_terminals( int serial_cons );
extern int
init_main(struct FileInfo * i, int argc, char * * argv)
{
static const char * const rc = "etc/rc";
const char * arguments[100];
int run_rc = 1;
int j;
int pid1 = 0;
int pid2 = 0;
int create_swap= -1;
struct stat statbuf;
#ifndef INCLUDE_DINSTALL
const char * tty_commands[2] = { "bin/sh", "bin/sh"};
#else
const char * tty_commands[2] = { "sbin/dinstall", "bin/sh"};
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
/* Apparently the sparc does wierd things... */
#if defined (__sparc__)
if (strncmp( s, "/dev/tty", 8 )==0) {
switch( s[8]) {
case 'a':
s=SERIAL_CON0;
break;
case 'b':
s=SERIAL_CON1;
}
}
#endif
char swap[20];
int serial_console = 0;
} else {
console = VT_CONSOLE;
tried_devcons++;
}
/*
* If I am started as /linuxrc instead of /sbin/init, I don't have the
* environment that init expects. I can't fix the signal behavior. Try
* to divorce from the controlling terminal with setsid(). This won't work
* if I am the process group leader.
*/
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
/* Can't open selected console -- try /dev/console */
if (!tried_devcons) {
tried_devcons++;
console = VT_CONSOLE;
continue;
}
/* Can't open selected console -- try vt1 */
if (!tried_vtprimary) {
tried_vtprimary++;
console = VT_PRIMARY;
continue;
}
break;
}
if (fd < 0)
/* Perhaps we should panic here? */
console = "/dev/null";
else
close(fd);
message(LOG, "console=%s\n", console );
}
static int waitfor(int pid)
{
int status, wpid;
message(LOG, "Waiting for process %d.\n", pid);
while ((wpid = wait(&status)) != pid) {
if (wpid > 0)
message(LOG, "pid %d exited, status=0x%x.\n", wpid, status);
}
return wpid;
}
static pid_t run(const char * const* command,
char *terminal, int get_enter)
{
int fd;
pid_t pid;
const char * const* cmd = command+1;
static const char press_enter[] =
"\nPlease press Enter to activate this console. ";
if ((pid = fork()) == 0) {
/* Clean up */
close(0);
close(1);
close(2);
setsid();
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
signal(SIGTERM, exit_signal);
/* Reset signal handlers set for parent process */
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
reboot(RB_DISABLE_CAD);
message(log, "%s: started. ", argv[0]);
for ( j = 1; j < argc; j++ ) {
if ( strcmp(argv[j], "single") == 0 ) {
run_rc = 0;
tty_commands[0] = "bin/sh";
tty_commands[1] = 0;
}
if ((fd = device_open(terminal, O_RDWR)) < 0) {
message(LOG, "Bummer, can't open %s\r\n", terminal);
exit(-1);
}
for ( j = 0; __environ[j] != 0; j++ ) {
if ( strncmp(__environ[j], "tty", 3) == 0
&& __environ[j][3] >= '1'
&& __environ[j][3] <= '2'
&& __environ[j][4] == '=' ) {
const char * s = &__environ[j][5];
dup(fd);
dup(fd);
tcsetpgrp(0, getpgrp());
set_term(0);
if ( *s == 0 || strcmp(s, "off") == 0 )
s = 0;
tty_commands[__environ[j][3] - '1'] = s;
}
/* Should catch the syntax of Sparc kernel console setting. */
/* The kernel does not recognize a serial console when getting*/
/* console=/dev/ttySX !! */
else if ( strcmp(__environ[j], "console=ttya") == 0 ) {
serial_console=1;
}
else if ( strcmp(__environ[j], "console=ttyb") == 0 ) {
serial_console=2;
}
/* standard console settings */
else if ( strncmp(__environ[j], "console=", 8) == 0 ) {
first_terminal=&(__environ[j][8]);
}
else if ( strncmp(__environ[j], "TERM=", 5) == 0) {
term_ptr=__environ[j];
}
}
configure_terminals( serial_console );
printf("mounting /proc ...\n");
if (mount("/proc","/proc","proc",0,0)) {
perror("mounting /proc failed\n");
}
printf("\tdone.\n");
set_free_pages();
if (mem_total() < 3500) { /* not enough memory for standard install */
int retval;
retval= stat("/etc/swappartition",&statbuf);
if (retval) {
printf("
You do not have enough RAM, hence you must boot using the Boot Disk
for Low Memory systems.
Read the instructions in the install.html file.
");
while (1) {;}
} else { /* everything OK */
FILE *f;
f=fopen("/etc/swappartition","r");
fgets(swap,19,f);
fclose(f);
*(strstr(swap,"\n"))='\0';
if (swapon(swap,0)) {
perror("swapon failed\n");
} else {
f=fopen("/etc/swaps","w");
fprintf(f,"%s none swap rw 0 0",swap);
fclose(f);
create_swap = 0;
}
}
if (get_enter==TRUE) {
/*
* Save memory by not exec-ing anything large (like a shell)
* before the user wants it. This is critical if swap is not
* enabled and the system has low memory. Generally this will
* be run on the second virtual console, and the first will
* be allowed to start a shell or whatever an init script
* specifies.
*/
char c;
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
*cmd, getpid(), terminal );
write(1, press_enter, sizeof(press_enter) - 1);
read(0, &c, 1);
}
/*
* Don't modify **argv directly, it would show up in the "ps" display.
* I don't want "init" to look like "rc".
*/
arguments[0] = rc;
for ( j = 1; j < argc; j++ ) {
arguments[j] = argv[j];
}
arguments[j] = 0;
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
while ( *cmd) message(LOG, "%s ", *cmd++);
message(LOG, "'\r\n");
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
execvp(*command, (char**)command+1);
if ( run_rc )
waitfor(run(rc, arguments, console, 0));
if ( 0 == create_swap) {
if (unlink("/etc/swappartition")) {
perror("unlinking /etc/swappartition");
}
}
arguments[0] = "-sh";
arguments[1] = 0;
for ( ; ; ) {
int wpid;
int status;
if ( pid1 == 0 && tty_commands[0] ) {
/* Ask before starting a shell */
/*
arguments[0] = tty_commands[0];
*/
pid1 = run(tty_commands[0], arguments, first_terminal, 0);
}
if ( pid2 == 0 && tty_commands[1] )
pid2 = run(tty_commands[1], arguments, second_terminal, 1);
wpid = wait(&status);
if ( wpid > 0 ) {
/* DEBUGGING */
message(log, "pid %d exited, status=%x.\n", wpid, status);
}
if ( wpid == pid1 ) {
pid1 = 0;
}
if ( wpid == pid2 )
pid2 = 0;
}
message(LOG, "Bummer, could not run '%s'\n", command);
exit(-1);
}
return pid;
}
void
configure_terminals( int serial_cons )
/* Make sure there is enough memory to do something useful. *
* Calls swapon if needed so be sure /proc is mounted. */
static void check_memory()
{
//struct stat statbuf;
char *tty;
struct stat statbuf;
const char* const swap_on_cmd[] =
{ "/bin/swapon", "swapon", "-a", 0};
switch (serial_cons) {
case 1:
strcpy( console, "/dev/ttyS0" );
break;
case 2:
strcpy( console, "/dev/ttyS1" );
break;
default:
tty = ttyname(0);
if (tty) {
strcpy( console, tty );
if (!strncmp( tty, "/dev/ttyS", 9 ))
serial_cons=1;
}
else
/* falls back to /dev/tty1 if an error occurs */
strcpy( console, default_console );
if (mem_total() > 3500)
return;
if (stat("/etc/fstab", &statbuf) == 0) {
/* Try to turn on swap */
waitfor(run(swap_on_cmd, log, FALSE));
if (mem_total() < 3500)
goto goodnight;
} else
goto goodnight;
return;
goodnight:
message(CONSOLE, "Sorry, your computer does not have enough memory.\r\n");
while (1) sleep(1);
}
static void shutdown_system(void)
{
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
#ifndef DEBUG_INIT
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
#endif
message(CONSOLE, "The system is going down NOW !!\r\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
#ifndef DEBUG_INIT
kill(-1, SIGHUP);
#endif
sleep(2);
sync();
message(CONSOLE, "Sending SIGKILL to all processes.\r\n");
#ifndef DEBUG_INIT
kill(-1, SIGKILL);
#endif
sleep(1);
waitfor(run( swap_off_cmd, console, FALSE));
waitfor(run( umount_cmd, console, FALSE));
sync();
message(CONSOLE, "Skipping bdflush\r\n");
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
}
}
static void halt_signal(int sig)
{
shutdown_system();
message(CONSOLE,
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
sync();
#ifndef DEBUG_INIT
reboot(RB_HALT_SYSTEM);
//reboot(RB_POWER_OFF);
#endif
exit(0);
}
static void reboot_signal(int sig)
{
shutdown_system();
message(CONSOLE, "Please stand by while rebooting the system.\r\n");
sync();
#ifndef DEBUG_INIT
reboot(RB_AUTOBOOT);
#endif
exit(0);
}
extern int init_main(int argc, char **argv)
{
int run_rc = TRUE;
int wait_for_enter = TRUE;
pid_t pid1 = 0;
pid_t pid2 = 0;
struct stat statbuf;
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
const char* const* tty0_commands = shell_commands;
const char* const* tty1_commands = shell_commands;
#ifdef DEBUG_INIT
char *hello_msg_format =
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
#else
char *hello_msg_format =
"init started: BusyBox v%s (%s) multi-call binary\r\n";
#endif
/* Check if we are supposed to be in single user mode */
if ( argc > 1 && (!strcmp(argv[1], "single") ||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
run_rc = FALSE;
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, reboot_signal);
signal(SIGINT, reboot_signal);
signal(SIGTERM, reboot_signal);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
#ifndef DEBUG_INIT
reboot(RB_DISABLE_CAD);
#endif
/* Figure out where the default console should be */
console_init();
/* Close whatever files are open, and reset the console. */
close(0);
close(1);
close(2);
set_term(0);
setsid();
/* Make sure PATH is set to something sane */
putenv(PATH_DEFAULT);
/* Hello world */
#ifndef DEBUG_INIT
message(CONSOLE|LOG, hello_msg_format, BB_VER, BB_BT);
#else
message(CONSOLE|LOG, hello_msg_format, getpid(), BB_VER, BB_BT);
#endif
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0)
message(CONSOLE|LOG, "Mounting /proc: done.\n");
else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
check_memory();
/* Make sure an init script exists before trying to run it */
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) {
wait_for_enter = FALSE;
tty0_commands = init_commands;
}
/* Ok, now launch the rc script and/or prepare to
* start up some VTs if somebody hits enter...
*/
for (;;) {
pid_t wpid;
int status;
if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter);
}
if (!first_terminal)
first_terminal = console;
if (serial_cons && !strncmp(term_ptr,"TERM=linux",10))
term_ptr = "TERM=vt100";
if (pid2 == 0 && tty1_commands) {
pid2 = run(tty1_commands, second_console, TRUE);
}
wpid = wait(&status);
if (wpid > 0 ) {
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
}
/* Don't respawn init script if it exits */
if (wpid == pid1) {
if (run_rc == FALSE) {
pid1 = 0;
}
#if 0
/* Turn this on to start a shell on the console if the init script exits.... */
else {
run_rc=FALSE;
wait_for_enter=TRUE;
tty0_commands=shell_commands;
}
#endif
}
if (wpid == pid2) {
pid2 = 0;
}
sleep(1);
}
}
+24 -6
View File
@@ -1,12 +1,30 @@
/*
* 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);
exit( kill(1, SIGUSR2));
}
+101 -110
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_
@@ -10,11 +32,10 @@
/* 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,65 +47,29 @@ 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 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 grep_main(int argc, char** argv);
extern int halt_main(int argc, char** argv);
@@ -92,98 +77,104 @@ 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 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 tar_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 uname_main(int argc, char** argv);
extern int zcat_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);
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 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[];
extern void createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern volatile void usage(const char *usage);
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 void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
#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
#endif /* _INTERNAL_H_ */
+125 -106
View File
@@ -1,140 +1,159 @@
/*
* 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>
const char kill_usage[] = "kill [-signal] process-id [process-id ...]\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;
if ( argc < 2 )
usage (kill_usage);
if ( **(argv+1) == '-' ) {
if (isdigit( *(*(++argv)+1) )) {
sig = atoi (*argv);
if (sig < 0 || sig >= NSIG)
goto end;
}
while ( argc > 1 ) {
int pid;
if ( argv[1][0] < '0' || argv[1][0] > '9' ) {
usage(kill_usage);
exit(-1);
else {
const struct signal_name *s = signames;
while (s->name != 0) {
if (strcasecmp (s->name, *argv+1) == 0) {
sig = s->number;
break;
}
pid = atoi(argv[1]);
if ( kill(pid, sig) != 0 ) {
had_error = 1;
perror(argv[1]);
}
argv++;
argc--;
s++;
}
if (s->name == 0)
goto end;
}
if ( had_error )
return -1;
else
return 0;
}
while (--argc > 1) {
int pid;
if (! isdigit( **(++argv))) {
fprintf(stderr, "bad PID: %s\n", *argv);
exit( FALSE);
}
pid = atoi (*argv);
if (kill (pid, sig) != 0) {
perror (*argv);
exit ( FALSE);
}
}
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 -33
View File
@@ -1,52 +1,100 @@
/*
* 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"
static 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 int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{
int status = 0;
char d[PATH_MAX];
const char * destination = i->destination;
int status;
char newdestName[NAME_MAX];
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);
}
destName = argv[argc - 1];
if ( status != 0 ) {
name_and_error(destination);
return 1;
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
else
return 0;
status = link(*argv, newdestName);
if ( status != 0 ) {
perror(newdestName);
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;
-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;
}
+17 -19
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,20 @@
* 1. requires lstat (BSD) - how do you do it without?
*/
#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
//#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>
@@ -93,7 +90,7 @@
/* The 9 mode bits to test */
static const umode_t MBIT[] = {
static const mode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
@@ -101,7 +98,7 @@ static const umode_t MBIT[] = {
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const umode_t SBIT[] = {
static const mode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
@@ -146,7 +143,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;
@@ -192,7 +189,7 @@ static void tab(short col)
}
#ifdef FEATURE_FILETYPECHAR
static char append_char(umode_t mode)
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
return '\0';
@@ -211,14 +208,14 @@ static char append_char(umode_t mode)
static void list_single(const char *name, struct stat *info)
{
char scratch[20];
char scratch[PATH_MAX];
short len = strlen(name);
#ifdef FEATURE_FILETYPECHAR
char append = append_char(info->st_mode);
#endif
if (display_fmt == FMT_LONG) {
umode_t mode = info->st_mode;
mode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
@@ -436,11 +433,11 @@ direrr:
closedir(dir);
listerr:
newline();
name_and_error(name);
perror(name);
return 1;
}
const char ls_usage[] = "Usage: ls [-1a"
static const char ls_usage[] = "ls [-1a"
#ifdef FEATURE_TIMESTAMPS
"c"
#endif
@@ -465,7 +462,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;
@@ -534,9 +531,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;
+2 -2
View File
@@ -6,7 +6,7 @@
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
const char math_usage[] = "math expression ...";
static const char math_usage[] = "math expression ...";
static double stack[100];
static unsigned int pointer;
@@ -137,7 +137,7 @@ stack_machine(const char * argument)
}
int
math_main(struct FileInfo * i, int argc, char * * argv)
math_main(int argc, char * * argv)
{
while ( argc >= 2 ) {
stack_machine(argv[1]);
+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)
static 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);
}
+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;
+9 -10
View File
@@ -3,7 +3,7 @@
#include <sys/mtio.h>
#include <sys/fcntl.h>
const char mt_usage[] = "mt [-f device] opcode value\n";
static const char mt_usage[] = "mt [-f device] opcode value\n";
struct mt_opcodes {
char * name;
@@ -50,7 +50,7 @@ static const struct mt_opcodes opcodes[] = {
};
extern int
mt_main(struct FileInfo * i, int argc, char * * argv)
mt_main(int argc, char** argv)
{
const char * file = "/dev/tape";
const struct mt_opcodes * code = opcodes;
@@ -59,8 +59,7 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
if ( strcmp(argv[1], "-f") == 0 ) {
if ( argc < 4 ) {
usage(mt_usage);
return 1;
usage (mt_usage);
}
file = argv[2];
argv += 2;
@@ -75,7 +74,7 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
if ( code->name == 0 ) {
fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]);
return 1;
return( FALSE);
}
op.mt_op = code->value;
@@ -85,14 +84,14 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
op.mt_count = 1; /* One, not zero, right? */
if ( (fd = open(file, O_RDONLY, 0)) < 0 ) {
name_and_error(file);
return 1;
perror(file);
return( FALSE);
}
if ( ioctl(fd, MTIOCTOP, &op) != 0 ) {
name_and_error(file);
return 1;
perror(file);
return( FALSE);
}
return 0;
return( TRUE);
}
+23 -5
View File
@@ -1,10 +1,28 @@
/*
* Mini update 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 <linux/unistd.h>
const char update_usage[] = "update\n"
"\n"
"\tFlush buffered data to the disk devices every 30 seconds.\n";
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
#else
@@ -12,7 +30,7 @@ _syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
extern int
update_main(struct FileInfo * i, int argc, char * * argv)
update_main(int argc, char** argv)
{
/*
* Update is actually two daemons, bdflush and update.
+89 -46
View File
@@ -1,58 +1,101 @@
/*
* 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"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"-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 = 777;
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;
status=stat(*argv, &statBuf);
if (status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", *argv);
exit( FALSE);
}
if (parentFlag == TRUE)
createPath(*argv, mode);
else {
if (mkdir (*argv, mode) != 0) {
perror(*argv);
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;
}
+746
View File
@@ -0,0 +1,746 @@
/*
* mkfs.c - make a linux (minix) file-system.
*
* (C) 1991 Linus Torvalds. This file may be redistributed as per
* the Linux copyright.
*/
/*
* DD.MM.YY
*
* 24.11.91 - Time began. Used the fsck sources to get started.
*
* 25.11.91 - Corrected some bugs. Added support for ".badblocks"
* The algorithm for ".badblocks" is a bit weird, but
* it should work. Oh, well.
*
* 25.01.92 - Added the -l option for getting the list of bad blocks
* out of a named file. (Dave Rivers, rivers@ponds.uucp)
*
* 28.02.92 - Added %-information when using -c.
*
* 28.02.93 - Added support for other namelengths than the original
* 14 characters so that I can test the new kernel routines..
*
* 09.10.93 - Make exit status conform to that required by fsutil
* (Rik Faith, faith@cs.unc.edu)
*
* 31.10.93 - Added inode request feature, for backup floppies: use
* 32 inodes, for a news partition use more.
* (Scott Heavner, sdh@po.cwru.edu)
*
* 03.01.94 - Added support for file system valid flag.
* (Dr. Wettstein, greg%wind.uucp@plains.nodak.edu)
*
* 30.10.94 - added support for v2 filesystem
* (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)
*
* 09.11.94 - Added test to prevent overwrite of mounted fs adapted
* from Theodore Ts'o's (tytso@athena.mit.edu) mke2fs
* program. (Daniel Quinlan, quinlan@yggdrasil.com)
*
* 03.20.95 - Clear first 512 bytes of filesystem to make certain that
* the filesystem is not misidentified as a MS-DOS FAT filesystem.
* (Daniel Quinlan, quinlan@yggdrasil.com)
*
* 02.07.96 - Added small patch from Russell King to make the program a
* good deal more portable (janl@math.uio.no)
*
* Usage: mkfs [-c | -l filename ] [-v] [-nXX] [-iXX] device [size-in-blocks]
*
* -c for readablility checking (SLOW!)
* -l for getting a list of bad blocks from a file.
* -n for namelength (currently the kernel only uses 14 or 30)
* -i for number of inodes
* -v for v2 filesystem
*
* The device may be a block device or a image of one, but this isn't
* enforced (but it's not much fun on a character device :-).
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <mntent.h>
#include <getopt.h>
#include <linux/fs.h>
#include <linux/minix_fs.h>
#ifdef MINIX2_SUPER_MAGIC2
#define HAVE_MINIX2 1
#endif
#ifndef __GNUC__
#error "needs gcc for the bitop-__asm__'s"
#endif
#ifndef __linux__
#define volatile
#endif
#define MINIX_ROOT_INO 1
#define MINIX_BAD_INO 2
#define TEST_BUFFER_BLOCKS 16
#define MAX_GOOD_BLOCKS 512
#define UPPER(size,n) (((size)+((n)-1))/(n))
#define INODE_SIZE (sizeof(struct minix_inode))
#ifdef HAVE_MINIX2
#define INODE_SIZE2 (sizeof(struct minix2_inode))
#define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
: MINIX_INODES_PER_BLOCK))
#else
#define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK))
#endif
#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
static char * program_name = "mkfs";
static char * device_name = NULL;
static int DEV = -1;
static long BLOCKS = 0;
static int check = 0;
static int badblocks = 0;
static int namelen = 30; /* default (changed to 30, per Linus's
suggestion, Sun Nov 21 08:05:07 1993) */
static int dirsize = 32;
static int magic = MINIX_SUPER_MAGIC2;
static int version2 = 0;
static char root_block[BLOCK_SIZE] = "\0";
static char * inode_buffer = NULL;
#define Inode (((struct minix_inode *) inode_buffer)-1)
#ifdef HAVE_MINIX2
#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
#endif
static char super_block_buffer[BLOCK_SIZE];
static char boot_block_buffer[512];
#define Super (*(struct minix_super_block *)super_block_buffer)
#define INODES ((unsigned long)Super.s_ninodes)
#ifdef HAVE_MINIX2
#define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones))
#else
#define ZONES ((unsigned long)(Super.s_nzones))
#endif
#define IMAPS ((unsigned long)Super.s_imap_blocks)
#define ZMAPS ((unsigned long)Super.s_zmap_blocks)
#define FIRSTZONE ((unsigned long)Super.s_firstdatazone)
#define ZONESIZE ((unsigned long)Super.s_log_zone_size)
#define MAXSIZE ((unsigned long)Super.s_max_size)
#define MAGIC (Super.s_magic)
#define NORM_FIRSTZONE (2+IMAPS+ZMAPS+INODE_BLOCKS)
static char *inode_map;
static char *zone_map;
static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks = 0;
static unsigned long req_nr_inodes = 0;
#define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
#define mark_inode(x) (setbit(inode_map,(x)))
#define unmark_inode(x) (clrbit(inode_map,(x)))
#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1))
#define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1))
/*
* Volatile to let gcc know that this doesn't return. When trying
* to compile this under minix, volatile gives a warning, as
* exit() isn't defined as volatile under minix.
*/
static volatile void die(char *str) {
fprintf(stderr, "%s: %s\n", program_name, str);
exit(8);
}
static volatile void show_usage()
{
fprintf(stderr, "%s\n", program_name);
fprintf(stderr,
"Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n",
program_name);
exit(16);
}
/*
* Check to make certain that our new filesystem won't be created on
* an already mounted partition. Code adapted from mke2fs, Copyright
* (C) 1994 Theodore Ts'o. Also licensed under GPL.
*/
static void check_mount(void)
{
FILE * f;
struct mntent * mnt;
if ((f = setmntent (MOUNTED, "r")) == NULL)
return;
while ((mnt = getmntent (f)) != NULL)
if (strcmp (device_name, mnt->mnt_fsname) == 0)
break;
endmntent (f);
if (!mnt)
return;
die("%s is mounted; will not make a filesystem here!");
}
static long valid_offset (int fd, int offset)
{
char ch;
if (lseek (fd, offset, 0) < 0)
return 0;
if (read (fd, &ch, 1) < 1)
return 0;
return 1;
}
static int count_blocks (int fd)
{
int high, low;
low = 0;
for (high = 1; valid_offset (fd, high); high *= 2)
low = high;
while (low < high - 1)
{
const int mid = (low + high) / 2;
if (valid_offset (fd, mid))
low = mid;
else
high = mid;
}
valid_offset (fd, 0);
return (low + 1);
}
static int get_size(const char *file)
{
int fd;
long size;
fd = open(file, O_RDWR);
if (fd < 0) {
perror(file);
exit(1);
}
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd);
return (size * 512);
}
size = count_blocks(fd);
close(fd);
return size;
}
static void write_tables(void)
{
/* Mark the super block valid. */
Super.s_state |= MINIX_VALID_FS;
Super.s_state &= ~MINIX_ERROR_FS;
if (lseek(DEV, 0, SEEK_SET))
die("seek to boot block failed in write_tables");
if (512 != write(DEV, boot_block_buffer, 512))
die("unable to clear boot sector");
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
die("unable to write super-block");
if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE))
die("unable to write inode map");
if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE))
die("unable to write zone map");
if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE))
die("unable to write inodes");
}
static void write_block(int blk, char * buffer)
{
if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET))
die("seek failed in write_block");
if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE))
die("write failed in write_block");
}
static int get_free_block(void)
{
int blk;
if (used_good_blocks+1 >= MAX_GOOD_BLOCKS)
die("too many bad blocks");
if (used_good_blocks)
blk = good_blocks_table[used_good_blocks-1]+1;
else
blk = FIRSTZONE;
while (blk < ZONES && zone_in_use(blk))
blk++;
if (blk >= ZONES)
die("not enough good blocks");
good_blocks_table[used_good_blocks] = blk;
used_good_blocks++;
return blk;
}
static void mark_good_blocks(void)
{
int blk;
for (blk=0 ; blk < used_good_blocks ; blk++)
mark_zone(good_blocks_table[blk]);
}
inline int next(int zone)
{
if (!zone)
zone = FIRSTZONE-1;
while (++zone < ZONES)
if (zone_in_use(zone))
return zone;
return 0;
}
static void make_bad_inode(void)
{
struct minix_inode * inode = &Inode[MINIX_BAD_INO];
int i,j,zone;
int ind=0,dind=0;
unsigned short ind_block[BLOCK_SIZE>>1];
unsigned short dind_block[BLOCK_SIZE>>1];
#define NEXT_BAD (zone = next(zone))
if (!badblocks)
return;
mark_inode(MINIX_BAD_INO);
inode->i_nlinks = 1;
inode->i_time = time(NULL);
inode->i_mode = S_IFREG + 0000;
inode->i_size = badblocks*BLOCK_SIZE;
zone = next(0);
for (i=0 ; i<7 ; i++) {
inode->i_zone[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
inode->i_zone[7] = ind = get_free_block();
memset(ind_block,0,BLOCK_SIZE);
for (i=0 ; i<512 ; i++) {
ind_block[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
inode->i_zone[8] = dind = get_free_block();
memset(dind_block,0,BLOCK_SIZE);
for (i=0 ; i<512 ; i++) {
write_block(ind,(char *) ind_block);
dind_block[i] = ind = get_free_block();
memset(ind_block,0,BLOCK_SIZE);
for (j=0 ; j<512 ; j++) {
ind_block[j] = zone;
if (!NEXT_BAD)
goto end_bad;
}
}
die("too many bad blocks");
end_bad:
if (ind)
write_block(ind, (char *) ind_block);
if (dind)
write_block(dind, (char *) dind_block);
}
#ifdef HAVE_MINIX2
static void
make_bad_inode2 (void)
{
struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
int i, j, zone;
int ind = 0, dind = 0;
unsigned long ind_block[BLOCK_SIZE >> 2];
unsigned long dind_block[BLOCK_SIZE >> 2];
if (!badblocks)
return;
mark_inode (MINIX_BAD_INO);
inode->i_nlinks = 1;
inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL);
inode->i_mode = S_IFREG + 0000;
inode->i_size = badblocks * BLOCK_SIZE;
zone = next (0);
for (i = 0; i < 7; i++) {
inode->i_zone[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
inode->i_zone[7] = ind = get_free_block ();
memset (ind_block, 0, BLOCK_SIZE);
for (i = 0; i < 256; i++) {
ind_block[i] = zone;
if (!NEXT_BAD)
goto end_bad;
}
inode->i_zone[8] = dind = get_free_block ();
memset (dind_block, 0, BLOCK_SIZE);
for (i = 0; i < 256; i++) {
write_block (ind, (char *) ind_block);
dind_block[i] = ind = get_free_block ();
memset (ind_block, 0, BLOCK_SIZE);
for (j = 0; j < 256; j++) {
ind_block[j] = zone;
if (!NEXT_BAD)
goto end_bad;
}
}
/* Could make triple indirect block here */
die ("too many bad blocks");
end_bad:
if (ind)
write_block (ind, (char *) ind_block);
if (dind)
write_block (dind, (char *) dind_block);
}
#endif
static void make_root_inode(void)
{
struct minix_inode * inode = &Inode[MINIX_ROOT_INO];
mark_inode(MINIX_ROOT_INO);
inode->i_zone[0] = get_free_block();
inode->i_nlinks = 2;
inode->i_time = time(NULL);
if (badblocks)
inode->i_size = 3*dirsize;
else {
root_block[2*dirsize] = '\0';
root_block[2*dirsize+1] = '\0';
inode->i_size = 2*dirsize;
}
inode->i_mode = S_IFDIR + 0755;
inode->i_uid = getuid();
if (inode->i_uid)
inode->i_gid = getgid();
write_block(inode->i_zone[0],root_block);
}
#ifdef HAVE_MINIX2
static void
make_root_inode2 (void)
{
struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
mark_inode (MINIX_ROOT_INO);
inode->i_zone[0] = get_free_block ();
inode->i_nlinks = 2;
inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL);
if (badblocks)
inode->i_size = 3 * dirsize;
else {
root_block[2 * dirsize] = '\0';
root_block[2 * dirsize + 1] = '\0';
inode->i_size = 2 * dirsize;
}
inode->i_mode = S_IFDIR + 0755;
inode->i_uid = getuid();
if (inode->i_uid)
inode->i_gid = getgid();
write_block (inode->i_zone[0], root_block);
}
#endif
static void setup_tables(void)
{
int i;
unsigned long inodes;
memset(super_block_buffer,0,BLOCK_SIZE);
memset(boot_block_buffer,0,512);
MAGIC = magic;
ZONESIZE = 0;
MAXSIZE = version2 ? 0x7fffffff : (7+512+512*512)*1024;
ZONES = BLOCKS;
/* some magic nrs: 1 inode / 3 blocks */
if ( req_nr_inodes == 0 )
inodes = BLOCKS/3;
else
inodes = req_nr_inodes;
/* Round up inode count to fill block size */
#ifdef HAVE_MINIX2
if (version2)
inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
~(MINIX2_INODES_PER_BLOCK - 1));
else
#endif
inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) &
~(MINIX_INODES_PER_BLOCK - 1));
if (inodes > 65535)
inodes = 65535;
INODES = inodes;
IMAPS = UPPER(INODES + 1,BITS_PER_BLOCK);
ZMAPS = 0;
i=0;
while (ZMAPS != UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK) && i<1000) {
ZMAPS = UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK);
i++;
}
/* Real bad hack but overwise mkfs.minix can be thrown
* in infinite loop...
* try:
* dd if=/dev/zero of=test.fs count=10 bs=1024
* /sbin/mkfs.minix -i 200 test.fs
* */
if (i>=999) {
die ("unable to allocate buffers for maps");
}
FIRSTZONE = NORM_FIRSTZONE;
inode_map = malloc(IMAPS * BLOCK_SIZE);
zone_map = malloc(ZMAPS * BLOCK_SIZE);
if (!inode_map || !zone_map)
die("unable to allocate buffers for maps");
memset(inode_map,0xff,IMAPS * BLOCK_SIZE);
memset(zone_map,0xff,ZMAPS * BLOCK_SIZE);
for (i = FIRSTZONE ; i<ZONES ; i++)
unmark_zone(i);
for (i = MINIX_ROOT_INO ; i<=INODES ; i++)
unmark_inode(i);
inode_buffer = malloc(INODE_BUFFER_SIZE);
if (!inode_buffer)
die("unable to allocate buffer for inodes");
memset(inode_buffer,0,INODE_BUFFER_SIZE);
printf("%ld inodes\n",INODES);
printf("%ld blocks\n",ZONES);
printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE);
printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE);
printf("Maxsize=%ld\n\n",MAXSIZE);
}
/*
* Perform a test of a block; return the number of
* blocks readable/writeable.
*/
long do_check(char * buffer, int try, unsigned int current_block)
{
long got;
/* Seek to the correct loc. */
if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) !=
current_block * BLOCK_SIZE ) {
die("seek failed during testing of blocks");
}
/* Try the read */
got = read(DEV, buffer, try * BLOCK_SIZE);
if (got < 0) got = 0;
if (got & (BLOCK_SIZE - 1 )) {
printf("Weird values in do_check: probably bugs\n");
}
got /= BLOCK_SIZE;
return got;
}
static unsigned int currently_testing = 0;
static void alarm_intr(int alnum)
{
if (currently_testing >= ZONES)
return;
signal(SIGALRM,alarm_intr);
alarm(5);
if (!currently_testing)
return;
printf("%d ...", currently_testing);
fflush(stdout);
}
static void check_blocks(void)
{
int try,got;
static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
currently_testing=0;
signal(SIGALRM,alarm_intr);
alarm(5);
while (currently_testing < ZONES) {
if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) !=
currently_testing*BLOCK_SIZE)
die("seek failed in check_blocks");
try = TEST_BUFFER_BLOCKS;
if (currently_testing + try > ZONES)
try = ZONES-currently_testing;
got = do_check(buffer, try, currently_testing);
currently_testing += got;
if (got == try)
continue;
if (currently_testing < FIRSTZONE)
die("bad blocks before data-area: cannot make fs");
mark_zone(currently_testing);
badblocks++;
currently_testing++;
}
if (badblocks > 1)
printf("%d bad blocks\n", badblocks);
else if (badblocks == 1)
printf("one bad block\n");
}
static void get_list_blocks(filename)
char *filename;
{
FILE *listfile;
unsigned long blockno;
listfile=fopen(filename,"r");
if(listfile == (FILE *)NULL) {
die("can't open file of bad blocks");
}
while(!feof(listfile)) {
fscanf(listfile,"%ld\n", &blockno);
mark_zone(blockno);
badblocks++;
}
if(badblocks > 1)
printf("%d bad blocks\n", badblocks);
else if (badblocks == 1)
printf("one bad block\n");
}
extern int
mkfs_minix_main(int argc, char ** argv)
{
int i;
char * tmp;
struct stat statbuf;
char * listfile = NULL;
if (argc && *argv)
program_name = *argv;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
die("bad inode size");
#ifdef HAVE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
die("bad inode size");
#endif
opterr = 0;
while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF)
switch (i) {
case 'c':
check=1; break;
case 'i':
req_nr_inodes = (unsigned long) atol(optarg);
break;
case 'l':
listfile = optarg; break;
case 'n':
i = strtoul(optarg,&tmp,0);
if (*tmp)
show_usage();
if (i == 14)
magic = MINIX_SUPER_MAGIC;
else if (i == 30)
magic = MINIX_SUPER_MAGIC2;
else
show_usage();
namelen = i;
dirsize = i+2;
break;
case 'v':
#ifdef HAVE_MINIX2
version2 = 1;
#else
fprintf(stderr,"%s: not compiled with minix v2 support\n",program_name,device_name);
exit(-1);
#endif
break;
default:
show_usage();
}
argc -= optind;
argv += optind;
if (argc > 0 && !device_name) {
device_name = argv[0];
argc--;
argv++;
}
if (argc > 0) {
BLOCKS = strtol(argv[0],&tmp,0);
if (*tmp) {
printf("strtol error: number of blocks not specified");
show_usage();
}
}
if (device_name && !BLOCKS)
BLOCKS = get_size (device_name) / 1024;
if (!device_name || BLOCKS<10) {
show_usage();
}
#ifdef HAVE_MINIX2
if (version2) {
if (namelen == 14)
magic = MINIX2_SUPER_MAGIC;
else
magic = MINIX2_SUPER_MAGIC2;
} else
#endif
if (BLOCKS > 65535)
BLOCKS = 65535;
check_mount(); /* is it already mounted? */
tmp = root_block;
*(short *)tmp = 1;
strcpy(tmp+2,".");
tmp += dirsize;
*(short *)tmp = 1;
strcpy(tmp+2,"..");
tmp += dirsize;
*(short *)tmp = 2;
strcpy(tmp+2,".badblocks");
DEV = open(device_name,O_RDWR );
if (DEV<0)
die("unable to open %s");
if (fstat(DEV,&statbuf)<0)
die("unable to stat %s");
if (!S_ISBLK(statbuf.st_mode))
check=0;
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
die("will not try to make filesystem on '%s'");
setup_tables();
if (check)
check_blocks();
else if (listfile)
get_list_blocks(listfile);
#ifdef HAVE_MINIX2
if (version2) {
make_root_inode2 ();
make_bad_inode2 ();
} else
#endif
{
make_root_inode();
make_bad_inode();
}
mark_good_blocks();
write_tables();
return 0;
}
+29 -9
View File
@@ -1,11 +1,33 @@
/*
* 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"
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
"\tMake special files.\n"
"\n"
"\tb:\tMake a block (buffered) device.\n"
@@ -13,7 +35,7 @@ const char mknod_usage[] = "mknod file b|c|u|p major minor\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);
}
+347 -132
View File
@@ -1,4 +1,3 @@
#include "internal.h"
/*
* mkswap.c - set up a linux swap device
*
@@ -9,51 +8,170 @@
/*
* 20.12.91 - time began. Got VM working yesterday by doing this by hand.
*
* Usage: mkswap [-c] device [size-in-blocks]
* Usage: mkswap [-c] [-vN] [-f] device [size-in-blocks]
*
* -c for readablility checking (use it unless you are SURE!)
* -c for readability checking. (Use it unless you are SURE!)
* -vN for swap areas version N. (Only N=0,1 known today.)
* -f for forcing swap creation even if it would smash partition table.
*
* The device may be a block device or a image of one, but this isn't
* The device may be a block device or an image of one, but this isn't
* enforced (but it's not much fun on a character device :-).
*
* Patches from jaggy@purplet.demon.co.uk (Mike Jagdis) to make the
* size-in-blocks parameter optional added Wed Feb 8 10:33:43 1995.
*
* Version 1 swap area code (for kernel 2.1.117), aeb, 981010.
*
* Sparc fixes, jj@ultra.linux.cz (Jakub Jelinek), 981201 - mangled by aeb.
* V1_MAX_PAGES fixes, jj, 990325.
*
* 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, made some stuff smaller, and fitted for life in busybox.
*
*/
#include "internal.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h> /* for _IO */
#include <sys/utsname.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */
/* we also get PAGE_SIZE via getpagesize() */
#include <asm/page.h>
#include <linux/fs.h>
#ifndef __linux__
# define volatile
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n"
"Prepare a disk partition to be used as a swap partition.\n\n"
"\t-c\tCheck for read-ability.\n"
"\t-v0\tMake version 0 swap [max 128 Megs].\n"
"\t-v1\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n"
"\tblock-count\tNumber of block to use (default is entire partition).\n";
#ifndef _IO
/* pre-1.3.45 */
#define BLKGETSIZE 0x1260
#else
/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */
#define BLKGETSIZE _IO(0x12,96)
#endif
#define TEST_BUFFER_PAGES 8
const char mkswap_usage[] = "mkswap [-c] partition [block-count]\n"
"\n"
"\tPrepare a disk partition to be used as a swap partition.\n"
"\tThe default block count is the size of the entire partition.\n"
"\n"
"\t-c:\tCheck for read-ability.\n"
"\tblock-count\tUse only this many blocks.\n";
static const char * program_name = "mkswap";
static const char * device_name = NULL;
static char * program_name = "mkswap";
static char * device_name = NULL;
static int DEV = -1;
static long PAGES = 0;
static int do_check = 0;
static int check = 0;
static int badpages = 0;
static int version = -1;
#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
static long bit_test_and_set (unsigned int *addr, unsigned int nr)
static int
linux_version_code(void) {
struct utsname my_utsname;
int p, q, r;
if (uname(&my_utsname) == 0) {
p = atoi(strtok(my_utsname.release, "."));
q = atoi(strtok(NULL, "."));
r = atoi(strtok(NULL, "."));
return MAKE_VERSION(p,q,r);
}
return 0;
}
/*
* The definition of the union swap_header uses the constant PAGE_SIZE.
* Unfortunately, on some architectures this depends on the hardware model,
* and can only be found at run time -- we use getpagesize().
*/
static int pagesize;
static int *signature_page;
struct swap_header_v1 {
char bootbits[1024]; /* Space for disklabel etc. */
unsigned int version;
unsigned int last_page;
unsigned int nr_badpages;
unsigned int padding[125];
unsigned int badpages[1];
} *p;
static void
init_signature_page() {
pagesize = getpagesize();
#ifdef PAGE_SIZE
if (pagesize != PAGE_SIZE)
fprintf(stderr, "Assuming pages of size %d\n", pagesize);
#endif
signature_page = (int *) malloc(pagesize);
memset(signature_page,0,pagesize);
p = (struct swap_header_v1 *) signature_page;
}
static void
write_signature(char *sig) {
char *sp = (char *) signature_page;
strncpy(sp+pagesize-10, sig, 10);
}
#define V0_MAX_PAGES (8 * (pagesize - 10))
/* Before 2.2.0pre9 */
#define V1_OLD_MAX_PAGES ((0x7fffffff / pagesize) - 1)
/* Since 2.2.0pre9:
error if nr of pages >= SWP_OFFSET(SWP_ENTRY(0,~0UL))
with variations on
#define SWP_ENTRY(type,offset) (((type) << 1) | ((offset) << 8))
#define SWP_OFFSET(entry) ((entry) >> 8)
on the various architectures. Below the result - yuk.
Machine pagesize SWP_ENTRY SWP_OFFSET bound+1 oldbound+2
i386 2^12 o<<8 e>>8 1<<24 1<<19
mips 2^12 o<<15 e>>15 1<<17 1<<19
alpha 2^13 o<<40 e>>40 1<<24 1<<18
m68k 2^12 o<<12 e>>12 1<<20 1<<19
sparc 2^{12,13} (o&0x3ffff)<<9 (e>>9)&0x3ffff 1<<18 1<<{19,18}
sparc64 2^13 o<<13 e>>13 1<<51 1<<18
ppc 2^12 o<<8 e>>8 1<<24 1<<19
armo 2^{13,14,15} o<<8 e>>8 1<<24 1<<{18,17,16}
armv 2^12 o<<9 e>>9 1<<23 1<<19
assuming that longs have 64 bits on alpha and sparc64 and 32 bits elsewhere.
The bad part is that we need to know this since the kernel will
refuse a swap space if it is too large.
*/
/* patch from jj - why does this differ from the above? */
#if defined(__alpha__)
#define V1_MAX_PAGES ((1 << 24) - 1)
#elif defined(__mips__)
#define V1_MAX_PAGES ((1 << 17) - 1)
#elif defined(__sparc_v9__)
#define V1_MAX_PAGES ((3 << 29) - 1)
#elif defined(__sparc__)
#define V1_MAX_PAGES (pagesize == 8192 ? ((3 << 29) - 1) : ((1 << 18) - 1))
#else
#define V1_MAX_PAGES V1_OLD_MAX_PAGES
#endif
/* man page now says:
The maximum useful size of a swap area now depends on the architecture.
It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,
128GB on alpha and 3TB on sparc64.
*/
#define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
static void bit_set (unsigned int *addr, unsigned int nr)
{
unsigned int r, m;
@@ -61,7 +179,6 @@ static long bit_test_and_set (unsigned int *addr, unsigned int nr)
r = *addr;
m = 1 << (nr & (8 * sizeof(int) - 1));
*addr = r | m;
return (r & m) != 0;
}
static int bit_test_and_clear (unsigned int *addr, unsigned int nr)
@@ -75,47 +192,59 @@ static int bit_test_and_clear (unsigned int *addr, unsigned int nr)
return (r & m) != 0;
}
/*
* Volatile to let gcc know that this doesn't return. When trying
* to compile this under minix, volatile gives a warning, as
* exit() isn't defined as volatile under minix.
*/
volatile void fatal_error(const char * fmt_string)
{
fprintf(stderr,fmt_string,program_name,device_name);
exit(1);
void
die(const char *str) {
fprintf(stderr, "%s: %s\n", program_name, str);
exit( FALSE);
}
#define die(str) fatal_error("%s: " str "\n")
void
page_ok(int page) {
if (version==0)
bit_set(signature_page, page);
}
static void check_blocks(int * signature_page)
{
void
page_bad(int page) {
if (version == 0)
bit_test_and_clear(signature_page, page);
else {
if (badpages == MAX_BADPAGES)
die("too many bad pages");
p->badpages[badpages] = page;
}
badpages++;
}
void
check_blocks(void) {
unsigned int current_page;
int do_seek = 1;
char buffer[PAGE_SIZE];
char *buffer;
buffer = malloc(pagesize);
if (!buffer)
die("Out of memory");
current_page = 0;
while (current_page < PAGES) {
if (!do_check) {
bit_test_and_set(signature_page,current_page++);
if (!check) {
page_ok(current_page++);
continue;
} else {
printf("\r%d", current_page);
}
if (do_seek && lseek(DEV,current_page*PAGE_SIZE,SEEK_SET) !=
current_page*PAGE_SIZE)
if (do_seek && lseek(DEV,current_page*pagesize,SEEK_SET) !=
current_page*pagesize)
die("seek failed in check_blocks");
if ( (do_seek = (PAGE_SIZE != read(DEV, buffer, PAGE_SIZE))) ) {
bit_test_and_clear(signature_page,current_page++);
badpages++;
if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) {
page_bad(current_page++);
continue;
}
bit_test_and_set(signature_page,current_page++);
page_ok(current_page++);
}
if (do_check)
printf("\n");
if (badpages)
printf("%d bad page%s\n",badpages,(badpages>1)?"s":"");
if (badpages == 1)
printf("one bad page\n");
else if (badpages > 1)
printf("%d bad pages\n", badpages);
}
static long valid_offset (int fd, int offset)
@@ -129,12 +258,13 @@ static long valid_offset (int fd, int offset)
return 1;
}
static int count_blocks (int fd)
static int
find_size (int fd)
{
int high, low;
unsigned int high, low;
low = 0;
for (high = 1; valid_offset (fd, high); high *= 2)
for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
low = high;
while (low < high - 1)
{
@@ -145,109 +275,194 @@ static int count_blocks (int fd)
else
high = mid;
}
valid_offset (fd, 0);
return (low + 1);
}
static int get_size(const char *file)
/* return size in pages, to avoid integer overflow */
static long
get_size(const char *file)
{
int fd;
int size;
long size;
fd = open(file, O_RDWR);
fd = open(file, O_RDONLY);
if (fd < 0) {
perror(file);
exit(1);
}
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd);
return (size * 512);
int sectors_per_page = pagesize/512;
size /= sectors_per_page;
} else {
size = find_size(fd) / pagesize;
}
size = count_blocks(fd);
close(fd);
return size;
}
int
mkswap(char *device_name, int pages, int check)
{
struct stat statbuf;
int goodpages;
int signature_page[PAGE_SIZE/sizeof(int)];
PAGES = pages;
do_check = check;
memset(signature_page,0,PAGE_SIZE);
if (device_name && !PAGES) {
PAGES = get_size(device_name) / PAGE_SIZE;
}
if (!device_name || PAGES<10) {
fprintf(stderr,
"%s: error: swap area needs to be at least %ldkB\n",
program_name, 10 * PAGE_SIZE / 1024);
/* usage(mkswap_usage); */
exit(1);
}
if (PAGES > 8 * (PAGE_SIZE - 10)) {
PAGES = 8 * (PAGE_SIZE - 10);
fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n",
program_name, PAGES * PAGE_SIZE / 1024);
}
DEV = open(device_name,O_RDWR);
if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
perror(device_name);
exit(1);
}
if (!S_ISBLK(statbuf.st_mode))
do_check=0;
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
die("Will not try to make swapdevice on '%s'");
check_blocks(signature_page);
if (!bit_test_and_clear(signature_page,0))
die("fatal: first page unreadable");
goodpages = PAGES - badpages - 1;
if (goodpages <= 0)
die("Unable to set up swap-space: unreadable");
printf("Setting up swapspace, size = %ld bytes\n",goodpages*PAGE_SIZE);
strncpy((char*)signature_page+PAGE_SIZE-10,"SWAP-SPACE",10);
if (lseek(DEV, 0, SEEK_SET))
die("unable to rewind swap-device");
if (PAGE_SIZE != write(DEV, signature_page, PAGE_SIZE))
die("unable to write signature page");
close(DEV);
return 0;
}
int mkswap_main(struct FileInfo * unnecessary, int argc, char ** argv)
int mkswap_main(int argc, char ** argv)
{
char * tmp;
long int pages=0;
int check=0;
struct stat statbuf;
int sz;
int maxpages;
int goodpages;
int offset;
int force = 0;
if (argc && *argv)
program_name = *argv;
while (argc > 1) {
init_signature_page(); /* get pagesize */
while (argc-- > 1) {
argv++;
argc--;
if (argv[0][0] != '-')
if (argv[0][0] != '-') {
if (device_name) {
pages = strtol(argv[0],&tmp,0)>>(PAGE_SHIFT-10);
if (*tmp) {
usage(mkswap_usage);
exit(1);
}
int blocks_per_page = pagesize/1024;
PAGES = strtol(argv[0],&tmp,0)/blocks_per_page;
if (*tmp)
usage( mkswap_usage);
} else
device_name = argv[0];
else while (*++argv[0])
switch (argv[0][0]) {
case 'c': check=1; break;
default: usage(mkswap_usage);
exit(1);
} else {
switch (argv[0][1]) {
case 'c':
check=1;
break;
case 'f':
force=1;
break;
case 'v':
version=atoi(argv[0]+2);
break;
default:
usage( mkswap_usage);
}
}
}
return mkswap(device_name, pages, check);
if (!device_name) {
fprintf(stderr,
"%s: error: Nowhere to set up swap on?\n",
program_name);
usage( mkswap_usage);
}
sz = get_size(device_name);
if (!PAGES) {
PAGES = sz;
} else if (PAGES > sz && !force) {
fprintf(stderr,
"%s: error: "
"size %ld is larger than device size %d\n",
program_name,
PAGES*(pagesize/1024), sz*(pagesize/1024));
exit( FALSE);
}
if (version == -1) {
if (PAGES <= V0_MAX_PAGES)
version = 0;
else if (linux_version_code() < MAKE_VERSION(2,1,117))
version = 0;
else if (pagesize < 2048)
version = 0;
else
version = 1;
}
if (version != 0 && version != 1) {
fprintf(stderr, "%s: error: unknown version %d\n",
program_name, version);
usage( mkswap_usage);
}
if (PAGES < 10) {
fprintf(stderr,
"%s: error: swap area needs to be at least %ldkB\n",
program_name, (long)(10 * pagesize / 1024));
usage( mkswap_usage);
}
#if 0
maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES);
#else
if (!version)
maxpages = V0_MAX_PAGES;
else if (linux_version_code() >= MAKE_VERSION(2,2,1))
maxpages = V1_MAX_PAGES;
else {
maxpages = V1_OLD_MAX_PAGES;
if (maxpages > V1_MAX_PAGES)
maxpages = V1_MAX_PAGES;
}
#endif
if (PAGES > maxpages) {
PAGES = maxpages;
fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n",
program_name, PAGES * pagesize / 1024);
}
DEV = open(device_name,O_RDWR);
if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
perror(device_name);
exit( FALSE);
}
if (!S_ISBLK(statbuf.st_mode))
check=0;
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
die("Will not try to make swapdevice on '%s'");
#ifdef __sparc__
if (!force && version == 0) {
/* Don't overwrite partition table unless forced */
unsigned char *buffer = (unsigned char *)signature_page;
unsigned short *q, sum;
if (read(DEV, buffer, 512) != 512)
die("fatal: first page unreadable");
if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
q = (unsigned short *)(buffer + 510);
for (sum = 0; q >= (unsigned short *) buffer;)
sum ^= *q--;
if (!sum) {
fprintf(stderr, "\
%s: Device '%s' contains a valid Sun disklabel.\n\
This probably means creating v0 swap would destroy your partition table\n\
No swap created. If you really want to create swap v0 on that device, use\n\
the -f option to force it.\n",
program_name, device_name);
exit( FALSE);
}
}
}
#endif
if (version == 0 || check)
check_blocks();
if (version == 0 && !bit_test_and_clear(signature_page,0))
die("fatal: first page unreadable");
if (version == 1) {
p->version = version;
p->last_page = PAGES-1;
p->nr_badpages = badpages;
}
goodpages = PAGES - badpages - 1;
if (goodpages <= 0)
die("Unable to set up swap-space: unreadable");
printf("Setting up swapspace version %d, size = %ld bytes\n",
version, (long)(goodpages*pagesize));
write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");
offset = ((version == 0) ? 0 : 1024);
if (lseek(DEV, offset, SEEK_SET) != offset)
die("unable to rewind swap-device");
if (write(DEV,(char*)signature_page+offset, pagesize-offset)
!= pagesize-offset)
die("unable to write signature page");
/*
* A subsequent swapon() will fail if the signature
* is not actually on disk. (This is a kernel bug.)
*/
if (fsync(DEV))
die("fsync failed");
exit ( TRUE);
}
+33 -48
View File
@@ -3,9 +3,11 @@
0.0.1 6K It works.
0.0.2 5K Smaller and you can also check the exit condition if you wish.
0.0.3 Uses select()
19980918 Busy Boxed! Dave Cinege
19990512 Uses Select. Charles P. Wright
19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright
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
@@ -35,26 +37,24 @@
#include <sys/time.h>
#include <sys/ioctl.h>
const char mnc_usage[] =
"mini-netcat 0.0.1 -- Open pipe to IP:port\n"
#define BUFSIZE 100
static const char mnc_usage[] =
"mini-netcat 0.0.3 -- Open pipe to IP:port\n"
"\tmnc [IP] [port]\n";
int
mnc_main(struct FileInfo * i, int argc, char **argv)
mnc_main(int argc, char **argv)
{
int sfd;
int result;
int len;
int pid;
char ch;
char ch[BUFSIZE];
struct sockaddr_in address;
struct hostent *hostinfo;
#ifdef SELECT
fd_set readfds, testfds;
#endif
sfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -78,7 +78,6 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
exit(2);
}
#ifdef SELECT
FD_ZERO(&readfds);
FD_SET(sfd, &readfds);
FD_SET(fileno(stdin), &readfds);
@@ -86,6 +85,7 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
while(1)
{
int fd;
int ofd;
int nread;
testfds = readfds;
@@ -101,48 +101,33 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
{
if(FD_ISSET(fd,&testfds))
{
ioctl(fd, FIONREAD, &nread);
int trn = 0;
int rn;
if (nread == 0)
exit(0);
ioctl(fd, FIONREAD, &nread);
if(fd == sfd)
{
read(sfd, &ch, 1);
write(fileno(stdout), &ch, 1);
}
else
{
read(fileno(stdin), &ch, 1);
write(sfd, &ch, 1);
}
}
}
}
#else
pid = fork();
if (nread == 0)
exit(0);
ofd = fileno(stdout);
}
else
{
ofd = sfd;
}
if (!pid)
{
int retval;
retval = 1;
while(retval == 1)
{
retval = read(fileno(stdin), &ch, 1);
write(sfd, &ch, 1);
}
}
else
{
int retval;
retval = 1;
while(retval == 1)
{
retval = read(sfd, &ch, 1);
write(fileno(stdout), &ch, 1);
}
}
exit(0);
#endif
do
{
rn = (BUFSIZE < nread - trn) ? BUFSIZE : nread - trn;
trn += rn;
read(fd, ch, rn);
write(ofd, ch, rn);
}
while (trn < nread);
}
}
}
}
-126
View File
@@ -1,126 +0,0 @@
#include "internal.h"
#include <stdio.h>
#include <string.h>
#include <grp.h>
extern int
monadic_main(
struct FileInfo * i
,int argc
,char * * argv)
{
int status = 0;
while ( argc > 1 && argv[1][0] == '-' ) {
switch ( argv[1][1] ) {
case 'c':
i->create = 1;
break;
case 'f':
i->force = 1;
break;
case 'g':
if ( argc > 2 ) {
struct group * g;
if ( (g = getgrnam(argv[2])) == 0 ) {
fprintf(stderr, "%s: no such group.\n", argv[1]);
return 1;
}
i->groupID = g->gr_gid;
i->changeGroupID = 1;
i->complainInPostProcess = 1;
argc--;
argv++;
break;
}
usage(i->applet->usage);
return 1;
case 'm':
if ( argc > 2 ) {
status = parse_mode(
argv[2]
,&i->orWithMode
,&i->andWithMode, 0);
if ( status == 0 ) {
i->changeMode = 1;
i->complainInPostProcess = 1;
argc--;
argv++;
break;
}
}
usage(i->applet->usage);
return 1;
case 'o':
if ( argc > 2 ) {
status = parse_user_name(argv[2], i);
if ( status != 0 )
return status;
i->changeUserID = 1;
i->complainInPostProcess = 1;
argc--;
argv++;
break;
}
usage(i->applet->usage);
return 1;
case 'p':
i->makeParentDirectories = 1;
break;
case 'r':
case 'R':
i->recursive = 1;
break;
case 's':
i->makeSymbolicLink = 1;
break;
default:
usage(i->applet->usage);
return 1;
}
argv++;
argc--;
}
while ( argc > 1 ) {
char * slash;
i->source = argv[1];
if ( (slash = strrchr(i->source, '/')) != 0 ) {
i->directoryLength = slash - i->source;
if ( i->source[i->directoryLength] == '\0' )
i->directoryLength = 0;
}
else
i->directoryLength = 0;
if ( !i->dyadic )
i->destination = i->source;
if ( lstat(i->source, &i->stat) == 0 ) {
i->isSymbolicLink = (i->stat.st_mode & S_IFMT)==S_IFLNK;
if ( i->isSymbolicLink )
if ( stat(i->source, &i->stat) != 0 )
memset(&i->stat, 0, sizeof(i->stat));
}
else
memset(&i->stat, 0, sizeof(i->stat));
if ( i->isSymbolicLink
|| !i->recursive
|| ((i->stat.st_mode & S_IFMT) != S_IFDIR) ) {
if ( i->applet->function )
status = i->applet->function(i);
if ( status == 0 )
status = post_process(i);
}
else
status = descend(i, i->applet->function);
if ( status != 0 && !i->force )
return status;
argv++;
argc--;
}
return 0;
}
+134 -82
View File
@@ -1,110 +1,162 @@
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
/*
* Mini more implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Blended by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based on the original more implementation and code from the Debian
* boot-floppies team.
*
* 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
*
*/
/* Turning this off makes things a bit smaller (and less pretty) */
#define BB_MORE_TERM
#include "internal.h"
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
static const char more_usage[] = "[file ...]";
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_MORE_TERM
#include <termios.h>
#include <signal.h>
FILE *cin;
struct termios initial_settings, new_settings;
void gotsig(int sig) {
tcsetattr(fileno(cin), TCSANOW, &initial_settings);
exit(0);
}
#if defined (__sparc__)
# define USE_OLD_TERMIO
# include <termio.h>
# include <sys/ioctl.h>
# define termios termio
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
#else
# include <termios.h>
# define stty(fd,argp) tcsetattr(fd,TCSANOW,argp)
#endif
const char more_usage[] = "more [file]\n"
"\n"
"\tDisplays a file, one page at a time.\n"
"\tIf there are no arguments, the standard input is displayed.\n";
FILE *cin;
struct termios initial_settings, new_settings;
extern int
more_fn(const struct FileInfo * i)
void gotsig(int sig) {
stty(fileno(cin), &initial_settings);
exit( TRUE);
}
#endif
extern int more_main(int argc, char **argv)
{
FILE * f = stdin;
int c;
int lines = 0, tlines = 0;
int next_page = 0;
int rows = 24, cols = 79;
#ifdef BB_MORE_TERM
long sizeb = 0;
struct stat st;
struct winsize win;
#endif
if ( i ) {
if (! (f = fopen(i->source, "r") )) {
name_and_error(i->source);
return 1;
}
fstat(fileno(f), &st);
sizeb = st.st_size / 100;
int c, lines=0, input=0;
int next_page=0;
struct stat st;
FILE *file;
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
usage (more_usage);
}
argc--;
argv++;
while (argc >= 0) {
if (argc==0) {
file = stdin;
}
else
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
}
fstat(fileno(file), &st);
#ifdef BB_MORE_TERM
cin = fopen("/dev/tty", "r");
if (!cin)
cin = fopen("/dev/console", "r");
#ifdef USE_OLD_TERMIO
ioctl(fileno(cin),TCGETA,&initial_settings);
#else
tcgetattr(fileno(cin),&initial_settings);
#endif
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
tcsetattr(fileno(cin), TCSANOW, &new_settings);
stty(fileno(cin), &new_settings);
(void) signal(SIGINT, gotsig);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
if (win.ws_row > 4) rows = win.ws_row - 2;
if (win.ws_col > 0) cols = win.ws_col - 1;
#endif
while ((c = getc(file)) != EOF) {
if ( next_page ) {
int len=0;
next_page = 0;
lines=0;
len = fprintf(stdout, "--More-- ");
if (file != stdin) {
len += fprintf(stdout, "(%d%% of %ld bytes)",
(int) (100*( (double) ftell(file) / (double) st.st_size )),
st.st_size);
}
len += fprintf(stdout, "%s",
#ifdef BB_MORE_TERM
""
#else
"\n"
#endif
);
fflush(stdout);
input = getc( cin);
#ifdef BB_MORE_TERM
/* Erase the "More" message */
while(len-- > 0)
putc('\b', stdout);
while(len++ < 79)
putc(' ', stdout);
while(len-- > 0)
putc('\b', stdout);
fflush(stdout);
#endif
while ( (c = getc(f)) != EOF ) {
if ( next_page ) {
char garbage;
int len;
tlines += lines;
lines = 0;
next_page = 0; //Percentage is based on bytes, not lines.
if ( i && i->source ) //It is not very acurate, but still useful.
len = printf("%s - %%%2ld - line: %d", i->source, (ftell(f) - sizeb - sizeb) / sizeb, tlines);
else
len = printf("line: %d", tlines);
fflush(stdout);
#ifndef BB_MORE_TERM
read(2, &garbage, 1);
#else
do {
fread(&garbage, 1, 1, cin);
} while ((garbage != ' ') && (garbage != '\n'));
if (garbage == '\n') {
lines = rows;
tlines -= rows;
}
garbage = 0;
//clear line, since tabs don't overwrite.
while(len-- > 0) putchar('\b');
while(len++ < cols) putchar(' ');
while(len-- > 0) putchar('\b');
fflush(stdout);
#endif
}
putchar(c);
if ( c == '\n' && ++lines == (rows + 1) )
next_page = 1;
}
if (input=='q')
goto end;
if (input==' ' && c == '\n' )
next_page = 1;
if ( c == '\n' && ++lines == 24 )
next_page = 1;
putc(c, stdout);
}
if ( f != stdin )
fclose(f);
fclose(file);
fflush(stdout);
argc--;
argv++;
}
end:
#ifdef BB_MORE_TERM
gotsig(0);
gotsig(0);
#endif
return 0;
exit(TRUE);
}
+293 -383
View File
@@ -1,9 +1,33 @@
/*
3/21/1999 Charles P. Wright <cpwright@cpwright.com>
searches through fstab when -a is passed
will try mounting stuff with all fses when passed -t auto
1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
* Mini mount 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
*
* 3/21/1999 Charles P. Wright <cpwright@cpwright.com>
* searches through fstab when -a is passed
* will try mounting stuff with all fses when passed -t auto
*
* 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab.
*
* 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>.
* Rewrote of a lot of code. Removed mtab usage (I plan on
* putting it back as a compile-time option some time),
* major adjustments to option parsing, and some serious
* dieting all around.
*/
#include "internal.h"
@@ -15,416 +39,302 @@
#include <mntent.h>
#include <sys/mount.h>
#include <ctype.h>
#include <fstab.h>
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "Usage:\tmount [flags]\n"
"\tmount [flags] device directory [-o options,more-options]\n"
"\n"
"Flags:\n"
"\t-a:\tMount all file systems in fstab.\n"
#ifdef BB_MTAB
"\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
"\t-n:\tDon't write a mount table entry.\n"
#endif
"\t-o option:\tOne of many filesystem options, listed below.\n"
"\t-r:\tMount the filesystem read-only.\n"
"\t-t filesystem-type:\tSpecify the filesystem type.\n"
"\t-w:\tMount for reading and writing (default).\n"
"\n"
"Options for use with the \"-o\" flag:\n"
"\tasync / sync:\tWrites are asynchronous / synchronous.\n"
"\tdev / nodev:\tAllow use of special device files / disallow them.\n"
"\texec / noexec:\tAllow use of executable files / disallow them.\n"
"\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
"\tro / rw: Mount for read-only / read-write.\n"
"\t"
"There are EVEN MORE flags that are specific to each filesystem.\n"
"You'll have to see the written documentation for those.\n";
const char mount_usage[] = "mount\n"
"\t\tmount [flags] special-device directory\n"
"\n"
"Flags:\n"
"\t-a:\tMount all file systems in fstab.\n"
"\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
"\t-n:\tDon't write a mount table entry.\n"
"\t-o option:\tOne of many filesystem options, listed below.\n"
"\t-r:\tMount the filesystem read-only.\n"
"\t-t filesystem-type:\tSpecify the filesystem type.\n"
"\t-w:\tMount for reading and writing (default).\n"
"\n"
"Options for use with the \"-o\" flag:\n"
"\tasync / sync:\tWrites are asynchronous / synchronous.\n"
"\tdev / nodev:\tAllow use of special device files / disallow them.\n"
"\texec / noexec:\tAllow use of executable files / disallow them.\n"
"\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
"\tro / rw: Mount for read-only / read-write.\n"
"\t"
"There are EVEN MORE flags that are specific to each filesystem.\n"
"You'll have to see the written documentation for those.\n";
struct mount_options {
const char * name;
unsigned long and;
unsigned long or;
const char *name;
unsigned long and;
unsigned long or;
};
static const struct mount_options mount_options[] = {
{ "async", ~MS_SYNCHRONOUS,0 },
{ "defaults", ~0, 0 },
{ "dev", ~MS_NODEV, 0 },
{ "exec", ~MS_NOEXEC, 0 },
{ "nodev", ~0, MS_NODEV },
{ "noexec", ~0, MS_NOEXEC },
{ "nosuid", ~0, MS_NOSUID },
{ "remount", ~0, MS_REMOUNT },
{ "ro", ~0, MS_RDONLY },
{ "rw", ~MS_RDONLY, 0 },
{ "suid", ~MS_NOSUID, 0 },
{ "sync", ~0, MS_SYNCHRONOUS },
{ 0, 0, 0 }
static const struct mount_options mount_options[] = {
{"async", ~MS_SYNCHRONOUS, 0},
{"defaults", ~0, 0},
{"dev", ~MS_NODEV, 0},
{"exec", ~MS_NOEXEC, 0},
{"nodev", ~0, MS_NODEV},
{"noexec", ~0, MS_NOEXEC},
{"nosuid", ~0, MS_NOSUID},
{"remount", ~0, MS_REMOUNT},
{"ro", ~0, MS_RDONLY},
{"rw", ~MS_RDONLY, 0},
{"suid", ~MS_NOSUID, 0},
{"sync", ~0, MS_SYNCHRONOUS},
{0, 0, 0}
};
static void
show_flags(unsigned long flags, char * buffer)
#if ! defined BB_MTAB
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
mount(specialfile, dir, filesystemtype, flags, string_flags)
#else
static int
do_mount(char* specialfile, char* dir, char* filesystemtype,
long flags, void* string_flags, int useMtab, int fakeIt)
{
const struct mount_options * f = mount_options;
while ( f->name ) {
if ( flags & f->and ) {
int length = strlen(f->name);
memcpy(buffer, f->name, length);
buffer += length;
*buffer++ = ',';
*buffer = '\0';
}
f++;
}
int status=0;
if (fakeIt==FALSE)
status=mount(specialfile, dir, filesystemtype, flags, string_flags);
if ( status == 0 ) {
if ( useMtab==TRUE )
write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
return 0;
}
else
return( status);
}
#endif
/* Seperate standard mount options from the nonstandard string options */
static void
one_option(
char * option
,unsigned long * flags
,char * data)
parse_mount_options ( char *options, unsigned long *flags, char *strflags)
{
const struct mount_options * f = mount_options;
while (options) {
int gotone=FALSE;
char *comma = strchr (options, ',');
const struct mount_options* f = mount_options;
if (comma)
*comma = '\0';
while ( f->name != 0 ) {
if ( strcasecmp(f->name, option) == 0 ) {
*flags &= f->and;
*flags |= f->or;
return;
}
f++;
}
if ( *data ) {
data += strlen(data);
*data++ = ',';
}
strcpy(data, option);
}
while (f->name != 0) {
if (strcasecmp (f->name, options) == 0) {
static void
parse_mount_options(
char * options
,unsigned long * flags
,char * data)
{
while ( *options ) {
char * comma = strchr(options, ',');
if ( comma )
*comma = '\0';
one_option(options, flags, data);
if ( comma ) {
*comma = ',';
options = ++comma;
}
else
break;
*flags &= f->and;
*flags |= f->or;
gotone=TRUE;
break;
}
f++;
}
if (*strflags && strflags!= '\0' && gotone==FALSE) {
char *temp=strflags;
temp += strlen (strflags);
*temp++ = ',';
*temp++ = '\0';
}
if (gotone==FALSE) {
strcat (strflags, options);
gotone=FALSE;
}
if (comma) {
*comma = ',';
options = ++comma;
} else {
break;
}
}
}
int
mount_one(
char * blockDevice
,char * directory
,char * filesystemType
,unsigned long flags
,char * string_flags
,int noMtab
,int fake)
mount_one(char *blockDevice, char *directory, char *filesystemType,
unsigned long flags, char *string_flags, int useMtab, int fakeIt)
{
int error = 0;
int status = 0;
int status = 0;
char buf[255];
if (!fake) {
if (*filesystemType == 'a') { //Will fail on real FS starting with 'a'
char buf[255];
FILE *f = fopen("/proc/filesystems", "r");
if (strcmp(filesystemType, "auto") == 0) {
FILE *f = fopen ("/proc/filesystems", "r");
if (f == NULL) return 1;
if (f == NULL)
return( FALSE);
while (fgets(buf, sizeof(buf), f) != NULL) {
filesystemType = buf;
if (*filesystemType == '\t') { // Not a nodev filesystem
while (*filesystemType && *filesystemType != '\n') filesystemType++;
*filesystemType = '\0';
filesystemType = buf;
filesystemType++; //hop past tab
status = mount(blockDevice, directory, filesystemType,
flags|MS_MGC_VAL ,string_flags);
error = errno;
while (fgets (buf, sizeof (buf), f) != NULL) {
filesystemType = buf;
if (*filesystemType == '\t') { // Not a nodev filesystem
if (status == 0) break;
}
}
fclose(f);
} else {
// Add NULL termination to each line
while (*filesystemType && *filesystemType != '\n')
filesystemType++;
*filesystemType = '\0';
status = mount( blockDevice, directory, filesystemType,
flags|MS_MGC_VAL ,string_flags);
error = errno;
}
filesystemType = buf;
filesystemType++; // hop past tab
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
if (status == 0)
break;
}
}
fclose (f);
} else {
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
}
if ( status == 0 ) {
char * s = &string_flags[strlen(string_flags)];
FILE * mountTable;
if ( s != string_flags ) {
*s++ = ',';
show_flags(flags, s);
}
if ( !noMtab && (mountTable = setmntent("/etc/mtab", "a+")) ) {
int length = strlen(directory);
struct mntent m;
if ( length > 1 && directory[length - 1] == '/' )
directory[length - 1] = '\0';
if ( filesystemType == 0 ) {
struct mntent * p
= findMountPoint(blockDevice, "/proc/mounts");
if ( p && p->mnt_type )
filesystemType = p->mnt_type;
}
m.mnt_fsname = blockDevice;
m.mnt_dir = directory;
m.mnt_type = filesystemType ? filesystemType : "default";
if (*string_flags) {
m.mnt_opts = string_flags;
} else {
if ( (flags | MS_RDONLY) == flags )
m.mnt_opts = "ro";
else
m.mnt_opts = "rw";
}
m.mnt_freq = 0;
m.mnt_passno = 0;
addmntent(mountTable, &m);
endmntent(mountTable);
}
return 0;
} else {
fprintf(stderr, "Mount %s", blockDevice);
if ( filesystemType && *filesystemType )
fprintf(stderr, " (type %s)", filesystemType);
fprintf(
stderr
," on %s: "
,directory);
switch ( error ) {
case EPERM:
if (geteuid() == 0)
fprintf(
stderr
,"mount point %s is not a directory"
,blockDevice);
else
fprintf(
stderr
,"must be superuser to use mount");
break;
case EBUSY:
fprintf(
stderr
,"%s already mounted or %s busy"
,blockDevice
,directory);
break;
case ENOENT:
{
struct stat statbuf;
if ( stat(directory, &statbuf) != 0 )
fprintf(
stderr
,"directory %s does not exist"
,directory);
else if ( stat(blockDevice, &statbuf) != 0 )
fprintf(
stderr
,"block device %s does not exist"
,blockDevice);
else
fprintf(
stderr
,"%s is not mounted on %s, but the mount table says it is."
,blockDevice
,directory);
break;
}
case ENOTDIR:
fprintf(
stderr
,"%s is not a directory"
,directory);
break;
case EINVAL:
fprintf(
stderr
,"wrong filesystem type, or bad superblock on %s"
,blockDevice);
break;
case EMFILE:
fprintf(stderr, "mount table full");
break;
case EIO:
fprintf(
stderr
,"I/O error reading %s"
,blockDevice);
break;
case ENODEV:
{
FILE * f = fopen("/proc/filesystems", "r");
fprintf(
stderr
,"filesystem type %s not in kernel.\n"
,filesystemType);
fprintf(stderr, "Do you need to load a module?\n");
if ( f ) {
char buf[100];
fprintf(
stderr
,"Here are the filesystem types the kernel"
" can mount:\n");
while ( fgets(buf, sizeof(buf), f) != 0 )
fprintf(stderr, "\t%s", buf);
fclose(f);
}
break;
}
case ENOTBLK:
fprintf(
stderr
,"%s is not a block device"
,blockDevice);
break;
case ENXIO:
fprintf(
stderr
,"%s is not a valid block device"
,blockDevice);
break;
default:
fputs(strerror(errno), stderr);
}
putc('\n', stderr);
return -1;
}
if (status) {
fprintf (stderr, "Mounting %s on %s failed: %s\n",
blockDevice, directory, strerror(errno));
return (FALSE);
}
return (TRUE);
}
extern int
mount_main(struct FileInfo * i, int argc, char * * argv)
extern int mount_main (int argc, char **argv)
{
char string_flags[1024];
unsigned long flags = 0;
char * filesystemType = "auto";
int fake = 0;
int noMtab = 0;
int all = 0;
*string_flags = '\0';
char string_flags[1024]="";
unsigned long flags = 0;
char *filesystemType = "auto";
char *device = NULL;
char *directory = NULL;
struct stat statBuf;
int all = FALSE;
int fakeIt = FALSE;
int useMtab = TRUE;
int i;
if ( argc == 1 ) {
FILE * mountTable;
if ( (mountTable = setmntent("/etc/mtab", "r")) ) {
struct mntent * m;
while ( (m = getmntent(mountTable)) != 0 ) {
printf(
"%s on %s type %s (%s)\n"
,m->mnt_fsname
,m->mnt_dir
,m->mnt_type
,m->mnt_opts);
}
endmntent(mountTable);
if (stat("/etc/fstab", &statBuf) < 0)
fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
if (argc == 1) {
FILE *mountTable = setmntent (mtab_file, "r");
if (mountTable) {
struct mntent *m;
while ((m = getmntent (mountTable)) != 0) {
struct fstab* fstabItem;
char *blockDevice = m->mnt_fsname;
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (blockDevice, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
blockDevice = fstabItem->fs_spec;
}
return 0;
}
while ( argc >= 2 && argv[1][0] == '-' ) {
switch ( argv[1][1] ) {
case 'f':
fake = 1;
break;
case 'n':
noMtab = 1;
break;
case 'o':
if ( argc < 3 ) {
usage(mount_usage);
return 1;
}
parse_mount_options(argv[2], &flags, string_flags);
argc--;
argv++;
break;
case 'r':
flags |= MS_RDONLY;
break;
case 't':
if ( argc < 3 ) {
usage(mount_usage);
return 1;
}
filesystemType = argv[2];
argc--;
argv++;
break;
case 'v':
break;
case 'w':
flags &= ~MS_RDONLY;
break;
case 'a':
all = 1;
break;
default:
usage(mount_usage);
return 1;
}
argc--;
argv++;
}
if (all == 1) {
struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r");
if (f == NULL) {
return 1;
}
// FIXME: Combine read routine (make new function) with unmount_all to save space.
while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto, and isn't mounted on /, mount it
if ((!strstr(m->mnt_opts, "noauto")) && (m->mnt_dir[1] != '\0')
&& !((m->mnt_type[0] == 's') && (m->mnt_type[1] == 'w'))
&& !((m->mnt_type[0] == 'n') && (m->mnt_type[1] == 'f'))) {
mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, flags, m->mnt_opts, noMtab, fake);
}
}
endmntent(f);
printf ("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts);
}
endmntent (mountTable);
} else {
if ( argc >= 3 ) {
if ( mount_one( argv[1], argv[2], filesystemType, flags, string_flags, noMtab, fake) == 0 )
return 0;
else
return 1;
} else {
usage(mount_usage);
return 1;
}
perror(mtab_file);
}
return 0;
exit( TRUE);
}
/* Parse options */
i = --argc;
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
case 'o':
if (--i == 0) {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
}
parse_mount_options (*(++argv), &flags, string_flags);
--i;
++argv;
break;
case 'r':
flags |= MS_RDONLY;
break;
case 't':
if (--i == 0) {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
}
filesystemType = *(++argv);
--i;
++argv;
break;
case 'w':
flags &= ~MS_RDONLY;
break;
case 'a':
all = TRUE;
break;
#ifdef BB_MTAB
case 'f':
fakeIt = TRUE;
break;
case 'n':
useMtab = FALSE;
break;
#endif
case 'v':
case 'h':
case '-':
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
break;
}
} else {
if (device == NULL)
device=*argv;
else if (directory == NULL)
directory=*argv;
else {
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
}
}
i--;
argv++;
}
if (all == TRUE) {
struct mntent *m;
FILE *f = setmntent ("/etc/fstab", "r");
if (f == NULL) {
perror("/etc/fstab");
exit( FALSE);
}
while ((m = getmntent (f)) != NULL) {
// If the file system isn't noauto, and isn't mounted on /,
// and isn't swap or nfs, then mount it
if ((!strstr (m->mnt_opts, "noauto")) &&
(m->mnt_dir[1] != '\0') &&
(!strstr (m->mnt_type, "swap")) &&
(!strstr (m->mnt_type, "nfs")))
{
flags = 0;
*string_flags = '\0';
parse_mount_options(m->mnt_opts, &flags, string_flags);
mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type,
flags, string_flags, useMtab, fakeIt);
}
}
endmntent (f);
} else {
if (device && directory) {
exit (mount_one (device, directory, filesystemType,
flags, string_flags, useMtab, fakeIt));
} else {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
}
}
exit( TRUE);
}
+9 -10
View File
@@ -3,7 +3,7 @@
#include <sys/mtio.h>
#include <sys/fcntl.h>
const char mt_usage[] = "mt [-f device] opcode value\n";
static const char mt_usage[] = "mt [-f device] opcode value\n";
struct mt_opcodes {
char * name;
@@ -50,7 +50,7 @@ static const struct mt_opcodes opcodes[] = {
};
extern int
mt_main(struct FileInfo * i, int argc, char * * argv)
mt_main(int argc, char** argv)
{
const char * file = "/dev/tape";
const struct mt_opcodes * code = opcodes;
@@ -59,8 +59,7 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
if ( strcmp(argv[1], "-f") == 0 ) {
if ( argc < 4 ) {
usage(mt_usage);
return 1;
usage (mt_usage);
}
file = argv[2];
argv += 2;
@@ -75,7 +74,7 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
if ( code->name == 0 ) {
fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]);
return 1;
return( FALSE);
}
op.mt_op = code->value;
@@ -85,14 +84,14 @@ mt_main(struct FileInfo * i, int argc, char * * argv)
op.mt_count = 1; /* One, not zero, right? */
if ( (fd = open(file, O_RDONLY, 0)) < 0 ) {
name_and_error(file);
return 1;
perror(file);
return( FALSE);
}
if ( ioctl(fd, MTIOCTOP, &op) != 0 ) {
name_and_error(file);
return 1;
perror(file);
return( FALSE);
}
return 0;
return( TRUE);
}
+70 -28
View File
@@ -1,38 +1,80 @@
/*
* 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"
"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));
}
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);
}
Loaded 100 of 137 files, more files were not shown because too many files have changed in this diff. Show more