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