summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-28 00:58:14 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-28 00:58:14 +0000
commit3364d78b18386623e7af5da18ba1bb0cc6286279 (patch)
tree36b57afb6f3eefcdc8fdaf40e51fa6956264db50
parent6acaa40f27de0da935c3063b6be2ead9eeee5d0b (diff)
downloadbusybox-w32-3364d78b18386623e7af5da18ba1bb0cc6286279.tar.gz
busybox-w32-3364d78b18386623e7af5da18ba1bb0cc6286279.tar.bz2
busybox-w32-3364d78b18386623e7af5da18ba1bb0cc6286279.zip
Yet another installment in the ongoing tar saga
-Erik
-rw-r--r--archival/tar.c86
-rw-r--r--chmod_chown_chgrp.c7
-rw-r--r--coreutils/rm.c6
-rw-r--r--cp_mv.c8
-rw-r--r--find.c4
-rw-r--r--findutils/find.c4
-rw-r--r--internal.h7
-rw-r--r--rm.c6
-rw-r--r--swaponoff.c7
-rw-r--r--tar.c86
-rw-r--r--util-linux/swaponoff.c7
-rw-r--r--utility.c32
12 files changed, 191 insertions, 69 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 37a28a3d0..af0e4f8ef 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -228,6 +228,7 @@ extern int tar_main(int argc, char **argv)
228 228
229 case 'O': 229 case 'O':
230 tostdoutFlag = TRUE; 230 tostdoutFlag = TRUE;
231 tarName = "-";
231 break; 232 break;
232 233
233 case '-': 234 case '-':
@@ -439,7 +440,7 @@ static long getOctal(const char *cp, int size)
439 440
440/* Parse the tar header and fill in the nice struct with the details */ 441/* Parse the tar header and fill in the nice struct with the details */
441static int 442static int
442parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 443readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
443{ 444{
444 int i; 445 int i;
445 long chksum, sum; 446 long chksum, sum;
@@ -502,7 +503,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
502 while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) { 503 while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
503 504
504 /* First, try to read the header */ 505 /* First, try to read the header */
505 if ( parseTarHeader(&rawHeader, &header) == FALSE ) { 506 if ( readTarHeader(&rawHeader, &header) == FALSE ) {
506 close( tarFd); 507 close( tarFd);
507 if ( *(header.name) == '\0' ) { 508 if ( *(header.name) == '\0' ) {
508 goto endgame; 509 goto endgame;
@@ -661,25 +662,80 @@ static int putOctal (char *cp, int len, long value)
661 return TRUE; 662 return TRUE;
662} 663}
663 664
664static int fileAction(const char *fileName, struct stat *statbuf) 665/* Write out a tar header for the specified file */
666static int
667writeTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
665{ 668{
666 fprintf(stdout, "%s\n", fileName); 669 int i;
670 long chksum, sum;
671 unsigned char *s = (unsigned char *)rawHeader;
672
673 struct TarHeader header;
674
675 strcpy(header.name, fileName);
676 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 0777);
677 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
678 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
679 putOctal(header.size, sizeof(header.size), statbuf->st_size);
680 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
681
682 if (S_ISLNK(statbuf.st_mode)) {
683 header.type = LNKTYPE;
684 // Handle SYMTYPE
685 } else if (S_ISDIR(statbuf.st_mode)) {
686 header.type = DIRTYPE;
687 } else if (S_ISCHR(statbuf.st_mode)) {
688 header.type = CHRTYPE;
689 } else if (S_ISBLK(statbuf.st_mode)) {
690 header.type = BLKTYPE;
691 } else if (S_ISFIFO(statbuf.st_mode)) {
692 header.type = FIFOTYPE;
693 } else if (S_ISSOCK(statbuf.st_mode)) {
694 header.type = S_ISSOCK;
695 } else if (S_ISLNK(statbuf.st_mode)) {
696 header.type = LNKTYPE;
697 } else if (S_ISLNK(statbuf.st_mode)) {
698 header.type = REGTYPE;
699 }
700#if 0
701 header->linkname = rawHeader->linkname;
702 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor));
703 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor));
704
705 /* Write out the checksum */
706 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
707#endif
708
709 return ( TRUE);
710}
711
712
713static int fileAction(const char *fileName, struct stat *statbuf, void* userData)
714{
715 int *tarFd=(int*)userData;
716 dprintf(*tarFd, "%s\n", fileName);
667 return (TRUE); 717 return (TRUE);
668} 718}
669 719
670static int writeTarFile(const char* tarName, int extractFlag, int listFlag, 720static int writeTarFile(const char* tarName, int extractFlag, int listFlag,
671 int tostdoutFlag, int verboseFlag, int argc, char **argv) 721 int tostdoutFlag, int verboseFlag, int argc, char **argv)
672{ 722{
673 int tarFd=0; 723 int tarFd=-1;
674 //int errorFlag=FALSE; 724 //int errorFlag=FALSE;
675 //TarHeader rawHeader; 725 //TarHeader rawHeader;
676 //TarInfo header; 726 //TarInfo header;
677 //int alreadyWarned=FALSE; 727 //int alreadyWarned=FALSE;
678 char *directory = ".";
679 //int skipFileFlag=FALSE; 728 //int skipFileFlag=FALSE;
729 struct stat tarballStat;
730 dev_t tarDev = 0;
731 ino_t tarInode = 0;
732
733 /* Make sure there is at least one file to tar up. */
734 if (argc <= 0)
735 fatalError("tar: Cowardly refusing to create an empty archive\n");
680 736
681 /* Open the tar file for writing. */ 737 /* Open the tar file for writing. */
682 if (!strcmp(tarName, "-")) 738 if (tostdoutFlag == TRUE)
683 tarFd = fileno(stdout); 739 tarFd = fileno(stdout);
684 else 740 else
685 tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); 741 tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -687,19 +743,25 @@ static int writeTarFile(const char* tarName, int extractFlag, int listFlag,
687 errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno)); 743 errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno));
688 return ( FALSE); 744 return ( FALSE);
689 } 745 }
746 /* Store the device and inode of the tarball, so we can be sure
747 * not to try and include it into itself.... */
748 if (fstat(tarFd, &tarballStat) < 0)
749 fatalError(io_error, tarName, strerror(errno));
750 tarDev = tarballStat.st_dev;
751 tarInode = tarballStat.st_ino;
690 752
691 /* Set the umask for this process so it doesn't 753 /* Set the umask for this process so it doesn't
692 * screw up permission setting for us later. */ 754 * screw up permission setting for us later. */
693 umask(0); 755 umask(0);
694 756
695 /* Read the directory/files and iterate over them one at a time */ 757 /* Read the directory/files and iterate over them one at a time */
696 if (recursiveAction(directory, TRUE, FALSE, FALSE, 758 while (argc-- > 0) {
697 fileAction, fileAction) == FALSE) { 759 if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
698 exit(FALSE); 760 fileAction, fileAction, (void*) &tarFd) == FALSE) {
761 exit(FALSE);
762 }
699 } 763 }
700 764
701
702 // TODO: DO STUFF HERE
703 close(tarFd); 765 close(tarFd);
704 return( TRUE); 766 return( TRUE);
705} 767}
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index e197ee3e8..00c6b349a 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -60,7 +60,7 @@ static const char chmod_usage[] =
60 "\nOptions:\n\t-R\tchange files and directories recursively.\n"; 60 "\nOptions:\n\t-R\tchange files and directories recursively.\n";
61 61
62 62
63static int fileAction(const char *fileName, struct stat *statbuf) 63static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
64{ 64{
65 switch (whichApp) { 65 switch (whichApp) {
66 case CHGRP_APP: 66 case CHGRP_APP:
@@ -169,9 +169,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
169 fatalError( "%s: too few arguments\n", invocationName); 169 fatalError( "%s: too few arguments\n", invocationName);
170 } 170 }
171 while (argc-- > 1) { 171 while (argc-- > 1) {
172 if (recursiveAction 172 if (recursiveAction (*(++argv), recursiveFlag, TRUE, FALSE,
173 (*(++argv), recursiveFlag, TRUE, FALSE, fileAction, 173 fileAction, fileAction, NULL) == FALSE)
174 fileAction) == FALSE)
175 exit(FALSE); 174 exit(FALSE);
176 } 175 }
177 exit(TRUE); 176 exit(TRUE);
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 41afedaf9..683bf8bdf 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -42,7 +42,7 @@ static int forceFlag = FALSE;
42static const char *srcName; 42static const char *srcName;
43 43
44 44
45static int fileAction(const char *fileName, struct stat *statbuf) 45static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
46{ 46{
47 if (unlink(fileName) < 0) { 47 if (unlink(fileName) < 0) {
48 perror(fileName); 48 perror(fileName);
@@ -51,7 +51,7 @@ static int fileAction(const char *fileName, struct stat *statbuf)
51 return (TRUE); 51 return (TRUE);
52} 52}
53 53
54static int dirAction(const char *fileName, struct stat *statbuf) 54static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
55{ 55{
56 if (rmdir(fileName) < 0) { 56 if (rmdir(fileName) < 0) {
57 perror(fileName); 57 perror(fileName);
@@ -95,7 +95,7 @@ extern int rm_main(int argc, char **argv)
95 /* do not reports errors for non-existent files if -f, just skip them */ 95 /* do not reports errors for non-existent files if -f, just skip them */
96 } else { 96 } else {
97 if (recursiveAction(srcName, recursiveFlag, FALSE, 97 if (recursiveAction(srcName, recursiveFlag, FALSE,
98 TRUE, fileAction, dirAction) == FALSE) { 98 TRUE, fileAction, dirAction, NULL) == FALSE) {
99 exit(FALSE); 99 exit(FALSE);
100 } 100 }
101 } 101 }
diff --git a/cp_mv.c b/cp_mv.c
index 8dbc4e8f1..72b0791c2 100644
--- a/cp_mv.c
+++ b/cp_mv.c
@@ -105,7 +105,7 @@ fill_baseDest_buf(char *_buf, size_t * _buflen) {
105} 105}
106 106
107static int 107static int
108cp_mv_Action(const char *fileName, struct stat *statbuf) 108cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
109{ 109{
110 char destName[PATH_MAX + 1]; 110 char destName[PATH_MAX + 1];
111 size_t destLen; 111 size_t destLen;
@@ -165,7 +165,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf)
165} 165}
166 166
167static int 167static int
168rm_Action(const char *fileName, struct stat *statbuf) 168rm_Action(const char *fileName, struct stat *statbuf, void* junk)
169{ 169{
170 int status = TRUE; 170 int status = TRUE;
171 171
@@ -310,11 +310,11 @@ extern int cp_mv_main(int argc, char **argv)
310 mv_Action_first_time = 1; 310 mv_Action_first_time = 1;
311 if (recursiveAction(baseSrcName, 311 if (recursiveAction(baseSrcName,
312 recursiveFlag, followLinks, FALSE, 312 recursiveFlag, followLinks, FALSE,
313 cp_mv_Action, cp_mv_Action) == FALSE) goto exit_false; 313 cp_mv_Action, cp_mv_Action, NULL) == FALSE) goto exit_false;
314 if (dz_i == is_mv && 314 if (dz_i == is_mv &&
315 recursiveAction(baseSrcName, 315 recursiveAction(baseSrcName,
316 recursiveFlag, followLinks, TRUE, 316 recursiveFlag, followLinks, TRUE,
317 rm_Action, rm_Action) == FALSE) goto exit_false; 317 rm_Action, rm_Action, NULL) == FALSE) goto exit_false;
318 } 318 }
319 if (flags_memo) 319 if (flags_memo)
320 *(baseDestName + baseDestLen) = '\0'; 320 *(baseDestName + baseDestLen) = '\0';
diff --git a/find.c b/find.c
index 2c1039b53..c23ac5f46 100644
--- a/find.c
+++ b/find.c
@@ -42,7 +42,7 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
42 "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n"; 42 "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n";
43 43
44 44
45static int fileAction(const char *fileName, struct stat *statbuf) 45static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
46{ 46{
47 if (pattern == NULL) 47 if (pattern == NULL)
48 fprintf(stdout, "%s\n", fileName); 48 fprintf(stdout, "%s\n", fileName);
@@ -109,7 +109,7 @@ int find_main(int argc, char **argv)
109 } 109 }
110 110
111 if (recursiveAction(directory, TRUE, FALSE, FALSE, 111 if (recursiveAction(directory, TRUE, FALSE, FALSE,
112 fileAction, fileAction) == FALSE) { 112 fileAction, fileAction, NULL) == FALSE) {
113 exit(FALSE); 113 exit(FALSE);
114 } 114 }
115 115
diff --git a/findutils/find.c b/findutils/find.c
index 2c1039b53..c23ac5f46 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -42,7 +42,7 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
42 "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n"; 42 "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n";
43 43
44 44
45static int fileAction(const char *fileName, struct stat *statbuf) 45static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
46{ 46{
47 if (pattern == NULL) 47 if (pattern == NULL)
48 fprintf(stdout, "%s\n", fileName); 48 fprintf(stdout, "%s\n", fileName);
@@ -109,7 +109,7 @@ int find_main(int argc, char **argv)
109 } 109 }
110 110
111 if (recursiveAction(directory, TRUE, FALSE, FALSE, 111 if (recursiveAction(directory, TRUE, FALSE, FALSE,
112 fileAction, fileAction) == FALSE) { 112 fileAction, fileAction, NULL) == FALSE) {
113 exit(FALSE); 113 exit(FALSE);
114 } 114 }
115 115
diff --git a/internal.h b/internal.h
index c54480e2b..e69e62534 100644
--- a/internal.h
+++ b/internal.h
@@ -191,8 +191,9 @@ void freeChunks(void);
191int fullWrite(int fd, const char *buf, int len); 191int fullWrite(int fd, const char *buf, int len);
192int fullRead(int fd, char *buf, int len); 192int fullRead(int fd, char *buf, int len);
193int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst, 193int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
194 int (*fileAction) (const char *fileName, struct stat* statbuf), 194 int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
195 int (*dirAction) (const char *fileName, struct stat* statbuf)); 195 int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
196 void* userData);
196const char* timeString(time_t timeVal); 197const char* timeString(time_t timeVal);
197 198
198extern int createPath (const char *name, int mode); 199extern int createPath (const char *name, int mode);
@@ -227,8 +228,6 @@ extern void cmdedit_init(void);
227#if defined BB_INIT || defined BB_SYSLOGD 228#if defined BB_INIT || defined BB_SYSLOGD
228extern int device_open(char *device, int mode); 229extern int device_open(char *device, int mode);
229#endif 230#endif
230extern void whine_if_fstab_is_missing();
231
232#if defined BB_FEATURE_MOUNT_LOOP 231#if defined BB_FEATURE_MOUNT_LOOP
233extern int del_loop(const char *device); 232extern int del_loop(const char *device);
234extern int set_loop(const char *device, const char *file, int offset, int *loopro); 233extern int set_loop(const char *device, const char *file, int offset, int *loopro);
diff --git a/rm.c b/rm.c
index 41afedaf9..683bf8bdf 100644
--- a/rm.c
+++ b/rm.c
@@ -42,7 +42,7 @@ static int forceFlag = FALSE;
42static const char *srcName; 42static const char *srcName;
43 43
44 44
45static int fileAction(const char *fileName, struct stat *statbuf) 45static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
46{ 46{
47 if (unlink(fileName) < 0) { 47 if (unlink(fileName) < 0) {
48 perror(fileName); 48 perror(fileName);
@@ -51,7 +51,7 @@ static int fileAction(const char *fileName, struct stat *statbuf)
51 return (TRUE); 51 return (TRUE);
52} 52}
53 53
54static int dirAction(const char *fileName, struct stat *statbuf) 54static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
55{ 55{
56 if (rmdir(fileName) < 0) { 56 if (rmdir(fileName) < 0) {
57 perror(fileName); 57 perror(fileName);
@@ -95,7 +95,7 @@ extern int rm_main(int argc, char **argv)
95 /* do not reports errors for non-existent files if -f, just skip them */ 95 /* do not reports errors for non-existent files if -f, just skip them */
96 } else { 96 } else {
97 if (recursiveAction(srcName, recursiveFlag, FALSE, 97 if (recursiveAction(srcName, recursiveFlag, FALSE,
98 TRUE, fileAction, dirAction) == FALSE) { 98 TRUE, fileAction, dirAction, NULL) == FALSE) {
99 exit(FALSE); 99 exit(FALSE);
100 } 100 }
101 } 101 }
diff --git a/swaponoff.c b/swaponoff.c
index bc096ea95..dca401966 100644
--- a/swaponoff.c
+++ b/swaponoff.c
@@ -108,7 +108,12 @@ extern int swap_on_off_main(int argc, char **argv)
108 while (*++(*argv)) 108 while (*++(*argv))
109 switch (**argv) { 109 switch (**argv) {
110 case 'a': 110 case 'a':
111 whine_if_fstab_is_missing(); 111 {
112 struct stat statBuf;
113
114 if (stat("/etc/fstab", &statBuf) < 0)
115 fatalError("/etc/fstab file missing\n");
116 }
112 do_em_all(); 117 do_em_all();
113 break; 118 break;
114 default: 119 default:
diff --git a/tar.c b/tar.c
index 37a28a3d0..af0e4f8ef 100644
--- a/tar.c
+++ b/tar.c
@@ -228,6 +228,7 @@ extern int tar_main(int argc, char **argv)
228 228
229 case 'O': 229 case 'O':
230 tostdoutFlag = TRUE; 230 tostdoutFlag = TRUE;
231 tarName = "-";
231 break; 232 break;
232 233
233 case '-': 234 case '-':
@@ -439,7 +440,7 @@ static long getOctal(const char *cp, int size)
439 440
440/* Parse the tar header and fill in the nice struct with the details */ 441/* Parse the tar header and fill in the nice struct with the details */
441static int 442static int
442parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 443readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
443{ 444{
444 int i; 445 int i;
445 long chksum, sum; 446 long chksum, sum;
@@ -502,7 +503,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
502 while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) { 503 while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
503 504
504 /* First, try to read the header */ 505 /* First, try to read the header */
505 if ( parseTarHeader(&rawHeader, &header) == FALSE ) { 506 if ( readTarHeader(&rawHeader, &header) == FALSE ) {
506 close( tarFd); 507 close( tarFd);
507 if ( *(header.name) == '\0' ) { 508 if ( *(header.name) == '\0' ) {
508 goto endgame; 509 goto endgame;
@@ -661,25 +662,80 @@ static int putOctal (char *cp, int len, long value)
661 return TRUE; 662 return TRUE;
662} 663}
663 664
664static int fileAction(const char *fileName, struct stat *statbuf) 665/* Write out a tar header for the specified file */
666static int
667writeTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
665{ 668{
666 fprintf(stdout, "%s\n", fileName); 669 int i;
670 long chksum, sum;
671 unsigned char *s = (unsigned char *)rawHeader;
672
673 struct TarHeader header;
674
675 strcpy(header.name, fileName);
676 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 0777);
677 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
678 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
679 putOctal(header.size, sizeof(header.size), statbuf->st_size);
680 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
681
682 if (S_ISLNK(statbuf.st_mode)) {
683 header.type = LNKTYPE;
684 // Handle SYMTYPE
685 } else if (S_ISDIR(statbuf.st_mode)) {
686 header.type = DIRTYPE;
687 } else if (S_ISCHR(statbuf.st_mode)) {
688 header.type = CHRTYPE;
689 } else if (S_ISBLK(statbuf.st_mode)) {
690 header.type = BLKTYPE;
691 } else if (S_ISFIFO(statbuf.st_mode)) {
692 header.type = FIFOTYPE;
693 } else if (S_ISSOCK(statbuf.st_mode)) {
694 header.type = S_ISSOCK;
695 } else if (S_ISLNK(statbuf.st_mode)) {
696 header.type = LNKTYPE;
697 } else if (S_ISLNK(statbuf.st_mode)) {
698 header.type = REGTYPE;
699 }
700#if 0
701 header->linkname = rawHeader->linkname;
702 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor));
703 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor));
704
705 /* Write out the checksum */
706 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
707#endif
708
709 return ( TRUE);
710}
711
712
713static int fileAction(const char *fileName, struct stat *statbuf, void* userData)
714{
715 int *tarFd=(int*)userData;
716 dprintf(*tarFd, "%s\n", fileName);
667 return (TRUE); 717 return (TRUE);
668} 718}
669 719
670static int writeTarFile(const char* tarName, int extractFlag, int listFlag, 720static int writeTarFile(const char* tarName, int extractFlag, int listFlag,
671 int tostdoutFlag, int verboseFlag, int argc, char **argv) 721 int tostdoutFlag, int verboseFlag, int argc, char **argv)
672{ 722{
673 int tarFd=0; 723 int tarFd=-1;
674 //int errorFlag=FALSE; 724 //int errorFlag=FALSE;
675 //TarHeader rawHeader; 725 //TarHeader rawHeader;
676 //TarInfo header; 726 //TarInfo header;
677 //int alreadyWarned=FALSE; 727 //int alreadyWarned=FALSE;
678 char *directory = ".";
679 //int skipFileFlag=FALSE; 728 //int skipFileFlag=FALSE;
729 struct stat tarballStat;
730 dev_t tarDev = 0;
731 ino_t tarInode = 0;
732
733 /* Make sure there is at least one file to tar up. */
734 if (argc <= 0)
735 fatalError("tar: Cowardly refusing to create an empty archive\n");
680 736
681 /* Open the tar file for writing. */ 737 /* Open the tar file for writing. */
682 if (!strcmp(tarName, "-")) 738 if (tostdoutFlag == TRUE)
683 tarFd = fileno(stdout); 739 tarFd = fileno(stdout);
684 else 740 else
685 tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); 741 tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -687,19 +743,25 @@ static int writeTarFile(const char* tarName, int extractFlag, int listFlag,
687 errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno)); 743 errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno));
688 return ( FALSE); 744 return ( FALSE);
689 } 745 }
746 /* Store the device and inode of the tarball, so we can be sure
747 * not to try and include it into itself.... */
748 if (fstat(tarFd, &tarballStat) < 0)
749 fatalError(io_error, tarName, strerror(errno));
750 tarDev = tarballStat.st_dev;
751 tarInode = tarballStat.st_ino;
690 752
691 /* Set the umask for this process so it doesn't 753 /* Set the umask for this process so it doesn't
692 * screw up permission setting for us later. */ 754 * screw up permission setting for us later. */
693 umask(0); 755 umask(0);
694 756
695 /* Read the directory/files and iterate over them one at a time */ 757 /* Read the directory/files and iterate over them one at a time */
696 if (recursiveAction(directory, TRUE, FALSE, FALSE, 758 while (argc-- > 0) {
697 fileAction, fileAction) == FALSE) { 759 if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
698 exit(FALSE); 760 fileAction, fileAction, (void*) &tarFd) == FALSE) {
761 exit(FALSE);
762 }
699 } 763 }
700 764
701
702 // TODO: DO STUFF HERE
703 close(tarFd); 765 close(tarFd);
704 return( TRUE); 766 return( TRUE);
705} 767}
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index bc096ea95..dca401966 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -108,7 +108,12 @@ extern int swap_on_off_main(int argc, char **argv)
108 while (*++(*argv)) 108 while (*++(*argv))
109 switch (**argv) { 109 switch (**argv) {
110 case 'a': 110 case 'a':
111 whine_if_fstab_is_missing(); 111 {
112 struct stat statBuf;
113
114 if (stat("/etc/fstab", &statBuf) < 0)
115 fatalError("/etc/fstab file missing\n");
116 }
112 do_em_all(); 117 do_em_all();
113 break; 118 break;
114 default: 119 default:
diff --git a/utility.c b/utility.c
index a582f708c..0d4799f2d 100644
--- a/utility.c
+++ b/utility.c
@@ -542,9 +542,12 @@ int fullRead(int fd, char *buf, int len)
542int recursiveAction(const char *fileName, 542int recursiveAction(const char *fileName,
543 int recurse, int followLinks, int depthFirst, 543 int recurse, int followLinks, int depthFirst,
544 int (*fileAction) (const char *fileName, 544 int (*fileAction) (const char *fileName,
545 struct stat * statbuf), 545 struct stat * statbuf,
546 void* userData),
546 int (*dirAction) (const char *fileName, 547 int (*dirAction) (const char *fileName,
547 struct stat * statbuf)) 548 struct stat * statbuf,
549 void* userData),
550 void* userData)
548{ 551{
549 int status; 552 int status;
550 struct stat statbuf; 553 struct stat statbuf;
@@ -569,13 +572,13 @@ int recursiveAction(const char *fileName,
569 if (fileAction == NULL) 572 if (fileAction == NULL)
570 return TRUE; 573 return TRUE;
571 else 574 else
572 return fileAction(fileName, &statbuf); 575 return fileAction(fileName, &statbuf, userData);
573 } 576 }
574 577
575 if (recurse == FALSE) { 578 if (recurse == FALSE) {
576 if (S_ISDIR(statbuf.st_mode)) { 579 if (S_ISDIR(statbuf.st_mode)) {
577 if (dirAction != NULL) 580 if (dirAction != NULL)
578 return (dirAction(fileName, &statbuf)); 581 return (dirAction(fileName, &statbuf, userData));
579 else 582 else
580 return TRUE; 583 return TRUE;
581 } 584 }
@@ -590,7 +593,7 @@ int recursiveAction(const char *fileName,
590 return FALSE; 593 return FALSE;
591 } 594 }
592 if (dirAction != NULL && depthFirst == FALSE) { 595 if (dirAction != NULL && depthFirst == FALSE) {
593 status = dirAction(fileName, &statbuf); 596 status = dirAction(fileName, &statbuf, userData);
594 if (status == FALSE) { 597 if (status == FALSE) {
595 perror(fileName); 598 perror(fileName);
596 return FALSE; 599 return FALSE;
@@ -610,7 +613,7 @@ int recursiveAction(const char *fileName,
610 sprintf(nextFile, "%s/%s", fileName, next->d_name); 613 sprintf(nextFile, "%s/%s", fileName, next->d_name);
611 status = 614 status =
612 recursiveAction(nextFile, TRUE, followLinks, depthFirst, 615 recursiveAction(nextFile, TRUE, followLinks, depthFirst,
613 fileAction, dirAction); 616 fileAction, dirAction, userData);
614 if (status < 0) { 617 if (status < 0) {
615 closedir(dir); 618 closedir(dir);
616 return FALSE; 619 return FALSE;
@@ -622,7 +625,7 @@ int recursiveAction(const char *fileName,
622 return FALSE; 625 return FALSE;
623 } 626 }
624 if (dirAction != NULL && depthFirst == TRUE) { 627 if (dirAction != NULL && depthFirst == TRUE) {
625 status = dirAction(fileName, &statbuf); 628 status = dirAction(fileName, &statbuf, userData);
626 if (status == FALSE) { 629 if (status == FALSE) {
627 perror(fileName); 630 perror(fileName);
628 return FALSE; 631 return FALSE;
@@ -632,7 +635,7 @@ int recursiveAction(const char *fileName,
632 if (fileAction == NULL) 635 if (fileAction == NULL)
633 return TRUE; 636 return TRUE;
634 else 637 else
635 return fileAction(fileName, &statbuf); 638 return fileAction(fileName, &statbuf, userData);
636 } 639 }
637 return TRUE; 640 return TRUE;
638} 641}
@@ -1514,19 +1517,6 @@ extern int find_real_root_device_name(char* name)
1514#endif 1517#endif
1515 1518
1516 1519
1517#if defined BB_MTAB
1518#define whine_if_fstab_is_missing() {}
1519#else
1520extern void whine_if_fstab_is_missing()
1521{
1522 struct stat statBuf;
1523
1524 if (stat("/etc/fstab", &statBuf) < 0)
1525 fprintf(stderr,
1526 "/etc/fstab file missing -- install one to name /dev/root.\n\n");
1527}
1528#endif
1529
1530/* END CODE */ 1520/* END CODE */
1531/* 1521/*
1532Local Variables: 1522Local Variables: