<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">*** linux/Documentation/filesystems/supermount.txt.~1~	Thu May 30 15:49:07 1996
--- linux/Documentation/filesystems/supermount.txt	Thu May 30 15:22:30 1996
***************
*** 0 ****
--- 1,141 ----
+ Supermount README
+ =================
+ 
+ For supermount v0.4
+ 
+ Supermount is a pseudo-filesystem which manages filesystems on
+ removable media like floppy disks and CD-ROMs.  It aims to make
+ management of removable media as easy as it is under DOS.
+ 
+ With supermount, you can change the disk in the drive whenever you
+ want (with the obvious exception that you shouldn't do it when the
+ filesystem is actively in use).  You don't need to "cd" out of the
+ directory first, and you don't need to tell the kernel what you're
+ doing --- supermount will detect the media change automatically.
+ 
+ Supermount will automatically detect whether the media you are
+ mounting is read-write or readonly, and if you mount a write-protected
+ disk, then the subfs will be mounted as a readonly filesystem.
+ 
+ Supermount detects when you have finished activity on the subfs, and
+ will flush all buffers to the disk before completing the operation.
+ So, if you copy a file onto a supermounted floppy disk, the data will
+ all be written to disk before the "cp" command finishes.  When the
+ command does complete, it will be safe to remove the disk.
+ 
+ It is worth while defining what I mean by "activity" here.  The subfs
+ is active if there are any processes running which have a handle on a
+ non-directory inode on the subfs, or which have a file open on the
+ subfs (even if only for reading).  There is one important case which
+ does NOT count as activity: if you "cd" to a directory or a
+ subdirectory under the supermount mount point, then that reference
+ does not make the subfs active, and you can safely remove the disk.
+ 
+ Yes, that's right.  You can "cd /floppy; ls" and get a listing of a
+ dos floppy.  Remove the disk, insert a new one, and "ls" will now list
+ the new contents.  Remove the disk altogether, and "ls" will give you
+ an I/O error.  Put in a new disk, and "ls" starts working again.  It
+ is NOT an error to remove a supermounted disk which is acting as the
+ current working directory for one or more processes!
+ 
+ 
+ The Superfilesystem and Subfilesystem concepts
+ ----------------------------------------------
+ 
+ Normally, when you mount a filesystem, you create a direct connection
+ between a mount point in the directory tree and a filesystem on a
+ block device.  Supermount adds an extra layer in between; with
+ supermount, you explicitly mount the pseudo-filesystem (the
+ "superfilesystem") on the mount point, and supermount then
+ automatically mounts the real filesystem (the "subfilesystem") on the
+ block device when needed.
+ 
+ Running supermount
+ ------------------
+ 
+ To run supermount, compile and install a kernel with the supermount
+ patches and select "Y" to the question
+ 
+ 	Dynamic mounting of removable media?
+ 
+ when you run "make config".  You set up a supermount filesystem with
+ the normal mount command, using the syntax:
+ 
+ 	mount -o &lt;superfs-options&gt;,--,&lt;subfs-options&gt; / &lt;mount-point&gt;
+ 
+ Notice that I specified "/" instead of giving a block device to
+ supermount.  This is because the supermount filesystem is NOT
+ connected to a block device; rather, supermount is responsible for
+ connecting a separate filesystem to the block device.  You specify
+ this by providing the &lt;superfs-options&gt; field, where the following
+ options are currently recognised:
+ 
+ * subfs=&lt;filesystem-type&gt;		[default is "msdos"]
+ 
+ 	Specify the subfilesystem type.  "msdos" and "iso9660" have
+ been tested, but any block-device filesystem should work with one
+ important restriction: the filesystem must NOT try to write to the
+ device when you unmount it.  This is because supermount doesn't know
+ in advance when it will have to unmount the subfs, so it doesn't try
+ to do so until it detects that the media has been changed.  By this
+ time it is too late to write to the device!
+ 
+ 	If you mount supermount as a readonly filesystem ("mount -r"
+ or "mount -o ro"), then you won't have this problem.  Otherwise, you
+ will not be able to use the ext2fs or minix filesystems with
+ supermount.  This will hopefully be addressed in a future release of
+ supermount.
+ 
+ * dev=&lt;block-device&gt;			[default is "/dev/fd0"]
+ 
+ 	Specify the block device on which the subfs is to be mounted.
+ 
+ * debug
+ 
+ 	Enable debugging code in the supermount filesystem, if
+ the debug option was enabled at compile time.  By default, debugging
+ code is compiled into the kernel but is disabled until a debug mount
+ option is seen.
+ 
+ * '--'
+ 
+ 	All options after the option string '--' will be passed
+ directly to the subfilesystem when it gets mounted.
+ 
+ 
+ Here is an example of supermount options, taken directly out of my
+ current /etc/fstab:
+ 
+ / /floppy	supermount	--,gid=51,conv=binary	0 0
+ / /cd		supermount	ro,fs=iso9660,dev=/dev/hdd,--,conv=binary 0 0
+ 
+ This tells supermount to manage a msdos filesystem on /dev/fd0 mounted
+ at /floppy (msdos and /dev/fd0 are defaults for supermount), with the
+ msdos filesystem getting the options "gid=51,conv=binary".  My cdrom
+ on /dev/hdd is similarly mounted on /cd.
+ 
+ 
+ Enjoy supermount.  I hope you find it useful --- I certainly find it
+ extremely convenient.  Send any comments, bug-fixes or bug-reports,
+ suggestions and success stories to sct@dcs.ed.ac.uk.  Flames to
+ /dev/null, please!
+ 
+ Cheers,
+  Stephen.
+ --
+ Stephen Tweedie &lt;sct@dcs.ed.ac.uk&gt;
+ Department of Computer Science, Edinburgh University, Scotland.
+ 
+ 
+ ================================================================
+ Changes for v0.4:
+ Performance tuning only.  Read-only operations like "find" should now
+ be MUCH faster.
+ 
+ Changes for v0.3:
+ Fixed supermount_create bug; now returns a properly attached
+ superinode.
+ 
+ Changes for v0.2:
+ Improved device invalidation code, so CD-ROMs work now.
+ 
*** linux/fs/Config.in.~1~	Thu May 30 15:49:07 1996
--- linux/fs/Config.in	Thu May 30 15:22:31 1996
***************
*** 6,11 ****
--- 6,12 ----
  
  bool	 'Quota support' CONFIG_QUOTA
  bool	 'Mandatory lock support' CONFIG_LOCK_MANDATORY
+ bool	 'Supermount removable media support' CONFIG_SUPERMOUNT
  tristate 'Minix fs support' CONFIG_MINIX_FS
  tristate 'Extended fs support' CONFIG_EXT_FS
  tristate 'Second extended fs support' CONFIG_EXT2_FS
*** linux/fs/Makefile.~1~	Thu May 30 15:49:07 1996
--- linux/fs/Makefile	Thu May 30 15:23:05 1996
***************
*** 17,23 ****
  
  MOD_LIST_NAME := FS_MODULES
  ALL_SUB_DIRS = minix ext ext2 fat msdos vfat proc isofs nfs xiafs umsdos \
! 		hpfs sysv smbfs ncpfs ufs affs
  
  ifeq ($(CONFIG_QUOTA),y)
  O_OBJS += dquot.o
--- 17,23 ----
  
  MOD_LIST_NAME := FS_MODULES
  ALL_SUB_DIRS = minix ext ext2 fat msdos vfat proc isofs nfs xiafs umsdos \
! 		hpfs sysv smbfs ncpfs ufs affs supermount
  
  ifeq ($(CONFIG_QUOTA),y)
  O_OBJS += dquot.o
***************
*** 139,144 ****
--- 139,152 ----
    ifeq ($(CONFIG_HPFS_FS),m)
    MOD_SUB_DIRS += hpfs
    endif
+ endif
+ 
+ ifeq ($(CONFIG_SUPERMOUNT),y)
+ SUB_DIRS += supermount
+ #else
+ #  ifeq ($(CONFIG_SUPERMOUNT),m)
+ #  MOD_SUB_DIRS += supermount
+ #  endif
  endif
  
  ifeq ($(CONFIG_UFS_FS),y)
