4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * super.c contains code to handle: - mount structures
8 * - filesystem drivers list
10 * - umount system call
13 * GK 2/5/95 - Changed to support mounting the root fs via NFS
15 * Added kerneld support: Jacques Gelinas and Bjorn Ekwall
16 * Added change_root: Werner Almesberger & Hans Lermen, Feb '96
17 * Added options to /proc/mounts:
18 * Torbjörn Lindh (torbjorn.lindh@gopta.se), April 14, 1996.
19 * Added devfs support: Richard Gooch <rgooch@atnf.csiro.au>, 13-JAN-1998
20 * Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/smp_lock.h>
27 #include <linux/acct.h>
28 #include <linux/blkdev.h>
29 #include <linux/quotaops.h>
30 #include <linux/namei.h>
31 #include <linux/mount.h>
32 #include <linux/security.h>
33 #include <linux/syscalls.h>
34 #include <linux/vfs.h>
35 #include <linux/writeback.h> /* for the emergency remount stuff */
36 #include <linux/idr.h>
37 #include <linux/kobject.h>
38 #include <linux/mutex.h>
39 #include <linux/file.h>
40 #include <linux/backing-dev.h>
41 #include <asm/uaccess.h>
45 LIST_HEAD(super_blocks
);
46 DEFINE_SPINLOCK(sb_lock
);
49 * alloc_super - create new superblock
50 * @type: filesystem type superblock should belong to
52 * Allocates and initializes a new &struct super_block. alloc_super()
53 * returns a pointer new superblock or %NULL if allocation had failed.
55 static struct super_block
*alloc_super(struct file_system_type
*type
)
57 struct super_block
*s
= kzalloc(sizeof(struct super_block
), GFP_USER
);
58 static const struct super_operations default_op
;
61 if (security_sb_alloc(s
)) {
66 INIT_LIST_HEAD(&s
->s_files
);
67 s
->s_bdi
= &default_backing_dev_info
;
68 INIT_LIST_HEAD(&s
->s_instances
);
69 INIT_HLIST_HEAD(&s
->s_anon
);
70 INIT_LIST_HEAD(&s
->s_inodes
);
71 INIT_LIST_HEAD(&s
->s_dentry_lru
);
72 init_rwsem(&s
->s_umount
);
73 mutex_init(&s
->s_lock
);
74 lockdep_set_class(&s
->s_umount
, &type
->s_umount_key
);
76 * The locking rules for s_lock are up to the
77 * filesystem. For example ext3fs has different
78 * lock ordering than usbfs:
80 lockdep_set_class(&s
->s_lock
, &type
->s_lock_key
);
82 * sget() can have s_umount recursion.
84 * When it cannot find a suitable sb, it allocates a new
85 * one (this one), and tries again to find a suitable old
88 * In case that succeeds, it will acquire the s_umount
89 * lock of the old one. Since these are clearly distrinct
90 * locks, and this object isn't exposed yet, there's no
93 * Annotate this by putting this lock in a different
96 down_write_nested(&s
->s_umount
, SINGLE_DEPTH_NESTING
);
98 atomic_set(&s
->s_active
, 1);
99 mutex_init(&s
->s_vfs_rename_mutex
);
100 mutex_init(&s
->s_dquot
.dqio_mutex
);
101 mutex_init(&s
->s_dquot
.dqonoff_mutex
);
102 init_rwsem(&s
->s_dquot
.dqptr_sem
);
103 init_waitqueue_head(&s
->s_wait_unfrozen
);
104 s
->s_maxbytes
= MAX_NON_LFS
;
105 s
->dq_op
= sb_dquot_ops
;
106 s
->s_qcop
= sb_quotactl_ops
;
107 s
->s_op
= &default_op
;
108 s
->s_time_gran
= 1000000000;
115 * destroy_super - frees a superblock
116 * @s: superblock to free
118 * Frees a superblock.
120 static inline void destroy_super(struct super_block
*s
)
128 /* Superblock refcounting */
131 * Drop a superblock's refcount. Returns non-zero if the superblock was
132 * destroyed. The caller must hold sb_lock.
134 static int __put_super(struct super_block
*sb
)
138 if (!--sb
->s_count
) {
146 * Drop a superblock's refcount.
147 * Returns non-zero if the superblock is about to be destroyed and
148 * at least is already removed from super_blocks list, so if we are
149 * making a loop through super blocks then we need to restart.
150 * The caller must hold sb_lock.
152 int __put_super_and_need_restart(struct super_block
*sb
)
154 /* check for race with generic_shutdown_super() */
155 if (list_empty(&sb
->s_list
)) {
156 /* super block is removed, need to restart... */
160 /* can't be the last, since s_list is still in use */
162 BUG_ON(sb
->s_count
== 0);
167 * put_super - drop a temporary reference to superblock
168 * @sb: superblock in question
170 * Drops a temporary reference, frees superblock if there's no
173 void put_super(struct super_block
*sb
)
177 spin_unlock(&sb_lock
);
182 * deactivate_super - drop an active reference to superblock
183 * @s: superblock to deactivate
185 * Drops an active reference to superblock, acquiring a temprory one if
186 * there is no active references left. In that case we lock superblock,
187 * tell fs driver to shut it down and drop the temporary reference we
190 void deactivate_super(struct super_block
*s
)
192 struct file_system_type
*fs
= s
->s_type
;
193 if (atomic_dec_and_lock(&s
->s_active
, &sb_lock
)) {
194 s
->s_count
-= S_BIAS
-1;
195 spin_unlock(&sb_lock
);
197 down_write(&s
->s_umount
);
204 EXPORT_SYMBOL(deactivate_super
);
207 * deactivate_locked_super - drop an active reference to superblock
208 * @s: superblock to deactivate
210 * Equivalent of up_write(&s->s_umount); deactivate_super(s);, except that
211 * it does not unlock it until it's all over. As the result, it's safe to
212 * use to dispose of new superblock on ->get_sb() failure exits - nobody
213 * will see the sucker until it's all over. Equivalent using up_write +
214 * deactivate_super is safe for that purpose only if superblock is either
215 * safe to use or has NULL ->s_root when we unlock.
217 void deactivate_locked_super(struct super_block
*s
)
219 struct file_system_type
*fs
= s
->s_type
;
220 if (atomic_dec_and_lock(&s
->s_active
, &sb_lock
)) {
221 s
->s_count
-= S_BIAS
-1;
222 spin_unlock(&sb_lock
);
228 up_write(&s
->s_umount
);
232 EXPORT_SYMBOL(deactivate_locked_super
);
235 * grab_super - acquire an active reference
236 * @s: reference we are trying to make active
238 * Tries to acquire an active reference. grab_super() is used when we
239 * had just found a superblock in super_blocks or fs_type->fs_supers
240 * and want to turn it into a full-blown active reference. grab_super()
241 * is called with sb_lock held and drops it. Returns 1 in case of
242 * success, 0 if we had failed (superblock contents was already dead or
243 * dying when grab_super() had been called).
245 static int grab_super(struct super_block
*s
) __releases(sb_lock
)
248 spin_unlock(&sb_lock
);
249 down_write(&s
->s_umount
);
252 if (s
->s_count
> S_BIAS
) {
253 atomic_inc(&s
->s_active
);
255 spin_unlock(&sb_lock
);
258 spin_unlock(&sb_lock
);
260 up_write(&s
->s_umount
);
267 * Superblock locking. We really ought to get rid of these two.
269 void lock_super(struct super_block
* sb
)
272 mutex_lock(&sb
->s_lock
);
275 void unlock_super(struct super_block
* sb
)
278 mutex_unlock(&sb
->s_lock
);
281 EXPORT_SYMBOL(lock_super
);
282 EXPORT_SYMBOL(unlock_super
);
285 * generic_shutdown_super - common helper for ->kill_sb()
286 * @sb: superblock to kill
288 * generic_shutdown_super() does all fs-independent work on superblock
289 * shutdown. Typical ->kill_sb() should pick all fs-specific objects
290 * that need destruction out of superblock, call generic_shutdown_super()
291 * and release aforementioned objects. Note: dentries and inodes _are_
292 * taken care of and do not need specific handling.
294 * Upon calling this function, the filesystem may no longer alter or
295 * rearrange the set of dentries belonging to this super_block, nor may it
296 * change the attachments of dentries to inodes.
298 void generic_shutdown_super(struct super_block
*sb
)
300 const struct super_operations
*sop
= sb
->s_op
;
304 shrink_dcache_for_umount(sb
);
307 sb
->s_flags
&= ~MS_ACTIVE
;
309 /* bad name - it should be evict_inodes() */
310 invalidate_inodes(sb
);
315 /* Forget any remaining inodes */
316 if (invalidate_inodes(sb
)) {
317 printk("VFS: Busy inodes after unmount of %s. "
318 "Self-destruct in 5 seconds. Have a nice day...\n",
324 /* should be initialized for __put_super_and_need_restart() */
325 list_del_init(&sb
->s_list
);
326 list_del(&sb
->s_instances
);
327 spin_unlock(&sb_lock
);
328 up_write(&sb
->s_umount
);
331 EXPORT_SYMBOL(generic_shutdown_super
);
334 * sget - find or create a superblock
335 * @type: filesystem type superblock should belong to
336 * @test: comparison callback
337 * @set: setup callback
338 * @data: argument to each of them
340 struct super_block
*sget(struct file_system_type
*type
,
341 int (*test
)(struct super_block
*,void *),
342 int (*set
)(struct super_block
*,void *),
345 struct super_block
*s
= NULL
;
346 struct super_block
*old
;
352 list_for_each_entry(old
, &type
->fs_supers
, s_instances
) {
353 if (!test(old
, data
))
355 if (!grab_super(old
))
358 up_write(&s
->s_umount
);
362 if (unlikely(!(old
->s_flags
& MS_BORN
))) {
363 deactivate_locked_super(old
);
370 spin_unlock(&sb_lock
);
371 s
= alloc_super(type
);
373 return ERR_PTR(-ENOMEM
);
379 spin_unlock(&sb_lock
);
380 up_write(&s
->s_umount
);
385 strlcpy(s
->s_id
, type
->name
, sizeof(s
->s_id
));
386 list_add_tail(&s
->s_list
, &super_blocks
);
387 list_add(&s
->s_instances
, &type
->fs_supers
);
388 spin_unlock(&sb_lock
);
389 get_filesystem(type
);
395 void drop_super(struct super_block
*sb
)
397 up_read(&sb
->s_umount
);
401 EXPORT_SYMBOL(drop_super
);
404 * sync_supers - helper for periodic superblock writeback
406 * Call the write_super method if present on all dirty superblocks in
407 * the system. This is for the periodic writeback used by most older
408 * filesystems. For data integrity superblock writeback use
409 * sync_filesystems() instead.
411 * Note: check the dirty flag before waiting, so we don't
412 * hold up the sync while mounting a device. (The newly
413 * mounted device won't need syncing.)
415 void sync_supers(void)
417 struct super_block
*sb
;
421 list_for_each_entry(sb
, &super_blocks
, s_list
) {
422 if (sb
->s_op
->write_super
&& sb
->s_dirt
) {
424 spin_unlock(&sb_lock
);
426 down_read(&sb
->s_umount
);
427 if (sb
->s_root
&& sb
->s_dirt
)
428 sb
->s_op
->write_super(sb
);
429 up_read(&sb
->s_umount
);
432 if (__put_super_and_need_restart(sb
))
436 spin_unlock(&sb_lock
);
440 * get_super - get the superblock of a device
441 * @bdev: device to get the superblock for
443 * Scans the superblock list and finds the superblock of the file system
444 * mounted on the device given. %NULL is returned if no match is found.
447 struct super_block
* get_super(struct block_device
*bdev
)
449 struct super_block
*sb
;
456 list_for_each_entry(sb
, &super_blocks
, s_list
) {
457 if (sb
->s_bdev
== bdev
) {
459 spin_unlock(&sb_lock
);
460 down_read(&sb
->s_umount
);
463 up_read(&sb
->s_umount
);
464 /* restart only when sb is no longer on the list */
466 if (__put_super_and_need_restart(sb
))
470 spin_unlock(&sb_lock
);
474 EXPORT_SYMBOL(get_super
);
477 * get_active_super - get an active reference to the superblock of a device
478 * @bdev: device to get the superblock for
480 * Scans the superblock list and finds the superblock of the file system
481 * mounted on the device given. Returns the superblock with an active
482 * reference and s_umount held exclusively or %NULL if none was found.
484 struct super_block
*get_active_super(struct block_device
*bdev
)
486 struct super_block
*sb
;
492 list_for_each_entry(sb
, &super_blocks
, s_list
) {
493 if (sb
->s_bdev
!= bdev
)
497 spin_unlock(&sb_lock
);
498 down_write(&sb
->s_umount
);
501 if (sb
->s_count
> S_BIAS
) {
502 atomic_inc(&sb
->s_active
);
504 spin_unlock(&sb_lock
);
507 spin_unlock(&sb_lock
);
509 up_write(&sb
->s_umount
);
514 spin_unlock(&sb_lock
);
518 struct super_block
* user_get_super(dev_t dev
)
520 struct super_block
*sb
;
524 list_for_each_entry(sb
, &super_blocks
, s_list
) {
525 if (sb
->s_dev
== dev
) {
527 spin_unlock(&sb_lock
);
528 down_read(&sb
->s_umount
);
531 up_read(&sb
->s_umount
);
532 /* restart only when sb is no longer on the list */
534 if (__put_super_and_need_restart(sb
))
538 spin_unlock(&sb_lock
);
542 SYSCALL_DEFINE2(ustat
, unsigned, dev
, struct ustat __user
*, ubuf
)
544 struct super_block
*s
;
549 s
= user_get_super(new_decode_dev(dev
));
552 err
= vfs_statfs(s
->s_root
, &sbuf
);
557 memset(&tmp
,0,sizeof(struct ustat
));
558 tmp
.f_tfree
= sbuf
.f_bfree
;
559 tmp
.f_tinode
= sbuf
.f_ffree
;
561 err
= copy_to_user(ubuf
,&tmp
,sizeof(struct ustat
)) ? -EFAULT
: 0;
567 * do_remount_sb - asks filesystem to change mount options.
568 * @sb: superblock in question
569 * @flags: numeric part of options
570 * @data: the rest of options
571 * @force: whether or not to force the change
573 * Alters the mount options of a mounted file system.
575 int do_remount_sb(struct super_block
*sb
, int flags
, void *data
, int force
)
578 int remount_rw
, remount_ro
;
580 if (sb
->s_frozen
!= SB_UNFROZEN
)
584 if (!(flags
& MS_RDONLY
) && bdev_read_only(sb
->s_bdev
))
588 if (flags
& MS_RDONLY
)
590 shrink_dcache_sb(sb
);
593 remount_ro
= (flags
& MS_RDONLY
) && !(sb
->s_flags
& MS_RDONLY
);
594 remount_rw
= !(flags
& MS_RDONLY
) && (sb
->s_flags
& MS_RDONLY
);
596 /* If we are remounting RDONLY and current sb is read/write,
597 make sure there are no rw files opened */
601 else if (!fs_may_remount_ro(sb
))
603 retval
= vfs_dq_off(sb
, 1);
604 if (retval
< 0 && retval
!= -ENOSYS
)
608 if (sb
->s_op
->remount_fs
) {
609 retval
= sb
->s_op
->remount_fs(sb
, &flags
, data
);
613 sb
->s_flags
= (sb
->s_flags
& ~MS_RMT_MASK
) | (flags
& MS_RMT_MASK
);
615 vfs_dq_quota_on_remount(sb
);
617 * Some filesystems modify their metadata via some other path than the
618 * bdev buffer cache (eg. use a private mapping, or directories in
619 * pagecache, etc). Also file data modifications go via their own
620 * mappings. So If we try to mount readonly then copy the filesystem
621 * from bdev, we could get stale data, so invalidate it to give a best
622 * effort at coherency.
624 if (remount_ro
&& sb
->s_bdev
)
625 invalidate_bdev(sb
->s_bdev
);
629 static void do_emergency_remount(struct work_struct
*work
)
631 struct super_block
*sb
;
634 list_for_each_entry(sb
, &super_blocks
, s_list
) {
636 spin_unlock(&sb_lock
);
637 down_write(&sb
->s_umount
);
638 if (sb
->s_root
&& sb
->s_bdev
&& !(sb
->s_flags
& MS_RDONLY
)) {
640 * ->remount_fs needs lock_kernel().
642 * What lock protects sb->s_flags??
644 do_remount_sb(sb
, MS_RDONLY
, NULL
, 1);
646 up_write(&sb
->s_umount
);
650 spin_unlock(&sb_lock
);
652 printk("Emergency Remount complete\n");
655 void emergency_remount(void)
657 struct work_struct
*work
;
659 work
= kmalloc(sizeof(*work
), GFP_ATOMIC
);
661 INIT_WORK(work
, do_emergency_remount
);
667 * Unnamed block devices are dummy devices used by virtual
668 * filesystems which don't use real block-devices. -- jrs
671 static DEFINE_IDA(unnamed_dev_ida
);
672 static DEFINE_SPINLOCK(unnamed_dev_lock
);/* protects the above */
673 static int unnamed_dev_start
= 0; /* don't bother trying below it */
675 int set_anon_super(struct super_block
*s
, void *data
)
681 if (ida_pre_get(&unnamed_dev_ida
, GFP_ATOMIC
) == 0)
683 spin_lock(&unnamed_dev_lock
);
684 error
= ida_get_new_above(&unnamed_dev_ida
, unnamed_dev_start
, &dev
);
686 unnamed_dev_start
= dev
+ 1;
687 spin_unlock(&unnamed_dev_lock
);
688 if (error
== -EAGAIN
)
689 /* We raced and lost with another CPU. */
694 if ((dev
& MAX_ID_MASK
) == (1 << MINORBITS
)) {
695 spin_lock(&unnamed_dev_lock
);
696 ida_remove(&unnamed_dev_ida
, dev
);
697 if (unnamed_dev_start
> dev
)
698 unnamed_dev_start
= dev
;
699 spin_unlock(&unnamed_dev_lock
);
702 s
->s_dev
= MKDEV(0, dev
& MINORMASK
);
703 s
->s_bdi
= &noop_backing_dev_info
;
707 EXPORT_SYMBOL(set_anon_super
);
709 void kill_anon_super(struct super_block
*sb
)
711 int slot
= MINOR(sb
->s_dev
);
713 generic_shutdown_super(sb
);
714 spin_lock(&unnamed_dev_lock
);
715 ida_remove(&unnamed_dev_ida
, slot
);
716 if (slot
< unnamed_dev_start
)
717 unnamed_dev_start
= slot
;
718 spin_unlock(&unnamed_dev_lock
);
721 EXPORT_SYMBOL(kill_anon_super
);
723 void kill_litter_super(struct super_block
*sb
)
726 d_genocide(sb
->s_root
);
730 EXPORT_SYMBOL(kill_litter_super
);
732 static int ns_test_super(struct super_block
*sb
, void *data
)
734 return sb
->s_fs_info
== data
;
737 static int ns_set_super(struct super_block
*sb
, void *data
)
739 sb
->s_fs_info
= data
;
740 return set_anon_super(sb
, NULL
);
743 int get_sb_ns(struct file_system_type
*fs_type
, int flags
, void *data
,
744 int (*fill_super
)(struct super_block
*, void *, int),
745 struct vfsmount
*mnt
)
747 struct super_block
*sb
;
749 sb
= sget(fs_type
, ns_test_super
, ns_set_super
, data
);
756 err
= fill_super(sb
, data
, flags
& MS_SILENT
? 1 : 0);
758 deactivate_locked_super(sb
);
762 sb
->s_flags
|= MS_ACTIVE
;
765 simple_set_mnt(mnt
, sb
);
769 EXPORT_SYMBOL(get_sb_ns
);
772 static int set_bdev_super(struct super_block
*s
, void *data
)
775 s
->s_dev
= s
->s_bdev
->bd_dev
;
778 * We set the bdi here to the queue backing, file systems can
779 * overwrite this in ->fill_super()
781 s
->s_bdi
= &bdev_get_queue(s
->s_bdev
)->backing_dev_info
;
785 static int test_bdev_super(struct super_block
*s
, void *data
)
787 return (void *)s
->s_bdev
== data
;
790 int get_sb_bdev(struct file_system_type
*fs_type
,
791 int flags
, const char *dev_name
, void *data
,
792 int (*fill_super
)(struct super_block
*, void *, int),
793 struct vfsmount
*mnt
)
795 struct block_device
*bdev
;
796 struct super_block
*s
;
797 fmode_t mode
= FMODE_READ
;
800 if (!(flags
& MS_RDONLY
))
803 bdev
= open_bdev_exclusive(dev_name
, mode
, fs_type
);
805 return PTR_ERR(bdev
);
808 * once the super is inserted into the list by sget, s_umount
809 * will protect the lockfs code from trying to start a snapshot
810 * while we are mounting
812 mutex_lock(&bdev
->bd_fsfreeze_mutex
);
813 if (bdev
->bd_fsfreeze_count
> 0) {
814 mutex_unlock(&bdev
->bd_fsfreeze_mutex
);
818 s
= sget(fs_type
, test_bdev_super
, set_bdev_super
, bdev
);
819 mutex_unlock(&bdev
->bd_fsfreeze_mutex
);
824 if ((flags
^ s
->s_flags
) & MS_RDONLY
) {
825 deactivate_locked_super(s
);
830 close_bdev_exclusive(bdev
, mode
);
832 char b
[BDEVNAME_SIZE
];
836 strlcpy(s
->s_id
, bdevname(bdev
, b
), sizeof(s
->s_id
));
837 sb_set_blocksize(s
, block_size(bdev
));
838 error
= fill_super(s
, data
, flags
& MS_SILENT
? 1 : 0);
840 deactivate_locked_super(s
);
844 s
->s_flags
|= MS_ACTIVE
;
848 simple_set_mnt(mnt
, s
);
854 close_bdev_exclusive(bdev
, mode
);
859 EXPORT_SYMBOL(get_sb_bdev
);
861 void kill_block_super(struct super_block
*sb
)
863 struct block_device
*bdev
= sb
->s_bdev
;
864 fmode_t mode
= sb
->s_mode
;
866 bdev
->bd_super
= NULL
;
867 generic_shutdown_super(sb
);
869 close_bdev_exclusive(bdev
, mode
);
872 EXPORT_SYMBOL(kill_block_super
);
875 int get_sb_nodev(struct file_system_type
*fs_type
,
876 int flags
, void *data
,
877 int (*fill_super
)(struct super_block
*, void *, int),
878 struct vfsmount
*mnt
)
881 struct super_block
*s
= sget(fs_type
, NULL
, set_anon_super
, NULL
);
888 error
= fill_super(s
, data
, flags
& MS_SILENT
? 1 : 0);
890 deactivate_locked_super(s
);
893 s
->s_flags
|= MS_ACTIVE
;
894 simple_set_mnt(mnt
, s
);
898 EXPORT_SYMBOL(get_sb_nodev
);
900 static int compare_single(struct super_block
*s
, void *p
)
905 int get_sb_single(struct file_system_type
*fs_type
,
906 int flags
, void *data
,
907 int (*fill_super
)(struct super_block
*, void *, int),
908 struct vfsmount
*mnt
)
910 struct super_block
*s
;
913 s
= sget(fs_type
, compare_single
, set_anon_super
, NULL
);
918 error
= fill_super(s
, data
, flags
& MS_SILENT
? 1 : 0);
920 deactivate_locked_super(s
);
923 s
->s_flags
|= MS_ACTIVE
;
925 do_remount_sb(s
, flags
, data
, 0);
927 simple_set_mnt(mnt
, s
);
931 EXPORT_SYMBOL(get_sb_single
);
934 vfs_kern_mount(struct file_system_type
*type
, int flags
, const char *name
, void *data
)
936 struct vfsmount
*mnt
;
937 char *secdata
= NULL
;
941 return ERR_PTR(-ENODEV
);
944 mnt
= alloc_vfsmnt(name
);
948 if (flags
& MS_KERNMOUNT
)
949 mnt
->mnt_flags
= MNT_INTERNAL
;
951 if (data
&& !(type
->fs_flags
& FS_BINARY_MOUNTDATA
)) {
952 secdata
= alloc_secdata();
956 error
= security_sb_copy_data(data
, secdata
);
958 goto out_free_secdata
;
961 error
= type
->get_sb(type
, flags
, name
, data
, mnt
);
963 goto out_free_secdata
;
964 BUG_ON(!mnt
->mnt_sb
);
965 WARN_ON(!mnt
->mnt_sb
->s_bdi
);
966 WARN_ON(mnt
->mnt_sb
->s_bdi
== &default_backing_dev_info
);
967 mnt
->mnt_sb
->s_flags
|= MS_BORN
;
969 error
= security_sb_kern_mount(mnt
->mnt_sb
, flags
, secdata
);
974 * filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
975 * but s_maxbytes was an unsigned long long for many releases. Throw
976 * this warning for a little while to try and catch filesystems that
977 * violate this rule. This warning should be either removed or
978 * converted to a BUG() in 2.6.34.
980 WARN((mnt
->mnt_sb
->s_maxbytes
< 0), "%s set sb->s_maxbytes to "
981 "negative value (%lld)\n", type
->name
, mnt
->mnt_sb
->s_maxbytes
);
983 mnt
->mnt_mountpoint
= mnt
->mnt_root
;
984 mnt
->mnt_parent
= mnt
;
985 up_write(&mnt
->mnt_sb
->s_umount
);
986 free_secdata(secdata
);
990 deactivate_locked_super(mnt
->mnt_sb
);
992 free_secdata(secdata
);
996 return ERR_PTR(error
);
999 EXPORT_SYMBOL_GPL(vfs_kern_mount
);
1001 static struct vfsmount
*fs_set_subtype(struct vfsmount
*mnt
, const char *fstype
)
1004 const char *subtype
= strchr(fstype
, '.');
1013 mnt
->mnt_sb
->s_subtype
= kstrdup(subtype
, GFP_KERNEL
);
1015 if (!mnt
->mnt_sb
->s_subtype
)
1021 return ERR_PTR(err
);
1025 do_kern_mount(const char *fstype
, int flags
, const char *name
, void *data
)
1027 struct file_system_type
*type
= get_fs_type(fstype
);
1028 struct vfsmount
*mnt
;
1030 return ERR_PTR(-ENODEV
);
1031 mnt
= vfs_kern_mount(type
, flags
, name
, data
);
1032 if (!IS_ERR(mnt
) && (type
->fs_flags
& FS_HAS_SUBTYPE
) &&
1033 !mnt
->mnt_sb
->s_subtype
)
1034 mnt
= fs_set_subtype(mnt
, fstype
);
1035 put_filesystem(type
);
1038 EXPORT_SYMBOL_GPL(do_kern_mount
);
1040 struct vfsmount
*kern_mount_data(struct file_system_type
*type
, void *data
)
1042 return vfs_kern_mount(type
, MS_KERNMOUNT
, type
->name
, data
);
1045 EXPORT_SYMBOL_GPL(kern_mount_data
);