Compare commits

...
25 Commits
Author SHA1 Message Date
Eric Andersen ded6259f62 Latest and greatest 1999-11-18 00:19:26 +00:00
Eric Andersen d80e851dc0 Stuf 1999-11-16 00:46:00 +00:00
Eric Andersen a9c95ea655 Updates 1999-11-15 17:33:30 +00:00
Eric Andersen 80974fad03 Fix makefile 1999-11-13 04:51:47 +00:00
Eric Andersen b6a44b8d39 updates for the day 1999-11-13 04:47:09 +00:00
Eric Andersen eded54bd96 Adjust install a bit... 1999-11-12 08:03:23 +00:00
Eric Andersen 96bcfd346b Latest and greatest
-Erik
1999-11-12 01:30:18 +00:00
Eric Andersen 0dfac6b9ce Stuff 1999-11-11 05:46:32 +00:00
Eric Andersen c296b54827 Stuf 1999-11-11 01:36:55 +00:00
Eric Andersen d73dc5b073 Updates to usage, and made tar work.
-Erik
1999-11-10 23:13:02 +00:00
Eric Andersen 84d8568071 spelling fixes 1999-11-10 20:17:47 +00:00
Eric Andersen 5556c1874b Maybe works now...
-Erik
1999-11-10 19:27:58 +00:00
Eric Andersen 3e2bb288da Stuf 1999-11-09 03:12:29 +00:00
Eric Andersen add0158554 LAtest and greatest 1999-11-09 03:10:26 +00:00
Eric Andersen 3d8dbe1ca0 Stuf 1999-11-09 01:51:02 +00:00
Eric Andersen 50d6360771 Stuff 1999-11-09 01:47:36 +00:00
Eric Andersen fbb39c83b6 Stuff
-Erik
1999-11-08 17:00:52 +00:00
Eric Andersen 07e5297ca7 init and ls -l fixes 1999-11-07 07:38:08 +00:00
Eric Andersen dc6301e7ca Stuf 1999-11-06 07:34:50 +00:00
Eric Andersen 350577c5a0 Minor stuf 1999-11-06 06:34:20 +00:00
Eric Andersen 29d2e362de Fixed ln, df, and removed redundant stuff from mtab. 1999-11-06 06:07:27 +00:00
Eric Andersen bc34190694 Forgot this file... 1999-11-06 04:56:00 +00:00
Eric Andersen f14937d177 Update 1999-11-06 03:02:42 +00:00
Eric Andersen e18c75a563 Fixed init so it won't hang on reboot... 1999-11-05 04:23:05 +00:00
Eric Andersen 9997685953 Changelog fix 1999-11-05 01:21:49 +00:00
82 changed files with 2027 additions and 3293 deletions

No files matched your search

