1 /* 2 * Copyright 2002-2008, 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 _FSSH_VFS_H 9 #define _FSSH_VFS_H 10 11 12 #include "fssh_fs_interface.h" 13 #include "fssh_lock.h" 14 #include "list.h" 15 16 17 namespace FSShell { 18 19 20 /* R5 figures, but we don't use a table for monitors anyway */ 21 #define DEFAULT_FD_TABLE_SIZE 128 22 #define MAX_FD_TABLE_SIZE 8192 23 #define DEFAULT_NODE_MONITORS 4096 24 #define MAX_NODE_MONITORS 65536 25 26 struct kernel_args; 27 struct vm_cache_ref; 28 struct file_descriptor; 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 fssh_mutex io_mutex; 35 uint32_t table_size; 36 uint32_t num_used_fds; 37 struct file_descriptor **fds; 38 uint8_t *fds_close_on_exec; 39 } io_context; 40 41 struct fd_info { 42 int number; 43 int32_t open_mode; 44 fssh_dev_t device; 45 fssh_ino_t node; 46 }; 47 48 /* macro to allocate a iovec array on the stack */ 49 #define IOVECS(name, size) \ 50 uint8_t _##name[sizeof(fssh_iovecs) + (size)*sizeof(fssh_iovec)]; \ 51 fssh_iovecs *name = (fssh_iovecs *)_##name 52 53 54 fssh_status_t vfs_init(struct kernel_args *args); 55 fssh_status_t vfs_bootstrap_file_systems(void); 56 void vfs_mount_boot_file_system(struct kernel_args *args); 57 void vfs_exec_io_context(void *context); 58 void* vfs_new_io_context(void *parentContext); 59 fssh_status_t vfs_free_io_context(void *context); 60 61 /* calls needed by the VM for paging and by the file cache */ 62 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode); 63 fssh_status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode); 64 fssh_status_t vfs_get_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID, 65 void **_vnode); 66 fssh_status_t vfs_entry_ref_to_vnode(fssh_mount_id mountID, 67 fssh_vnode_id directoryID, const char *name, void **_vnode); 68 void vfs_vnode_to_node_ref(void *_vnode, fssh_mount_id *_mountID, 69 fssh_vnode_id *_vnodeID); 70 71 fssh_status_t vfs_lookup_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID, 72 void **_vnode); 73 void vfs_put_vnode(void *vnode); 74 void vfs_acquire_vnode(void *vnode); 75 fssh_status_t vfs_get_cookie_from_fd(int fd, void **_cookie); 76 fssh_status_t vfs_read_pages(void *vnode, void *cookie, fssh_off_t pos, 77 const fssh_iovec *vecs, fssh_size_t count, 78 fssh_size_t *_numBytes); 79 fssh_status_t vfs_write_pages(void *vnode, void *cookie, 80 fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count, 81 fssh_size_t *_numBytes); 82 fssh_status_t vfs_get_file_map(void *_vnode, fssh_off_t offset, 83 fssh_size_t size, fssh_file_io_vec *vecs, 84 fssh_size_t *_count); 85 fssh_status_t vfs_get_fs_node_from_path(fssh_mount_id mountID, 86 const char *path, bool kernel, void **_node); 87 fssh_status_t vfs_stat_vnode(void *_vnode, struct fssh_stat *stat); 88 fssh_status_t vfs_get_vnode_name(void *vnode, char *name, 89 fssh_size_t nameSize); 90 fssh_status_t vfs_get_cwd(fssh_mount_id *_mountID, fssh_vnode_id *_vnodeID); 91 void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor); 92 fssh_status_t vfs_disconnect_vnode(fssh_mount_id mountID, 93 fssh_vnode_id vnodeID); 94 void vfs_free_unused_vnodes(int32_t level); 95 96 /* special module convenience call */ 97 fssh_status_t vfs_get_module_path(const char *basePath, 98 const char *moduleName, char *pathBuffer, 99 fssh_size_t bufferSize); 100 101 /* service call for whoever needs a normalized path */ 102 fssh_status_t vfs_normalize_path(const char *path, char *buffer, 103 fssh_size_t bufferSize, bool kernel); 104 105 /* service call for the node monitor */ 106 fssh_status_t resolve_mount_point_to_volume_root(fssh_mount_id mountID, 107 fssh_vnode_id nodeID, fssh_mount_id *resolvedMountID, 108 fssh_vnode_id *resolvedNodeID); 109 110 // cache initialization functions defined in the respective cache implementation 111 extern fssh_status_t block_cache_init(); 112 extern fssh_status_t file_cache_init(); 113 114 } // namespace FSShell 115 116 117 #endif /* _FSSH_VFS_H */ 118