diff options
-rw-r--r-- | applets/usage.c | 4 | ||||
-rw-r--r-- | archival/tar.c | 94 | ||||
-rw-r--r-- | docs/busybox.pod | 4 | ||||
-rw-r--r-- | docs/busybox.sgml | 8 | ||||
-rw-r--r-- | mount.c | 88 | ||||
-rw-r--r-- | tar.c | 94 | ||||
-rw-r--r-- | usage.c | 4 | ||||
-rw-r--r-- | util-linux/mount.c | 88 | ||||
-rw-r--r-- | utility.c | 8 |
9 files changed, 206 insertions, 186 deletions
diff --git a/applets/usage.c b/applets/usage.c index 1e2eb64cc..6c3f59797 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
@@ -1053,7 +1053,7 @@ const char tar_usage[] = | |||
1053 | "tar -[xtvO] " | 1053 | "tar -[xtvO] " |
1054 | #endif | 1054 | #endif |
1055 | #if defined BB_FEATURE_TAR_EXCLUDE | 1055 | #if defined BB_FEATURE_TAR_EXCLUDE |
1056 | "[-X File(s)] " | 1056 | "[--exclude File] " |
1057 | #endif | 1057 | #endif |
1058 | "[-f tarFile] [FILE(s)] ...\n" | 1058 | "[-f tarFile] [FILE(s)] ...\n" |
1059 | #ifndef BB_FEATURE_TRIVIAL_HELP | 1059 | #ifndef BB_FEATURE_TRIVIAL_HELP |
@@ -1069,7 +1069,7 @@ const char tar_usage[] = | |||
1069 | "\tf\t\tname of tarfile or \"-\" for stdin\n" | 1069 | "\tf\t\tname of tarfile or \"-\" for stdin\n" |
1070 | "\tO\t\textract to stdout\n" | 1070 | "\tO\t\textract to stdout\n" |
1071 | #if defined BB_FEATURE_TAR_EXCLUDE | 1071 | #if defined BB_FEATURE_TAR_EXCLUDE |
1072 | "\tX\t\tfile(s) to exclude\n" | 1072 | "\texclude\t\tfile to exclude\n" |
1073 | #endif | 1073 | #endif |
1074 | "\nInformative output:\n" | 1074 | "\nInformative output:\n" |
1075 | "\tv\t\tverbosely list files processed\n" | 1075 | "\tv\t\tverbosely list files processed\n" |
diff --git a/archival/tar.c b/archival/tar.c index 3227ce5bd..cab53aa10 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -148,85 +148,65 @@ extern int tar_main(int argc, char **argv) | |||
148 | int createFlag = FALSE; | 148 | int createFlag = FALSE; |
149 | int verboseFlag = FALSE; | 149 | int verboseFlag = FALSE; |
150 | int tostdoutFlag = FALSE; | 150 | int tostdoutFlag = FALSE; |
151 | int stopIt; | 151 | int opt; |
152 | 152 | ||
153 | if (argc <= 1) | 153 | if (argc <= 1) |
154 | usage(tar_usage); | 154 | usage(tar_usage); |
155 | 155 | ||
156 | /* Parse any options */ | 156 | /* do normal option parsing */ |
157 | while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { | 157 | while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) { |
158 | stopIt=FALSE; | 158 | switch (opt) { |
159 | while (stopIt==FALSE && *argv && **argv) { | 159 | case 'c': |
160 | switch (**argv) { | 160 | if (extractFlag == TRUE || listFlag == TRUE) |
161 | case 'f': | ||
162 | if (--argc == 0) { | ||
163 | fatalError( "Option requires an argument: No file specified\n"); | ||
164 | } | ||
165 | if (*tarName != '-') | ||
166 | fatalError( "Only one 'f' option allowed\n"); | ||
167 | tarName = *(++argv); | ||
168 | if (tarName == NULL) | ||
169 | fatalError( "Option requires an argument: No file specified\n"); | ||
170 | if (!strcmp(tarName, "-") && createFlag == TRUE) | ||
171 | tostdoutFlag = TRUE; | ||
172 | stopIt=TRUE; | ||
173 | break; | ||
174 | |||
175 | case 't': | ||
176 | if (extractFlag == TRUE || createFlag == TRUE) | ||
177 | goto flagError; | 161 | goto flagError; |
178 | listFlag = TRUE; | 162 | createFlag = TRUE; |
179 | break; | 163 | break; |
180 | |||
181 | case 'x': | 164 | case 'x': |
182 | if (listFlag == TRUE || createFlag == TRUE) | 165 | if (listFlag == TRUE || createFlag == TRUE) |
183 | goto flagError; | 166 | goto flagError; |
184 | extractFlag = TRUE; | 167 | extractFlag = TRUE; |
185 | break; | 168 | break; |
186 | case 'c': | 169 | case 't': |
187 | if (extractFlag == TRUE || listFlag == TRUE) | 170 | if (extractFlag == TRUE || createFlag == TRUE) |
188 | goto flagError; | 171 | goto flagError; |
189 | createFlag = TRUE; | 172 | listFlag = TRUE; |
190 | break; | 173 | break; |
191 | |||
192 | case 'v': | 174 | case 'v': |
193 | verboseFlag = TRUE; | 175 | verboseFlag = TRUE; |
194 | break; | 176 | break; |
195 | |||
196 | case 'O': | 177 | case 'O': |
197 | tostdoutFlag = TRUE; | 178 | tostdoutFlag = TRUE; |
198 | tarName = "-"; | 179 | tarName = "-"; |
180 | break; | ||
181 | case 'f': | ||
182 | if (*tarName != '-') | ||
183 | fatalError( "Only one 'f' option allowed\n"); | ||
184 | tarName = optarg; | ||
185 | if (!strcmp(tarName, "-") && createFlag == TRUE) | ||
186 | tostdoutFlag = TRUE; | ||
199 | break; | 187 | break; |
200 | case '-': | 188 | case '-': |
201 | #if defined BB_FEATURE_TAR_EXCLUDE | 189 | #if defined BB_FEATURE_TAR_EXCLUDE |
202 | if (strcmp(*argv, "-exclude")==0) { | 190 | if (strcmp(optarg, "exclude")==0) { |
203 | if (--argc == 0) { | 191 | if (argv[optind]==NULL) |
204 | fatalError( "Option requires an argument: No file specified\n"); | 192 | fatalError( "option `--exclude' requires an argument\n"); |
205 | } | ||
206 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); | 193 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); |
207 | excludeList[excludeListSize] = *(++argv); | 194 | excludeList[excludeListSize] = argv[optind]; |
208 | /* Remove leading "/"s */ | 195 | /* Remove leading "/"s */ |
209 | if (*excludeList[excludeListSize] =='/') { | 196 | if (*excludeList[excludeListSize] =='/') { |
210 | excludeList[excludeListSize] = (excludeList[excludeListSize])+1; | 197 | excludeList[excludeListSize] = (excludeList[excludeListSize])+1; |
211 | } | 198 | } |
212 | if (excludeList[excludeListSize++] == NULL) | ||
213 | fatalError( "Option requires an argument: No file specified\n"); | ||
214 | /* Tack a NULL onto the end of the list */ | 199 | /* Tack a NULL onto the end of the list */ |
215 | excludeList[excludeListSize] = NULL; | 200 | excludeList[excludeListSize] = NULL; |
216 | stopIt=TRUE; | 201 | optind++; |
217 | break; | 202 | break; |
218 | } | 203 | } |
219 | #endif | 204 | #endif |
220 | if (strcmp(*argv, "-help")==0) { | 205 | fatalError( "Unknown tar flag '%s'\n" |
221 | usage(tar_usage); | 206 | "Try `tar --help' for more information\n", optarg); |
222 | } | ||
223 | break; | ||
224 | |||
225 | default: | 207 | default: |
226 | fatalError( "Unknown tar flag '%c'\n" | 208 | fatalError( "Unknown tar flag '%c'\n" |
227 | "Try `tar --help' for more information\n", **argv); | 209 | "Try `tar --help' for more information\n", **argv); |
228 | } | ||
229 | ++(*argv); | ||
230 | } | 210 | } |
231 | } | 211 | } |
232 | 212 | ||
@@ -238,7 +218,7 @@ extern int tar_main(int argc, char **argv) | |||
238 | #ifndef BB_FEATURE_TAR_CREATE | 218 | #ifndef BB_FEATURE_TAR_CREATE |
239 | fatalError( "This version of tar was not compiled with tar creation support.\n"); | 219 | fatalError( "This version of tar was not compiled with tar creation support.\n"); |
240 | #else | 220 | #else |
241 | exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); | 221 | exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList)); |
242 | #endif | 222 | #endif |
243 | } | 223 | } |
244 | if (listFlag == TRUE || extractFlag == TRUE) { | 224 | if (listFlag == TRUE || extractFlag == TRUE) { |
@@ -603,18 +583,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
603 | } | 583 | } |
604 | } | 584 | } |
605 | /* List contents if we are supposed to do that */ | 585 | /* List contents if we are supposed to do that */ |
606 | if (verboseFlag == TRUE || listFlag == TRUE) { | 586 | if (verboseFlag == TRUE && listFlag != TRUE) { |
607 | /* Now the normal listing */ | 587 | /* Now the normal listing */ |
608 | printf("%s", header.name); | 588 | FILE *vbFd = stdout; |
589 | if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr | ||
590 | vbFd = stderr; | ||
591 | fprintf(vbFd, "%s\n", header.name); | ||
609 | } | 592 | } |
593 | |||
610 | if (verboseFlag == TRUE && listFlag == TRUE) { | 594 | if (verboseFlag == TRUE && listFlag == TRUE) { |
611 | /* If this is a link, say so */ | 595 | printf("%s", header.name); |
612 | if (header.type==LNKTYPE) | 596 | if (header.type==LNKTYPE) /* If this is a link, say so */ |
613 | printf(" link to %s", header.linkname); | 597 | printf(" link to %s", header.linkname); |
614 | else if (header.type==SYMTYPE) | 598 | else if (header.type==SYMTYPE) |
615 | printf(" -> %s", header.linkname); | 599 | printf(" -> %s", header.linkname); |
616 | } | ||
617 | if (verboseFlag == TRUE || listFlag == TRUE) { | ||
618 | printf("\n"); | 600 | printf("\n"); |
619 | } | 601 | } |
620 | 602 | ||
@@ -745,7 +727,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
745 | #endif | 727 | #endif |
746 | const unsigned char *cp = (const unsigned char *) &header; | 728 | const unsigned char *cp = (const unsigned char *) &header; |
747 | ssize_t size = sizeof(struct TarHeader); | 729 | ssize_t size = sizeof(struct TarHeader); |
748 | 730 | ||
749 | memset( &header, 0, size); | 731 | memset( &header, 0, size); |
750 | 732 | ||
751 | if (*fileName=='/') { | 733 | if (*fileName=='/') { |
@@ -848,8 +830,12 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
848 | write(tbInfo->tarFd, "\0", 1); | 830 | write(tbInfo->tarFd, "\0", 1); |
849 | } | 831 | } |
850 | /* Now do the verbose thing (or not) */ | 832 | /* Now do the verbose thing (or not) */ |
851 | if (tbInfo->verboseFlag==TRUE) | 833 | if (tbInfo->verboseFlag==TRUE) { |
852 | fprintf(stdout, "%s\n", header.name); | 834 | FILE *vbFd = stdout; |
835 | if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr | ||
836 | vbFd = stderr; | ||
837 | fprintf(vbFd, "%s\n", header.name); | ||
838 | } | ||
853 | 839 | ||
854 | return ( TRUE); | 840 | return ( TRUE); |
855 | } | 841 | } |
diff --git a/docs/busybox.pod b/docs/busybox.pod index d42985306..cdbe3e0f0 100644 --- a/docs/busybox.pod +++ b/docs/busybox.pod | |||
@@ -1634,7 +1634,7 @@ File selection: | |||
1634 | 1634 | ||
1635 | f name of tarfile or "-" for stdin | 1635 | f name of tarfile or "-" for stdin |
1636 | O extract to stdout | 1636 | O extract to stdout |
1637 | --exclude file to exclude | 1637 | exclude file to exclude |
1638 | 1638 | ||
1639 | Informative output: | 1639 | Informative output: |
1640 | 1640 | ||
@@ -2044,4 +2044,4 @@ Enrique Zanardi <ezanardi@ull.es> | |||
2044 | 2044 | ||
2045 | =cut | 2045 | =cut |
2046 | 2046 | ||
2047 | # $Id: busybox.pod,v 1.59 2000/07/21 21:32:12 andersen Exp $ | 2047 | # $Id: busybox.pod,v 1.60 2000/08/02 18:48:25 andersen Exp $ |
diff --git a/docs/busybox.sgml b/docs/busybox.sgml index f65abda69..560bd61f6 100644 --- a/docs/busybox.sgml +++ b/docs/busybox.sgml | |||
@@ -2901,10 +2901,10 @@ | |||
2901 | 2901 | ||
2902 | <para> | 2902 | <para> |
2903 | <screen> | 2903 | <screen> |
2904 | f FILE Use FILE for tarfile (or stdin if '-') | 2904 | f FILE Use FILE for tarfile (or stdin if '-') |
2905 | O Extract to stdout | 2905 | O Extract to stdout |
2906 | --exclude FILE Exclude FILE | 2906 | exclude FILE File to exclude |
2907 | v List files processed | 2907 | v List files processed |
2908 | </screen> | 2908 | </screen> |
2909 | </para> | 2909 | </para> |
2910 | 2910 | ||
@@ -34,6 +34,13 @@ | |||
34 | * | 34 | * |
35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's | 35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's |
36 | * mount to add loop support. | 36 | * mount to add loop support. |
37 | * | ||
38 | * 2000-04-30 Dave Cinege <dcinege@psychosis.com> | ||
39 | * Rewrote fstab while loop and lower mount section. Can now do | ||
40 | * single mounts from fstab. Can override fstab options for single | ||
41 | * mount. Common mount_one call for single mounts and 'all'. Fixed | ||
42 | * mtab updating and stale entries. Removed 'remount' default. | ||
43 | * | ||
37 | */ | 44 | */ |
38 | 45 | ||
39 | #include "internal.h" | 46 | #include "internal.h" |
@@ -147,6 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
147 | 154 | ||
148 | #if defined BB_MTAB | 155 | #if defined BB_MTAB |
149 | if (useMtab == TRUE) { | 156 | if (useMtab == TRUE) { |
157 | erase_mtab(specialfile); // Clean any stale entries | ||
150 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); | 158 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); |
151 | } | 159 | } |
152 | #endif | 160 | #endif |
@@ -318,6 +326,8 @@ extern int mount_main(int argc, char **argv) | |||
318 | int fakeIt = FALSE; | 326 | int fakeIt = FALSE; |
319 | int useMtab = TRUE; | 327 | int useMtab = TRUE; |
320 | int i; | 328 | int i; |
329 | int rc = FALSE; | ||
330 | int fstabmount = FALSE; | ||
321 | 331 | ||
322 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 332 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
323 | if (argc == 1) { | 333 | if (argc == 1) { |
@@ -435,56 +445,70 @@ extern int mount_main(int argc, char **argv) | |||
435 | argv++; | 445 | argv++; |
436 | } | 446 | } |
437 | 447 | ||
438 | if (all == TRUE) { | 448 | if (all == TRUE || directory == NULL) { |
439 | struct mntent *m; | 449 | struct mntent *m; |
440 | FILE *f = setmntent("/etc/fstab", "r"); | 450 | FILE *f = setmntent("/etc/fstab", "r"); |
451 | fstabmount = TRUE; | ||
441 | 452 | ||
442 | if (f == NULL) | 453 | if (f == NULL) |
443 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); | 454 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); |
444 | 455 | ||
445 | while ((m = getmntent(f)) != NULL) { | 456 | while ((m = getmntent(f)) != NULL) { |
446 | // If the filesystem isn't noauto, | 457 | if (all == FALSE && directory == NULL && ( |
447 | // and isn't swap or nfs, then mount it | 458 | (strcmp(device, m->mnt_fsname) != 0) && |
448 | if ((!strstr(m->mnt_opts, "noauto")) && | 459 | (strcmp(device, m->mnt_dir) != 0) ) ) { |
449 | (!strstr(m->mnt_type, "swap")) && | 460 | continue; |
450 | (!strstr(m->mnt_type, "nfs"))) { | 461 | } |
462 | |||
463 | if (all == TRUE && ( // If we're mounting 'all' | ||
464 | (strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto, | ||
465 | (strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it | ||
466 | (strstr(m->mnt_type, "nfs")) ) ) { | ||
467 | continue; | ||
468 | } | ||
469 | |||
470 | if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags | ||
451 | flags = 0; | 471 | flags = 0; |
452 | *string_flags = '\0'; | 472 | *string_flags = '\0'; |
453 | parse_mount_options(m->mnt_opts, &flags, string_flags); | 473 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
454 | if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
455 | flags, string_flags, useMtab, fakeIt, | ||
456 | extra_opts, FALSE)==FALSE) | ||
457 | { | ||
458 | /* Try again, but this time try a remount */ | ||
459 | mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
460 | flags|MS_REMOUNT, string_flags, useMtab, fakeIt, | ||
461 | extra_opts, TRUE); | ||
462 | } | ||
463 | } | 474 | } |
464 | } | 475 | |
465 | endmntent(f); | 476 | device = strdup(m->mnt_fsname); |
466 | } else { | 477 | directory = strdup(m->mnt_dir); |
467 | if (device && directory) { | 478 | filesystemType = strdup(m->mnt_type); |
479 | singlemount: | ||
468 | #ifdef BB_NFSMOUNT | 480 | #ifdef BB_NFSMOUNT |
469 | if (strchr(device, ':') != NULL) | 481 | if (strchr(device, ':') != NULL) |
470 | filesystemType = "nfs"; | 482 | filesystemType = "nfs"; |
471 | if (strcmp(filesystemType, "nfs") == 0) { | 483 | if (strcmp(filesystemType, "nfs") == 0) { |
472 | int ret; | 484 | rc = nfsmount (device, directory, &flags, &extra_opts, &string_flags, 1) |
473 | ret = nfsmount (device, directory, &flags, | 485 | if ( rc != 0) { |
474 | &extra_opts, &string_flags, 1); | 486 | fatalError("nfsmount failed: %s\n", strerror(errno)); |
475 | if (ret != 0) | 487 | rc = FALSE; |
476 | fatalError("nfsmount failed: %s\n", strerror(errno)); | 488 | } |
477 | } | 489 | } else |
478 | #endif | 490 | #endif |
479 | exit(mount_one(device, directory, filesystemType, | 491 | rc = mount_one(device, directory, filesystemType, flags, |
480 | flags, string_flags, useMtab, fakeIt, | 492 | string_flags, useMtab, fakeIt, extra_opts, TRUE); |
481 | extra_opts, TRUE)); | 493 | |
482 | } else { | 494 | if (all == FALSE) |
483 | goto goodbye; | 495 | break; |
496 | |||
497 | rc = TRUE; // Always return 0 for 'all' | ||
484 | } | 498 | } |
499 | if (fstabmount == TRUE) | ||
500 | endmntent(f); | ||
501 | |||
502 | if (all == FALSE && fstabmount == TRUE && directory == NULL) | ||
503 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); | ||
504 | |||
505 | exit(rc); | ||
485 | } | 506 | } |
486 | exit(TRUE); | 507 | |
508 | goto singlemount; | ||
509 | |||
510 | exit(FALSE); | ||
487 | 511 | ||
488 | goodbye: | 512 | goodbye: |
489 | usage(mount_usage); | 513 | usage(mount_usage); |
490 | } | 514 | } |
@@ -148,85 +148,65 @@ extern int tar_main(int argc, char **argv) | |||
148 | int createFlag = FALSE; | 148 | int createFlag = FALSE; |
149 | int verboseFlag = FALSE; | 149 | int verboseFlag = FALSE; |
150 | int tostdoutFlag = FALSE; | 150 | int tostdoutFlag = FALSE; |
151 | int stopIt; | 151 | int opt; |
152 | 152 | ||
153 | if (argc <= 1) | 153 | if (argc <= 1) |
154 | usage(tar_usage); | 154 | usage(tar_usage); |
155 | 155 | ||
156 | /* Parse any options */ | 156 | /* do normal option parsing */ |
157 | while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { | 157 | while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) { |
158 | stopIt=FALSE; | 158 | switch (opt) { |
159 | while (stopIt==FALSE && *argv && **argv) { | 159 | case 'c': |
160 | switch (**argv) { | 160 | if (extractFlag == TRUE || listFlag == TRUE) |
161 | case 'f': | ||
162 | if (--argc == 0) { | ||
163 | fatalError( "Option requires an argument: No file specified\n"); | ||
164 | } | ||
165 | if (*tarName != '-') | ||
166 | fatalError( "Only one 'f' option allowed\n"); | ||
167 | tarName = *(++argv); | ||
168 | if (tarName == NULL) | ||
169 | fatalError( "Option requires an argument: No file specified\n"); | ||
170 | if (!strcmp(tarName, "-") && createFlag == TRUE) | ||
171 | tostdoutFlag = TRUE; | ||
172 | stopIt=TRUE; | ||
173 | break; | ||
174 | |||
175 | case 't': | ||
176 | if (extractFlag == TRUE || createFlag == TRUE) | ||
177 | goto flagError; | 161 | goto flagError; |
178 | listFlag = TRUE; | 162 | createFlag = TRUE; |
179 | break; | 163 | break; |
180 | |||
181 | case 'x': | 164 | case 'x': |
182 | if (listFlag == TRUE || createFlag == TRUE) | 165 | if (listFlag == TRUE || createFlag == TRUE) |
183 | goto flagError; | 166 | goto flagError; |
184 | extractFlag = TRUE; | 167 | extractFlag = TRUE; |
185 | break; | 168 | break; |
186 | case 'c': | 169 | case 't': |
187 | if (extractFlag == TRUE || listFlag == TRUE) | 170 | if (extractFlag == TRUE || createFlag == TRUE) |
188 | goto flagError; | 171 | goto flagError; |
189 | createFlag = TRUE; | 172 | listFlag = TRUE; |
190 | break; | 173 | break; |
191 | |||
192 | case 'v': | 174 | case 'v': |
193 | verboseFlag = TRUE; | 175 | verboseFlag = TRUE; |
194 | break; | 176 | break; |
195 | |||
196 | case 'O': | 177 | case 'O': |
197 | tostdoutFlag = TRUE; | 178 | tostdoutFlag = TRUE; |
198 | tarName = "-"; | 179 | tarName = "-"; |
180 | break; | ||
181 | case 'f': | ||
182 | if (*tarName != '-') | ||
183 | fatalError( "Only one 'f' option allowed\n"); | ||
184 | tarName = optarg; | ||
185 | if (!strcmp(tarName, "-") && createFlag == TRUE) | ||
186 | tostdoutFlag = TRUE; | ||
199 | break; | 187 | break; |
200 | case '-': | 188 | case '-': |
201 | #if defined BB_FEATURE_TAR_EXCLUDE | 189 | #if defined BB_FEATURE_TAR_EXCLUDE |
202 | if (strcmp(*argv, "-exclude")==0) { | 190 | if (strcmp(optarg, "exclude")==0) { |
203 | if (--argc == 0) { | 191 | if (argv[optind]==NULL) |
204 | fatalError( "Option requires an argument: No file specified\n"); | 192 | fatalError( "option `--exclude' requires an argument\n"); |
205 | } | ||
206 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); | 193 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); |
207 | excludeList[excludeListSize] = *(++argv); | 194 | excludeList[excludeListSize] = argv[optind]; |
208 | /* Remove leading "/"s */ | 195 | /* Remove leading "/"s */ |
209 | if (*excludeList[excludeListSize] =='/') { | 196 | if (*excludeList[excludeListSize] =='/') { |
210 | excludeList[excludeListSize] = (excludeList[excludeListSize])+1; | 197 | excludeList[excludeListSize] = (excludeList[excludeListSize])+1; |
211 | } | 198 | } |
212 | if (excludeList[excludeListSize++] == NULL) | ||
213 | fatalError( "Option requires an argument: No file specified\n"); | ||
214 | /* Tack a NULL onto the end of the list */ | 199 | /* Tack a NULL onto the end of the list */ |
215 | excludeList[excludeListSize] = NULL; | 200 | excludeList[excludeListSize] = NULL; |
216 | stopIt=TRUE; | 201 | optind++; |
217 | break; | 202 | break; |
218 | } | 203 | } |
219 | #endif | 204 | #endif |
220 | if (strcmp(*argv, "-help")==0) { | 205 | fatalError( "Unknown tar flag '%s'\n" |
221 | usage(tar_usage); | 206 | "Try `tar --help' for more information\n", optarg); |
222 | } | ||
223 | break; | ||
224 | |||
225 | default: | 207 | default: |
226 | fatalError( "Unknown tar flag '%c'\n" | 208 | fatalError( "Unknown tar flag '%c'\n" |
227 | "Try `tar --help' for more information\n", **argv); | 209 | "Try `tar --help' for more information\n", **argv); |
228 | } | ||
229 | ++(*argv); | ||
230 | } | 210 | } |
231 | } | 211 | } |
232 | 212 | ||
@@ -238,7 +218,7 @@ extern int tar_main(int argc, char **argv) | |||
238 | #ifndef BB_FEATURE_TAR_CREATE | 218 | #ifndef BB_FEATURE_TAR_CREATE |
239 | fatalError( "This version of tar was not compiled with tar creation support.\n"); | 219 | fatalError( "This version of tar was not compiled with tar creation support.\n"); |
240 | #else | 220 | #else |
241 | exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); | 221 | exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList)); |
242 | #endif | 222 | #endif |
243 | } | 223 | } |
244 | if (listFlag == TRUE || extractFlag == TRUE) { | 224 | if (listFlag == TRUE || extractFlag == TRUE) { |
@@ -603,18 +583,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
603 | } | 583 | } |
604 | } | 584 | } |
605 | /* List contents if we are supposed to do that */ | 585 | /* List contents if we are supposed to do that */ |
606 | if (verboseFlag == TRUE || listFlag == TRUE) { | 586 | if (verboseFlag == TRUE && listFlag != TRUE) { |
607 | /* Now the normal listing */ | 587 | /* Now the normal listing */ |
608 | printf("%s", header.name); | 588 | FILE *vbFd = stdout; |
589 | if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr | ||
590 | vbFd = stderr; | ||
591 | fprintf(vbFd, "%s\n", header.name); | ||
609 | } | 592 | } |
593 | |||
610 | if (verboseFlag == TRUE && listFlag == TRUE) { | 594 | if (verboseFlag == TRUE && listFlag == TRUE) { |
611 | /* If this is a link, say so */ | 595 | printf("%s", header.name); |
612 | if (header.type==LNKTYPE) | 596 | if (header.type==LNKTYPE) /* If this is a link, say so */ |
613 | printf(" link to %s", header.linkname); | 597 | printf(" link to %s", header.linkname); |
614 | else if (header.type==SYMTYPE) | 598 | else if (header.type==SYMTYPE) |
615 | printf(" -> %s", header.linkname); | 599 | printf(" -> %s", header.linkname); |
616 | } | ||
617 | if (verboseFlag == TRUE || listFlag == TRUE) { | ||
618 | printf("\n"); | 600 | printf("\n"); |
619 | } | 601 | } |
620 | 602 | ||
@@ -745,7 +727,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
745 | #endif | 727 | #endif |
746 | const unsigned char *cp = (const unsigned char *) &header; | 728 | const unsigned char *cp = (const unsigned char *) &header; |
747 | ssize_t size = sizeof(struct TarHeader); | 729 | ssize_t size = sizeof(struct TarHeader); |
748 | 730 | ||
749 | memset( &header, 0, size); | 731 | memset( &header, 0, size); |
750 | 732 | ||
751 | if (*fileName=='/') { | 733 | if (*fileName=='/') { |
@@ -848,8 +830,12 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
848 | write(tbInfo->tarFd, "\0", 1); | 830 | write(tbInfo->tarFd, "\0", 1); |
849 | } | 831 | } |
850 | /* Now do the verbose thing (or not) */ | 832 | /* Now do the verbose thing (or not) */ |
851 | if (tbInfo->verboseFlag==TRUE) | 833 | if (tbInfo->verboseFlag==TRUE) { |
852 | fprintf(stdout, "%s\n", header.name); | 834 | FILE *vbFd = stdout; |
835 | if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr | ||
836 | vbFd = stderr; | ||
837 | fprintf(vbFd, "%s\n", header.name); | ||
838 | } | ||
853 | 839 | ||
854 | return ( TRUE); | 840 | return ( TRUE); |
855 | } | 841 | } |
@@ -1053,7 +1053,7 @@ const char tar_usage[] = | |||
1053 | "tar -[xtvO] " | 1053 | "tar -[xtvO] " |
1054 | #endif | 1054 | #endif |
1055 | #if defined BB_FEATURE_TAR_EXCLUDE | 1055 | #if defined BB_FEATURE_TAR_EXCLUDE |
1056 | "[-X File(s)] " | 1056 | "[--exclude File] " |
1057 | #endif | 1057 | #endif |
1058 | "[-f tarFile] [FILE(s)] ...\n" | 1058 | "[-f tarFile] [FILE(s)] ...\n" |
1059 | #ifndef BB_FEATURE_TRIVIAL_HELP | 1059 | #ifndef BB_FEATURE_TRIVIAL_HELP |
@@ -1069,7 +1069,7 @@ const char tar_usage[] = | |||
1069 | "\tf\t\tname of tarfile or \"-\" for stdin\n" | 1069 | "\tf\t\tname of tarfile or \"-\" for stdin\n" |
1070 | "\tO\t\textract to stdout\n" | 1070 | "\tO\t\textract to stdout\n" |
1071 | #if defined BB_FEATURE_TAR_EXCLUDE | 1071 | #if defined BB_FEATURE_TAR_EXCLUDE |
1072 | "\tX\t\tfile(s) to exclude\n" | 1072 | "\texclude\t\tfile to exclude\n" |
1073 | #endif | 1073 | #endif |
1074 | "\nInformative output:\n" | 1074 | "\nInformative output:\n" |
1075 | "\tv\t\tverbosely list files processed\n" | 1075 | "\tv\t\tverbosely list files processed\n" |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 6e95cdc79..9f25e05ce 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -34,6 +34,13 @@ | |||
34 | * | 34 | * |
35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's | 35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's |
36 | * mount to add loop support. | 36 | * mount to add loop support. |
37 | * | ||
38 | * 2000-04-30 Dave Cinege <dcinege@psychosis.com> | ||
39 | * Rewrote fstab while loop and lower mount section. Can now do | ||
40 | * single mounts from fstab. Can override fstab options for single | ||
41 | * mount. Common mount_one call for single mounts and 'all'. Fixed | ||
42 | * mtab updating and stale entries. Removed 'remount' default. | ||
43 | * | ||
37 | */ | 44 | */ |
38 | 45 | ||
39 | #include "internal.h" | 46 | #include "internal.h" |
@@ -147,6 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
147 | 154 | ||
148 | #if defined BB_MTAB | 155 | #if defined BB_MTAB |
149 | if (useMtab == TRUE) { | 156 | if (useMtab == TRUE) { |
157 | erase_mtab(specialfile); // Clean any stale entries | ||
150 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); | 158 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); |
151 | } | 159 | } |
152 | #endif | 160 | #endif |
@@ -318,6 +326,8 @@ extern int mount_main(int argc, char **argv) | |||
318 | int fakeIt = FALSE; | 326 | int fakeIt = FALSE; |
319 | int useMtab = TRUE; | 327 | int useMtab = TRUE; |
320 | int i; | 328 | int i; |
329 | int rc = FALSE; | ||
330 | int fstabmount = FALSE; | ||
321 | 331 | ||
322 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 332 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
323 | if (argc == 1) { | 333 | if (argc == 1) { |
@@ -435,56 +445,70 @@ extern int mount_main(int argc, char **argv) | |||
435 | argv++; | 445 | argv++; |
436 | } | 446 | } |
437 | 447 | ||
438 | if (all == TRUE) { | 448 | if (all == TRUE || directory == NULL) { |
439 | struct mntent *m; | 449 | struct mntent *m; |
440 | FILE *f = setmntent("/etc/fstab", "r"); | 450 | FILE *f = setmntent("/etc/fstab", "r"); |
451 | fstabmount = TRUE; | ||
441 | 452 | ||
442 | if (f == NULL) | 453 | if (f == NULL) |
443 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); | 454 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); |
444 | 455 | ||
445 | while ((m = getmntent(f)) != NULL) { | 456 | while ((m = getmntent(f)) != NULL) { |
446 | // If the filesystem isn't noauto, | 457 | if (all == FALSE && directory == NULL && ( |
447 | // and isn't swap or nfs, then mount it | 458 | (strcmp(device, m->mnt_fsname) != 0) && |
448 | if ((!strstr(m->mnt_opts, "noauto")) && | 459 | (strcmp(device, m->mnt_dir) != 0) ) ) { |
449 | (!strstr(m->mnt_type, "swap")) && | 460 | continue; |
450 | (!strstr(m->mnt_type, "nfs"))) { | 461 | } |
462 | |||
463 | if (all == TRUE && ( // If we're mounting 'all' | ||
464 | (strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto, | ||
465 | (strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it | ||
466 | (strstr(m->mnt_type, "nfs")) ) ) { | ||
467 | continue; | ||
468 | } | ||
469 | |||
470 | if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags | ||
451 | flags = 0; | 471 | flags = 0; |
452 | *string_flags = '\0'; | 472 | *string_flags = '\0'; |
453 | parse_mount_options(m->mnt_opts, &flags, string_flags); | 473 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
454 | if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
455 | flags, string_flags, useMtab, fakeIt, | ||
456 | extra_opts, FALSE)==FALSE) | ||
457 | { | ||
458 | /* Try again, but this time try a remount */ | ||
459 | mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
460 | flags|MS_REMOUNT, string_flags, useMtab, fakeIt, | ||
461 | extra_opts, TRUE); | ||
462 | } | ||
463 | } | 474 | } |
464 | } | 475 | |
465 | endmntent(f); | 476 | device = strdup(m->mnt_fsname); |
466 | } else { | 477 | directory = strdup(m->mnt_dir); |
467 | if (device && directory) { | 478 | filesystemType = strdup(m->mnt_type); |
479 | singlemount: | ||
468 | #ifdef BB_NFSMOUNT | 480 | #ifdef BB_NFSMOUNT |
469 | if (strchr(device, ':') != NULL) | 481 | if (strchr(device, ':') != NULL) |
470 | filesystemType = "nfs"; | 482 | filesystemType = "nfs"; |
471 | if (strcmp(filesystemType, "nfs") == 0) { | 483 | if (strcmp(filesystemType, "nfs") == 0) { |
472 | int ret; | 484 | rc = nfsmount (device, directory, &flags, &extra_opts, &string_flags, 1) |
473 | ret = nfsmount (device, directory, &flags, | 485 | if ( rc != 0) { |
474 | &extra_opts, &string_flags, 1); | 486 | fatalError("nfsmount failed: %s\n", strerror(errno)); |
475 | if (ret != 0) | 487 | rc = FALSE; |
476 | fatalError("nfsmount failed: %s\n", strerror(errno)); | 488 | } |
477 | } | 489 | } else |
478 | #endif | 490 | #endif |
479 | exit(mount_one(device, directory, filesystemType, | 491 | rc = mount_one(device, directory, filesystemType, flags, |
480 | flags, string_flags, useMtab, fakeIt, | 492 | string_flags, useMtab, fakeIt, extra_opts, TRUE); |
481 | extra_opts, TRUE)); | 493 | |
482 | } else { | 494 | if (all == FALSE) |
483 | goto goodbye; | 495 | break; |
496 | |||
497 | rc = TRUE; // Always return 0 for 'all' | ||
484 | } | 498 | } |
499 | if (fstabmount == TRUE) | ||
500 | endmntent(f); | ||
501 | |||
502 | if (all == FALSE && fstabmount == TRUE && directory == NULL) | ||
503 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); | ||
504 | |||
505 | exit(rc); | ||
485 | } | 506 | } |
486 | exit(TRUE); | 507 | |
508 | goto singlemount; | ||
509 | |||
510 | exit(FALSE); | ||
487 | 511 | ||
488 | goodbye: | 512 | goodbye: |
489 | usage(mount_usage); | 513 | usage(mount_usage); |
490 | } | 514 | } |
@@ -68,11 +68,11 @@ | |||
68 | 68 | ||
69 | 69 | ||
70 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF | 70 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF |
71 | # if defined BB_FEATURE_USE_PROCFS | 71 | # if defined BB_MTAB |
72 | const char mtab_file[] = "/proc/mounts"; | ||
73 | # else | ||
74 | # if defined BB_MTAB | ||
75 | const char mtab_file[] = "/etc/mtab"; | 72 | const char mtab_file[] = "/etc/mtab"; |
73 | # else | ||
74 | # if defined BB_FEATURE_USE_PROCFS | ||
75 | const char mtab_file[] = "/proc/mounts"; | ||
76 | # else | 76 | # else |
77 | # if defined BB_FEATURE_USE_DEVPS_PATCH | 77 | # if defined BB_FEATURE_USE_DEVPS_PATCH |
78 | const char mtab_file[] = "/dev/mtab"; | 78 | const char mtab_file[] = "/dev/mtab"; |