xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/mount_api.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun====================
4*4882a593SmuzhiyunFilesystem Mount API
5*4882a593Smuzhiyun====================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun.. CONTENTS
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun (1) Overview.
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun (2) The filesystem context.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun (3) The filesystem context operations.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun (4) Filesystem context security.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun (5) VFS filesystem context API.
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun (6) Superblock creation helpers.
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun (7) Parameter description.
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun (8) Parameter helper functions.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunOverview
27*4882a593Smuzhiyun========
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunThe creation of new mounts is now to be done in a multistep process:
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun (1) Create a filesystem context.
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun (2) Parse the parameters and attach them to the context.  Parameters are
34*4882a593Smuzhiyun     expected to be passed individually from userspace, though legacy binary
35*4882a593Smuzhiyun     parameters can also be handled.
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun (3) Validate and pre-process the context.
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun (4) Get or create a superblock and mountable root.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun (5) Perform the mount.
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun (6) Return an error message attached to the context.
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun (7) Destroy the context.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunTo support this, the file_system_type struct gains two new fields::
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun	int (*init_fs_context)(struct fs_context *fc);
50*4882a593Smuzhiyun	const struct fs_parameter_description *parameters;
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunThe first is invoked to set up the filesystem-specific parts of a filesystem
53*4882a593Smuzhiyuncontext, including the additional space, and the second points to the
54*4882a593Smuzhiyunparameter description for validation at registration time and querying by a
55*4882a593Smuzhiyunfuture system call.
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunNote that security initialisation is done *after* the filesystem is called so
58*4882a593Smuzhiyunthat the namespaces may be adjusted first.
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunThe Filesystem context
62*4882a593Smuzhiyun======================
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunThe creation and reconfiguration of a superblock is governed by a filesystem
65*4882a593Smuzhiyuncontext.  This is represented by the fs_context structure::
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun	struct fs_context {
68*4882a593Smuzhiyun		const struct fs_context_operations *ops;
69*4882a593Smuzhiyun		struct file_system_type *fs_type;
70*4882a593Smuzhiyun		void			*fs_private;
71*4882a593Smuzhiyun		struct dentry		*root;
72*4882a593Smuzhiyun		struct user_namespace	*user_ns;
73*4882a593Smuzhiyun		struct net		*net_ns;
74*4882a593Smuzhiyun		const struct cred	*cred;
75*4882a593Smuzhiyun		char			*source;
76*4882a593Smuzhiyun		char			*subtype;
77*4882a593Smuzhiyun		void			*security;
78*4882a593Smuzhiyun		void			*s_fs_info;
79*4882a593Smuzhiyun		unsigned int		sb_flags;
80*4882a593Smuzhiyun		unsigned int		sb_flags_mask;
81*4882a593Smuzhiyun		unsigned int		s_iflags;
82*4882a593Smuzhiyun		unsigned int		lsm_flags;
83*4882a593Smuzhiyun		enum fs_context_purpose	purpose:8;
84*4882a593Smuzhiyun		...
85*4882a593Smuzhiyun	};
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunThe fs_context fields are as follows:
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun   * ::
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun       const struct fs_context_operations *ops
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun     These are operations that can be done on a filesystem context (see
94*4882a593Smuzhiyun     below).  This must be set by the ->init_fs_context() file_system_type
95*4882a593Smuzhiyun     operation.
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun   * ::
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun       struct file_system_type *fs_type
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun     A pointer to the file_system_type of the filesystem that is being
102*4882a593Smuzhiyun     constructed or reconfigured.  This retains a reference on the type owner.
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun   * ::
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun       void *fs_private
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun     A pointer to the file system's private data.  This is where the filesystem
109*4882a593Smuzhiyun     will need to store any options it parses.
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun   * ::
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun       struct dentry *root
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun     A pointer to the root of the mountable tree (and indirectly, the
116*4882a593Smuzhiyun     superblock thereof).  This is filled in by the ->get_tree() op.  If this
117*4882a593Smuzhiyun     is set, an active reference on root->d_sb must also be held.
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun   * ::
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun       struct user_namespace *user_ns
122*4882a593Smuzhiyun       struct net *net_ns
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun     There are a subset of the namespaces in use by the invoking process.  They
125*4882a593Smuzhiyun     retain references on each namespace.  The subscribed namespaces may be
126*4882a593Smuzhiyun     replaced by the filesystem to reflect other sources, such as the parent
127*4882a593Smuzhiyun     mount superblock on an automount.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun   * ::
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun       const struct cred *cred
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun     The mounter's credentials.  This retains a reference on the credentials.
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun   * ::
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun       char *source
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun     This specifies the source.  It may be a block device (e.g. /dev/sda1) or
140*4882a593Smuzhiyun     something more exotic, such as the "host:/path" that NFS desires.
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun   * ::
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun       char *subtype
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun     This is a string to be added to the type displayed in /proc/mounts to
147*4882a593Smuzhiyun     qualify it (used by FUSE).  This is available for the filesystem to set if
148*4882a593Smuzhiyun     desired.
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun   * ::
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun       void *security
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun     A place for the LSMs to hang their security data for the superblock.  The
155*4882a593Smuzhiyun     relevant security operations are described below.
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun   * ::
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun       void *s_fs_info
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun     The proposed s_fs_info for a new superblock, set in the superblock by
162*4882a593Smuzhiyun     sget_fc().  This can be used to distinguish superblocks.
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun   * ::
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun       unsigned int sb_flags
167*4882a593Smuzhiyun       unsigned int sb_flags_mask
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun     Which bits SB_* flags are to be set/cleared in super_block::s_flags.
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun   * ::
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun       unsigned int s_iflags
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun     These will be bitwise-OR'd with s->s_iflags when a superblock is created.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun   * ::
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun       enum fs_context_purpose
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun     This indicates the purpose for which the context is intended.  The
182*4882a593Smuzhiyun     available values are:
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun	==========================	======================================
185*4882a593Smuzhiyun	FS_CONTEXT_FOR_MOUNT,		New superblock for explicit mount
186*4882a593Smuzhiyun	FS_CONTEXT_FOR_SUBMOUNT		New automatic submount of extant mount
187*4882a593Smuzhiyun	FS_CONTEXT_FOR_RECONFIGURE	Change an existing mount
188*4882a593Smuzhiyun	==========================	======================================
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunThe mount context is created by calling vfs_new_fs_context() or
191*4882a593Smuzhiyunvfs_dup_fs_context() and is destroyed with put_fs_context().  Note that the
192*4882a593Smuzhiyunstructure is not refcounted.
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunVFS, security and filesystem mount options are set individually with
195*4882a593Smuzhiyunvfs_parse_mount_option().  Options provided by the old mount(2) system call as
196*4882a593Smuzhiyuna page of data can be parsed with generic_parse_monolithic().
197*4882a593Smuzhiyun
198*4882a593SmuzhiyunWhen mounting, the filesystem is allowed to take data from any of the pointers
199*4882a593Smuzhiyunand attach it to the superblock (or whatever), provided it clears the pointer
200*4882a593Smuzhiyunin the mount context.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunThe filesystem is also allowed to allocate resources and pin them with the
203*4882a593Smuzhiyunmount context.  For instance, NFS might pin the appropriate protocol version
204*4882a593Smuzhiyunmodule.
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun
207*4882a593SmuzhiyunThe Filesystem Context Operations
208*4882a593Smuzhiyun=================================
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunThe filesystem context points to a table of operations::
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun	struct fs_context_operations {
213*4882a593Smuzhiyun		void (*free)(struct fs_context *fc);
214*4882a593Smuzhiyun		int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
215*4882a593Smuzhiyun		int (*parse_param)(struct fs_context *fc,
216*4882a593Smuzhiyun				   struct fs_parameter *param);
217*4882a593Smuzhiyun		int (*parse_monolithic)(struct fs_context *fc, void *data);
218*4882a593Smuzhiyun		int (*get_tree)(struct fs_context *fc);
219*4882a593Smuzhiyun		int (*reconfigure)(struct fs_context *fc);
220*4882a593Smuzhiyun	};
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunThese operations are invoked by the various stages of the mount procedure to
223*4882a593Smuzhiyunmanage the filesystem context.  They are as follows:
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun   * ::
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun	void (*free)(struct fs_context *fc);
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun     Called to clean up the filesystem-specific part of the filesystem context
230*4882a593Smuzhiyun     when the context is destroyed.  It should be aware that parts of the
231*4882a593Smuzhiyun     context may have been removed and NULL'd out by ->get_tree().
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun   * ::
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun	int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun     Called when a filesystem context has been duplicated to duplicate the
238*4882a593Smuzhiyun     filesystem-private data.  An error may be returned to indicate failure to
239*4882a593Smuzhiyun     do this.
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun     .. Warning::
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun         Note that even if this fails, put_fs_context() will be called
244*4882a593Smuzhiyun	 immediately thereafter, so ->dup() *must* make the
245*4882a593Smuzhiyun	 filesystem-private data safe for ->free().
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun   * ::
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun	int (*parse_param)(struct fs_context *fc,
250*4882a593Smuzhiyun			   struct fs_parameter *param);
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun     Called when a parameter is being added to the filesystem context.  param
253*4882a593Smuzhiyun     points to the key name and maybe a value object.  VFS-specific options
254*4882a593Smuzhiyun     will have been weeded out and fc->sb_flags updated in the context.
255*4882a593Smuzhiyun     Security options will also have been weeded out and fc->security updated.
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun     The parameter can be parsed with fs_parse() and fs_lookup_param().  Note
258*4882a593Smuzhiyun     that the source(s) are presented as parameters named "source".
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun     If successful, 0 should be returned or a negative error code otherwise.
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun   * ::
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun	int (*parse_monolithic)(struct fs_context *fc, void *data);
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun     Called when the mount(2) system call is invoked to pass the entire data
267*4882a593Smuzhiyun     page in one go.  If this is expected to be just a list of "key[=val]"
268*4882a593Smuzhiyun     items separated by commas, then this may be set to NULL.
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun     The return value is as for ->parse_param().
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun     If the filesystem (e.g. NFS) needs to examine the data first and then
273*4882a593Smuzhiyun     finds it's the standard key-val list then it may pass it off to
274*4882a593Smuzhiyun     generic_parse_monolithic().
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun   * ::
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun	int (*get_tree)(struct fs_context *fc);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun     Called to get or create the mountable root and superblock, using the
281*4882a593Smuzhiyun     information stored in the filesystem context (reconfiguration goes via a
282*4882a593Smuzhiyun     different vector).  It may detach any resources it desires from the
283*4882a593Smuzhiyun     filesystem context and transfer them to the superblock it creates.
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun     On success it should set fc->root to the mountable root and return 0.  In
286*4882a593Smuzhiyun     the case of an error, it should return a negative error code.
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun     The phase on a userspace-driven context will be set to only allow this to
289*4882a593Smuzhiyun     be called once on any particular context.
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun   * ::
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun	int (*reconfigure)(struct fs_context *fc);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun     Called to effect reconfiguration of a superblock using information stored
296*4882a593Smuzhiyun     in the filesystem context.  It may detach any resources it desires from
297*4882a593Smuzhiyun     the filesystem context and transfer them to the superblock.  The
298*4882a593Smuzhiyun     superblock can be found from fc->root->d_sb.
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun     On success it should return 0.  In the case of an error, it should return
301*4882a593Smuzhiyun     a negative error code.
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun     .. Note:: reconfigure is intended as a replacement for remount_fs.
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun
306*4882a593SmuzhiyunFilesystem context Security
307*4882a593Smuzhiyun===========================
308*4882a593Smuzhiyun
309*4882a593SmuzhiyunThe filesystem context contains a security pointer that the LSMs can use for
310*4882a593Smuzhiyunbuilding up a security context for the superblock to be mounted.  There are a
311*4882a593Smuzhiyunnumber of operations used by the new mount code for this purpose:
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun   * ::
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun	int security_fs_context_alloc(struct fs_context *fc,
316*4882a593Smuzhiyun				      struct dentry *reference);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun     Called to initialise fc->security (which is preset to NULL) and allocate
319*4882a593Smuzhiyun     any resources needed.  It should return 0 on success or a negative error
320*4882a593Smuzhiyun     code on failure.
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun     reference will be non-NULL if the context is being created for superblock
323*4882a593Smuzhiyun     reconfiguration (FS_CONTEXT_FOR_RECONFIGURE) in which case it indicates
324*4882a593Smuzhiyun     the root dentry of the superblock to be reconfigured.  It will also be
325*4882a593Smuzhiyun     non-NULL in the case of a submount (FS_CONTEXT_FOR_SUBMOUNT) in which case
326*4882a593Smuzhiyun     it indicates the automount point.
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun   * ::
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun	int security_fs_context_dup(struct fs_context *fc,
331*4882a593Smuzhiyun				    struct fs_context *src_fc);
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun     Called to initialise fc->security (which is preset to NULL) and allocate
334*4882a593Smuzhiyun     any resources needed.  The original filesystem context is pointed to by
335*4882a593Smuzhiyun     src_fc and may be used for reference.  It should return 0 on success or a
336*4882a593Smuzhiyun     negative error code on failure.
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun   * ::
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun	void security_fs_context_free(struct fs_context *fc);
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun     Called to clean up anything attached to fc->security.  Note that the
343*4882a593Smuzhiyun     contents may have been transferred to a superblock and the pointer cleared
344*4882a593Smuzhiyun     during get_tree.
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun   * ::
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun	int security_fs_context_parse_param(struct fs_context *fc,
349*4882a593Smuzhiyun					    struct fs_parameter *param);
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun     Called for each mount parameter, including the source.  The arguments are
352*4882a593Smuzhiyun     as for the ->parse_param() method.  It should return 0 to indicate that
353*4882a593Smuzhiyun     the parameter should be passed on to the filesystem, 1 to indicate that
354*4882a593Smuzhiyun     the parameter should be discarded or an error to indicate that the
355*4882a593Smuzhiyun     parameter should be rejected.
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun     The value pointed to by param may be modified (if a string) or stolen
358*4882a593Smuzhiyun     (provided the value pointer is NULL'd out).  If it is stolen, 1 must be
359*4882a593Smuzhiyun     returned to prevent it being passed to the filesystem.
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun   * ::
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun	int security_fs_context_validate(struct fs_context *fc);
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun     Called after all the options have been parsed to validate the collection
366*4882a593Smuzhiyun     as a whole and to do any necessary allocation so that
367*4882a593Smuzhiyun     security_sb_get_tree() and security_sb_reconfigure() are less likely to
368*4882a593Smuzhiyun     fail.  It should return 0 or a negative error code.
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun     In the case of reconfiguration, the target superblock will be accessible
371*4882a593Smuzhiyun     via fc->root.
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun   * ::
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun	int security_sb_get_tree(struct fs_context *fc);
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun     Called during the mount procedure to verify that the specified superblock
378*4882a593Smuzhiyun     is allowed to be mounted and to transfer the security data there.  It
379*4882a593Smuzhiyun     should return 0 or a negative error code.
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun   * ::
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun	void security_sb_reconfigure(struct fs_context *fc);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun     Called to apply any reconfiguration to an LSM's context.  It must not
386*4882a593Smuzhiyun     fail.  Error checking and resource allocation must be done in advance by
387*4882a593Smuzhiyun     the parameter parsing and validation hooks.
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun   * ::
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun	int security_sb_mountpoint(struct fs_context *fc,
392*4882a593Smuzhiyun			           struct path *mountpoint,
393*4882a593Smuzhiyun				   unsigned int mnt_flags);
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun     Called during the mount procedure to verify that the root dentry attached
396*4882a593Smuzhiyun     to the context is permitted to be attached to the specified mountpoint.
397*4882a593Smuzhiyun     It should return 0 on success or a negative error code on failure.
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunVFS Filesystem context API
401*4882a593Smuzhiyun==========================
402*4882a593Smuzhiyun
403*4882a593SmuzhiyunThere are four operations for creating a filesystem context and one for
404*4882a593Smuzhiyundestroying a context:
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun   * ::
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun       struct fs_context *fs_context_for_mount(struct file_system_type *fs_type,
409*4882a593Smuzhiyun					       unsigned int sb_flags);
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun     Allocate a filesystem context for the purpose of setting up a new mount,
412*4882a593Smuzhiyun     whether that be with a new superblock or sharing an existing one.  This
413*4882a593Smuzhiyun     sets the superblock flags, initialises the security and calls
414*4882a593Smuzhiyun     fs_type->init_fs_context() to initialise the filesystem private data.
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun     fs_type specifies the filesystem type that will manage the context and
417*4882a593Smuzhiyun     sb_flags presets the superblock flags stored therein.
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun   * ::
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun       struct fs_context *fs_context_for_reconfigure(
422*4882a593Smuzhiyun		struct dentry *dentry,
423*4882a593Smuzhiyun		unsigned int sb_flags,
424*4882a593Smuzhiyun		unsigned int sb_flags_mask);
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun     Allocate a filesystem context for the purpose of reconfiguring an
427*4882a593Smuzhiyun     existing superblock.  dentry provides a reference to the superblock to be
428*4882a593Smuzhiyun     configured.  sb_flags and sb_flags_mask indicate which superblock flags
429*4882a593Smuzhiyun     need changing and to what.
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun   * ::
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun       struct fs_context *fs_context_for_submount(
434*4882a593Smuzhiyun		struct file_system_type *fs_type,
435*4882a593Smuzhiyun		struct dentry *reference);
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun     Allocate a filesystem context for the purpose of creating a new mount for
438*4882a593Smuzhiyun     an automount point or other derived superblock.  fs_type specifies the
439*4882a593Smuzhiyun     filesystem type that will manage the context and the reference dentry
440*4882a593Smuzhiyun     supplies the parameters.  Namespaces are propagated from the reference
441*4882a593Smuzhiyun     dentry's superblock also.
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun     Note that it's not a requirement that the reference dentry be of the same
444*4882a593Smuzhiyun     filesystem type as fs_type.
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun   * ::
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun        struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc);
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun     Duplicate a filesystem context, copying any options noted and duplicating
451*4882a593Smuzhiyun     or additionally referencing any resources held therein.  This is available
452*4882a593Smuzhiyun     for use where a filesystem has to get a mount within a mount, such as NFS4
453*4882a593Smuzhiyun     does by internally mounting the root of the target server and then doing a
454*4882a593Smuzhiyun     private pathwalk to the target directory.
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun     The purpose in the new context is inherited from the old one.
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun   * ::
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun       void put_fs_context(struct fs_context *fc);
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun     Destroy a filesystem context, releasing any resources it holds.  This
463*4882a593Smuzhiyun     calls the ->free() operation.  This is intended to be called by anyone who
464*4882a593Smuzhiyun     created a filesystem context.
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun     .. Warning::
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun        filesystem contexts are not refcounted, so this causes unconditional
469*4882a593Smuzhiyun	destruction.
470*4882a593Smuzhiyun
471*4882a593SmuzhiyunIn all the above operations, apart from the put op, the return is a mount
472*4882a593Smuzhiyuncontext pointer or a negative error code.
473*4882a593Smuzhiyun
474*4882a593SmuzhiyunFor the remaining operations, if an error occurs, a negative error code will be
475*4882a593Smuzhiyunreturned.
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun   * ::
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun        int vfs_parse_fs_param(struct fs_context *fc,
480*4882a593Smuzhiyun			       struct fs_parameter *param);
481*4882a593Smuzhiyun
482*4882a593Smuzhiyun     Supply a single mount parameter to the filesystem context.  This includes
483*4882a593Smuzhiyun     the specification of the source/device which is specified as the "source"
484*4882a593Smuzhiyun     parameter (which may be specified multiple times if the filesystem
485*4882a593Smuzhiyun     supports that).
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun     param specifies the parameter key name and the value.  The parameter is
488*4882a593Smuzhiyun     first checked to see if it corresponds to a standard mount flag (in which
489*4882a593Smuzhiyun     case it is used to set an SB_xxx flag and consumed) or a security option
490*4882a593Smuzhiyun     (in which case the LSM consumes it) before it is passed on to the
491*4882a593Smuzhiyun     filesystem.
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun     The parameter value is typed and can be one of:
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun	====================		=============================
496*4882a593Smuzhiyun	fs_value_is_flag		Parameter not given a value
497*4882a593Smuzhiyun	fs_value_is_string		Value is a string
498*4882a593Smuzhiyun	fs_value_is_blob		Value is a binary blob
499*4882a593Smuzhiyun	fs_value_is_filename		Value is a filename* + dirfd
500*4882a593Smuzhiyun	fs_value_is_file		Value is an open file (file*)
501*4882a593Smuzhiyun	====================		=============================
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun     If there is a value, that value is stored in a union in the struct in one
504*4882a593Smuzhiyun     of param->{string,blob,name,file}.  Note that the function may steal and
505*4882a593Smuzhiyun     clear the pointer, but then becomes responsible for disposing of the
506*4882a593Smuzhiyun     object.
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun   * ::
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun       int vfs_parse_fs_string(struct fs_context *fc, const char *key,
511*4882a593Smuzhiyun			       const char *value, size_t v_size);
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun     A wrapper around vfs_parse_fs_param() that copies the value string it is
514*4882a593Smuzhiyun     passed.
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun   * ::
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun       int generic_parse_monolithic(struct fs_context *fc, void *data);
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun     Parse a sys_mount() data page, assuming the form to be a text list
521*4882a593Smuzhiyun     consisting of key[=val] options separated by commas.  Each item in the
522*4882a593Smuzhiyun     list is passed to vfs_mount_option().  This is the default when the
523*4882a593Smuzhiyun     ->parse_monolithic() method is NULL.
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun   * ::
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun       int vfs_get_tree(struct fs_context *fc);
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun     Get or create the mountable root and superblock, using the parameters in
530*4882a593Smuzhiyun     the filesystem context to select/configure the superblock.  This invokes
531*4882a593Smuzhiyun     the ->get_tree() method.
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun   * ::
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun       struct vfsmount *vfs_create_mount(struct fs_context *fc);
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun     Create a mount given the parameters in the specified filesystem context.
538*4882a593Smuzhiyun     Note that this does not attach the mount to anything.
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun
541*4882a593SmuzhiyunSuperblock Creation Helpers
542*4882a593Smuzhiyun===========================
543*4882a593Smuzhiyun
544*4882a593SmuzhiyunA number of VFS helpers are available for use by filesystems for the creation
545*4882a593Smuzhiyunor looking up of superblocks.
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun   * ::
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun       struct super_block *
550*4882a593Smuzhiyun       sget_fc(struct fs_context *fc,
551*4882a593Smuzhiyun	       int (*test)(struct super_block *sb, struct fs_context *fc),
552*4882a593Smuzhiyun	       int (*set)(struct super_block *sb, struct fs_context *fc));
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun     This is the core routine.  If test is non-NULL, it searches for an
555*4882a593Smuzhiyun     existing superblock matching the criteria held in the fs_context, using
556*4882a593Smuzhiyun     the test function to match them.  If no match is found, a new superblock
557*4882a593Smuzhiyun     is created and the set function is called to set it up.
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun     Prior to the set function being called, fc->s_fs_info will be transferred
560*4882a593Smuzhiyun     to sb->s_fs_info - and fc->s_fs_info will be cleared if set returns
561*4882a593Smuzhiyun     success (ie. 0).
562*4882a593Smuzhiyun
563*4882a593SmuzhiyunThe following helpers all wrap sget_fc():
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun   * ::
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun       int vfs_get_super(struct fs_context *fc,
568*4882a593Smuzhiyun		         enum vfs_get_super_keying keying,
569*4882a593Smuzhiyun		         int (*fill_super)(struct super_block *sb,
570*4882a593Smuzhiyun					   struct fs_context *fc))
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun     This creates/looks up a deviceless superblock.  The keying indicates how
573*4882a593Smuzhiyun     many superblocks of this type may exist and in what manner they may be
574*4882a593Smuzhiyun     shared:
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun	(1) vfs_get_single_super
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun	    Only one such superblock may exist in the system.  Any further
579*4882a593Smuzhiyun	    attempt to get a new superblock gets this one (and any parameter
580*4882a593Smuzhiyun	    differences are ignored).
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun	(2) vfs_get_keyed_super
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun	    Multiple superblocks of this type may exist and they're keyed on
585*4882a593Smuzhiyun	    their s_fs_info pointer (for example this may refer to a
586*4882a593Smuzhiyun	    namespace).
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun	(3) vfs_get_independent_super
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun	    Multiple independent superblocks of this type may exist.  This
591*4882a593Smuzhiyun	    function never matches an existing one and always creates a new
592*4882a593Smuzhiyun	    one.
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun
595*4882a593SmuzhiyunParameter Description
596*4882a593Smuzhiyun=====================
597*4882a593Smuzhiyun
598*4882a593SmuzhiyunParameters are described using structures defined in linux/fs_parser.h.
599*4882a593SmuzhiyunThere's a core description struct that links everything together::
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun	struct fs_parameter_description {
602*4882a593Smuzhiyun		const struct fs_parameter_spec *specs;
603*4882a593Smuzhiyun		const struct fs_parameter_enum *enums;
604*4882a593Smuzhiyun	};
605*4882a593Smuzhiyun
606*4882a593SmuzhiyunFor example::
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun	enum {
609*4882a593Smuzhiyun		Opt_autocell,
610*4882a593Smuzhiyun		Opt_bar,
611*4882a593Smuzhiyun		Opt_dyn,
612*4882a593Smuzhiyun		Opt_foo,
613*4882a593Smuzhiyun		Opt_source,
614*4882a593Smuzhiyun	};
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun	static const struct fs_parameter_description afs_fs_parameters = {
617*4882a593Smuzhiyun		.specs		= afs_param_specs,
618*4882a593Smuzhiyun		.enums		= afs_param_enums,
619*4882a593Smuzhiyun	};
620*4882a593Smuzhiyun
621*4882a593SmuzhiyunThe members are as follows:
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun (1) ::
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun       const struct fs_parameter_specification *specs;
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun     Table of parameter specifications, terminated with a null entry, where the
628*4882a593Smuzhiyun     entries are of type::
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun	struct fs_parameter_spec {
631*4882a593Smuzhiyun		const char		*name;
632*4882a593Smuzhiyun		u8			opt;
633*4882a593Smuzhiyun		enum fs_parameter_type	type:8;
634*4882a593Smuzhiyun		unsigned short		flags;
635*4882a593Smuzhiyun	};
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun     The 'name' field is a string to match exactly to the parameter key (no
638*4882a593Smuzhiyun     wildcards, patterns and no case-independence) and 'opt' is the value that
639*4882a593Smuzhiyun     will be returned by the fs_parser() function in the case of a successful
640*4882a593Smuzhiyun     match.
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun     The 'type' field indicates the desired value type and must be one of:
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun	=======================	=======================	=====================
645*4882a593Smuzhiyun	TYPE NAME		EXPECTED VALUE		RESULT IN
646*4882a593Smuzhiyun	=======================	=======================	=====================
647*4882a593Smuzhiyun	fs_param_is_flag	No value		n/a
648*4882a593Smuzhiyun	fs_param_is_bool	Boolean value		result->boolean
649*4882a593Smuzhiyun	fs_param_is_u32		32-bit unsigned int	result->uint_32
650*4882a593Smuzhiyun	fs_param_is_u32_octal	32-bit octal int	result->uint_32
651*4882a593Smuzhiyun	fs_param_is_u32_hex	32-bit hex int		result->uint_32
652*4882a593Smuzhiyun	fs_param_is_s32		32-bit signed int	result->int_32
653*4882a593Smuzhiyun	fs_param_is_u64		64-bit unsigned int	result->uint_64
654*4882a593Smuzhiyun	fs_param_is_enum	Enum value name 	result->uint_32
655*4882a593Smuzhiyun	fs_param_is_string	Arbitrary string	param->string
656*4882a593Smuzhiyun	fs_param_is_blob	Binary blob		param->blob
657*4882a593Smuzhiyun	fs_param_is_blockdev	Blockdev path		* Needs lookup
658*4882a593Smuzhiyun	fs_param_is_path	Path			* Needs lookup
659*4882a593Smuzhiyun	fs_param_is_fd		File descriptor		result->int_32
660*4882a593Smuzhiyun	=======================	=======================	=====================
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun     Note that if the value is of fs_param_is_bool type, fs_parse() will try
663*4882a593Smuzhiyun     to match any string value against "0", "1", "no", "yes", "false", "true".
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun     Each parameter can also be qualified with 'flags':
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun	=======================	================================================
668*4882a593Smuzhiyun	fs_param_v_optional	The value is optional
669*4882a593Smuzhiyun	fs_param_neg_with_no	result->negated set if key is prefixed with "no"
670*4882a593Smuzhiyun	fs_param_neg_with_empty	result->negated set if value is ""
671*4882a593Smuzhiyun	fs_param_deprecated	The parameter is deprecated.
672*4882a593Smuzhiyun	=======================	================================================
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun     These are wrapped with a number of convenience wrappers:
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun	=======================	===============================================
677*4882a593Smuzhiyun	MACRO			SPECIFIES
678*4882a593Smuzhiyun	=======================	===============================================
679*4882a593Smuzhiyun	fsparam_flag()		fs_param_is_flag
680*4882a593Smuzhiyun	fsparam_flag_no()	fs_param_is_flag, fs_param_neg_with_no
681*4882a593Smuzhiyun	fsparam_bool()		fs_param_is_bool
682*4882a593Smuzhiyun	fsparam_u32()		fs_param_is_u32
683*4882a593Smuzhiyun	fsparam_u32oct()	fs_param_is_u32_octal
684*4882a593Smuzhiyun	fsparam_u32hex()	fs_param_is_u32_hex
685*4882a593Smuzhiyun	fsparam_s32()		fs_param_is_s32
686*4882a593Smuzhiyun	fsparam_u64()		fs_param_is_u64
687*4882a593Smuzhiyun	fsparam_enum()		fs_param_is_enum
688*4882a593Smuzhiyun	fsparam_string()	fs_param_is_string
689*4882a593Smuzhiyun	fsparam_blob()		fs_param_is_blob
690*4882a593Smuzhiyun	fsparam_bdev()		fs_param_is_blockdev
691*4882a593Smuzhiyun	fsparam_path()		fs_param_is_path
692*4882a593Smuzhiyun	fsparam_fd()		fs_param_is_fd
693*4882a593Smuzhiyun	=======================	===============================================
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun     all of which take two arguments, name string and option number - for
696*4882a593Smuzhiyun     example::
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun	static const struct fs_parameter_spec afs_param_specs[] = {
699*4882a593Smuzhiyun		fsparam_flag	("autocell",	Opt_autocell),
700*4882a593Smuzhiyun		fsparam_flag	("dyn",		Opt_dyn),
701*4882a593Smuzhiyun		fsparam_string	("source",	Opt_source),
702*4882a593Smuzhiyun		fsparam_flag_no	("foo",		Opt_foo),
703*4882a593Smuzhiyun		{}
704*4882a593Smuzhiyun	};
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun     An addition macro, __fsparam() is provided that takes an additional pair
707*4882a593Smuzhiyun     of arguments to specify the type and the flags for anything that doesn't
708*4882a593Smuzhiyun     match one of the above macros.
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun (2) ::
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun       const struct fs_parameter_enum *enums;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun     Table of enum value names to integer mappings, terminated with a null
715*4882a593Smuzhiyun     entry.  This is of type::
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun	struct fs_parameter_enum {
718*4882a593Smuzhiyun		u8		opt;
719*4882a593Smuzhiyun		char		name[14];
720*4882a593Smuzhiyun		u8		value;
721*4882a593Smuzhiyun	};
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun     Where the array is an unsorted list of { parameter ID, name }-keyed
724*4882a593Smuzhiyun     elements that indicate the value to map to, e.g.::
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun	static const struct fs_parameter_enum afs_param_enums[] = {
727*4882a593Smuzhiyun		{ Opt_bar,   "x",      1},
728*4882a593Smuzhiyun		{ Opt_bar,   "y",      23},
729*4882a593Smuzhiyun		{ Opt_bar,   "z",      42},
730*4882a593Smuzhiyun	};
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun     If a parameter of type fs_param_is_enum is encountered, fs_parse() will
733*4882a593Smuzhiyun     try to look the value up in the enum table and the result will be stored
734*4882a593Smuzhiyun     in the parse result.
735*4882a593Smuzhiyun
736*4882a593SmuzhiyunThe parser should be pointed to by the parser pointer in the file_system_type
737*4882a593Smuzhiyunstruct as this will provide validation on registration (if
738*4882a593SmuzhiyunCONFIG_VALIDATE_FS_PARSER=y) and will allow the description to be queried from
739*4882a593Smuzhiyunuserspace using the fsinfo() syscall.
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun
742*4882a593SmuzhiyunParameter Helper Functions
743*4882a593Smuzhiyun==========================
744*4882a593Smuzhiyun
745*4882a593SmuzhiyunA number of helper functions are provided to help a filesystem or an LSM
746*4882a593Smuzhiyunprocess the parameters it is given.
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun   * ::
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun       int lookup_constant(const struct constant_table tbl[],
751*4882a593Smuzhiyun			   const char *name, int not_found);
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun     Look up a constant by name in a table of name -> integer mappings.  The
754*4882a593Smuzhiyun     table is an array of elements of the following type::
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun	struct constant_table {
757*4882a593Smuzhiyun		const char	*name;
758*4882a593Smuzhiyun		int		value;
759*4882a593Smuzhiyun	};
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun     If a match is found, the corresponding value is returned.  If a match
762*4882a593Smuzhiyun     isn't found, the not_found value is returned instead.
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun   * ::
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun       bool validate_constant_table(const struct constant_table *tbl,
767*4882a593Smuzhiyun				    size_t tbl_size,
768*4882a593Smuzhiyun				    int low, int high, int special);
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun     Validate a constant table.  Checks that all the elements are appropriately
771*4882a593Smuzhiyun     ordered, that there are no duplicates and that the values are between low
772*4882a593Smuzhiyun     and high inclusive, though provision is made for one allowable special
773*4882a593Smuzhiyun     value outside of that range.  If no special value is required, special
774*4882a593Smuzhiyun     should just be set to lie inside the low-to-high range.
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun     If all is good, true is returned.  If the table is invalid, errors are
777*4882a593Smuzhiyun     logged to dmesg and false is returned.
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun   * ::
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun       bool fs_validate_description(const struct fs_parameter_description *desc);
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun     This performs some validation checks on a parameter description.  It
784*4882a593Smuzhiyun     returns true if the description is good and false if it is not.  It will
785*4882a593Smuzhiyun     log errors to dmesg if validation fails.
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun   * ::
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun        int fs_parse(struct fs_context *fc,
790*4882a593Smuzhiyun		     const struct fs_parameter_description *desc,
791*4882a593Smuzhiyun		     struct fs_parameter *param,
792*4882a593Smuzhiyun		     struct fs_parse_result *result);
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun     This is the main interpreter of parameters.  It uses the parameter
795*4882a593Smuzhiyun     description to look up a parameter by key name and to convert that to an
796*4882a593Smuzhiyun     option number (which it returns).
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun     If successful, and if the parameter type indicates the result is a
799*4882a593Smuzhiyun     boolean, integer or enum type, the value is converted by this function and
800*4882a593Smuzhiyun     the result stored in result->{boolean,int_32,uint_32,uint_64}.
801*4882a593Smuzhiyun
802*4882a593Smuzhiyun     If a match isn't initially made, the key is prefixed with "no" and no
803*4882a593Smuzhiyun     value is present then an attempt will be made to look up the key with the
804*4882a593Smuzhiyun     prefix removed.  If this matches a parameter for which the type has flag
805*4882a593Smuzhiyun     fs_param_neg_with_no set, then a match will be made and result->negated
806*4882a593Smuzhiyun     will be set to true.
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun     If the parameter isn't matched, -ENOPARAM will be returned; if the
809*4882a593Smuzhiyun     parameter is matched, but the value is erroneous, -EINVAL will be
810*4882a593Smuzhiyun     returned; otherwise the parameter's option number will be returned.
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun   * ::
813*4882a593Smuzhiyun
814*4882a593Smuzhiyun       int fs_lookup_param(struct fs_context *fc,
815*4882a593Smuzhiyun			   struct fs_parameter *value,
816*4882a593Smuzhiyun			   bool want_bdev,
817*4882a593Smuzhiyun			   struct path *_path);
818*4882a593Smuzhiyun
819*4882a593Smuzhiyun     This takes a parameter that carries a string or filename type and attempts
820*4882a593Smuzhiyun     to do a path lookup on it.  If the parameter expects a blockdev, a check
821*4882a593Smuzhiyun     is made that the inode actually represents one.
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun     Returns 0 if successful and ``*_path`` will be set; returns a negative
824*4882a593Smuzhiyun     error code if not.
825