xref: /freebsd/share/man/man9/kernel_mount.9 (revision 315ee00f)
1.\"
2.\" Copyright (c) 2004 Tom Rhodes
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd November 20, 2021
27.Dt KERNEL_MOUNT 9
28.Os
29.Sh NAME
30.Nm free_mntarg ,
31.Nm kernel_mount ,
32.Nm mount_arg ,
33.Nm mount_argb ,
34.Nm mount_argf ,
35.Nm mount_argsu
36.Nd "functions provided as part of the kernel mount interface"
37.Sh SYNOPSIS
38.Ft void
39.Fn free_mntarg "struct mntarg *ma"
40.Ft int
41.Fn kernel_mount "struct mntarg *ma" "int flags"
42.Ft "struct mntarg *"
43.Fo mount_arg
44.Fa "struct mntarg *ma" "const char *name" "const void *val" "int len"
45.Fc
46.Ft "struct mntarg *"
47.Fn mount_argb "struct mntarg *ma" "int flag" "const char *name"
48.Ft "struct mntarg *"
49.Fn mount_argf "struct mntarg *ma" "const char *name" "const char *fmt" ...
50.Ft "struct mntarg *"
51.Fo mount_argsu
52.Fa "struct mntarg *ma" "const char *name" "const void *val" "int len"
53.Fc
54.Sh DESCRIPTION
55The
56.Fn kernel_mount
57family of functions are provided as an API for building a list
58of mount arguments which will be used to mount file systems
59from inside the kernel.
60By accumulating a list of arguments, the API takes shape and
61provides the information necessary for the kernel to control
62the
63.Xr mount 8
64utility.
65When an error occurs, the process will stop.
66This will not cause a
67.Xr panic 9 .
68.Pp
69The header of the structure is stored in
70.Pa src/sys/kern/vfs_mount.c
71which permits automatic structure creation to
72ease the mount process.
73Memory allocation must always be freed when the entire
74process is complete, it is an error otherwise.
75.Pp
76The
77.Fn free_mntarg
78function is used to free or clear the
79.Vt mntarg
80structure.
81.Pp
82The
83.Fn kernel_mount
84function pulls information from the structure to perform
85the mount request on a given file system.
86Additionally, the
87.Fn kernel_mount
88function always calls the
89.Fn free_mntarg
90function.
91If
92.Fa ma
93contains any error code generated during the construction,
94that code will be called and the file system mount will
95not be attempted.
96.Pp
97The
98.Fn mount_arg
99function takes a plain argument and crafts parts of
100the structure with regards to various mount options.
101If the length is a value less than 0,
102.Xr strlen 3
103is used.
104This argument will be referenced until either
105.Fn free_mntarg
106or
107.Fn kernel_mount
108is called.
109.Pp
110The
111.Fn mount_argb
112function is used to add boolean arguments to
113the structure.
114The
115.Fa flag
116is the boolean value and
117.Fa name
118must start with
119.Qq Li no ,
120otherwise a panic will occur.
121.Pp
122The
123.Fn mount_argf
124function adds
125.Xr printf 9
126style arguments to the current structure.
127.Pp
128The
129.Fn mount_argsu
130function will add arguments to the structure from a
131userland string.
132.Sh EXAMPLES
133An example of the
134.Fn *_cmount
135function:
136.Bd -literal
137static int
138msdosfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
139{
140	struct msdosfs_args args;
141	int error;
142
143	if (data == NULL)
144		return (EINVAL);
145	error = copyin(data, &args, sizeof(args));
146	if (error)
147		return (error);
148
149	ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
150	ma = mount_arg(ma, "export", &args.export, sizeof(args.export));
151	ma = mount_argf(ma, "uid", "%d", args.uid);
152	ma = mount_argf(ma, "gid", "%d", args.gid);
153	ma = mount_argf(ma, "mask", "%d", args.mask);
154	ma = mount_argf(ma, "dirmask", "%d", args.dirmask);
155
156	ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
157	ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
158	ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
159	ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");
160
161	ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
162	ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
163	ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);
164
165	error = kernel_mount(ma, flags);
166
167	return (error);
168}
169.Ed
170.Sh SEE ALSO
171.Xr VFS 9 ,
172.Xr VFS_MOUNT 9
173.Sh HISTORY
174The
175.Fn kernel_mount
176family of functions and this manual page first
177appeared in
178.Fx 6.0 .
179.Sh AUTHORS
180.An -nosplit
181The
182.Fn kernel_mount
183family of functions and API was developed by
184.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
185This manual page was written by
186.An Tom Rhodes Aq Mt trhodes@FreeBSD.org .
187