1 /* 2 * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 #ifndef _KERNEL_VFS_H 9 #define _KERNEL_VFS_H 10 11 12 #include <kernel.h> 13 #include <lock.h> 14 #include <util/list.h> 15 16 #include <fs_interface.h> 17 18 #include <dirent.h> 19 #include <signal.h> 20 #include <sys/stat.h> 21 #include <sys/select.h> 22 23 24 #define DEFAULT_FD_TABLE_SIZE 256 25 #define MAX_FD_TABLE_SIZE 8192 26 #define DEFAULT_NODE_MONITORS 4096 27 #define MAX_NODE_MONITORS 65536 28 29 struct kernel_args; 30 struct vm_cache; 31 struct file_descriptor; 32 struct selectsync; 33 struct pollfd; 34 35 36 /** The I/O context of a process/team, holds the fd array among others */ 37 typedef struct io_context { 38 struct vnode *cwd; 39 mutex io_mutex; 40 uint32 table_size; 41 uint32 num_used_fds; 42 struct file_descriptor **fds; 43 uint8 *fds_close_on_exec; 44 struct list node_monitors; 45 uint32 num_monitors; 46 uint32 max_monitors; 47 } io_context; 48 49 struct fd_info { 50 int number; 51 int32 open_mode; 52 dev_t device; 53 ino_t node; 54 }; 55 56 /* macro to allocate a iovec array on the stack */ 57 #define IOVECS(name, size) \ 58 uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \ 59 iovecs *name = (iovecs *)_##name 60 61 62 #ifdef __cplusplus 63 extern "C" { 64 #endif 65 66 status_t vfs_init(struct kernel_args *args); 67 status_t vfs_bootstrap_file_systems(void); 68 void vfs_mount_boot_file_system(struct kernel_args *args); 69 void vfs_exec_io_context(void *context); 70 void *vfs_new_io_context(void *parentContext); 71 status_t vfs_free_io_context(void *context); 72 73 struct rlimit; 74 int vfs_getrlimit(int resource, struct rlimit * rlp); 75 int vfs_setrlimit(int resource, const struct rlimit * rlp); 76 77 /* calls needed by the VM for paging and by the file cache */ 78 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode); 79 status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode); 80 status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, void **_vnode); 81 status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID, 82 const char *name, void **_vnode); 83 void vfs_vnode_to_node_ref(void *_vnode, dev_t *_mountID, ino_t *_vnodeID); 84 85 status_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, void **_vnode); 86 void vfs_put_vnode(void *vnode); 87 void vfs_acquire_vnode(void *vnode); 88 status_t vfs_get_cookie_from_fd(int fd, void **_cookie); 89 bool vfs_can_page(void *vnode, void *cookie); 90 status_t vfs_read_pages(void *vnode, void *cookie, off_t pos, 91 const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); 92 status_t vfs_write_pages(void *vnode, void *cookie, off_t pos, 93 const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); 94 status_t vfs_get_vnode_cache(void *vnode, struct vm_cache **_cache, bool allocate); 95 status_t vfs_get_file_map( void *_vnode, off_t offset, size_t size, 96 struct file_io_vec *vecs, size_t *_count); 97 status_t vfs_get_fs_node_from_path(dev_t mountID, const char *path, 98 bool kernel, void **_node); 99 status_t vfs_stat_vnode(void *_vnode, struct stat *stat); 100 status_t vfs_get_vnode_name(void *vnode, char *name, size_t nameSize); 101 status_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID); 102 void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor); 103 status_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID); 104 void vfs_free_unused_vnodes(int32 level); 105 106 /* special module convenience call */ 107 status_t vfs_get_module_path(const char *basePath, const char *moduleName, 108 char *pathBuffer, size_t bufferSize); 109 110 /* service call for whoever needs a normalized path */ 111 status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize, 112 bool kernel); 113 114 /* service call for the node monitor */ 115 status_t resolve_mount_point_to_volume_root(dev_t mountID, ino_t nodeID, 116 dev_t *resolvedMountID, ino_t *resolvedNodeID); 117 118 /* calls the syscall dispatcher should use for user file I/O */ 119 dev_t _user_mount(const char *path, const char *device, const char *fs_name, 120 uint32 flags, const char *args, size_t argsLength); 121 status_t _user_unmount(const char *path, uint32 flags); 122 status_t _user_read_fs_info(dev_t device, struct fs_info *info); 123 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask); 124 dev_t _user_next_device(int32 *_cookie); 125 status_t _user_sync(void); 126 status_t _user_get_next_fd_info(team_id team, uint32 *cookie, struct fd_info *info, 127 size_t infoSize); 128 status_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf, 129 char *userPath, size_t pathLength); 130 int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms); 131 int _user_open(int fd, const char *path, int openMode, int perms); 132 int _user_open_dir_node_ref(dev_t device, ino_t inode); 133 int _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname); 134 int _user_open_dir(int fd, const char *path); 135 int _user_open_parent_dir(int fd, char *name, size_t nameLength); 136 status_t _user_fcntl(int fd, int op, uint32 argument); 137 status_t _user_fsync(int fd); 138 status_t _user_read_stat(int fd, const char *path, bool traverseLink, 139 struct stat *stat, size_t statSize); 140 status_t _user_write_stat(int fd, const char *path, bool traverseLink, 141 const struct stat *stat, size_t statSize, int statMask); 142 off_t _user_seek(int fd, off_t pos, int seekType); 143 status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms); 144 status_t _user_create_dir(int fd, const char *path, int perms); 145 status_t _user_remove_dir(int fd, const char *path); 146 status_t _user_read_link(int fd, const char *path, char *buffer, size_t *_bufferSize); 147 status_t _user_write_link(const char *path, const char *toPath); 148 status_t _user_create_symlink(int fd, const char *path, const char *toPath, 149 int mode); 150 status_t _user_create_link(const char *path, const char *toPath); 151 status_t _user_unlink(int fd, const char *path); 152 status_t _user_rename(int oldFD, const char *oldpath, int newFD, 153 const char *newpath); 154 status_t _user_access(const char *path, int mode); 155 ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, 156 bigtime_t timeout, const sigset_t *sigMask); 157 ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 158 int _user_open_attr_dir(int fd, const char *path); 159 int _user_create_attr(int fd, const char *name, uint32 type, int openMode); 160 int _user_open_attr(int fd, const char *name, int openMode); 161 status_t _user_remove_attr(int fd, const char *name); 162 status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName); 163 int _user_open_index_dir(dev_t device); 164 status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags); 165 status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat); 166 status_t _user_remove_index(dev_t device, const char *name); 167 status_t _user_getcwd(char *buffer, size_t size); 168 status_t _user_setcwd(int fd, const char *path); 169 int _user_open_query(dev_t device, const char *query, size_t queryLength, uint32 flags, 170 port_id port, int32 token); 171 172 /* fd user prototypes (implementation located in fd.c) */ 173 extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize); 174 extern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count); 175 extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize); 176 extern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count); 177 extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length); 178 extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount); 179 extern status_t _user_rewind_dir(int fd); 180 extern status_t _user_close(int fd); 181 extern int _user_dup(int fd); 182 extern int _user_dup2(int ofd, int nfd); 183 extern status_t _user_lock_node(int fd); 184 extern status_t _user_unlock_node(int fd); 185 186 /* vfs entry points... */ 187 188 #ifdef __cplusplus 189 } 190 #endif 191 192 #endif /* _KERNEL_VFS_H */ 193