NetBSD Problem Report #441

From gnats  Mon Aug 29 08:12:45 1994
Received: from Collatz.McRCIM.McGill.EDU (Collatz.McRCIM.McGill.EDU [132.206.78.1]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id IAA07912 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Mon, 29 Aug 1994 08:12:40 -0700
Message-Id: <199408291513.LAA00897@Collatz.McRCIM.McGill.EDU>
Date: Mon, 29 Aug 1994 11:13:49 -0400
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
Reply-To: mouse@Collatz.McRCIM.McGill.EDU
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: mount can mount something umount can't unmount
X-Send-Pr-Version: 3.2

>Number:         441
>Category:       bin
>Synopsis:       mount can mount something umount can't unmount
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 29 08:20:09 +0000 1994
>Closed-Date:    Wed May 21 21:49:46 +0000 1997
>Last-Modified:  Wed May 21 21:50:14 +0000 1997
>Originator:     der Mouse
>Release:        NetBSD/sparc 1.0-beta
>Organization:
	Organization?  Me??  Surely you jest.
>Environment:
	SPARC IPC, not that it matters
>Description:
	/sbin/mount is willing to mount anything on top of a directory
	(or rather, mount_null and probably others are), but
	/sbin/umount refuses to attempt an unmount unless a directory
	(or a block special device) is given.  If the thing mounted
	doesn't stat() as a directory, it's impossible to unmount it.
>How-To-Repeat:
	echo foo > /tmp/foo  # create a plain file
	mkdir /tmp/bar       # create a place to mount it
	mount -t null -o ro /tmp/foo /tmp/bar  # NULLFS needed in your kernel
	ls -l /tmp/bar       # looks like a plain file, as it should
	umount /tmp/bar      # notice umount gets upset
>Fix:
	Uncertain.  The following patch makes umount willing to unmount
	such things, but I assume the check was put in there for a
	reason, so I'm hesitant to recommend this without knowing what
	that reason is.  Notice that even with this patch, it's still
	possible to get into a bind if the thing mounted stat()s as a
	block special device, because then mount will try to find where
	it's mounted, not what's mounted on it.  Perhaps an option
	should be added to make umount pass the given string directly
	to the unmount syscall, without attempting any sort of smarts,
	to make it possible to deal with this and other potentially
	difficult cases (like mount points containing : or @)?

	*** /sources/supped/netbsd/src/sbin/umount/umount.c	Wed Aug 24 17:31:27 1994
	--- umount.c	Mon Aug 29 10:57:19 1994
	***************
	*** 202,208 ****
	  			warnx("%s: not currently mounted", name);
	  			return (1);
	  		}
	! 	} else if (S_ISDIR(sb.st_mode)) {
	  		mntpt = name;
	  		if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
	  			warnx("%s: not currently mounted", mntpt);
	--- 202,208 ----	
	  			warnx("%s: not currently mounted", name);
	  			return (1);
	  		}
	! 	} else if (/*S_ISDIR(sb.st_mode)*/1) {
	  		mntpt = name;
	  		if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
	  			warnx("%s: not currently mounted", mntpt);

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Release-Note:
>Audit-Trail:

From: der Mouse  <mouse@Rodents.Montreal.QC.CA>
To: gnats-bugs@gnats.netbsd.org
Cc: netbsd-bugs@netbsd.org
Subject: Re: bin/441: mount can mount something umount can't unmount
Date: Mon, 21 Apr 1997 12:13:36 -0400 (EDT)

 My PR 441, from August 1994 (1994?  I'm making myself feel old!), says
 that
 	/sbin/mount is willing to mount anything on top of a directory
 	(or rather, mount_null and probably others are), but
 	/sbin/umount refuses to attempt an unmount unless a directory
 	(or a block special device) is given.  If the thing mounted
 	doesn't stat() as a directory, it's impossible to unmount it.

 I've now fixed this (and in the process documented the previous
 undocumented -F flag to umount(8)).

 Here's my fix, relative to

 .\"     $NetBSD: umount.8,v 1.2 1995/03/18 15:01:35 cgd Exp $
 /*      $NetBSD: umount.c,v 1.16 1996/05/11 14:13:55 mycroft Exp $      */

 Both -current and 1.2 have those same version numbers for these two
 files.

 --- OLD/sbin/umount/umount.8	Thu Jan  1 00:00:00 1970
 +++ NEW/sbin/umount/umount.8	Thu Jan  1 00:00:00 1970
 @@ -41,11 +41,11 @@
  .Nd unmount file systems
  .Sh SYNOPSIS
  .Nm umount
 -.Op Fl fv
 +.Op Fl fvFR
  .Ar special | node
  .Nm umount
  .Fl a
 -.Op Fl fv
 +.Op Fl fvF
  .Op Fl h Ar host
  .Op Fl t Ar ufs | lfs | external_type
  .Sh DESCRIPTION
 @@ -77,6 +77,29 @@
  Active special devices continue to work,
  but all other files return errors if further accesses are attempted.
  The root file system cannot be forcibly unmounted.
 +.It Fl F
 +Fake the unmount: perform all other processing but do not actually
 +attempt the unmount.  (This is most useful in conjunction with
 +.Fl v ,
 +to see what
 +.Nm
 +would attempt to do.)
 +.It Fl R
 +Take the
 +.Ar special | node
 +argument as a path to be passed directly to
 +.Xr unmount 2 ,
 +bypassing all attempts to be smart about mechanically determining the
 +correct path from the argument.  This option is incompatible with any
 +option that potentially umounts more than one filesystem, such as
 +.Fl a ,
 +but it can be used with
 +.Fl f
 +and/or
 +.Fl v .
 +This is the only way to unmount something that does not appear as a
 +directory (such as a nullfs mount of a plain file); there are probably
 +other cases where it is necessary.
  .It Fl h Ar host
  Only filesystems mounted from the specified host will be
  unmounted.
 --- OLD/sbin/umount/umount.c	Thu Jan  1 00:00:00 1970
 +++ NEW/sbin/umount/umount.c	Thu Jan  1 00:00:00 1970
 @@ -69,7 +69,7 @@

  typedef enum { MNTON, MNTFROM } mntwhat;

 -int	fake, fflag, verbose;
 +int	fake, fflag, verbose, raw;
  char	**typelist = NULL;
  char	*nfshost;

 @@ -93,7 +93,7 @@
  	sync();

  	all = 0;
 -	while ((ch = getopt(argc, argv, "aFfh:t:v")) != EOF)
 +	while ((ch = getopt(argc, argv, "aFfh:Rt:v")) != EOF)
  		switch (ch) {
  		case 'a':
  			all = 1;
 @@ -108,6 +108,9 @@
  			all = 1;
  			nfshost = optarg;
  			break;
 +		case 'R':
 +			raw = 1;
 +			break;
  		case 't':
  			if (typelist != NULL)
  				errx(1, "only one -t option may be specified.");
 @@ -123,7 +126,7 @@
  	argc -= optind;
  	argv += optind;

 -	if (argc == 0 && !all || argc != 0 && all)
 +	if (argc == 0 && !all || argc != 0 && all || all && raw)
  		usage();

  	/* -h implies "-t nfs" if no -t flag. */
 @@ -178,55 +181,60 @@
  	int so;
  	char *delimp, *hostp, *mntpt, rname[MAXPATHLEN], type[MFSNAMELEN];

 -	if (realpath(name, rname) == NULL) {
 -		warn("%s", rname);
 -		return (1);
 -	}
 -
 -	mntpt = name = rname;
 -
 -	if (stat(name, &sb) < 0) {
 -		if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
 -			name = rname;
 +	hp = 0;
 +	if (raw) {
 +		mntpt = name;
 +	} else {
 +		if (realpath(name, rname) == NULL) {
 +			warn("%s", rname);
 +			return (1);
 +		}
 +		mntpt = name = rname;
 +		if (stat(name, &sb) < 0) {
 +			name = getmntname(mntpt, MNTFROM, type);
 +			if (name == NULL) {
 +				name = rname;
 +				mntpt = getmntname(name, MNTON, type);
 +				if (mntpt == NULL) {
 +					warnx("%s: not currently mounted", name);
 +					return (1);
 +				}
 +			}
 +		} else if (S_ISBLK(sb.st_mode)) {
  			if ((mntpt = getmntname(name, MNTON, type)) == NULL) {
  				warnx("%s: not currently mounted", name);
  				return (1);
  			}
 -		}
 -	} else if (S_ISBLK(sb.st_mode)) {
 -		if ((mntpt = getmntname(name, MNTON, type)) == NULL) {
 -			warnx("%s: not currently mounted", name);
 -			return (1);
 -		}
 -	} else if (S_ISDIR(sb.st_mode)) {
 -		if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
 -			warnx("%s: not currently mounted", mntpt);
 +		} else if (S_ISDIR(sb.st_mode)) {
 +			if ((name = getmntname(mntpt, MNTFROM, type)) == NULL) {
 +				warnx("%s: not currently mounted", mntpt);
 +				return (1);
 +			}
 +		} else {
 +			warnx("%s: not a directory or special device", name);
  			return (1);
  		}
 -	} else {
 -		warnx("%s: not a directory or special device", name);
 -		return (1);
 -	}

 -	if (!selected(type))
 -		return (1);
 -
 -	if (!strncmp(type, MOUNT_NFS, MFSNAMELEN)) {
 -		if ((delimp = strchr(name, '@')) != NULL) {
 -			hostp = delimp + 1;
 -			*delimp = '\0';
 -			hp = gethostbyname(hostp);
 -			*delimp = '@';
 -		} else if ((delimp = strchr(name, ':')) != NULL) {
 -			*delimp = '\0';
 -			hostp = name;
 -			hp = gethostbyname(hostp);
 -			name = delimp + 1;
 -			*delimp = ':';
 -		} else
 -			hp = NULL;
 -		if (!namematch(hp))
 +		if (!selected(type))
  			return (1);
 +
 +		if (!strncmp(type, MOUNT_NFS, MFSNAMELEN)) {
 +			if ((delimp = strchr(name, '@')) != NULL) {
 +				hostp = delimp + 1;
 +				*delimp = '\0';
 +				hp = gethostbyname(hostp);
 +				*delimp = '@';
 +			} else if ((delimp = strchr(name, ':')) != NULL) {
 +				*delimp = '\0';
 +				hostp = name;
 +				hp = gethostbyname(hostp);
 +				name = delimp + 1;
 +				*delimp = ':';
 +			} else
 +				hp = NULL;
 +			if (!namematch(hp))
 +				return (1);
 +		}
  	}

  	if (verbose)
 @@ -398,7 +406,7 @@
  {
  	(void)fprintf(stderr,
  	    "usage: %s\n       %s\n",
 -	    "umount [-fv] [-t fstypelist] special | node",
 -	    "umount -a[fv] [-h host] [-t fstypelist]");
 +	    "umount [-fvFR] [-t fstypelist] special | node",
 +	    "umount -a[fvF] [-h host] [-t fstypelist]");
  	exit(1);
  }

 					der Mouse

 			       mouse@rodents.montreal.qc.ca
 		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
State-Changed-From-To: open->closed 
State-Changed-By: pk 
State-Changed-When: Wed May 21 14:49:46 PDT 1997 
State-Changed-Why:  
The S_ISDIR/S_ISBLK check has been relaxed. 
(see also PR#3016) 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.