1 /* 2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 3 ** Distributed under the terms of the NewOS License. 4 */ 5 6 #ifndef _KERNEL_VFS_H 7 #define _KERNEL_VFS_H 8 9 #include <kernel.h> 10 #include <sys/stat.h> 11 #include <sys/select.h> 12 #include <signal.h> 13 #include <dirent.h> 14 #include <fs_interface.h> 15 #include <lock.h> 16 #include <util/list.h> 17 18 #define DEFAULT_FD_TABLE_SIZE 128 19 #define MAX_FD_TABLE_SIZE 2048 20 #define MAX_NODE_MONITORS 4096 21 22 #include <vfs_types.h> 23 24 25 struct kernel_args; 26 struct file_descriptor; 27 struct selectsync; 28 struct pollfd; 29 30 31 /** The I/O context of a process/team, holds the fd array among others */ 32 typedef struct io_context { 33 struct vnode *cwd; 34 mutex io_mutex; 35 uint32 table_size; 36 uint32 num_used_fds; 37 struct file_descriptor **fds; 38 struct list node_monitors; 39 uint32 num_monitors; 40 uint32 max_monitors; 41 } io_context; 42 43 44 /* macro to allocate a iovec array on the stack */ 45 #define IOVECS(name, size) \ 46 uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \ 47 iovecs *name = (iovecs *)_##name 48 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 int vfs_init(struct kernel_args *ka); 55 int vfs_bootstrap_all_filesystems(void); 56 int vfs_register_filesystem(const char *name, struct fs_ops *calls); 57 void *vfs_new_io_context(void *parent_ioctx); 58 int vfs_free_io_context(void *ioctx); 59 int vfs_test(void); 60 61 struct rlimit; 62 int vfs_getrlimit(int resource, struct rlimit * rlp); 63 int vfs_setrlimit(int resource, const struct rlimit * rlp); 64 65 // ToDo: for now; this prototype should be in os/drivers/Drivers.h 66 // or similar places. 67 extern status_t notify_select_event(struct selectsync *sync, uint32 ref, uint8 event); 68 69 /* calls needed by fs internals */ 70 extern status_t vfs_new_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode); 71 extern status_t vfs_get_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode *_privateNode); 72 extern status_t vfs_put_vnode(mount_id mountID, vnode_id vnodeID); 73 extern status_t vfs_remove_vnode(mount_id mountID, vnode_id vnodeID); 74 75 /* calls needed by the VM for paging */ 76 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode); 77 status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode); 78 int vfs_put_vnode_ptr(void *vnode); 79 void vfs_vnode_acquire_ref(void *vnode); 80 void vfs_vnode_release_ref(void *vnode); 81 ssize_t vfs_can_page(void *vnode); 82 ssize_t vfs_read_page(void *vnode, iovecs *vecs, off_t pos); 83 ssize_t vfs_write_page(void *vnode, iovecs *vecs, off_t pos); 84 void *vfs_get_cache_ptr(void *vnode); 85 int vfs_set_cache_ptr(void *vnode, void *cache); 86 87 /* special module convenience call */ 88 status_t vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuffer, size_t bufferSize); 89 90 /* calls kernel code should make for file I/O */ 91 int sys_mount(const char *path, const char *device, const char *fs_name, void *args); 92 int sys_unmount(const char *path); 93 status_t _kern_read_fs_info(dev_t device, struct fs_info *info); 94 status_t _kern_write_fs_info(dev_t device, const struct fs_info *info, int mask); 95 int sys_sync(void); 96 int sys_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode); 97 int sys_open(const char *path, int omode); 98 int sys_open_dir_node_ref(dev_t device, ino_t inode); 99 int sys_open_dir_entry_ref(dev_t device, ino_t inode, const char *name); 100 int sys_open_dir(const char *path); 101 int sys_fsync(int fd); 102 off_t sys_seek(int fd, off_t pos, int seekType); 103 int sys_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms); 104 int sys_create(const char *path, int omode, int perms); 105 int sys_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms); 106 int sys_create_dir(const char *path, int perms); 107 int sys_remove_dir(const char *path); 108 int sys_read_link(const char *path, char *buffer, size_t bufferSize); 109 int sys_write_link(const char *path, const char *toPath); 110 int sys_create_symlink(const char *path, const char *toPath, int mode); 111 int sys_create_link(const char *path, const char *toPath); 112 int sys_unlink(const char *path); 113 int sys_rename(const char *oldpath, const char *newpath); 114 int sys_access(const char *path, int mode); 115 int sys_read_path_stat(const char *path, bool traverseLink, struct stat *stat); 116 int sys_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask); 117 int sys_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, 118 bigtime_t timeout, const sigset_t *sigMask); 119 int sys_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 120 int sys_open_attr_dir(int fd, const char *path); 121 int sys_create_attr(int fd, const char *name, uint32 type, int openMode); 122 int sys_open_attr(int fd, const char *name, int openMode); 123 int sys_remove_attr(int fd, const char *name); 124 int sys_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName); 125 int sys_open_index_dir(dev_t device); 126 int sys_create_index(dev_t device, const char *name, uint32 type, uint32 flags); 127 int sys_read_index_stat(dev_t device, const char *name, struct stat *stat); 128 int sys_remove_index(dev_t device, const char *name); 129 int sys_getcwd(char *buffer, size_t size); 130 int sys_setcwd(int fd, const char *path); 131 132 /* calls the syscall dispatcher should use for user file I/O */ 133 int user_mount(const char *path, const char *device, const char *fs_name, void *args); 134 int user_unmount(const char *path); 135 status_t _user_read_fs_info(dev_t device, struct fs_info *info); 136 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask); 137 int user_sync(void); 138 int user_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode); 139 int user_open(const char *path, int omode); 140 int user_open_dir_node_ref(dev_t device, ino_t inode); 141 int user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname); 142 int user_open_dir(const char *path); 143 int user_fsync(int fd); 144 off_t user_seek(int fd, off_t pos, int seekType); 145 int user_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms); 146 int user_create(const char *path, int omode, int perms); 147 int user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms); 148 int user_create_dir(const char *path, int perms); 149 int user_remove_dir(const char *path); 150 int user_read_link(const char *path, char *buffer, size_t bufferSize); 151 int user_write_link(const char *path, const char *toPath); 152 int user_create_symlink(const char *path, const char *toPath, int mode); 153 int user_create_link(const char *path, const char *toPath); 154 int user_unlink(const char *path); 155 int user_rename(const char *oldpath, const char *newpath); 156 int user_access(const char *path, int mode); 157 int user_read_path_stat(const char *path, bool traverseLink, struct stat *stat); 158 int user_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask); 159 int user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, 160 bigtime_t timeout, const sigset_t *sigMask); 161 int user_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 162 int user_open_attr_dir(int fd, const char *path); 163 int user_create_attr(int fd, const char *name, uint32 type, int openMode); 164 int user_open_attr(int fd, const char *name, int openMode); 165 int user_remove_attr(int fd, const char *name); 166 int user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName); 167 int user_open_index_dir(dev_t device); 168 int user_create_index(dev_t device, const char *name, uint32 type, uint32 flags); 169 int user_read_index_stat(dev_t device, const char *name, struct stat *stat); 170 int user_remove_index(dev_t device, const char *name); 171 int user_getcwd(char *buffer, size_t size); 172 int user_setcwd(int fd, const char *path); 173 174 /* fd kernel prototypes (implementation located in fd.c) */ 175 extern ssize_t sys_read(int fd, off_t pos, void *buffer, size_t bufferSize); 176 extern ssize_t sys_write(int fd, off_t pos, const void *buffer, size_t bufferSize); 177 extern int sys_ioctl(int fd, ulong cmd, void *data, size_t length); 178 extern ssize_t sys_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount); 179 extern status_t sys_rewind_dir(int fd); 180 extern int sys_read_stat(int fd, struct stat *stat); 181 extern int sys_write_stat(int fd, const struct stat *stat, int statMask); 182 extern int sys_close(int fd); 183 extern int sys_dup(int fd); 184 extern int sys_dup2(int ofd, int nfd); 185 186 /* fd user prototypes (implementation located in fd.c) */ 187 extern ssize_t user_read(int fd, off_t pos, void *buffer, size_t bufferSize); 188 extern ssize_t user_write(int fd, off_t pos, const void *buffer, size_t bufferSize); 189 extern int user_ioctl(int fd, ulong cmd, void *data, size_t length); 190 extern ssize_t user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount); 191 extern status_t user_rewind_dir(int fd); 192 extern int user_read_stat(int fd, struct stat *stat); 193 extern int user_write_stat(int fd, const struct stat *stat, int statMask); 194 extern int user_close(int fd); 195 extern int user_dup(int fd); 196 extern int user_dup2(int ofd, int nfd); 197 198 /* vfs entry points... */ 199 200 #ifdef __cplusplus 201 } 202 #endif 203 204 #endif /* _KERNEL_VFS_H */ 205