1 /* 2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU) 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef FS_VNODE_H 13 #define FS_VNODE_H 14 15 #include <chcore/type.h> 16 #include <assert.h> 17 #include <sys/types.h> 18 #include <chcore/container/list.h> 19 #include <chcore/container/hashtable.h> 20 #include <chcore/container/rbtree.h> 21 22 #include "fs_page_cache.h" 23 #include "fs_wrapper_defs.h" 24 25 #define MAX_FILE_PAGES 512 26 #define MAX_SERVER_ENTRY_NUM 1024 27 28 enum fs_vnode_type { FS_NODE_RESERVED = 0, FS_NODE_REG, FS_NODE_DIR }; 29 30 /* 31 * per-inode 32 */ 33 #define PC_HASH_SIZE 512 34 struct fs_vnode { 35 ino_t vnode_id; /* identifier */ 36 struct rb_node node; /* rbtree node */ 37 38 enum fs_vnode_type type; /* regular or directory */ 39 int refcnt; /* reference count */ 40 off_t size; /* file size or directory entry number */ 41 struct page_cache_entity_of_inode *page_cache; 42 cap_t pmo_cap; /* fmap fault is handled by this */ 43 void *private; 44 45 pthread_rwlock_t rwlock; /* vnode rwlock */ 46 }; 47 48 /* 49 * per-fd 50 */ 51 struct server_entry { 52 /* `flags` and `offset` is assigned to each fd */ 53 int flags; 54 off_t offset; 55 int refcnt; 56 /* 57 * Different FS may use different struct to store path, 58 * normally `char*` 59 */ 60 void *path; 61 62 /* Entry lock */ 63 pthread_mutex_t lock; 64 65 /* Each vnode is binding with a disk inode */ 66 struct fs_vnode *vnode; 67 }; 68 69 extern struct server_entry *server_entrys[MAX_SERVER_ENTRY_NUM]; 70 71 extern bool using_page_cache; 72 73 extern void free_entry(int entry_idx); 74 extern int alloc_entry(void); 75 extern void assign_entry(struct server_entry *e, u64 f, off_t o, int t, void *p, 76 struct fs_vnode *n); 77 78 /* 79 * fs_vnode pool 80 * key: ino_t vnode_id 81 * value: struct fs_vnode *vnode 82 */ 83 extern struct rb_root *fs_vnode_list; 84 85 extern void fs_vnode_init(void); 86 extern struct fs_vnode *alloc_fs_vnode(ino_t id, enum fs_vnode_type type, 87 off_t size, void *private); 88 extern void push_fs_vnode(struct fs_vnode *n); 89 extern void pop_free_fs_vnode(struct fs_vnode *n); 90 extern struct fs_vnode *get_fs_vnode_by_id(ino_t vnode_id); 91 92 int inc_ref_fs_vnode(void *); 93 int dec_ref_fs_vnode(void *); 94 95 #endif /* FS_VNODE_H */