More stuff

This commit is contained in:
Eric Andersen 1999-10-13 21:12:06 +00:00
parent 305a73f5ea
commit f6be944a6a
17 changed files with 618 additions and 428 deletions

View File

@ -49,7 +49,7 @@ static const struct Applet applets[] = {
{"false", false_main}, {"false", false_main},
#endif #endif
#ifdef BB_FDFLUSH //bin #ifdef BB_FDFLUSH //bin
{"fdflush", monadic_main}, {"fdflush", fdflush_main},
#endif #endif
#ifdef BB_FIND //usr/bin #ifdef BB_FIND //usr/bin
{"find", find_main}, {"find", find_main},
@ -70,7 +70,7 @@ static const struct Applet applets[] = {
{"length", length_main}, {"length", length_main},
#endif #endif
#ifdef BB_LN //bin #ifdef BB_LN //bin
{"ln", dyadic_main}, {"ln", ln_main},
#endif #endif
#ifdef BB_LOADKMAP //sbin #ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main}, {"loadkmap", loadkmap_main},
@ -88,7 +88,7 @@ static const struct Applet applets[] = {
{"math", math_main}, {"math", math_main},
#endif #endif
#ifdef BB_MKDIR //bin #ifdef BB_MKDIR //bin
{"mkdir", monadic_main}, {"mkdir", mkdir_main},
#endif #endif
#ifdef BB_MKNOD //bin #ifdef BB_MKNOD //bin
{"mknod", mknod_main}, {"mknod", mknod_main},
@ -124,7 +124,7 @@ static const struct Applet applets[] = {
{"rm", rm_main}, {"rm", rm_main},
#endif #endif
#ifdef BB_RMDIR //bin #ifdef BB_RMDIR //bin
{"rmdir", monadic_main}, {"rmdir", rmdir_main},
#endif #endif
#ifdef BB_SLEEP //bin #ifdef BB_SLEEP //bin
{"sleep", sleep_main}, {"sleep", sleep_main},

View File

@ -103,7 +103,6 @@ static ino_t tarInode;
*/ */
static void readTarFile (int fileCount, char **fileTable); static void readTarFile (int fileCount, char **fileTable);
static void readData (const char *cp, int count); static void readData (const char *cp, int count);
static void createPath (const char *name, int mode);
static long getOctal (const char *cp, int len); static long getOctal (const char *cp, int len);
static void readHeader (const TarHeader * hp, static void readHeader (const TarHeader * hp,
@ -1022,36 +1021,6 @@ static void writeTarBlock (const char *buf, int len)
} }
/*
* Attempt to create the directories along the specified path, except for
* the final component. The mode is given for the final directory only,
* while all previous ones get default protections. Errors are not reported
* here, as failures to restore files can be reported later.
*/
static void createPath (const char *name, int mode)
{
char *cp;
char *cpOld;
char buf[TAR_NAME_SIZE];
strcpy (buf, name);
cp = strchr (buf, '/');
while (cp) {
cpOld = cp;
cp = strchr (cp + 1, '/');
*cpOld = '\0';
if (mkdir (buf, cp ? 0777 : mode) == 0)
printf ("Directory \"%s\" created\n", buf);
*cpOld = '/';
}
}
/* /*
* Read an octal value in a field of the specified width, with optional * Read an octal value in a field of the specified width, with optional
* spaces on both sides of the number and with an optional null character * spaces on both sides of the number and with an optional null character

View File

@ -49,7 +49,7 @@ static const struct Applet applets[] = {
{"false", false_main}, {"false", false_main},
#endif #endif
#ifdef BB_FDFLUSH //bin #ifdef BB_FDFLUSH //bin
{"fdflush", monadic_main}, {"fdflush", fdflush_main},
#endif #endif
#ifdef BB_FIND //usr/bin #ifdef BB_FIND //usr/bin
{"find", find_main}, {"find", find_main},
@ -70,7 +70,7 @@ static const struct Applet applets[] = {
{"length", length_main}, {"length", length_main},
#endif #endif
#ifdef BB_LN //bin #ifdef BB_LN //bin
{"ln", dyadic_main}, {"ln", ln_main},
#endif #endif
#ifdef BB_LOADKMAP //sbin #ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main}, {"loadkmap", loadkmap_main},
@ -88,7 +88,7 @@ static const struct Applet applets[] = {
{"math", math_main}, {"math", math_main},
#endif #endif
#ifdef BB_MKDIR //bin #ifdef BB_MKDIR //bin
{"mkdir", monadic_main}, {"mkdir", mkdir_main},
#endif #endif
#ifdef BB_MKNOD //bin #ifdef BB_MKNOD //bin
{"mknod", mknod_main}, {"mknod", mknod_main},
@ -124,7 +124,7 @@ static const struct Applet applets[] = {
{"rm", rm_main}, {"rm", rm_main},
#endif #endif
#ifdef BB_RMDIR //bin #ifdef BB_RMDIR //bin
{"rmdir", monadic_main}, {"rmdir", rmdir_main},
#endif #endif
#ifdef BB_SLEEP //bin #ifdef BB_SLEEP //bin
{"sleep", sleep_main}, {"sleep", sleep_main},

View File

@ -3,7 +3,6 @@
* IE //#define BB_BLAH * IE //#define BB_BLAH
*/ */
//#define BB_BLOCK_DEVICE
#define BB_BUSYBOX #define BB_BUSYBOX
#define BB_CAT #define BB_CAT
#define BB_CHMOD_CHOWN_CHGRP #define BB_CHMOD_CHOWN_CHGRP
@ -16,20 +15,20 @@
#define BB_DMESG #define BB_DMESG
#define BB_DUTMP #define BB_DUTMP
#define BB_FALSE #define BB_FALSE
//#define BB_FDFLUSH #define BB_FDFLUSH
#define BB_FIND #define BB_FIND
#define BB_GREP #define BB_GREP
////#define BB_HALT ////#define BB_HALT
//#define BB_INIT //#define BB_INIT
#define BB_KILL #define BB_KILL
////#define BB_LENGTH ////#define BB_LENGTH
//#define BB_LN #define BB_LN
//#define BB_LOADKMAP //#define BB_LOADKMAP
////#define BB_LOSETUP ////#define BB_LOSETUP
#define BB_LS #define BB_LS
//#define BB_MAKEDEVS //#define BB_MAKEDEVS
////#define BB_MATH #define BB_MATH
//#define BB_MKDIR #define BB_MKDIR
//#define BB_MKNOD //#define BB_MKNOD
////#define BB_MKSWAP ////#define BB_MKSWAP
#define BB_MNC #define BB_MNC
@ -37,12 +36,11 @@
#define BB_MOUNT #define BB_MOUNT
////#define BB_MT ////#define BB_MT
#define BB_MV #define BB_MV
//#define BB_POSTPROCESS
//#define BB_PRINTF //#define BB_PRINTF
#define BB_PWD #define BB_PWD
#define BB_REBOOT #define BB_REBOOT
//#define BB_RM //#define BB_RM
//#define BB_RMDIR #define BB_RMDIR
#define BB_SLEEP #define BB_SLEEP
////#define BB_SWAPOFF ////#define BB_SWAPOFF
//#define BB_SWAPON //#define BB_SWAPON

View File

@ -29,7 +29,7 @@ static int uid=-1;
static int gid=0; static int gid=0;
static int whichApp; static int whichApp;
static char* invocationName=NULL; static char* invocationName=NULL;
static mode_t mode=7777; static mode_t mode=0644;
#define CHGRP_APP 1 #define CHGRP_APP 1
@ -59,6 +59,7 @@ static int fileAction(const char *fileName)
if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0) if (chown(fileName, ((whichApp==CHOWN_APP)? uid: statBuf.st_uid), gid) < 0)
return( TRUE); return( TRUE);
case CHMOD_APP: case CHMOD_APP:
fprintf(stderr, "%s, %d\n", fileName, mode);
if (chmod(fileName, mode)) if (chmod(fileName, mode))
return( TRUE); return( TRUE);
} }
@ -67,118 +68,13 @@ static int fileAction(const char *fileName)
return( FALSE); return( FALSE);
} }
/* [ugoa]{+|-|=}[rwxstl] */
int parse_mode( const char* s, mode_t* or, mode_t* and, int* group_execute)
{
mode_t mode = 0;
mode_t groups = S_ISVTX;
char type;
char c;
do {
for ( ; ; ) {
switch ( c = *s++ ) {
case '\0':
return (FALSE);
case 'u':
groups |= S_ISUID|S_IRWXU;
continue;
case 'g':
groups |= S_ISGID|S_IRWXG;
continue;
case 'o':
groups |= S_IRWXO;
continue;
case 'a':
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
continue;
case '+':
case '=':
case '-':
type = c;
if ( groups == S_ISVTX ) /* The default is "all" */
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
break;
default:
if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
*and = 0;
*or = strtol(--s, 0, 010);
return (TRUE);
}
else
return (FALSE);
}
break;
}
while ( (c = *s++) != '\0' ) {
switch ( c ) {
case ',':
break;
case 'r':
mode |= S_IRUSR|S_IRGRP|S_IROTH;
continue;
case 'w':
mode |= S_IWUSR|S_IWGRP|S_IWOTH;
continue;
case 'x':
mode |= S_IXUSR|S_IXGRP|S_IXOTH;
continue;
case 's':
if ( group_execute != 0 && (groups & S_IRWXG) ) {
if ( *group_execute < 0 )
return (FALSE);
if ( type != '-' ) {
mode |= S_IXGRP;
*group_execute = 1;
}
}
mode |= S_ISUID|S_ISGID;
continue;
case 'l':
if ( *group_execute > 0 )
return (FALSE);
if ( type != '-' ) {
*and &= ~S_IXGRP;
*group_execute = -1;
}
mode |= S_ISGID;
groups |= S_ISGID;
continue;
case 't':
mode |= S_ISVTX;
continue;
default:
return (FALSE);
}
break;
}
switch ( type ) {
case '=':
*and &= ~(groups);
/* fall through */
case '+':
*or |= mode & groups;
break;
case '-':
*and &= ~(mode & groups);
*or &= *and;
break;
}
} while ( c == ',' );
return (TRUE);
}
int chmod_chown_chgrp_main(int argc, char **argv) int chmod_chown_chgrp_main(int argc, char **argv)
{ {
struct group *grp; struct group *grp;
struct passwd *pwd; struct passwd *pwd;
int recursiveFlag=FALSE; int recursiveFlag=FALSE;
char *groupName; char *groupName;
mode_t andWithMode = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; mode_t andWithMode= S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
mode_t orWithMode = 0;
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP; whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
@ -207,12 +103,12 @@ int chmod_chown_chgrp_main(int argc, char **argv)
if ( whichApp == CHMOD_APP ) { if ( whichApp == CHMOD_APP ) {
/* Find the specified modes */ /* Find the specified modes */
if ( parse_mode(*argv, &orWithMode, &andWithMode, 0) == FALSE ) { if ( parse_mode(*argv, &mode) == FALSE ) {
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv); fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv);
exit( FALSE); exit( FALSE);
} }
mode &= andWithMode; //mode &= andWithMode;
mode |= orWithMode; fprintf(stderr, "mode %d\n", mode);
} else { } else {
/* Find the selected group */ /* Find the selected group */
@ -245,8 +141,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
exit( FALSE); exit( FALSE);
} }
while (argc-- > 1) { while (argc-- > 1) {
argv++; if (recursiveAction( *(++argv), recursiveFlag, TRUE, fileAction, fileAction)==FALSE)
recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction); exit( FALSE);
} }
exit(TRUE); exit(TRUE);
} }

