18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci==================== 48c2ecf20Sopenharmony_ciFilesystem Mount API 58c2ecf20Sopenharmony_ci==================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci.. CONTENTS 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci (1) Overview. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci (2) The filesystem context. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci (3) The filesystem context operations. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci (4) Filesystem context security. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci (5) VFS filesystem context API. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci (6) Superblock creation helpers. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci (7) Parameter description. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci (8) Parameter helper functions. 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciOverview 278c2ecf20Sopenharmony_ci======== 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciThe creation of new mounts is now to be done in a multistep process: 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci (1) Create a filesystem context. 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci (2) Parse the parameters and attach them to the context. Parameters are 348c2ecf20Sopenharmony_ci expected to be passed individually from userspace, though legacy binary 358c2ecf20Sopenharmony_ci parameters can also be handled. 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci (3) Validate and pre-process the context. 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci (4) Get or create a superblock and mountable root. 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci (5) Perform the mount. 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci (6) Return an error message attached to the context. 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci (7) Destroy the context. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciTo support this, the file_system_type struct gains two new fields:: 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci int (*init_fs_context)(struct fs_context *fc); 508c2ecf20Sopenharmony_ci const struct fs_parameter_description *parameters; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciThe first is invoked to set up the filesystem-specific parts of a filesystem 538c2ecf20Sopenharmony_cicontext, including the additional space, and the second points to the 548c2ecf20Sopenharmony_ciparameter description for validation at registration time and querying by a 558c2ecf20Sopenharmony_cifuture system call. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciNote that security initialisation is done *after* the filesystem is called so 588c2ecf20Sopenharmony_cithat the namespaces may be adjusted first. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciThe Filesystem context 628c2ecf20Sopenharmony_ci====================== 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciThe creation and reconfiguration of a superblock is governed by a filesystem 658c2ecf20Sopenharmony_cicontext. This is represented by the fs_context structure:: 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci struct fs_context { 688c2ecf20Sopenharmony_ci const struct fs_context_operations *ops; 698c2ecf20Sopenharmony_ci struct file_system_type *fs_type; 708c2ecf20Sopenharmony_ci void *fs_private; 718c2ecf20Sopenharmony_ci struct dentry *root; 728c2ecf20Sopenharmony_ci struct user_namespace *user_ns; 738c2ecf20Sopenharmony_ci struct net *net_ns; 748c2ecf20Sopenharmony_ci const struct cred *cred; 758c2ecf20Sopenharmony_ci char *source; 768c2ecf20Sopenharmony_ci char *subtype; 778c2ecf20Sopenharmony_ci void *security; 788c2ecf20Sopenharmony_ci void *s_fs_info; 798c2ecf20Sopenharmony_ci unsigned int sb_flags; 808c2ecf20Sopenharmony_ci unsigned int sb_flags_mask; 818c2ecf20Sopenharmony_ci unsigned int s_iflags; 828c2ecf20Sopenharmony_ci unsigned int lsm_flags; 838c2ecf20Sopenharmony_ci enum fs_context_purpose purpose:8; 848c2ecf20Sopenharmony_ci ... 858c2ecf20Sopenharmony_ci }; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciThe fs_context fields are as follows: 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci * :: 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci const struct fs_context_operations *ops 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci These are operations that can be done on a filesystem context (see 948c2ecf20Sopenharmony_ci below). This must be set by the ->init_fs_context() file_system_type 958c2ecf20Sopenharmony_ci operation. 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci * :: 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci struct file_system_type *fs_type 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci A pointer to the file_system_type of the filesystem that is being 1028c2ecf20Sopenharmony_ci constructed or reconfigured. This retains a reference on the type owner. 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci * :: 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci void *fs_private 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci A pointer to the file system's private data. This is where the filesystem 1098c2ecf20Sopenharmony_ci will need to store any options it parses. 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci * :: 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci struct dentry *root 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci A pointer to the root of the mountable tree (and indirectly, the 1168c2ecf20Sopenharmony_ci superblock thereof). This is filled in by the ->get_tree() op. If this 1178c2ecf20Sopenharmony_ci is set, an active reference on root->d_sb must also be held. 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci * :: 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci struct user_namespace *user_ns 1228c2ecf20Sopenharmony_ci struct net *net_ns 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci There are a subset of the namespaces in use by the invoking process. They 1258c2ecf20Sopenharmony_ci retain references on each namespace. The subscribed namespaces may be 1268c2ecf20Sopenharmony_ci replaced by the filesystem to reflect other sources, such as the parent 1278c2ecf20Sopenharmony_ci mount superblock on an automount. 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci * :: 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci const struct cred *cred 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci The mounter's credentials. This retains a reference on the credentials. 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci * :: 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci char *source 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci This specifies the source. It may be a block device (e.g. /dev/sda1) or 1408c2ecf20Sopenharmony_ci something more exotic, such as the "host:/path" that NFS desires. 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci * :: 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci char *subtype 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci This is a string to be added to the type displayed in /proc/mounts to 1478c2ecf20Sopenharmony_ci qualify it (used by FUSE). This is available for the filesystem to set if 1488c2ecf20Sopenharmony_ci desired. 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci * :: 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci void *security 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci A place for the LSMs to hang their security data for the superblock. The 1558c2ecf20Sopenharmony_ci relevant security operations are described below. 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci * :: 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci void *s_fs_info 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci The proposed s_fs_info for a new superblock, set in the superblock by 1628c2ecf20Sopenharmony_ci sget_fc(). This can be used to distinguish superblocks. 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci * :: 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci unsigned int sb_flags 1678c2ecf20Sopenharmony_ci unsigned int sb_flags_mask 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci Which bits SB_* flags are to be set/cleared in super_block::s_flags. 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci * :: 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci unsigned int s_iflags 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci These will be bitwise-OR'd with s->s_iflags when a superblock is created. 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci * :: 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci enum fs_context_purpose 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci This indicates the purpose for which the context is intended. The 1828c2ecf20Sopenharmony_ci available values are: 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci ========================== ====================================== 1858c2ecf20Sopenharmony_ci FS_CONTEXT_FOR_MOUNT, New superblock for explicit mount 1868c2ecf20Sopenharmony_ci FS_CONTEXT_FOR_SUBMOUNT New automatic submount of extant mount 1878c2ecf20Sopenharmony_ci FS_CONTEXT_FOR_RECONFIGURE Change an existing mount 1888c2ecf20Sopenharmony_ci ========================== ====================================== 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciThe mount context is created by calling vfs_new_fs_context() or 1918c2ecf20Sopenharmony_civfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the 1928c2ecf20Sopenharmony_cistructure is not refcounted. 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ciVFS, security and filesystem mount options are set individually with 1958c2ecf20Sopenharmony_civfs_parse_mount_option(). Options provided by the old mount(2) system call as 1968c2ecf20Sopenharmony_cia page of data can be parsed with generic_parse_monolithic(). 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ciWhen mounting, the filesystem is allowed to take data from any of the pointers 1998c2ecf20Sopenharmony_ciand attach it to the superblock (or whatever), provided it clears the pointer 2008c2ecf20Sopenharmony_ciin the mount context. 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ciThe filesystem is also allowed to allocate resources and pin them with the 2038c2ecf20Sopenharmony_cimount context. For instance, NFS might pin the appropriate protocol version 2048c2ecf20Sopenharmony_cimodule. 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ciThe Filesystem Context Operations 2088c2ecf20Sopenharmony_ci================================= 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ciThe filesystem context points to a table of operations:: 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci struct fs_context_operations { 2138c2ecf20Sopenharmony_ci void (*free)(struct fs_context *fc); 2148c2ecf20Sopenharmony_ci int (*dup)(struct fs_context *fc, struct fs_context *src_fc); 2158c2ecf20Sopenharmony_ci int (*parse_param)(struct fs_context *fc, 2168c2ecf20Sopenharmony_ci struct fs_parameter *param); 2178c2ecf20Sopenharmony_ci int (*parse_monolithic)(struct fs_context *fc, void *data); 2188c2ecf20Sopenharmony_ci int (*get_tree)(struct fs_context *fc); 2198c2ecf20Sopenharmony_ci int (*reconfigure)(struct fs_context *fc); 2208c2ecf20Sopenharmony_ci }; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ciThese operations are invoked by the various stages of the mount procedure to 2238c2ecf20Sopenharmony_cimanage the filesystem context. They are as follows: 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci * :: 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci void (*free)(struct fs_context *fc); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci Called to clean up the filesystem-specific part of the filesystem context 2308c2ecf20Sopenharmony_ci when the context is destroyed. It should be aware that parts of the 2318c2ecf20Sopenharmony_ci context may have been removed and NULL'd out by ->get_tree(). 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci * :: 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci int (*dup)(struct fs_context *fc, struct fs_context *src_fc); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci Called when a filesystem context has been duplicated to duplicate the 2388c2ecf20Sopenharmony_ci filesystem-private data. An error may be returned to indicate failure to 2398c2ecf20Sopenharmony_ci do this. 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci .. Warning:: 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci Note that even if this fails, put_fs_context() will be called 2448c2ecf20Sopenharmony_ci immediately thereafter, so ->dup() *must* make the 2458c2ecf20Sopenharmony_ci filesystem-private data safe for ->free(). 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci * :: 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci int (*parse_param)(struct fs_context *fc, 2508c2ecf20Sopenharmony_ci struct fs_parameter *param); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci Called when a parameter is being added to the filesystem context. param 2538c2ecf20Sopenharmony_ci points to the key name and maybe a value object. VFS-specific options 2548c2ecf20Sopenharmony_ci will have been weeded out and fc->sb_flags updated in the context. 2558c2ecf20Sopenharmony_ci Security options will also have been weeded out and fc->security updated. 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci The parameter can be parsed with fs_parse() and fs_lookup_param(). Note 2588c2ecf20Sopenharmony_ci that the source(s) are presented as parameters named "source". 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci If successful, 0 should be returned or a negative error code otherwise. 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci * :: 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci int (*parse_monolithic)(struct fs_context *fc, void *data); 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci Called when the mount(2) system call is invoked to pass the entire data 2678c2ecf20Sopenharmony_ci page in one go. If this is expected to be just a list of "key[=val]" 2688c2ecf20Sopenharmony_ci items separated by commas, then this may be set to NULL. 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci The return value is as for ->parse_param(). 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci If the filesystem (e.g. NFS) needs to examine the data first and then 2738c2ecf20Sopenharmony_ci finds it's the standard key-val list then it may pass it off to 2748c2ecf20Sopenharmony_ci generic_parse_monolithic(). 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci * :: 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci int (*get_tree)(struct fs_context *fc); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci Called to get or create the mountable root and superblock, using the 2818c2ecf20Sopenharmony_ci information stored in the filesystem context (reconfiguration goes via a 2828c2ecf20Sopenharmony_ci different vector). It may detach any resources it desires from the 2838c2ecf20Sopenharmony_ci filesystem context and transfer them to the superblock it creates. 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci On success it should set fc->root to the mountable root and return 0. In 2868c2ecf20Sopenharmony_ci the case of an error, it should return a negative error code. 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci The phase on a userspace-driven context will be set to only allow this to 2898c2ecf20Sopenharmony_ci be called once on any particular context. 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci * :: 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci int (*reconfigure)(struct fs_context *fc); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci Called to effect reconfiguration of a superblock using information stored 2968c2ecf20Sopenharmony_ci in the filesystem context. It may detach any resources it desires from 2978c2ecf20Sopenharmony_ci the filesystem context and transfer them to the superblock. The 2988c2ecf20Sopenharmony_ci superblock can be found from fc->root->d_sb. 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci On success it should return 0. In the case of an error, it should return 3018c2ecf20Sopenharmony_ci a negative error code. 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci .. Note:: reconfigure is intended as a replacement for remount_fs. 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ciFilesystem context Security 3078c2ecf20Sopenharmony_ci=========================== 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ciThe filesystem context contains a security pointer that the LSMs can use for 3108c2ecf20Sopenharmony_cibuilding up a security context for the superblock to be mounted. There are a 3118c2ecf20Sopenharmony_cinumber of operations used by the new mount code for this purpose: 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci * :: 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci int security_fs_context_alloc(struct fs_context *fc, 3168c2ecf20Sopenharmony_ci struct dentry *reference); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci Called to initialise fc->security (which is preset to NULL) and allocate 3198c2ecf20Sopenharmony_ci any resources needed. It should return 0 on success or a negative error 3208c2ecf20Sopenharmony_ci code on failure. 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci reference will be non-NULL if the context is being created for superblock 3238c2ecf20Sopenharmony_ci reconfiguration (FS_CONTEXT_FOR_RECONFIGURE) in which case it indicates 3248c2ecf20Sopenharmony_ci the root dentry of the superblock to be reconfigured. It will also be 3258c2ecf20Sopenharmony_ci non-NULL in the case of a submount (FS_CONTEXT_FOR_SUBMOUNT) in which case 3268c2ecf20Sopenharmony_ci it indicates the automount point. 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci * :: 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci int security_fs_context_dup(struct fs_context *fc, 3318c2ecf20Sopenharmony_ci struct fs_context *src_fc); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci Called to initialise fc->security (which is preset to NULL) and allocate 3348c2ecf20Sopenharmony_ci any resources needed. The original filesystem context is pointed to by 3358c2ecf20Sopenharmony_ci src_fc and may be used for reference. It should return 0 on success or a 3368c2ecf20Sopenharmony_ci negative error code on failure. 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci * :: 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci void security_fs_context_free(struct fs_context *fc); 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci Called to clean up anything attached to fc->security. Note that the 3438c2ecf20Sopenharmony_ci contents may have been transferred to a superblock and the pointer cleared 3448c2ecf20Sopenharmony_ci during get_tree. 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci * :: 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci int security_fs_context_parse_param(struct fs_context *fc, 3498c2ecf20Sopenharmony_ci struct fs_parameter *param); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci Called for each mount parameter, including the source. The arguments are 3528c2ecf20Sopenharmony_ci as for the ->parse_param() method. It should return 0 to indicate that 3538c2ecf20Sopenharmony_ci the parameter should be passed on to the filesystem, 1 to indicate that 3548c2ecf20Sopenharmony_ci the parameter should be discarded or an error to indicate that the 3558c2ecf20Sopenharmony_ci parameter should be rejected. 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci The value pointed to by param may be modified (if a string) or stolen 3588c2ecf20Sopenharmony_ci (provided the value pointer is NULL'd out). If it is stolen, 1 must be 3598c2ecf20Sopenharmony_ci returned to prevent it being passed to the filesystem. 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci * :: 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci int security_fs_context_validate(struct fs_context *fc); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci Called after all the options have been parsed to validate the collection 3668c2ecf20Sopenharmony_ci as a whole and to do any necessary allocation so that 3678c2ecf20Sopenharmony_ci security_sb_get_tree() and security_sb_reconfigure() are less likely to 3688c2ecf20Sopenharmony_ci fail. It should return 0 or a negative error code. 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci In the case of reconfiguration, the target superblock will be accessible 3718c2ecf20Sopenharmony_ci via fc->root. 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci * :: 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci int security_sb_get_tree(struct fs_context *fc); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci Called during the mount procedure to verify that the specified superblock 3788c2ecf20Sopenharmony_ci is allowed to be mounted and to transfer the security data there. It 3798c2ecf20Sopenharmony_ci should return 0 or a negative error code. 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci * :: 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci void security_sb_reconfigure(struct fs_context *fc); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci Called to apply any reconfiguration to an LSM's context. It must not 3868c2ecf20Sopenharmony_ci fail. Error checking and resource allocation must be done in advance by 3878c2ecf20Sopenharmony_ci the parameter parsing and validation hooks. 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci * :: 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci int security_sb_mountpoint(struct fs_context *fc, 3928c2ecf20Sopenharmony_ci struct path *mountpoint, 3938c2ecf20Sopenharmony_ci unsigned int mnt_flags); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci Called during the mount procedure to verify that the root dentry attached 3968c2ecf20Sopenharmony_ci to the context is permitted to be attached to the specified mountpoint. 3978c2ecf20Sopenharmony_ci It should return 0 on success or a negative error code on failure. 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ciVFS Filesystem context API 4018c2ecf20Sopenharmony_ci========================== 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ciThere are four operations for creating a filesystem context and one for 4048c2ecf20Sopenharmony_cidestroying a context: 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci * :: 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci struct fs_context *fs_context_for_mount(struct file_system_type *fs_type, 4098c2ecf20Sopenharmony_ci unsigned int sb_flags); 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci Allocate a filesystem context for the purpose of setting up a new mount, 4128c2ecf20Sopenharmony_ci whether that be with a new superblock or sharing an existing one. This 4138c2ecf20Sopenharmony_ci sets the superblock flags, initialises the security and calls 4148c2ecf20Sopenharmony_ci fs_type->init_fs_context() to initialise the filesystem private data. 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci fs_type specifies the filesystem type that will manage the context and 4178c2ecf20Sopenharmony_ci sb_flags presets the superblock flags stored therein. 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci * :: 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci struct fs_context *fs_context_for_reconfigure( 4228c2ecf20Sopenharmony_ci struct dentry *dentry, 4238c2ecf20Sopenharmony_ci unsigned int sb_flags, 4248c2ecf20Sopenharmony_ci unsigned int sb_flags_mask); 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci Allocate a filesystem context for the purpose of reconfiguring an 4278c2ecf20Sopenharmony_ci existing superblock. dentry provides a reference to the superblock to be 4288c2ecf20Sopenharmony_ci configured. sb_flags and sb_flags_mask indicate which superblock flags 4298c2ecf20Sopenharmony_ci need changing and to what. 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci * :: 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci struct fs_context *fs_context_for_submount( 4348c2ecf20Sopenharmony_ci struct file_system_type *fs_type, 4358c2ecf20Sopenharmony_ci struct dentry *reference); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci Allocate a filesystem context for the purpose of creating a new mount for 4388c2ecf20Sopenharmony_ci an automount point or other derived superblock. fs_type specifies the 4398c2ecf20Sopenharmony_ci filesystem type that will manage the context and the reference dentry 4408c2ecf20Sopenharmony_ci supplies the parameters. Namespaces are propagated from the reference 4418c2ecf20Sopenharmony_ci dentry's superblock also. 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci Note that it's not a requirement that the reference dentry be of the same 4448c2ecf20Sopenharmony_ci filesystem type as fs_type. 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci * :: 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci Duplicate a filesystem context, copying any options noted and duplicating 4518c2ecf20Sopenharmony_ci or additionally referencing any resources held therein. This is available 4528c2ecf20Sopenharmony_ci for use where a filesystem has to get a mount within a mount, such as NFS4 4538c2ecf20Sopenharmony_ci does by internally mounting the root of the target server and then doing a 4548c2ecf20Sopenharmony_ci private pathwalk to the target directory. 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci The purpose in the new context is inherited from the old one. 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci * :: 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci void put_fs_context(struct fs_context *fc); 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci Destroy a filesystem context, releasing any resources it holds. This 4638c2ecf20Sopenharmony_ci calls the ->free() operation. This is intended to be called by anyone who 4648c2ecf20Sopenharmony_ci created a filesystem context. 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci .. Warning:: 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci filesystem contexts are not refcounted, so this causes unconditional 4698c2ecf20Sopenharmony_ci destruction. 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ciIn all the above operations, apart from the put op, the return is a mount 4728c2ecf20Sopenharmony_cicontext pointer or a negative error code. 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ciFor the remaining operations, if an error occurs, a negative error code will be 4758c2ecf20Sopenharmony_cireturned. 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci * :: 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci int vfs_parse_fs_param(struct fs_context *fc, 4808c2ecf20Sopenharmony_ci struct fs_parameter *param); 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci Supply a single mount parameter to the filesystem context. This includes 4838c2ecf20Sopenharmony_ci the specification of the source/device which is specified as the "source" 4848c2ecf20Sopenharmony_ci parameter (which may be specified multiple times if the filesystem 4858c2ecf20Sopenharmony_ci supports that). 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci param specifies the parameter key name and the value. The parameter is 4888c2ecf20Sopenharmony_ci first checked to see if it corresponds to a standard mount flag (in which 4898c2ecf20Sopenharmony_ci case it is used to set an SB_xxx flag and consumed) or a security option 4908c2ecf20Sopenharmony_ci (in which case the LSM consumes it) before it is passed on to the 4918c2ecf20Sopenharmony_ci filesystem. 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci The parameter value is typed and can be one of: 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci ==================== ============================= 4968c2ecf20Sopenharmony_ci fs_value_is_flag Parameter not given a value 4978c2ecf20Sopenharmony_ci fs_value_is_string Value is a string 4988c2ecf20Sopenharmony_ci fs_value_is_blob Value is a binary blob 4998c2ecf20Sopenharmony_ci fs_value_is_filename Value is a filename* + dirfd 5008c2ecf20Sopenharmony_ci fs_value_is_file Value is an open file (file*) 5018c2ecf20Sopenharmony_ci ==================== ============================= 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci If there is a value, that value is stored in a union in the struct in one 5048c2ecf20Sopenharmony_ci of param->{string,blob,name,file}. Note that the function may steal and 5058c2ecf20Sopenharmony_ci clear the pointer, but then becomes responsible for disposing of the 5068c2ecf20Sopenharmony_ci object. 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci * :: 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci int vfs_parse_fs_string(struct fs_context *fc, const char *key, 5118c2ecf20Sopenharmony_ci const char *value, size_t v_size); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci A wrapper around vfs_parse_fs_param() that copies the value string it is 5148c2ecf20Sopenharmony_ci passed. 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci * :: 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci int generic_parse_monolithic(struct fs_context *fc, void *data); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci Parse a sys_mount() data page, assuming the form to be a text list 5218c2ecf20Sopenharmony_ci consisting of key[=val] options separated by commas. Each item in the 5228c2ecf20Sopenharmony_ci list is passed to vfs_mount_option(). This is the default when the 5238c2ecf20Sopenharmony_ci ->parse_monolithic() method is NULL. 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci * :: 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci int vfs_get_tree(struct fs_context *fc); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci Get or create the mountable root and superblock, using the parameters in 5308c2ecf20Sopenharmony_ci the filesystem context to select/configure the superblock. This invokes 5318c2ecf20Sopenharmony_ci the ->get_tree() method. 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci * :: 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci struct vfsmount *vfs_create_mount(struct fs_context *fc); 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci Create a mount given the parameters in the specified filesystem context. 5388c2ecf20Sopenharmony_ci Note that this does not attach the mount to anything. 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ciSuperblock Creation Helpers 5428c2ecf20Sopenharmony_ci=========================== 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ciA number of VFS helpers are available for use by filesystems for the creation 5458c2ecf20Sopenharmony_cior looking up of superblocks. 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci * :: 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci struct super_block * 5508c2ecf20Sopenharmony_ci sget_fc(struct fs_context *fc, 5518c2ecf20Sopenharmony_ci int (*test)(struct super_block *sb, struct fs_context *fc), 5528c2ecf20Sopenharmony_ci int (*set)(struct super_block *sb, struct fs_context *fc)); 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci This is the core routine. If test is non-NULL, it searches for an 5558c2ecf20Sopenharmony_ci existing superblock matching the criteria held in the fs_context, using 5568c2ecf20Sopenharmony_ci the test function to match them. If no match is found, a new superblock 5578c2ecf20Sopenharmony_ci is created and the set function is called to set it up. 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci Prior to the set function being called, fc->s_fs_info will be transferred 5608c2ecf20Sopenharmony_ci to sb->s_fs_info - and fc->s_fs_info will be cleared if set returns 5618c2ecf20Sopenharmony_ci success (ie. 0). 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ciThe following helpers all wrap sget_fc(): 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci * :: 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci int vfs_get_super(struct fs_context *fc, 5688c2ecf20Sopenharmony_ci enum vfs_get_super_keying keying, 5698c2ecf20Sopenharmony_ci int (*fill_super)(struct super_block *sb, 5708c2ecf20Sopenharmony_ci struct fs_context *fc)) 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci This creates/looks up a deviceless superblock. The keying indicates how 5738c2ecf20Sopenharmony_ci many superblocks of this type may exist and in what manner they may be 5748c2ecf20Sopenharmony_ci shared: 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci (1) vfs_get_single_super 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci Only one such superblock may exist in the system. Any further 5798c2ecf20Sopenharmony_ci attempt to get a new superblock gets this one (and any parameter 5808c2ecf20Sopenharmony_ci differences are ignored). 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci (2) vfs_get_keyed_super 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci Multiple superblocks of this type may exist and they're keyed on 5858c2ecf20Sopenharmony_ci their s_fs_info pointer (for example this may refer to a 5868c2ecf20Sopenharmony_ci namespace). 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci (3) vfs_get_independent_super 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci Multiple independent superblocks of this type may exist. This 5918c2ecf20Sopenharmony_ci function never matches an existing one and always creates a new 5928c2ecf20Sopenharmony_ci one. 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ciParameter Description 5968c2ecf20Sopenharmony_ci===================== 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ciParameters are described using structures defined in linux/fs_parser.h. 5998c2ecf20Sopenharmony_ciThere's a core description struct that links everything together:: 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci struct fs_parameter_description { 6028c2ecf20Sopenharmony_ci const struct fs_parameter_spec *specs; 6038c2ecf20Sopenharmony_ci const struct fs_parameter_enum *enums; 6048c2ecf20Sopenharmony_ci }; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ciFor example:: 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci enum { 6098c2ecf20Sopenharmony_ci Opt_autocell, 6108c2ecf20Sopenharmony_ci Opt_bar, 6118c2ecf20Sopenharmony_ci Opt_dyn, 6128c2ecf20Sopenharmony_ci Opt_foo, 6138c2ecf20Sopenharmony_ci Opt_source, 6148c2ecf20Sopenharmony_ci }; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci static const struct fs_parameter_description afs_fs_parameters = { 6178c2ecf20Sopenharmony_ci .specs = afs_param_specs, 6188c2ecf20Sopenharmony_ci .enums = afs_param_enums, 6198c2ecf20Sopenharmony_ci }; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ciThe members are as follows: 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci (1) :: 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci const struct fs_parameter_specification *specs; 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci Table of parameter specifications, terminated with a null entry, where the 6288c2ecf20Sopenharmony_ci entries are of type:: 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci struct fs_parameter_spec { 6318c2ecf20Sopenharmony_ci const char *name; 6328c2ecf20Sopenharmony_ci u8 opt; 6338c2ecf20Sopenharmony_ci enum fs_parameter_type type:8; 6348c2ecf20Sopenharmony_ci unsigned short flags; 6358c2ecf20Sopenharmony_ci }; 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci The 'name' field is a string to match exactly to the parameter key (no 6388c2ecf20Sopenharmony_ci wildcards, patterns and no case-independence) and 'opt' is the value that 6398c2ecf20Sopenharmony_ci will be returned by the fs_parser() function in the case of a successful 6408c2ecf20Sopenharmony_ci match. 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci The 'type' field indicates the desired value type and must be one of: 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci ======================= ======================= ===================== 6458c2ecf20Sopenharmony_ci TYPE NAME EXPECTED VALUE RESULT IN 6468c2ecf20Sopenharmony_ci ======================= ======================= ===================== 6478c2ecf20Sopenharmony_ci fs_param_is_flag No value n/a 6488c2ecf20Sopenharmony_ci fs_param_is_bool Boolean value result->boolean 6498c2ecf20Sopenharmony_ci fs_param_is_u32 32-bit unsigned int result->uint_32 6508c2ecf20Sopenharmony_ci fs_param_is_u32_octal 32-bit octal int result->uint_32 6518c2ecf20Sopenharmony_ci fs_param_is_u32_hex 32-bit hex int result->uint_32 6528c2ecf20Sopenharmony_ci fs_param_is_s32 32-bit signed int result->int_32 6538c2ecf20Sopenharmony_ci fs_param_is_u64 64-bit unsigned int result->uint_64 6548c2ecf20Sopenharmony_ci fs_param_is_enum Enum value name result->uint_32 6558c2ecf20Sopenharmony_ci fs_param_is_string Arbitrary string param->string 6568c2ecf20Sopenharmony_ci fs_param_is_blob Binary blob param->blob 6578c2ecf20Sopenharmony_ci fs_param_is_blockdev Blockdev path * Needs lookup 6588c2ecf20Sopenharmony_ci fs_param_is_path Path * Needs lookup 6598c2ecf20Sopenharmony_ci fs_param_is_fd File descriptor result->int_32 6608c2ecf20Sopenharmony_ci ======================= ======================= ===================== 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci Note that if the value is of fs_param_is_bool type, fs_parse() will try 6638c2ecf20Sopenharmony_ci to match any string value against "0", "1", "no", "yes", "false", "true". 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci Each parameter can also be qualified with 'flags': 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci ======================= ================================================ 6688c2ecf20Sopenharmony_ci fs_param_v_optional The value is optional 6698c2ecf20Sopenharmony_ci fs_param_neg_with_no result->negated set if key is prefixed with "no" 6708c2ecf20Sopenharmony_ci fs_param_neg_with_empty result->negated set if value is "" 6718c2ecf20Sopenharmony_ci fs_param_deprecated The parameter is deprecated. 6728c2ecf20Sopenharmony_ci ======================= ================================================ 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci These are wrapped with a number of convenience wrappers: 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci ======================= =============================================== 6778c2ecf20Sopenharmony_ci MACRO SPECIFIES 6788c2ecf20Sopenharmony_ci ======================= =============================================== 6798c2ecf20Sopenharmony_ci fsparam_flag() fs_param_is_flag 6808c2ecf20Sopenharmony_ci fsparam_flag_no() fs_param_is_flag, fs_param_neg_with_no 6818c2ecf20Sopenharmony_ci fsparam_bool() fs_param_is_bool 6828c2ecf20Sopenharmony_ci fsparam_u32() fs_param_is_u32 6838c2ecf20Sopenharmony_ci fsparam_u32oct() fs_param_is_u32_octal 6848c2ecf20Sopenharmony_ci fsparam_u32hex() fs_param_is_u32_hex 6858c2ecf20Sopenharmony_ci fsparam_s32() fs_param_is_s32 6868c2ecf20Sopenharmony_ci fsparam_u64() fs_param_is_u64 6878c2ecf20Sopenharmony_ci fsparam_enum() fs_param_is_enum 6888c2ecf20Sopenharmony_ci fsparam_string() fs_param_is_string 6898c2ecf20Sopenharmony_ci fsparam_blob() fs_param_is_blob 6908c2ecf20Sopenharmony_ci fsparam_bdev() fs_param_is_blockdev 6918c2ecf20Sopenharmony_ci fsparam_path() fs_param_is_path 6928c2ecf20Sopenharmony_ci fsparam_fd() fs_param_is_fd 6938c2ecf20Sopenharmony_ci ======================= =============================================== 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci all of which take two arguments, name string and option number - for 6968c2ecf20Sopenharmony_ci example:: 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci static const struct fs_parameter_spec afs_param_specs[] = { 6998c2ecf20Sopenharmony_ci fsparam_flag ("autocell", Opt_autocell), 7008c2ecf20Sopenharmony_ci fsparam_flag ("dyn", Opt_dyn), 7018c2ecf20Sopenharmony_ci fsparam_string ("source", Opt_source), 7028c2ecf20Sopenharmony_ci fsparam_flag_no ("foo", Opt_foo), 7038c2ecf20Sopenharmony_ci {} 7048c2ecf20Sopenharmony_ci }; 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci An addition macro, __fsparam() is provided that takes an additional pair 7078c2ecf20Sopenharmony_ci of arguments to specify the type and the flags for anything that doesn't 7088c2ecf20Sopenharmony_ci match one of the above macros. 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci (2) :: 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci const struct fs_parameter_enum *enums; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci Table of enum value names to integer mappings, terminated with a null 7158c2ecf20Sopenharmony_ci entry. This is of type:: 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci struct fs_parameter_enum { 7188c2ecf20Sopenharmony_ci u8 opt; 7198c2ecf20Sopenharmony_ci char name[14]; 7208c2ecf20Sopenharmony_ci u8 value; 7218c2ecf20Sopenharmony_ci }; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci Where the array is an unsorted list of { parameter ID, name }-keyed 7248c2ecf20Sopenharmony_ci elements that indicate the value to map to, e.g.:: 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci static const struct fs_parameter_enum afs_param_enums[] = { 7278c2ecf20Sopenharmony_ci { Opt_bar, "x", 1}, 7288c2ecf20Sopenharmony_ci { Opt_bar, "y", 23}, 7298c2ecf20Sopenharmony_ci { Opt_bar, "z", 42}, 7308c2ecf20Sopenharmony_ci }; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci If a parameter of type fs_param_is_enum is encountered, fs_parse() will 7338c2ecf20Sopenharmony_ci try to look the value up in the enum table and the result will be stored 7348c2ecf20Sopenharmony_ci in the parse result. 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ciThe parser should be pointed to by the parser pointer in the file_system_type 7378c2ecf20Sopenharmony_cistruct as this will provide validation on registration (if 7388c2ecf20Sopenharmony_ciCONFIG_VALIDATE_FS_PARSER=y) and will allow the description to be queried from 7398c2ecf20Sopenharmony_ciuserspace using the fsinfo() syscall. 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ciParameter Helper Functions 7438c2ecf20Sopenharmony_ci========================== 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ciA number of helper functions are provided to help a filesystem or an LSM 7468c2ecf20Sopenharmony_ciprocess the parameters it is given. 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci * :: 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_ci int lookup_constant(const struct constant_table tbl[], 7518c2ecf20Sopenharmony_ci const char *name, int not_found); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci Look up a constant by name in a table of name -> integer mappings. The 7548c2ecf20Sopenharmony_ci table is an array of elements of the following type:: 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci struct constant_table { 7578c2ecf20Sopenharmony_ci const char *name; 7588c2ecf20Sopenharmony_ci int value; 7598c2ecf20Sopenharmony_ci }; 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci If a match is found, the corresponding value is returned. If a match 7628c2ecf20Sopenharmony_ci isn't found, the not_found value is returned instead. 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci * :: 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci bool validate_constant_table(const struct constant_table *tbl, 7678c2ecf20Sopenharmony_ci size_t tbl_size, 7688c2ecf20Sopenharmony_ci int low, int high, int special); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci Validate a constant table. Checks that all the elements are appropriately 7718c2ecf20Sopenharmony_ci ordered, that there are no duplicates and that the values are between low 7728c2ecf20Sopenharmony_ci and high inclusive, though provision is made for one allowable special 7738c2ecf20Sopenharmony_ci value outside of that range. If no special value is required, special 7748c2ecf20Sopenharmony_ci should just be set to lie inside the low-to-high range. 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci If all is good, true is returned. If the table is invalid, errors are 7778c2ecf20Sopenharmony_ci logged to dmesg and false is returned. 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci * :: 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci bool fs_validate_description(const struct fs_parameter_description *desc); 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci This performs some validation checks on a parameter description. It 7848c2ecf20Sopenharmony_ci returns true if the description is good and false if it is not. It will 7858c2ecf20Sopenharmony_ci log errors to dmesg if validation fails. 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci * :: 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci int fs_parse(struct fs_context *fc, 7908c2ecf20Sopenharmony_ci const struct fs_parameter_description *desc, 7918c2ecf20Sopenharmony_ci struct fs_parameter *param, 7928c2ecf20Sopenharmony_ci struct fs_parse_result *result); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci This is the main interpreter of parameters. It uses the parameter 7958c2ecf20Sopenharmony_ci description to look up a parameter by key name and to convert that to an 7968c2ecf20Sopenharmony_ci option number (which it returns). 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci If successful, and if the parameter type indicates the result is a 7998c2ecf20Sopenharmony_ci boolean, integer or enum type, the value is converted by this function and 8008c2ecf20Sopenharmony_ci the result stored in result->{boolean,int_32,uint_32,uint_64}. 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci If a match isn't initially made, the key is prefixed with "no" and no 8038c2ecf20Sopenharmony_ci value is present then an attempt will be made to look up the key with the 8048c2ecf20Sopenharmony_ci prefix removed. If this matches a parameter for which the type has flag 8058c2ecf20Sopenharmony_ci fs_param_neg_with_no set, then a match will be made and result->negated 8068c2ecf20Sopenharmony_ci will be set to true. 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci If the parameter isn't matched, -ENOPARAM will be returned; if the 8098c2ecf20Sopenharmony_ci parameter is matched, but the value is erroneous, -EINVAL will be 8108c2ecf20Sopenharmony_ci returned; otherwise the parameter's option number will be returned. 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci * :: 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci int fs_lookup_param(struct fs_context *fc, 8158c2ecf20Sopenharmony_ci struct fs_parameter *value, 8168c2ecf20Sopenharmony_ci bool want_bdev, 8178c2ecf20Sopenharmony_ci struct path *_path); 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci This takes a parameter that carries a string or filename type and attempts 8208c2ecf20Sopenharmony_ci to do a path lookup on it. If the parameter expects a blockdev, a check 8218c2ecf20Sopenharmony_ci is made that the inode actually represents one. 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci Returns 0 if successful and ``*_path`` will be set; returns a negative 8248c2ecf20Sopenharmony_ci error code if not. 825