VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100   1) // SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   2) /*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   3)  *  linux/fs/filesystems.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   4)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   5)  *  Copyright (C) 1991, 1992  Linus Torvalds
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   6)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   7)  *  table of configured filesystems
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   8)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   9) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  10) #include <linux/syscalls.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  11) #include <linux/fs.h>
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400  12) #include <linux/proc_fs.h>
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400  13) #include <linux/seq_file.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  14) #include <linux/kmod.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  15) #include <linux/init.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  16) #include <linux/module.h>
5a0e3ad6af866 (Tejun Heo          2010-03-24 17:04:11 +0900  17) #include <linux/slab.h>
7c0f6ba682b9c (Linus Torvalds     2016-12-24 11:46:01 -0800  18) #include <linux/uaccess.h>
3e1aeb00e6d13 (David Howells      2018-11-01 23:07:25 +0000  19) #include <linux/fs_parser.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  20) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  21) /*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  22)  * Handling of filesystem drivers list.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  23)  * Rules:
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  24)  *	Inclusion to/removals from/scanning of list are protected by spinlock.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  25)  *	During the unload module must call unregister_filesystem().
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  26)  *	We can access the fields of list element if:
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  27)  *		1) spinlock is held or
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  28)  *		2) we hold the reference to the module.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  29)  *	The latter can be guaranteed by call of try_module_get(); if it
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  30)  *	returned 0 we must skip the element, otherwise we got the reference.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  31)  *	Once the reference is obtained we can drop the spinlock.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  32)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  33) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  34) static struct file_system_type *file_systems;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  35) static DEFINE_RWLOCK(file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  36) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  37) /* WARNING: This can be used only if we _already_ own a reference */
ee416bcdba997 (David Howells      2017-07-04 17:25:16 +0100  38) struct file_system_type *get_filesystem(struct file_system_type *fs)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  39) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  40) 	__module_get(fs->owner);
ee416bcdba997 (David Howells      2017-07-04 17:25:16 +0100  41) 	return fs;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  42) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  43) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  44) void put_filesystem(struct file_system_type *fs)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  45) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  46) 	module_put(fs->owner);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  47) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  48) 
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700  49) static struct file_system_type **find_filesystem(const char *name, unsigned len)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  50) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  51) 	struct file_system_type **p;
558041d8d21b4 (Al Viro            2016-01-19 11:40:44 -0500  52) 	for (p = &file_systems; *p; p = &(*p)->next)
558041d8d21b4 (Al Viro            2016-01-19 11:40:44 -0500  53) 		if (strncmp((*p)->name, name, len) == 0 &&
558041d8d21b4 (Al Viro            2016-01-19 11:40:44 -0500  54) 		    !(*p)->name[len])
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  55) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  56) 	return p;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  57) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  58) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  59) /**
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  60)  *	register_filesystem - register a new filesystem
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  61)  *	@fs: the file system structure
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  62)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  63)  *	Adds the file system passed to the list of file systems the kernel
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  64)  *	is aware of for mount and other syscalls. Returns 0 on success,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  65)  *	or a negative errno code on an error.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  66)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  67)  *	The &struct file_system_type that is passed is linked into the kernel 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  68)  *	structures and must not be freed until the file system has been
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  69)  *	unregistered.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  70)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  71)  
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  72) int register_filesystem(struct file_system_type * fs)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  73) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  74) 	int res = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  75) 	struct file_system_type ** p;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  76) 
96cafb9ccb153 (Eric Sandeen       2019-12-06 10:45:01 -0600  77) 	if (fs->parameters &&
96cafb9ccb153 (Eric Sandeen       2019-12-06 10:45:01 -0600  78) 	    !fs_validate_description(fs->name, fs->parameters))
3e1aeb00e6d13 (David Howells      2018-11-01 23:07:25 +0000  79) 		return -EINVAL;
3e1aeb00e6d13 (David Howells      2018-11-01 23:07:25 +0000  80) 
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700  81) 	BUG_ON(strchr(fs->name, '.'));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  82) 	if (fs->next)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  83) 		return -EBUSY;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  84) 	write_lock(&file_systems_lock);
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700  85) 	p = find_filesystem(fs->name, strlen(fs->name));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  86) 	if (*p)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  87) 		res = -EBUSY;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  88) 	else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  89) 		*p = fs;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  90) 	write_unlock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  91) 	return res;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  92) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  93) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  94) EXPORT_SYMBOL(register_filesystem);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  95) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  96) /**
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  97)  *	unregister_filesystem - unregister a file system
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  98)  *	@fs: filesystem to unregister
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  99)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 100)  *	Remove a file system that was previously successfully registered
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 101)  *	with the kernel. An error is returned if the file system is not found.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 102)  *	Zero is returned on a success.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 103)  *	
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 104)  *	Once this function has returned the &struct file_system_type structure
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 105)  *	may be freed or reused.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 106)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 107)  
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 108) int unregister_filesystem(struct file_system_type * fs)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 109) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 110) 	struct file_system_type ** tmp;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 111) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 112) 	write_lock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 113) 	tmp = &file_systems;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 114) 	while (*tmp) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 115) 		if (fs == *tmp) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 116) 			*tmp = fs->next;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 117) 			fs->next = NULL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 118) 			write_unlock(&file_systems_lock);
fff3e5ade4455 (Milton Miller      2011-04-14 10:30:08 -0500 119) 			synchronize_rcu();
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 120) 			return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 121) 		}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 122) 		tmp = &(*tmp)->next;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 123) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 124) 	write_unlock(&file_systems_lock);
31e6b01f4183f (Nicholas Piggin    2011-01-07 17:49:52 +1100 125) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 126) 	return -EINVAL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 127) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 128) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 129) EXPORT_SYMBOL(unregister_filesystem);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 130) 
6af9f7bf3c399 (Fabian Frederick   2014-04-03 14:48:25 -0700 131) #ifdef CONFIG_SYSFS_SYSCALL
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 132) static int fs_index(const char __user * __name)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 133) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 134) 	struct file_system_type * tmp;
91a27b2a75678 (Jeff Layton        2012-10-10 15:25:28 -0400 135) 	struct filename *name;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 136) 	int err, index;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 137) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 138) 	name = getname(__name);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 139) 	err = PTR_ERR(name);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 140) 	if (IS_ERR(name))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 141) 		return err;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 142) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 143) 	err = -EINVAL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 144) 	read_lock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 145) 	for (tmp=file_systems, index=0 ; tmp ; tmp=tmp->next, index++) {
91a27b2a75678 (Jeff Layton        2012-10-10 15:25:28 -0400 146) 		if (strcmp(tmp->name, name->name) == 0) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 147) 			err = index;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 148) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 149) 		}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 150) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 151) 	read_unlock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 152) 	putname(name);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 153) 	return err;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 154) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 155) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 156) static int fs_name(unsigned int index, char __user * buf)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 157) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 158) 	struct file_system_type * tmp;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 159) 	int len, res;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 160) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 161) 	read_lock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 162) 	for (tmp = file_systems; tmp; tmp = tmp->next, index--)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 163) 		if (index <= 0 && try_module_get(tmp->owner))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 164) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 165) 	read_unlock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 166) 	if (!tmp)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 167) 		return -EINVAL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 168) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 169) 	/* OK, we got the reference, so we can safely block */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 170) 	len = strlen(tmp->name) + 1;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 171) 	res = copy_to_user(buf, tmp->name, len) ? -EFAULT : 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 172) 	put_filesystem(tmp);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 173) 	return res;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 174) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 175) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 176) static int fs_maxindex(void)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 177) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 178) 	struct file_system_type * tmp;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 179) 	int index;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 180) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 181) 	read_lock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 182) 	for (tmp = file_systems, index = 0 ; tmp ; tmp = tmp->next, index++)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 183) 		;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 184) 	read_unlock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 185) 	return index;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 186) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 187) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 188) /*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 189)  * Whee.. Weird sysv syscall. 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 190)  */
1e7bfb2134dfe (Heiko Carstens     2009-01-14 14:14:29 +0100 191) SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 192) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 193) 	int retval = -EINVAL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 194) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 195) 	switch (option) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 196) 		case 1:
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 197) 			retval = fs_index((const char __user *) arg1);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 198) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 199) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 200) 		case 2:
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 201) 			retval = fs_name(arg1, (char __user *) arg2);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 202) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 203) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 204) 		case 3:
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 205) 			retval = fs_maxindex();
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 206) 			break;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 207) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 208) 	return retval;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 209) }
6af9f7bf3c399 (Fabian Frederick   2014-04-03 14:48:25 -0700 210) #endif
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 211) 
38e23c95f92a8 (Tetsuo Handa       2009-04-09 20:17:52 +0900 212) int __init get_filesystem_list(char *buf)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 213) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 214) 	int len = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 215) 	struct file_system_type * tmp;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 216) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 217) 	read_lock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 218) 	tmp = file_systems;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 219) 	while (tmp && len < PAGE_SIZE - 80) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 220) 		len += sprintf(buf+len, "%s\t%s\n",
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 221) 			(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 222) 			tmp->name);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 223) 		tmp = tmp->next;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 224) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 225) 	read_unlock(&file_systems_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 226) 	return len;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 227) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 228) 
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 229) #ifdef CONFIG_PROC_FS
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 230) static int filesystems_proc_show(struct seq_file *m, void *v)
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 231) {
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 232) 	struct file_system_type * tmp;
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 233) 
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 234) 	read_lock(&file_systems_lock);
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 235) 	tmp = file_systems;
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 236) 	while (tmp) {
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 237) 		seq_printf(m, "%s\t%s\n",
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 238) 			(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 239) 			tmp->name);
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 240) 		tmp = tmp->next;
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 241) 	}
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 242) 	read_unlock(&file_systems_lock);
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 243) 	return 0;
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 244) }
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 245) 
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 246) static int __init proc_filesystems_init(void)
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 247) {
3f3942aca6da3 (Christoph Hellwig  2018-05-15 15:57:23 +0200 248) 	proc_create_single("filesystems", 0, NULL, filesystems_proc_show);
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 249) 	return 0;
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 250) }
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 251) module_init(proc_filesystems_init);
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 252) #endif
6827400713fa2 (Alexey Dobriyan    2008-10-04 14:08:37 +0400 253) 
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 254) static struct file_system_type *__get_fs_type(const char *name, int len)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 255) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 256) 	struct file_system_type *fs;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 257) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 258) 	read_lock(&file_systems_lock);
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 259) 	fs = *(find_filesystem(name, len));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 260) 	if (fs && !try_module_get(fs->owner))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 261) 		fs = NULL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 262) 	read_unlock(&file_systems_lock);
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 263) 	return fs;
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 264) }
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 265) 
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 266) struct file_system_type *get_fs_type(const char *name)
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 267) {
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 268) 	struct file_system_type *fs;
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 269) 	const char *dot = strchr(name, '.');
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 270) 	int len = dot ? dot - name : strlen(name);
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 271) 
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 272) 	fs = __get_fs_type(name, len);
41124db869b7e (Luis R. Rodriguez  2017-06-01 11:08:01 -0700 273) 	if (!fs && (request_module("fs-%.*s", len, name) == 0)) {
d8e9650dff480 (Li Zefan           2008-12-25 13:32:15 +0800 274) 		fs = __get_fs_type(name, len);
26c5d78c976ca (Eric Biggers       2020-04-10 14:33:47 -0700 275) 		if (!fs)
26c5d78c976ca (Eric Biggers       2020-04-10 14:33:47 -0700 276) 			pr_warn_once("request_module fs-%.*s succeeded, but still no fs?\n",
26c5d78c976ca (Eric Biggers       2020-04-10 14:33:47 -0700 277) 				     len, name);
41124db869b7e (Luis R. Rodriguez  2017-06-01 11:08:01 -0700 278) 	}
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 279) 
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 280) 	if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 281) 		put_filesystem(fs);
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 282) 		fs = NULL;
79c0b2df79eb5 (Miklos Szeredi     2007-05-08 00:25:43 -0700 283) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 284) 	return fs;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 285) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 286) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 287) EXPORT_SYMBOL(get_fs_type);