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