*** linux/fs/devices.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/devices.c	Thu May 30 15:22:30 1996
***************
*** 187,201 ****
  }
  
  /*
!  * This routine checks whether a removable media has been changed,
!  * and invalidates all buffer-cache-entries in that case. This
!  * is a relatively slow routine, so we have to try to minimize using
!  * it. Thus it is called only upon a 'mount' or 'open'. This
!  * is the best way of combining speed and utility, I think.
!  * People changing diskettes in the middle of an operation deserve
!  * to loose :-)
!  */
! int check_disk_change(kdev_t dev)
  {
  	int i;
  	struct file_operations * fops;
--- 187,200 ----
  }
  
  /*
!  * These routines checks whether a removable media has been changed,
!  * and (for check_disk_change only) invalidate all
!  * buffer-cache-entries in that case. This is a relatively slow
!  * routine, so we have to try to minimize using it. Thus it is called
!  * only upon a 'mount' or 'open'. This is the best way of combining
!  * speed and utility, I think.  People changing diskettes in the
!  * middle of an operation deserve to loose :-) */
! int query_disk_change(kdev_t dev)
  {
  	int i;
  	struct file_operations * fops;
***************
*** 208,224 ****
  	if (!fops-&gt;check_media_change(dev))
  		return 0;
  
  	printk(KERN_DEBUG "VFS: Disk change detected on device %s\n",
  		kdevname(dev));
  	for (i=0 ; i&lt;NR_SUPER ; i++)
  		if (super_blocks[i].s_dev == dev)
  			put_super(super_blocks[i].s_dev);
  	invalidate_inodes(dev);
  	invalidate_buffers(dev);
  
! 	if (fops-&gt;revalidate)
  		fops-&gt;revalidate(dev);
! 	return 1;
  }
  
  /*
--- 207,243 ----
  	if (!fops-&gt;check_media_change(dev))
  		return 0;
  
+ 	return 1;
+ }
+ 
+ int check_disk_change(kdev_t dev)
+ {
+ 	if (!query_disk_change(dev))
+ 		return 0;
  	printk(KERN_DEBUG "VFS: Disk change detected on device %s\n",
  		kdevname(dev));
+ 	invalidate_media(dev);
+ 	return 1;
+ }
+ 
+ void invalidate_media(kdev_t dev) 
+ {
+ 	int i;
+ 	struct file_operations * fops;
+ 	
+ 	i = MAJOR(dev);
+ 	if (i &gt;= MAX_BLKDEV)
+ 		return;
+ 	fops = blkdevs[i].fops;
  	for (i=0 ; i&lt;NR_SUPER ; i++)
  		if (super_blocks[i].s_dev == dev)
  			put_super(super_blocks[i].s_dev);
  	invalidate_inodes(dev);
  	invalidate_buffers(dev);
  
! 	if (fops &amp;&amp; fops-&gt;revalidate)
  		fops-&gt;revalidate(dev);
! 	return;
  }
  
  /*
*** linux/fs/filesystems.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/filesystems.c	Thu May 30 15:22:30 1996
***************
*** 9,14 ****
--- 9,15 ----
  #include &lt;linux/config.h&gt;
  #include &lt;linux/fs.h&gt;
  
+ #include &lt;linux/supermount_fs.h&gt;
  #include &lt;linux/minix_fs.h&gt;
  #include &lt;linux/ext_fs.h&gt;
  #include &lt;linux/ext2_fs.h&gt;
***************
*** 39,44 ****
--- 40,50 ----
  	callable = 0;
  
  	device_setup();
+ 
+ #ifdef CONFIG_SUPERMOUNT
+ 	register_filesystem(&amp;(struct file_system_type)
+ 		{supermount_read_super, "supermount", 0, NULL});
+ #endif
  
  	binfmt_setup();
  
*** linux/fs/inode.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/inode.c	Thu May 30 15:22:30 1996
***************
*** 219,224 ****
--- 219,226 ----
  		if (inode == mount_root &amp;&amp; inode-&gt;i_count ==
  		    (inode-&gt;i_mount != inode ? 1 : 2))
  			continue;
+ 		if (IS_UNBOUND(inode))
+ 			continue;
  		return 0;
  	}
  	return 1;
***************
*** 254,259 ****
--- 256,264 ----
  	inode-&gt;i_lock = 1;	
  	inode-&gt;i_sb-&gt;s_op-&gt;write_inode(inode);
  	unlock_inode(inode);
+ 	if (inode-&gt;i_shadow &amp;&amp; inode-&gt;i_shadow-&gt;i_shadow_op &amp;&amp; 
+ 	    inode-&gt;i_shadow-&gt;i_shadow_op-&gt;write)
+ 		inode-&gt;i_shadow-&gt;i_shadow_op-&gt;write(inode-&gt;i_shadow);
  }
  
  static inline void read_inode(struct inode * inode)
***************
*** 414,428 ****
  	}
  }
  
  void iput(struct inode * inode)
  {
  	if (!inode)
  		return;
  	wait_on_inode(inode);
  	if (!inode-&gt;i_count) {
  		printk("VFS: iput: trying to free free inode\n");
  		printk("VFS: device %s, inode %lu, mode=0%07o\n",
! 			kdevname(inode-&gt;i_rdev), inode-&gt;i_ino, inode-&gt;i_mode);
  		return;
  	}
  	if (inode-&gt;i_pipe)
--- 419,442 ----
  	}
  }
  
+ static inline void release_shadow(struct inode * inode) {
+ 	/* Shadow-release should be atomic. */
+ 	struct inode * tmp;
+ 	tmp = inode-&gt;i_shadow;
+ 	inode-&gt;i_shadow = 0;
+ }
+ 
  void iput(struct inode * inode)
  {
+ 	struct inode * shadow;
+ 
  	if (!inode)
  		return;
  	wait_on_inode(inode);
  	if (!inode-&gt;i_count) {
  		printk("VFS: iput: trying to free free inode\n");
  		printk("VFS: device %s, inode %lu, mode=0%07o\n",
! 			kdevname(inode-&gt;i_dev), inode-&gt;i_ino, inode-&gt;i_mode);
  		return;
  	}
  	if (inode-&gt;i_pipe)
***************
*** 441,449 ****
  	}
  
  	if (inode-&gt;i_sb &amp;&amp; inode-&gt;i_sb-&gt;s_op &amp;&amp; inode-&gt;i_sb-&gt;s_op-&gt;put_inode) {
  		inode-&gt;i_sb-&gt;s_op-&gt;put_inode(inode);
! 		if (!inode-&gt;i_nlink)
  			return;
  	}
  
  	if (inode-&gt;i_dirt) {
--- 455,476 ----
  	}
  
  	if (inode-&gt;i_sb &amp;&amp; inode-&gt;i_sb-&gt;s_op &amp;&amp; inode-&gt;i_sb-&gt;s_op-&gt;put_inode) {
+ 		shadow = inode-&gt;i_shadow;
  		inode-&gt;i_sb-&gt;s_op-&gt;put_inode(inode);
! 		if (!inode-&gt;i_nlink) {
! 			/* The inode should have been cleared, so we
!                            don't reset inode-&gt;i_shadow here. */
! 			if (shadow) {
! 			if (shadow-&gt;i_shadow_op &amp;&amp; 
! 			    shadow-&gt;i_shadow_op-&gt;release)
! 				shadow-&gt;i_shadow_op-&gt;release(shadow);
! 			iput (shadow);
! 			}
! 			/* put_inode should do a clear_inode() if the
! 			   inode is unlinked, so don't bother falling
! 			   through... */
  			return;
+ 		}
  	}
  
  	if (inode-&gt;i_dirt) {
***************
*** 473,478 ****
--- 500,513 ----
  	}
  
  	nr_free_inodes++;
+ 	shadow = inode-&gt;i_shadow;
+ 	inode-&gt;i_shadow = 0;
+ 	if (shadow) {
+ 		if (shadow-&gt;i_shadow_op &amp;&amp; 
+ 		    shadow-&gt;i_shadow_op-&gt;release)
+ 			shadow-&gt;i_shadow_op-&gt;release(shadow);
+ 		iput (shadow);
+ 	}
  	return;
  }
  
*** linux/fs/open.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/open.c	Thu May 30 15:22:30 1996
***************
*** 520,525 ****
--- 520,529 ----
  			goto cleanup_inode;
  	}
  
+ 	if (inode-&gt;i_shadow &amp;&amp; inode-&gt;i_shadow-&gt;i_shadow_op &amp;&amp;
+ 	    inode-&gt;i_shadow-&gt;i_shadow_op-&gt;open)
+ 		inode-&gt;i_shadow-&gt;i_shadow_op-&gt;open(inode-&gt;i_shadow, flag);
+ 
  	f-&gt;f_inode = inode;
  	f-&gt;f_pos = 0;
  	f-&gt;f_reada = 0;
*** linux/fs/super.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/super.c	Thu May 30 15:40:16 1996
***************
*** 628,648 ****
   * functions, they should be faked here.  -- jrs
   */
  
