Merge in two patches from Dave Cinege:

the first is a cleanup of tar --exclude
    the second changes mount so mtab works more as it should, and
    also allows mount to use the traditional short form (i.e.
    'mount / -o remount,rw' now works.

While inside tar, I changed it to use getopt...
 -Erik
This commit is contained in:
Eric Andersen 2000-08-02 18:48:26 +00:00
parent 5ae166813f
commit fdd5103348
9 changed files with 218 additions and 198 deletions

View File

@ -1053,7 +1053,7 @@ const char tar_usage[] =
"tar -[xtvO] " "tar -[xtvO] "
#endif #endif
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
"[-X File(s)] " "[--exclude File] "
#endif #endif
"[-f tarFile] [FILE(s)] ...\n" "[-f tarFile] [FILE(s)] ...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP
@ -1069,7 +1069,7 @@ const char tar_usage[] =
"\tf\t\tname of tarfile or \"-\" for stdin\n" "\tf\t\tname of tarfile or \"-\" for stdin\n"
"\tO\t\textract to stdout\n" "\tO\t\textract to stdout\n"
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
"\tX\t\tfile(s) to exclude\n" "\texclude\t\tfile to exclude\n"
#endif #endif
"\nInformative output:\n" "\nInformative output:\n"
"\tv\t\tverbosely list files processed\n" "\tv\t\tverbosely list files processed\n"

View File

@ -148,85 +148,65 @@ extern int tar_main(int argc, char **argv)
int createFlag = FALSE; int createFlag = FALSE;
int verboseFlag = FALSE; int verboseFlag = FALSE;
int tostdoutFlag = FALSE; int tostdoutFlag = FALSE;
int stopIt; int opt;
if (argc <= 1) if (argc <= 1)
usage(tar_usage); usage(tar_usage);
/* Parse any options */ /* do normal option parsing */
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) {
stopIt=FALSE; switch (opt) {
while (stopIt==FALSE && *argv && **argv) {
switch (**argv) {
case 'f':
if (--argc == 0) {
fatalError( "Option requires an argument: No file specified\n");
}
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv);
if (tarName == NULL)
fatalError( "Option requires an argument: No file specified\n");
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
stopIt=TRUE;
break;
case 't':
if (extractFlag == TRUE || createFlag == TRUE)
goto flagError;
listFlag = TRUE;
break;
case 'x':
if (listFlag == TRUE || createFlag == TRUE)
goto flagError;
extractFlag = TRUE;
break;
case 'c': case 'c':
if (extractFlag == TRUE || listFlag == TRUE) if (extractFlag == TRUE || listFlag == TRUE)
goto flagError; goto flagError;
createFlag = TRUE; createFlag = TRUE;
break; break;
case 'x':
if (listFlag == TRUE || createFlag == TRUE)
goto flagError;
extractFlag = TRUE;
break;
case 't':
if (extractFlag == TRUE || createFlag == TRUE)
goto flagError;
listFlag = TRUE;
break;
case 'v': case 'v':
verboseFlag = TRUE; verboseFlag = TRUE;
break; break;
case 'O': case 'O':
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
tarName = "-"; tarName = "-";
break;
case 'f':
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = optarg;
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
break; break;
case '-': case '-':
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
if (strcmp(*argv, "-exclude")==0) { if (strcmp(optarg, "exclude")==0) {
if (--argc == 0) { if (argv[optind]==NULL)
fatalError( "Option requires an argument: No file specified\n"); fatalError( "option `--exclude' requires an argument\n");
}
excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = *(++argv); excludeList[excludeListSize] = argv[optind];
/* Remove leading "/"s */ /* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/') { if (*excludeList[excludeListSize] =='/') {
excludeList[excludeListSize] = (excludeList[excludeListSize])+1; excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
} }
if (excludeList[excludeListSize++] == NULL)
fatalError( "Option requires an argument: No file specified\n");
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[excludeListSize] = NULL; excludeList[excludeListSize] = NULL;
stopIt=TRUE; optind++;
break; break;
} }
#endif #endif
if (strcmp(*argv, "-help")==0) { fatalError( "Unknown tar flag '%s'\n"
usage(tar_usage); "Try `tar --help' for more information\n", optarg);
}
break;
default: default:
fatalError( "Unknown tar flag '%c'\n" fatalError( "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n", **argv); "Try `tar --help' for more information\n", **argv);
}
++(*argv);
} }
} }
@ -238,7 +218,7 @@ extern int tar_main(int argc, char **argv)
#ifndef BB_FEATURE_TAR_CREATE #ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n"); fatalError( "This version of tar was not compiled with tar creation support.\n");
#else #else
exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList));
#endif #endif
} }
if (listFlag == TRUE || extractFlag == TRUE) { if (listFlag == TRUE || extractFlag == TRUE) {
@ -603,18 +583,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
} }
} }
/* List contents if we are supposed to do that */ /* List contents if we are supposed to do that */
if (verboseFlag == TRUE || listFlag == TRUE) { if (verboseFlag == TRUE && listFlag != TRUE) {
/* Now the normal listing */ /* Now the normal listing */
printf("%s", header.name); FILE *vbFd = stdout;
if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
vbFd = stderr;
fprintf(vbFd, "%s\n", header.name);
} }
if (verboseFlag == TRUE && listFlag == TRUE) { if (verboseFlag == TRUE && listFlag == TRUE) {
/* If this is a link, say so */ printf("%s", header.name);
if (header.type==LNKTYPE) if (header.type==LNKTYPE) /* If this is a link, say so */
printf(" link to %s", header.linkname); printf(" link to %s", header.linkname);
else if (header.type==SYMTYPE) else if (header.type==SYMTYPE)
printf(" -> %s", header.linkname); printf(" -> %s", header.linkname);
}
if (verboseFlag == TRUE || listFlag == TRUE) {
printf("\n"); printf("\n");
} }
@ -745,7 +727,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
#endif #endif
const unsigned char *cp = (const unsigned char *) &header; const unsigned char *cp = (const unsigned char *) &header;
ssize_t size = sizeof(struct TarHeader); ssize_t size = sizeof(struct TarHeader);
memset( &header, 0, size); memset( &header, 0, size);
if (*fileName=='/') { if (*fileName=='/') {
@ -848,8 +830,12 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
write(tbInfo->tarFd, "\0", 1); write(tbInfo->tarFd, "\0", 1);
} }
/* Now do the verbose thing (or not) */ /* Now do the verbose thing (or not) */
if (tbInfo->verboseFlag==TRUE) if (tbInfo->verboseFlag==TRUE) {
fprintf(stdout, "%s\n", header.name); FILE *vbFd = stdout;
if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
vbFd = stderr;
fprintf(vbFd, "%s\n", header.name);
}
return ( TRUE); return ( TRUE);
} }

View File

@ -1634,7 +1634,7 @@ File selection:
f name of tarfile or "-" for stdin f name of tarfile or "-" for stdin
O extract to stdout O extract to stdout
--exclude file to exclude exclude file to exclude
Informative output: Informative output:
@ -2044,4 +2044,4 @@ Enrique Zanardi <ezanardi@ull.es>
=cut =cut
# $Id: busybox.pod,v 1.59 2000/07/21 21:32:12 andersen Exp $ # $Id: busybox.pod,v 1.60 2000/08/02 18:48:25 andersen Exp $

View File

@ -2901,10 +2901,10 @@
<para> <para>
<screen> <screen>
f FILE Use FILE for tarfile (or stdin if '-') f FILE Use FILE for tarfile (or stdin if '-')
O Extract to stdout O Extract to stdout
--exclude FILE Exclude FILE exclude FILE File to exclude
v List files processed v List files processed
</screen> </screen>
</para> </para>

92
mount.c
View File

@ -34,6 +34,13 @@
* *
* 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
* mount to add loop support. * mount to add loop support.
*
* 2000-04-30 Dave Cinege <dcinege@psychosis.com>
* Rewrote fstab while loop and lower mount section. Can now do
* single mounts from fstab. Can override fstab options for single
* mount. Common mount_one call for single mounts and 'all'. Fixed
* mtab updating and stale entries. Removed 'remount' default.
*
*/ */
#include "internal.h" #include "internal.h"
@ -147,6 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
#if defined BB_MTAB #if defined BB_MTAB
if (useMtab == TRUE) { if (useMtab == TRUE) {
erase_mtab(specialfile); // Clean any stale entries
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
} }
#endif #endif
@ -318,6 +326,8 @@ extern int mount_main(int argc, char **argv)
int fakeIt = FALSE; int fakeIt = FALSE;
int useMtab = TRUE; int useMtab = TRUE;
int i; int i;
int rc = FALSE;
int fstabmount = FALSE;
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) { if (argc == 1) {
@ -435,56 +445,70 @@ extern int mount_main(int argc, char **argv)
argv++; argv++;
} }
if (all == TRUE) { if (all == TRUE || directory == NULL) {
struct mntent *m; struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r"); FILE *f = setmntent("/etc/fstab", "r");
fstabmount = TRUE;
if (f == NULL) if (f == NULL)
fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) { while ((m = getmntent(f)) != NULL) {
// If the filesystem isn't noauto, if (all == FALSE && directory == NULL && (
// and isn't swap or nfs, then mount it (strcmp(device, m->mnt_fsname) != 0) &&
if ((!strstr(m->mnt_opts, "noauto")) && (strcmp(device, m->mnt_dir) != 0) ) ) {
(!strstr(m->mnt_type, "swap")) && continue;
(!strstr(m->mnt_type, "nfs"))) { }
if (all == TRUE && ( // If we're mounting 'all'
(strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto,
(strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it
(strstr(m->mnt_type, "nfs")) ) ) {
continue;
}
if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags
flags = 0; flags = 0;
*string_flags = '\0'; *string_flags = '\0';
parse_mount_options(m->mnt_opts, &flags, string_flags); parse_mount_options(m->mnt_opts, &flags, string_flags);
if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
flags, string_flags, useMtab, fakeIt,
extra_opts, FALSE)==FALSE)
{
/* Try again, but this time try a remount */
mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
extra_opts, TRUE);
}
} }
}
endmntent(f); device = strdup(m->mnt_fsname);
} else { directory = strdup(m->mnt_dir);
if (device && directory) { filesystemType = strdup(m->mnt_type);
singlemount:
#ifdef BB_NFSMOUNT #ifdef BB_NFSMOUNT
if (strchr(device, ':') != NULL) if (strchr(device, ':') != NULL)
filesystemType = "nfs"; filesystemType = "nfs";
if (strcmp(filesystemType, "nfs") == 0) { if (strcmp(filesystemType, "nfs") == 0) {
int ret; rc = nfsmount (device, directory, &flags, &extra_opts, &string_flags, 1)
ret = nfsmount (device, directory, &flags, if ( rc != 0) {
&extra_opts, &string_flags, 1); fatalError("nfsmount failed: %s\n", strerror(errno));
if (ret != 0) rc = FALSE;
fatalError("nfsmount failed: %s\n", strerror(errno)); }
} } else
#endif #endif
exit(mount_one(device, directory, filesystemType, rc = mount_one(device, directory, filesystemType, flags,
flags, string_flags, useMtab, fakeIt, string_flags, useMtab, fakeIt, extra_opts, TRUE);
extra_opts, TRUE));
} else { if (all == FALSE)
goto goodbye; break;
}
}
exit(TRUE);
goodbye: rc = TRUE; // Always return 0 for 'all'
}
if (fstabmount == TRUE)
endmntent(f);
if (all == FALSE && fstabmount == TRUE && directory == NULL)
fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
exit(rc);
}
goto singlemount;
exit(FALSE);
goodbye:
usage(mount_usage); usage(mount_usage);
} }

