00001 /* 00002 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 00003 * The President and Fellows of Harvard College. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the University nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 */ 00029 00030 #ifndef _VFS_H_ 00031 #define _VFS_H_ 00032 00033 00034 #include <array.h> 00035 00036 00037 /* 00038 * Virtual File System layer functions. 00039 * 00040 * The VFS layer translates operations on abstract on-disk files or 00041 * pathnames to operations on specific files on specific filesystems. 00042 */ 00043 00044 struct uio; /* kernel or userspace I/O buffer (uio.h) */ 00045 struct device; /* abstract structure for a device (dev.h) */ 00046 struct fs; /* abstract structure for a filesystem (fs.h) */ 00047 struct vnode; /* abstract structure for an on-disk file (vnode.h) */ 00048 00049 /* 00050 * VFS layer low-level operations. 00051 * See vnode.h for direct operations on vnodes. 00052 * See fs.h for direct operations on filesystems/devices. 00053 * 00054 * vfs_setcurdir - change current directory of current thread by vnode 00055 * vfs_clearcurdir - change current directory of current thread to "none" 00056 * vfs_getcurdir - retrieve vnode of current directory of current thread 00057 * vfs_sync - force all dirty buffers to disk 00058 * vfs_getroot - get root vnode for the filesystem named DEVNAME 00059 * vfs_getdevname - get mounted device name for the filesystem passed in 00060 */ 00061 00062 int vfs_setcurdir(struct vnode *dir); 00063 int vfs_clearcurdir(void); 00064 int vfs_getcurdir(struct vnode **retdir); 00065 int vfs_sync(void); 00066 int vfs_getroot(const char *devname, struct vnode **result); 00067 const char *vfs_getdevname(struct fs *fs); 00068 00069 /* 00070 * VFS layer mid-level operations. 00071 * 00072 * vfs_lookup - Like VOP_LOOKUP, but takes a full device:path name, 00073 * or a name relative to the current directory, and 00074 * goes to the correct filesystem. 00075 * vfs_lookparent - Likewise, for VOP_LOOKPARENT. 00076 * 00077 * Both of these may destroy the path passed in. 00078 */ 00079 00080 int vfs_lookup(char *path, struct vnode **result); 00081 int vfs_lookparent(char *path, struct vnode **result, 00082 char *buf, size_t buflen); 00083 00084 /* 00085 * VFS layer high-level operations on pathnames 00086 * Because namei may destroy pathnames, these all may too. 00087 * 00088 * vfs_open - Open or create a file. FLAGS/MODE per the syscall. 00089 * vfs_readlink - Read contents of a symlink into a uio. 00090 * vfs_symlink - Create a symlink PATH containing contents CONTENTS. 00091 * vfs_mkdir - Create a directory. MODE per the syscall. 00092 * vfs_link - Create a hard link to a file. 00093 * vfs_remove - Delete a file. 00094 * vfs_rmdir - Delete a directory. 00095 * vfs_rename - rename a file. 00096 * 00097 * vfs_chdir - Change current directory of current thread by name. 00098 * vfs_getcwd - Retrieve name of current directory of current thread. 00099 * 00100 * vfs_close - Close a vnode opened with vfs_open. Does not fail. 00101 * (See vfspath.c for a discussion of why.) 00102 */ 00103 00104 int vfs_open(char *path, int openflags, mode_t mode, struct vnode **ret); 00105 void vfs_close(struct vnode *vn); 00106 int vfs_readlink(char *path, struct uio *data); 00107 int vfs_symlink(const char *contents, char *path); 00108 int vfs_mkdir(char *path, mode_t mode); 00109 int vfs_link(char *oldpath, char *newpath); 00110 int vfs_remove(char *path); 00111 int vfs_rmdir(char *path); 00112 int vfs_rename(char *oldpath, char *newpath); 00113 00114 int vfs_chdir(char *path); 00115 int vfs_getcwd(struct uio *buf); 00116 00117 /* 00118 * Misc 00119 * 00120 * vfs_bootstrap - Call during system initialization to allocate 00121 * structures. 00122 * 00123 * vfs_setbootfs - Set the filesystem that paths beginning with a 00124 * slash are sent to. If not set, these paths fail 00125 * with ENOENT. The argument should be the device 00126 * name or volume name for the filesystem (such as 00127 * "lhd0:") but need not have the trailing colon. 00128 * 00129 * vfs_clearbootfs - Clear the bootfs filesystem. This should be 00130 * done during shutdown so that the filesystem in 00131 * question can be unmounted. 00132 * 00133 * vfs_adddev - Add a device to the VFS named device list. If 00134 * MOUNTABLE is zero, the device will be accessible 00135 * as "DEVNAME:". If the mountable flag is set, the 00136 * device will be accessible as "DEVNAMEraw:" and 00137 * mountable under the name "DEVNAME". Thus, the 00138 * console, added with MOUNTABLE not set, would be 00139 * accessed by pathname as "con:", and lhd0, added 00140 * with mountable set, would be accessed by 00141 * pathname as "lhd0raw:" and mounted by passing 00142 * "lhd0" to vfs_mount. 00143 * 00144 * vfs_addfs - Add a hardwired filesystem to the VFS named device 00145 * list. It will be accessible as "devname:". This is 00146 * intended for filesystem-devices like emufs, and 00147 * gizmos like Linux procfs or BSD kernfs, not for 00148 * mounting filesystems on disk devices. 00149 * 00150 * vfs_mount - Attempt to mount a filesystem on a device. The 00151 * device named by DEVNAME will be looked up and 00152 * passed, along with DATA, to the supplied function 00153 * MOUNTFUNC, which should create a struct fs and 00154 * return it in RESULT. 00155 * 00156 * vfs_unmount - Unmount the filesystem presently mounted on the 00157 * specified device. 00158 * 00159 * vfs_unmountall - Unmount all mounted filesystems. 00160 */ 00161 00162 void vfs_bootstrap(void); 00163 00164 int vfs_setbootfs(const char *fsname); 00165 void vfs_clearbootfs(void); 00166 00167 int vfs_adddev(const char *devname, struct device *dev, int mountable); 00168 int vfs_addfs(const char *devname, struct fs *fs); 00169 00170 int vfs_mount(const char *devname, void *data, 00171 int (*mountfunc)(void *data, 00172 struct device *dev, 00173 struct fs **result)); 00174 int vfs_unmount(const char *devname); 00175 int vfs_unmountall(void); 00176 00177 /* 00178 * Array of vnodes. 00179 */ 00180 #ifndef VFSINLINE 00181 #define VFSINLINE INLINE 00182 #endif 00183 00184 DECLARRAY(vnode); 00185 DEFARRAY(vnode, VFSINLINE); 00186 00187 /* 00188 * Global one-big-lock for all filesystem operations. 00189 * You must remove this for the filesystem assignment. 00190 */ 00191 void vfs_biglock_acquire(void); 00192 void vfs_biglock_release(void); 00193 bool vfs_biglock_do_i_hold(void); 00194 00195 00196 #endif /* _VFS_H_ */