! asmlinkage int sys_umount(char * name)
  {
- 	struct inode * inode;
  	kdev_t dev;
  	int retval;
  	struct inode dummy_inode;
  
- 	if (!suser())
- 		return -EPERM;
- 	retval = namei(name, &amp;inode);
- 	if (retval) {
- 		retval = lnamei(name, &amp;inode);
- 		if (retval)
- 			return retval;
- 	}
  	if (S_ISBLK(inode-&gt;i_mode)) {
  		dev = inode-&gt;i_rdev;
  		if (IS_NODEV(inode)) {
--- 628,639 ----
   * functions, they should be faked here.  -- jrs
   */
  
! int do_umounti(struct inode * inode)
  {
  	kdev_t dev;
  	int retval;
  	struct inode dummy_inode;
  
  	if (S_ISBLK(inode-&gt;i_mode)) {
  		dev = inode-&gt;i_rdev;
  		if (IS_NODEV(inode)) {
***************
*** 681,730 ****
  	return 0;
  }
  
  /*
!  * do_mount() does the actual mounting after sys_mount has done the ugly
!  * parameter parsing. When enough time has gone by, and everything uses the
!  * new mount() parameters, sys_mount() can then be cleaned up.
   *
   * We cannot mount a filesystem if it has active, used, or dirty inodes.
   * We also have to flush all inode-data for this device, as the new mount
!  * might need new info.
!  */
  
! int do_mount(kdev_t dev, const char * dev_name, const char * dir_name, const char * type, int flags, void * data)
  {
- 	struct inode * dir_i;
  	struct super_block * sb;
  	struct vfsmount *vfsmnt;
- 	int error;
  
  	if (!(flags &amp; MS_RDONLY) &amp;&amp; dev &amp;&amp; is_read_only(dev))
  		return -EACCES;
  		/*flags |= MS_RDONLY;*/
! 	error = namei(dir_name, &amp;dir_i);
! 	if (error)
! 		return error;
! 	if (dir_i-&gt;i_count != 1 || dir_i-&gt;i_mount) {
! 		iput(dir_i);
  		return -EBUSY;
! 	}
! 	if (!S_ISDIR(dir_i-&gt;i_mode)) {
! 		iput(dir_i);
  		return -ENOTDIR;
! 	}
! 	if (!fs_may_mount(dev)) {
! 		iput(dir_i);
  		return -EBUSY;
- 	}
  	sb = read_super(dev,type,flags,data,0);
! 	if (!sb) {
! 		iput(dir_i);
  		return -EINVAL;
! 	}
! 	if (sb-&gt;s_covered) {
! 		iput(dir_i);
  		return -EBUSY;
- 	}
  	vfsmnt = add_vfsmnt(dev, dev_name, dir_name);
  	if (vfsmnt) {
  		vfsmnt-&gt;mnt_sb = sb;
--- 672,722 ----
  	return 0;
  }
  
+ asmlinkage int sys_umount(char * name)
+ {
+ 	struct inode * inode;
+ 	int retval;
+ 
+ 	if (!suser())
+ 		return -EPERM;
+ 	retval = namei(name,&amp;inode);
+ 	if (retval) {
+ 		retval = lnamei(name,&amp;inode);
+ 		if (retval)
+ 			return retval;
+ 	}
+ 	return do_umounti(inode);
+ }
+ 
  /*
!  * do_mountdev() does the actual mounting after sys_mount has done the
!  * ugly parameter parsing. When enough time has gone by, and
!  * everything uses the new mount() parameters, sys_mount() can then be
!  * cleaned up.
   *
   * We cannot mount a filesystem if it has active, used, or dirty inodes.
   * We also have to flush all inode-data for this device, as the new mount
!  * might need new info.  */
  
! int do_mountdev(kdev_t dev, struct inode * dir_i, const char * dev_name, const char * dir_name, const char * type, int flags, void * data)
  {
  	struct super_block * sb;
  	struct vfsmount *vfsmnt;
  
  	if (!(flags &amp; MS_RDONLY) &amp;&amp; dev &amp;&amp; is_read_only(dev))
  		return -EACCES;
  		/*flags |= MS_RDONLY;*/
! 	if (dir_i-&gt;i_count != 1 || dir_i-&gt;i_mount)
  		return -EBUSY;
! 	if (!S_ISDIR(dir_i-&gt;i_mode))
  		return -ENOTDIR;
! 	if (!fs_may_mount(dev))
  		return -EBUSY;
  	sb = read_super(dev,type,flags,data,0);
! 	if (!sb)
  		return -EINVAL;
! 	if (sb-&gt;s_covered)
  		return -EBUSY;
  	vfsmnt = add_vfsmnt(dev, dev_name, dir_name);
  	if (vfsmnt) {
  		vfsmnt-&gt;mnt_sb = sb;
***************
*** 735,740 ****
--- 727,745 ----
  	return 0;		/* we don't iput(dir_i) - see umount */
  }
  
+ int do_mount(kdev_t dev, const char * dev_name, const char * dir_name, const char * type, int flags, void * data)
+ {
+ 	int error;
+ 	struct inode * dir_i;
+ 
+ 	error = namei(dir_name, &amp;dir_i);
+ 	if (error)
+ 		return error;
+ 	error = do_mountdev(dev, dir_i, dev_name, dir_name, type, flags, data);
+ 	if (error)
+ 		iput(dir_i);
+ 	return error;
+ }
  
  /*
   * Alters the mount flags of a mounted file system. Only the mount point
***************
*** 793,810 ****
  	*where = 0;
  	if (!data)
  		return 0;
! 
! 	vma = find_vma(current, (unsigned long) data);
! 	if (!vma || (unsigned long) data &lt; vma-&gt;vm_start)
! 		return -EFAULT;
! 	if (!(vma-&gt;vm_flags &amp; VM_READ))
! 		return -EFAULT;
! 	i = vma-&gt;vm_end - (unsigned long) data;
! 	if (PAGE_SIZE &lt;= (unsigned long) i)
  		i = PAGE_SIZE-1;
  	if (!(page = __get_free_page(GFP_KERNEL))) {
  		return -ENOMEM;
  	}
  	memcpy_fromfs((void *) page,data,i);
  	*where = page;
  	return 0;
--- 798,818 ----
  	*where = 0;
  	if (!data)
  		return 0;
! 	if (get_fs() != get_ds()) {
! 		vma = find_vma(current, (unsigned long) data);
! 		if (!vma || (unsigned long) data &lt; vma-&gt;vm_start)
! 			return -EFAULT;
! 		if (!(vma-&gt;vm_flags &amp; VM_READ))
! 			return -EFAULT;
! 		i = vma-&gt;vm_end - (unsigned long) data;
! 		if (PAGE_SIZE &lt;= (unsigned long) i)
! 			i = PAGE_SIZE-1;
! 	} else
  		i = PAGE_SIZE-1;
  	if (!(page = __get_free_page(GFP_KERNEL))) {
  		return -ENOMEM;
  	}
+ 
  	memcpy_fromfs((void *) page,data,i);
  	*where = page;
  	return 0;
***************
*** 825,839 ****
   * version that didn't understand them.
   */
  asmlinkage int sys_mount(char * dev_name, char * dir_name, char * type,
! 	unsigned long new_flags, void * data)
  {
! 	struct file_system_type * fstype;
! 	struct inode * inode;
! 	struct file_operations * fops;
! 	kdev_t dev;
  	int retval;
- 	const char * t;
- 	unsigned long flags = 0;
  	unsigned long page = 0;
  
  	if (!suser())
--- 833,842 ----
   * version that didn't understand them.
   */
  asmlinkage int sys_mount(char * dev_name, char * dir_name, char * type,
! 			 unsigned long new_flags, void * data)
  {
! 	struct inode * dir_inode;
  	int retval;
  	unsigned long page = 0;
  
  	if (!suser())
***************
*** 849,854 ****
--- 852,880 ----
  		free_page(page);
  		return retval;
  	}
+ 	retval = namei(dir_name, &amp;dir_inode);
+ 	if (retval)
+ 		return retval;
+ 	retval = do_mounti(dir_inode,dir_name,dev_name,type,new_flags,data);
+ 	if (retval)
+ 		iput(dir_inode);
+ 	return retval;
+ }
+ 
+ /* Mount on a given inode.  Don't iput() the mount point! */
+ int do_mounti(struct inode * dir_inode, const char * dir_name, 
+ 	      const char * dev_name, const char * type, 
+ 	      unsigned long new_flags, const void * data)
+ {
+ 	struct file_system_type * fstype;
+ 	struct inode * inode;
+ 	struct file_operations * fops;
+ 	dev_t dev;
+ 	int retval;
+ 	const char * t;
+ 	unsigned long flags = 0;
+ 	unsigned long page = 0;
+ 
  	retval = copy_mount_options (type, &amp;page);
  	if (retval &lt; 0)
  		return retval;
***************
*** 906,912 ****
  			return retval;
  		}
  	}
! 	retval = do_mount(dev,dev_name,dir_name,t,flags,(void *) page);
  	free_page(page);
  	if (retval &amp;&amp; fops &amp;&amp; fops-&gt;release)
  		fops-&gt;release(inode, NULL);
--- 932,939 ----
  			return retval;
  		}
  	}
! 	retval = do_mountdev(dev,dir_inode,dev_name,dir_name,
! 			     t,flags,(void *) page);
  	free_page(page);
  	if (retval &amp;&amp; fops &amp;&amp; fops-&gt;release)
  		fops-&gt;release(inode, NULL);
*** linux/fs/supermount/Makefile.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/Makefile	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,14 ----
+ #
+ # Makefile for the linux supermounting routines.
+ #
+ # Note! Dependencies are done automagically by 'make dep', which also
+ # removes any old dependencies. DON'T put your own dependencies here
+ # unless it's something special (ie not a .c file).
+ #
+ # Note 2! The CFLAGS definitions are now in the main makefile...
+ 
+ O_TARGET := supermount.o
+ O_OBJS	 := dir.o inode.o namei.o super.o
+ M_OBJS	 := $(O_TARGET)
+ 
+ include $(TOPDIR)/Rules.make
*** linux/fs/supermount/TODO.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/TODO	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,40 ----
+ Notes:
+ 
+ TODO:
+ 
+   Supermount directory inodes do auto-remount as root of the subfs.  Make
+   a mount option to restrict this behaviour to the root?
+ 
+   Make supermount_attach a special case of read_hidden_inode, not the other
+   way around.
+ 
+   Replace shadow inodes with shadow superblock?  Do release that way?
+ 
+   Unmount on suspend?  OK iff inode numbers on open directories will
+   be the same next time around!  (Normally true.)  Bad for performance, but
+   maybe necessary for ext2fs, for example.
+ 
+ Done:::
+ 
+   Sigh.  We can't rely on the one-to-one mapping of superinode to
+   subinode i_ino numbers any more.  Why not?  Well, what happens if we
+   remove and remount a medium?  We can end up with one process holding
+   a handle to an old, obsolete superinode, and a new process opening a
+   subinode with the same i_ino.  Well, we can do a quadratic hash on
+   the superinode numbers to avoid collisions.  Think about this!
+ 
+   * What happens when we do get an inode collision?  We rehash to make
+     another superinode the current one; the old inode remains as a
+     placeholder.  But then, what if the old inode becomes released?  A
+     subsequent attach may place the subinode under that old inode
+     instead of the new superinode.
+ 
+     OK: There is only ever one hidden/shadow connection between super
+     and sub inodes.  If that is broken, we can reestablish it from any
+     superinode we want to.  Previously valid superinodes will have to
+     rely on i_subino to get to their subinode (the subinode i_ino will
+     NOT change behind our backs, hopefully).  Such mappings should
+     only ever be one way, from superinode to subinode, done by
+     subiget().
+ 
+   Special handling of root directory to do auto remount.
*** linux/fs/supermount/dir.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/dir.c	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,97 ----
+ /*
+  *  linux/fs/supermount/dir.c
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  *  from
+  *
+  *  linux/fs/minix/dir.c
+  *  Copyright (C) 1991, 1992  Linus Torvalds
+  *
+  *  and
+  *
+  *  linux/fs/ext2/dir.c
+  *  Copyright (C) 1992, 1993, 1994, 1995  Remy Card
+  */
+ 
+ #include &lt;asm/segment.h&gt;
+ 
+ #include &lt;linux/errno.h&gt;
+ #include &lt;linux/kernel.h&gt;
+ #include &lt;linux/fs.h&gt;
+ #include &lt;linux/supermount_fs.h&gt;
+ #include &lt;linux/stat.h&gt;
+ 
+ static int supermount_dir_open (struct inode *, struct file *);
+ 
+ static struct file_operations supermount_dir_operations = {
+ 	NULL,			/* lseek - default */
+ 	NULL,			/* read */
+ 	NULL,			/* write - bad */
+ 	NULL,			/* readdir */
+ 	NULL,			/* select - default */
+ 	NULL,			/* ioctl */
+ 	NULL,			/* mmap */
+ 	supermount_dir_open,	/* Redirect to the subfs readdir() code */
+ 	NULL,			/* no special release code */
+ 	NULL,			/* fsync */
+ 	NULL,			/* fasync */
+ 	NULL,			/* check_media_change */
+ 	NULL			/* revalidate */
+ };
+ 
+ /*
+  * directories can handle most operations...  supermount/namei.c just
+  * passes them through to the underlying subfs, except for lookup().
+  */
+ struct inode_operations supermount_dir_iops = {
+ 	&amp;supermount_dir_operations,	/* default directory file-ops */
+ 	supermount_create,		/* create */
+ 	supermount_lookup,		/* lookup */
+ 	supermount_link,		/* link */
+ 	supermount_unlink,		/* unlink */
+ 	supermount_symlink,		/* symlink */
+ 	supermount_mkdir,		/* mkdir */
+ 	supermount_rmdir,		/* rmdir */
+ 	supermount_mknod,		/* mknod */
+ 	supermount_rename,		/* rename */
+ 	NULL,				/* readlink */
+ 	NULL,				/* follow_link */
+ 	NULL,				/* bmap */
+ 	NULL,				/* truncate */
+ 	supermount_permission,		/* permission */
+ 	NULL				/* smap */
+ };
+ 
+ 
+ /* When we open() a directory (for readdir), just rewrite the file
+    struct to point to the subfs inode, and let it handle all the
+    work. */
+ static int supermount_dir_open (struct inode * inode, struct file * file)
+ {
+ 	struct inode * subi;
+ 	int rc;
+ 	
+ 	if (file-&gt;f_mode &amp; 2)
+ 		return -EPERM;
+ 
+ 	supermount_debug ("dir_open inode %ld\n", inode-&gt;i_ino);
+ 	
+ 	subi = subiget(inode);
+ 	if (!subi)
+ 		return -ENOENT;
+ 
+ 	file-&gt;f_inode = subi;
+ 	file-&gt;f_op = subi-&gt;i_op ? subi-&gt;i_op-&gt;default_file_ops : NULL;
+ 	if (file-&gt;f_op &amp;&amp; file-&gt;f_op-&gt;open) {
+ 		rc = file-&gt;f_op-&gt;open(subi, file);
+ 		if (rc) {
+ 			iput(subi);
+ 			return rc;
+ 		}
+ 	}
+ 	iput(inode);
+ 	return 0;
+ }
+ 
*** linux/fs/supermount/file.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/file.c	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,21 ----
+ /*
+  *  linux/fs/supermount/file.c
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  */
+ 
+ #include &lt;asm/segment.h&gt;
+ #include &lt;asm/system.h&gt;
+ 
+ #include &lt;linux/errno.h&gt;
+ #include &lt;linux/fs.h&gt;
+ #include &lt;linux/supermount_fs.h&gt;
+ #include &lt;linux/fcntl.h&gt;
+ #include &lt;linux/sched.h&gt;
+ #include &lt;linux/stat.h&gt;
+ #include &lt;linux/locks.h&gt;
+ 
+ static void supermount_inode_release (struct inode *);
+ 
*** linux/fs/supermount/inode.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/inode.c	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,380 ----
+ /*
+  *  linux/fs/supermount/inode.c
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  *  from
+  *
+  *  linux/fs/minix/inode.c
+  *  Copyright (C) 1991, 1992  Linus Torvalds
+  *
+  *  and
+  *
+  *  linux/fs/ext2/inode.c
+  *  Copyright (C) 1992, 1993, 1994, 1995  Remy Card
+  *  and           1993  Stephen Tweedie
+  */
+ 
+ #include &lt;asm/segment.h&gt;
+ #include &lt;asm/system.h&gt;
+ 
+ #include &lt;linux/errno.h&gt;
+ #include &lt;linux/fs.h&gt;
+ #include &lt;linux/supermount_fs.h&gt;
+ #include &lt;linux/sched.h&gt;
+ #include &lt;linux/stat.h&gt;
+ #include &lt;linux/string.h&gt;
+ #include &lt;linux/locks.h&gt;
+ #include &lt;linux/mm.h&gt;
+ 
+ static void read_hidden_inode (struct inode *);
+ static void supermount_inode_open (struct inode *, int);
+ static void supermount_inode_write (struct inode *);
+ static void supermount_inode_release (struct inode *);
+ 
+ /* Deal with the shadow interface.  Whenever a subfs inode is
+    released, break the bi-directional link between them, and close and
+    iput the supermount inode.  */
+ 
+ struct inode_shadow_operations supermount_shadow_iops = {
+ 	supermount_inode_open,
+ 	supermount_inode_write,
+ 	supermount_inode_release,
+ };
+ 
+ void supermount_inode_open (struct inode *inode, int flag)
+ {
+ 	if (flag &amp; 2)
+ 		mark_subfs_dirty(inode-&gt;i_sb);
+ }
+ 
+ void supermount_inode_write (struct inode *inode)
+ {
+ 	mark_subfs_dirty(inode-&gt;i_sb);
+ }
+ 
+ void supermount_inode_release (struct inode *inode)
+ {
+ 	supermount_debug ("inode = %ld\n", inode-&gt;i_ino);
+ 	if (inode-&gt;u.supermount_i.i_hidden)
+ 		supermount_debug("subinode = %ld\n", 
+ 				 inode-&gt;u.supermount_i.i_hidden-&gt;i_ino);
+ 	
+ 	inode-&gt;u.supermount_i.i_hidden = NULL;
+ 	supermount_iclose(inode);
+ }
+ 
+ 
+ /* Do an iget on the appropriate subfs inode */
+ struct inode * subiget(struct inode * inode) 
+ {
+ 	struct inode * tmp;
+ 	supermount_debug("subiget inode %ld\n", inode-&gt;i_ino);
+ 
+ 	if (!S_ISDIR(inode-&gt;i_mode))
+ 		return 0;
+ 	if (supermount_media_check(inode-&gt;i_sb)) {
+ 		supermount_debug("media is invalid\n");
+ 		return 0;
+ 	}
+ 	
+ 	if (inode_is_obsolete(inode)) {
+ 		/* For obsolete directory with new mounted media ---
+                    return the new root subinode. */
+ 		if (inode-&gt;u.supermount_i.i_hidden) 
+ 			supermount_panic (inode-&gt;i_sb, "subiget", 
+ 					  "Hidden inode on obsolete inode %ld",
+ 					  inode-&gt;i_ino);
+ 		tmp = inode-&gt;i_sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted;
+ 		inode-&gt;u.supermount_i.i_subino = tmp-&gt;i_ino;
+ 		tmp-&gt;i_count++;
+ 		supermount_debug("mapping obsolete inode %ld to "
+ 				 "subroot inode %ld\n",
+ 				 inode-&gt;i_ino, tmp-&gt;i_ino);
+ 		return tmp;
+ 	}
+ 	
+ 	if (inode-&gt;u.supermount_i.i_hidden) {
+ 		inode-&gt;u.supermount_i.i_hidden-&gt;i_count++;
+ 		supermount_debug("inode %ld/%ld, found hidden, "
+ 				 "count now %d/%d\n",
+ 				 inode-&gt;i_ino,
+ 				 inode-&gt;u.supermount_i.i_hidden-&gt;i_ino,
+ 				 inode-&gt;i_count,
+ 				 inode-&gt;u.supermount_i.i_hidden-&gt;i_count);
+ 		return inode-&gt;u.supermount_i.i_hidden;
+ 	}
+ 	read_hidden_inode(inode);
+ 	if (!inode-&gt;u.supermount_i.i_hidden) {
+ 		supermount_debug("inode %ld, no subinode, count=%d\n",
+ 				 inode-&gt;i_ino, inode-&gt;i_count);
+ 		return 0;
+ 	}
+ 	
+ 	supermount_debug("inode %ld/%ld, found new, "
+ 			 "count now %d/%d\n",
+ 			 inode-&gt;i_ino,
+ 			 inode-&gt;u.supermount_i.i_hidden-&gt;i_ino,
+ 			 inode-&gt;i_count,
+ 			 inode-&gt;u.supermount_i.i_hidden-&gt;i_count);
+ 	return inode-&gt;u.supermount_i.i_hidden;
+ }
+ 
+ /* We sometimes do a lookup on a subinode and want to get back a
+    superinode in return, with a single iget() outstanding on both (not
+    counting the i_shadow reference).  supermount_attach generates the
+    superinode for a given subinode. */
+ struct inode * supermount_attach(struct super_block *sb, struct inode *inode) 
+ {
+ 	struct inode *tmp;
+ 	unsigned long new_ino, incr=1237;
+ 	
+ 	supermount_debug ("inode = %ld\n", inode-&gt;i_ino);
+ 	
+ 	if (inode-&gt;i_shadow) {
+ 		supermount_debug ("return existing shadow %ld, count %d/%d\n",
+ 				  inode-&gt;i_shadow-&gt;i_ino,
+ 				  inode-&gt;i_shadow-&gt;i_count, inode-&gt;i_count);
+ 		inode-&gt;i_shadow-&gt;i_count++;
+ 		return inode-&gt;i_shadow;
+ 	}
+ 	
+ 	/* The rules are a little different at the root. */
+ 	if (inode == sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted) {
+ 		tmp = sb-&gt;s_mounted;
+ 		supermount_debug ("return existing superfs root %ld, "
+ 				  "count %d/%d\n",
+ 				  tmp-&gt;i_ino, tmp-&gt;i_count, inode-&gt;i_count);
+ 		tmp-&gt;i_count++;
+ 		return tmp;
+ 	}
+ 
+ 	/* Find a new superinode, avoiding collisions with old
+            obsolete superinodes by a quadratic hash. */
+ 	new_ino = inode-&gt;i_ino;
+ 	for ( ; (tmp = iget(sb, new_ino)) &amp;&amp; tmp-&gt;i_count &gt; 1 &amp;&amp;
+ 			inode_is_obsolete(tmp); ) {
+ 		iput(tmp);
+ 		new_ino += incr;
+ 		new_ino &amp;= 0xffffff;
+ 		incr &lt;&lt;= 1; incr++;
+ 	}
+ 	
+ 	tmp-&gt;u.supermount_i.i_subino = inode-&gt;i_ino;
+ 	/* If we found a previously obsolete inode which is now no
+            longer used, we can safely remove the obsolesence flag. */
+ 	if (inode_is_obsolete(tmp)) {
+ 		tmp-&gt;u.supermount_i.i_sb_version = 
+ 			tmp-&gt;i_sb-&gt;u.supermount_sb.s_version;
+ 	}
+ 	
+ 	/* We have now done iget() on superi and subi.  Doing the
+            attachment may incur another iget() on the subinode. */
+ 	if (!tmp-&gt;u.supermount_i.i_hidden) {
+ 		read_hidden_inode(tmp);
+ 		iput(inode);
+ 	}
+ 	return tmp;
+ }
+ 
+ /* Supermount open/close inode.  These functions maintain the
+    superblock reference counts of active inodes; the subfs is
+    suspended when that count reaches zero.
+ 
+    Files are opened on any significant reference, and are not closed
+    until they become fully dereferenced (during the last iput).
+    Directories, on the other hand, are always closed unless they are
+    active and opened; a directory referenced as CWD is not open.
+ 
+    The difference is in the way the application gets given inodes.
+    For dirs and symlinks, it will be given the superinode to deal
+    with; for other file types, we return the subinode. */
+ 
+ 
+ void supermount_iopen(struct inode * inode)
+ {
+ 	supermount_debug ("inode %ld, count %d\n", 
+ 			  inode-&gt;i_ino, inode-&gt;i_count);
+ 	if (inode-&gt;i_sb-&gt;u.supermount_sb.s_state == SUPERMOUNT_UNMOUNTED)
+ 		supermount_panic (inode-&gt;i_sb, "supermount_iopen", 
+ 				  "opening inode on unmounted subfs");
+ 	if (!inode-&gt;u.supermount_i.i_counted) {
+ 		supermount_debug("Opened inode %ld\n", inode-&gt;i_ino);
+ 		inode-&gt;u.supermount_i.i_counted = 1;
+ 		if (!subfs_is_active(inode-&gt;i_sb)) {
+ 			supermount_debug ("going online.\n");
+ 			inode-&gt;i_sb-&gt;u.supermount_sb.s_state = 
+ 				SUPERMOUNT_ONLINE;
+ 		}
+ 		inode-&gt;i_sb-&gt;u.supermount_sb.s_opencount++;
+ 	}
+ }
+ 
+ void supermount_iclose(struct inode * inode)
+ {
+ 	supermount_debug ("inode %ld, count %d\n", 
+ 			  inode-&gt;i_ino, inode-&gt;i_count);
+ 	if (inode-&gt;u.supermount_i.i_counted) {
+ 		supermount_debug("Closed inode %ld\n", inode-&gt;i_ino);
+ 		inode-&gt;u.supermount_i.i_counted = 0;
+ 		inode-&gt;i_sb-&gt;u.supermount_sb.s_opencount--;
+ 		if (!subfs_is_active(inode-&gt;i_sb))
+ 			supermount_go_inactive(inode-&gt;i_sb);
+ 	}
+ }
+ 
+ void supermount_go_inactive(struct super_block *sb)
+ {
+ 	supermount_debug("Checking state\n");
+ 	if (!subfs_is_active(sb)) {
+ 		supermount_debug("going offline.\n");
+ 		sb-&gt;u.supermount_sb.s_state = 
+ 			SUPERMOUNT_SUSPENDED;
+ 		if (subfs_is_dirty(sb)) {
+ 			mark_subfs_clean(sb);
+ 			fsync_dev(sb-&gt;u.supermount_sb.s_subfs-&gt;s_dev);
+ 		}
+ 	}
+ }
+ 
+ static void read_hidden_inode (struct inode * inode)
+ {
+ 	struct super_block * sb;
+ 	struct inode * tmp;
+ 
+ 	supermount_debug("inode = %ld\n", inode-&gt;i_ino);
+ 	supermount_media_check(inode-&gt;i_sb);
+ 
+ 	if (inode-&gt;i_sb-&gt;u.supermount_sb.s_state ==
+ 	    SUPERMOUNT_UNMOUNTED) {
+ 		supermount_panic (inode-&gt;i_sb, "read_hidden_inode",
+ 				  "Trying to read inode on unmounted media");
+ 	}
+ 	sb=inode-&gt;i_sb-&gt;u.supermount_sb.s_subfs;
+ 	/* The root inode is a bit special.  For that one, the
+            subinode is the root of the subfs, and we can't guarantee
+            its inode number in advance. */
+ 	if (inode-&gt;i_ino == SUPERMOUNT_ROOT_INO) {
+ 		tmp = sb-&gt;s_mounted;
+ 		tmp-&gt;i_count++;
+ 	} else {
+ 		if (!inode-&gt;u.supermount_i.i_subino)
+ 			inode-&gt;u.supermount_i.i_subino = inode-&gt;i_ino;
+ 		tmp = iget(sb, inode-&gt;u.supermount_i.i_subino);
+ 	}
+ 	if (!tmp)
+ 		return;
+ 
+ 	/* If the inode is already linked to its superinode, don't do
+            any further processing.  Also, don't bother trying to
+            attach to the superinode if we are reading from an obsolete
+            superinode. */
+ 	if (tmp-&gt;i_shadow || inode_is_obsolete(inode))
+ 		return;
+ 	tmp-&gt;i_shadow = inode;
+ 	inode-&gt;u.supermount_i.i_hidden = tmp;
+ 	inode-&gt;i_count++;
+ 	supermount_iopen(inode);
+ 
+ 	inode-&gt;i_mode = tmp-&gt;i_mode;
+ 	inode-&gt;i_uid = tmp-&gt;i_uid;
+ 	inode-&gt;i_gid = tmp-&gt;i_gid;
+ 	inode-&gt;i_nlink = tmp-&gt;i_nlink;
+ 	inode-&gt;i_size = tmp-&gt;i_size;
+ 	inode-&gt;i_atime = tmp-&gt;i_atime;
+ 	inode-&gt;i_ctime = tmp-&gt;i_ctime;
+ 	inode-&gt;i_mtime = tmp-&gt;i_mtime;
+ 	inode-&gt;i_blksize = tmp-&gt;i_blksize;
+ 	inode-&gt;i_blocks = tmp-&gt;i_blocks;
+ 	inode-&gt;i_rdev = tmp-&gt;i_rdev;
+ 	inode-&gt;i_version = ++event;
+ 
+ 	if (S_ISDIR(inode-&gt;i_mode))
+ 		inode-&gt;i_op = &amp;supermount_dir_iops;
+ 	else
+ 		inode-&gt;i_op = NULL;
+ }
+ 
+ void supermount_read_inode (struct inode * inode)
+ {
+ 	supermount_debug ("inode = %ld\n", inode-&gt;i_ino);
+ 	
+ 	inode-&gt;i_shadow_op = &amp;supermount_shadow_iops;
+ 	inode-&gt;u.supermount_i.i_sb_version = 
+ 		inode-&gt;i_sb-&gt;u.supermount_sb.s_version;
+ 	
+ 	switch (inode-&gt;i_ino) {
+ 	case SUPERMOUNT_ROOT_INO:
+ 		if (inode-&gt;i_sb-&gt;u.supermount_sb.s_state !=
+ 		    SUPERMOUNT_UNMOUNTED) {
+ 			supermount_panic (inode-&gt;i_sb, "supermount_read_inode",
+ 					  "Help - trying to read root while "
+ 					  "already mounted!");
+ 		}
+ 		/* Fall through */
+ 	case SUPERMOUNT_HIDDEN_INO:
+ 		inode-&gt;i_mode = inode-&gt;i_sb-&gt;u.supermount_sb.s_default_mode;
+ 		inode-&gt;i_uid = 0;
+ 		inode-&gt;i_gid = 0;
+ 		inode-&gt;i_nlink = 1;
+ 		inode-&gt;i_size = 0;
+ 		inode-&gt;i_atime = CURRENT_TIME;
+ 		inode-&gt;i_ctime = CURRENT_TIME;
+ 		inode-&gt;i_mtime = CURRENT_TIME;
+ 		inode-&gt;i_blksize = inode-&gt;i_sb-&gt;s_blocksize;
+ 		inode-&gt;i_blocks = 0;
+ 		inode-&gt;i_version = ++event;
+ 		inode-&gt;i_op = (inode-&gt;i_ino == SUPERMOUNT_ROOT_INO)
+ 			? &amp;supermount_dir_iops : NULL;
+ 		return;
+ 	default:
+ 		;
+ 	}
+ }
+ 
+ void supermount_write_inode (struct inode * inode)
+ {
+ 	struct super_block *tmp;
+ 	tmp = inode-&gt;i_sb-&gt;u.supermount_sb.s_subfs;
+ 	
+ 	if (inode-&gt;u.supermount_i.i_hidden &amp;&amp;
+ 	    tmp &amp;&amp; tmp-&gt;s_op &amp;&amp; tmp-&gt;s_op-&gt;write_inode)
+ 		tmp-&gt;s_op-&gt;write_inode(inode-&gt;u.supermount_i.i_hidden);
+ 
+ 	mark_subfs_dirty(inode-&gt;i_sb);
+ }
+ 
+ int supermount_permission (struct inode * inode, int mask)
+ {
+ 	unsigned short mode;
+ 	struct inode *subi;
+ 
+ 	supermount_debug("inode %ld, mask 0%o\n", inode-&gt;i_ino, mask);
+ 
+ 	subi = subiget(inode);
+ 	if (!subi)
+ 		return -EIO;
+ 	if (subi-&gt;i_op &amp;&amp; subi-&gt;i_op-&gt;permission) {
+ 		int rc = subi-&gt;i_op-&gt;permission(subi, mask);
+ 		iput(subi);
+ 		return rc;
+ 	}
+ 	
+ 	mode = inode-&gt;i_mode;
+ 	/*
+ 	 * Special case, access is always granted for root
+ 	 */
+ 	if (fsuser()) {
+ 		iput(subi);
+ 		return 0;
+ 	} else if (current-&gt;fsuid == inode-&gt;i_uid)
+ 		mode &gt;&gt;= 6;
+ 	else if (in_group_p (inode-&gt;i_gid))
+ 		mode &gt;&gt;= 3;
+ 	iput(subi);
+ 	if (((mode &amp; mask &amp; S_IRWXO) == mask))
+ 		return 0;
+ 	else
+ 		return -EACCES;
+ }
*** linux/fs/supermount/namei.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/namei.c	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,347 ----
+ /*
+  *  linux/fs/supermount/namei.c
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  *  from
+  *
+  *  linux/fs/minix/namei.c
+  *  Copyright (C) 1991, 1992  Linus Torvalds
+  *
+  *  and
+  *
+  *  linux/fs/ext2/namei.c
+  *  Copyright (C) 1992, 1993, 1994, 1995  Remy Card
+  */
+ 
+ /* This file handles almost all of the normal filesystem running of
+    supermount.  We don't have to deal to much with the subfs
+    interface, since we just pass subinodes out to the application on
+    demand. */
+ 
+ #include &lt;asm/segment.h&gt;
+ #include &lt;linux/errno.h&gt;
+ #include &lt;linux/fs.h&gt;
+ #include &lt;linux/supermount_fs.h&gt;
+ #include &lt;linux/fcntl.h&gt;
+ #include &lt;linux/sched.h&gt;
+ #include &lt;linux/stat.h&gt;
+ #include &lt;linux/string.h&gt;
+ #include &lt;linux/locks.h&gt;
+ 
+ /* Attach a superinode to a subinode, and prepare a result for the
+    upper VFS layers.  We return the superinode for directories, and
+    the subinode for other file types.
+    */
+ static void attach_and_prepare(struct super_block *sb,
+ 			       struct inode *subi, struct inode **result)
+ {
+ 	struct inode *superi;
+ 	superi = supermount_attach(sb, subi);
+ 	/* We have now done iget() on superi and subi. */
+ 	
+ 	/* If the subfs inode is a directory or a symlink, then we
+ 	   need to deal with it ourselves, and only give back the
+ 	   superinode to the application.  Otherwise, we can just
+ 	   return the subfs inode. */
+ 	if (S_ISDIR(subi-&gt;i_mode)) {
+ 		superi-&gt;i_op = &amp;supermount_dir_iops;
+ 		iput(subi);
+ 		*result = superi;
+ 		return;
+ 	} else {
+ 		/* Not a directory-related inode, so we return the
+ 		   subfs inode to the upper layers.  We still need the
+ 		   supermount inode in that case, though, to maintain
+ 		   reference counts in the supermount superblock. */
+ 
+ 		iput(superi);
+ 		*result = subi;
+ 		return;
+ 	}
+ }
+ 
+ int supermount_lookup (struct inode * dir, const char * name, int len,
+ 		       struct inode ** result)
+ {
+ 	struct inode *subi, *subdir;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s\n",
+ 			  dir-&gt;i_ino, len, name);
+ 
+ 	*result = NULL;
+ 	if (!dir)
+ 		return -ENOENT;
+ 	if (!S_ISDIR(dir-&gt;i_mode)) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!(subdir = subiget(dir)))  {
+ 		/* This now becomes the *easy* case. :-) */
+ 		iput (dir);
+ 		return -EIO;
+ 	}
+ 
+ 	rc = subdir-&gt;i_op-&gt;lookup(subdir, name, len, &amp;subi);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput (dir);
+ 	if (rc)
+ 		return rc;
+ 	/* It worked, so now create a shadow supermount inode for the
+            result... */
+ 	attach_and_prepare(dir-&gt;i_sb, subi, result);
+ 	return 0;
+ }
+ 
+ int supermount_create (struct inode * dir,const char * name, int len, int mode,
+ 		       struct inode ** result)
+ {
+ 	struct inode * inode, * subi;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s, mode = %o\n",
+ 			  dir-&gt;i_ino, len, name, mode);
+ 
+ 	*result = NULL;
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;create) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;create(inode, name, len, mode, &amp;subi);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	if (rc)
+ 		return rc;
+ 	attach_and_prepare(dir-&gt;i_sb, subi, result);
+ 	return 0;
+ }
+ 
+ int supermount_mknod (struct inode * dir, const char * name, int len, int mode,
+ 		      int rdev)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s, mode = %o\n",
+ 			  dir-&gt;i_ino, len, name, mode);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;mknod) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;mknod(inode, name, len, mode, rdev);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ int supermount_mkdir (struct inode * dir, const char * name, int len, int mode)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s, mode = %o\n",
+ 			  dir-&gt;i_ino, len, name, mode);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;mkdir) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;mkdir(inode, name, len, mode);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ int supermount_rmdir (struct inode * dir, const char * name, int len)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s\n",
+ 			  dir-&gt;i_ino, len, name);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;rmdir) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;rmdir(inode, name, len);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ int supermount_unlink (struct inode * dir, const char * name, int len)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s\n",
+ 			  dir-&gt;i_ino, len, name);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;unlink) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;unlink(inode, name, len);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ int supermount_symlink (struct inode * dir, const char * name, int len,
+ 			const char * symname)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s, link = %s\n",
+ 			  dir-&gt;i_ino, len, name, symname);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;symlink) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;symlink(inode, name, len, symname);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ /* This probably won't work because higher levels will complain about
+    cross-device links. */
+ int supermount_link (struct inode * oldinode, struct inode * dir,
+ 		     const char * name, int len)
+ {
+ 	struct inode * inode;
+ 	int rc;
+ 	
+ 	supermount_debug ("inode = %ld, name = %*s, link to inode %ld\n",
+ 			  dir-&gt;i_ino, len, name, oldinode-&gt;i_ino);
+ 
+ 	if (!dir)
+ 		return -ENOENT;
+ 	inode = subiget(dir);
+ 	if (!inode) {
+ 		iput(dir);
+ 		return -ENOENT;
+ 	}
+ 	if (!inode-&gt;i_op || !inode-&gt;i_op-&gt;link) {
+ 		iput(dir);
+ 		iput(inode);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = inode-&gt;i_op-&gt;link(oldinode, inode, name, len);
+ 	mark_subfs_dirty(dir-&gt;i_sb);
+ 	supermount_go_inactive(dir-&gt;i_sb);
+ 	iput(dir);
+ 	return rc;
+ }
+ 
+ int supermount_rename (struct inode * old_dir, const char * old_name, 
+ 		       int old_len,
+ 		       struct inode * new_dir, const char * new_name, 
+ 		       int new_len)
+ {
+ 	struct inode * old_subi, * new_subi;
+ 	int rc;
+ 	
+ 	supermount_debug ("from inode %ld, %*s to inode %ld, %*s\n",
+ 			  old_dir-&gt;i_ino, old_len, old_name,
+ 			  new_dir-&gt;i_ino, new_len, new_name);
+ 
+ 	if (!old_dir || !new_dir)
+ 		return -ENOENT;
+ 	old_subi = subiget(old_dir);
+ 	if (!old_subi) {
+ 		iput(old_dir);
+ 		iput(new_dir);
+ 		return -ENOENT;
+ 	}
+ 	new_subi = subiget(new_dir);
+ 	if (!new_subi) {
+ 		iput(old_dir);
+ 		iput(new_dir);
+ 		iput(old_subi);
+ 		return -ENOENT;
+ 	}
+ 
+ 	if (!old_subi-&gt;i_op || !old_subi-&gt;i_op-&gt;rename) {
+ 		iput(old_dir);
+ 		iput(new_dir);
+ 		iput(old_subi);
+ 		iput(new_subi);
+ 		return -EPERM;
+ 	}
+ 	
+ 	rc = old_subi-&gt;i_op-&gt;rename(old_subi, old_name, old_len,
+ 				    new_subi, new_name, new_len);
+ 	mark_subfs_dirty(old_dir-&gt;i_sb);
+ 	supermount_go_inactive(old_dir-&gt;i_sb);
+ 	iput(old_dir);
+ 	iput(new_dir);
+ 	return rc;
+ }
*** linux/fs/supermount/super.c.~1~	Thu May 30 15:49:07 1996
--- linux/fs/supermount/super.c	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,430 ----
+ /*
+  *  linux/fs/supermount/super.c
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  *  from
+  *
+  *  linux/fs/minix/inode.c
+  *  Copyright (C) 1991, 1992  Linus Torvalds
+  *
+  *  and
+  *
+  *  linux/fs/ext2/super.c
+  *  Copyright (C) 1992, 1993, 1994, 1995  Remy Card
+  */
+ 
+ #include &lt;stdarg.h&gt;
+ 
+ #include &lt;asm/segment.h&gt;
+ #include &lt;asm/system.h&gt;
+ 
+ #include &lt;linux/errno.h&gt;
+ #include &lt;linux/fs.h&gt;
+ #include &lt;linux/supermount_fs.h&gt;
+ #include &lt;linux/malloc.h&gt;
+ #include &lt;linux/sched.h&gt;
+ #include &lt;linux/stat.h&gt;
+ #include &lt;linux/string.h&gt;
+ #include &lt;linux/locks.h&gt;
+ #include &lt;linux/major.h&gt;
+ 
+ /* From fs/super.c */
+ extern int do_umount(kdev_t);
+ 
+ #ifdef SUPERMOUNT_DEBUG
+ char supermount_debug_enable = 0;
+ #endif
+ 
+ static struct super_operations supermount_sops = { 
+ 	supermount_read_inode,
+ 	NULL,
+ 	supermount_write_inode,
+ 	NULL,				/* put_inode */
+ 	supermount_put_super,
+ 	supermount_write_super,
+ 	supermount_statfs,
+ 	NULL,				 /* supermount_remount */
+ };
+ 
+ static char error_buf[1024];
+ 
+ /* Mount and mount the hidden fs */
+ static void umount_subfs(struct super_block *);
+ 
+ void supermount_error (struct super_block * sb, const char * function,
+ 		       const char * fmt, ...)
+ {
+ 	va_list args;
+ 
+ 	va_start (args, fmt);
+ 	vsprintf (error_buf, fmt, args);
+ 	va_end (args);
+ 	printk (KERN_CRIT "SUPERMOUNT error (device %d/%d): %s: %s\n",
+ 		MAJOR(sb-&gt;s_dev), MINOR(sb-&gt;s_dev), function, error_buf);
+ 	/* @@ Do we want to do any special error handling here? */
+ }
+ 
+ NORET_TYPE void supermount_panic (struct super_block * sb, const char * function,
+ 			    const char * fmt, ...)
+ {
+ 	va_list args;
+ 
+ 	va_start (args, fmt);
+ 	vsprintf (error_buf, fmt, args);
+ 	va_end (args);
+ 	panic ("SUPERMOUNT panic (device %d/%d): %s: %s\n",
+ 	       MAJOR(sb-&gt;s_dev), MINOR(sb-&gt;s_dev), function, error_buf);
+ }
+ 
+ void supermount_warning (struct super_block * sb, const char * function,
+ 		   const char * fmt, ...)
+ {
+ 	va_list args;
+ 
+ 	va_start (args, fmt);
+ 	vsprintf (error_buf, fmt, args);
+ 	va_end (args);
+ 	printk (KERN_WARNING "SUPERMOUNT-fs warning (device %d/%d): %s: %s\n",
+ 		MAJOR(sb-&gt;s_dev), MINOR(sb-&gt;s_dev), function, error_buf);
+ }
+ 
+ /* Release the superblock and any resources it has reserved */
+ void supermount_put_super (struct super_block * sb)
+ {
+ 	lock_super (sb);
+ 	if (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED)
+ 		umount_subfs (sb);
+ 	sb-&gt;s_dev = 0;
+ 	unlock_super (sb);
+ }
+ 
+ 
+ static int copy_option(const char **option, const char *val)
+ {
+ 	char *tmp;
+ 	supermount_debug ("assigning value \"%s\"\n", val);
+ 	if (!val || !*val)
+ 		return -EINVAL;
+ 	tmp = (char *) kmalloc(1 + strlen(val), GFP_KERNEL);
+ 	if (!tmp)
+ 		return -ENOMEM;
+ 	strcpy(tmp, val);
+ 	*option = tmp;
+ 	return 0;
+ }
+ 
+ /*
+  * This function has been shamelessly adapted from the msdos fs
+  */
+ static int parse_options (char * options, struct super_block *sb)
+ {
+ 	char * this_char;
+ 	char * value;
+ 	int rc;
+ 	
+ 	if (!options)
+ 		return 0;
+ 	while ((this_char = options)) {
+ 		if (!strncmp(this_char, "--,", 3))
+ 			this_char += 2;
+ 		if (*this_char == ',') {
+ 			/* An empty option, or the option "--",
+ 			   introduces options to be passed through to
+ 			   the subfs */
+ 			supermount_debug ("assigning remainder\n");
+ 			return copy_option(&amp;sb-&gt;u.supermount_sb.s_data,
+ 					   ++this_char);
+ 		}
+ 		if ((options = strchr (this_char, ',')))
+ 			*options++ = 0;
+ 		
+ 		if ((value = strchr (this_char, '=')) != NULL)
+ 			*value++ = 0;
+ 
+ 		supermount_debug ("parsing option \"%s\"\n", this_char);
+ 		if (!strcmp (this_char, "fs")) {
+ 			rc = copy_option(&amp;sb-&gt;u.supermount_sb.s_type, value);
+ 			if (rc) return rc;
+ 		} else if (!strcmp (this_char, "dev")) {
+ 			rc = copy_option(&amp;sb-&gt;u.supermount_sb.s_devname, 
+ 					 value);
+ 			if (rc) return rc;
+ 		} else if (!strcmp (this_char, "debug")) {
+ 			supermount_debug_enable = 1;
+ 		} else {
+ 			printk ("supermount: "
+ 				"Unrecognized mount option %s\n", this_char);
+ 			return -EINVAL;
+ 		}
+ 	}
+ 	return 0;
+ }
+ 
+ /* read_super: the main mount() entry point into the VFS layer. */
+ struct super_block * supermount_read_super (struct super_block * sb, 
+ 					    void * data,
+ 					    int silent)
+ {
+ 	sb-&gt;s_blocksize = 1024;
+ 	sb-&gt;s_blocksize_bits = 10;
+ 	sb-&gt;s_magic = SUPERMOUNT_SUPER_MAGIC;
+ 	sb-&gt;s_op = &amp;supermount_sops;
+ 	unlock_super(sb);
+ 	sb-&gt;u.supermount_sb.s_state = SUPERMOUNT_UNMOUNTED;
+ 	sb-&gt;u.supermount_sb.s_default_mode = 0111 | S_IFDIR;
+ 	sb-&gt;u.supermount_sb.s_mflags = sb-&gt;s_flags &amp; (MS_REMOUNT - 1);
+ 	sb-&gt;u.supermount_sb.s_data = NULL;
+ 	sb-&gt;u.supermount_sb.s_undermount = NULL;
+ 	sb-&gt;u.supermount_sb.s_subfs = NULL;
+ 	sb-&gt;u.supermount_sb.s_opencount = 0;
+ 	sb-&gt;u.supermount_sb.s_dirty = 0;
+ 	sb-&gt;u.supermount_sb.s_type = NULL;
+ 	sb-&gt;u.supermount_sb.s_devname = NULL;
+ 
+ 	if (parse_options ((char *) data, sb)) {
+ 		sb-&gt;s_dev = 0;
+ 		return NULL;
+ 	}
+ 	if (!sb-&gt;u.supermount_sb.s_type)
+ 		copy_option(&amp;sb-&gt;u.supermount_sb.s_type, "msdos");
+ 	if (!sb-&gt;u.supermount_sb.s_devname)
+ 		copy_option(&amp;sb-&gt;u.supermount_sb.s_devname, "/dev/fd0");
+ 
+ 	sb-&gt;s_flags = sb-&gt;u.supermount_sb.s_mflags;
+ 	if (!(sb-&gt;s_mounted = iget(sb, SUPERMOUNT_ROOT_INO))) {
+ 		sb-&gt;s_dev = 0;
+ 		supermount_error (sb, "supermount_read_super",
+ 				  "get root inode failed\n");
+ 		return NULL;
+ 	}
+ 	return sb;
+ }
+ 
+ void supermount_write_super (struct super_block * sb)
+ {
+ 	supermount_media_check(sb);
+ 	if (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED) {
+ 		struct super_block *tmp = sb-&gt;u.supermount_sb.s_subfs;
+ 		if (tmp &amp;&amp; tmp-&gt;s_op &amp;&amp; tmp-&gt;s_op-&gt;write_super)
+ 			tmp-&gt;s_op-&gt;write_super(tmp);
+ 	}
+ 	sb-&gt;s_dirt = 0;
+ }
+ 
+ #if 0
+ int supermount_remount (struct super_block * sb, int * flags, char * data)
+ {
+ }
+ #endif /* 0 */
+ 
+ void supermount_statfs (struct super_block * sb, struct statfs * buf, 
+ 			int bufsize)
+ {
+ 	unsigned short fs;
+ 	struct statfs tmp;
+ 	supermount_media_check(sb);
+ 
+ 	if (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED) {
+ 		struct super_block * tmpsb = 
+ 			sb-&gt;u.supermount_sb.s_undermount-&gt;i_mount-&gt;i_sb;
+ 		fs = get_fs();
+ 		set_fs(KERNEL_DS);
+ 		if (tmpsb-&gt;s_op &amp;&amp; tmpsb-&gt;s_op-&gt;statfs)
+ 			tmpsb-&gt;s_op-&gt;statfs(tmpsb, &amp;tmp, sizeof(tmp));
+ 		set_fs(fs);
+ 	} else {
+ 		tmp.f_bsize = sb-&gt;s_blocksize;
+ 		tmp.f_blocks = 0;
+ 		tmp.f_bfree = 0;
+ 		tmp.f_bavail = 0;
+ 		tmp.f_files = 0;
+ 		tmp.f_ffree = 0;
+ 		tmp.f_namelen = 0;
+ 	}
+ 	tmp.f_type = SUPERMOUNT_SUPER_MAGIC;
+ 	memcpy_tofs(buf, &amp;tmp, bufsize);
+ }
+ 
+ /* Check for media change, but without invalidating buffers and inodes */
+ static int just_check_disk_change(dev_t dev)
+ {
+ 	if (!query_disk_change(dev))
+ 		return 0;
+ 	supermount_debug("Disk change detected on device %d/%d\n",
+ 			 MAJOR(dev), MINOR(dev));
+ 	return 1;
+ }
+ 
+ static void umount_subfs(struct super_block *sb)
+ {
+ 	int retval;
+ 	struct inode *inode, *subi;
+ 	
+ 	supermount_debug("Trying to unmount device %s.\n",
+ 			 sb-&gt;u.supermount_sb.s_devname);
+ 	
+ 	/* Detach the subfs from the supermount root inode */
+ 	inode = sb-&gt;s_mounted;
+ 	/* Inode may not be set if we are currently unmounting the superfs */
+ 	if (inode) {
+ 		subi = inode-&gt;u.supermount_i.i_hidden;
+ 		if (subi) {
+ 			subi-&gt;i_shadow = 0;
+ 			inode-&gt;u.supermount_i.i_hidden = 0;
+ 			iput(inode);
+ 		}
+ 	}
+ 		
+ 	if (sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted-&gt;i_count != 1)
+ 		supermount_panic (sb, "umount_subfs",
+ 				  "subfs root i_count = %d, should be 1\n",
+ 				  sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted-&gt;i_count);
+ 	if (sb-&gt;u.supermount_sb.s_undermount-&gt;i_count != 1)
+ 		supermount_panic (sb, "umount_subfs",
+ 				  "undermount i_count = %d, should be 1\n",
+ 				  sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted-&gt;i_count);
+ 
+ 	sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted-&gt;i_count++;
+ 	sb-&gt;u.supermount_sb.s_state = SUPERMOUNT_UNMOUNTED;
+ 	retval = do_umounti(sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted);
+ 	if (retval)
+ 		supermount_panic (sb, "umount_subfs",
+ 				  "Help - can't umount subfs!!!");
+ 	supermount_debug("subfs is unmounted.\n");
+ 	sb-&gt;u.supermount_sb.s_undermount = 0;
+ 	sb-&gt;u.supermount_sb.s_version = ++event;
+ 	sb-&gt;u.supermount_sb.s_subfs = 0;
+ 	sb-&gt;s_flags = sb-&gt;u.supermount_sb.s_mflags;
+ 	if (inode)
+ 		inode-&gt;i_mode = sb-&gt;u.supermount_sb.s_default_mode;
+ }
+ 
+ /* Return 0 (OK) if medium is valid. */
+ int supermount_media_check(struct super_block * sb) 
+ {
+ 	int retval;
+ 	unsigned short fs;
+ 
+ 	/* If there are still files open, we never bother checking the
+            medium. */
+ 	if (sb-&gt;u.supermount_sb.s_subfs &amp;&amp; 
+ 	    subfs_is_active(sb)) {
+ 		supermount_debug ("subfs is active.\n");
+ 		return 0;
+ 	}
+ 
+ 	supermount_debug ("starting (%sactive now)\n",
+ 			  (sb-&gt;u.supermount_sb.s_subfs &amp;&amp;
+ 			   subfs_is_active(sb)) ?
+ 			  "" : "not ");
+ 	
+ 	lock_super(sb);
+ 
+ 	/* Are we checking for mount or unmount/remount? */
+ 	if (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED) {
+ 		/* Already mounted --- check for disk change or
+ 		   disk not present */
+ 		int dev = sb-&gt;u.supermount_sb.s_subfs-&gt;s_dev;
+ 		if (!just_check_disk_change(dev)) {
+ 			unlock_super(sb);
+ 			return 0;
+ 		}
+ 		
+ 		/* We have a disk change!  Unmount the subfs */
+ 		supermount_debug ("trying to unmount\n");
+ 		umount_subfs(sb);
+ 		/* The call to just_check_disk_change may clear the media-
+ 		   changed flag on the device, so we need to force a media
+ 		   invalidation.  We don't want to do this before unmounting
+ 		   the subfs, naturally! */
+ 		invalidate_media(dev);
+ 		/* Now we are unmounted; fall through to the next check. */
+ 	}
+ 	
+ 	if (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED) {
+ 		unlock_super(sb);
+ 		return 0;
+ 	}
+ 	
+ 	/* OK, we're unmounted now --- can we remount?  Please? */
+ 	if (!sb-&gt;u.supermount_sb.s_undermount) {
+ 		sb-&gt;u.supermount_sb.s_undermount =
+ 			iget(sb, SUPERMOUNT_HIDDEN_INO);
+ 		if (!sb-&gt;u.supermount_sb.s_undermount)
+ 			supermount_panic (sb, "supermount_media_check",
+ 					  "Can't get root hidden inode!");
+ 		sb-&gt;u.supermount_sb.s_undermount-&gt;i_flags |= S_UNBOUND;
+ 	}
+ 
+ 	sb-&gt;u.supermount_sb.s_version = ++event;
+ 	sb-&gt;s_mounted-&gt;u.supermount_i.i_sb_version = event;
+ 	supermount_debug ("trying to mount\n");
+ 	supermount_debug ("fs=%s, dev=%s, data=%s, flags=%08lx\n",
+ 			  sb-&gt;u.supermount_sb.s_type,
+ 			  sb-&gt;u.supermount_sb.s_devname,
+ 			  sb-&gt;u.supermount_sb.s_data,
+ 			  sb-&gt;s_flags);
+ 	fs = get_fs();
+ 	set_fs(KERNEL_DS);
+ 	sb-&gt;s_flags = sb-&gt;u.supermount_sb.s_mflags,
+ 		retval = do_mounti(sb-&gt;u.supermount_sb.s_undermount,
+ 				   "&lt;supermount&gt;",
+ 				   sb-&gt;u.supermount_sb.s_devname,
+ 				   sb-&gt;u.supermount_sb.s_type,
+ 				   sb-&gt;s_flags | MS_MGC_VAL,
+ 				   sb-&gt;u.supermount_sb.s_data);
+ 	if (retval == -EROFS &amp;&amp; !(sb-&gt;u.supermount_sb.s_mflags &amp; MS_RDONLY)) {
+ 		/* OK, that failed, so try it readonly */
+ 		sb-&gt;s_flags |= MS_RDONLY;
+ 		retval = do_mounti(sb-&gt;u.supermount_sb.s_undermount,
+ 				   "&lt;supermount&gt;",
+ 				   sb-&gt;u.supermount_sb.s_devname,
+ 				   sb-&gt;u.supermount_sb.s_type,
+ 				   sb-&gt;s_flags | MS_MGC_VAL,
+ 				   sb-&gt;u.supermount_sb.s_data);
+ 	}
+ 	set_fs(fs);
+ 	
+ 	unlock_super(sb);
+ 	if (retval) {
+ 		sb-&gt;s_flags = sb-&gt;u.supermount_sb.s_mflags;
+ 		iput(sb-&gt;u.supermount_sb.s_undermount);
+ 		sb-&gt;u.supermount_sb.s_undermount = 0;
+ 		supermount_debug ("Mount failed, errno %d\n", -retval);
+ 		return 1;
+ 	}
+ 	/* Hey --- success!!! */
+ 	sb-&gt;u.supermount_sb.s_subfs = sb-&gt;u.supermount_sb.s_undermount
+ 		-&gt;i_mount-&gt;i_sb;
+ 	if (!sb-&gt;u.supermount_sb.s_subfs-&gt;s_mounted)
+ 		supermount_panic (sb, "supermount_media_check", 
+ 				  "Mounted subfs has no root inode!");
+ 	sb-&gt;u.supermount_sb.s_state = SUPERMOUNT_SUSPENDED;
+ 	supermount_debug ("Mount succeeded!\n");
+ 	/* For counting open inodes on the subfs, we rely on the fact
+            that the root inode is always exactly one count.  So make
+            sure we guarantee it is always open! */
+ 	supermount_iopen(sb-&gt;s_mounted);
+ 	sb-&gt;s_mounted-&gt;i_flags |= S_UNBOUND;
+ 	return 0;
+ }
+ 
+ /* Check whether an inode still belongs to valid medium. */
+ int supermount_check_inode(struct inode * inode)
+ {
+ 	supermount_debug ("inode = %ld\n", inode-&gt;i_ino);
+ 	
+ 	if (supermount_media_check(inode-&gt;i_sb))
+ 		return 1;
+ 	if (inode_is_obsolete(inode)) {
+ 		/* What happens if we remount an old disk, and get
+                    back the same superinode number?  subiget() will
+                    handle it through the i_subino field, and
+                    supermount_attach will avoid reusing the old
+                    inode. */
+ 		return 1;
+ 	}
+ 	return 0;
+ }
*** linux/include/linux/fs.h.~1~	Thu May 30 15:49:07 1996
--- linux/include/linux/fs.h	Thu May 30 15:22:31 1996
***************
*** 72,77 ****
--- 72,81 ----
  #define S_WRITE		128	/* Write on file/directory/symlink */
  #define S_APPEND	256	/* Append-only file */
  #define S_IMMUTABLE	512	/* Immutable file */
+ #define S_UNBOUND	1024	/* inode is not bound to user space,
+ 				   and so the filesystem may be
+ 				   unmounted even if this inode is in
+ 				   use. */
  
  /*
   * Flags that can be altered by MS_REMOUNT
***************
*** 101,106 ****
--- 105,111 ----
  #define IS_WRITABLE(inode) ((inode)-&gt;i_flags &amp; S_WRITE)
  #define IS_APPEND(inode) ((inode)-&gt;i_flags &amp; S_APPEND)
  #define IS_IMMUTABLE(inode) ((inode)-&gt;i_flags &amp; S_IMMUTABLE)
+ #define IS_UNBOUND(inode) ((inode)-&gt;i_flags &amp; S_UNBOUND)
  
  /* the read-only stuff doesn't really belong here, but any other place is
     probably as bad and I don't want to create yet another include file. */
***************
*** 214,219 ****
--- 219,225 ----
  }
  
  #include &lt;linux/pipe_fs_i.h&gt;