102
tar.c
View File

@ -148,85 +148,65 @@ extern int tar_main(int argc, char **argv)
int createFlag = FALSE; int createFlag = FALSE;
int verboseFlag = FALSE; int verboseFlag = FALSE;
int tostdoutFlag = FALSE; int tostdoutFlag = FALSE;
int stopIt; int opt;
if (argc <= 1) if (argc <= 1)
usage(tar_usage); usage(tar_usage);
/* Parse any options */ /* do normal option parsing */
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) {
stopIt=FALSE; switch (opt) {
while (stopIt==FALSE && *argv && **argv) {
switch (**argv) {
case 'f':
if (--argc == 0) {
fatalError( "Option requires an argument: No file specified\n");
}
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv);
if (tarName == NULL)
fatalError( "Option requires an argument: No file specified\n");
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
stopIt=TRUE;
break;
case 't':
if (extractFlag == TRUE || createFlag == TRUE)
goto flagError;
listFlag = TRUE;
break;
case 'x':
if (listFlag == TRUE || createFlag == TRUE)
goto flagError;
extractFlag = TRUE;
break;
case 'c': case 'c':
if (extractFlag == TRUE || listFlag == TRUE) if (extractFlag == TRUE || listFlag == TRUE)
goto flagError; goto flagError;
createFlag = TRUE; createFlag = TRUE;
break; break;
case 'x':
if (listFlag == TRUE || createFlag == TRUE)
goto flagError;
extractFlag = TRUE;
break;
case 't':
if (extractFlag == TRUE || createFlag == TRUE)
goto flagError;
listFlag = TRUE;
break;
case 'v': case 'v':
verboseFlag = TRUE; verboseFlag = TRUE;
break; break;
case 'O': case 'O':
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
tarName = "-"; tarName = "-";
break;
case 'f':
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = optarg;
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
break; break;
case '-': case '-':
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
if (strcmp(*argv, "-exclude")==0) { if (strcmp(optarg, "exclude")==0) {
if (--argc == 0) { if (argv[optind]==NULL)
fatalError( "Option requires an argument: No file specified\n"); fatalError( "option `--exclude' requires an argument\n");
}
excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = *(++argv); excludeList[excludeListSize] = argv[optind];
/* Remove leading "/"s */ /* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/') { if (*excludeList[excludeListSize] =='/') {
excludeList[excludeListSize] = (excludeList[excludeListSize])+1; excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
} }
if (excludeList[excludeListSize++] == NULL)
fatalError( "Option requires an argument: No file specified\n");
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[excludeListSize] = NULL; excludeList[excludeListSize] = NULL;
stopIt=TRUE; optind++;
break; break;
} }
#endif #endif
if (strcmp(*argv, "-help")==0) { fatalError( "Unknown tar flag '%s'\n"
usage(tar_usage); "Try `tar --help' for more information\n", optarg);
}
break;
default: default:
fatalError( "Unknown tar flag '%c'\n" fatalError( "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n", **argv); "Try `tar --help' for more information\n", **argv);
}
++(*argv);
} }
} }
@ -238,7 +218,7 @@ extern int tar_main(int argc, char **argv)
#ifndef BB_FEATURE_TAR_CREATE #ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n"); fatalError( "This version of tar was not compiled with tar creation support.\n");
#else #else
exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList));
#endif #endif
} }
if (listFlag == TRUE || extractFlag == TRUE) { if (listFlag == TRUE || extractFlag == TRUE) {
@ -603,18 +583,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
} }
} }
/* List contents if we are supposed to do that */ /* List contents if we are supposed to do that */
if (verboseFlag == TRUE || listFlag == TRUE) { if (verboseFlag == TRUE && listFlag != TRUE) {
/* Now the normal listing */ /* Now the normal listing */
printf("%s", header.name); FILE *vbFd = stdout;
if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
vbFd = stderr;
fprintf(vbFd, "%s\n", header.name);
} }
if (verboseFlag == TRUE && listFlag == TRUE) { if (verboseFlag == TRUE && listFlag == TRUE) {
/* If this is a link, say so */ printf("%s", header.name);
if (header.type==LNKTYPE) if (header.type==LNKTYPE) /* If this is a link, say so */
printf(" link to %s", header.linkname); printf(" link to %s", header.linkname);
else if (header.type==SYMTYPE) else if (header.type==SYMTYPE)
printf(" -> %s", header.linkname); printf(" -> %s", header.linkname);
}
if (verboseFlag == TRUE || listFlag == TRUE) {
printf("\n"); printf("\n");
} }
@ -745,7 +727,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
#endif #endif
const unsigned char *cp = (const unsigned char *) &header; const unsigned char *cp = (const unsigned char *) &header;
ssize_t size = sizeof(struct TarHeader); ssize_t size = sizeof(struct TarHeader);
memset( &header, 0, size); memset( &header, 0, size);
if (*fileName=='/') { if (*fileName=='/') {
@ -848,8 +830,12 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
write(tbInfo->tarFd, "\0", 1); write(tbInfo->tarFd, "\0", 1);
} }
/* Now do the verbose thing (or not) */ /* Now do the verbose thing (or not) */
if (tbInfo->verboseFlag==TRUE) if (tbInfo->verboseFlag==TRUE) {
fprintf(stdout, "%s\n", header.name); FILE *vbFd = stdout;
if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
vbFd = stderr;
fprintf(vbFd, "%s\n", header.name);
}
return ( TRUE); return ( TRUE);
} }

View File

@ -1053,7 +1053,7 @@ const char tar_usage[] =
"tar -[xtvO] " "tar -[xtvO] "
#endif #endif
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
"[-X File(s)] " "[--exclude File] "
#endif #endif
"[-f tarFile] [FILE(s)] ...\n" "[-f tarFile] [FILE(s)] ...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP
@ -1069,7 +1069,7 @@ const char tar_usage[] =
"\tf\t\tname of tarfile or \"-\" for stdin\n" "\tf\t\tname of tarfile or \"-\" for stdin\n"
"\tO\t\textract to stdout\n" "\tO\t\textract to stdout\n"
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
"\tX\t\tfile(s) to exclude\n" "\texclude\t\tfile to exclude\n"
#endif #endif
"\nInformative output:\n" "\nInformative output:\n"
"\tv\t\tverbosely list files processed\n" "\tv\t\tverbosely list files processed\n"

View File

@ -34,6 +34,13 @@
* *
* 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
* mount to add loop support. * mount to add loop support.
*
* 2000-04-30 Dave Cinege <dcinege@psychosis.com>
* Rewrote fstab while loop and lower mount section. Can now do
* single mounts from fstab. Can override fstab options for single
* mount. Common mount_one call for single mounts and 'all'. Fixed
* mtab updating and stale entries. Removed 'remount' default.
*
*/ */
#include "internal.h" #include "internal.h"
@ -147,6 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
#if defined BB_MTAB #if defined BB_MTAB
if (useMtab == TRUE) { if (useMtab == TRUE) {
erase_mtab(specialfile); // Clean any stale entries
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
} }
#endif #endif
@ -318,6 +326,8 @@ extern int mount_main(int argc, char **argv)
int fakeIt = FALSE; int fakeIt = FALSE;
int useMtab = TRUE; int useMtab = TRUE;
int i; int i;
int rc = FALSE;
int fstabmount = FALSE;
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) { if (argc == 1) {
@ -435,56 +445,70 @@ extern int mount_main(int argc, char **argv)
argv++; argv++;
} }
if (all == TRUE) { if (all == TRUE || directory == NULL) {
struct mntent *m; struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r"); FILE *f = setmntent("/etc/fstab", "r");
fstabmount = TRUE;
if (f == NULL) if (f == NULL)
fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) { while ((m = getmntent(f)) != NULL) {
// If the filesystem isn't noauto, if (all == FALSE && directory == NULL && (
// and isn't swap or nfs, then mount it (strcmp(device, m->mnt_fsname) != 0) &&
if ((!strstr(m->mnt_opts, "noauto")) && (strcmp(device, m->mnt_dir) != 0) ) ) {
(!strstr(m->mnt_type, "swap")) && continue;
(!strstr(m->mnt_type, "nfs"))) { }
if (all == TRUE && ( // If we're mounting 'all'
(strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto,
(strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it
(strstr(m->mnt_type, "nfs")) ) ) {
continue;
}
if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags
flags = 0; flags = 0;
*string_flags = '\0'; *string_flags = '\0';
parse_mount_options(m->mnt_opts, &flags, string_flags); parse_mount_options(m->mnt_opts, &flags, string_flags);
if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
flags, string_flags, useMtab, fakeIt,
extra_opts, FALSE)==FALSE)
{
/* Try again, but this time try a remount */
mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
extra_opts, TRUE);
}
} }
}
endmntent(f); device = strdup(m->mnt_fsname);
} else { directory = strdup(m->mnt_dir);
if (device && directory) { filesystemType = strdup(m->mnt_type);
singlemount:
#ifdef BB_NFSMOUNT #ifdef BB_NFSMOUNT
if (strchr(device, ':') != NULL) if (strchr(device, ':') != NULL)
filesystemType = "nfs"; filesystemType = "nfs";
if (strcmp(filesystemType, "nfs") == 0) { if (strcmp(filesystemType, "nfs") == 0) {
int ret; rc = nfsmount (device, directory, &flags, &extra_opts, &string_flags, 1)
ret = nfsmount (device, directory, &flags, if ( rc != 0) {
&extra_opts, &string_flags, 1); fatalError("nfsmount failed: %s\n", strerror(errno));
if (ret != 0) rc = FALSE;
fatalError("nfsmount failed: %s\n", strerror(errno)); }
} } else
#endif #endif
exit(mount_one(device, directory, filesystemType, rc = mount_one(device, directory, filesystemType, flags,
flags, string_flags, useMtab, fakeIt, string_flags, useMtab, fakeIt, extra_opts, TRUE);
extra_opts, TRUE));
} else { if (all == FALSE)
goto goodbye; break;
}
}
exit(TRUE);
goodbye: rc = TRUE; // Always return 0 for 'all'
}
if (fstabmount == TRUE)
endmntent(f);
if (all == FALSE && fstabmount == TRUE && directory == NULL)
fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
exit(rc);
}
goto singlemount;
exit(FALSE);
goodbye:
usage(mount_usage); usage(mount_usage);
} }

View File

@ -68,11 +68,11 @@
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
# if defined BB_FEATURE_USE_PROCFS # if defined BB_MTAB
const char mtab_file[] = "/proc/mounts";
# else
# if defined BB_MTAB
const char mtab_file[] = "/etc/mtab"; const char mtab_file[] = "/etc/mtab";
# else
# if defined BB_FEATURE_USE_PROCFS
const char mtab_file[] = "/proc/mounts";
# else # else
# if defined BB_FEATURE_USE_DEVPS_PATCH # if defined BB_FEATURE_USE_DEVPS_PATCH
const char mtab_file[] = "/dev/mtab"; const char mtab_file[] = "/dev/mtab";