Compare commits

..
6 Commits
Author SHA1 Message Date
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
16 changed files with 253 additions and 153 deletions

No files matched your search

+14 -1
View File
@@ -1,5 +1,18 @@
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
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.
+1 -1
View File
@@ -17,7 +17,7 @@
PROG=busybox
VERSION=0.32
VERSION=0.33
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
# Comment out the following to make a debuggable build
-2
View File
@@ -380,7 +380,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 +390,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
+10 -44
View File
@@ -38,6 +38,7 @@ 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);
@@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint)
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)),
@@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint)
return 0;
}
/*
* 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;
+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"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
"\nOptions:\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);
}
}
+10 -44
View File
@@ -38,6 +38,7 @@ 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);
@@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint)
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)),
@@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint)
return 0;
}
/*
* 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;
-2
View File
@@ -380,7 +380,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 +390,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
+6 -5
View File
@@ -56,7 +56,7 @@
static char *console = VT_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
/* try to open up the specified device */
@@ -350,9 +350,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();
}
@@ -445,9 +445,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. */
+6 -5
View File
@@ -56,7 +56,7 @@
static char *console = VT_CONSOLE;
static char *second_console = VT_SECONDARY;
static char *log = VT_LOG;
static int kernel_version = 0;
/* try to open up the specified device */
@@ -350,9 +350,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();
}
@@ -445,9 +445,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. */
+9 -1
View File
@@ -29,6 +29,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <mntent.h>
/* Some useful definitions */
@@ -145,12 +146,19 @@ 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_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"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
"\nOptions:\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);
}
}
+2 -3
View File
@@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv)
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");
+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);
}
}
+2 -3
View File
@@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv)
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");
+59
View File
@@ -868,5 +868,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 */
-4
View File
@@ -76,8 +76,6 @@ static char *license_msg[] = {
* The target dependent functions should be defined in tailor.c.
*/
/* $Id: zcat.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
#define RECORD_IO 0
#define get_char() get_byte()
@@ -432,8 +430,6 @@ extern int unlzw OF((int in, int out));
# undef LZW
#endif
/* $Id: zcat.c,v 1.5 1999/10/23 07:09:58 andersen Exp $ */
/* #include "getopt.h" */
/* Declarations for getopt.