/* [<][>][^][v][top][bottom][index][help] */
1 /*
2 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3 * The President and Fellows of Harvard College.
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 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #ifndef _VFS_H_
31 #define _VFS_H_
32
33
34 #include <array.h>
35
36
37 /*
38 * Virtual File System layer functions.
39 *
40 * The VFS layer translates operations on abstract on-disk files or
41 * pathnames to operations on specific files on specific filesystems.
42 */
43
44 struct uio; /* kernel or userspace I/O buffer (uio.h) */
45 struct device; /* abstract structure for a device (dev.h) */
46 struct fs; /* abstract structure for a filesystem (fs.h) */
47 struct vnode; /* abstract structure for an on-disk file (vnode.h) */
48
49 /*
50 * VFS layer low-level operations.
51 * See vnode.h for direct operations on vnodes.
52 * See fs.h for direct operations on filesystems/devices.
53 *
54 * vfs_setcurdir - change current directory of current thread by vnode
55 * vfs_clearcurdir - change current directory of current thread to "none"
56 * vfs_getcurdir - retrieve vnode of current directory of current thread
57 * vfs_sync - force all dirty buffers to disk
58 * vfs_getroot - get root vnode for the filesystem named DEVNAME
59 * vfs_getdevname - get mounted device name for the filesystem passed in
60 */
61
62 int vfs_setcurdir(struct vnode *dir);
63 int vfs_clearcurdir(void);
64 int vfs_getcurdir(struct vnode **retdir);
65 int vfs_sync(void);
66 int vfs_getroot(const char *devname, struct vnode **result);
67 const char *vfs_getdevname(struct fs *fs);
68
69 /*
70 * VFS layer mid-level operations.
71 *
72 * vfs_lookup - Like VOP_LOOKUP, but takes a full device:path name,
73 * or a name relative to the current directory, and
74 * goes to the correct filesystem.
75 * vfs_lookparent - Likewise, for VOP_LOOKPARENT.
76 *
77 * Both of these may destroy the path passed in.
78 */
79
80 int vfs_lookup(char *path, struct vnode **result);
81 int vfs_lookparent(char *path, struct vnode **result,
82 char *buf, size_t buflen);
83
84 /*
85 * VFS layer high-level operations on pathnames
86 * Because namei may destroy pathnames, these all may too.
87 *
88 * vfs_open - Open or create a file. FLAGS/MODE per the syscall.
89 * vfs_readlink - Read contents of a symlink into a uio.
90 * vfs_symlink - Create a symlink PATH containing contents CONTENTS.
91 * vfs_mkdir - Create a directory. MODE per the syscall.
92 * vfs_link - Create a hard link to a file.
93 * vfs_remove - Delete a file.
94 * vfs_rmdir - Delete a directory.
95 * vfs_rename - rename a file.
96 *
97 * vfs_chdir - Change current directory of current thread by name.
98 * vfs_getcwd - Retrieve name of current directory of current thread.
99 *
100 * vfs_close - Close a vnode opened with vfs_open. Does not fail.
101 * (See vfspath.c for a discussion of why.)
102 */
103
104 int vfs_open(char *path, int openflags, mode_t mode, struct vnode **ret);
105 void vfs_close(struct vnode *vn);
106 int vfs_readlink(char *path, struct uio *data);
107 int vfs_symlink(const char *contents, char *path);
108 int vfs_mkdir(char *path, mode_t mode);
109 int vfs_link(char *oldpath, char *newpath);
110 int vfs_remove(char *path);
111 int vfs_rmdir(char *path);
112 int vfs_rename(char *oldpath, char *newpath);
113
114 int vfs_chdir(char *path);
115 int vfs_getcwd(struct uio *buf);
116
117 /*
118 * Misc
119 *
120 * vfs_bootstrap - Call during system initialization to allocate
121 * structures.
122 *
123 * vfs_setbootfs - Set the filesystem that paths beginning with a
124 * slash are sent to. If not set, these paths fail
125 * with ENOENT. The argument should be the device
126 * name or volume name for the filesystem (such as
127 * "lhd0:") but need not have the trailing colon.
128 *
129 * vfs_clearbootfs - Clear the bootfs filesystem. This should be
130 * done during shutdown so that the filesystem in
131 * question can be unmounted.
132 *
133 * vfs_adddev - Add a device to the VFS named device list. If
134 * MOUNTABLE is zero, the device will be accessible
135 * as "DEVNAME:". If the mountable flag is set, the
136 * device will be accessible as "DEVNAMEraw:" and
137 * mountable under the name "DEVNAME". Thus, the
138 * console, added with MOUNTABLE not set, would be
139 * accessed by pathname as "con:", and lhd0, added
140 * with mountable set, would be accessed by
141 * pathname as "lhd0raw:" and mounted by passing
142 * "lhd0" to vfs_mount.
143 *
144 * vfs_addfs - Add a hardwired filesystem to the VFS named device
145 * list. It will be accessible as "devname:". This is
146 * intended for filesystem-devices like emufs, and
147 * gizmos like Linux procfs or BSD kernfs, not for
148 * mounting filesystems on disk devices.
149 *
150 * vfs_mount - Attempt to mount a filesystem on a device. The
151 * device named by DEVNAME will be looked up and
152 * passed, along with DATA, to the supplied function
153 * MOUNTFUNC, which should create a struct fs and
154 * return it in RESULT.
155 *
156 * vfs_unmount - Unmount the filesystem presently mounted on the
157 * specified device.
158 *
159 * vfs_unmountall - Unmount all mounted filesystems.
160 */
161
162 void vfs_bootstrap(void);
163
164 int vfs_setbootfs(const char *fsname);
165 void vfs_clearbootfs(void);
166
167 int vfs_adddev(const char *devname, struct device *dev, int mountable);
168 int vfs_addfs(const char *devname, struct fs *fs);
169
170 int vfs_mount(const char *devname, void *data,
171 int (*mountfunc)(void *data,
172 struct device *dev,
173 struct fs **result));
174 int vfs_unmount(const char *devname);
175 int vfs_unmountall(void);
176
177 /*
178 * Array of vnodes.
179 */
180 #ifndef VFSINLINE
181 #define VFSINLINE INLINE
182 #endif
183
184 DECLARRAY(vnode);
185 DEFARRAY(vnode, VFSINLINE);
186
187 /*
188 * Global one-big-lock for all filesystem operations.
189 * You must remove this for the filesystem assignment.
190 */
191 void vfs_biglock_acquire(void);
192 void vfs_biglock_release(void);
193 bool vfs_biglock_do_i_hold(void);
194
195
196 #endif /* _VFS_H_ */