+92 -4
View File
@@ -1,5 +1,89 @@
0.36
* fixed dd so it properly defaults to stdin and stdout when no
if= and of= are set (fix thanks to Eric Delaunay).
* Don't try to close the file descriptor of a pipein tar. (fix also from
Eric Delaunay).
* Made createPath be quiet (again thanks to Eric Delaunay).
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
command you define it as will be run if the init script exits.
* Updated install.sh to make it more robust (thanks to Adam Di Carlo)
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled
in, but that is still a big win for those that use NFS.
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay).
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise
and acts as god intended gunzip and zcat to act. They answer --help and
obey the '-c' flag.
* Fixed a bug in mv which caused it to not move files when the destination
was a directory.
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories
with very wrong permissions.
* chmod would overwrite file permissions instead of modifying them.
Now it properly modifies permissions.
* Init now sends warnings destined for the console to /dev/console to ensure
they show up on whatever the active console it. Otherwise important
messages (for example that the system is rebooting) were not seen when
switched to a different VT.
-Erik Andersen, Nov 17, 1999
0.35
* gzip now obeys the principle of least surprise and acts like god intended
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag
and only then outputs to stdout).
* Fixed more.c to compile autowidth on sparc and set initial winsize
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay.
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
* tar now accepts --help
* chmod, chown, and chgrp usage now works
* General usage (i.e. --help) cleanups for most apps
* umount now parses options correctly
* tar can now unpack tarballs containing device special files,
sockets, and fifos (though it can't pack them up) thanks
to Matt Porter. Creating archives containing these is still
left to the interested student.
* fixed up the license in more.c to properly point to Bruce Perens.
-Erik Andersen, Nov 11, 1999
0.34
* ls -l now displays link names outside the current directory,
Patch thanks to Eric Delaunay
* init now properly handles sparc serial consoles and does a
better job of finding the real console device rather than using
/dev/console which doesn't support job control. Patch also
thanks to Eric Delaunay.
* more started to read from stdin after the last file was finished, and
options were not parsed correctly (fix thanks to Eric Delaunay).
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
* rm wouldn't remove a symlink unless the symlink was valid. This was
a side effect of the busybox 0.32 recursiveAction() fix. Things
should now work correctly.
* grep wouldn't grep stdin. Now it does.
* sed wouldn't sed stdin. Now it does.
* sed was appending a \n to the end of lines with replacements.
Now it doesn't do that.
* ls -l now bypasses libc6 nss when displaying user/group names.
Now uses my_getpwuid and my_getgrgid.
-Erik Andersen, Nov 8, 1999
0.33
* Fixed a bug where init could hang instead of rebooting.
* Removed some debugging noise from init.c
* Fixed ln so it works now (it was very broken).
* Fixed df so it won't segfault when there is no /etc/fstab,
* If BB_MTAB is not defined, df and mount will whine if /etc/fstab
is not installed (since they cannot fixup "/dev/root" to
state the real root device name)
* merged some redundant code from mtab.c/df.c into utility.c
-Erik Andersen, Nov 5, 1999
0.32
* usage() now printf the BusyBox version. This will help folks
* More changes -- many thanks to Lineo for paying me to work on
busybox. If you have any problems please let me know ASAP
at andersen@lineo.com or andersee@debian.org
* usage() now prints the BusyBox version. This will help folks
realize that they are not in Kansas anymore.
* Fixed mkdir -m option so that it works.
* kill segfaulted w/o any arguments. Now it doesn't do that.
@@ -22,7 +106,7 @@
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>.
-Erik Andersen
-Erik Andersen, Nov 4, 1999
0.31
* I added a changelog for version 0.30.
@@ -37,7 +121,7 @@
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
-Erik Andersen, Oct 21, 1999
0.30
Major changes -- lots of stuff rewritten. Many thanks to Lineo for
@@ -106,7 +190,11 @@
* sfdisk -- Added from util-linux (minus internationalization and such).
* Probably some other changes that I forgot to document...
-Erik Andersen
-Erik Andersen, Oct 20, 1999
0.29
This version was a messy pre-alpha. stay away or it will bite you.
-Erik Andersen, Sep 24, 1999
0.28
mini-netcat (mnc) rewritten.
+353 -6
View File
@@ -17,15 +17,362 @@ Copyright 1998 Dave Cinege <dcinege@psychosis.com>
mini-gzip(gzip), mini-netcat(mnc)
Copyright 1998 Charles P. Wright <cpwright@villagenet.com>
bunches of stuff as noted in header files
Tons of new stuff as noted in header files
Copyright (C) 1999 by Lineo, inc. and written by
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
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>.
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
Busybox may be used and distributed under the GNU General Public License.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
+44 -11
View File
@@ -17,7 +17,7 @@
PROG=busybox
VERSION=0.32
VERSION=0.36
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
# Comment out the following to make a debuggable build
@@ -31,14 +31,38 @@ DOSTATIC=false
#This will choke on a non-debian system
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
GCCMAJVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\1/p"`
GCCMINVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\2/p"`
GCCSUPPORTSOPTSIZE=$(shell \
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
if ( test $(GCCMINVERSION) -ge 95 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
else \
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
fi; )
ifeq ($(GCCSUPPORTSOPTSIZE), true)
OPTIMIZATION=-Os
else
OPTIMIZATION=-O2
endif
# -D_GNU_SOURCE is needed because environ is used in init.c
ifeq ($(DODEBUG),true)
CFLAGS=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
STRIP=
LDFLAGS=
else
CFLAGS=-Wall -Os -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS= -s
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
#Only staticly link when _not_ debugging
@@ -48,27 +72,27 @@ else
endif
ifndef $(prefix)
prefix=`pwd`
ifndef $(PREFIX)
PREFIX=`pwd`/busybox_install
endif
BINDIR=$(prefix)
LIBRARIES=
OBJECTS=$(shell ./busybox.sh)
CFLAGS+= -DBB_VER='"$(VERSION)"'
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
all: busybox links
all: busybox busybox.links
busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
$(STRIP)
links:
- ./busybox.mkll | sort >busybox.links
busybox.links:
- ./busybox.mkll | sort >$@
clean:
- rm -f $(PROG) busybox.links *~ *.o core
- rm -rf busybox_install
distclean: clean
- rm -f $(PROG)
@@ -77,6 +101,15 @@ force:
$(OBJECTS): busybox.def.h internal.h Makefile
install: $(PROG)
install.sh $(BINDIR)
install: busybox
./install.sh $(PREFIX)
whichversion:
@echo $(VERSION)
dist: release
release: distclean
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
+20 -20
View File
@@ -1,26 +1,26 @@
Please see the LICENSE file for copyright information.
Busybox is a multicall binary used to provide a minimal subset of
POSIX style commands and specialized functions.
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a working system.
Busybox was begun to support the Debian Rescue/Install disks, but it
also makes an excellent environment for any small or embedded system.
It is geared toward 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 now modularized to easily allow you to build of only the
BB parts you need, thereby reducing binary size. To turn off unwanted
Busybox components, simply edit the file busybox.def.h and comment out
the parts you do not need using C++ style (//) comments.
As of version 0.20 there is a version number. : )
Also as of version 0.20, BB is modularized to allow an easy build of
only the BB parts you need, to reduce binary size.
After the build is complete a busybox.links file is generated which is
then used by 'make install' to create symlinks to the busybox binary
for all compiled in functions. By default, 'make install' will place
the symlink forest into `pwd`/busybox_install unless you have defined
the PREFIX environment variable.
Edit the file busybox.def.h and comment out the parts you do not need
using C++ comments (//)
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
After the build is complete a busybox.links file is generated to allow
you to easily make the sym/hard links to the busybox binary.
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:
Erik Andersen <andersee@deban.org>
+7 -7
View File
@@ -174,9 +174,9 @@ static const struct Applet applets[] = {
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_ZCAT //bin
{"zcat", zcat_main},
{"gunzip", zcat_main},
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
@@ -220,12 +220,12 @@ int busybox_main(int argc, char **argv)
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
set -e
if [ "$1" == "" ]; then
echo "No installation directory, aborting."
exit 1;
fi
# can't just use cat, rmdir is not unique
#h=`cat busybox.links`
h=`sort busybox.links | uniq`
mkdir -p $1/bin
for i in $h ; do
[ ${verbose} ] && echo " making link to $i"
mkdir -p $1/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
ln -s busybox $1/bin/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `
done
rm -f $1/bin/busybox
install -m 755 busybox $1/bin/busybox
+113 -38
View File
@@ -7,11 +7,17 @@
#include "internal.h"
#ifdef BB_GZIP
#ifndef BB_ZCAT
#error you need zcat to have gzip support!
#endif
//#ifndef BB_ZCAT
//#error you need zcat to have gzip support!
//#endif
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"When FILE is -, reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
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.
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
extern int verbose; /* be verbose (-v) */
extern int quiet; /* be quiet (-q) */
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
#define WARN(msg) {if (!quiet) fprintf msg ; \
if (exit_code == OK) exit_code = WARNING;}
local void do_exit(int exitcode);
local void do_exit(int exitcode) __attribute__ ((noreturn));
/* in zip.c: */
extern int zip OF((int in, int out));
@@ -380,7 +385,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# undef LZW
#endif
/* $Id: gzip.c,v 1.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 +395,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -1728,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
/* local variables */
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
int decompress = 0; /* decompress (-d) */
int no_name = -1; /* don't save or restore the original file name */
int no_time = -1; /* don't save or restore the original file time */
@@ -1760,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
/* local functions */
local void treat_stdin OF((void));
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
// int main (argc, argv)
// int argc;
// char **argv;
int gzip_main(int argc, char * * argv)
int gzip_main(int argc, char ** argv)
{
int result;
int inFileNum;
int outFileNum;
struct stat statBuf;
char* delFileName;
int tostdout = 0;
int fromstdin = 0;
if (argc==1)
usage(gzip_usage);
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromstdin = 1;
tostdout = 1;
}
while (*(++(*argv))) {
switch (**argv) {
case 'c':
tostdout = 1;
break;
default:
usage(gzip_usage);
}
}
}
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
(void) signal (SIGINT, (sig_type)abort_gzip);
@@ -1789,8 +1816,6 @@ int gzip_main(int argc, char * * argv)
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
z_len = strlen(z_suffix);
to_stdout = 1;
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
@@ -1803,33 +1828,84 @@ int gzip_main(int argc, char * * argv)
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
/* And get to work */
treat_stdin();
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
if (fromstdin==1) {
strcpy(ofname, "stdin");
/* ========================================================================
* Compress or decompress stdin
*/
local void treat_stdin()
{
inFileNum=fileno(stdin);
time_stamp = 0; /* time unknown by default */
ifile_size = -1L; /* convention for unknown size */
} else {
/* Open up the input file */
if (*argv=='\0')
usage(gzip_usage);
strncpy(ifname, *argv, MAX_PATH_LEN);
/* Open input fille */
inFileNum=open( ifname, O_RDONLY);
if (inFileNum < 0) {
perror(ifname);
do_exit(WARNING);
}
/* Get the time stamp on the input file. */
result = stat(ifname, &statBuf);
if (result < 0) {
perror(ifname);
do_exit(WARNING);
}
time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size;
}
if (tostdout==1) {
/* And get to work */
strcpy(ofname, "stdout");
outFileNum=fileno(stdout);
SET_BINARY_MODE(fileno(stdout));
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
/* Get the time stamp on the input file. */
time_stamp = 0; /* time unknown by default */
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
ifile_size = -1L; /* convention for unknown size */
/* Actually do the compression/decompression. */
zip(inFileNum, outFileNum);
clear_bufs(); /* clear input and output buffers */
to_stdout = 1;
part_nb = 0;
} else {
/* Actually do the compression/decompression. Loop over zipped members.
*/
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
/* And get to work */
strncpy(ofname, ifname, MAX_PATH_LEN-4);
strcat(ofname, ".gz");
/* Open output fille */
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
if (outFileNum < 0) {
perror(ofname);
do_exit(WARNING);
}
SET_BINARY_MODE(outFileNum);
/* Set permissions on the file */
fchmod(outFileNum, statBuf.st_mode);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
result=zip(inFileNum, outFileNum);
close( outFileNum);
close( inFileNum);
/* Delete the original file */
if (result == OK)
delFileName=ifname;
else
delFileName=ofname;
if (unlink (delFileName) < 0) {
perror (delFileName);
exit( FALSE);
}
}
do_exit(exit_code);
}
/* ========================================================================
@@ -2943,8 +3019,6 @@ local void set_file_type()
extern int errno;
#endif
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
* Copy input to output unchanged: zcat == cat with --force.
* IN assertion: insize bytes have already been read in inbuf.
@@ -3152,6 +3226,7 @@ int zip(in, out)
/* Write the header to the gzip file. See algorithm.doc for the format */
method = DEFLATED;
put_byte(GZIP_MAGIC[0]); /* magic header */
put_byte(GZIP_MAGIC[1]);
+67 -40
View File
@@ -10,6 +10,9 @@
* Modified for busybox by Erik Andersen <andersee@debian.org>
* Adjusted to grok stdin/stdout options.
*
* Modified to handle device special files by Matt Porter
* <porter@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
@@ -34,13 +37,15 @@
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
static const char tar_usage[] =
"tar -[cxtvOf] [tarFileName] [FILE] ...\n"
"Create, extract, or list files from a tar file\n\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
"Create, extract, or list files from a tar file\n\n"
"Options:\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
@@ -92,7 +97,7 @@ static int createFlag;
static int verboseFlag;
static int tostdoutFlag;
static int inHeader;
static int inHeader; // <- check me
static int badHeader;
static int errorFlag;
static int skipFileFlag;
@@ -169,10 +174,9 @@ extern int tar_main (int argc, char **argv)
/*
* Parse the options.
*/
options = *argv++;
argc--;
if (**argv == '-') {
options = (*argv++) + 1;
argc--;
for (; *options; options++) {
switch (*options) {
case 'f':
@@ -208,10 +212,13 @@ extern int tar_main (int argc, char **argv)
break;
case '-':
usage( tar_usage);
break;
default:
fprintf (stderr, "Unknown tar flag '%c'\n", *options);
fprintf (stderr, "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n",
*options);
exit (FALSE);
}
@@ -221,7 +228,7 @@ extern int tar_main (int argc, char **argv)
/*
* Validate the options.
*/
if (extractFlag + listFlag + createFlag != 1) {
if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n");
@@ -232,13 +239,13 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process.
*/
if (createFlag)
if (createFlag==TRUE)
writeTarFile (argc, argv);
else
readTarFile (argc, argv);
if (errorFlag)
if (errorFlag==TRUE)
fprintf (stderr, "\n");
exit (errorFlag);
exit (!errorFlag);
}
@@ -283,7 +290,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Read blocks from the file until an end of file header block
* has been seen. (A real end of file from a read is an error.)
*/
while (!eofFlag) {
while (eofFlag==FALSE) {
/*
* Read the next block of data if necessary.
* This will be a large block if possible, which we will
@@ -310,7 +317,7 @@ static void readTarFile (int fileCount, char **fileTable)
/*
* If we are expecting a header block then examine it.
*/
if (inHeader) {
if (inHeader==TRUE) {
readHeader ((const TarHeader *) cp, fileCount, fileTable);
cp += TAR_BLOCK_SIZE;
@@ -374,12 +381,15 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
int uid;
int gid;
int checkSum;
int major;
int minor;
long size;
time_t mtime;
const char *name;
int cc;
int hardLink;
int softLink;
int devFileFlag;
/*
* If the block is completely empty, then this is the end of the
@@ -408,9 +418,11 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
size = getOctal (hp->size, sizeof (hp->size));
mtime = getOctal (hp->mtime, sizeof (hp->mtime));
checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
major = getOctal (hp->devMajor, sizeof (hp->devMajor));
minor = getOctal (hp->devMinor, sizeof (hp->devMinor));
if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
if (!badHeader)
if (badHeader==FALSE)
fprintf (stderr, "Bad tar header, skipping\n");
badHeader = TRUE;
@@ -420,6 +432,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
badHeader = FALSE;
skipFileFlag = FALSE;
devFileFlag = FALSE;
/*
* Check for the file modes.
@@ -431,12 +444,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
(hp->typeFlag == TAR_TYPE_SOFT_LINK - '0'));
/*
* Check for a directory or a regular file.
* Check for a directory.
*/
if (name[strlen (name) - 1] == '/')
mode |= S_IFDIR;
else if ((mode & S_IFMT) == 0)
mode |= S_IFREG;
/*
* Check for absolute paths in the file.
@@ -446,7 +457,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
while (*name == '/')
name++;
if (!warnedRoot) {
if (warnedRoot==FALSE) {
fprintf (stderr,
"Absolute path detected, removing leading slashes\n");
}
@@ -458,9 +469,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* See if we want this file to be restored.
* If not, then set up to skip it.
*/
if (!wantFileName (name, fileCount, fileTable)) {
if (!hardLink && !softLink && S_ISREG (mode)) {
inHeader = (size == 0);
if (wantFileName (name, fileCount, fileTable) == FALSE) {
if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
|| S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
}
@@ -473,8 +485,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* This file is to be handled.
* If we aren't extracting then just list information about the file.
*/
if (!extractFlag) {
if (verboseFlag) {
if (extractFlag==FALSE) {
if (verboseFlag==TRUE) {
printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
uid, gid, size, timeString (mtime), name);
} else
@@ -484,8 +496,9 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
printf (" (link to \"%s\")", hp->linkName);
else if (softLink)
printf (" (symlink to \"%s\")", hp->linkName);
else if (S_ISREG (mode)) {
inHeader = (size == 0);
else if (S_ISREG (mode) || S_ISCHR (mode) || S_ISBLK (mode) ||
S_ISSOCK(mode) || S_ISFIFO(mode) ) {
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
}
@@ -497,7 +510,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/*
* We really want to extract the file.
*/
if (verboseFlag)
if (verboseFlag==TRUE)
printf ("x %s\n", name);
if (hardLink) {
@@ -532,7 +545,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/
createPath (name, 0777);
inHeader = (size == 0);
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
/*
@@ -540,8 +553,18 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/
if (tostdoutFlag == TRUE)
outFd = STDOUT;
else
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
else {
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
devFileFlag = TRUE;
outFd = mknod (name, mode, makedev(major, minor) );
}
else if (S_ISFIFO(mode) ) {
devFileFlag = TRUE;
outFd = mkfifo(name, mode);
} else {
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
}
if (outFd < 0) {
perror (name);
@@ -552,7 +575,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/*
* If the file is empty, then that's all we need to do.
*/
if (size == 0 && tostdoutFlag == FALSE) {
if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
(void) close (outFd);
outFd = -1;
}
@@ -578,7 +601,7 @@ static void readData (const char *cp, int count)
* If we aren't extracting files or this file is being
* skipped then do nothing more.
*/
if (!extractFlag || skipFileFlag)
if (extractFlag==FALSE || skipFileFlag==TRUE)
return;
/*
@@ -653,7 +676,7 @@ static void writeTarFile (int fileCount, char **fileTable)
* Append each file name into the archive file.
* Follow symbolic links for these top level file names.
*/
while (!errorFlag && (fileCount-- > 0)) {
while (errorFlag==FALSE && (fileCount-- > 0)) {
saveFile (*fileTable++, FALSE);
}
@@ -685,7 +708,7 @@ static void saveFile (const char *fileName, int seeLinks)
int mode;
struct stat statbuf;
if (verboseFlag)
if (verboseFlag==TRUE)
printf ("a %s\n", fileName);
/*
@@ -701,7 +724,7 @@ static void saveFile (const char *fileName, int seeLinks)
* Find out about the file.
*/
#ifdef S_ISLNK
if (seeLinks)
if (seeLinks==TRUE)
status = lstat (fileName, &statbuf);
else
#endif
@@ -732,12 +755,16 @@ static void saveFile (const char *fileName, int seeLinks)
return;
}
if (S_ISREG (mode)) {
saveRegularFile (fileName, &statbuf);
return;
}
/* Some day add support for tarring these up... but not today. :) */
// if (S_ISLNK(mode) || S_ISFIFO(mode) || S_ISBLK(mode) || S_ISCHR (mode) ) {
// fprintf (stderr, "%s: This version of tar can't store this type of file\n", fileName);
// }
/*
* The file is a strange type of file, ignore it.
@@ -801,7 +828,7 @@ saveRegularFile (const char *fileName, const struct stat *statbuf)
*/
cc = 0;
if (!sawEof) {
if (sawEof==FALSE) {
cc = fullRead (fileFd, data, dataCount);
if (cc < 0) {
@@ -890,7 +917,7 @@ static void saveDirectory (const char *dirName, const struct stat *statbuf)
* Read all of the directory entries and check them,
* except for the current and parent directory entries.
*/
while (!errorFlag && ((entry = readdir (dir)) != NULL)) {
while (errorFlag==FALSE && ((entry = readdir (dir)) != NULL)) {
if ((strcmp (entry->d_name, ".") == 0) ||
(strcmp (entry->d_name, "..") == 0)) {
continue;
@@ -989,7 +1016,7 @@ static void writeTarBlock (const char *buf, int len)
/*
* If we had a write error before, then do nothing more.
*/
if (errorFlag)
if (errorFlag==TRUE)
return;
/*
+7 -7
View File
@@ -174,9 +174,9 @@ static const struct Applet applets[] = {
#ifdef BB_UPDATE //sbin
{"update", update_main},
#endif
#ifdef BB_ZCAT //bin
{"zcat", zcat_main},
{"gunzip", zcat_main},
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
@@ -220,12 +220,12 @@ int busybox_main(int argc, char **argv)
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
+4 -3
View File
@@ -37,6 +37,7 @@
//#define BB_MNC
#define BB_MORE
#define BB_MOUNT
#define BB_NFSMOUNT
//#define BB_MT
//#define BB_MTAB
#define BB_MV
@@ -54,12 +55,12 @@
#define BB_SYNC
#define BB_TAR
#define BB_TOUCH
//#define BB_TRUE_FALSE // Supplied by ash
#define BB_TRUE_FALSE
#define BB_UMOUNT
#define BB_UPDATE
#define BB_UNAME
#define BB_ZCAT
//#define BB_GZIP
#define BB_GZIP
#define BB_GUNZIP
// Don't turn BB_UTILITY off. It contains support code
// that compiles to 0 if everything else if turned off.
#define BB_UTILITY
+4 -12
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.32
Version: 0.36
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,7 +7,7 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.32.tar.gz
Source: %{Name}-%{Version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,22 +18,14 @@ is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
%setup -q -n busybox
%setup -q -n %{Name}-%{Version}
%Build
make
%Install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/bin
h=`cat busybox.links`
for i in $h ; do
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/busybox
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
make PREFIX=$RPM_BUILD_ROOT install
%Clean
rm -rf $RPM_BUILD_ROOT
+20 -20
View File
@@ -31,23 +31,23 @@ static uid_t uid=-1;
static gid_t gid=-1;
static int whichApp;
static char* invocationName=NULL;
static mode_t mode=0644;
static char* theMode=NULL;
#define CHGRP_APP 1
#define CHOWN_APP 2
#define CHMOD_APP 3
static const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n"
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\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"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
static const char chmod_usage[] = "[-R] MODE[,MODE]... FILE...\n"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
"one or more of the letters rwxst.\n\n"
"\t-R\tchange files and directories recursively.\n";
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
static int fileAction(const char *fileName, struct stat* statbuf)
@@ -61,7 +61,12 @@ static int fileAction(const char *fileName, struct stat* statbuf)
}
break;
case CHMOD_APP:
if (chmod(fileName, mode) == 0)
/* Parse the specified modes */
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
exit( FALSE);
}
if (chmod(fileName, statbuf->st_mode) == 0)
return( TRUE);
break;
}
@@ -73,14 +78,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
{
int recursiveFlag=FALSE;
char *groupName;
const char *appUsage;
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv,
(whichApp==TRUE)? chown_usage : chgrp_usage);
exit( FALSE);
}
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
if (argc < 2)
usage( appUsage);
invocationName=*argv;
argc--;
argv++;
@@ -93,19 +98,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
exit( FALSE);
usage( appUsage);
}
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);
}
theMode=*argv;
} else {
/* Find the selected group */
+1 -1
View File
@@ -27,7 +27,7 @@
#include <errno.h>
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
+1 -1
View File
@@ -19,7 +19,7 @@ chvt_main(int argc, char** argv)
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt </dev/ttyN>\n");
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
+1 -1
View File
@@ -19,7 +19,7 @@ chvt_main(int argc, char** argv)
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt </dev/ttyN>\n");
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
+4 -2
View File
@@ -17,8 +17,10 @@ int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
if (argc < 1) /* unlikely */
exit(1);
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
progname = argv[0];
fd = get_console_fd("/dev/console");
+1 -1
View File
@@ -27,7 +27,7 @@
#include <errno.h>
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
+3 -1
View File
@@ -28,7 +28,7 @@
#include <dirent.h>
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
@@ -54,6 +54,8 @@ static int fileAction(const char *fileName, struct stat* statbuf)
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
+1 -1
View File
@@ -35,7 +35,7 @@
mail commands */
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
+2 -5
View File
@@ -34,7 +34,7 @@
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n"
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
"\tof=FILE\twrite to FILE instead of stout\n"
@@ -152,8 +152,6 @@ extern int dd_main (int argc, char **argv)
argc--;
argv++;
}
if ( inFile == NULL || outFile == NULL)
goto usage;
buf = malloc (blockSize);
if (buf == NULL) {
@@ -227,8 +225,7 @@ extern int dd_main (int argc, char **argv)
exit( TRUE);
usage:
fprintf (stderr, "%s", dd_usage);
exit( FALSE);
usage( dd_usage);
}
+17 -51
View File
@@ -38,19 +38,23 @@ static int df(char *device, const char *mountPoint)
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct fstab* fstabItem;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return 1;
return FALSE;
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
if (strcmp(device, "/dev/root") == 0)
device = (getfsfile("/"))->fs_spec;
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (device, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
device = fstabItem->fs_spec;
}
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
@@ -60,55 +64,17 @@ static int df(char *device, const char *mountPoint)
}
return 0;
return TRUE;
}
/*
* 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;
}
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
if (argc > 1) {
struct mntent *mountEntry;
int status;
@@ -117,15 +83,15 @@ extern int df_main(int argc, char **argv)
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
0) {
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
return 1;
exit( FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
return status;
exit( status);
argc--;
argv++;
}
return 0;
exit( TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
@@ -139,10 +105,10 @@ extern int df_main(int argc, char **argv)
while ((mountEntry = getmntent(mountTable))) {
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status)
return status;
exit( status);
}
endmntent(mountTable);
}
return 0;
exit( TRUE);
}
+14 -19
View File
@@ -27,23 +27,21 @@
#include <errno.h>
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";
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{
int status;
char newdestName[NAME_MAX];
static char* linkName;
if (argc < 3) {
usage (ln_usage);
@@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
}
destName = argv[argc - 1];
linkName = argv[argc - 1];
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
perror(linkName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
status = symlink(*argv, linkName);
else
status = link(*argv, newdestName);
status = link(*argv, linkName);
if ( status != 0 ) {
perror(newdestName);
perror(linkName);
exit( FALSE);
}
}
+18 -53
View File
@@ -40,7 +40,7 @@
* 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 (bypasses libc6 NSS) */
#define FEATURE_TIMESTAMPS /* show file timestamps */
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
#define FEATURE_FILETYPECHAR /* enable -p and -F */
@@ -64,10 +64,6 @@
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#ifdef FEATURE_USERNAME
#include <pwd.h>
#include <grp.h>
#endif
#ifdef FEATURE_TIMESTAMPS
#include <time.h>
#endif
@@ -83,27 +79,6 @@
#define MINOR(dev) ((dev)&0xff)
#endif
#define MODE1 "rwxrwxrwx"
#define MODE0 "---------"
#define SMODE1 "..s..s..t"
#define SMODE0 "..S..S..T"
/* The 9 mode bits to test */
static const mode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const mode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
};
#define FMT_AUTO 0
#define FMT_LONG 1 /* one record per line, extended info */
#define FMT_SINGLE 2 /* one record per line */
@@ -206,7 +181,7 @@ static char append_char(mode_t mode)
**
**/
static void list_single(const char *name, struct stat *info)
static void list_single(const char *name, struct stat *info, const char *fullname)
{
char scratch[PATH_MAX];
short len = strlen(name);
@@ -216,45 +191,35 @@ static void list_single(const char *name, struct stat *info)
if (display_fmt == FMT_LONG) {
mode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
for (i=0; i<9; i++)
if (mode & SBIT[i])
scratch[i+1] = (mode & MBIT[i])
? SMODE1[i]
: SMODE0[i];
else
scratch[i+1] = (mode & MBIT[i])
? MODE1[i]
: MODE0[i];
newline();
wr(scratch, 10);
wr(modeString(mode), 10);
column=10;
writenum((long)info->st_nlink,(short)4);
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
#ifdef FEATURE_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct passwd *pw = getpwuid(info->st_uid);
if (pw)
fputs(pw->pw_name, stdout);
scratch[8]='\0';
my_getpwuid( scratch, info->st_uid);
if (*scratch)
fputs(scratch, stdout);
else
writenum((long)info->st_uid,(short)0);
} else
#endif
writenum((long)info->st_uid,(short)0);
tab(24);
tab(16);
#ifdef FEATURE_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct group *gr = getgrgid(info->st_gid);
if (gr)
fputs(gr->gr_name, stdout);
scratch[8]='\0';
my_getgrgid( scratch, info->st_gid);
if (*scratch)
fputs(scratch, stdout);
else
writenum((long)info->st_gid,(short)0);
} else
#endif
writenum((long)info->st_gid,(short)0);
tab(33);
tab(17);
if (S_ISBLK(mode) || S_ISCHR(mode)) {
writenum((long)MAJOR(info->st_rdev),(short)3);
fputs(", ", stdout);
@@ -297,12 +262,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len);
if (S_ISLNK(mode)) {
wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(name, info)) {
if (!stat(fullname, info)) {
append = append_char(info->st_mode);
if (append)
fputc(append, stdout);
@@ -372,7 +337,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) {
list_single(name, &info);
list_single(name, &info, name);
return 0;
}
@@ -424,7 +389,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name);
if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info);
list_single(entry->d_name, &info, fullname);
}
closedir(dir);
return 0;
+5 -4
View File
@@ -26,14 +26,15 @@
#include <errno.h>
#include <sys/param.h>
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\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";
"Options:\n"
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-p\tno error if existing, make parent directories as needed\n";
static int parentFlag = FALSE;
static mode_t mode = 777;
static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
+3 -3
View File
@@ -27,9 +27,9 @@
#include <fcntl.h>
#include <unistd.h>
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
"\tMake special files.\n"
"\n"
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
"Make block or character special files.\n\n"
"Options:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
+7 -2
View File
@@ -29,7 +29,7 @@
static const char mv_usage[] = "mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
@@ -56,7 +56,7 @@ extern int mv_main(int argc, char **argv)
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
@@ -67,6 +67,11 @@ extern int mv_main(int argc, char **argv)
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(srcName, skipName));
else
strcat(newdestName, srcName);
fprintf(stderr, "srcName='%s'\n", srcName);
fprintf(stderr, "skipName='%s'\n", skipName);
fprintf(stderr, "newdestName='%s'\n", newdestName);
}
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
exit( FALSE);
+12 -4
View File
@@ -26,9 +26,11 @@
#include <time.h>
#include <utime.h>
#include <dirent.h>
#include <errno.h>
static const char* rm_usage = "rm [OPTION]... FILE...\n"
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\tremove existing destinations, never prompt\n"
"\t-r\tremove the contents of directories recursively\n";
@@ -58,6 +60,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
extern int rm_main(int argc, char **argv)
{
struct stat statbuf;
if (argc < 2) {
usage( rm_usage);
@@ -84,9 +87,14 @@ extern int rm_main(int argc, char **argv)
while (argc-- > 0) {
srcName = *(argv++);
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
fileAction, dirAction) == FALSE) {
exit( FALSE);
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
}
else {
if (recursiveAction( srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction) == FALSE) {
exit( FALSE);
}
}
}
exit( TRUE);
+1 -1
View File
@@ -29,7 +29,7 @@
extern int rmdir_main(int argc, char **argv)
{
if ( argc==1 || **(argv+1) == '-' ) {
usage( "rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
}
while (--argc > 0) {
+2 -2
View File
@@ -23,8 +23,8 @@
#include "internal.h"
#include <stdio.h>
const char sleep_usage[] = " NUMBER\n"
"Pause for NUMBER seconds.\n";
const char sleep_usage[] = "sleep N\n\n"
"Pause for N seconds.\n";
extern int
sleep_main(int argc, char * * argv)
+1 -1
View File
@@ -27,7 +27,7 @@ extern int
sync_main(int argc, char * * argv)
{
if ( argc>1 && **(argv+1) == '-' ) {
usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
}
exit( sync());
}
+2 -2
View File
@@ -31,7 +31,7 @@
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
"\tUpdate the last-modified date on the given file[s].\n";
"Update the last-modified date on the given file[s].\n";
@@ -54,7 +54,7 @@ touch_main(int argc, char **argv)
create = FALSE;
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
usage( touch_usage);
exit( FALSE);
}
argc--;
+3 -2
View File
@@ -41,8 +41,9 @@
static const char uname_usage[] =
"uname [OPTION]...\n"
"Print certain system information. With no OPTION, same as -s.\n"
"uname [OPTION]...\n\n"
"Print certain system information. With no OPTION, same as -s.\n\n"
"Options:\n"
"\t-a\tprint all information\n"
"\t-m\tthe machine (hardware) type\n"
"\t-n\tprint the machine's network node hostname\n"
+3 -1
View File
@@ -28,7 +28,7 @@
#include <dirent.h>
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
@@ -54,6 +54,8 @@ static int fileAction(const char *fileName, struct stat* statbuf)
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
+1 -1
View File
@@ -35,7 +35,7 @@
mail commands */
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
+2 -5
View File
@@ -34,7 +34,7 @@
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n"
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
"\tof=FILE\twrite to FILE instead of stout\n"
@@ -152,8 +152,6 @@ extern int dd_main (int argc, char **argv)
argc--;
argv++;
}
if ( inFile == NULL || outFile == NULL)
goto usage;
buf = malloc (blockSize);
if (buf == NULL) {
@@ -227,8 +225,7 @@ extern int dd_main (int argc, char **argv)
exit( TRUE);
usage:
fprintf (stderr, "%s", dd_usage);
exit( FALSE);
usage( dd_usage);
}
+4 -2
View File
@@ -17,8 +17,10 @@ int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
if (argc < 1) /* unlikely */
exit(1);
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
progname = argv[0];
fd = get_console_fd("/dev/console");
+17 -51
View File
@@ -38,19 +38,23 @@ static int df(char *device, const char *mountPoint)
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct fstab* fstabItem;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return 1;
return FALSE;
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
if (strcmp(device, "/dev/root") == 0)
device = (getfsfile("/"))->fs_spec;
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (device, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
device = fstabItem->fs_spec;
}
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
@@ -60,55 +64,17 @@ static int df(char *device, const char *mountPoint)
}
return 0;
return TRUE;
}
/*
* 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;
}
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
if (argc > 1) {
struct mntent *mountEntry;
int status;
@@ -117,15 +83,15 @@ extern int df_main(int argc, char **argv)
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
0) {
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
return 1;
exit( FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
return status;
exit( status);
argc--;
argv++;
}
return 0;
exit( TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
@@ -139,10 +105,10 @@ extern int df_main(int argc, char **argv)
while ((mountEntry = getmntent(mountTable))) {
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status)
return status;
exit( status);
}
endmntent(mountTable);
}
return 0;
exit( TRUE);
}
+1 -1
View File
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
"\tdutmp /var/run/utmp\n";
static int dutmp_main (int argc, char **argv)
extern int dutmp_main (int argc, char **argv)
{
FILE *f = stdin;
+44 -42
View File
@@ -32,22 +32,36 @@
#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"
"sed [-n] [-e script] [file...]\n\n"
"Allowed sed scripts come in the following form:\n"
"\t's/regexp/replacement/[gp]'\n"
"which attempt to match regexp against the pattern space\n"
"and if successful replaces the matched portion with replacement.\n\n"
"Options:\n"
"-e\tadd the script to the commands to be executed\n"
"-n\tsuppress automatic printing of pattern space\n\n"
#if defined BB_REGEXP
"This version of sed matches full regexps.\n";
"This version of sed matches full regular expresions.\n";
#else
"This version of sed matches strings (not full regexps).\n";
"This version of sed matches strings (not full regular expresions).\n";
#endif
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
{
int foundOne=FALSE;
char haystack[1024];
while (fgets (haystack, 1023, fp)) {
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
if (foundOne==TRUE && printFlag==TRUE) {
fprintf(stdout, haystack);
}
if (quietFlag==FALSE) {
fprintf(stdout, haystack);
}
}
}
extern int sed_main (int argc, char **argv)
{
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
char *name;
char *cp;
int ignoreCase=FALSE;
int foundOne=FALSE;
int printFlag=FALSE;
int quietFlag=FALSE;
int stopNow;
char *haystack;
argc--;
argv++;
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
cp = *argv++;
stopNow=FALSE;
while (*++cp && 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++;
if ( *++cp != 's')
cp = *argv++;
while( *cp ) {
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
char* pos=needle=cp+2;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "B\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "C\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
*pos=0;
if (pos+2 != 0) {
while (*++pos) {
fprintf(stderr, "pos='%s'\n", pos);
switch (*pos) {
case 'i':
ignoreCase=TRUE;
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
}
cp++;
}
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
//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++;
if (argc==0) {
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
} else {
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
if (ferror (fp))
perror (name);
fclose (fp);
}
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);
}
+4 -12
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.32
Version: 0.36
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -7,7 +7,7 @@ Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
Buildroot: /tmp/%{Name}-%{Version}
Source: busybox-0.32.tar.gz
Source: %{Name}-%{Version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,22 +18,14 @@ is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
%setup -q -n busybox
%setup -q -n %{Name}-%{Version}
%Build
make
%Install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/bin
h=`cat busybox.links`
for i in $h ; do
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
done
rm -f $RPM_BUILD_ROOT/bin/busybox
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
make PREFIX=$RPM_BUILD_ROOT install
%Clean
rm -rf $RPM_BUILD_ROOT
+12 -3
View File
@@ -32,9 +32,18 @@ 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 const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\n\t\tDereference symbolic links.\n"
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
#if defined BB_REGEXP
"This version of find matches full regular expresions.\n";
#else
"This version of find matches strings (not regular expresions).\n";
#endif
+12 -3
View File
@@ -32,9 +32,18 @@ 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 const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\n\t\tDereference symbolic links.\n"
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
#if defined BB_REGEXP
"This version of find matches full regular expresions.\n";
#else
"This version of find matches strings (not regular expresions).\n";
#endif
+50 -39
View File
@@ -32,29 +32,55 @@
#include <ctype.h>
static const char grep_usage[] =
"grep [-ihn]... PATTERN [FILE]...\n"
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
"\t-n\tprint line number with output lines\n\n"
#if defined BB_REGEXP
"This version of grep matches full regexps.\n";
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not full regexps).\n";
"This version of grep matches strings (not regular expresions).\n";
#endif
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
{
char *cp;
long line = 0;
char haystack[BUF_SIZE];
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", fileName);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s:", fileName);
if (tellLine==TRUE)
printf ("%ld:", line);
fputs (haystack, stdout);
}
}
}
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *needle;
char *name;
char *cp;
int tellName=TRUE;
char *needle;
char *fileName;
int tellName=FALSE;
int ignoreCase=FALSE;
int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
ignoreCase = FALSE;
tellLine = FALSE;
@@ -76,7 +102,7 @@ extern int grep_main (int argc, char **argv)
break;
case 'h':
tellName = FALSE;
tellName = TRUE;
break;
case 'n':
@@ -91,39 +117,24 @@ extern int grep_main (int argc, char **argv)
needle = *argv++;
argc--;
while (argc-- > 0) {
name = *argv++;
if (argc==0) {
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
} else {
while (argc-- > 0) {
fileName = *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);
fp = fopen (fileName, "r");
if (fp == NULL) {
perror (fileName);
continue;
}
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
if (ferror (fp))
perror (fileName);
fclose (fp);
}
if (ferror (fp))
perror (name);
fclose (fp);
}
exit( TRUE);
}
+11 -3
View File
@@ -191,9 +191,17 @@ static void leave(int status)
}
static void show_usage(void) {
fprintf(stderr,
"Usage: %s [-larvsmf] /dev/name\n",
program_name);
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name);
fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-l\tLists all filenames\n");
fprintf(stderr, "\t-r\tPerform interactive repairs\n");
fprintf(stderr, "\t-a\tPerform automatic repairs\n");
fprintf(stderr, "\t-v\tverbose\n");
fprintf(stderr, "\t-s\tOutputs super-block information\n");
fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n");
fprintf(stderr, "\t-f\tForce file system check.\n\n");
leave(16);
}
+50 -39
View File
@@ -32,29 +32,55 @@
#include <ctype.h>
static const char grep_usage[] =
"grep [-ihn]... PATTERN [FILE]...\n"
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
"\t-n\tprint line number with output lines\n\n"
#if defined BB_REGEXP
"This version of grep matches full regexps.\n";
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not full regexps).\n";
"This version of grep matches strings (not regular expresions).\n";
#endif
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
{
char *cp;
long line = 0;
char haystack[BUF_SIZE];
while (fgets (haystack, sizeof (haystack), fp)) {
line++;
cp = &haystack[strlen (haystack) - 1];
if (*cp != '\n')
fprintf (stderr, "%s: Line too long\n", fileName);
if (find_match(haystack, needle, ignoreCase) == TRUE) {
if (tellName==TRUE)
printf ("%s:", fileName);
if (tellLine==TRUE)
printf ("%ld:", line);
fputs (haystack, stdout);
}
}
}
extern int grep_main (int argc, char **argv)
{
FILE *fp;
char *needle;
char *name;
char *cp;
int tellName=TRUE;
char *needle;
char *fileName;
int tellName=FALSE;
int ignoreCase=FALSE;
int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
ignoreCase = FALSE;
tellLine = FALSE;
@@ -76,7 +102,7 @@ extern int grep_main (int argc, char **argv)
break;
case 'h':
tellName = FALSE;
tellName = TRUE;
break;
case 'n':
@@ -91,39 +117,24 @@ extern int grep_main (int argc, char **argv)
needle = *argv++;
argc--;
while (argc-- > 0) {
name = *argv++;
if (argc==0) {
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
} else {
while (argc-- > 0) {
fileName = *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);
fp = fopen (fileName, "r");
if (fp == NULL) {
perror (fileName);
continue;
}
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
if (ferror (fp))
perror (fileName);
fclose (fp);
}
if (ferror (fp))
perror (name);
fclose (fp);
}
exit( TRUE);
}
+113 -38
View File
@@ -7,11 +7,17 @@
#include "internal.h"
#ifdef BB_GZIP
#ifndef BB_ZCAT
#error you need zcat to have gzip support!
#endif
//#ifndef BB_ZCAT
//#error you need zcat to have gzip support!
//#endif
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"When FILE is -, reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
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.
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
extern int verbose; /* be verbose (-v) */
extern int quiet; /* be quiet (-q) */
extern int test; /* check .z file integrity */
extern int to_stdout; /* output to stdout (-c) */
extern int save_orig_name; /* set if original name must be saved */
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
#define WARN(msg) {if (!quiet) fprintf msg ; \
if (exit_code == OK) exit_code = WARNING;}
local void do_exit(int exitcode);
local void do_exit(int exitcode) __attribute__ ((noreturn));
/* in zip.c: */
extern int zip OF((int in, int out));
@@ -380,7 +385,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
# undef LZW
#endif
/* $Id: gzip.c,v 1.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 +395,6 @@ extern int block_mode; /* block compress mode -C compatible with 2.0 */
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: gzip.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
@@ -1728,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
/* local variables */
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
int decompress = 0; /* decompress (-d) */
int no_name = -1; /* don't save or restore the original file name */
int no_time = -1; /* don't save or restore the original file time */
@@ -1760,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
/* local functions */
local void treat_stdin OF((void));
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
// int main (argc, argv)
// int argc;
// char **argv;
int gzip_main(int argc, char * * argv)
int gzip_main(int argc, char ** argv)
{
int result;
int inFileNum;
int outFileNum;
struct stat statBuf;
char* delFileName;
int tostdout = 0;
int fromstdin = 0;
if (argc==1)
usage(gzip_usage);
/* Parse any options */
while (--argc > 0 && **(++argv) == '-') {
if (*((*argv)+1) == '\0') {
fromstdin = 1;
tostdout = 1;
}
while (*(++(*argv))) {
switch (**argv) {
case 'c':
tostdout = 1;
break;
default:
usage(gzip_usage);
}
}
}
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
(void) signal (SIGINT, (sig_type)abort_gzip);
@@ -1789,8 +1816,6 @@ int gzip_main(int argc, char * * argv)
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
z_len = strlen(z_suffix);
to_stdout = 1;
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
@@ -1803,33 +1828,84 @@ int gzip_main(int argc, char * * argv)
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
/* And get to work */
treat_stdin();
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
if (fromstdin==1) {
strcpy(ofname, "stdin");
/* ========================================================================
* Compress or decompress stdin
*/
local void treat_stdin()
{
inFileNum=fileno(stdin);
time_stamp = 0; /* time unknown by default */
ifile_size = -1L; /* convention for unknown size */
} else {
/* Open up the input file */
if (*argv=='\0')
usage(gzip_usage);
strncpy(ifname, *argv, MAX_PATH_LEN);
/* Open input fille */
inFileNum=open( ifname, O_RDONLY);
if (inFileNum < 0) {
perror(ifname);
do_exit(WARNING);
}
/* Get the time stamp on the input file. */
result = stat(ifname, &statBuf);
if (result < 0) {
perror(ifname);
do_exit(WARNING);
}
time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size;
}
if (tostdout==1) {
/* And get to work */
strcpy(ofname, "stdout");
outFileNum=fileno(stdout);
SET_BINARY_MODE(fileno(stdout));
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
/* Get the time stamp on the input file. */
time_stamp = 0; /* time unknown by default */
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
ifile_size = -1L; /* convention for unknown size */
/* Actually do the compression/decompression. */
zip(inFileNum, outFileNum);
clear_bufs(); /* clear input and output buffers */
to_stdout = 1;
part_nb = 0;
} else {
/* Actually do the compression/decompression. Loop over zipped members.
*/
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
/* And get to work */
strncpy(ofname, ifname, MAX_PATH_LEN-4);
strcat(ofname, ".gz");
/* Open output fille */
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
if (outFileNum < 0) {
perror(ofname);
do_exit(WARNING);
}
SET_BINARY_MODE(outFileNum);
/* Set permissions on the file */
fchmod(outFileNum, statBuf.st_mode);
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
/* Actually do the compression/decompression. */
result=zip(inFileNum, outFileNum);
close( outFileNum);
close( inFileNum);
/* Delete the original file */
if (result == OK)
delFileName=ifname;
else
delFileName=ofname;
if (unlink (delFileName) < 0) {
perror (delFileName);
exit( FALSE);
}
}
do_exit(exit_code);
}
/* ========================================================================
@@ -2943,8 +3019,6 @@ local void set_file_type()
extern int errno;
#endif
extern ulg crc_32_tab[]; /* crc table, defined below */
/* ===========================================================================
* Copy input to output unchanged: zcat == cat with --force.
* IN assertion: insize bytes have already been read in inbuf.
@@ -3152,6 +3226,7 @@ int zip(in, out)
/* Write the header to the gzip file. See algorithm.doc for the format */
method = DEFLATED;
put_byte(GZIP_MAGIC[0]); /* magic header */
put_byte(GZIP_MAGIC[1]);
+81 -40
View File
@@ -41,7 +41,7 @@
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
#define VT_CONSOLE "/dev/console" /* Logical system console */
#define DEV_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 */
@@ -53,10 +53,10 @@
#define LOG 0x1
#define CONSOLE 0x2
static char *console = VT_CONSOLE;
static char *console = DEV_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
/* try to open up the specified device */
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
/* 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) {
if (log_fd < 0) {
if (log == NULL) {
/* don't even try to log, because there is no such console */
log_fd = -2;
/* log to main console instead */
device = CONSOLE;
}
else 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);
@@ -97,13 +103,14 @@ void message(int device, char *fmt, ...)
}
}
if ( (device & LOG) && (log_fd != -1) ) {
if ( (device & LOG) && (log_fd >= 0) ) {
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) {
/* Always send console messages to /dev/console so people will see them. */
if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
va_start(arguments, fmt);
vdprintf(fd, fmt, arguments);
va_end(arguments);
@@ -180,32 +187,47 @@ static void console_init()
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
struct serial_struct sr;
char *s;
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;
}
}
}
#if #cpu(sparc)
/* sparc kernel supports console=tty[ab] parameter which is also
* passed to init, so catch it here */
else if ((s = getenv("console")) != NULL) {
/* remap tty[ab] to /dev/ttyS[01] */
if (strcmp( s, "ttya" )==0)
console = SERIAL_CON0;
else if (strcmp( s, "ttyb" )==0)
console = SERIAL_CON1;
}
#endif
} else {
console = VT_CONSOLE;
tried_devcons++;
else {
struct vt_stat vt;
static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
} else {
console = DEV_CONSOLE;
tried_devcons++;
}
}
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;
console = DEV_CONSOLE;
continue;
}
/* Can't open selected console -- try vt1 */
@@ -219,8 +241,15 @@ static void console_init()
if (fd < 0)
/* Perhaps we should panic here? */
console = "/dev/null";
else
else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
log = NULL;
second_console = NULL;
}
close(fd);
}
message(LOG, "console=%s\n", console );
}
@@ -350,9 +379,9 @@ static void shutdown_system(void)
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) {
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
message(CONSOLE, "Flushing buffers.\r\n");
bdflush(1, 0);
sync();
}
@@ -389,10 +418,14 @@ extern int init_main(int argc, char **argv)
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;
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
const char* const* tty0_command = shell_command;
const char* const* tty1_command = shell_command;
#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
const char* const rc_exit_command[] = BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS;
#endif
#ifdef DEBUG_INIT
char *hello_msg_format =
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
@@ -402,6 +435,13 @@ extern int init_main(int argc, char **argv)
#endif
#ifndef DEBUG_INIT
if (getpid() != 1) {
usage( "init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\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"))) {
@@ -445,9 +485,10 @@ extern int init_main(int argc, char **argv)
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0)
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
message(CONSOLE|LOG, "Mounting /proc: done.\n");
else
kernel_version = get_kernel_revision();
} else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
@@ -457,7 +498,7 @@ extern int init_main(int argc, char **argv)
/* 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;
tty0_command = rc_script_command;
}
@@ -468,11 +509,11 @@ extern int init_main(int argc, char **argv)
pid_t wpid;
int status;
if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter);
if (pid1 == 0 && tty0_command) {
pid1 = run(tty0_command, console, wait_for_enter);
}
if (pid2 == 0 && tty1_commands) {
pid2 = run(tty1_commands, second_console, TRUE);
if (pid2 == 0 && tty1_command && second_console) {
pid2 = run(tty1_command, second_console, TRUE);
}
wpid = wait(&status);
if (wpid > 0 ) {
@@ -482,13 +523,13 @@ extern int init_main(int argc, char **argv)
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.... */
}
#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
else {
pid1 = 0;
run_rc=FALSE;
wait_for_enter=TRUE;
tty0_commands=shell_commands;
tty0_command=rc_exit_command;
}
#endif
}
+81 -40
View File
@@ -41,7 +41,7 @@
#include <sys/vt.h> /* for vt_stat */
#include <sys/ioctl.h>
#define VT_CONSOLE "/dev/console" /* Logical system console */
#define DEV_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 */
@@ -53,10 +53,10 @@
#define LOG 0x1
#define CONSOLE 0x2
static char *console = VT_CONSOLE;
static char *console = DEV_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
/* try to open up the specified device */
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
/* 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) {
if (log_fd < 0) {
if (log == NULL) {
/* don't even try to log, because there is no such console */
log_fd = -2;
/* log to main console instead */
device = CONSOLE;
}
else 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);
@@ -97,13 +103,14 @@ void message(int device, char *fmt, ...)
}
}
if ( (device & LOG) && (log_fd != -1) ) {
if ( (device & LOG) && (log_fd >= 0) ) {
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) {
/* Always send console messages to /dev/console so people will see them. */
if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
va_start(arguments, fmt);
vdprintf(fd, fmt, arguments);
va_end(arguments);
@@ -180,32 +187,47 @@ static void console_init()
int fd;
int tried_devcons = 0;
int tried_vtprimary = 0;
struct serial_struct sr;
char *s;
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;
}
}
}
#if #cpu(sparc)
/* sparc kernel supports console=tty[ab] parameter which is also
* passed to init, so catch it here */
else if ((s = getenv("console")) != NULL) {
/* remap tty[ab] to /dev/ttyS[01] */
if (strcmp( s, "ttya" )==0)
console = SERIAL_CON0;
else if (strcmp( s, "ttyb" )==0)
console = SERIAL_CON1;
}
#endif
} else {
console = VT_CONSOLE;
tried_devcons++;
else {
struct vt_stat vt;
static char the_console[13];
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
/* this is linux virtual tty */
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
} else {
console = DEV_CONSOLE;
tried_devcons++;
}
}
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;
console = DEV_CONSOLE;
continue;
}
/* Can't open selected console -- try vt1 */
@@ -219,8 +241,15 @@ static void console_init()
if (fd < 0)
/* Perhaps we should panic here? */
console = "/dev/null";
else
else {
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
log = NULL;
second_console = NULL;
}
close(fd);
}
message(LOG, "console=%s\n", console );
}
@@ -350,9 +379,9 @@ static void shutdown_system(void)
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) {
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
message(CONSOLE, "Flushing buffers.\r\n");
bdflush(1, 0);
sync();
}
@@ -389,10 +418,14 @@ extern int init_main(int argc, char **argv)
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;
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
const char* const* tty0_command = shell_command;
const char* const* tty1_command = shell_command;
#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
const char* const rc_exit_command[] = BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS;
#endif
#ifdef DEBUG_INIT
char *hello_msg_format =
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
@@ -402,6 +435,13 @@ extern int init_main(int argc, char **argv)
#endif
#ifndef DEBUG_INIT
if (getpid() != 1) {
usage( "init\n\nInit is the parent of all processes.\n\n"
"This version of init is designed to be run only by the kernel\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"))) {
@@ -445,9 +485,10 @@ extern int init_main(int argc, char **argv)
/* Mount /proc */
if (mount ("proc", "/proc", "proc", 0, 0) == 0)
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
message(CONSOLE|LOG, "Mounting /proc: done.\n");
else
kernel_version = get_kernel_revision();
} else
message(CONSOLE|LOG, "Mounting /proc: failed!\n");
/* Make sure there is enough memory to do something useful. */
@@ -457,7 +498,7 @@ extern int init_main(int argc, char **argv)
/* 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;
tty0_command = rc_script_command;
}
@@ -468,11 +509,11 @@ extern int init_main(int argc, char **argv)
pid_t wpid;
int status;
if (pid1 == 0 && tty0_commands) {
pid1 = run(tty0_commands, console, wait_for_enter);
if (pid1 == 0 && tty0_command) {
pid1 = run(tty0_command, console, wait_for_enter);
}
if (pid2 == 0 && tty1_commands) {
pid2 = run(tty1_commands, second_console, TRUE);
if (pid2 == 0 && tty1_command && second_console) {
pid2 = run(tty1_command, second_console, TRUE);
}
wpid = wait(&status);
if (wpid > 0 ) {
@@ -482,13 +523,13 @@ extern int init_main(int argc, char **argv)
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.... */
}
#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
else {
pid1 = 0;
run_rc=FALSE;
wait_for_enter=TRUE;
tty0_commands=shell_commands;
tty0_command=rc_exit_command;
}
#endif
}
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
set -e
if [ "$1" == "" ]; then
echo "No installation directory, aborting."
exit 1;
fi
# can't just use cat, rmdir is not unique
#h=`cat busybox.links`
h=`sort busybox.links | uniq`
mkdir -p $1/bin
for i in $h ; do
[ ${verbose} ] && echo " making link to $i"
mkdir -p $1/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
ln -s busybox $1/bin/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `
done
rm -f $1/bin/busybox
install -m 755 busybox $1/bin/busybox
+15 -3
View File
@@ -29,6 +29,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <mntent.h>
/* Some useful definitions */
@@ -113,7 +114,7 @@ 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 gunzip_main (int argc, char** argv);
extern int gzip_main(int argc, char** argv);
@@ -137,7 +138,7 @@ const char* timeString(time_t timeVal);
extern void createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern volatile void usage(const char *usage);
extern void usage(const char *usage) __attribute__ ((noreturn));
extern uid_t my_getpwnam(char *name);
extern gid_t my_getgrnam(char *name);
@@ -145,12 +146,23 @@ extern void my_getpwuid(char* name, uid_t uid);
extern void my_getgrgid(char* group, gid_t gid);
extern int get_kernel_revision();
extern int get_console_fd(char* tty_name);
extern struct mntent *findMountPoint(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
#if defined BB_MTAB
#define whine_if_fstab_is_missing() {}
#else
extern void whine_if_fstab_is_missing();
#endif
#if defined BB_NFSMOUNT
int nfsmount(const char *spec, const char *node, unsigned long *flags,
char **extra_opts, char **mount_opts, int running_bg);
#endif
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
static inline int bit(char * addr,unsigned int nr)
+14 -19
View File
@@ -27,23 +27,21 @@
#include <errno.h>
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";
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{
int status;
char newdestName[NAME_MAX];
static char* linkName;
if (argc < 3) {
usage (ln_usage);
@@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
}
destName = argv[argc - 1];
linkName = argv[argc - 1];
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
perror(linkName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
status = symlink(*argv, linkName);
else
status = link(*argv, newdestName);
status = link(*argv, linkName);
if ( status != 0 ) {
perror(newdestName);
perror(linkName);
exit( FALSE);
}
}
+18 -53
View File
@@ -40,7 +40,7 @@
* 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 (bypasses libc6 NSS) */
#define FEATURE_TIMESTAMPS /* show file timestamps */
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
#define FEATURE_FILETYPECHAR /* enable -p and -F */
@@ -64,10 +64,6 @@
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#ifdef FEATURE_USERNAME
#include <pwd.h>
#include <grp.h>
#endif
#ifdef FEATURE_TIMESTAMPS
#include <time.h>
#endif
@@ -83,27 +79,6 @@
#define MINOR(dev) ((dev)&0xff)
#endif
#define MODE1 "rwxrwxrwx"
#define MODE0 "---------"
#define SMODE1 "..s..s..t"
#define SMODE0 "..S..S..T"
/* The 9 mode bits to test */
static const mode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const mode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
};
#define FMT_AUTO 0
#define FMT_LONG 1 /* one record per line, extended info */
#define FMT_SINGLE 2 /* one record per line */
@@ -206,7 +181,7 @@ static char append_char(mode_t mode)
**
**/
static void list_single(const char *name, struct stat *info)
static void list_single(const char *name, struct stat *info, const char *fullname)
{
char scratch[PATH_MAX];
short len = strlen(name);
@@ -216,45 +191,35 @@ static void list_single(const char *name, struct stat *info)
if (display_fmt == FMT_LONG) {
mode_t mode = info->st_mode;
int i;
scratch[0] = TYPECHAR(mode);
for (i=0; i<9; i++)
if (mode & SBIT[i])
scratch[i+1] = (mode & MBIT[i])
? SMODE1[i]
: SMODE0[i];
else
scratch[i+1] = (mode & MBIT[i])
? MODE1[i]
: MODE0[i];
newline();
wr(scratch, 10);
wr(modeString(mode), 10);
column=10;
writenum((long)info->st_nlink,(short)4);
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
#ifdef FEATURE_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct passwd *pw = getpwuid(info->st_uid);
if (pw)
fputs(pw->pw_name, stdout);
scratch[8]='\0';
my_getpwuid( scratch, info->st_uid);
if (*scratch)
fputs(scratch, stdout);
else
writenum((long)info->st_uid,(short)0);
} else
#endif
writenum((long)info->st_uid,(short)0);
tab(24);
tab(16);
#ifdef FEATURE_USERNAME
if (!(opts & DISP_NUMERIC)) {
struct group *gr = getgrgid(info->st_gid);
if (gr)
fputs(gr->gr_name, stdout);
scratch[8]='\0';
my_getgrgid( scratch, info->st_gid);
if (*scratch)
fputs(scratch, stdout);
else
writenum((long)info->st_gid,(short)0);
} else
#endif
writenum((long)info->st_gid,(short)0);
tab(33);
tab(17);
if (S_ISBLK(mode) || S_ISCHR(mode)) {
writenum((long)MAJOR(info->st_rdev),(short)3);
fputs(", ", stdout);
@@ -297,12 +262,12 @@ static void list_single(const char *name, struct stat *info)
wr(name, len);
if (S_ISLNK(mode)) {
wr(" -> ", 4);
len = readlink(name, scratch, sizeof scratch);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
#ifdef FEATURE_FILETYPECHAR
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(name, info)) {
if (!stat(fullname, info)) {
append = append_char(info->st_mode);
if (append)
fputc(append, stdout);
@@ -372,7 +337,7 @@ static int list_item(const char *name)
if (!S_ISDIR(info.st_mode) ||
(opts & DIR_NOLIST)) {
list_single(name, &info);
list_single(name, &info, name);
return 0;
}
@@ -424,7 +389,7 @@ static int list_item(const char *name)
strcpy(fnend, entry->d_name);
if (lstat(fullname, &info))
goto direrr; /* (shouldn't fail) */
list_single(entry->d_name, &info);
list_single(entry->d_name, &info, fullname);
}
closedir(dir);
return 0;
+1 -1
View File
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
"\tdutmp /var/run/utmp\n";
static int dutmp_main (int argc, char **argv)
extern int dutmp_main (int argc, char **argv)
{
FILE *f = stdin;
+5 -4
View File
@@ -26,14 +26,15 @@
#include <errno.h>
#include <sys/param.h>
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\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";
"Options:\n"
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-p\tno error if existing, make parent directories as needed\n";
static int parentFlag = FALSE;
static mode_t mode = 777;
static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
+9 -4
View File
@@ -171,10 +171,15 @@ static volatile void die(char *str) {
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);
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
fprintf(stderr, "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", program_name);
fprintf(stderr, "Make a MINIX filesystem.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
fprintf(stderr, "\t-n [14|30]\tSpecify the maximum length of filenames\n");
fprintf(stderr, "\t-i\t\tSpecify the number of inodes for the filesystem\n");
fprintf(stderr, "\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
exit(16);
}
+3 -3
View File
@@ -27,9 +27,9 @@
#include <fcntl.h>
#include <unistd.h>
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
"\tMake special files.\n"
"\n"
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
"Make block or character special files.\n\n"
"Options:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
+5 -4
View File
@@ -47,11 +47,12 @@
/* we also get PAGE_SIZE via getpagesize() */
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n"
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n\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"
"Options:\n"
"\t-c\t\tCheck for read-ability.\n"
"\t-v0\t\tMake version 0 swap [max 128 Megs].\n"
"\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n"
"\tblock-count\tNumber of block to use (default is entire partition).\n";
+10 -4
View File
@@ -40,8 +40,8 @@
#define BUFSIZE 100
static const char mnc_usage[] =
"mini-netcat 0.0.3 -- Open pipe to IP:port\n"
"\tmnc [IP] [port]\n";
"mnc [IP] [port]\n\n"
"mini-netcat opens a pipe to IP:port\n";
int
mnc_main(int argc, char **argv)
@@ -56,9 +56,15 @@ mnc_main(int argc, char **argv)
fd_set readfds, testfds;
if (argc<=1 || **(argv+1) == '-' ) {
usage( mnc_usage);
}
argc--;
argv++;
sfd = socket(AF_INET, SOCK_STREAM, 0);
hostinfo = (struct hostent *) gethostbyname(argv[1]);
hostinfo = (struct hostent *) gethostbyname(*argv);
if (!hostinfo)
{
@@ -67,7 +73,7 @@ mnc_main(int argc, char **argv)
address.sin_family = AF_INET;
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(argv[2]));
address.sin_port = htons(atoi(*(++argv)));
len = sizeof(address);
+67 -32
View File
@@ -2,10 +2,11 @@
* 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.
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* Latest version blended together by Erik Andersen <andersen@lineo.com>,
* based on the original more implementation by Bruce, 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
@@ -25,7 +26,9 @@
/* Turning this off makes things a bit smaller (and less pretty) */
#define BB_MORE_TERM
#define BB_FEATURE_USE_TERMIOS
/* Turning this off makes things a bit smaller (and less pretty) */
#define BB_FEATURE_AUTOWIDTH
@@ -33,19 +36,16 @@
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
static const char more_usage[] = "[file ...]";
static const char more_usage[] = "more [file ...]\n";
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
#if defined (__sparc__)
#if #cpu(sparc)
# define USE_OLD_TERMIO
# include <termio.h>
# include <sys/ioctl.h>
# define termios termio
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
#else
@@ -58,24 +58,43 @@ static const char more_usage[] = "[file ...]";
void gotsig(int sig) {
stty(fileno(cin), &initial_settings);
fprintf(stdout, "\n");
exit( TRUE);
}
#endif
#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
#define TERMINAL_HEIGHT 24
#if defined BB_FEATURE_AUTOWIDTH
static int terminal_width = 0, terminal_height = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define terminal_height TERMINAL_HEIGHT
#endif
extern int more_main(int argc, char **argv)
{
int c, lines=0, input=0;
int next_page=0;
struct stat st;
FILE *file;
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = {0,0};
#endif
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
usage (more_usage);
}
argc--;
argv++;
while (argc >= 0) {
if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
usage (more_usage);
}
do {
if (argc==0) {
file = stdin;
}
@@ -88,7 +107,7 @@ extern int more_main(int argc, char **argv)
}
fstat(fileno(file), &st);
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
cin = fopen("/dev/tty", "r");
if (!cin)
cin = fopen("/dev/console", "r");
@@ -101,8 +120,18 @@ extern int more_main(int argc, char **argv)
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
stty(fileno(cin), &new_settings);
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
(void) signal(SIGINT, gotsig);
(void) signal(SIGQUIT, gotsig);
(void) signal(SIGTERM, gotsig);
#endif
while ((c = getc(file)) != EOF) {
@@ -117,7 +146,7 @@ extern int more_main(int argc, char **argv)
st.st_size);
}
len += fprintf(stdout, "%s",
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
""
#else
"\n"
@@ -127,34 +156,40 @@ extern int more_main(int argc, char **argv)
fflush(stdout);
input = getc( cin);
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */
while(len-- > 0)
while(--len >= 0)
putc('\b', stdout);
while(len++ < 79)
while(++len <= terminal_width)
putc(' ', stdout);
while(len-- > 0)
while(--len >= 0)
putc('\b', stdout);
fflush(stdout);
#endif
}
if (input=='q')
goto end;
if (input==' ' && c == '\n' )
next_page = 1;
if ( c == '\n' && ++lines == 24 )
next_page = 1;
if (c == '\n' ) {
switch(input) {
case 'q':
goto end;
case '\n':
/* increment by just one line if we are at
* the end of this line*/
next_page = 1;
break;
}
if ( ++lines == terminal_height )
next_page = 1;
}
putc(c, stdout);
}
fclose(file);
fflush(stdout);
argc--;
argv++;
}
} while (--argc > 0);
end:
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
gotsig(0);
#endif
exit(TRUE);
+32 -29
View File
@@ -43,7 +43,7 @@
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "Usage:\tmount [flags]\n"
static const char mount_usage[] = "\tmount [flags]\n"
"\tmount [flags] device directory [-o options,more-options]\n"
"\n"
"Flags:\n"
@@ -92,12 +92,12 @@ static const struct mount_options mount_options[] = {
};
#if ! defined BB_MTAB
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
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)
long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
{
int status=0;
@@ -106,7 +106,7 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
if ( status == 0 ) {
if ( useMtab==TRUE )
write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
return 0;
}
else
@@ -157,7 +157,7 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
int
mount_one(char *blockDevice, char *directory, char *filesystemType,
unsigned long flags, char *string_flags, int useMtab, int fakeIt)
unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts)
{
int status = 0;
@@ -182,7 +182,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
filesystemType++; // hop past tab
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
if (status == 0)
break;
}
@@ -190,7 +191,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
fclose (f);
} else {
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
}
if (status) {
@@ -203,19 +205,20 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
extern int mount_main (int argc, char **argv)
{
char string_flags[1024]="";
char string_flags_buf[1024]="";
char *string_flags = string_flags_buf;
char *extra_opts = string_flags_buf;
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 (stat("/etc/fstab", &statBuf) < 0)
fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
if (argc == 1) {
FILE *mountTable = setmntent (mtab_file, "r");
@@ -246,27 +249,22 @@ extern int mount_main (int argc, char **argv)
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
char *opt = *argv;
while (i>0 && *++opt) switch (*opt) {
case 'o':
if (--i == 0) {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
goto goodbye;
}
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);
goto goodbye;
}
filesystemType = *(++argv);
--i;
++argv;
break;
case 'w':
flags &= ~MS_RDONLY;
@@ -285,9 +283,7 @@ extern int mount_main (int argc, char **argv)
case 'v':
case 'h':
case '-':
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
break;
goto goodbye;
}
} else {
if (device == NULL)
@@ -295,8 +291,7 @@ extern int mount_main (int argc, char **argv)
else if (directory == NULL)
directory=*argv;
else {
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
goto goodbye;
}
}
i--;
@@ -323,18 +318,26 @@ extern int mount_main (int argc, char **argv)
*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);
flags, string_flags, useMtab, fakeIt, extra_opts);
}
}
endmntent (f);
} else {
if (device && directory) {
#ifdef BB_NFSMOUNT
if (strcmp(filesystemType, "nfs") == 0) {
if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
exit(FALSE);
}
#endif
exit (mount_one (device, directory, filesystemType,
flags, string_flags, useMtab, fakeIt));
flags, string_flags, useMtab, fakeIt, extra_opts));
} else {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
goto goodbye;
}
}
exit( TRUE);
goodbye:
usage( mount_usage);
}
+106
View File
@@ -0,0 +1,106 @@
#include "internal.h"
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <mntent.h>
#include <sys/mount.h>
extern const char mtab_file[]; /* Defined in utility.c */
static char *
stralloc(const char * string)
{
int length = strlen(string) + 1;
char * n = malloc(length);
memcpy(n, string, length);
return n;
}
extern void
erase_mtab(const char * name)
{
struct mntent entries[20];
int count = 0;
FILE *mountTable = setmntent(mtab_file, "r");
struct mntent * m;
if ( mountTable == 0
&& (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
perror(mtab_file);
return;
}
while ( (m = getmntent(mountTable)) != 0 ) {
entries[count].mnt_fsname = stralloc(m->mnt_fsname);
entries[count].mnt_dir = stralloc(m->mnt_dir);
entries[count].mnt_type = stralloc(m->mnt_type);
entries[count].mnt_opts = stralloc(m->mnt_opts);
entries[count].mnt_freq = m->mnt_freq;
entries[count].mnt_passno = m->mnt_passno;
count++;
}
endmntent(mountTable);
if ( (mountTable = setmntent(mtab_file, "w")) ) {
int i;
for ( i = 0; i < count; i++ ) {
int result = ( strcmp(entries[i].mnt_fsname, name) == 0
|| strcmp(entries[i].mnt_dir, name) == 0 );
if ( result )
continue;
else
addmntent(mountTable, &entries[i]);
}
endmntent(mountTable);
}
else if ( errno != EROFS )
perror(mtab_file);
}
extern void
write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags)
{
FILE *mountTable = setmntent(mtab_file, "a+");
struct mntent m;
if ( mountTable == 0 ) {
perror(mtab_file);
return;
}
if (mountTable) {
int length = strlen(directory);
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);
}
}
+7 -2
View File
@@ -29,7 +29,7 @@
static const char mv_usage[] = "mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
@@ -56,7 +56,7 @@ extern int mv_main(int argc, char **argv)
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
@@ -67,6 +67,11 @@ extern int mv_main(int argc, char **argv)
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(srcName, skipName));
else
strcat(newdestName, srcName);
fprintf(stderr, "srcName='%s'\n", srcName);
fprintf(stderr, "skipName='%s'\n", skipName);
fprintf(stderr, "newdestName='%s'\n", newdestName);
}
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
exit( FALSE);
+2 -2
View File
@@ -74,7 +74,7 @@ static void parse_proc_status(char* S, proc_t* P)
);
else fprintf(stderr, "Internal error!\n");
/* For busybox, ignoring effecting, saved, etc */
/* For busybox, ignoring effective, saved, etc */
tmp = strstr (S,"Uid:");
if(tmp) sscanf (tmp,
"Uid:\t%d", &P->ruid);
@@ -100,7 +100,7 @@ extern int ps_main(int argc, char **argv)
int i, c;
if ( argc>1 && **(argv+1) == '-' ) {
usage ("ps - report process status\nThis version of ps accepts no options.\n");
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
}
dir = opendir("/proc");
+2 -2
View File
@@ -74,7 +74,7 @@ static void parse_proc_status(char* S, proc_t* P)
);
else fprintf(stderr, "Internal error!\n");
/* For busybox, ignoring effecting, saved, etc */
/* For busybox, ignoring effective, saved, etc */
tmp = strstr (S,"Uid:");
if(tmp) sscanf (tmp,
"Uid:\t%d", &P->ruid);
@@ -100,7 +100,7 @@ extern int ps_main(int argc, char **argv)
int i, c;
if ( argc>1 && **(argv+1) == '-' ) {
usage ("ps - report process status\nThis version of ps accepts no options.\n");
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
}
dir = opendir("/proc");
+2 -3
View File
@@ -50,7 +50,6 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
} while (regexec(re, s, FALSE, ignoreCase) == TRUE);
/* copy stuff from after the match */
while ( (*d++ = *s++) ) {}
d[-1] = '\n';
d[0] = '\0';
strcpy(haystack, buf);
}
@@ -136,7 +135,7 @@ static char *retext; /* points to the text being compiled */
/* error-handling stuff */
jmp_buf errorhandler;
#define FAIL(why) fprintf(stderr, why); longjmp(errorhandler, 1)
#define FAIL(why) do {fprintf(stderr, why); longjmp(errorhandler, 1);} while (0)
@@ -505,7 +504,7 @@ extern regexp *regcomp(char* text)
int token;
int peek;
char *build;
regexp *re;
regexp *re; // Ignore compiler whining. If we longjmp, we don't use re anymore.
/* prepare for error handling */
+12 -4
View File
@@ -26,9 +26,11 @@
#include <time.h>
#include <utime.h>
#include <dirent.h>
#include <errno.h>
static const char* rm_usage = "rm [OPTION]... FILE...\n"
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\tremove existing destinations, never prompt\n"
"\t-r\tremove the contents of directories recursively\n";
@@ -58,6 +60,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
extern int rm_main(int argc, char **argv)
{
struct stat statbuf;
if (argc < 2) {
usage( rm_usage);
@@ -84,9 +87,14 @@ extern int rm_main(int argc, char **argv)
while (argc-- > 0) {
srcName = *(argv++);
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
fileAction, dirAction) == FALSE) {
exit( FALSE);
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
}
else {
if (recursiveAction( srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction) == FALSE) {
exit( FALSE);
}
}
}
exit( TRUE);
+1 -1
View File
@@ -29,7 +29,7 @@
extern int rmdir_main(int argc, char **argv)
{
if ( argc==1 || **(argv+1) == '-' ) {
usage( "rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
}
while (--argc > 0) {
+44 -42
View File
@@ -32,22 +32,36 @@
#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"
"sed [-n] [-e script] [file...]\n\n"
"Allowed sed scripts come in the following form:\n"
"\t's/regexp/replacement/[gp]'\n"
"which attempt to match regexp against the pattern space\n"
"and if successful replaces the matched portion with replacement.\n\n"
"Options:\n"
"-e\tadd the script to the commands to be executed\n"
"-n\tsuppress automatic printing of pattern space\n\n"
#if defined BB_REGEXP
"This version of sed matches full regexps.\n";
"This version of sed matches full regular expresions.\n";
#else
"This version of sed matches strings (not full regexps).\n";
"This version of sed matches strings (not full regular expresions).\n";
#endif
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
{
int foundOne=FALSE;
char haystack[1024];
while (fgets (haystack, 1023, fp)) {
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
if (foundOne==TRUE && printFlag==TRUE) {
fprintf(stdout, haystack);
}
if (quietFlag==FALSE) {
fprintf(stdout, haystack);
}
}
}
extern int sed_main (int argc, char **argv)
{
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
char *name;
char *cp;
int ignoreCase=FALSE;
int foundOne=FALSE;
int printFlag=FALSE;
int quietFlag=FALSE;
int stopNow;
char *haystack;
argc--;
argv++;
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
cp = *argv++;
stopNow=FALSE;
while (*++cp && 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++;
if ( *++cp != 's')
cp = *argv++;
while( *cp ) {
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
char* pos=needle=cp+2;
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "B\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
for(;;) {
pos = strchr(pos, '/');
if (pos==NULL) {
fprintf(stderr, "C\n");
usage( sed_usage);
}
if (*(pos-1) == '\\') {
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
*pos=0;
if (pos+2 != 0) {
while (*++pos) {
fprintf(stderr, "pos='%s'\n", pos);
switch (*pos) {
case 'i':
ignoreCase=TRUE;
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
}
cp++;
}
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
//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++;
if (argc==0) {
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
} else {
while (argc-- > 0) {
name = *argv++;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
fp = fopen (name, "r");
if (fp == NULL) {
perror (name);
continue;
}
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
if (ferror (fp))
perror (name);
fclose (fp);
}
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);
}
+2 -2
View File
@@ -23,8 +23,8 @@
#include "internal.h"
#include <stdio.h>
const char sleep_usage[] = " NUMBER\n"
"Pause for NUMBER seconds.\n";
const char sleep_usage[] = "sleep N\n\n"
"Pause for N seconds.\n";
extern int
sleep_main(int argc, char * * argv)
+1 -1
View File
@@ -27,7 +27,7 @@ extern int
sync_main(int argc, char * * argv)
{
if ( argc>1 && **(argv+1) == '-' ) {
usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
}
exit( sync());
}
+67 -40
View File
@@ -10,6 +10,9 @@
* Modified for busybox by Erik Andersen <andersee@debian.org>
* Adjusted to grok stdin/stdout options.
*
* Modified to handle device special files by Matt Porter
* <porter@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
@@ -34,13 +37,15 @@
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
static const char tar_usage[] =
"tar -[cxtvOf] [tarFileName] [FILE] ...\n"
"Create, extract, or list files from a tar file\n\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
"Create, extract, or list files from a tar file\n\n"
"Options:\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
@@ -92,7 +97,7 @@ static int createFlag;
static int verboseFlag;
static int tostdoutFlag;
static int inHeader;
static int inHeader; // <- check me
static int badHeader;
static int errorFlag;
static int skipFileFlag;
@@ -169,10 +174,9 @@ extern int tar_main (int argc, char **argv)
/*
* Parse the options.
*/
options = *argv++;
argc--;
if (**argv == '-') {
options = (*argv++) + 1;
argc--;
for (; *options; options++) {
switch (*options) {
case 'f':
@@ -208,10 +212,13 @@ extern int tar_main (int argc, char **argv)
break;
case '-':
usage( tar_usage);
break;
default:
fprintf (stderr, "Unknown tar flag '%c'\n", *options);
fprintf (stderr, "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n",
*options);
exit (FALSE);
}
@@ -221,7 +228,7 @@ extern int tar_main (int argc, char **argv)
/*
* Validate the options.
*/
if (extractFlag + listFlag + createFlag != 1) {
if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n");
@@ -232,13 +239,13 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process.
*/
if (createFlag)
if (createFlag==TRUE)
writeTarFile (argc, argv);
else
readTarFile (argc, argv);
if (errorFlag)
if (errorFlag==TRUE)
fprintf (stderr, "\n");
exit (errorFlag);
exit (!errorFlag);
}
@@ -283,7 +290,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Read blocks from the file until an end of file header block
* has been seen. (A real end of file from a read is an error.)
*/
while (!eofFlag) {
while (eofFlag==FALSE) {
/*
* Read the next block of data if necessary.
* This will be a large block if possible, which we will
@@ -310,7 +317,7 @@ static void readTarFile (int fileCount, char **fileTable)
/*
* If we are expecting a header block then examine it.
*/
if (inHeader) {
if (inHeader==TRUE) {
readHeader ((const TarHeader *) cp, fileCount, fileTable);
cp += TAR_BLOCK_SIZE;
@@ -374,12 +381,15 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
int uid;
int gid;
int checkSum;
int major;
int minor;
long size;
time_t mtime;
const char *name;
int cc;
int hardLink;
int softLink;
int devFileFlag;
/*
* If the block is completely empty, then this is the end of the
@@ -408,9 +418,11 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
size = getOctal (hp->size, sizeof (hp->size));
mtime = getOctal (hp->mtime, sizeof (hp->mtime));
checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
major = getOctal (hp->devMajor, sizeof (hp->devMajor));
minor = getOctal (hp->devMinor, sizeof (hp->devMinor));
if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
if (!badHeader)
if (badHeader==FALSE)
fprintf (stderr, "Bad tar header, skipping\n");
badHeader = TRUE;
@@ -420,6 +432,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
badHeader = FALSE;
skipFileFlag = FALSE;
devFileFlag = FALSE;
/*
* Check for the file modes.
@@ -431,12 +444,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
(hp->typeFlag == TAR_TYPE_SOFT_LINK - '0'));
/*
* Check for a directory or a regular file.
* Check for a directory.
*/
if (name[strlen (name) - 1] == '/')
mode |= S_IFDIR;
else if ((mode & S_IFMT) == 0)
mode |= S_IFREG;
/*
* Check for absolute paths in the file.
@@ -446,7 +457,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
while (*name == '/')
name++;
if (!warnedRoot) {
if (warnedRoot==FALSE) {
fprintf (stderr,
"Absolute path detected, removing leading slashes\n");
}
@@ -458,9 +469,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* See if we want this file to be restored.
* If not, then set up to skip it.
*/
if (!wantFileName (name, fileCount, fileTable)) {
if (!hardLink && !softLink && S_ISREG (mode)) {
inHeader = (size == 0);
if (wantFileName (name, fileCount, fileTable) == FALSE) {
if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
|| S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
}
@@ -473,8 +485,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* This file is to be handled.
* If we aren't extracting then just list information about the file.
*/
if (!extractFlag) {
if (verboseFlag) {
if (extractFlag==FALSE) {
if (verboseFlag==TRUE) {
printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
uid, gid, size, timeString (mtime), name);
} else
@@ -484,8 +496,9 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
printf (" (link to \"%s\")", hp->linkName);
else if (softLink)
printf (" (symlink to \"%s\")", hp->linkName);
else if (S_ISREG (mode)) {
inHeader = (size == 0);
else if (S_ISREG (mode) || S_ISCHR (mode) || S_ISBLK (mode) ||
S_ISSOCK(mode) || S_ISFIFO(mode) ) {
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
}
@@ -497,7 +510,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/*
* We really want to extract the file.
*/
if (verboseFlag)
if (verboseFlag==TRUE)
printf ("x %s\n", name);
if (hardLink) {
@@ -532,7 +545,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/
createPath (name, 0777);
inHeader = (size == 0);
inHeader = (size == 0)? TRUE : FALSE;
dataCc = size;
/*
@@ -540,8 +553,18 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/
if (tostdoutFlag == TRUE)
outFd = STDOUT;
else
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
else {
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
devFileFlag = TRUE;
outFd = mknod (name, mode, makedev(major, minor) );
}
else if (S_ISFIFO(mode) ) {
devFileFlag = TRUE;
outFd = mkfifo(name, mode);
} else {
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
}
if (outFd < 0) {
perror (name);
@@ -552,7 +575,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/*
* If the file is empty, then that's all we need to do.
*/
if (size == 0 && tostdoutFlag == FALSE) {
if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
(void) close (outFd);
outFd = -1;
}
@@ -578,7 +601,7 @@ static void readData (const char *cp, int count)
* If we aren't extracting files or this file is being
* skipped then do nothing more.
*/
if (!extractFlag || skipFileFlag)
if (extractFlag==FALSE || skipFileFlag==TRUE)
return;
/*
@@ -653,7 +676,7 @@ static void writeTarFile (int fileCount, char **fileTable)
* Append each file name into the archive file.
* Follow symbolic links for these top level file names.
*/
while (!errorFlag && (fileCount-- > 0)) {
while (errorFlag==FALSE && (fileCount-- > 0)) {
saveFile (*fileTable++, FALSE);
}
@@ -685,7 +708,7 @@ static void saveFile (const char *fileName, int seeLinks)
int mode;
struct stat statbuf;
if (verboseFlag)
if (verboseFlag==TRUE)
printf ("a %s\n", fileName);
/*
@@ -701,7 +724,7 @@ static void saveFile (const char *fileName, int seeLinks)
* Find out about the file.
*/
#ifdef S_ISLNK
if (seeLinks)
if (seeLinks==TRUE)
status = lstat (fileName, &statbuf);
else
#endif
@@ -732,12 +755,16 @@ static void saveFile (const char *fileName, int seeLinks)
return;
}
if (S_ISREG (mode)) {
saveRegularFile (fileName, &statbuf);
return;
}
/* Some day add support for tarring these up... but not today. :) */
// if (S_ISLNK(mode) || S_ISFIFO(mode) || S_ISBLK(mode) || S_ISCHR (mode) ) {
// fprintf (stderr, "%s: This version of tar can't store this type of file\n", fileName);
// }
/*
* The file is a strange type of file, ignore it.
@@ -801,7 +828,7 @@ saveRegularFile (const char *fileName, const struct stat *statbuf)
*/
cc = 0;
if (!sawEof) {
if (sawEof==FALSE) {
cc = fullRead (fileFd, data, dataCount);
if (cc < 0) {
@@ -890,7 +917,7 @@ static void saveDirectory (const char *dirName, const struct stat *statbuf)
* Read all of the directory entries and check them,
* except for the current and parent directory entries.
*/
while (!errorFlag && ((entry = readdir (dir)) != NULL)) {
while (errorFlag==FALSE && ((entry = readdir (dir)) != NULL)) {
if ((strcmp (entry->d_name, ".") == 0) ||
(strcmp (entry->d_name, "..") == 0)) {
continue;
@@ -989,7 +1016,7 @@ static void writeTarBlock (const char *buf, int len)
/*
* If we had a write error before, then do nothing more.
*/
if (errorFlag)
if (errorFlag==TRUE)
return;
/*
+2 -2
View File
@@ -31,7 +31,7 @@
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
"\tUpdate the last-modified date on the given file[s].\n";
"Update the last-modified date on the given file[s].\n";
@@ -54,7 +54,7 @@ touch_main(int argc, char **argv)
create = FALSE;
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
usage( touch_usage);
exit( FALSE);
}
argc--;
+4 -4
View File
@@ -29,8 +29,8 @@
#include <errno.h>
static const char umount_usage[] =
"Usage: umount [flags] filesystem|directory\n"
"Optional Flags:\n"
"Usage: umount [flags] filesystem|directory\n\n"
"Flags:\n"
"\t-a:\tUnmount all file systems"
#ifdef BB_MTAB
" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
@@ -108,7 +108,7 @@ umount_main(int argc, char** argv)
}
/* Parse any options */
while (argc-- > 0 && **(argv++) == '-') {
while (--argc > 0 && **(++argv) == '-') {
while (*++(*argv)) switch (**argv) {
case 'a':
umountAll = TRUE;
@@ -124,7 +124,7 @@ umount_main(int argc, char** argv)
}
if(umountAll) {
if(umountAll==TRUE) {
exit(umount_all(useMtab));
}
if ( do_umount(*argv,useMtab) == 0 )
+3 -2
View File
@@ -41,8 +41,9 @@
static const char uname_usage[] =
"uname [OPTION]...\n"
"Print certain system information. With no OPTION, same as -s.\n"
"uname [OPTION]...\n\n"
"Print certain system information. With no OPTION, same as -s.\n\n"
"Options:\n"
"\t-a\tprint all information\n"
"\t-m\tthe machine (hardware) type\n"
"\t-n\tprint the machine's network node hostname\n"
+11 -3
View File
@@ -191,9 +191,17 @@ static void leave(int status)
}
static void show_usage(void) {
fprintf(stderr,
"Usage: %s [-larvsmf] /dev/name\n",
program_name);
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name);
fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-l\tLists all filenames\n");
fprintf(stderr, "\t-r\tPerform interactive repairs\n");
fprintf(stderr, "\t-a\tPerform automatic repairs\n");
fprintf(stderr, "\t-v\tverbose\n");
fprintf(stderr, "\t-s\tOutputs super-block information\n");
fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n");
fprintf(stderr, "\t-f\tForce file system check.\n\n");
leave(16);
}
+9 -4
View File
@@ -171,10 +171,15 @@ static volatile void die(char *str) {
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);
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
fprintf(stderr, "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", program_name);
fprintf(stderr, "Make a MINIX filesystem.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
fprintf(stderr, "\t-n [14|30]\tSpecify the maximum length of filenames\n");
fprintf(stderr, "\t-i\t\tSpecify the number of inodes for the filesystem\n");
fprintf(stderr, "\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
exit(16);
}
+5 -4
View File
@@ -47,11 +47,12 @@
/* we also get PAGE_SIZE via getpagesize() */
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n"
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n\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"
"Options:\n"
"\t-c\t\tCheck for read-ability.\n"
"\t-v0\t\tMake version 0 swap [max 128 Megs].\n"
"\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n"
"\tblock-count\tNumber of block to use (default is entire partition).\n";
+67 -32
View File
@@ -2,10 +2,11 @@
* 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.
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* Latest version blended together by Erik Andersen <andersen@lineo.com>,
* based on the original more implementation by Bruce, 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
@@ -25,7 +26,9 @@
/* Turning this off makes things a bit smaller (and less pretty) */
#define BB_MORE_TERM
#define BB_FEATURE_USE_TERMIOS
/* Turning this off makes things a bit smaller (and less pretty) */
#define BB_FEATURE_AUTOWIDTH
@@ -33,19 +36,16 @@
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
static const char more_usage[] = "[file ...]";
static const char more_usage[] = "more [file ...]\n";
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
#if defined (__sparc__)
#if #cpu(sparc)
# define USE_OLD_TERMIO
# include <termio.h>
# include <sys/ioctl.h>
# define termios termio
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
#else
@@ -58,24 +58,43 @@ static const char more_usage[] = "[file ...]";
void gotsig(int sig) {
stty(fileno(cin), &initial_settings);
fprintf(stdout, "\n");
exit( TRUE);
}
#endif
#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
#define TERMINAL_HEIGHT 24
#if defined BB_FEATURE_AUTOWIDTH
static int terminal_width = 0, terminal_height = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define terminal_height TERMINAL_HEIGHT
#endif
extern int more_main(int argc, char **argv)
{
int c, lines=0, input=0;
int next_page=0;
struct stat st;
FILE *file;
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = {0,0};
#endif
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
usage (more_usage);
}
argc--;
argv++;
while (argc >= 0) {
if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
usage (more_usage);
}
do {
if (argc==0) {
file = stdin;
}
@@ -88,7 +107,7 @@ extern int more_main(int argc, char **argv)
}
fstat(fileno(file), &st);
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
cin = fopen("/dev/tty", "r");
if (!cin)
cin = fopen("/dev/console", "r");
@@ -101,8 +120,18 @@ extern int more_main(int argc, char **argv)
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
stty(fileno(cin), &new_settings);
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
#endif
(void) signal(SIGINT, gotsig);
(void) signal(SIGQUIT, gotsig);
(void) signal(SIGTERM, gotsig);
#endif
while ((c = getc(file)) != EOF) {
@@ -117,7 +146,7 @@ extern int more_main(int argc, char **argv)
st.st_size);
}
len += fprintf(stdout, "%s",
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
""
#else
"\n"
@@ -127,34 +156,40 @@ extern int more_main(int argc, char **argv)
fflush(stdout);
input = getc( cin);
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */
while(len-- > 0)
while(--len >= 0)
putc('\b', stdout);
while(len++ < 79)
while(++len <= terminal_width)
putc(' ', stdout);
while(len-- > 0)
while(--len >= 0)
putc('\b', stdout);
fflush(stdout);
#endif
}
if (input=='q')
goto end;
if (input==' ' && c == '\n' )
next_page = 1;
if ( c == '\n' && ++lines == 24 )
next_page = 1;
if (c == '\n' ) {
switch(input) {
case 'q':
goto end;
case '\n':
/* increment by just one line if we are at
* the end of this line*/
next_page = 1;
break;
}
if ( ++lines == terminal_height )
next_page = 1;
}
putc(c, stdout);
}
fclose(file);
fflush(stdout);
argc--;
argv++;
}
} while (--argc > 0);
end:
#ifdef BB_MORE_TERM
#ifdef BB_FEATURE_USE_TERMIOS
gotsig(0);
#endif
exit(TRUE);
+32 -29
View File
@@ -43,7 +43,7 @@
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "Usage:\tmount [flags]\n"
static const char mount_usage[] = "\tmount [flags]\n"
"\tmount [flags] device directory [-o options,more-options]\n"
"\n"
"Flags:\n"
@@ -92,12 +92,12 @@ static const struct mount_options mount_options[] = {
};
#if ! defined BB_MTAB
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
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)
long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
{
int status=0;
@@ -106,7 +106,7 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
if ( status == 0 ) {
if ( useMtab==TRUE )
write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
return 0;
}
else
@@ -157,7 +157,7 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
int
mount_one(char *blockDevice, char *directory, char *filesystemType,
unsigned long flags, char *string_flags, int useMtab, int fakeIt)
unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts)
{
int status = 0;
@@ -182,7 +182,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
filesystemType++; // hop past tab
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
if (status == 0)
break;
}
@@ -190,7 +191,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
fclose (f);
} else {
status = do_mount (blockDevice, directory, filesystemType,
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
flags | MS_MGC_VAL, string_flags, useMtab,
fakeIt, mtab_opts);
}
if (status) {
@@ -203,19 +205,20 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
extern int mount_main (int argc, char **argv)
{
char string_flags[1024]="";
char string_flags_buf[1024]="";
char *string_flags = string_flags_buf;
char *extra_opts = string_flags_buf;
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 (stat("/etc/fstab", &statBuf) < 0)
fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
if (argc == 1) {
FILE *mountTable = setmntent (mtab_file, "r");
@@ -246,27 +249,22 @@ extern int mount_main (int argc, char **argv)
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
char *opt = *argv;
while (i>0 && *++opt) switch (*opt) {
case 'o':
if (--i == 0) {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
goto goodbye;
}
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);
goto goodbye;
}
filesystemType = *(++argv);
--i;
++argv;
break;
case 'w':
flags &= ~MS_RDONLY;
@@ -285,9 +283,7 @@ extern int mount_main (int argc, char **argv)
case 'v':
case 'h':
case '-':
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
break;
goto goodbye;
}
} else {
if (device == NULL)
@@ -295,8 +291,7 @@ extern int mount_main (int argc, char **argv)
else if (directory == NULL)
directory=*argv;
else {
fprintf (stderr, "%s\n", mount_usage);
exit( TRUE);
goto goodbye;
}
}
i--;
@@ -323,18 +318,26 @@ extern int mount_main (int argc, char **argv)
*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);
flags, string_flags, useMtab, fakeIt, extra_opts);
}
}
endmntent (f);
} else {
if (device && directory) {
#ifdef BB_NFSMOUNT
if (strcmp(filesystemType, "nfs") == 0) {
if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
exit(FALSE);
}
#endif
exit (mount_one (device, directory, filesystemType,
flags, string_flags, useMtab, fakeIt));
flags, string_flags, useMtab, fakeIt, extra_opts));
} else {
fprintf (stderr, "%s\n", mount_usage);
exit( FALSE);
goto goodbye;
}
}
exit( TRUE);
goodbye:
usage( mount_usage);
}
+4 -4
View File
@@ -29,8 +29,8 @@
#include <errno.h>
static const char umount_usage[] =
"Usage: umount [flags] filesystem|directory\n"
"Optional Flags:\n"
"Usage: umount [flags] filesystem|directory\n\n"
"Flags:\n"
"\t-a:\tUnmount all file systems"
#ifdef BB_MTAB
" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
@@ -108,7 +108,7 @@ umount_main(int argc, char** argv)
}
/* Parse any options */
while (argc-- > 0 && **(argv++) == '-') {
while (--argc > 0 && **(++argv) == '-') {
while (*++(*argv)) switch (**argv) {
case 'a':
umountAll = TRUE;
@@ -124,7 +124,7 @@ umount_main(int argc, char** argv)
}
if(umountAll) {
if(umountAll==TRUE) {
exit(umount_all(useMtab));
}
if ( do_umount(*argv,useMtab) == 0 )
+105 -63
View File
@@ -46,7 +46,7 @@ const char mtab_file[] = "/proc/mounts";
/* volatile so gcc knows this is the enod of the line */
volatile void usage(const char *usage)
extern void usage(const char *usage)
{
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
fprintf(stderr, "Usage: %s\n", usage);
@@ -236,7 +236,30 @@ copyFile( const char *srcName, const char *destName,
#ifdef BB_TAR
#if defined BB_TAR || defined BB_LS
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
static const mode_t SBIT[] = {
0, 0, S_ISUID,
0, 0, S_ISGID,
0, 0, S_ISVTX
};
/* The 9 mode bits to test */
static const mode_t MBIT[] = {
S_IRUSR, S_IWUSR, S_IXUSR,
S_IRGRP, S_IWGRP, S_IXGRP,
S_IROTH, S_IWOTH, S_IXOTH
};
#define MODE1 "rwxrwxrwx"
#define MODE0 "---------"
#define SMODE1 "..s..s..t"
#define SMODE0 "..S..S..T"
/*
* Return the standard ls-like mode string from a file mode.
* This is static and so is overwritten on each call.
@@ -245,64 +268,25 @@ const char *modeString(int mode)
{
static char buf[12];
strcpy(buf, "----------");
/*
* Fill in the file type.
*/
if (S_ISDIR(mode))
buf[0] = 'd';
if (S_ISCHR(mode))
buf[0] = 'c';
if (S_ISBLK(mode))
buf[0] = 'b';
if (S_ISFIFO(mode))
buf[0] = 'p';
if (S_ISLNK(mode))
buf[0] = 'l';
if (S_ISSOCK(mode))
buf[0] = 's';
/*
* Now fill in the normal file permissions.
*/
if (mode & S_IRUSR)
buf[1] = 'r';
if (mode & S_IWUSR)
buf[2] = 'w';
if (mode & S_IXUSR)
buf[3] = 'x';
if (mode & S_IRGRP)
buf[4] = 'r';
if (mode & S_IWGRP)
buf[5] = 'w';
if (mode & S_IXGRP)
buf[6] = 'x';
if (mode & S_IROTH)
buf[7] = 'r';
if (mode & S_IWOTH)
buf[8] = 'w';
if (mode & S_IXOTH)
buf[9] = 'x';
/*
* Finally fill in magic stuff like suid and sticky text.
*/
if (mode & S_ISUID)
buf[3] = ((mode & S_IXUSR) ? 's' : 'S');
if (mode & S_ISGID)
buf[6] = ((mode & S_IXGRP) ? 's' : 'S');
if (mode & S_ISVTX)
buf[9] = ((mode & S_IXOTH) ? 't' : 'T');
int i;
buf[0] = TYPECHAR(mode);
for (i=0; i<9; i++) {
if (mode & SBIT[i])
buf[i+1] = (mode & MBIT[i])?
SMODE1[i] : SMODE0[i];
else
buf[i+1] = (mode & MBIT[i])?
MODE1[i] : MODE0[i];
}
return buf;
}
#endif
#ifdef BB_TAR
/*
* Get the time string to be used for a file.
* This is down to the minute for new files, but only the date for old files.
* The string is returned from a static buffer, and so is overwritten for
* each call.
* Return the standard ls-like time string from a time_t
* This is static and so is overwritten on each call.
*/
const char *timeString(time_t timeVal)
{
@@ -325,7 +309,6 @@ const char *timeString(time_t timeVal)
return buf;
}
/*
* Write all of the supplied buffer out to a file.
* This does multiple writes as necessary.
@@ -415,8 +398,12 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
return (FALSE);
}
if ( (followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) )
return (TRUE);
if ( (followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) ) {
if (fileAction == NULL)
return (TRUE);
else
return (fileAction(fileName, &statbuf));
}
if (recurse == FALSE) {
if (S_ISDIR(statbuf.st_mode)) {
@@ -501,12 +488,8 @@ extern void createPath (const char *name, int mode)
while (cp) {
cpOld = cp;
cp = strchr (cp + 1, '/');
*cpOld = '\0';
if (mkdir (buf, cp ? 0777 : mode) == 0)
printf ("Directory \"%s\" created\n", buf);
mkdir (buf, cp ? 0777 : mode);
*cpOld = '/';
}
}
@@ -868,5 +851,64 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
#endif
#if defined BB_DF | defined BB_MTAB
/*
* 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;
}
#endif
#if !defined BB_MTAB && (defined BB_MOUNT || defined BB_DF )
extern void whine_if_fstab_is_missing()
{
struct stat statBuf;
if (stat("/etc/fstab", &statBuf) < 0)
fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n");
}
#endif
/* END CODE */
-2246
View File
File diff suppressed because it is too large. Load diff