From 8341a1565306a54e685455d19efb0516ad3328a1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 8 Oct 1999 17:14:14 +0000 Subject: [PATCH] Finally mount works properly. Made debugging work (no more -s ld flag when debugging is on). --- Makefile | 6 ++-- mount.c | 87 +++++++++++++++++++++++++--------------------- util-linux/mount.c | 87 +++++++++++++++++++++++++--------------------- 3 files changed, 99 insertions(+), 81 deletions(-) diff --git a/Makefile b/Makefile index cf182097e..86fc9f6a6 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,10 @@ ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'` ifeq ($(DODEBUG),true) CFLAGS=-Wall -g -D_GNU_SOURCE STRIP= + LDFLAGS= else CFLAGS=-Wall -O2 -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE + LDFLAGS= -s STRIP= strip --remove-section=.note --remove-section=.comment busybox endif @@ -21,17 +23,15 @@ ifndef $(prefix) endif BINDIR=$(prefix) -LDFLAGS= -s LIBRARIES=-lc OBJECTS=$(shell ./busybox.sh) CFLAGS+= -DBB_VER='"$(VERSION)"' CFLAGS+= -DBB_BT='"$(BUILDTIME)"' all: busybox links -#all: busybox busybox: $(OBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) -o busybox $(OBJECTS) $(LIBRARIES) + $(CC) $(LDFLAGS) -o busybox $(OBJECTS) $(LIBRARIES) $(STRIP) links: diff --git a/mount.c b/mount.c index 9a1accc88..4e5c0745b 100644 --- a/mount.c +++ b/mount.c @@ -22,8 +22,8 @@ * will try mounting stuff with all fses when passed -t auto * * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. - * 1999-10-07 Erik Andersen. Removed mtab usage, major adjustments, - * and some serious dieting all around. + * 1999-10-07 Erik Andersen. Rewrote of a lot of code. Removed mtab + * usage, major adjustments, and some serious dieting all around. */ #include "internal.h" @@ -81,36 +81,42 @@ static const struct mount_options mount_options[] = { }; +/* Seperate standard mount options from the nonstandard string options */ static void -parse_mount_options ( char *options, unsigned long *flags, char *data) +parse_mount_options ( char *options, unsigned long *flags, char *strflags) { - printf("option=%s\n", options); - while (*options) { + while (options) { + int gotone=FALSE; char *comma = strchr (options, ','); const struct mount_options* f = mount_options; if (comma) *comma = '\0'; - printf("checking option=%s vs %s\n", options, f->name); while (f->name != 0) { - printf("checking option=%s vs %s\n", options, f->name); if (strcasecmp (f->name, options) == 0) { *flags &= f->and; *flags |= f->or; - return; + gotone=TRUE; + break; } f++; } - if (*data) { - data += strlen (data); - *data++ = ','; + if (*strflags && strflags!= '\0' && gotone==FALSE) { + char *temp=strflags; + temp += strlen (strflags); + *temp++ = ','; + *temp++ = '\0'; + } + if (gotone==FALSE) { + strcat (strflags, options); + gotone=FALSE; } - strcpy (data, options); if (comma) { *comma = ','; options = ++comma; - } else + } else { break; + } } } @@ -163,11 +169,13 @@ mount_one ( extern int mount_main (int argc, char **argv) { - char string_flags[1024]="\0"; + char string_flags[1024]=""; unsigned long flags = 0; char *filesystemType = "auto"; + char *device = NULL; + char *directory = NULL; int all = 0; - int i = argc; + int i; if (argc == 1) { FILE *mountTable; @@ -187,29 +195,31 @@ extern int mount_main (int argc, char **argv) /* Parse options */ - while (**argv) { + i = --argc; + argv++; + while (i > 0 && **argv) { if (**argv == '-') { - switch (**argv) { + while (i>0 && *++(*argv)) switch (**argv) { case 'o': - if (++argv == 0) { + if (--i == 0) { fprintf (stderr, "%s\n", mount_usage); return( FALSE); } - parse_mount_options (*argv, &flags, string_flags); - argc--; - argv++; + parse_mount_options (*(++argv), &flags, string_flags); + --i; + ++argv; break; case 'r': flags |= MS_RDONLY; break; case 't': - if (++argv == 0) { + if (--i == 0) { fprintf (stderr, "%s\n", mount_usage); return( FALSE); } - filesystemType = *argv; - argc--; - argv++; + filesystemType = *(++argv); + --i; + ++argv; break; case 'w': flags &= ~MS_RDONLY; @@ -222,6 +232,16 @@ extern int mount_main (int argc, char **argv) case '-': fprintf (stderr, "%s\n", mount_usage); return( TRUE); + break; + } + } else { + if (device == NULL) + device=*argv; + else if (directory == NULL) + directory=*argv; + else { + fprintf (stderr, "%s\n", mount_usage); + return( TRUE); } } i--; @@ -236,9 +256,6 @@ extern int mount_main (int argc, char **argv) perror("/etc/fstab"); return( FALSE); } - // FIXME: Combine read routine (make new function) with unmount_all - // to save space. - while ((m = getmntent (f)) != NULL) { // If the file system isn't noauto, and isn't mounted on /, mount // it @@ -250,19 +267,11 @@ extern int mount_main (int argc, char **argv) m->mnt_opts); } } - endmntent (f); } else { - if (argc >= 3) { - while (i < argc) - argv--; - while (**argv == '-') - argv++; - if (mount_one - (*argv, *(argv+1), filesystemType, flags, - string_flags) == 0) return 0; - else - return( FALSE); + if (device && directory) { + return (mount_one (device, directory, filesystemType, + flags, string_flags)); } else { fprintf (stderr, "%s\n", mount_usage); return( FALSE); diff --git a/util-linux/mount.c b/util-linux/mount.c index 9a1accc88..4e5c0745b 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -22,8 +22,8 @@ * will try mounting stuff with all fses when passed -t auto * * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. - * 1999-10-07 Erik Andersen. Removed mtab usage, major adjustments, - * and some serious dieting all around. + * 1999-10-07 Erik Andersen. Rewrote of a lot of code. Removed mtab + * usage, major adjustments, and some serious dieting all around. */ #include "internal.h" @@ -81,36 +81,42 @@ static const struct mount_options mount_options[] = { }; +/* Seperate standard mount options from the nonstandard string options */ static void -parse_mount_options ( char *options, unsigned long *flags, char *data) +parse_mount_options ( char *options, unsigned long *flags, char *strflags) { - printf("option=%s\n", options); - while (*options) { + while (options) { + int gotone=FALSE; char *comma = strchr (options, ','); const struct mount_options* f = mount_options; if (comma) *comma = '\0'; - printf("checking option=%s vs %s\n", options, f->name); while (f->name != 0) { - printf("checking option=%s vs %s\n", options, f->name); if (strcasecmp (f->name, options) == 0) { *flags &= f->and; *flags |= f->or; - return; + gotone=TRUE; + break; } f++; } - if (*data) { - data += strlen (data); - *data++ = ','; + if (*strflags && strflags!= '\0' && gotone==FALSE) { + char *temp=strflags; + temp += strlen (strflags); + *temp++ = ','; + *temp++ = '\0'; + } + if (gotone==FALSE) { + strcat (strflags, options); + gotone=FALSE; } - strcpy (data, options); if (comma) { *comma = ','; options = ++comma; - } else + } else { break; + } } } @@ -163,11 +169,13 @@ mount_one ( extern int mount_main (int argc, char **argv) { - char string_flags[1024]="\0"; + char string_flags[1024]=""; unsigned long flags = 0; char *filesystemType = "auto"; + char *device = NULL; + char *directory = NULL; int all = 0; - int i = argc; + int i; if (argc == 1) { FILE *mountTable; @@ -187,29 +195,31 @@ extern int mount_main (int argc, char **argv) /* Parse options */ - while (**argv) { + i = --argc; + argv++; + while (i > 0 && **argv) { if (**argv == '-') { - switch (**argv) { + while (i>0 && *++(*argv)) switch (**argv) { case 'o': - if (++argv == 0) { + if (--i == 0) { fprintf (stderr, "%s\n", mount_usage); return( FALSE); } - parse_mount_options (*argv, &flags, string_flags); - argc--; - argv++; + parse_mount_options (*(++argv), &flags, string_flags); + --i; + ++argv; break; case 'r': flags |= MS_RDONLY; break; case 't': - if (++argv == 0) { + if (--i == 0) { fprintf (stderr, "%s\n", mount_usage); return( FALSE); } - filesystemType = *argv; - argc--; - argv++; + filesystemType = *(++argv); + --i; + ++argv; break; case 'w': flags &= ~MS_RDONLY; @@ -222,6 +232,16 @@ extern int mount_main (int argc, char **argv) case '-': fprintf (stderr, "%s\n", mount_usage); return( TRUE); + break; + } + } else { + if (device == NULL) + device=*argv; + else if (directory == NULL) + directory=*argv; + else { + fprintf (stderr, "%s\n", mount_usage); + return( TRUE); } } i--; @@ -236,9 +256,6 @@ extern int mount_main (int argc, char **argv) perror("/etc/fstab"); return( FALSE); } - // FIXME: Combine read routine (make new function) with unmount_all - // to save space. - while ((m = getmntent (f)) != NULL) { // If the file system isn't noauto, and isn't mounted on /, mount // it @@ -250,19 +267,11 @@ extern int mount_main (int argc, char **argv) m->mnt_opts); } } - endmntent (f); } else { - if (argc >= 3) { - while (i < argc) - argv--; - while (**argv == '-') - argv++; - if (mount_one - (*argv, *(argv+1), filesystemType, flags, - string_flags) == 0) return 0; - else - return( FALSE); + if (device && directory) { + return (mount_one (device, directory, filesystemType, + flags, string_flags)); } else { fprintf (stderr, "%s\n", mount_usage); return( FALSE);