Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [0da4e41:75160a6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
r0da4e41 r75160a6 67 67 68 68 /* Forward declarations of static functions. */ 69 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 70 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t); 71 static int tmpfs_node_put(fs_node_t *); 72 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); 73 static int tmpfs_destroy_node(fs_node_t *); 69 static fs_node_t *tmpfs_match(fs_node_t *, const char *); 70 static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t); 71 static void tmpfs_node_put(fs_node_t *); 72 static fs_node_t *tmpfs_create_node(dev_handle_t, int); 74 73 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); 75 74 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *); 75 static int tmpfs_destroy_node(fs_node_t *); 76 76 77 77 /* Implementation of helper functions. */ 78 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle)79 {80 return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT);81 }82 83 static int tmpfs_has_children(bool *has_children, fs_node_t *fn)84 {85 *has_children = !list_empty(&TMPFS_NODE(fn)->cs_head);86 return EOK;87 }88 89 78 static fs_index_t tmpfs_index_get(fs_node_t *fn) 90 79 { … … 100 89 { 101 90 return TMPFS_NODE(fn)->lnkcnt; 91 } 92 93 static bool tmpfs_has_children(fs_node_t *fn) 94 { 95 return !list_empty(&TMPFS_NODE(fn)->cs_head); 96 } 97 98 static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle) 99 { 100 return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT); 102 101 } 103 102 … … 119 118 /** libfs operations */ 120 119 libfs_ops_t tmpfs_libfs_ops = { 121 .root_get = tmpfs_root_get,122 120 .match = tmpfs_match, 123 121 .node_get = tmpfs_node_get, … … 127 125 .link = tmpfs_link_node, 128 126 .unlink = tmpfs_unlink_node, 129 .has_children = tmpfs_has_children,130 127 .index_get = tmpfs_index_get, 131 128 .size_get = tmpfs_size_get, 132 129 .lnkcnt_get = tmpfs_lnkcnt_get, 130 .has_children = tmpfs_has_children, 131 .root_get = tmpfs_root_get, 133 132 .plb_get_char = tmpfs_plb_get_char, 134 133 .is_directory = tmpfs_is_directory, … … 198 197 { 199 198 fs_node_t *rfn; 200 int rc;201 199 202 r c = tmpfs_create_node(&rfn,dev_handle, L_DIRECTORY);203 if ( rc != EOK || !rfn)200 rfn = tmpfs_create_node(dev_handle, L_DIRECTORY); 201 if (!rfn) 204 202 return false; 205 203 TMPFS_NODE(rfn)->lnkcnt = 0; /* FS root is not linked */ … … 207 205 } 208 206 209 int tmpfs_match(fs_node_t **rfn,fs_node_t *pfn, const char *component)207 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component) 210 208 { 211 209 tmpfs_node_t *parentp = TMPFS_NODE(pfn); … … 214 212 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 215 213 lnk = lnk->next) { 216 tmpfs_dentry_t *dentryp; 217 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 218 if (!str_cmp(dentryp->name, component)) { 219 *rfn = FS_NODE(dentryp->node); 220 return EOK; 221 } 222 } 223 224 *rfn = NULL; 225 return EOK; 226 } 227 228 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 214 tmpfs_dentry_t *dentryp = list_get_instance(lnk, tmpfs_dentry_t, 215 link); 216 if (!str_cmp(dentryp->name, component)) 217 return FS_NODE(dentryp->node); 218 } 219 220 return NULL; 221 } 222 223 fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 229 224 { 230 225 unsigned long key[] = { … … 233 228 }; 234 229 link_t *lnk = hash_table_find(&nodes, key); 235 if (lnk) { 236 tmpfs_node_t *nodep; 237 nodep = hash_table_get_instance(lnk, tmpfs_node_t, nh_link); 238 *rfn = FS_NODE(nodep); 239 } else { 240 *rfn = NULL; 241 } 242 return EOK; 243 } 244 245 int tmpfs_node_put(fs_node_t *fn) 230 if (!lnk) 231 return NULL; 232 return FS_NODE(hash_table_get_instance(lnk, tmpfs_node_t, nh_link)); 233 } 234 235 void tmpfs_node_put(fs_node_t *fn) 246 236 { 247 237 /* nothing to do */ 248 return EOK; 249 } 250 251 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 252 { 253 fs_node_t *rootfn; 254 int rc; 255 238 } 239 240 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag) 241 { 256 242 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 257 243 258 244 tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t)); 259 245 if (!nodep) 260 return ENOMEM;246 return NULL; 261 247 tmpfs_node_initialize(nodep); 262 248 nodep->bp = malloc(sizeof(fs_node_t)); 263 249 if (!nodep->bp) { 264 250 free(nodep); 265 return ENOMEM;251 return NULL; 266 252 } 267 253 fs_node_initialize(nodep->bp); 268 254 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 269 270 rc = tmpfs_root_get(&rootfn, dev_handle); 271 assert(rc == EOK); 272 if (!rootfn) 255 if (!tmpfs_root_get(dev_handle)) 273 256 nodep->index = TMPFS_SOME_ROOT; 274 257 else … … 286 269 }; 287 270 hash_table_insert(&nodes, key, &nodep->nh_link); 288 *rfn = FS_NODE(nodep); 289 return EOK; 290 } 291 292 int tmpfs_destroy_node(fs_node_t *fn) 293 { 294 tmpfs_node_t *nodep = TMPFS_NODE(fn); 295 296 assert(!nodep->lnkcnt); 297 assert(list_empty(&nodep->cs_head)); 298 299 unsigned long key[] = { 300 [NODES_KEY_INDEX] = nodep->index, 301 [NODES_KEY_DEV] = nodep->dev_handle 302 }; 303 hash_table_remove(&nodes, key, 2); 304 305 if (nodep->type == TMPFS_FILE) 306 free(nodep->data); 307 free(nodep->bp); 308 free(nodep); 309 return EOK; 271 return FS_NODE(nodep); 310 272 } 311 273 … … 381 343 } 382 344 345 int tmpfs_destroy_node(fs_node_t *fn) 346 { 347 tmpfs_node_t *nodep = TMPFS_NODE(fn); 348 349 assert(!nodep->lnkcnt); 350 assert(list_empty(&nodep->cs_head)); 351 352 unsigned long key[] = { 353 [NODES_KEY_INDEX] = nodep->index, 354 [NODES_KEY_DEV] = nodep->dev_handle 355 }; 356 hash_table_remove(&nodes, key, 2); 357 358 if (nodep->type == TMPFS_FILE) 359 free(nodep->data); 360 free(nodep->bp); 361 free(nodep); 362 return EOK; 363 } 364 383 365 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 384 366 { 385 367 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 386 int rc;387 368 388 369 /* accept the mount options */ 389 370 ipc_callid_t callid; 390 371 size_t size; 391 if (! async_data_write_receive(&callid, &size)) {372 if (!ipc_data_write_receive(&callid, &size)) { 392 373 ipc_answer_0(callid, EINVAL); 393 374 ipc_answer_0(rid, EINVAL); … … 400 381 return; 401 382 } 402 ipcarg_t retval = async_data_write_finalize(callid, opts, size);383 ipcarg_t retval = ipc_data_write_finalize(callid, opts, size); 403 384 if (retval != EOK) { 404 385 ipc_answer_0(rid, retval); … … 414 395 } 415 396 416 fs_node_t *rootfn; 417 rc = tmpfs_root_get(&rootfn, dev_handle); 418 assert(rc == EOK); 419 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 397 tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle)); 420 398 if (str_cmp(opts, "restore") == 0) { 421 399 if (tmpfs_restore(dev_handle)) … … 467 445 ipc_callid_t callid; 468 446 size_t size; 469 if (! async_data_read_receive(&callid, &size)) {447 if (!ipc_data_read_receive(&callid, &size)) { 470 448 ipc_answer_0(callid, EINVAL); 471 449 ipc_answer_0(rid, EINVAL); … … 476 454 if (nodep->type == TMPFS_FILE) { 477 455 bytes = max(0, min(nodep->size - pos, size)); 478 (void) async_data_read_finalize(callid, nodep->data + pos,456 (void) ipc_data_read_finalize(callid, nodep->data + pos, 479 457 bytes); 480 458 } else { … … 503 481 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 504 482 505 (void) async_data_read_finalize(callid, dentryp->name,483 (void) ipc_data_read_finalize(callid, dentryp->name, 506 484 str_size(dentryp->name) + 1); 507 485 bytes = 1; … … 541 519 ipc_callid_t callid; 542 520 size_t size; 543 if (! async_data_write_receive(&callid, &size)) {521 if (!ipc_data_write_receive(&callid, &size)) { 544 522 ipc_answer_0(callid, EINVAL); 545 523 ipc_answer_0(rid, EINVAL); … … 552 530 if (pos + size <= nodep->size) { 553 531 /* The file size is not changing. */ 554 (void) async_data_write_finalize(callid, nodep->data + pos, size);532 (void) ipc_data_write_finalize(callid, nodep->data + pos, size); 555 533 ipc_answer_2(rid, EOK, size, nodep->size); 556 534 return; … … 574 552 nodep->size += delta; 575 553 nodep->data = newdata; 576 (void) async_data_write_finalize(callid, nodep->data + pos, size);554 (void) ipc_data_write_finalize(callid, nodep->data + pos, size); 577 555 ipc_answer_2(rid, EOK, size, nodep->size); 578 556 }
Note:
See TracChangeset
for help on using the changeset viewer.