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