Changeset 8d049ee0 in mainline
- Timestamp:
- 2009-04-18T20:14:49Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c1eb69
- Parents:
- 594303b
- Location:
- uspace/srv/fs/tmpfs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs.c
r594303b r8d049ee0 128 128 { 129 129 printf(NAME ": HelenOS TMPFS file system server\n"); 130 130 131 if (!tmpfs_init()) { 132 printf(NAME ": failed to initialize TMPFS\n"); 133 return -1; 134 } 135 131 136 int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); 132 137 if (vfs_phone < EOK) { … … 141 146 return rc; 142 147 } 143 148 144 149 printf(NAME ": Accepting connections\n"); 145 150 async_manager(); -
uspace/srv/fs/tmpfs/tmpfs.h
r594303b r8d049ee0 53 53 typedef struct tmpfs_dentry { 54 54 fs_index_t index; /**< TMPFS node index. */ 55 dev_handle_t dev_handle;/**< Device handle. */ 55 56 link_t dh_link; /**< Dentries hash table link. */ 56 57 struct tmpfs_dentry *sibling; … … 66 67 67 68 extern libfs_ops_t tmpfs_libfs_ops; 69 70 extern bool tmpfs_init(void); 68 71 69 72 extern void tmpfs_mounted(ipc_callid_t, ipc_call_t *); -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r594303b r8d049ee0 59 59 #define NAMES_BUCKETS 4 60 60 61 /* 62 * For now, we don't distinguish between different dev_handles/instances. All 63 * requests resolve to the only instance, rooted in the following variable. 64 */ 65 static tmpfs_dentry_t *root; 66 67 #define TMPFS_DEV 0 /**< Dummy device handle for TMPFS */ 61 /** All root nodes have index 0. */ 62 #define TMPFS_SOME_ROOT 0 63 /** Global counter for assigning node indices. Shared by all instances. */ 64 fs_index_t tmpfs_next_index = 1; 68 65 69 66 /* … … 103 100 static void *tmpfs_root_get(dev_handle_t dev_handle) 104 101 { 105 return root;102 return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT); 106 103 } 107 104 … … 143 140 hash_table_t dentries; 144 141 142 #define DENTRIES_KEY_INDEX 0 143 #define DENTRIES_KEY_DEV 1 144 145 145 /* Implementation of hash table interface for the dentries hash table. */ 146 static hash_index_t dentries_hash(unsigned long *key)147 { 148 return *key% DENTRIES_BUCKETS;149 } 150 151 static int dentries_compare(unsigned long *key, hash_count_t keys,146 static hash_index_t dentries_hash(unsigned long key[]) 147 { 148 return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS; 149 } 150 151 static int dentries_compare(unsigned long key[], hash_count_t keys, 152 152 link_t *item) 153 153 { 154 154 tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t, 155 155 dh_link); 156 return dentry->index == *key; 156 return (dentry->index == key[DENTRIES_KEY_INDEX] && 157 dentry->dev_handle == key[DENTRIES_KEY_DEV]); 157 158 } 158 159 … … 168 169 }; 169 170 170 fs_index_t tmpfs_next_index = 1;171 172 171 typedef struct { 173 172 char *name; … … 216 215 { 217 216 dentry->index = 0; 217 dentry->dev_handle = 0; 218 218 dentry->sibling = NULL; 219 219 dentry->child = NULL; … … 227 227 } 228 228 229 staticbool tmpfs_init(void)230 { 231 if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))229 bool tmpfs_init(void) 230 { 231 if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 2, &dentries_ops)) 232 232 return false; 233 root = (tmpfs_dentry_t *) tmpfs_create_node(TMPFS_DEV, L_DIRECTORY); 234 if (!root) { 235 hash_table_destroy(&dentries); 233 234 return true; 235 } 236 237 static bool tmpfs_instance_init(dev_handle_t dev_handle) 238 { 239 tmpfs_dentry_t *root; 240 241 root = (tmpfs_dentry_t *) tmpfs_create_node(dev_handle, L_DIRECTORY); 242 if (!root) 236 243 return false; 237 }238 244 root->lnkcnt = 0; /* FS root is not linked */ 239 245 return true; … … 273 279 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 274 280 { 275 unsigned long key = index; 276 link_t *lnk = hash_table_find(&dentries, &key); 281 unsigned long key[] = { 282 [DENTRIES_KEY_INDEX] = index, 283 [DENTRIES_KEY_DEV] = dev_handle 284 }; 285 link_t *lnk = hash_table_find(&dentries, key); 277 286 if (!lnk) 278 287 return NULL; … … 297 306 return NULL; 298 307 } 299 node->index = tmpfs_next_index++; 308 if (!tmpfs_root_get(dev_handle)) 309 node->index = TMPFS_SOME_ROOT; 310 else 311 node->index = tmpfs_next_index++; 312 node->dev_handle = dev_handle; 300 313 if (lflag & L_DIRECTORY) 301 314 node->type = TMPFS_DIRECTORY; … … 304 317 305 318 /* Insert the new node into the dentry hash table. */ 306 unsigned long key = node->index; 307 hash_table_insert(&dentries, &key, &node->dh_link); 319 unsigned long key[] = { 320 [DENTRIES_KEY_INDEX] = node->index, 321 [DENTRIES_KEY_DEV] = node->dev_handle 322 }; 323 hash_table_insert(&dentries, key, &node->dh_link); 308 324 return (void *) node; 309 325 } … … 385 401 assert(!dentry->sibling); 386 402 387 unsigned long key = dentry->index; 388 hash_table_remove(&dentries, &key, 1); 403 unsigned long key[] = { 404 [DENTRIES_KEY_INDEX] = dentry->index, 405 [DENTRIES_KEY_DEV] = dentry->dev_handle 406 }; 407 hash_table_remove(&dentries, key, 2); 389 408 390 409 hash_table_destroy(&dentry->names); … … 422 441 opts[size] = '\0'; 423 442 424 /* Initialize TMPFS . */425 if (! root && !tmpfs_init()) {443 /* Initialize TMPFS instance. */ 444 if (!tmpfs_instance_init(dev_handle)) { 426 445 ipc_answer_0(rid, ENOMEM); 427 446 return; 428 447 } 429 448 449 tmpfs_dentry_t *root = tmpfs_root_get(dev_handle); 430 450 if (str_cmp(opts, "restore") == 0) { 431 451 if (tmpfs_restore(dev_handle)) … … 464 484 */ 465 485 link_t *hlp; 466 unsigned long key = index; 467 hlp = hash_table_find(&dentries, &key); 486 unsigned long key[] = { 487 [DENTRIES_KEY_INDEX] = index, 488 [DENTRIES_KEY_DEV] = dev_handle, 489 }; 490 hlp = hash_table_find(&dentries, key); 468 491 if (!hlp) { 469 492 ipc_answer_0(rid, ENOENT); … … 537 560 */ 538 561 link_t *hlp; 539 unsigned long key = index; 540 hlp = hash_table_find(&dentries, &key); 562 unsigned long key[] = { 563 [DENTRIES_KEY_INDEX] = index, 564 [DENTRIES_KEY_DEV] = dev_handle 565 }; 566 hlp = hash_table_find(&dentries, key); 541 567 if (!hlp) { 542 568 ipc_answer_0(rid, ENOENT); … … 598 624 */ 599 625 link_t *hlp; 600 unsigned long key = index; 601 hlp = hash_table_find(&dentries, &key); 626 unsigned long key[] = { 627 [DENTRIES_KEY_INDEX] = index, 628 [DENTRIES_KEY_DEV] = dev_handle 629 }; 630 hlp = hash_table_find(&dentries, key); 602 631 if (!hlp) { 603 632 ipc_answer_0(rid, ENOENT); … … 633 662 634 663 link_t *hlp; 635 unsigned long key = index; 636 hlp = hash_table_find(&dentries, &key); 664 unsigned long key[] = { 665 [DENTRIES_KEY_INDEX] = index, 666 [DENTRIES_KEY_DEV] = dev_handle 667 }; 668 hlp = hash_table_find(&dentries, key); 637 669 if (!hlp) { 638 670 ipc_answer_0(rid, ENOENT);
Note:
See TracChangeset
for help on using the changeset viewer.