View File

@ -1,52 +1,100 @@
/*
* Mini ln implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <dirent.h>
#include <sys/param.h>
#include <errno.h> #include <errno.h>
const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
"\n" "\n"
"\tAdd a new name that refers to the same file as \"original-name\"\n" "\tAdd a new name that refers to the same file as \"original-name\"\n"
"\n" "\n"
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
"\t-f:\tRemove existing destination files.\n"; "\t-f:\tRemove existing destination files.\n";
int
ln_fn(const struct FileInfo * i) static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{ {
int status = 0; int status;
char d[PATH_MAX]; char newdestName[NAME_MAX];
const char * destination = i->destination;
if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { if (argc < 3) {
fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); fprintf(stderr, "Usage: %s", ln_usage);
return 1; exit (FALSE);
} }
argc--;
/* argv++;
* If the destination is a directory, create a file within it.
*/ /* Parse any options */
if ( is_a_directory(i->destination) ) { while (**argv == '-') {
destination = join_paths( while (*++(*argv))
d switch (**argv) {
,i->destination case 's':
,&i->source[i->directoryLength]); symlinkFlag = TRUE;
} break;
case 'f':
if ( i->force ) removeoldFlag = TRUE;
status = ( unlink(destination) && errno != ENOENT ); break;
default:
if ( status == 0 ) { fprintf(stderr, "Usage: %s\n", ln_usage);
if ( i->makeSymbolicLink ) exit(FALSE);
status = symlink(i->source, destination); }
else argc--;
status = link(i->source, destination); argv++;
} }
if ( status != 0 ) {
name_and_error(destination); destName = argv[argc - 1];
return 1;
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
} }
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
else else
return 0; status = link(*argv, newdestName);
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
}
exit( TRUE);
} }

