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