/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _VFS_H_30#define _VFS_H_313233#include <array.h>343536/*37* Virtual File System layer functions.38*39* The VFS layer translates operations on abstract on-disk files or40* pathnames to operations on specific files on specific filesystems.41*/4243struct uio; /* kernel or userspace I/O buffer (uio.h) */44struct device; /* abstract structure for a device (dev.h) */45struct fs; /* abstract structure for a filesystem (fs.h) */46struct vnode; /* abstract structure for an on-disk file (vnode.h) */4748/*49* VFS layer low-level operations.50* See vnode.h for direct operations on vnodes.51* See fs.h for direct operations on filesystems/devices.52*53* vfs_setcurdir - change current directory of current thread by vnode54* vfs_clearcurdir - change current directory of current thread to "none"55* vfs_getcurdir - retrieve vnode of current directory of current thread56* vfs_sync - force all dirty buffers to disk57* vfs_getroot - get root vnode for the filesystem named DEVNAME58* vfs_getdevname - get mounted device name for the filesystem passed in59*/6061int vfs_setcurdir(struct vnode *dir);62int vfs_clearcurdir(void);63int vfs_getcurdir(struct vnode **retdir);64int vfs_sync(void);65int vfs_getroot(const char *devname, struct vnode **result);66const char *vfs_getdevname(struct fs *fs);6768/*69* VFS layer mid-level operations.70*71* vfs_lookup - Like VOP_LOOKUP, but takes a full device:path name,72* or a name relative to the current directory, and73* goes to the correct filesystem.74* vfs_lookparent - Likewise, for VOP_LOOKPARENT.75*76* Both of these may destroy the path passed in.77*/7879int vfs_lookup(char *path, struct vnode **result);80int vfs_lookparent(char *path, struct vnode **result,81char *buf, size_t buflen);8283/*84* VFS layer high-level operations on pathnames85* Because namei may destroy pathnames, these all may too.86*87* vfs_open - Open or create a file. FLAGS/MODE per the syscall.88* vfs_readlink - Read contents of a symlink into a uio.89* vfs_symlink - Create a symlink PATH containing contents CONTENTS.90* vfs_mkdir - Create a directory. MODE per the syscall.91* vfs_link - Create a hard link to a file.92* vfs_remove - Delete a file.93* vfs_rmdir - Delete a directory.94* vfs_rename - rename a file.95*96* vfs_chdir - Change current directory of current thread by name.97* vfs_getcwd - Retrieve name of current directory of current thread.98*99* vfs_close - Close a vnode opened with vfs_open. Does not fail.100* (See vfspath.c for a discussion of why.)101*/102103int vfs_open(char *path, int openflags, mode_t mode, struct vnode **ret);104void vfs_close(struct vnode *vn);105int vfs_readlink(char *path, struct uio *data);106int vfs_symlink(const char *contents, char *path);107int vfs_mkdir(char *path, mode_t mode);108int vfs_link(char *oldpath, char *newpath);109int vfs_remove(char *path);110int vfs_rmdir(char *path);111int vfs_rename(char *oldpath, char *newpath);112113int vfs_chdir(char *path);114int vfs_getcwd(struct uio *buf);115116/*117* Misc118*119* vfs_bootstrap - Call during system initialization to allocate120* structures.121*122* vfs_setbootfs - Set the filesystem that paths beginning with a123* slash are sent to. If not set, these paths fail124* with ENOENT. The argument should be the device125* name or volume name for the filesystem (such as126* "lhd0:") but need not have the trailing colon.127*128* vfs_clearbootfs - Clear the bootfs filesystem. This should be129* done during shutdown so that the filesystem in130* question can be unmounted.131*132* vfs_adddev - Add a device to the VFS named device list. If133* MOUNTABLE is zero, the device will be accessible134* as "DEVNAME:". If the mountable flag is set, the135* device will be accessible as "DEVNAMEraw:" and136* mountable under the name "DEVNAME". Thus, the137* console, added with MOUNTABLE not set, would be138* accessed by pathname as "con:", and lhd0, added139* with mountable set, would be accessed by140* pathname as "lhd0raw:" and mounted by passing141* "lhd0" to vfs_mount.142*143* vfs_addfs - Add a hardwired filesystem to the VFS named device144* list. It will be accessible as "devname:". This is145* intended for filesystem-devices like emufs, and146* gizmos like Linux procfs or BSD kernfs, not for147* mounting filesystems on disk devices.148*149* vfs_mount - Attempt to mount a filesystem on a device. The150* device named by DEVNAME will be looked up and151* passed, along with DATA, to the supplied function152* MOUNTFUNC, which should create a struct fs and153* return it in RESULT.154*155* vfs_unmount - Unmount the filesystem presently mounted on the156* specified device.157*158* vfs_unmountall - Unmount all mounted filesystems.159*/160161void vfs_bootstrap(void);162163int vfs_setbootfs(const char *fsname);164void vfs_clearbootfs(void);165166int vfs_adddev(const char *devname, struct device *dev, int mountable);167int vfs_addfs(const char *devname, struct fs *fs);168169int vfs_mount(const char *devname, void *data,170int (*mountfunc)(void *data,171struct device *dev,172struct fs **result));173int vfs_unmount(const char *devname);174int vfs_unmountall(void);175176/*177* Array of vnodes.178*/179#ifndef VFSINLINE180#define VFSINLINE INLINE181#endif182183DECLARRAY(vnode);184DEFARRAY(vnode, VFSINLINE);185186/*187* Global one-big-lock for all filesystem operations.188* You must remove this for the filesystem assignment.189*/190void vfs_biglock_acquire(void);191void vfs_biglock_release(void);192bool vfs_biglock_do_i_hold(void);193194195#endif /* _VFS_H_ */196197198