Changeset b6035ba in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2009-05-05T22:09:13Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 770d281
- Parents:
- c852f4be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rc852f4be rb6035ba 69 69 70 70 /* Forward declarations of static functions. */ 71 static void *tmpfs_match(void*, const char *);72 static void*tmpfs_node_get(dev_handle_t, fs_index_t);73 static void tmpfs_node_put( void*);74 static void*tmpfs_create_node(dev_handle_t, int);75 static int tmpfs_link_node( void *, void*, const char *);76 static int tmpfs_unlink_node( void *, void*);77 static int tmpfs_destroy_node( void*);71 static fs_node_t *tmpfs_match(fs_node_t *, const char *); 72 static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t); 73 static void tmpfs_node_put(fs_node_t *); 74 static fs_node_t *tmpfs_create_node(dev_handle_t, int); 75 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); 76 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *); 77 static int tmpfs_destroy_node(fs_node_t *); 78 78 79 79 /* Implementation of helper functions. */ 80 static fs_index_t tmpfs_index_get( void *nodep)81 { 82 return ((tmpfs_dentry_t *) nodep)->index;83 } 84 85 static size_t tmpfs_size_get( void *nodep)86 { 87 return ((tmpfs_dentry_t *) nodep)->size;88 } 89 90 static unsigned tmpfs_lnkcnt_get( void *nodep)91 { 92 return ((tmpfs_dentry_t *) nodep)->lnkcnt;93 } 94 95 static bool tmpfs_has_children( void *nodep)96 { 97 return ((tmpfs_dentry_t *) nodep)->child != NULL;98 } 99 100 static void*tmpfs_root_get(dev_handle_t dev_handle)80 static fs_index_t tmpfs_index_get(fs_node_t *fn) 81 { 82 return TMPFS_NODE(fn)->index; 83 } 84 85 static size_t tmpfs_size_get(fs_node_t *fn) 86 { 87 return TMPFS_NODE(fn)->size; 88 } 89 90 static unsigned tmpfs_lnkcnt_get(fs_node_t *fn) 91 { 92 return TMPFS_NODE(fn)->lnkcnt; 93 } 94 95 static bool tmpfs_has_children(fs_node_t *fn) 96 { 97 return TMPFS_NODE(fn)->child != NULL; 98 } 99 100 static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle) 101 101 { 102 102 return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT); … … 108 108 } 109 109 110 static bool tmpfs_is_directory( void *nodep)111 { 112 return ((tmpfs_dentry_t *) nodep)->type == TMPFS_DIRECTORY;113 } 114 115 static bool tmpfs_is_file( void *nodep)116 { 117 return ((tmpfs_dentry_t *) nodep)->type == TMPFS_FILE;110 static bool tmpfs_is_directory(fs_node_t *fn) 111 { 112 return TMPFS_NODE(fn)->type == TMPFS_DIRECTORY; 113 } 114 115 static bool tmpfs_is_file(fs_node_t *fn) 116 { 117 return TMPFS_NODE(fn)->type == TMPFS_FILE; 118 118 } 119 119 … … 214 214 static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry) 215 215 { 216 dentry->bp = NULL; 216 217 dentry->index = 0; 217 218 dentry->dev_handle = 0; … … 237 238 static bool tmpfs_instance_init(dev_handle_t dev_handle) 238 239 { 239 tmpfs_dentry_t *root;240 fs_node_t *rfn; 240 241 241 r oot = (tmpfs_dentry_t *)tmpfs_create_node(dev_handle, L_DIRECTORY);242 if (!r oot)242 rfn = tmpfs_create_node(dev_handle, L_DIRECTORY); 243 if (!rfn) 243 244 return false; 244 root->lnkcnt = 0; /* FS root is not linked */245 TMPFS_NODE(rfn)->lnkcnt = 0; /* FS root is not linked */ 245 246 return true; 246 247 } … … 265 266 } 266 267 267 void *tmpfs_match(void *prnt, const char *component)268 { 269 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;268 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component) 269 { 270 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 270 271 tmpfs_dentry_t *childp = parentp->child; 271 272 … … 273 274 childp = childp->sibling; 274 275 275 return (void *) childp; 276 } 277 278 void * 279 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 276 return FS_NODE(childp); 277 } 278 279 fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 280 280 { 281 281 unsigned long key[] = { … … 286 286 if (!lnk) 287 287 return NULL; 288 return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link);289 } 290 291 void tmpfs_node_put( void *node)288 return FS_NODE(hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link)); 289 } 290 291 void tmpfs_node_put(fs_node_t *fn) 292 292 { 293 293 /* nothing to do */ 294 294 } 295 295 296 void*tmpfs_create_node(dev_handle_t dev_handle, int lflag)296 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag) 297 297 { 298 298 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 299 299 300 fs_node_t *fn = malloc(sizeof(fs_node_t)); 301 if (!fn) 302 return NULL; 303 300 304 tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); 301 if (!node) 305 if (!node) { 306 free(fn); 302 307 return NULL; 303 308 } 304 309 if (!tmpfs_dentry_initialize(node)) { 310 free(fn); 305 311 free(node); 306 312 return NULL; 307 313 } 314 fn->data = node; 315 node->bp = fn; /* establish the back pointer */ 308 316 if (!tmpfs_root_get(dev_handle)) 309 317 node->index = TMPFS_SOME_ROOT; … … 322 330 }; 323 331 hash_table_insert(&dentries, key, &node->dh_link); 324 return (void *) node;325 } 326 327 int tmpfs_link_node( void *prnt, void *chld, const char *nm)328 { 329 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;330 tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;332 return fn; 333 } 334 335 int tmpfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 336 { 337 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 338 tmpfs_dentry_t *childp = TMPFS_NODE(cfn); 331 339 332 340 assert(parentp->type == TMPFS_DIRECTORY); … … 363 371 } 364 372 365 int tmpfs_unlink_node( void *prnt, void *chld)366 { 367 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;368 tmpfs_dentry_t *childp = (tmpfs_dentry_t *)chld;373 int tmpfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn) 374 { 375 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 376 tmpfs_dentry_t *childp = TMPFS_NODE(cfn); 369 377 370 378 if (!parentp) … … 393 401 } 394 402 395 int tmpfs_destroy_node( void *nodep)396 { 397 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;403 int tmpfs_destroy_node(fs_node_t *fn) 404 { 405 tmpfs_dentry_t *dentry = TMPFS_NODE(fn); 398 406 399 407 assert(!dentry->lnkcnt); … … 411 419 if (dentry->type == TMPFS_FILE) 412 420 free(dentry->data); 421 free(dentry->bp); 413 422 free(dentry); 414 423 return EOK; … … 447 456 } 448 457 449 tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);458 tmpfs_dentry_t *root = TMPFS_NODE(tmpfs_root_get(dev_handle)); 450 459 if (str_cmp(opts, "restore") == 0) { 451 460 if (tmpfs_restore(dev_handle)) … … 673 682 tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, 674 683 dh_link); 675 rc = tmpfs_destroy_node( dentry);684 rc = tmpfs_destroy_node(FS_NODE(dentry)); 676 685 ipc_answer_0(rid, rc); 677 686 }
Note:
See TracChangeset
for help on using the changeset viewer.