Changeset b818cff in mainline
- Timestamp:
- 2007-11-06T17:26:28Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44358c1
- Parents:
- 6537572
- Location:
- uspace/srv/vfs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs.c
r6537572 rb818cff 125 125 126 126 /* 127 * Initialize VFS node hash table. 128 */ 129 if (!vfs_nodes_init()) { 130 printf("Failed to initialize the VFS node hash table.\n"); 131 return ENOMEM; 132 } 133 134 /* 127 135 * Allocate and initialize the Path Lookup Buffer. 128 136 */ -
uspace/srv/vfs/vfs.h
r6537572 rb818cff 179 179 extern int vfs_lookup_internal(char *, size_t, vfs_triplet_t *, vfs_pair_t *); 180 180 181 181 extern bool vfs_nodes_init(void); 182 182 extern vfs_node_t *vfs_node_get(vfs_triplet_t *); 183 183 extern void vfs_node_put(vfs_node_t *); 184 185 #define MAX_OPEN_FILES 128 184 186 185 187 extern bool vfs_files_init(void); … … 194 196 extern void vfs_node_delref(vfs_node_t *); 195 197 196 #define MAX_OPEN_FILES 128197 198 198 extern void vfs_register(ipc_callid_t, ipc_call_t *); 199 199 extern void vfs_mount(ipc_callid_t, ipc_call_t *); -
uspace/srv/vfs/vfs_node.c
r6537572 rb818cff 37 37 38 38 #include "vfs.h" 39 #include <stdlib.h> 40 #include <string.h> 41 #include <atomic.h> 42 #include <futex.h> 43 #include <libadt/hash_table.h> 44 45 /** Futex protecting the VFS node hash table. */ 46 atomic_t nodes_futex = FUTEX_INITIALIZER; 47 48 #define NODES_BUCKETS_LOG 8 49 #define NODES_BUCKETS (1 << NODES_BUCKETS_LOG) 50 51 /** VFS node hash table containing all active, in-memory VFS nodes. */ 52 hash_table_t nodes; 53 54 #define KEY_FS_HANDLE 0 55 #define KEY_DEV_HANDLE 1 56 #define KEY_INDEX 2 57 58 static hash_index_t nodes_hash(unsigned long []); 59 static int nodes_compare(unsigned long [], hash_count_t, link_t *); 60 static void nodes_remove_callback(link_t *); 61 62 /** VFS node hash table operations. */ 63 hash_table_operations_t nodes_ops = { 64 .hash = nodes_hash, 65 .compare = nodes_compare, 66 .remove_callback = nodes_remove_callback 67 }; 68 69 /** Initialize the VFS node hash table. 70 * 71 * @return Return true on success, false on failure. 72 */ 73 bool vfs_nodes_init(void) 74 { 75 return hash_table_create(&nodes, NODES_BUCKETS, 3, &nodes_ops); 76 } 77 78 static inline void _vfs_node_addref(vfs_node_t *node) 79 { 80 node->refcnt++; 81 } 39 82 40 83 /** Increment reference count of a VFS node. … … 44 87 void vfs_node_addref(vfs_node_t *node) 45 88 { 46 /* TODO */ 89 futex_down(&nodes_futex); 90 _vfs_node_addref(node); 91 futex_up(&nodes_futex); 47 92 } 48 93 … … 55 100 void vfs_node_delref(vfs_node_t *node) 56 101 { 57 /* TODO */ 102 futex_down(&nodes_futex); 103 if (node->refcnt-- == 1) { 104 unsigned long key[] = { 105 [KEY_FS_HANDLE] = node->fs_handle, 106 [KEY_DEV_HANDLE] = node->dev_handle, 107 [KEY_INDEX] = node->index 108 }; 109 hash_table_remove(&nodes, key, 3); 110 } 111 futex_up(&nodes_futex); 58 112 } 59 113 … … 72 126 vfs_node_t *vfs_node_get(vfs_triplet_t *triplet) 73 127 { 74 /* TODO */ 75 return NULL; 128 unsigned long key[] = { 129 [KEY_FS_HANDLE] = triplet->fs_handle, 130 [KEY_DEV_HANDLE] = triplet->dev_handle, 131 [KEY_INDEX] = triplet->index 132 }; 133 link_t *tmp; 134 vfs_node_t *node; 135 136 futex_down(&nodes_futex); 137 tmp = hash_table_find(&nodes, key); 138 if (!tmp) { 139 node = (vfs_node_t *) malloc(sizeof(vfs_node_t)); 140 if (!node) { 141 futex_up(&nodes_futex); 142 return NULL; 143 } 144 memset(node, 0, sizeof(vfs_node_t)); 145 node->fs_handle = triplet->fs_handle; 146 node->dev_handle = triplet->fs_handle; 147 node->index = triplet->index; 148 link_initialize(&node->nh_link); 149 hash_table_insert(&nodes, key, &node->nh_link); 150 } else { 151 node = hash_table_get_instance(tmp, vfs_node_t, nh_link); 152 } 153 _vfs_node_addref(node); 154 futex_up(&nodes_futex); 155 156 return node; 76 157 } 77 158 … … 89 170 } 90 171 172 hash_index_t nodes_hash(unsigned long key[]) 173 { 174 hash_index_t a = key[KEY_FS_HANDLE] << (NODES_BUCKETS_LOG / 4); 175 hash_index_t b = (a | key[KEY_DEV_HANDLE]) << (NODES_BUCKETS_LOG / 2); 176 177 return (b | key[KEY_INDEX]) & ~(NODES_BUCKETS - 1); 178 } 179 180 int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item) 181 { 182 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link); 183 return (node->fs_handle == key[KEY_FS_HANDLE]) && 184 (node->dev_handle == key[KEY_DEV_HANDLE]) && 185 (node->index == key[KEY_INDEX]); 186 } 187 188 void nodes_remove_callback(link_t *item) 189 { 190 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link); 191 free(node); 192 } 193 91 194 /** 92 195 * @}
Note:
See TracChangeset
for help on using the changeset viewer.