View File

@ -1,58 +1,85 @@
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <sys/param.h> #include <sys/param.h>
const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n" const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
"\tCreate directories.\n" "Create the DIRECTORY(ies), if they do not already exist\n\n"
"\n" "-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-m mode:\tSpecifiy the mode for the new directory\n" "-p\tno error if existing, make parent directories as needed\n";
"\t\tunder the argument directory.";
/*make directories skipping the last part of the path. Used here and by untar*/
int mkdir_until(const char *fpath, const struct FileInfo * fi) static int parentFlag = FALSE;
static int permFlag = FALSE;
static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
{ {
char path[PATH_MAX]; argc--;
char * s = path; argv++;
strcpy(path, fpath); /* Parse any options */
if ( s[0] == '\0' && s[1] == '\0' ) { while (argc > 1 && **argv == '-') {
usage(mkdir_usage); while (*++(*argv))
return 1; switch (**argv) {
case 'm':
permFlag = TRUE;
break;
case 'p':
parentFlag = TRUE;
break;
default:
fprintf(stderr, "%s\n", mkdir_usage);
exit(FALSE);
}
argc--;
argv++;
}
if (argc < 1) {
fprintf(stderr, "%s\n", mkdir_usage);
exit (FALSE);
}
while (--argc > 0) {
struct stat statBuf;
if (stat(*(++argv), &statBuf) != ENOENT) {
fprintf(stderr, "%s: File exists\n", *argv);
return( FALSE);
} }
s++; if (parentFlag == TRUE)
while ( *s != '\0' ) { createPath(*argv, mode);
if ( *s == '/' ) { else {
int status; if (mkdir (*argv, mode) != 0) {
perror(*argv);
*s = '\0'; exit( FALSE);
status = mkdir(path, (fi?fi->orWithMode:0700) ); }
*s = '/';
if ( status != 0 ) {
if ( errno != EEXIST ) {
name_and_error(fpath);
return 1;
}
}
}
s++;
} }
return 0; }
exit( TRUE);
} }
int
mkdir_fn(const struct FileInfo * i)
{
if ( i->makeParentDirectories ) {
if(mkdir_until(i->source, i)) return 1;
}
if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) {
name_and_error(i->source);
return 1;
}
else
return 0;
}

