xref: /netbsd-src/lib/libukfs/ukfs.3 (revision 6deb2c22d20de1d75d538e8a5c57b573926fd157)
1.\"     $NetBSD: ukfs.3,v 1.9 2009/09/14 20:54:34 pooka Exp $
2.\"
3.\" Copyright (c) 2008 Antti Kantee.  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 28, 2008
27.Dt UKFS 3
28.Os
29.Sh NAME
30.Nm ukfs
31.Nd user kernel file system library interface
32.Sh LIBRARY
33ukfs Library (libukfs, \-lukfs)
34.Sh SYNOPSIS
35.In rump/ukfs.h
36.Sh DESCRIPTION
37The
38.Nm
39library provides direct access to file systems without having to
40specially mount a file system.
41Therefore, accessing a file system through
42.Nm
43requires no special kernel support apart from standard POSIX functionality.
44As
45.Nm
46is built upon
47.Xr rump 3 ,
48all kernel file systems which are supported by rump are available.
49It allows to write utilities for accessing file systems without having
50to duplicate file system internals knowledge already present in kernel
51file system drivers.
52.Pp
53.Nm
54provides a high-level pathname based interface for accessing file systems.
55If a lower level interface it desired,
56.Xr rump 3
57should be used directly.
58However, much like system calls, the interfaces of
59.Nm ,
60are self-contained and require no tracking and release of resources.
61The only exception is the file system handle
62.Ft struct ukfs
63which should be released after use.
64.Sh INITIALIZATION
65.Bl -ohang
66.It Ft int
67.Fn ukfs_init
68.It Ft int
69.Fn ukfs_modload "const char *fname"
70.It Ft int
71.Fn ukfs_modload_dir "const char *dirname"
72.It Ft ssize_t
73.Fn ukfs_vfstypes "char *buf" "size_t buflen"
74.It Ft struct ukfs *
75.Fn ukfs_mount "const char *vfsname" "const char *devpath" \
76"const char *mountpath"  "int mntflags" "void *arg" "size_t alen"
77.It Ft void
78.Fn ukfs_release "struct ukfs *ukfs" "int flags"
79.El
80.Pp
81.Fn ukfs_init
82intializes the library and must be called once per process using
83.Nm .
84.Pp
85.Fn ukfs_modload
86is used at runtime to dynamically load a library which contains a
87file system module.
88For this to succeed, the
89.Xr rump 3
90library and the module targetted must be compiled with compatible kernel
91versions and the application must be dynamically linked.
92Additionally, since this routine does not handle dependencies, all the
93dependencies of the library must be loaded beforehand.
94The routine returns \-1 for fatal error, 0 for dependency failure and 1
95for success.
96.Pp
97.Fn ukfs_modload_dir
98loads all
99.Xr rump 3
100file system modules in directory
101.Fa dirname .
102It looks for libraries which begin with
103.Pa librumpfs_
104and end in
105.Pa .so .
106The routine tries to handle dependencies by retrying to load libraries
107which failed due to dependencies.
108.Fn ukfs_modload_dir
109returns the number of vfs modules loaded or sets errno and
110returns \-1 in case of a fatal error in directory searching.
111In case a fatal error occurs after some modules have already been
112loaded, the number of loaded module is returned.
113Fatal errors in loading the modules themselves are ignored and
114.Fn ukfs_modload
115should be used directly if finegrained error reporting is desired.
116.Pp
117It should be noted that the above routines affect the whole process,
118not just a specific instance of
119.Nm .
120It is preferable to call them from only one thread, as the underlying
121dynamic library interfaces may not be threadsafe.
122.Pp
123.Fn ukfs_vfstypes
124queries the available file system types and returns a nul-terminated
125list of types separated by spaces in
126.Fa buf .
127The format of the list is equivalent to the one returned by
128.Xr sysctl 3
129on the name
130.Pa vfs.generic.fstypes .
131The function returns the length of the string without the trailing nul
132or \-1 for error.
133Notably, the return value 0 means there are no file systems available.
134If there is not enough room in the caller's buffer for all file system
135types, as many as fit will be returned.
136.Pp
137.Fn ukfs_mount
138intializes a file system image.
139The handle resulting from the operation is passed to all other routines
140and identifies the instance of the mount analoguous to what a pathname
141specifies in a normally mounted file system.
142The parameters are the following:
143.Bl -tag -width XXX -offset indent
144.It vfsname
145Name of the file system to be used, e.g.
146.Dv MOUNT_FFS .
147.It devpath
148Path of file system image.
149It can be either a regular file, device or, if the file system does
150not support the concept of a device, an abitrary string, e.g. network
151address.
152.It mountpath
153Path where the file system is mounted to.
154This parameter is used only by the file system being mounted.
155Most of the time
156.Dv UKFS_DEFAULTMP
157is the correct path.
158.It mntflags
159Flags as passed to the
160.Xr mount 2
161system call, for example
162.Dv MNT_RDONLY .
163In addition to generic parameters, file system specific parameters such as
164.Dv MNT_LOG
165(ffs) may be passed here.
166.It arg
167File system private argument structure.
168This is passed directly to the file system.
169It must match what
170.Fa vfsname
171expects.
172.It alen
173Size of said structure.
174.El
175.Pp
176.Fn ukfs_release
177releases the resources associated with
178.Fa ukfs .
179If
180.Fa flags
181is
182.Dv UKFS_RELFLAG_NOUNMOUNT ,
183the file system is not unmounted.
184This is required if the file system has already been unmounted due
185to prior activity, otherwise 0 should be passed.
186.Sh OPERATION
187.Bl -ohang
188.It Ft int
189.Fn ukfs_chdir "struct ukfs *ukfs" "const char *path"
190.It Ft int
191.Fn ukfs_getdents "struct ukfs *ukfs" "const char *dirname" "off_t *off" \
192"uint8_t *buf" "size_t bufsize"
193.It Ft ssize_t
194.Fn ukfs_read "struct ukfs *ukfs" "const char *filename" "off_t off" \
195"uint8_t *buf" "size_t bufsize"
196.It Ft ssize_t
197.Fn ukfs_write "struct ukfs *ukfs" "const char *filename" "off_t off" \
198"uint8_t *buf" "size_t bufsize"
199.It Ft int
200.Fn ukfs_create "struct ukfs *ukfs" "const char *filename" "mode_t mode"
201.It Ft int
202.Fn ukfs_mknod "struct ukfs *ukfs" "const char *path" "mode_t mode" "dev_t dev"
203.It Ft int
204.Fn ukfs_mkfifo "struct ukfs *ukfs" "const char *path" "mode_t mode"
205.It Ft int
206.Fn ukfs_mkdir "struct ukfs *ukfs" "const char *filename" "mode_t mode"
207.It Ft int
208.Fn ukfs_remove "struct ukfs *ukfs" "const char *filename"
209.It Ft int
210.Fn ukfs_rmdir "struct ukfs *ukfs" "const char *filename"
211.It Ft int
212.Fn ukfs_link "struct ukfs *ukfs" "const char *filename" "const char *f_create"
213.It Ft int
214.Fn ukfs_symlink "struct ukfs *ukfs" "const char *filename" \
215"const char *linkname"
216.It Ft ssize_t
217.Fn ukfs_readlink "struct ukfs *ukfs" "const char *filename" \
218"char *linkbuf" "size_t buflen"
219.It Ft int
220.Fn ukfs_rename "struct ukfs *ukfs" "const char *from" "const char *to"
221.It Ft int
222.Fn ukfs_stat "struct ukfs *ukfs" "const char *filename" \
223"struct stat *file_stat"
224.It Ft int
225.Fn ukfs_lstat "struct ukfs *ukfs" "const char *filename" \
226"struct stat *file_stat"
227.It Ft int
228.Fn ukfs_chmod "struct ukfs *ukfs" "const char *filename" "mode_t mode"
229.It Ft int
230.Fn ukfs_lchmod "struct ukfs *ukfs" "const char *filename" "mode_t mode"
231.It Ft int
232.Fn ukfs_chown "struct ukfs *ukfs" "const char *filename" "uid_t uid" \
233"gid_t gid"
234.It Ft int
235.Fn ukfs_lchown "struct ukfs *ukfs" "const char *filename" "uid_t uid" \
236"gid_t gid"
237.It Ft int
238.Fn ukfs_chflags "struct ukfs *ukfs" "const char *filename" "u_long flags"
239.It Ft int
240.Fn ukfs_lchflags "struct ukfs *ukfs" "const char *filename" "u_long flags"
241.It Ft int
242.Fn ukfs_utimes "struct ukfs *ukfs" "const char *filename" \
243"const struct timeval *tptr"
244.It Ft int
245.Fn ukfs_lutimes "struct ukfs *ukfs" "const char *filename" \
246"const struct timeval *tptr"
247.El
248.Pp
249The above routines operate like their system call counterparts and the
250system call manual pages without the ukfs_ prefix should be referred to
251for further information on the parameters.
252.Pp
253The only call which modifies
254.Fa ukfs
255state is
256.Fn ukfs_chdir .
257It works like
258.Xr chdir 2
259in the sense that it affects the interpretation of relative paths.
260If succesful, all relative pathnames will be resolved starting from the
261current directory.
262Currently the call affects all accesses to that particular
263.Fa ,
264but it might be later changed to be thread private.
265.Sh UTILITIES
266.Bl -ohang
267.It Ft int
268.Fn ukfs_util_builddirs "struct ukfs *ukfs" "const char *pathname" "mode_t mode"
269.El
270.Pp
271Builds a directory hierarchy.
272Unlike mkdir, the
273.Fa pathname
274argument may contain multiple levels of hierarchy.
275It is not considered an error if any of the directories specified exist
276already.
277.Sh SEE ALSO
278.Xr rump 3
279.Sh HISTORY
280.Nm
281first appeared in
282.Nx 5.0 .
283.Sh AUTHORS
284.An Antti Kantee Aq pooka@cs.hut.fi
285.Sh NOTES
286.Nm
287should be considered experimental technology and may change without warning.
288.Sh BUGS
289Due to how the runtime linker works, it is possible to include
290support for only one file system in dynamic binaries at linktime.
291The remaining desired file systems can be loaded with
292.Fn ukfs_modload .
293Statically linked binaries do not have this limitation, but cannot use
294.Fn ukfs_modload
295at all.
296The recommended approach is to use dynamically linked binaries and load all
297file system modules with
298.Fn ukfs_modload .
299