[PATCH 2/2] mount: -T OTHERTAB support

Isaac Dunham ibid.ag at gmail.com
Wed Mar 11 14:47:47 UTC 2015


On Wed, Mar 11, 2015 at 10:21:26AM +0100, walter harms wrote:
> 
> 
> Am 11.03.2015 06:35, schrieb Isaac Dunham:
> > +0 bytes disabled, +56 enabled when DESKTOP is enabled (glibc/i386):
> > function                                             old     new   delta
> > .rodata                                           144949  144971     +22
> > packed_usage                                       30236   30256     +20
> > mount_main                                          1200    1214     +14
> > ------------------------------------------------------------------------------
> > (add/remove: 0/0 grow/shrink: 3/0 up/down: 56/0)               Total: 56 bytes
> >    text	   data	    bss	    dec	    hex	filename
> >  757557	   2068	   9044	 768669	  bba9d	busybox_old
> >  757593	   2068	   9044	 768705	  bbac1	busybox_unstripped
> > 
> > Making fstabname always char* was tidier than the alternatives.
> > Should be +47 bytes without DESKTOP.
> > ---
> >  util-linux/mount.c | 22 ++++++++++++++++++----
> >  1 file changed, 18 insertions(+), 4 deletions(-)
> > 
> > diff --git a/util-linux/mount.c b/util-linux/mount.c
> > index 1e6a2c8..6e62882 100644
> > --- a/util-linux/mount.c
> > +++ b/util-linux/mount.c
> > @@ -105,6 +105,12 @@
> >  //config:	help
> >  //config:	  Support mount all and looking for files in /etc/fstab.
> >  //config:
> > +//config:config FEATURE_MOUNT_OTHERTAB
> > +//config:	depends on FEATURE_MOUNT_FSTAB
> > +//config:	bool "Support -T <alt_fstab>"
> > +//config:	default n
> > +//config:	help
> > +//config:	  Support mount -T (specifying an alternate fstab)
> >  //usage:#define mount_trivial_usage
> >  //usage:       "[OPTIONS] [-o OPTS] DEVICE NODE"
> >  //usage:#define mount_full_usage "\n\n"
> > @@ -131,6 +137,9 @@
> >  //usage:     "\n	-r		Read-only mount"
> >  //usage:     "\n	-w		Read-write mount (default)"
> >  //usage:     "\n	-t FSTYPE[,...]	Filesystem type(s)"
> > +//usage:	IF_FEATURE_MOUNT_OTHERTAB(
> > +//usage:     "\n	-T FSTAB	Read FSTAB instead of /etc/fstab"
> > +//usage:	)
<snip>
  
> >  #if ENABLE_FEATURE_MTAB_SUPPORT
> > @@ -2122,7 +2132,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
> >  	char *O_optmatch = NULL;
> >  	char *storage_path;
> >  	llist_t *lst_o = NULL;
> > -	const char *fstabname;
> > +	char *fstabname = (char*)"/etc/fstab";
> 
> i am curious why (char *) ?

The cast is just to shut up GCC, since busybox has enabled an option that
makes GCC treat "string" as const char *.

The architectural reason for using char * instead of const char *
is that -T makes fstabname variable (and it's simpler to use the same
declarations when practical).

In terms of generated code, I saw no difference (gcc 4.9 on i386,
Debian Jessie).

> > @@ -2149,12 +2159,17 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
> >  	// Max 2 params; -o is a list, -v is a counter
> >  	opt_complementary = "?2o::" IF_FEATURE_MOUNT_VERBOSE("vv");
> >  	opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch
> > +			IF_FEATURE_MOUNT_OTHERTAB(, &fstabname)
> >  			IF_FEATURE_MOUNT_VERBOSE(, &verbose));
> >  	while (lst_o) append_mount_options(&cmdopts, llist_pop(&lst_o)); // -o
> >  	if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r
> >  	if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w
> >  	argv += optind;
> >  
> > +	// A malicious user could overmount /usr without this.
> > +	if (ENABLE_FEATURE_MOUNT_OTHERTAB && nonroot)
> > +		fstabname = (char*)"/etc/fstab";
> > +
> >  	// If we have no arguments, show currently mounted filesystems
> >  	if (!argv[0]) {
> >  		if (!(opt & OPT_a)) {
> > @@ -2217,12 +2232,11 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
> >  	}
> >  
> >  	// Open either fstab or mtab
> > -	fstabname = "/etc/fstab";
> >  	if (cmdopt_flags & MS_REMOUNT) {
> >  		// WARNING. I am not sure this matches util-linux's
> >  		// behavior. It's possible util-linux does not
> >  		// take -o opts from mtab (takes only mount source).
> > -		fstabname = bb_path_mtab_file;
> > +		fstabname = (char*)bb_path_mtab_file;
> >  	}


More information about the busybox mailing list