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