Usenet comp.os.linux.announce (1993-2013)
 help / color / mirror / Atom feed
* MS_REMOUNT and other patches to Usermount-0.3
@ 1993-09-07  3:02 Kevin Brown
  0 siblings, 0 replies; only message in thread
From: Kevin Brown @ 1993-09-07  3:02 UTC (permalink / raw)


(Note: subject was "Re: noauto option in fstab?")

In article <1993Sep6.115713.15068@colorado.edu> drew@caesar.cs.colorado.edu (Drew Eckhardt) writes:
>In article <1993Sep6.111658.18252@mnemosyne.cs.du.edu> mcodogno@nyx.cs.du.edu (Maurizio Codogno) writes:
>>
>>If I correctly checked, there is no "noauto" option in fstab code
>>(on SunOs and I think BSDish systems, it says not to mount the
>>filesystem automatically with `mount -a'.
>>I think it is a very handy option to set parameters for floppies
>>without the system trying to search for them at boot. 
>>Of course it is not that difficult to add the option to the 
>>mount sources, and I think I'll eventually do so; I just wonder
>>if it is just a bell&whistle or it could be useful to other people.
>>Any comments?
>
>No, it's definately useful for floppy disks, CD's, etc.
>
>At one point, one of the Linux mount programs had support for -noauto,
>but it was removed.  Having noauto lines in my mount file, I added it 
>to the .99.6 version of mount, I don't know what the code looks like to
>newer versions of mount but I could probably get patches.

I've implemented this for the usermount code.  The patches below are against
usermount-0.3, which can be found on sunsite.unc.edu:/pub/Linux/system/Misc/
mount/usermount-0.3.tar.gz.

The patches also implement the remount option to make it possible to change
the options of an already-mounted filesystem, and implement a proper sequence
for umount -a (namely, the reverse of what's found in mtab).  See the README
file (which is also patched :-) for a list of my changes.

Please let me know if you find any bugs or if you have any suggestions for
enhancements.

BTW, the umount supplied with this package isn't capable of unmounting the
root filesystem.  This could be a problem with e2fs.  If someone would be so
kind as to tell me how to implement this (or point me to code that does), I'll
be happy to do so.

Here are the patches.  Apply by going into the directory where your usermount
code is and do a "patch -p" with the following as standard input:

------------ cut here -------------
*** README~	Fri Jul 30 16:31:04 1993
--- README	Mon Sep  6 13:52:06 1993
***************
*** 2,7 ****
--- 2,8 ----
  Date: 30-Jul-93
  Version: 0.3
  Author: Peter Orbaek <poe@daimi.aau.dk>
+ Modified by: Kevin Brown <kevin@frobozz.sccsi.com>
  
  Quick installation guide
  ========================
***************
*** 31,36 ****
--- 32,58 ----
  
  Changes since:
  ==============
+ Date: 3-Sep-93
+ Version: 0.3
+ 
+ 	Changed umount's -a behavior to umount filesystems in the reverse
+ 	order found in the mtab file.  This should yield a successful
+ 	umount on the first pass with filesystems mounted under other
+ 	(non-root) filesystems.  Fixed problem with user umounting
+ 	changing permissions on mtab file.  Fixed mount to use the fs type
+ 	field in fstab/ufstab if it's there rather than explicitly requiring
+ 	the user to specify it when not using -a.  Added noauto option so
+ 	that filesystems can be skipped when -a is specified.  KCB
+ 
+ Date: 2-Sep-93
+ Version: 0.3
+ 
+ 	Applied my patches to 0.2 to add the remount option (for changing
+ 	the attributes of an already-mounted filesystem) and to make the
+ 	behavior of -n truly hands-off (i.e., don't even bother screwing
+ 	with the lockfile, so that mount will behave itself with a read-only
+ 	root filesystem).  KCB
+ 
  Date: 26-Apr-93
  Version: 0.2
  
*** mount.8~	Mon Apr 26 12:28:50 1993
--- mount.8	Mon Sep  6 14:04:55 1993
***************
*** 50,56 ****
  Fake an entry in /etc/mtab without actually mounting anything.
  .TP
  \-n
! Do not write an entry in /etc/mtab for the mount.
  .TP
  \-p
  Print the entry that would otherwise have been written to /etc/mtab on stdout.
--- 50,59 ----
  Fake an entry in /etc/mtab without actually mounting anything.
  .TP
  \-n
! Do not write an entry in /etc/mtab for the mount.  This option also causes
! the lockfile, /etc/mtab~, to be ignored, since no changes will be made to
! /etc/mtab anyway.  This is particularly useful if you're trying to re-mount
! your root filesystem from read-only to read-write.
  .TP
  \-p
  Print the entry that would otherwise have been written to /etc/mtab on stdout.
***************
*** 73,79 ****
  depending on your kernel configuration.
  If no
  .I type
! is given, then 
  .B minix
  is assumed.
  
--- 76,83 ----
  depending on your kernel configuration.
  If no
  .I type
! is given, then the type specified in fstab/ufstab is assumed, and if no such
! entry exists,
  .B minix
  is assumed.
  
***************
*** 110,115 ****
--- 114,127 ----
  
  .BR sync :
  Always keep the mounted volume sync'ed.
+ 
+ .BR remount :
+ Apply the other specified options to an already-mounted filesystem.
+ 
+ .BR noauto :
+ When -a is specified, causes mount to ignore the fstab entry.  Has no effect
+ on the command line or when -a isn't specified.
+ 
  .RE
  .PP
  If \-u is given, or the caller of 
***************
*** 144,150 ****
  /etc/mtab~
  A lock file, the existence of this file prevents 
  .B mount
! from changing anything.
  
  .SH AUTHOR
  This version of mount for Linux is written by Peter Orbaek <poe@daimi.aau.dk>
--- 156,162 ----
  /etc/mtab~
  A lock file, the existence of this file prevents 
  .B mount
! from changing anything, unless -n is specified.
  
  .SH AUTHOR
  This version of mount for Linux is written by Peter Orbaek <poe@daimi.aau.dk>
*** mount.c~	Mon Apr 26 12:34:53 1993
--- mount.c	Mon Sep  6 13:36:36 1993
***************
*** 39,44 ****
--- 39,45 ----
  #define MNTOPT_NODEV    "nodev"
  #define MNTOPT_NOEXEC   "noexec"
  #define MNTOPT_SYNC     "sync"
+ #define MNTOPT_REMOUNT	"remount"
  
  #ifndef __STDC__
  #error Error: This program requires ANSI C to compile
***************
*** 57,62 ****
--- 58,64 ----
  int opt_usermount= 0;
  int opt_fakemtab = 0;
  int opt_nomtab   = 0;
+ int opt_noauto   = 0;
  
  char opt_nostd[200];
  char mntoptions[200] = "defaults";
***************
*** 131,137 ****
  	    FILE *fstab;
  	    struct mntent *mp;
  	    
- 
  	    /* only a mount-point was given, look up device in fstab */
  	    mntdir = mntdev; mntdev = NULL;
  
--- 133,138 ----
***************
*** 140,154 ****
--- 141,180 ----
  		if(!strcmp(mntdir, mp->mnt_dir)) {
  		    strncpy(mntdevbuf, mp->mnt_fsname, sizeof(mntdevbuf)-1);
  		    mntdev = mntdevbuf;
+ 		    if ( !mnttype[0] )
+ 			strncpy(mnttype, mp->mnt_type, sizeof(mnttype)-1);
  		    break;
  		} else if(!strcmp(mntdir, mp->mnt_fsname)) {
  		    strncpy(mntdevbuf, mp->mnt_dir, sizeof(mntdevbuf)-1);
  		    mntdev = mntdir;
  		    mntdir = mntdevbuf;
+ 		    if ( !mnttype[0] )
+ 			strncpy(mnttype, mp->mnt_type, sizeof(mnttype)-1);
  		}
  	    }
  	    endmntent(fstab);
  
+ 	    /*
+ 	     * If the fstab lookup failed, maybe it's a filesystem that's
+ 	     * already been mounted, in which case the "remount" option has
+ 	     * to be set.  We process the options early to test this.
+ 	     */
+ 	    process_options ( mntoptions );
+ 	    if (!mntdev && (opt_std & MS_REMOUNT)) {
+ 		if(!(fstab = setmntent(MTAB_FILE, "r"))) err(filename);
+ 		while((mp = getmntent(fstab))) {
+ 		    if(!strcmp(mntdir, mp->mnt_dir)) {
+ 			strncpy(mntdevbuf, mp->mnt_fsname, sizeof(mntdevbuf)-1);
+ 			mntdev = mntdevbuf;
+ 			break;
+ 		    } else if(!strcmp(mntdir, mp->mnt_fsname)) {
+ 			strncpy(mntdevbuf, mp->mnt_dir, sizeof(mntdevbuf)-1);
+ 			mntdev = mntdir;
+ 			mntdir = mntdevbuf;
+ 		    }
+ 		}
+ 	    }
+ 
  	    if(!mntdev) {
  		fprintf(stderr, "mount: Don't know what to mount on %s\n",
  			mntdir);
***************
*** 171,177 ****
      }
  
      /* check for lock */
!     if(!lock_mtab()) {
  	/* don't use err() for this */
  	fprintf(stderr, "mount: A lock-file exists, mount denied.\n");
  	exit(1);
--- 197,203 ----
      }
  
      /* check for lock */
!     if(!opt_nomtab && !lock_mtab()) {
  	/* don't use err() for this */
  	fprintf(stderr, "mount: A lock-file exists, mount denied.\n");
  	exit(1);
***************
*** 261,266 ****
--- 287,295 ----
      FILE *mtab;
  
      if(!mp->mnt_type || !mp->mnt_type[0]) mp->mnt_type = "minix";
+ 
+     process_options(mp->mnt_opts);
+     if ( opt_mountall && opt_noauto ) return 0;
      
      if(!opt_fakemtab) {
  	/* check the directory */
***************
*** 285,298 ****
  	    return 0;
  	}
  
- 	process_options(mp->mnt_opts);
- 
  #if 0
  	printf("mount(%s,%s,%s,%x,%s)\n", mp->mnt_fsname, mp->mnt_dir,
  	       mp->mnt_type, opt_std, opt_nostd);
  #endif
  
! 	if(strcmp(mp->mnt_dir, "/") == 0) {
  	    if(opt_verbose)
  	      fprintf(stderr, "mount: root already mounted by kernel\n");
  	} else {
--- 314,325 ----
  	    return 0;
  	}
  
  #if 0
  	printf("mount(%s,%s,%s,%x,%s)\n", mp->mnt_fsname, mp->mnt_dir,
  	       mp->mnt_type, opt_std, opt_nostd);
  #endif
  
! 	if(strcmp(mp->mnt_dir, "/") == 0 && !(opt_std & MS_REMOUNT)) {
  	    if(opt_verbose)
  	      fprintf(stderr, "mount: root already mounted by kernel\n");
  	} else {
***************
*** 324,330 ****
  	}
      } /* if(!opt_fakemtab) */
  
!     if(!opt_nomtab) {
  	if(!(mtab = setmntent(MTAB_FILE, "a"))) {
  	    fprintf(stderr, "mount: open(%s) failed.\n", MTAB_FILE);
  	    return 1;
--- 351,357 ----
  	}
      } /* if(!opt_fakemtab) */
  
!     if(!opt_nomtab && !(opt_std & MS_REMOUNT)) {
  	if(!(mtab = setmntent(MTAB_FILE, "a"))) {
  	    fprintf(stderr, "mount: open(%s) failed.\n", MTAB_FILE);
  	    return 1;
***************
*** 371,376 ****
--- 398,404 ----
  
      opt_nostd[0] = '\0';
      opt_std = 0;
+     opt_noauto = 0;
  
      while(opts && *opts) {
  	for(p = opt; *opts && *opts != ','; *p++ = *opts++);
***************
*** 391,396 ****
--- 419,430 ----
  	else if(!strcmp(opt, MNTOPT_NODEV))  opt_std |= MS_NODEV;
  	else if(!strcmp(opt, MNTOPT_NOEXEC)) opt_std |= MS_NOEXEC;
  	else if(!strcmp(opt, MNTOPT_SYNC))   opt_std |= MS_SYNC;
+ 	else if(!strcmp(opt, MNTOPT_REMOUNT)) opt_std |= MS_REMOUNT;
+ 	/*
+ 	 * Not a *real* mount option, but a directive to us which is
+ 	 * ignored if -a wasn't specified.
+ 	 */
+ 	else if(!strcmp(opt, MNTOPT_NOAUTO)) opt_noauto = 1;
  	else {
  	    /* non-standard options are put in a comma-sep. string */
  	    strcat(opt_nostd, opt);
*** umount.8~	Tue Dec 15 13:33:10 1992
--- umount.8	Fri Sep  3 22:07:58 1993
***************
*** 35,41 ****
  .SS OPTIONS
  .TP
  \-a
! Unmount all filesystems mentioned in /etc/mtab. Only root can do this.
  .TP
  \-v
  Verbose.
--- 35,43 ----
  .SS OPTIONS
  .TP
  \-a
! Unmount all filesystems mentioned in /etc/mtab (in the reverse order of what
! is found there, to maximize the chances of an error-free pass).  Only root can
! do this.
  .TP
  \-v
  Verbose.
*** umount.c~	Fri Jul 30 14:54:48 1993
--- umount.c	Mon Sep  6 13:43:48 1993
***************
*** 18,33 ****
      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
  
! 
  #define _POSIX_SOURCE 1
  #include <stdio.h>
  #include <mntent.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <string.h>
  #include <errno.h>
  #include <getopt.h>
  #include <sys/mount.h>
  
  #define MTAB_FILE MOUNTED
  #define LOCK_FILE "/etc/mtab~"
--- 18,35 ----
      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
  
! #define _BSD_SOURCE 1
  #define _POSIX_SOURCE 1
  #include <stdio.h>
  #include <mntent.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <string.h>
+ #include <stdlib.h>
  #include <errno.h>
  #include <getopt.h>
  #include <sys/mount.h>
+ #include <sys/stat.h>
  
  #define MTAB_FILE MOUNTED
  #define LOCK_FILE "/etc/mtab~"
***************
*** 58,63 ****
--- 60,66 ----
      FILE *mtab, *newmtab;
      struct mntent *mp;
      struct mntent mnt;
+     int perms;
  
      int flag;
  
***************
*** 85,91 ****
  
      if((!opt_all && !mntdev) || (opt_all && mntdev)) usage();
  
!     if(getuid()) opt_usermount = 1;
  
      if(geteuid()) {
  	fprintf(stderr, "umount: You must be root to umount filesystems.\n");
--- 88,106 ----
  
      if((!opt_all && !mntdev) || (opt_all && mntdev)) usage();
  
!     perms = 0666;
!     if(getuid())
!     {
!     struct stat statbuf;
! 
! 	umask (0);
! 	opt_usermount = 1;
! 	if ( stat ( MTAB_FILE, &statbuf ) < 0 ) {
! 	    perror ( "umount: can't stat mtab!!" );
! 	    exit(1);
! 	}
! 	perms = statbuf.st_mode & 0777;
!     }
  
      if(geteuid()) {
  	fprintf(stderr, "umount: You must be root to umount filesystems.\n");
***************
*** 115,136 ****
  	}
      }
  
!     if(!(newmtab = fdopen(open(LOCK_FILE, O_WRONLY|O_CREAT|O_EXCL, 0666), "w"))) {
  	fprintf(stderr, "umount: A lockfile exists, unmount denied\n");
  	exit(1);
      }
      if(!(mtab = setmntent(MTAB_FILE, "r"))) err(MTAB_FILE);
  
      if(opt_all) {
! 	while((mp = getmntent(mtab))) {
! 	    if(!mp->mnt_opts || !mp->mnt_opts[0]) mp->mnt_opts = "defaults";
! 	    if(mnttype[0] == '\0' || !strcmp(mnttype, mp->mnt_type)) {
! 		if(do_umount(mp) < 0) {
! 		    addmntent(newmtab, mp);
! 		    fprintf(stderr, "umount: Umount of %s failed\n",
! 			    mp->mnt_fsname);
! 		}
! 	    } else addmntent(newmtab, mp);
  	}
      } else {
  	flag = 0;
--- 130,217 ----
  	}
      }
  
!     if(!(newmtab = fdopen(open(LOCK_FILE, O_WRONLY|O_CREAT|O_EXCL, perms), "w"))) {
  	fprintf(stderr, "umount: A lockfile exists, unmount denied\n");
  	exit(1);
      }
      if(!(mtab = setmntent(MTAB_FILE, "r"))) err(MTAB_FILE);
  
      if(opt_all) {
! 	/*
! 	 * To work properly, filesystems have to unmounted in the reverse order
! 	 * of how they were mounted.  Otherwise, you may try to umount a
! 	 * filesystem that has another filesystem mounted to it (which will
! 	 * fail).
! 	 */
! 	struct mntentnode {
! 	    struct mntent m;
! 	    int mounted;
! 	    struct mntentnode *next;
! 	} *mnp = 0, *tmnp, *next;
! 	/*
! 	 * Build the list of things to umount, bottom-up...
! 	 */
! 	while((mp = getmntent(mtab))) {
! 	    if(!mp->mnt_opts || !mp->mnt_opts[0]) mp->mnt_opts = "defaults";
! 	    if ( ! ( tmnp = malloc ( sizeof ( struct mntentnode ) ) ) ) {
! 		/*
! 		 * If malloc failed, then the system is probably in dire
! 		 * straits, so we exit in order to avoid damage...
! 		 */
! 		perror ("umount: Out of memory!!!  Aborting...");
! 		exit(1);
! 	    }
! 	    tmnp->next = mnp;
! 	    mnp = tmnp;
! 	    mnp->mounted = 1;	/* It's currently mounted */
! 	    mnp->m = *mp;
! 	    /*
! 	     * We're safer in copying the various strings out of the
! 	     * mntent struct rather than just copying the pointers.
! 	     * For the case of Linux, this proves to be a prudent
! 	     * assumption, inasmuch as the string space is reused by
! 	     * getmntent()..
! 	     */
! 	    mnp->m.mnt_fsname = strdup ( mp->mnt_fsname );
! 	    mnp->m.mnt_dir = strdup ( mp->mnt_dir );
! 	    mnp->m.mnt_type = strdup ( mp->mnt_type );
! 	    mnp->m.mnt_opts = strdup ( mp->mnt_opts );
! 	}
! 	for ( tmnp = mnp ; tmnp ; tmnp = next ) {
! 	    next = tmnp->next;
! 	    if(mnttype[0] == '\0' || !strcmp(mnttype, mp->mnt_type)) {
! 		if(do_umount(&(tmnp->m)) < 0) {
! 		    /*
! 		     * Put this at the front of the list.  The end result
! 		     * will be a list of failed and skipped filesystems
! 		     * that will be in forward order (reverse of reverse).
! 		     * We use this to preserve the proper order of the
! 		     * mtab file.
! 		     */
! 		    tmnp->next = mnp;
! 		    mnp = tmnp;
! 		    fprintf(stderr, "umount: Umount of %s failed\n",
! 			    tmnp->m.mnt_fsname);
! 		} else
! 		    tmnp->mounted = 0;
! 	    } else {
! 		tmnp->next = mnp;
! 		mnp = tmnp;
! 	    }
! 	}
! 	for ( tmnp = mnp ; tmnp && tmnp->mounted ; tmnp = next ) {
! 	    addmntent(newmtab, &(tmnp->m));
! 	    /*
! 	     * We don't *have* to clean up behind ourselves, since we'll
! 	     * probably exit soon anyway, but it's always better to be
! 	     * safe...
! 	     */
! 	    next = tmnp->next;
! 	    free ( tmnp->m.mnt_fsname );
! 	    free ( tmnp->m.mnt_dir );
! 	    free ( tmnp->m.mnt_type );
! 	    free ( tmnp->m.mnt_opts );
! 	    free ( tmnp );
  	}
      } else {
  	flag = 0;
------------ cut here ------------



-- 
Kevin Brown					kevin@frobozz.sccsi.com
This is your .signature virus: < begin 644 .signature (9V]T8VAA(0K0z end >
	    This is your .signature virus on drugs: <>
			Any questions?

-- 
Send submissions for comp.os.linux.announce to: linux-announce@tc.cornell.edu


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1993-09-07  3:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-09-07  3:02 MS_REMOUNT and other patches to Usermount-0.3 Kevin Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox