vfs.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #ifndef _VFS_H_
  30. #define _VFS_H_
  31. #include <array.h>
  32. /*
  33. * Virtual File System layer functions.
  34. *
  35. * The VFS layer translates operations on abstract on-disk files or
  36. * pathnames to operations on specific files on specific filesystems.
  37. */
  38. struct uio; /* kernel or userspace I/O buffer (uio.h) */
  39. struct device; /* abstract structure for a device (dev.h) */
  40. struct fs; /* abstract structure for a filesystem (fs.h) */
  41. struct vnode; /* abstract structure for an on-disk file (vnode.h) */
  42. /*
  43. * VFS layer low-level operations.
  44. * See vnode.h for direct operations on vnodes.
  45. * See fs.h for direct operations on filesystems/devices.
  46. *
  47. * vfs_setcurdir - change current directory of current thread by vnode
  48. * vfs_clearcurdir - change current directory of current thread to "none"
  49. * vfs_getcurdir - retrieve vnode of current directory of current thread
  50. * vfs_sync - force all dirty buffers to disk
  51. * vfs_getroot - get root vnode for the filesystem named DEVNAME
  52. * vfs_getdevname - get mounted device name for the filesystem passed in
  53. */
  54. int vfs_setcurdir(struct vnode *dir);
  55. int vfs_clearcurdir(void);
  56. int vfs_getcurdir(struct vnode **retdir);
  57. int vfs_sync(void);
  58. int vfs_getroot(const char *devname, struct vnode **result);
  59. const char *vfs_getdevname(struct fs *fs);
  60. /*
  61. * VFS layer mid-level operations.
  62. *
  63. * vfs_lookup - Like VOP_LOOKUP, but takes a full device:path name,
  64. * or a name relative to the current directory, and
  65. * goes to the correct filesystem.
  66. * vfs_lookparent - Likewise, for VOP_LOOKPARENT.
  67. *
  68. * Both of these may destroy the path passed in.
  69. */
  70. int vfs_lookup(char *path, struct vnode **result);
  71. int vfs_lookparent(char *path, struct vnode **result,
  72. char *buf, size_t buflen);
  73. /*
  74. * VFS layer high-level operations on pathnames
  75. * Because namei may destroy pathnames, these all may too.
  76. *
  77. * vfs_open - Open or create a file. FLAGS/MODE per the syscall.
  78. * vfs_readlink - Read contents of a symlink into a uio.
  79. * vfs_symlink - Create a symlink PATH containing contents CONTENTS.
  80. * vfs_mkdir - Create a directory. MODE per the syscall.
  81. * vfs_link - Create a hard link to a file.
  82. * vfs_remove - Delete a file.
  83. * vfs_rmdir - Delete a directory.
  84. * vfs_rename - rename a file.
  85. *
  86. * vfs_chdir - Change current directory of current thread by name.
  87. * vfs_getcwd - Retrieve name of current directory of current thread.
  88. *
  89. * vfs_close - Close a vnode opened with vfs_open. Does not fail.
  90. * (See vfspath.c for a discussion of why.)
  91. */
  92. int vfs_open(char *path, int openflags, mode_t mode, struct vnode **ret);
  93. void vfs_close(struct vnode *vn);
  94. int vfs_readlink(char *path, struct uio *data);
  95. int vfs_symlink(const char *contents, char *path);
  96. int vfs_mkdir(char *path, mode_t mode);
  97. int vfs_link(char *oldpath, char *newpath);
  98. int vfs_remove(char *path);
  99. int vfs_rmdir(char *path);
  100. int vfs_rename(char *oldpath, char *newpath);
  101. int vfs_chdir(char *path);
  102. int vfs_getcwd(struct uio *buf);
  103. /*
  104. * Misc
  105. *
  106. * vfs_bootstrap - Call during system initialization to allocate
  107. * structures.
  108. *
  109. * vfs_setbootfs - Set the filesystem that paths beginning with a
  110. * slash are sent to. If not set, these paths fail
  111. * with ENOENT. The argument should be the device
  112. * name or volume name for the filesystem (such as
  113. * "lhd0:") but need not have the trailing colon.
  114. *
  115. * vfs_clearbootfs - Clear the bootfs filesystem. This should be
  116. * done during shutdown so that the filesystem in
  117. * question can be unmounted.
  118. *
  119. * vfs_adddev - Add a device to the VFS named device list. If
  120. * MOUNTABLE is zero, the device will be accessible
  121. * as "DEVNAME:". If the mountable flag is set, the
  122. * device will be accessible as "DEVNAMEraw:" and
  123. * mountable under the name "DEVNAME". Thus, the
  124. * console, added with MOUNTABLE not set, would be
  125. * accessed by pathname as "con:", and lhd0, added
  126. * with mountable set, would be accessed by
  127. * pathname as "lhd0raw:" and mounted by passing
  128. * "lhd0" to vfs_mount.
  129. *
  130. * vfs_addfs - Add a hardwired filesystem to the VFS named device
  131. * list. It will be accessible as "devname:". This is
  132. * intended for filesystem-devices like emufs, and
  133. * gizmos like Linux procfs or BSD kernfs, not for
  134. * mounting filesystems on disk devices.
  135. *
  136. * vfs_mount - Attempt to mount a filesystem on a device. The
  137. * device named by DEVNAME will be looked up and
  138. * passed, along with DATA, to the supplied function
  139. * MOUNTFUNC, which should create a struct fs and
  140. * return it in RESULT.
  141. *
  142. * vfs_unmount - Unmount the filesystem presently mounted on the
  143. * specified device.
  144. *
  145. * vfs_unmountall - Unmount all mounted filesystems.
  146. */
  147. void vfs_bootstrap(void);
  148. int vfs_setbootfs(const char *fsname);
  149. void vfs_clearbootfs(void);
  150. int vfs_adddev(const char *devname, struct device *dev, int mountable);
  151. int vfs_addfs(const char *devname, struct fs *fs);
  152. int vfs_mount(const char *devname, void *data,
  153. int (*mountfunc)(void *data,
  154. struct device *dev,
  155. struct fs **result));
  156. int vfs_unmount(const char *devname);
  157. int vfs_unmountall(void);
  158. /*
  159. * Array of vnodes.
  160. */
  161. #ifndef VFSINLINE
  162. #define VFSINLINE INLINE
  163. #endif
  164. DECLARRAY(vnode);
  165. DEFARRAY(vnode, VFSINLINE);
  166. /*
  167. * Global one-big-lock for all filesystem operations.
  168. * You must remove this for the filesystem assignment.
  169. */
  170. void vfs_biglock_acquire(void);
  171. void vfs_biglock_release(void);
  172. bool vfs_biglock_do_i_hold(void);
  173. #endif /* _VFS_H_ */