+ #include &lt;linux/supermount_fs_i.h&gt;
  #include &lt;linux/minix_fs_i.h&gt;
  #include &lt;linux/ext_fs_i.h&gt;
  #include &lt;linux/ext2_fs_i.h&gt;
***************
*** 282,287 ****
--- 288,295 ----
  	unsigned long	i_nrpages;
  	struct semaphore i_sem;
  	struct inode_operations *i_op;
+ 	struct inode * i_shadow;
+ 	struct inode_shadow_operations * i_shadow_op;
  	struct super_block *i_sb;
  	struct wait_queue *i_wait;
  	struct file_lock *i_flock;
***************
*** 303,308 ****
--- 311,317 ----
  	unsigned short i_writecount;
  	union {
  		struct pipe_inode_info pipe_i;
+ 		struct supermount_inode_info supermount_i;
  		struct minix_inode_info minix_i;
  		struct ext_inode_info ext_i;
  		struct ext2_inode_info ext2_i;
***************
*** 400,405 ****
--- 409,415 ----
  
  extern int fasync_helper(struct inode *, struct file *, int, struct fasync_struct **);
  
+ #include &lt;linux/supermount_fs_sb.h&gt;
  #include &lt;linux/minix_fs_sb.h&gt;
  #include &lt;linux/ext_fs_sb.h&gt;
  #include &lt;linux/ext2_fs_sb.h&gt;
***************
*** 429,434 ****
--- 439,445 ----
  	struct inode * s_mounted;
  	struct wait_queue * s_wait;
  	union {
+ 		struct supermount_sb_info supermount_sb;
  		struct minix_sb_info minix_sb;
  		struct ext_sb_info ext_sb;
  		struct ext2_sb_info ext2_sb;
***************
*** 489,494 ****
--- 500,511 ----
  	int (*smap) (struct inode *,int);
  };
  
+ struct inode_shadow_operations {
+ 	void (*open) (struct inode *, int);
+ 	void (*write) (struct inode *);
+ 	void (*release) (struct inode *);
+ };
+ 
  struct super_operations {
  	void (*read_inode) (struct inode *);
  	int (*notify_change) (struct inode *, struct iattr *);
***************
*** 598,606 ****
--- 615,625 ----
  }
  
  extern int check_disk_change(kdev_t dev);
+ extern int query_disk_change(kdev_t dev);
  extern void invalidate_inodes(kdev_t dev);
  extern void invalidate_inode_pages(struct inode *);
  extern void invalidate_buffers(kdev_t dev);
+ extern void invalidate_media(kdev_t dev);
  extern int floppy_is_wp(int minor);
  extern void sync_inodes(kdev_t dev);
  extern void sync_dev(kdev_t dev);
***************
*** 659,664 ****
--- 678,686 ----
  
  extern void show_buffers(void);
  extern void mount_root(void);
+ extern int do_mounti(struct inode *_inode, const char *, const char *, 
+ 		     const char *, unsigned long, const void *);
+ extern int do_umounti(struct inode *);
  
  #ifdef CONFIG_BLK_DEV_INITRD
  extern kdev_t real_root_dev;
*** linux/include/linux/supermount_fs.h.~1~	Thu May 30 15:49:07 1996
--- linux/include/linux/supermount_fs.h	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,165 ----
+ /*
+  *  linux/include/linux/supermount_fs.h
+  *
+  *  Defines and strutures for the dynamic remounting of removable media
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  *  from
+  *
+  *  linux/include/linux/minix_fs.h
+  *  Copyright (C) 1991, 1992  Linus Torvalds
+  *
+  *  and
+  *
+  *  linux/include/linux/ext2_fs.h
+  *  Copyright (C) 1992, 1993, 1994, 1995  Remy Card
+  */
+ 
+ #ifndef _LINUX_SUPERMOUNT_FS_H
+ #define _LINUX_SUPERMOUNT_FS_H
+ 
+ #include &lt;linux/types.h&gt;
+ 
+ #define SUPERMOUNT_DEBUG
+ 
+ #define SUPERMOUNT_VERSION		"0.4"
+ 
+ /*
+  * Debug code
+  */
+ #ifdef SUPERMOUNT_DEBUG
+  extern char supermount_debug_enable;
+ 
+  #define supermount_debug(f, a...) \
+ 	{ \
+ 		if (supermount_debug_enable) { \
+ 			printk ("SUPERMOUNT DEBUG (%s, %d): %s: ", \
+ 				__FILE__, __LINE__, __FUNCTION__); \
+ 			printk (f, ## a); \
+ 		} \
+ 	}
+ #else
+  #define supermount_debug(f, a...)	/**/
+ #endif
+ 
+ /*
+  * Special inodes numbers
+  */
+ #define SUPERMOUNT_HIDDEN_INO		 0	/* Hidden inode for
+ 						   sub-mounting */
+ #define SUPERMOUNT_ROOT_INO		 1	/* Root inode */
+ 
+ /*
+  * The supermount superblock magic number
+  */
+ #define SUPERMOUNT_SUPER_MAGIC	0x9fa1
+ 
+ #ifdef __KERNEL__
+ /*
+  * Function prototypes
+  */
+ 
+ /*
+  * Ok, these declarations are also in &lt;linux/kernel.h&gt; but none of the
+  * supermount source programs needs to include it so they are duplicated here.
+  */
+ #if __GNUC__ &lt; 2 || (__GNUC__ == 2 &amp;&amp; __GNUC_MINOR__ &lt; 5)
+ # define NORET_TYPE    __volatile__
+ # define ATTRIB_NORET  /**/
+ # define NORET_AND     /**/
+ #else
+ # define NORET_TYPE    /**/
+ # define ATTRIB_NORET  __attribute__((noreturn))
+ # define NORET_AND     noreturn,
+ #endif
+ 
+ /* How to test if a supermount filesystem is active or not: */
+ static inline int subfs_is_active(struct super_block *sb)
+ {
+ 	/* The subfs is deemed inactive iff only the root is open, and
+            the its i_count is one.  */
+ 	return (sb-&gt;u.supermount_sb.s_state != SUPERMOUNT_UNMOUNTED &amp;&amp;
+ 		(sb-&gt;u.supermount_sb.s_opencount &gt; 1 ||
+ 		 sb-&gt;u.supermount_sb.s_undermount-&gt;i_mount-&gt;i_count &gt; 1));
+ }
+ 
+ /* How to test if an inode is obsolete: */
+ static inline int inode_is_obsolete(struct inode *inode)
+ {
+ 	return (inode-&gt;u.supermount_i.i_sb_version !=
+ 		inode-&gt;i_sb-&gt;u.supermount_sb.s_version);
+ }
+ 
+ /* Manage the subfs dirty flag */
+ static inline void mark_subfs_dirty(struct super_block *sb)
+ {
+ 	sb-&gt;u.supermount_sb.s_dirty = 1;
+ }
+ static inline void mark_subfs_clean(struct super_block *sb)
+ {
+ 	sb-&gt;u.supermount_sb.s_dirty = 0;
+ }
+ static inline int subfs_is_dirty(struct super_block *sb)
+ {
+ 	return (sb-&gt;u.supermount_sb.s_dirty);
+ }
+ 
+ /* inode.c */
+ extern struct inode * subiget(struct inode *);
+ extern void supermount_iopen(struct inode *);
+ extern void supermount_iclose(struct inode *);
+ extern void supermount_go_inactive(struct super_block *);
+ extern struct inode * supermount_attach(struct super_block *, struct inode *);
+ extern void supermount_read_inode (struct inode *);
+ extern void supermount_write_inode (struct inode *);
+ extern void supermount_put_inode (struct inode *);
+ extern int supermount_permission (struct inode *, int mask);
+ 
+ /* namei.c */
+ extern void supermount_release (struct inode *, struct file *);
+ extern int supermount_lookup (struct inode *,const char *, int, struct inode **);
+ extern int supermount_create (struct inode *,const char *, int, int,
+ 			      struct inode **);
+ extern int supermount_mkdir (struct inode *, const char *, int, int);
+ extern int supermount_rmdir (struct inode *, const char *, int);
+ extern int supermount_unlink (struct inode *, const char *, int);
+ extern int supermount_symlink (struct inode *, const char *, int, const char *);
+ extern int supermount_link (struct inode *, struct inode *, const char *, int);
+ extern int supermount_mknod (struct inode *, const char *, int, int, int);
+ extern int supermount_rename (struct inode *, const char *, int,
+ 			      struct inode *, const char *, int);
+ 
+ /* super.c */
+ extern void supermount_error (struct super_block *, const char *, const char *, ...)
+ 	__attribute__ ((format (printf, 3, 4)));
+ extern NORET_TYPE void supermount_panic (struct super_block *, const char *,
+ 				   const char *, ...)
+ 	__attribute__ ((NORET_AND format (printf, 3, 4)));
+ extern void supermount_warning (struct super_block *, const char *, const char *, ...)
+ 	__attribute__ ((format (printf, 3, 4)));
+ extern void supermount_put_super (struct super_block *);
+ extern void supermount_write_super (struct super_block *);
+ extern int supermount_remount (struct super_block *, int *, char *);
+ extern struct super_block * supermount_read_super (struct super_block *,void *,int);
+ extern void supermount_statfs (struct super_block *, struct statfs *, int);
+ extern int supermount_media_check (struct super_block *);
+ extern int supermount_check_inode (struct inode *);
+ 
+ /* dir.c */
+ extern struct inode_operations supermount_dir_iops;
+ extern struct inode_operations supermount_root_iops;
+ 
+ /* inode.c */
+ extern struct inode_shadow_operations supermount_shadow_iops;
+ 
+ /* file.c */
+ /* extern struct inode_operations supermount_shadow_file_iops; */
+ 
+ /* symlink.c */
+ extern struct inode_operations supermount_symlink_iops;
+ 
+ #endif	/* __KERNEL__ */
+ 
+ #endif	/* _LINUX_SUPERMOUNT_FS_H */
*** linux/include/linux/supermount_fs_i.h.~1~	Thu May 30 15:49:07 1996
--- linux/include/linux/supermount_fs_i.h	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,23 ----
+ /*
+  *  linux/include/linux/supermount_fs.h
+  *
+  *  In-core inode structure for the dynamic remounting of removable media
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  */
+ 
+ #ifndef _LINUX_SUPERMOUNT_FS_I_H
+ #define _LINUX_SUPERMOUNT_FS_I_H
+ 
+ struct supermount_inode_info {
+ 	struct inode *	i_hidden;
+ 	int		i_sb_version;
+ 	int		i_subino;
+ 	int		i_counted;/* Has this inode been counted in
+ 				     the superblock reference counts
+ 				     yet? */
+ };
+ 
+ #endif	/* _LINUX_SUPERMOUNT_FS_I_H */
*** linux/include/linux/supermount_fs_sb.h.~1~	Thu May 30 15:49:07 1996
--- linux/include/linux/supermount_fs_sb.h	Thu May 30 15:22:31 1996
***************
*** 0 ****
--- 1,44 ----
+ /*
+  *  linux/include/linux/supermount_sb_fs.h
+  *
+  *  In-core superblock struct for the dynamic remounting of removable media
+  *
+  *  Copyright (C) 1995
+  *  Stephen Tweedie (sct@dcs.ed.ac.uk)
+  *
+  */
+ 
+ #ifndef _LINUX_SUPERMOUNT_FS_SB_H
+ #define _LINUX_SUPERMOUNT_FS_SB_H
+ 
+ typedef enum {
+ 	SUPERMOUNT_UNMOUNTED,	/* No media mounted */
+ 	SUPERMOUNT_SUSPENDED,	/* Mounted but suspended because 
+ 				   no files open */
+ 	SUPERMOUNT_ONLINE,	/* Mounted and active */
+ } sm_state_t;
+ 
+ /*
+  * supermount super-block data in memory
+  */
+ struct supermount_sb_info {
+ 	sm_state_t	s_state;
+ 	int		s_version;	/* Used to indicate obsolete inodes */
+ 	mode_t		s_default_mode;	/* Default mode for supermount root */
+ 
+ 	const char *	s_type;		/* Type of fs to be sub-mounted */
+ 	const char *	s_devname;	/* Where to mount the subfs */
+ 	int		s_mflags;	/* Flags to pass when mounting subfs */
+ 	const char *	s_data;		/* Data to pass when mounting subfs */
+ 
+ 	struct inode *	s_undermount;	/* Mount point for subfs */
+ 	struct super_block * s_subfs;	/* The submounted fs sb */
+ 	int		s_opencount;	/* Refcount of opened inodes
+ 					   (an inode in use as cwd
+ 					   does not count as open) */
+ 	
+ 	/* Flags */
+ 	int		s_dirty : 1;	/* Do we need to fsync() the subfs? */
+ };
+ 
+ #endif	/* _LINUX_SUPERMOUNT_FS_SB_H */
</pre></body></html>