View File

@ -1,17 +1,41 @@
/*
* Mini rmdir implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <errno.h> #include <errno.h>
const char rmdir_usage[] = "rmdir directory [directory ...]\n"
"\n"
"\tDelete directories.\n";
extern int extern int rmdir_main(int argc, char **argv)
rmdir_fn(const struct FileInfo * i)
{ {
if ( rmdir(i->source) != 0 && errno != ENOENT && !i->force ) { if ( argc==1 || **(argv+1) == '-' ) {
name_and_error(i->source); fprintf(stderr, "Usage: rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
return 1; exit(FALSE);
}
while (--argc > 0) {
if ( rmdir(*(++argv)) == -1 ) {
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
exit(FALSE);
} }
else }
return 0; exit(TRUE);
} }

View File

@ -1,36 +1,53 @@
/*
* Mini fdflush implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/fd.h> #include <linux/fd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
const char fdflush_usage[] = "fdflush device";
int extern int fdflush_main(int argc, char **argv)
fdflush(const char *filename)
{ {
int status; int value;
int fd = open(filename, 0); int fd;
if ( **(argv+1) == '-' ) {
fprintf(stderr, "Usage: fdflush device\n");
exit(FALSE);
}
if ( fd < 0 ) { fd = open(*argv, 0);
name_and_error(filename); if ( fd < 0 ) {
return 1; perror(*argv);
} exit(FALSE);
}
status = ioctl(fd, FDFLUSH, 0); value = ioctl(fd, FDFLUSH, 0);
close(fd); close(fd);
if ( status != 0 ) { if ( value ) {
name_and_error(filename); perror(*argv);
return 1; exit(FALSE);
} }
return 0; exit (TRUE);
}
int
fdflush_fn(const struct FileInfo * i)
{
return fdflush(i->source);
} }

View File

@ -66,9 +66,9 @@ extern int date_main(int argc, char** argv);
extern int dd_main(int argc, char** argv); extern int dd_main(int argc, char** argv);
extern int df_main(int argc, char** argv); extern int df_main(int argc, char** argv);
extern int dmesg_main(int argc, char** argv); extern int dmesg_main(int argc, char** argv);
extern int dyadic_main(int argc, char** argv);
extern int false_main(int argc, char** argv); extern int false_main(int argc, char** argv);
extern int fdisk_main(int argc, char** argv); extern int fdisk_main(int argc, char** argv);
extern int fdflush_main(int argc, char **argv);
extern int find_main(int argc, char** argv); extern int find_main(int argc, char** argv);
extern int grep_main(int argc, char** argv); extern int grep_main(int argc, char** argv);
extern int halt_main(int argc, char** argv); extern int halt_main(int argc, char** argv);
@ -81,16 +81,17 @@ extern int losetup_main(int argc, char** argv);
extern int ls_main(int argc, char** argv); extern int ls_main(int argc, char** argv);
extern int makedevs_main(int argc, char** argv); extern int makedevs_main(int argc, char** argv);
extern int math_main(int argc, char** argv); extern int math_main(int argc, char** argv);
extern int mkdir_main(int argc, char** argv);
extern int mknod_main(int argc, char** argv); extern int mknod_main(int argc, char** argv);
extern int mkswap_main(int argc, char** argv); extern int mkswap_main(int argc, char** argv);
extern int mnc_main(int argc, char** argv); extern int mnc_main(int argc, char** argv);
extern int monadic_main(int argc, char** argv);
extern int mount_main(int argc, char** argv); extern int mount_main(int argc, char** argv);
extern int mt_main(int argc, char** argv); extern int mt_main(int argc, char** argv);
extern int mv_main(int argc, char** argv); extern int mv_main(int argc, char** argv);
extern int printf_main(int argc, char** argv); extern int printf_main(int argc, char** argv);
extern int pwd_main(int argc, char** argv); extern int pwd_main(int argc, char** argv);
extern int reboot_main(int argc, char** argv); extern int reboot_main(int argc, char** argv);
extern int rmdir_main(int argc, char **argv);
extern int rm_main(int argc, char** argv); extern int rm_main(int argc, char** argv);
extern int scan_partitions_main(int argc, char** argv); extern int scan_partitions_main(int argc, char** argv);
extern int sh_main(int argc, char** argv); extern int sh_main(int argc, char** argv);
@ -126,6 +127,8 @@ int recursiveAction(const char *fileName, int recurse, int followLinks,
int match(const char* text, const char * pattern); int match(const char* text, const char * pattern);
const char* timeString(time_t timeVal); const char* timeString(time_t timeVal);
extern void createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
#endif #endif

122
ln.c
View File

@ -1,52 +1,100 @@
/*
* Mini ln implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <dirent.h>
#include <sys/param.h>
#include <errno.h> #include <errno.h>
const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
"\n" "\n"
"\tAdd a new name that refers to the same file as \"original-name\"\n" "\tAdd a new name that refers to the same file as \"original-name\"\n"
"\n" "\n"
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
"\t-f:\tRemove existing destination files.\n"; "\t-f:\tRemove existing destination files.\n";
int
ln_fn(const struct FileInfo * i) static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static const char *destName;
extern int ln_main(int argc, char **argv)
{ {
int status = 0; int status;
char d[PATH_MAX]; char newdestName[NAME_MAX];
const char * destination = i->destination;
if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { if (argc < 3) {
fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); fprintf(stderr, "Usage: %s", ln_usage);
return 1; exit (FALSE);
} }
argc--;
/* argv++;
* If the destination is a directory, create a file within it.
*/ /* Parse any options */
if ( is_a_directory(i->destination) ) { while (**argv == '-') {
destination = join_paths( while (*++(*argv))
d switch (**argv) {
,i->destination case 's':
,&i->source[i->directoryLength]); symlinkFlag = TRUE;
} break;
case 'f':
if ( i->force ) removeoldFlag = TRUE;
status = ( unlink(destination) && errno != ENOENT ); break;
default:
if ( status == 0 ) { fprintf(stderr, "Usage: %s\n", ln_usage);
if ( i->makeSymbolicLink ) exit(FALSE);
status = symlink(i->source, destination); }
else argc--;
status = link(i->source, destination); argv++;
} }
if ( status != 0 ) {
name_and_error(destination); destName = argv[argc - 1];
return 1;
if ((argc > 3) && !(isDirectory(destName))) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- >= 2) {
strcpy(newdestName, destName);
strcat(newdestName, (*argv)+(strlen(*(++argv))));
if (removeoldFlag==TRUE ) {
status = ( unlink(newdestName) && errno != ENOENT );
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
} }
if ( symlinkFlag==TRUE)
status = symlink(*argv, newdestName);
else else
return 0; status = link(*argv, newdestName);
if ( status != 0 ) {
perror(newdestName);
exit( FALSE);
}
}
exit( TRUE);
} }

