4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * super.c contains code to handle: - mount structures
7 * - super-block tables.
11 * Added options to /proc/mounts
12 * Torbjörn Lindh (torbjorn.lindh@gopta.se), April 14, 1996.
14 * GK 2/5/95 - Changed to support mounting the root fs via NFS
16 * Added kerneld support: Jacques Gelinas and Bjorn Ekwall
17 * Added change_root: Werner Almesberger & Hans Lermen, Feb '96
20 #include <linux/config.h>
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
23 #include <linux/mount.h>
24 #include <linux/malloc.h>
25 #include <linux/major.h>
26 #include <linux/stat.h>
27 #include <linux/errno.h>
28 #include <linux/string.h>
29 #include <linux/locks.h>
31 #include <linux/smp.h>
32 #include <linux/smp_lock.h>
34 #include <linux/init.h>
36 #include <asm/system.h>
37 #include <asm/uaccess.h>
38 #include <asm/bitops.h>
41 #include <linux/kerneld.h>
44 #include <linux/nfs_fs.h>
45 #include <linux/nfs_fs_sb.h>
46 #include <linux/nfs_mount.h>
49 * We use a semaphore to synchronize all mount/umount
50 * activity - imagine the mess if we have a race between
51 * unmounting a filesystem and re-mounting it (or something
54 static struct semaphore mount_sem
= MUTEX
;
56 extern void wait_for_keypress(void);
57 extern struct file_operations
* get_blkfops(unsigned int major
);
59 extern int root_mountflags
;
61 static int do_remount_sb(struct super_block
*sb
, int flags
, char * data
);
63 /* this is initialized in init/main.c */
66 struct super_block super_blocks
[NR_SUPER
];
67 static struct file_system_type
*file_systems
= (struct file_system_type
*) NULL
;
68 struct vfsmount
*vfsmntlist
= (struct vfsmount
*) NULL
;
69 static struct vfsmount
*vfsmnttail
= (struct vfsmount
*) NULL
,
70 *mru_vfsmnt
= (struct vfsmount
*) NULL
;
73 * This part handles the management of the list of mounted filesystems.
75 struct vfsmount
*lookup_vfsmnt(kdev_t dev
)
77 struct vfsmount
*lptr
;
79 if (vfsmntlist
== (struct vfsmount
*)NULL
)
80 return ((struct vfsmount
*)NULL
);
82 if (mru_vfsmnt
!= (struct vfsmount
*)NULL
&&
83 mru_vfsmnt
->mnt_dev
== dev
)
86 for (lptr
= vfsmntlist
;
87 lptr
!= (struct vfsmount
*)NULL
;
88 lptr
= lptr
->mnt_next
)
89 if (lptr
->mnt_dev
== dev
) {
94 return ((struct vfsmount
*)NULL
);
98 static struct vfsmount
*add_vfsmnt(struct super_block
*sb
,
99 const char *dev_name
, const char *dir_name
)
101 struct vfsmount
*lptr
;
104 lptr
= (struct vfsmount
*)kmalloc(sizeof(struct vfsmount
), GFP_KERNEL
);
107 memset(lptr
, 0, sizeof(struct vfsmount
));
110 lptr
->mnt_dev
= sb
->s_dev
;
111 lptr
->mnt_flags
= sb
->s_flags
;
112 sema_init(&lptr
->mnt_sem
, 1);
114 /* N.B. Is it really OK to have a vfsmount without names? */
115 if (dev_name
&& !IS_ERR(tmp
= getname(dev_name
))) {
116 name
= (char *) kmalloc(strlen(tmp
)+1, GFP_KERNEL
);
119 lptr
->mnt_devname
= name
;
123 if (dir_name
&& !IS_ERR(tmp
= getname(dir_name
))) {
124 name
= (char *) kmalloc(strlen(tmp
)+1, GFP_KERNEL
);
127 lptr
->mnt_dirname
= name
;
132 if (vfsmntlist
== (struct vfsmount
*)NULL
) {
133 vfsmntlist
= vfsmnttail
= lptr
;
135 vfsmnttail
->mnt_next
= lptr
;
142 static void remove_vfsmnt(kdev_t dev
)
144 struct vfsmount
*lptr
, *tofree
;
146 if (vfsmntlist
== (struct vfsmount
*)NULL
)
149 if (lptr
->mnt_dev
== dev
) {
151 vfsmntlist
= lptr
->mnt_next
;
152 if (vfsmnttail
->mnt_dev
== dev
)
153 vfsmnttail
= vfsmntlist
;
155 while (lptr
->mnt_next
!= (struct vfsmount
*)NULL
) {
156 if (lptr
->mnt_next
->mnt_dev
== dev
)
158 lptr
= lptr
->mnt_next
;
160 tofree
= lptr
->mnt_next
;
161 if (tofree
== (struct vfsmount
*)NULL
)
163 lptr
->mnt_next
= lptr
->mnt_next
->mnt_next
;
164 if (vfsmnttail
->mnt_dev
== dev
)
167 if (tofree
== mru_vfsmnt
)
169 kfree(tofree
->mnt_devname
);
170 kfree(tofree
->mnt_dirname
);
171 kfree_s(tofree
, sizeof(struct vfsmount
));
174 int register_filesystem(struct file_system_type
* fs
)
176 struct file_system_type
** tmp
;
184 if (strcmp((*tmp
)->name
, fs
->name
) == 0)
192 #ifdef CONFIG_MODULES
193 int unregister_filesystem(struct file_system_type
* fs
)
195 struct file_system_type
** tmp
;
210 static int fs_index(const char * __name
)
212 struct file_system_type
* tmp
;
216 name
= getname(__name
);
222 for (tmp
= file_systems
; tmp
; tmp
= tmp
->next
) {
223 if (strcmp(tmp
->name
, name
) == 0) {
233 static int fs_name(unsigned int index
, char * buf
)
235 struct file_system_type
* tmp
;
239 while (tmp
&& index
> 0) {
245 len
= strlen(tmp
->name
) + 1;
246 return copy_to_user(buf
, tmp
->name
, len
) ? -EFAULT
: 0;
249 static int fs_maxindex(void)
251 struct file_system_type
* tmp
;
255 for (tmp
= file_systems
; tmp
; tmp
= tmp
->next
)
261 * Whee.. Weird sysv syscall.
263 asmlinkage
int sys_sysfs(int option
, unsigned long arg1
, unsigned long arg2
)
265 int retval
= -EINVAL
;
270 retval
= fs_index((const char *) arg1
);
274 retval
= fs_name(arg1
, (char *) arg2
);
278 retval
= fs_maxindex();
285 static struct proc_fs_info
{
289 { MS_NOEXEC
, ",noexec" },
290 { MS_NOSUID
, ",nosuid" },
291 { MS_NODEV
, ",nodev" },
292 { MS_SYNCHRONOUS
, ",sync" },
293 { MS_MANDLOCK
, ",mand" },
294 { MS_NOATIME
, ",noatime" },
295 #ifdef MS_NOSUB /* Can't find this except in mount.c */
296 { MS_NOSUB
, ",nosub" },
301 static struct proc_nfs_info
{
305 { NFS_MOUNT_SOFT
, ",soft" },
306 { NFS_MOUNT_INTR
, ",intr" },
307 { NFS_MOUNT_POSIX
, ",posix" },
308 { NFS_MOUNT_NOCTO
, ",nocto" },
309 { NFS_MOUNT_NOAC
, ",noac" },
313 int get_filesystem_info( char *buf
)
315 struct vfsmount
*tmp
= vfsmntlist
;
316 struct proc_fs_info
*fs_infop
;
317 struct proc_nfs_info
*nfs_infop
;
318 struct nfs_server
*nfss
;
321 while ( tmp
&& len
< PAGE_SIZE
- 160)
323 len
+= sprintf( buf
+ len
, "%s %s %s %s",
324 tmp
->mnt_devname
, tmp
->mnt_dirname
, tmp
->mnt_sb
->s_type
->name
,
325 tmp
->mnt_flags
& MS_RDONLY
? "ro" : "rw" );
326 for (fs_infop
= fs_info
; fs_infop
->flag
; fs_infop
++) {
327 if (tmp
->mnt_flags
& fs_infop
->flag
) {
328 strcpy(buf
+ len
, fs_infop
->str
);
329 len
+= strlen(fs_infop
->str
);
332 if (!strcmp("nfs", tmp
->mnt_sb
->s_type
->name
)) {
333 nfss
= &tmp
->mnt_sb
->u
.nfs_sb
.s_server
;
334 if (nfss
->rsize
!= NFS_DEF_FILE_IO_BUFFER_SIZE
) {
335 len
+= sprintf(buf
+len
, ",rsize=%d",
338 if (nfss
->wsize
!= NFS_DEF_FILE_IO_BUFFER_SIZE
) {
339 len
+= sprintf(buf
+len
, ",wsize=%d",
343 if (nfss
->timeo
!= 7*HZ
/10) {
344 len
+= sprintf(buf
+len
, ",timeo=%d",
347 if (nfss
->retrans
!= 3) {
348 len
+= sprintf(buf
+len
, ",retrans=%d",
352 if (nfss
->acregmin
!= 3*HZ
) {
353 len
+= sprintf(buf
+len
, ",acregmin=%d",
356 if (nfss
->acregmax
!= 60*HZ
) {
357 len
+= sprintf(buf
+len
, ",acregmax=%d",
360 if (nfss
->acdirmin
!= 30*HZ
) {
361 len
+= sprintf(buf
+len
, ",acdirmin=%d",
364 if (nfss
->acdirmax
!= 60*HZ
) {
365 len
+= sprintf(buf
+len
, ",acdirmax=%d",
368 for (nfs_infop
= nfs_info
; nfs_infop
->flag
; nfs_infop
++) {
369 if (nfss
->flags
& nfs_infop
->flag
) {
370 strcpy(buf
+ len
, nfs_infop
->str
);
371 len
+= strlen(nfs_infop
->str
);
374 len
+= sprintf(buf
+len
, ",addr=%s",
377 len
+= sprintf( buf
+ len
, " 0 0\n" );
384 int get_filesystem_list(char * buf
)
387 struct file_system_type
* tmp
;
390 while (tmp
&& len
< PAGE_SIZE
- 80) {
391 len
+= sprintf(buf
+len
, "%s\t%s\n",
392 (tmp
->fs_flags
& FS_REQUIRES_DEV
) ? "" : "nodev",
399 struct file_system_type
*get_fs_type(const char *name
)
401 struct file_system_type
* fs
= file_systems
;
405 for (fs
= file_systems
; fs
&& strcmp(fs
->name
, name
); fs
= fs
->next
)
407 #ifdef CONFIG_KERNELD
408 if (!fs
&& (request_module(name
) == 0)) {
409 for (fs
= file_systems
; fs
&& strcmp(fs
->name
, name
); fs
= fs
->next
)
417 void __wait_on_super(struct super_block
* sb
)
419 struct wait_queue wait
= { current
, NULL
};
421 add_wait_queue(&sb
->s_wait
, &wait
);
423 current
->state
= TASK_UNINTERRUPTIBLE
;
428 remove_wait_queue(&sb
->s_wait
, &wait
);
429 current
->state
= TASK_RUNNING
;
433 * Note: check the dirty flag before waiting, so we don't
434 * hold up the sync while mounting a device. (The newly
435 * mounted device won't need syncing.)
437 void sync_supers(kdev_t dev
)
439 struct super_block
* sb
;
441 for (sb
= super_blocks
+ 0 ; sb
< super_blocks
+ NR_SUPER
; sb
++) {
444 if (dev
&& sb
->s_dev
!= dev
)
448 /* N.B. Should lock the superblock while writing */
450 if (!sb
->s_dev
|| !sb
->s_dirt
)
452 if (dev
&& (dev
!= sb
->s_dev
))
454 if (sb
->s_op
&& sb
->s_op
->write_super
)
455 sb
->s_op
->write_super(sb
);
459 struct super_block
* get_super(kdev_t dev
)
461 struct super_block
* s
;
467 while (s
< NR_SUPER
+super_blocks
)
468 if (s
->s_dev
== dev
) {
478 asmlinkage
int sys_ustat(dev_t dev
, struct ustat
* ubuf
)
480 struct super_block
*s
;
487 s
= get_super(to_kdev_t(dev
));
491 if (!(s
->s_op
->statfs
))
496 s
->s_op
->statfs(s
,&sbuf
,sizeof(struct statfs
));
499 memset(&tmp
,0,sizeof(struct ustat
));
500 tmp
.f_tfree
= sbuf
.f_bfree
;
501 tmp
.f_tinode
= sbuf
.f_ffree
;
503 err
= copy_to_user(ubuf
,&tmp
,sizeof(struct ustat
)) ? -EFAULT
: 0;
510 * Find a super_block with no device assigned.
512 static struct super_block
*get_empty_super(void)
514 struct super_block
*s
= 0+super_blocks
;
516 for (; s
< NR_SUPER
+super_blocks
; s
++) {
521 printk("VFS: empty superblock %p locked!\n", s
);
526 static struct super_block
* read_super(kdev_t dev
,const char *name
,int flags
,
527 void *data
, int silent
)
529 struct super_block
* s
;
530 struct file_system_type
*type
;
534 check_disk_change(dev
);
539 type
= get_fs_type(name
);
541 printk("VFS: on device %s: get_fs_type(%s) failed\n",
542 kdevname(dev
), name
);
545 s
= get_empty_super();
551 /* N.B. Should lock superblock now ... */
552 if (!type
->read_super(s
, data
, silent
))
554 s
->s_dev
= dev
; /* N.B. why do this again?? */
560 /* N.B. s_dev should be cleared in type->read_super */
569 * Unnamed block devices are dummy devices used by virtual
570 * filesystems which don't use real block-devices. -- jrs
573 static unsigned int unnamed_dev_in_use
[256/(8*sizeof(unsigned int))] = { 0, };
575 kdev_t
get_unnamed_dev(void)
579 for (i
= 1; i
< 256; i
++) {
580 if (!test_and_set_bit(i
,unnamed_dev_in_use
))
581 return MKDEV(UNNAMED_MAJOR
, i
);
586 void put_unnamed_dev(kdev_t dev
)
588 if (!dev
|| MAJOR(dev
) != UNNAMED_MAJOR
)
590 if (test_and_clear_bit(MINOR(dev
), unnamed_dev_in_use
))
592 printk("VFS: put_unnamed_dev: freeing unused device %s\n",
596 static int d_umount(struct super_block
* sb
)
598 struct dentry
* root
= sb
->s_root
;
599 struct dentry
* covered
= root
->d_covers
;
601 if (root
->d_count
!= 1)
604 if (root
->d_inode
->i_state
)
609 if (covered
!= root
) {
610 root
->d_covers
= root
;
611 covered
->d_mounts
= covered
;
618 static void d_mount(struct dentry
*covered
, struct dentry
*dentry
)
620 if (covered
->d_mounts
!= covered
) {
621 printk("VFS: mount - already mounted\n");
624 covered
->d_mounts
= dentry
;
625 dentry
->d_covers
= covered
;
628 static int do_umount(kdev_t dev
, int unmount_root
)
630 struct super_block
* sb
;
635 if (!sb
|| !sb
->s_root
)
639 * Before checking whether the filesystem is still busy,
640 * make sure the kernel doesn't hold any quotafiles open
641 * on the device. If the umount fails, too bad -- there
642 * are no quotas running anymore. Just turn them on again.
647 * Shrink dcache, then fsync. This guarantees that if the
648 * filesystem is quiescent at this point, then (a) only the
649 * root entry should be in use and (b) that root entry is
652 shrink_dcache_sb(sb
);
655 if (dev
==ROOT_DEV
&& !unmount_root
) {
657 * Special case for "unmounting" root ...
658 * we just try to remount it readonly.
661 if (!(sb
->s_flags
& MS_RDONLY
))
662 retval
= do_remount_sb(sb
, MS_RDONLY
, 0);
666 retval
= d_umount(sb
);
670 /* Forget any inodes */
671 if (invalidate_inodes(sb
)) {
672 printk("VFS: Busy inodes after unmount. "
673 "Self-destruct in 5 seconds. Bye-bye..\n");
677 if (sb
->s_op
->write_super
&& sb
->s_dirt
)
678 sb
->s_op
->write_super(sb
);
679 if (sb
->s_op
->put_super
)
680 sb
->s_op
->put_super(sb
);
687 static int umount_dev(kdev_t dev
)
690 struct inode
* inode
= get_empty_inode();
698 if (MAJOR(dev
) >= MAX_BLKDEV
)
705 retval
= do_umount(dev
,0);
708 if (dev
!= ROOT_DEV
) {
709 blkdev_release(inode
);
710 put_unnamed_dev(dev
);
722 * Now umount can handle mount points as well as block devices.
723 * This is important for filesystems which use unnamed block devices.
725 * There is a little kludge here with the dummy_inode. The current
726 * vfs release functions only use the r_dev field in the inode so
727 * we give them the info they need without using a real inode.
728 * If any other fields are ever needed by any block device release
729 * functions, they should be faked here. -- jrs
732 asmlinkage
int sys_umount(char * name
)
734 struct dentry
* dentry
;
741 dentry
= namei(name
);
742 retval
= PTR_ERR(dentry
);
743 if (!IS_ERR(dentry
)) {
744 struct inode
* inode
= dentry
->d_inode
;
745 kdev_t dev
= inode
->i_rdev
;
748 if (S_ISBLK(inode
->i_mode
)) {
752 struct super_block
*sb
= inode
->i_sb
;
754 if (sb
&& inode
== sb
->s_root
->d_inode
) {
762 retval
= umount_dev(dev
);
769 * Check whether we can mount the specified device.
771 int fs_may_mount(kdev_t dev
)
773 struct super_block
* sb
= get_super(dev
);
776 busy
= sb
&& sb
->s_root
&&
777 (sb
->s_root
->d_count
!= 1 || sb
->s_root
->d_covers
!= sb
->s_root
);
782 * do_mount() does the actual mounting after sys_mount has done the ugly
783 * parameter parsing. When enough time has gone by, and everything uses the
784 * new mount() parameters, sys_mount() can then be cleaned up.
786 * We cannot mount a filesystem if it has active, used, or dirty inodes.
787 * We also have to flush all inode-data for this device, as the new mount
788 * might need new info.
790 * [21-Mar-97] T.Schoebel-Theuer: Now this can be overridden when
791 * supplying a leading "!" before the dir_name, allowing "stacks" of
792 * mounted filesystems. The stacking will only influence any pathname lookups
793 * _after_ the mount, but open filedescriptors or working directories that
794 * are now covered remain valid. For example, when you overmount /home, any
795 * process with old cwd /home/joe will continue to use the old versions,
796 * as long as relative paths are used, but absolute paths like /home/joe/xxx
797 * will go to the new "top of stack" version. In general, crossing a
798 * mountpoint will always go to the top of stack element.
799 * Anyone using this new feature must know what he/she is doing.
802 int do_mount(kdev_t dev
, const char * dev_name
, const char * dir_name
, const char * type
, int flags
, void * data
)
804 struct dentry
* dir_d
;
805 struct super_block
* sb
;
806 struct vfsmount
*vfsmnt
;
811 if (!(flags
& MS_RDONLY
) && dev
&& is_read_only(dev
))
813 /*flags |= MS_RDONLY;*/
815 dir_d
= namei(dir_name
);
816 error
= PTR_ERR(dir_d
);
821 if (!S_ISDIR(dir_d
->d_inode
->i_mode
))
825 if (dir_d
->d_covers
!= dir_d
)
829 * Note: If the superblock already exists,
830 * read_super just does a get_super().
833 sb
= read_super(dev
, type
, flags
, data
, 0);
838 * We may have slept while reading the super block,
839 * so we check afterwards whether it's safe to mount.
842 if (!fs_may_mount(dev
))
846 vfsmnt
= add_vfsmnt(sb
, dev_name
, dir_name
);
849 d_mount(dir_d
, sb
->s_root
);
850 error
= 0; /* we don't dput(dir_d) - see umount */
863 * Alters the mount flags of a mounted file system. Only the mount point
864 * is used as a reference - file system type and the device are ignored.
865 * FS-specific mount options can't be altered by remounting.
868 static int do_remount_sb(struct super_block
*sb
, int flags
, char *data
)
871 struct vfsmount
*vfsmnt
;
874 * Invalidate the inodes, as some mount options may be changed.
875 * N.B. If we are changing media, we should check the return
876 * from invalidate_inodes ... can't allow _any_ open files.
878 invalidate_inodes(sb
);
880 if (!(flags
& MS_RDONLY
) && sb
->s_dev
&& is_read_only(sb
->s_dev
))
882 /*flags |= MS_RDONLY;*/
883 /* If we are remounting RDONLY, make sure there are no rw files open */
884 if ((flags
& MS_RDONLY
) && !(sb
->s_flags
& MS_RDONLY
))
885 if (!fs_may_remount_ro(sb
))
887 if (sb
->s_op
&& sb
->s_op
->remount_fs
) {
888 retval
= sb
->s_op
->remount_fs(sb
, &flags
, data
);
892 sb
->s_flags
= (sb
->s_flags
& ~MS_RMT_MASK
) | (flags
& MS_RMT_MASK
);
893 vfsmnt
= lookup_vfsmnt(sb
->s_dev
);
895 vfsmnt
->mnt_flags
= sb
->s_flags
;
899 static int do_remount(const char *dir
,int flags
,char *data
)
901 struct dentry
*dentry
;
905 retval
= PTR_ERR(dentry
);
906 if (!IS_ERR(dentry
)) {
907 struct super_block
* sb
= dentry
->d_inode
->i_sb
;
910 if (dentry
== sb
->s_root
) {
912 * Shrink the dcache and sync the device.
914 shrink_dcache_sb(sb
);
915 fsync_dev(sb
->s_dev
);
916 retval
= do_remount_sb(sb
, flags
, data
);
923 static int copy_mount_options (const void * data
, unsigned long *where
)
927 struct vm_area_struct
* vma
;
933 vma
= find_vma(current
->mm
, (unsigned long) data
);
934 if (!vma
|| (unsigned long) data
< vma
->vm_start
)
936 if (!(vma
->vm_flags
& VM_READ
))
938 i
= vma
->vm_end
- (unsigned long) data
;
939 if (PAGE_SIZE
<= (unsigned long) i
)
941 if (!(page
= __get_free_page(GFP_KERNEL
))) {
944 if (copy_from_user((void *) page
,data
,i
)) {
953 * Flags is a 16-bit value that allows up to 16 non-fs dependent flags to
954 * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
956 * data is a (void *) that can point to any structure up to
957 * PAGE_SIZE-1 bytes, which can contain arbitrary fs-dependent
958 * information (or be NULL).
960 * NOTE! As old versions of mount() didn't use this setup, the flags
961 * have to have a special 16-bit magic number in the high word:
962 * 0xC0ED. If this magic word isn't present, the flags and data info
963 * aren't used, as the syscall assumes we are talking to an older
964 * version that didn't understand them.
966 asmlinkage
int sys_mount(char * dev_name
, char * dir_name
, char * type
,
967 unsigned long new_flags
, void * data
)
969 struct file_system_type
* fstype
;
970 struct dentry
* dentry
= NULL
;
971 struct inode
* inode
= NULL
;
974 unsigned long flags
= 0;
975 unsigned long page
= 0;
976 struct file dummy
; /* allows read-write or read-only flag */
982 (MS_MGC_MSK
| MS_REMOUNT
)) == (MS_MGC_VAL
| MS_REMOUNT
)) {
983 retval
= copy_mount_options (data
, &page
);
986 retval
= do_remount(dir_name
,
987 new_flags
& ~MS_MGC_MSK
& ~MS_REMOUNT
,
993 retval
= copy_mount_options (type
, &page
);
996 fstype
= get_fs_type((char *) page
);
1002 memset(&dummy
, 0, sizeof(dummy
));
1003 if (fstype
->fs_flags
& FS_REQUIRES_DEV
) {
1004 dentry
= namei(dev_name
);
1005 retval
= PTR_ERR(dentry
);
1009 inode
= dentry
->d_inode
;
1011 if (!S_ISBLK(inode
->i_mode
))
1015 if (IS_NODEV(inode
))
1018 dev
= inode
->i_rdev
;
1020 if (MAJOR(dev
) >= MAX_BLKDEV
)
1024 dummy
.f_op
= get_blkfops(MAJOR(dev
));
1028 if (dummy
.f_op
->open
) {
1029 dummy
.f_dentry
= dentry
;
1030 dummy
.f_mode
= (new_flags
& MS_RDONLY
) ? 1 : 3;
1031 retval
= dummy
.f_op
->open(inode
, &dummy
);
1038 if (!(dev
= get_unnamed_dev()))
1043 if ((new_flags
& MS_MGC_MSK
) == MS_MGC_VAL
) {
1044 flags
= new_flags
& ~MS_MGC_MSK
;
1045 retval
= copy_mount_options(data
, &page
);
1049 retval
= do_mount(dev
, dev_name
, dir_name
, fstype
->name
, flags
,
1063 if (dummy
.f_op
->release
)
1064 dummy
.f_op
->release(inode
, NULL
);
1066 put_unnamed_dev(dev
);
1070 __initfunc(static void do_mount_root(void))
1072 struct file_system_type
* fs_type
;
1073 struct super_block
* sb
;
1074 struct vfsmount
*vfsmnt
;
1075 struct inode
* d_inode
= NULL
;
1079 #ifdef CONFIG_ROOT_NFS
1080 if (MAJOR(ROOT_DEV
) == UNNAMED_MAJOR
) {
1082 if ((fs_type
= get_fs_type("nfs"))) {
1083 sb
= get_empty_super(); /* "can't fail" */
1084 sb
->s_dev
= get_unnamed_dev();
1085 sb
->s_flags
= root_mountflags
& ~MS_RDONLY
;
1086 vfsmnt
= add_vfsmnt(sb
, "/dev/root", "/");
1088 if (nfs_root_mount(sb
) >= 0) {
1091 sb
->s_type
= fs_type
;
1092 current
->fs
->root
= dget(sb
->s_root
);
1093 current
->fs
->pwd
= dget(sb
->s_root
);
1094 ROOT_DEV
= sb
->s_dev
;
1095 printk (KERN_NOTICE
"VFS: Mounted root (nfs filesystem).\n");
1098 remove_vfsmnt(sb
->s_dev
);
1100 put_unnamed_dev(sb
->s_dev
);
1104 printk(KERN_ERR
"VFS: Unable to mount root fs via NFS, trying floppy.\n");
1105 ROOT_DEV
= MKDEV(FLOPPY_MAJOR
, 0);
1110 #ifdef CONFIG_BLK_DEV_FD
1111 if (MAJOR(ROOT_DEV
) == FLOPPY_MAJOR
) {
1113 #ifndef CONFIG_BLK_DEV_RAM
1114 printk(KERN_NOTICE
"(Warning, this kernel has no ramdisk support)\n");
1116 printk(KERN_NOTICE
"VFS: Insert root floppy and press ENTER\n");
1117 wait_for_keypress();
1121 memset(&filp
, 0, sizeof(filp
));
1122 d_inode
= get_empty_inode();
1123 d_inode
->i_rdev
= ROOT_DEV
;
1124 filp
.f_dentry
= NULL
;
1125 if ( root_mountflags
& MS_RDONLY
)
1126 filp
.f_mode
= 1; /* read only */
1128 filp
.f_mode
= 3; /* read write */
1129 retval
= blkdev_open(d_inode
, &filp
);
1130 if (retval
== -EROFS
) {
1131 root_mountflags
|= MS_RDONLY
;
1133 retval
= blkdev_open(d_inode
, &filp
);
1138 * Allow the user to distinguish between failed open
1139 * and bad superblock on root device.
1141 printk("VFS: Cannot open root device %s\n",
1142 kdevname(ROOT_DEV
));
1143 else for (fs_type
= file_systems
; fs_type
; fs_type
= fs_type
->next
) {
1144 if (!(fs_type
->fs_flags
& FS_REQUIRES_DEV
))
1146 sb
= read_super(ROOT_DEV
,fs_type
->name
,root_mountflags
,NULL
,1);
1148 sb
->s_flags
= root_mountflags
;
1149 current
->fs
->root
= dget(sb
->s_root
);
1150 current
->fs
->pwd
= dget(sb
->s_root
);
1151 printk ("VFS: Mounted root (%s filesystem)%s.\n",
1153 (sb
->s_flags
& MS_RDONLY
) ? " readonly" : "");
1154 vfsmnt
= add_vfsmnt(sb
, "/dev/root", "/");
1157 panic("VFS: add_vfsmnt failed for root fs");
1160 panic("VFS: Unable to mount root fs on %s",
1161 kdevname(ROOT_DEV
));
1165 __initfunc(void mount_root(void))
1167 struct super_block
* sb
= super_blocks
;
1170 memset(super_blocks
, 0, sizeof(super_blocks
));
1172 * Initialize the dirty inode list headers for the super blocks
1174 for (i
= NR_SUPER
; i
-- ; sb
++)
1175 INIT_LIST_HEAD(&sb
->s_dirty
);
1181 #ifdef CONFIG_BLK_DEV_INITRD
1183 extern int initmem_freed
;
1185 __initfunc(static int do_change_root(kdev_t new_root_dev
,const char *put_old
))
1187 kdev_t old_root_dev
;
1188 struct vfsmount
*vfsmnt
;
1189 struct dentry
*old_root
,*old_pwd
,*dir_d
= NULL
;
1192 old_root
= current
->fs
->root
;
1193 old_pwd
= current
->fs
->pwd
;
1194 old_root_dev
= ROOT_DEV
;
1195 if (!fs_may_mount(new_root_dev
)) {
1196 printk(KERN_CRIT
"New root is busy. Staying in initrd.\n");
1199 ROOT_DEV
= new_root_dev
;
1205 printk("do_change_root: old root has d_count=%d\n", old_root
->d_count
);
1208 * Get the new mount directory
1210 dir_d
= lookup_dentry(put_old
, NULL
, 1);
1211 if (IS_ERR(dir_d
)) {
1212 error
= PTR_ERR(dir_d
);
1213 } else if (!dir_d
->d_inode
) {
1219 if (!error
&& dir_d
->d_covers
!= dir_d
) {
1223 if (!error
&& !S_ISDIR(dir_d
->d_inode
->i_mode
)) {
1230 printk(KERN_NOTICE
"Trying to unmount old root ... ");
1231 umount_error
= do_umount(old_root_dev
,1);
1232 if (!umount_error
) {
1234 invalidate_buffers(old_root_dev
);
1237 printk(KERN_ERR
"error %d\n",umount_error
);
1240 remove_vfsmnt(old_root_dev
);
1241 vfsmnt
= add_vfsmnt(old_root
->d_sb
, "/dev/root.old", put_old
);
1243 d_mount(dir_d
,old_root
);
1246 printk(KERN_CRIT
"Trouble: add_vfsmnt failed\n");
1250 int change_root(kdev_t new_root_dev
,const char *put_old
)
1252 if (initmem_freed
) {
1253 printk (KERN_CRIT
"Initmem has been already freed. Staying in initrd\n");
1256 return do_change_root(new_root_dev
, put_old
);