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

	if (data == NULL)
		return (EINVAL);
	error = copyin(data, &args, sizeof(args));
	if (error)
		return (error);

	ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
	ma = mount_arg(ma, "export", &args.export, sizeof(args.export));
	ma = mount_argf(ma, "uid", "%d", args.uid);
	ma = mount_argf(ma, "gid", "%d", args.gid);
	ma = mount_argf(ma, "mask", "%d", args.mask);
	ma = mount_argf(ma, "dirmask", "%d", args.dirmask);

	ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname");
	ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname");
	ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95");
	ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv");

	ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN);
	ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN);
	ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN);

	error = kernel_mount(ma, flags);

	return (error);
}
.Ed
.Pp
When working with
.Fn kernel_vmount ,
.Fa varargs
must come in pairs, e.g.,
.Brq Va name , value .
.Bd -literal
	error = kernel_vmount(
	    MNT_RDONLY,
	    "fstype", vfsname,
	    "fspath", "/",
	    "from", path,
	    NULL);
.Ed
.Sh SEE ALSO
.Xr VFS 9 ,
.Xr VFS_MOUNT 9
.Sh HISTORY
The
.Fn kernel_mount
family of functions and this manual page first
appeared in
.Fx 6.0 .
.Sh AUTHORS
.An -nosplit
The
.Fn kernel_mount
family of functions and API was developed by
.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
This manual page was written by
.An Tom Rhodes Aq Mt trhodes@FreeBSD.org .