Rev 3625 | Rev 4268 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3625 | Rev 4264 | ||
|---|---|---|---|
| Line 253... | Line 253... | ||
| 253 | { |
253 | { |
| 254 | unsigned long key = (unsigned long) parentp; |
254 | unsigned long key = (unsigned long) parentp; |
| 255 | link_t *hlp = hash_table_find(&childp->names, &key); |
255 | link_t *hlp = hash_table_find(&childp->names, &key); |
| 256 | assert(hlp); |
256 | assert(hlp); |
| 257 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
257 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
| 258 | return !strcmp(namep->name, component); |
258 | return !str_cmp(namep->name, component); |
| 259 | } |
259 | } |
| 260 | 260 | ||
| 261 | void *tmpfs_match(void *prnt, const char *component) |
261 | void *tmpfs_match(void *prnt, const char *component) |
| 262 | { |
262 | { |
| 263 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
263 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
| Line 317... | Line 317... | ||
| 317 | 317 | ||
| 318 | tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t)); |
318 | tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t)); |
| 319 | if (!namep) |
319 | if (!namep) |
| 320 | return ENOMEM; |
320 | return ENOMEM; |
| 321 | tmpfs_name_initialize(namep); |
321 | tmpfs_name_initialize(namep); |
| 322 | size_t len = strlen(nm); |
322 | size_t size = str_size(nm); |
| 323 | namep->name = malloc(len + 1); |
323 | namep->name = malloc(size + 1); |
| 324 | if (!namep->name) { |
324 | if (!namep->name) { |
| 325 | free(namep); |
325 | free(namep); |
| 326 | return ENOMEM; |
326 | return ENOMEM; |
| 327 | } |
327 | } |
| 328 | strcpy(namep->name, nm); |
328 | strcpy(namep->name, nm); |
| Line 452... | Line 452... | ||
| 452 | 452 | ||
| 453 | /* |
453 | /* |
| 454 | * Receive the read request. |
454 | * Receive the read request. |
| 455 | */ |
455 | */ |
| 456 | ipc_callid_t callid; |
456 | ipc_callid_t callid; |
| 457 | size_t len; |
457 | size_t size; |
| 458 | if (!ipc_data_read_receive(&callid, &len)) { |
458 | if (!ipc_data_read_receive(&callid, &size)) { |
| 459 | ipc_answer_0(callid, EINVAL); |
459 | ipc_answer_0(callid, EINVAL); |
| 460 | ipc_answer_0(rid, EINVAL); |
460 | ipc_answer_0(rid, EINVAL); |
| 461 | return; |
461 | return; |
| 462 | } |
462 | } |
| 463 | 463 | ||
| 464 | size_t bytes; |
464 | size_t bytes; |
| 465 | if (dentry->type == TMPFS_FILE) { |
465 | if (dentry->type == TMPFS_FILE) { |
| 466 | bytes = max(0, min(dentry->size - pos, len)); |
466 | bytes = max(0, min(dentry->size - pos, size)); |
| 467 | (void) ipc_data_read_finalize(callid, dentry->data + pos, |
467 | (void) ipc_data_read_finalize(callid, dentry->data + pos, |
| 468 | bytes); |
468 | bytes); |
| 469 | } else { |
469 | } else { |
| 470 | int i; |
470 | int i; |
| 471 | tmpfs_dentry_t *cur; |
471 | tmpfs_dentry_t *cur; |
| Line 492... | Line 492... | ||
| 492 | assert(hlp); |
492 | assert(hlp); |
| 493 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, |
493 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, |
| 494 | link); |
494 | link); |
| 495 | 495 | ||
| 496 | (void) ipc_data_read_finalize(callid, namep->name, |
496 | (void) ipc_data_read_finalize(callid, namep->name, |
| 497 | strlen(namep->name) + 1); |
497 | str_size(namep->name) + 1); |
| 498 | bytes = 1; |
498 | bytes = 1; |
| 499 | } |
499 | } |
| 500 | 500 | ||
| 501 | /* |
501 | /* |
| 502 | * Answer the VFS_READ call. |
502 | * Answer the VFS_READ call. |
| Line 525... | Line 525... | ||
| 525 | 525 | ||
| 526 | /* |
526 | /* |
| 527 | * Receive the write request. |
527 | * Receive the write request. |
| 528 | */ |
528 | */ |
| 529 | ipc_callid_t callid; |
529 | ipc_callid_t callid; |
| 530 | size_t len; |
530 | size_t size; |
| 531 | if (!ipc_data_write_receive(&callid, &len)) { |
531 | if (!ipc_data_write_receive(&callid, &size)) { |
| 532 | ipc_answer_0(callid, EINVAL); |
532 | ipc_answer_0(callid, EINVAL); |
| 533 | ipc_answer_0(rid, EINVAL); |
533 | ipc_answer_0(rid, EINVAL); |
| 534 | return; |
534 | return; |
| 535 | } |
535 | } |
| 536 | 536 | ||
| 537 | /* |
537 | /* |
| 538 | * Check whether the file needs to grow. |
538 | * Check whether the file needs to grow. |
| 539 | */ |
539 | */ |
| 540 | if (pos + len <= dentry->size) { |
540 | if (pos + size <= dentry->size) { |
| 541 | /* The file size is not changing. */ |
541 | /* The file size is not changing. */ |
| 542 | (void) ipc_data_write_finalize(callid, dentry->data + pos, len); |
542 | (void) ipc_data_write_finalize(callid, dentry->data + pos, size); |
| 543 | ipc_answer_2(rid, EOK, len, dentry->size); |
543 | ipc_answer_2(rid, EOK, size, dentry->size); |
| 544 | return; |
544 | return; |
| 545 | } |
545 | } |
| 546 | size_t delta = (pos + len) - dentry->size; |
546 | size_t delta = (pos + size) - dentry->size; |
| 547 | /* |
547 | /* |
| 548 | * At this point, we are deliberately extremely straightforward and |
548 | * At this point, we are deliberately extremely straightforward and |
| 549 | * simply realloc the contents of the file on every write that grows the |
549 | * simply realloc the contents of the file on every write that grows the |
| 550 | * file. In the end, the situation might not be as bad as it may look: |
550 | * file. In the end, the situation might not be as bad as it may look: |
| 551 | * our heap allocator can save us and just grow the block whenever |
551 | * our heap allocator can save us and just grow the block whenever |
| Line 559... | Line 559... | ||
| 559 | } |
559 | } |
| 560 | /* Clear any newly allocated memory in order to emulate gaps. */ |
560 | /* Clear any newly allocated memory in order to emulate gaps. */ |
| 561 | memset(newdata + dentry->size, 0, delta); |
561 | memset(newdata + dentry->size, 0, delta); |
| 562 | dentry->size += delta; |
562 | dentry->size += delta; |
| 563 | dentry->data = newdata; |
563 | dentry->data = newdata; |
| 564 | (void) ipc_data_write_finalize(callid, dentry->data + pos, len); |
564 | (void) ipc_data_write_finalize(callid, dentry->data + pos, size); |
| 565 | ipc_answer_2(rid, EOK, len, dentry->size); |
565 | ipc_answer_2(rid, EOK, size, dentry->size); |
| 566 | } |
566 | } |
| 567 | 567 | ||
| 568 | void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) |
568 | void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) |
| 569 | { |
569 | { |
| 570 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
570 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |