Changes in uspace/srv/fs/tmpfs/tmpfs_ops.c [75160a6:1313ee9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
r75160a6 r1313ee9 67 67 68 68 /* Forward declarations of static functions. */ 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); 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_open(fs_node_t *); 72 static int tmpfs_node_put(fs_node_t *); 73 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); 74 static int tmpfs_destroy_node(fs_node_t *); 73 75 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); 74 76 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *); 75 static int tmpfs_destroy_node(fs_node_t *);76 77 77 78 /* Implementation of helper functions. */ 79 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle) 80 { 81 return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT); 82 } 83 84 static int tmpfs_has_children(bool *has_children, fs_node_t *fn) 85 { 86 *has_children = !list_empty(&TMPFS_NODE(fn)->cs_head); 87 return EOK; 88 } 89 78 90 static fs_index_t tmpfs_index_get(fs_node_t *fn) 79 91 { … … 91 103 } 92 104 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);101 }102 103 105 static char tmpfs_plb_get_char(unsigned pos) 104 106 { … … 114 116 { 115 117 return TMPFS_NODE(fn)->type == TMPFS_FILE; 118 } 119 120 static dev_handle_t tmpfs_device_get(fs_node_t *fn) 121 { 122 return 0; 116 123 } 117 124 118 125 /** libfs operations */ 119 126 libfs_ops_t tmpfs_libfs_ops = { 127 .root_get = tmpfs_root_get, 120 128 .match = tmpfs_match, 121 129 .node_get = tmpfs_node_get, 130 .node_open = tmpfs_node_open, 122 131 .node_put = tmpfs_node_put, 123 132 .create = tmpfs_create_node, … … 125 134 .link = tmpfs_link_node, 126 135 .unlink = tmpfs_unlink_node, 136 .has_children = tmpfs_has_children, 127 137 .index_get = tmpfs_index_get, 128 138 .size_get = tmpfs_size_get, 129 139 .lnkcnt_get = tmpfs_lnkcnt_get, 130 .has_children = tmpfs_has_children,131 .root_get = tmpfs_root_get,132 140 .plb_get_char = tmpfs_plb_get_char, 133 141 .is_directory = tmpfs_is_directory, 134 .is_file = tmpfs_is_file 142 .is_file = tmpfs_is_file, 143 .device_get = tmpfs_device_get 135 144 }; 136 145 … … 197 206 { 198 207 fs_node_t *rfn; 208 int rc; 199 209 200 r fn = tmpfs_create_node(dev_handle, L_DIRECTORY);201 if ( !rfn)210 rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY); 211 if (rc != EOK || !rfn) 202 212 return false; 203 213 TMPFS_NODE(rfn)->lnkcnt = 0; /* FS root is not linked */ … … 205 215 } 206 216 207 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component)217 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 208 218 { 209 219 tmpfs_node_t *parentp = TMPFS_NODE(pfn); … … 212 222 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 213 223 lnk = lnk->next) { 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) 224 tmpfs_dentry_t *dentryp; 225 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 226 if (!str_cmp(dentryp->name, component)) { 227 *rfn = FS_NODE(dentryp->node); 228 return EOK; 229 } 230 } 231 232 *rfn = NULL; 233 return EOK; 234 } 235 236 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 224 237 { 225 238 unsigned long key[] = { … … 228 241 }; 229 242 link_t *lnk = hash_table_find(&nodes, key); 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) 243 if (lnk) { 244 tmpfs_node_t *nodep; 245 nodep = hash_table_get_instance(lnk, tmpfs_node_t, nh_link); 246 *rfn = FS_NODE(nodep); 247 } else { 248 *rfn = NULL; 249 } 250 return EOK; 251 } 252 253 int tmpfs_node_open(fs_node_t *fn) 236 254 { 237 255 /* nothing to do */ 238 } 239 240 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag) 241 { 256 return EOK; 257 } 258 259 int tmpfs_node_put(fs_node_t *fn) 260 { 261 /* nothing to do */ 262 return EOK; 263 } 264 265 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 266 { 267 fs_node_t *rootfn; 268 int rc; 269 242 270 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 243 271 244 272 tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t)); 245 273 if (!nodep) 246 return NULL;274 return ENOMEM; 247 275 tmpfs_node_initialize(nodep); 248 276 nodep->bp = malloc(sizeof(fs_node_t)); 249 277 if (!nodep->bp) { 250 278 free(nodep); 251 return NULL;279 return ENOMEM; 252 280 } 253 281 fs_node_initialize(nodep->bp); 254 282 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 255 if (!tmpfs_root_get(dev_handle)) 283 284 rc = tmpfs_root_get(&rootfn, dev_handle); 285 assert(rc == EOK); 286 if (!rootfn) 256 287 nodep->index = TMPFS_SOME_ROOT; 257 288 else … … 269 300 }; 270 301 hash_table_insert(&nodes, key, &nodep->nh_link); 271 return FS_NODE(nodep); 302 *rfn = FS_NODE(nodep); 303 return EOK; 304 } 305 306 int tmpfs_destroy_node(fs_node_t *fn) 307 { 308 tmpfs_node_t *nodep = TMPFS_NODE(fn); 309 310 assert(!nodep->lnkcnt); 311 assert(list_empty(&nodep->cs_head)); 312 313 unsigned long key[] = { 314 [NODES_KEY_INDEX] = nodep->index, 315 [NODES_KEY_DEV] = nodep->dev_handle 316 }; 317 hash_table_remove(&nodes, key, 2); 318 319 if (nodep->type == TMPFS_FILE) 320 free(nodep->data); 321 free(nodep->bp); 322 free(nodep); 323 return EOK; 272 324 } 273 325 … … 343 395 } 344 396 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_handle355 };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 365 397 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 366 398 { 367 399 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 400 int rc; 368 401 369 402 /* accept the mount options */ 370 403 ipc_callid_t callid; 371 404 size_t size; 372 if (! ipc_data_write_receive(&callid, &size)) {405 if (!async_data_write_receive(&callid, &size)) { 373 406 ipc_answer_0(callid, EINVAL); 374 407 ipc_answer_0(rid, EINVAL); … … 381 414 return; 382 415 } 383 ipcarg_t retval = ipc_data_write_finalize(callid, opts, size);416 ipcarg_t retval = async_data_write_finalize(callid, opts, size); 384 417 if (retval != EOK) { 385 418 ipc_answer_0(rid, retval); … … 395 428 } 396 429 397 tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle)); 430 fs_node_t *rootfn; 431 rc = tmpfs_root_get(&rootfn, dev_handle); 432 assert(rc == EOK); 433 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 398 434 if (str_cmp(opts, "restore") == 0) { 399 435 if (tmpfs_restore(dev_handle)) … … 445 481 ipc_callid_t callid; 446 482 size_t size; 447 if (! ipc_data_read_receive(&callid, &size)) {483 if (!async_data_read_receive(&callid, &size)) { 448 484 ipc_answer_0(callid, EINVAL); 449 485 ipc_answer_0(rid, EINVAL); … … 454 490 if (nodep->type == TMPFS_FILE) { 455 491 bytes = max(0, min(nodep->size - pos, size)); 456 (void) ipc_data_read_finalize(callid, nodep->data + pos,492 (void) async_data_read_finalize(callid, nodep->data + pos, 457 493 bytes); 458 494 } else { … … 481 517 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 482 518 483 (void) ipc_data_read_finalize(callid, dentryp->name,519 (void) async_data_read_finalize(callid, dentryp->name, 484 520 str_size(dentryp->name) + 1); 485 521 bytes = 1; … … 519 555 ipc_callid_t callid; 520 556 size_t size; 521 if (! ipc_data_write_receive(&callid, &size)) {557 if (!async_data_write_receive(&callid, &size)) { 522 558 ipc_answer_0(callid, EINVAL); 523 559 ipc_answer_0(rid, EINVAL); … … 530 566 if (pos + size <= nodep->size) { 531 567 /* The file size is not changing. */ 532 (void) ipc_data_write_finalize(callid, nodep->data + pos, size);568 (void) async_data_write_finalize(callid, nodep->data + pos, size); 533 569 ipc_answer_2(rid, EOK, size, nodep->size); 534 570 return; … … 552 588 nodep->size += delta; 553 589 nodep->data = newdata; 554 (void) ipc_data_write_finalize(callid, nodep->data + pos, size);590 (void) async_data_write_finalize(callid, nodep->data + pos, size); 555 591 ipc_answer_2(rid, EOK, size, nodep->size); 556 592 }
Note:
See TracChangeset
for help on using the changeset viewer.