xref: /freebsd/share/man/man9/kernel_mount.9 (revision 81ad6265)
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.\" $FreeBSD$
27.\"
28.Dd November 20, 2021
29.Dt KERNEL_MOUNT 9
30.Os
31.Sh NAME
32.Nm free_mntarg ,
33.Nm kernel_mount ,
34.Nm mount_arg ,
35.Nm mount_argb ,
36.Nm mount_argf ,
37.Nm mount_argsu
38.Nd "functions provided as part of the kernel mount interface"
39.Sh SYNOPSIS
40.Ft void
41.Fn free_mntarg "struct mntarg *ma"
42.Ft int
43.Fn kernel_mount "struct mntarg *ma" "int flags"
44.Ft "struct mntarg *"
45.Fo mount_arg
46.Fa "struct mntarg *ma" "const char *name" "const void *val" "int len"
47.Fc
48.Ft "struct mntarg *"
49.Fn mount_argb "struct mntarg *ma" "int flag" "const char *name"
50.Ft "struct mntarg *"
51.Fn mount_argf "struct mntarg *ma" "const char *name" "const char *fmt" ...
52.Ft "struct mntarg *"
53.Fo mount_argsu
54.Fa "struct mntarg *ma" "const char *name" "const void *val" "int len"
55.Fc
56.Sh DESCRIPTION
57The
58.Fn kernel_mount
59family of functions are provided as an API for building a list
60of mount arguments which will be used to mount file systems
61from inside the kernel.
62By accumulating a list of arguments, the API takes shape and
63provides the information necessary for the kernel to control
64the
65.Xr mount 8
66utility.
67When an error occurs, the process will stop.
68This will not cause a
69.Xr panic 9 .
70.Pp
71The header of the structure is stored in
72.Pa src/sys/kern/vfs_mount.c
73which permits automatic structure creation to
74ease the mount process.
75Memory allocation must always be freed when the entire
76process is complete, it is an error otherwise.
77.Pp
78The
79.Fn free_mntarg
80function is used to free or clear the
81.Vt mntarg
82structure.
83.Pp
84The
85.Fn kernel_mount
86function pulls information from the structure to perform
87the mount request on a given file system.
88Additionally, the
89.Fn kernel_mount
90function always calls the
91.Fn free_mntarg
92function.
93If
94.Fa ma
95contains any error code generated during the construction,
96that code will be called and the file system mount will
97not be attempted.
98.Pp
99The
100.Fn mount_arg
101function takes a plain argument and crafts parts of
102the structure with regards to various mount options.
103If the length is a value less than 0,
104.Xr strlen 3
105is used.
106This argument will be referenced until either
107.Fn free_mntarg
108or
109.Fn kernel_mount
110is called.
111.Pp
112The
113.Fn mount_argb
114function is used to add boolean arguments to
115the structure.
116The
117.Fa flag
118is the boolean value and
119.Fa name
120must start with
121.Qq Li no ,
122otherwise a panic will occur.
123.Pp
124The
125.Fn mount_argf
126function adds
127.Xr printf 9
128style arguments to the current structure.
129.Pp
130The
131.Fn mount_argsu
132function will add arguments to the structure from a
133userland string.
134.Sh EXAMPLES
135An example of the
136.Fn *_cmount
137function:
138.Bd -literal
139static int
140msdosfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
141{
142	struct msdosfs_args args;
143	int error;
144
145	if (data == NULL)
146		return (EINVAL);
147	error = copyin(data, &args, sizeof(args));
148	if (error)
149		return (error);
150
151	ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
152	ma = mount_arg(ma, "export", &args.export, sizeof(args.export));
153	ma = mount_argf(ma, "uid", "%d", args.uid);
154	ma = mount_argf(ma, "gid", "%d", args.gid);
155	ma = mount_argf(ma, "mask", "%d", args.mask);
156	ma = mount_argf(ma, "dirmask", "%d", args.dirmask);
157
158	ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
159	ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
160	ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
161	ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");
162
163	ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
164	ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
165	ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);
166
167	error = kernel_mount(ma, flags);
168
169	return (error);
170}
171.Ed
172.Sh SEE ALSO
173.Xr VFS 9 ,
174.Xr VFS_MOUNT 9
175.Sh HISTORY
176The
177.Fn kernel_mount
178family of functions and this manual page first
179appeared in
180.Fx 6.0 .
181.Sh AUTHORS
182.An -nosplit
183The
184.Fn kernel_mount
185family of functions and API was developed by
186.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
187This manual page was written by
188.An Tom Rhodes Aq Mt trhodes@FreeBSD.org .
189