1 /* 2 ** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the Haiku 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 26 struct kernel_args; 27 struct file_descriptor; 28 struct selectsync; 29 struct pollfd; 30 31 32 /** The I/O context of a process/team, holds the fd array among others */ 33 typedef struct io_context { 34 struct vnode *cwd; 35 mutex io_mutex; 36 uint32 table_size; 37 uint32 num_used_fds; 38 struct file_descriptor **fds; 39 struct list node_monitors; 40 uint32 num_monitors; 41 uint32 max_monitors; 42 } io_context; 43 44 45 /* macro to allocate a iovec array on the stack */ 46 #define IOVECS(name, size) \ 47 uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \ 48 iovecs *name = (iovecs *)_##name 49 50 51 #ifdef __cplusplus 52 extern "C" { 53 #endif 54 55 status_t vfs_init(struct kernel_args *ka); 56 status_t vfs_bootstrap_file_systems(void); 57 status_t vfs_mount_boot_file_system(void); 58 void vfs_exec_io_context(void *context); 59 void *vfs_new_io_context(void *parentContext); 60 int vfs_free_io_context(void *context); 61 62 struct rlimit; 63 int vfs_getrlimit(int resource, struct rlimit * rlp); 64 int vfs_setrlimit(int resource, const struct rlimit * rlp); 65 66 /* calls needed by the VM for paging and by the file cache */ 67 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode); 68 status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode); 69 status_t vfs_get_vnode(mount_id mountID, vnode_id vnodeID, void **_vnode); 70 int vfs_put_vnode_ptr(void *vnode); 71 void vfs_vnode_acquire_ref(void *vnode); 72 void vfs_vnode_release_ref(void *vnode); 73 status_t vfs_get_cookie_from_fd(int fd, void **_cookie); 74 bool vfs_can_page(void *vnode, void *cookie); 75 status_t vfs_read_pages(void *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes); 76 status_t vfs_write_pages(void *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes); 77 status_t vfs_get_vnode_cache(void *vnode, void **_cache); 78 status_t vfs_get_file_map( void *_vnode, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count); 79 status_t vfs_get_fs_node_from_path(mount_id mountID, const char *path, bool kernel, void **_node); 80 81 /* special module convenience call */ 82 status_t vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuffer, size_t bufferSize); 83 84 /* service call for whoever needs a normalized path */ 85 status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize, 86 bool kernel); 87 88 /* calls the syscall dispatcher should use for user file I/O */ 89 status_t _user_mount(const char *path, const char *device, const char *fs_name, 90 uint32 flags, const char *args); 91 status_t _user_unmount(const char *path); 92 status_t _user_read_fs_info(dev_t device, struct fs_info *info); 93 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask); 94 dev_t _user_next_device(int32 *_cookie); 95 status_t _user_sync(void); 96 status_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf, 97 char *userPath, size_t pathLength); 98 int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode); 99 int _user_open(int fd, const char *path, int omode); 100 int _user_open_dir_node_ref(dev_t device, ino_t inode); 101 int _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname); 102 int _user_open_dir(int fd, const char *path); 103 int _user_open_parent_dir(int fd, char *name, size_t nameLength); 104 status_t _user_fcntl(int fd, int op, uint32 argument); 105 status_t _user_fsync(int fd); 106 status_t _user_read_stat(int fd, const char *path, bool traverseLink, 107 struct stat *stat, size_t statSize); 108 status_t _user_write_stat(int fd, const char *path, bool traverseLink, 109 const struct stat *stat, size_t statSize, int statMask); 110 off_t _user_seek(int fd, off_t pos, int seekType); 111 int _user_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms); 112 int _user_create(const char *path, int omode, int perms); 113 status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms); 114 status_t _user_create_dir(int fd, const char *path, int perms); 115 status_t _user_remove_dir(const char *path); 116 ssize_t _user_read_link(int fd, const char *path, char *buffer, size_t bufferSize); 117 status_t _user_write_link(const char *path, const char *toPath); 118 status_t _user_create_symlink(int fd, const char *path, const char *toPath, 119 int mode); 120 status_t _user_create_link(const char *path, const char *toPath); 121 status_t _user_unlink(int fd, const char *path); 122 status_t _user_rename(int oldFD, const char *oldpath, int newFD, 123 const char *newpath); 124 status_t _user_access(const char *path, int mode); 125 ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, 126 bigtime_t timeout, const sigset_t *sigMask); 127 ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 128 int _user_open_attr_dir(int fd, const char *path); 129 int _user_create_attr(int fd, const char *name, uint32 type, int openMode); 130 int _user_open_attr(int fd, const char *name, int openMode); 131 status_t _user_remove_attr(int fd, const char *name); 132 status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName); 133 int _user_open_index_dir(dev_t device); 134 status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags); 135 status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat); 136 status_t _user_remove_index(dev_t device, const char *name); 137 status_t _user_getcwd(char *buffer, size_t size); 138 status_t _user_setcwd(int fd, const char *path); 139 int _user_open_query(dev_t device, const char *query, uint32 flags, 140 port_id port, int32 token); 141 142 /* fd user prototypes (implementation located in fd.c) */ 143 extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize); 144 extern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count); 145 extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize); 146 extern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count); 147 extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length); 148 extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount); 149 extern status_t _user_rewind_dir(int fd); 150 extern status_t _user_close(int fd); 151 extern int _user_dup(int fd); 152 extern int _user_dup2(int ofd, int nfd); 153 extern status_t _user_lock_node(int fd); 154 extern status_t _user_unlock_node(int fd); 155 156 /* vfs entry points... */ 157 158 #ifdef __cplusplus 159 } 160 #endif 161 162 #endif /* _KERNEL_VFS_H */ 163