2
math.c
View File

@ -137,7 +137,7 @@ stack_machine(const char * argument)
} }
int int
math_main(struct FileInfo * i, int argc, char * * argv) math_main(int argc, char * * argv)
{ {
while ( argc >= 2 ) { while ( argc >= 2 ) {
stack_machine(argv[1]); stack_machine(argv[1]);

119
mkdir.c
View File

@ -1,58 +1,85 @@
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <sys/param.h> #include <sys/param.h>
const char mkdir_usage[] = "mkdir [-m mode] directory [directory ...]\n" const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
"\tCreate directories.\n" "Create the DIRECTORY(ies), if they do not already exist\n\n"
"\n" "-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-m mode:\tSpecifiy the mode for the new directory\n" "-p\tno error if existing, make parent directories as needed\n";
"\t\tunder the argument directory.";
/*make directories skipping the last part of the path. Used here and by untar*/
int mkdir_until(const char *fpath, const struct FileInfo * fi) static int parentFlag = FALSE;
static int permFlag = FALSE;
static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
{ {
char path[PATH_MAX]; argc--;
char * s = path; argv++;
strcpy(path, fpath); /* Parse any options */
if ( s[0] == '\0' && s[1] == '\0' ) { while (argc > 1 && **argv == '-') {
usage(mkdir_usage); while (*++(*argv))
return 1; switch (**argv) {
case 'm':
permFlag = TRUE;
break;
case 'p':
parentFlag = TRUE;
break;
default:
fprintf(stderr, "%s\n", mkdir_usage);
exit(FALSE);
}
argc--;
argv++;
}
if (argc < 1) {
fprintf(stderr, "%s\n", mkdir_usage);
exit (FALSE);
}
while (--argc > 0) {
struct stat statBuf;
if (stat(*(++argv), &statBuf) != ENOENT) {
fprintf(stderr, "%s: File exists\n", *argv);
return( FALSE);
} }
s++; if (parentFlag == TRUE)
while ( *s != '\0' ) { createPath(*argv, mode);
if ( *s == '/' ) { else {
int status; if (mkdir (*argv, mode) != 0) {
perror(*argv);
*s = '\0'; exit( FALSE);
status = mkdir(path, (fi?fi->orWithMode:0700) ); }
*s = '/';
if ( status != 0 ) {
if ( errno != EEXIST ) {
name_and_error(fpath);
return 1;
}
}
}
s++;
} }
return 0; }
exit( TRUE);
} }
int
mkdir_fn(const struct FileInfo * i)
{
if ( i->makeParentDirectories ) {
if(mkdir_until(i->source, i)) return 1;
}
if ( mkdir(i->source, i->orWithMode) != 0 && errno != EEXIST ) {
name_and_error(i->source);
return 1;
}
else
return 0;
}

44
rmdir.c
View File

@ -1,17 +1,41 @@
/*
* Mini rmdir implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <errno.h> #include <errno.h>
const char rmdir_usage[] = "rmdir directory [directory ...]\n"
"\n"
"\tDelete directories.\n";
extern int extern int rmdir_main(int argc, char **argv)
rmdir_fn(const struct FileInfo * i)
{ {
if ( rmdir(i->source) != 0 && errno != ENOENT && !i->force ) { if ( argc==1 || **(argv+1) == '-' ) {
name_and_error(i->source); fprintf(stderr, "Usage: rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
return 1; exit(FALSE);
}
while (--argc > 0) {
if ( rmdir(*(++argv)) == -1 ) {
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
exit(FALSE);
} }
else }
return 0; exit(TRUE);
} }

31
tar.c
View File

@ -103,7 +103,6 @@ static ino_t tarInode;
*/ */
static void readTarFile (int fileCount, char **fileTable); static void readTarFile (int fileCount, char **fileTable);
static void readData (const char *cp, int count); static void readData (const char *cp, int count);
static void createPath (const char *name, int mode);
static long getOctal (const char *cp, int len); static long getOctal (const char *cp, int len);
static void readHeader (const TarHeader * hp, static void readHeader (const TarHeader * hp,
@ -1022,36 +1021,6 @@ static void writeTarBlock (const char *buf, int len)
} }
/*
* Attempt to create the directories along the specified path, except for
* the final component. The mode is given for the final directory only,
* while all previous ones get default protections. Errors are not reported
* here, as failures to restore files can be reported later.
*/
static void createPath (const char *name, int mode)
{
char *cp;
char *cpOld;
char buf[TAR_NAME_SIZE];
strcpy (buf, name);
cp = strchr (buf, '/');
while (cp) {
cpOld = cp;
cp = strchr (cp + 1, '/');
*cpOld = '\0';
if (mkdir (buf, cp ? 0777 : mode) == 0)
printf ("Directory \"%s\" created\n", buf);
*cpOld = '/';
}
}
/* /*
* Read an octal value in a field of the specified width, with optional * Read an octal value in a field of the specified width, with optional
* spaces on both sides of the number and with an optional null character * spaces on both sides of the number and with an optional null character

View File

@ -1,36 +1,53 @@
/*
* Mini fdflush implementation for busybox
*
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h" #include "internal.h"
#include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/fd.h> #include <linux/fd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
const char fdflush_usage[] = "fdflush device";
int extern int fdflush_main(int argc, char **argv)
fdflush(const char *filename)
{ {
int status; int value;
int fd = open(filename, 0); int fd;
if ( **(argv+1) == '-' ) {
fprintf(stderr, "Usage: fdflush device\n");
exit(FALSE);
}
if ( fd < 0 ) { fd = open(*argv, 0);
name_and_error(filename); if ( fd < 0 ) {
return 1; perror(*argv);
} exit(FALSE);
}
status = ioctl(fd, FDFLUSH, 0); value = ioctl(fd, FDFLUSH, 0);
close(fd); close(fd);
if ( status != 0 ) { if ( value ) {
name_and_error(filename); perror(*argv);
return 1; exit(FALSE);
} }
return 0; exit (TRUE);
}
int
fdflush_fn(const struct FileInfo * i)
{
return fdflush(i->source);
} }

123
utility.c
View File

@ -544,4 +544,127 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
#endif #endif
#if defined (BB_TAR) || defined (BB_MKDIR)
/*
* Attempt to create the directories along the specified path, except for
* the final component. The mode is given for the final directory only,
* while all previous ones get default protections. Errors are not reported
* here, as failures to restore files can be reported later.
*/
extern void createPath (const char *name, int mode)
{
char *cp;
char *cpOld;
char buf[NAME_MAX];
strcpy (buf, name);
cp = strchr (buf, '/');
while (cp) {
cpOld = cp;
cp = strchr (cp + 1, '/');
*cpOld = '\0';
if (mkdir (buf, cp ? 0777 : mode) == 0)
printf ("Directory \"%s\" created\n", buf);
*cpOld = '/';
}
}
#endif
#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
/* [ugoa]{+|-|=}[rwxstl] */
extern int parse_mode( const char* s, mode_t* theMode)
{
mode_t or;
mode_t and;
mode_t mode = 0;
mode_t groups = S_ISVTX;
char type;
char c;
do {
for ( ; ; ) {
switch ( c = *s++ ) {
case '\0':
return (FALSE);
case 'u':
groups |= S_ISUID|S_IRWXU;
continue;
case 'g':
groups |= S_ISGID|S_IRWXG;
continue;
case 'o':
groups |= S_IRWXO;
continue;
case 'a':
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
continue;
case '+':
case '=':
case '-':
type = c;
if ( groups == S_ISVTX ) /* The default is "all" */
groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
break;
default:
if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
and = 0;
or = strtol(--s, 0, 010);
return (TRUE);
}
else
return (FALSE);
}
break;
}
while ( (c = *s++) != '\0' ) {
switch ( c ) {
case ',':
break;
case 'r':
mode |= S_IRUSR|S_IRGRP|S_IROTH;
continue;
case 'w':
mode |= S_IWUSR|S_IWGRP|S_IWOTH;
continue;
case 'x':
mode |= S_IXUSR|S_IXGRP|S_IXOTH;
continue;
case 's':
mode |= S_IXGRP|S_ISUID|S_ISGID;
continue;
case 't':
mode |= S_ISVTX;
continue;
default:
return (FALSE);
}
break;
}
switch ( type ) {
case '=':
and &= ~(groups);
/* fall through */
case '+':
or |= mode & groups;
break;
case '-':
and &= ~(mode & groups);
or &= and;
break;
}
} while ( c == ',' );
return (TRUE);
}
#endif
/* END CODE */ /* END CODE */