Changeset a35b458 in mainline for uspace/srv/fs/tmpfs
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/srv/fs/tmpfs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs.c
r3061bc1 ra35b458 75 75 } 76 76 } 77 77 78 78 if (!tmpfs_init()) { 79 79 printf(NAME ": failed to initialize TMPFS\n"); 80 80 return -1; 81 81 } 82 82 83 83 async_sess_t *vfs_sess = service_connect_blocking(SERVICE_VFS, 84 84 INTERFACE_VFS_DRIVER, 0); … … 87 87 return -1; 88 88 } 89 89 90 90 errno_t rc = fs_register(vfs_sess, &tmpfs_vfs_info, &tmpfs_ops, 91 91 &tmpfs_libfs_ops); … … 94 94 return rc; 95 95 } 96 96 97 97 printf(NAME ": Accepting connections\n"); 98 98 task_retval(0); 99 99 async_manager(); 100 100 101 101 /* Not reached */ 102 102 return 0; -
uspace/srv/fs/tmpfs/tmpfs_dump.c
r3061bc1 ra35b458 64 64 libfs_ops_t *ops = &tmpfs_libfs_ops; 65 65 errno_t rc; 66 66 67 67 do { 68 68 char *fname; … … 70 70 tmpfs_node_t *nodep; 71 71 uint32_t size; 72 72 73 73 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &entry, 74 74 sizeof(entry)) != EOK) 75 75 return false; 76 76 77 77 entry.len = uint32_t_le2host(entry.len); 78 78 79 79 switch (entry.type) { 80 80 case TMPFS_NONE: … … 84 84 if (fname == NULL) 85 85 return false; 86 86 87 87 rc = ops->create(&fn, dsid, L_FILE); 88 88 if (rc != EOK || fn == NULL) { … … 90 90 return false; 91 91 } 92 92 93 93 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname, 94 94 entry.len) != EOK) { … … 98 98 } 99 99 fname[entry.len] = 0; 100 100 101 101 rc = ops->link(pfn, fn, fname); 102 102 if (rc != EOK) { … … 106 106 } 107 107 free(fname); 108 108 109 109 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &size, 110 110 sizeof(size)) != EOK) 111 111 return false; 112 112 113 113 size = uint32_t_le2host(size); 114 114 115 115 nodep = TMPFS_NODE(fn); 116 116 nodep->data = malloc(size); 117 117 if (nodep->data == NULL) 118 118 return false; 119 119 120 120 nodep->size = size; 121 121 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, nodep->data, 122 122 size) != EOK) 123 123 return false; 124 124 125 125 break; 126 126 case TMPFS_DIRECTORY: … … 128 128 if (fname == NULL) 129 129 return false; 130 130 131 131 rc = ops->create(&fn, dsid, L_DIRECTORY); 132 132 if (rc != EOK || fn == NULL) { … … 134 134 return false; 135 135 } 136 136 137 137 if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname, 138 138 entry.len) != EOK) { … … 150 150 } 151 151 free(fname); 152 152 153 153 if (!tmpfs_restore_recursion(dsid, bufpos, buflen, pos, 154 154 fn)) 155 155 return false; 156 156 157 157 break; 158 158 default: … … 160 160 } 161 161 } while (entry.type != TMPFS_NONE); 162 162 163 163 return true; 164 164 } … … 173 173 if (rc != EOK) 174 174 return false; 175 175 176 176 size_t bufpos = 0; 177 177 size_t buflen = 0; 178 178 aoff64_t pos = 0; 179 179 180 180 char tag[6]; 181 181 if (block_seqread(dsid, tmpfs_buf, &bufpos, &buflen, &pos, tag, 5) != EOK) 182 182 goto error; 183 183 184 184 tag[5] = 0; 185 185 if (str_cmp(tag, "TMPFS") != 0) 186 186 goto error; 187 187 188 188 rc = ops->root_get(&fn, dsid); 189 189 if (rc != EOK) … … 192 192 if (!tmpfs_restore_recursion(dsid, &bufpos, &buflen, &pos, fn)) 193 193 goto error; 194 194 195 195 block_fini(dsid); 196 196 return true; 197 197 198 198 error: 199 199 block_fini(dsid); -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r3061bc1 ra35b458 163 163 tmpfs_node_t *node = hash_table_get_inst(item, tmpfs_node_t, nh_link); 164 164 node_key_t *key = (node_key_t *)key_arg; 165 165 166 166 return key->service_id == node->service_id && key->index == node->index; 167 167 } … … 220 220 if (!hash_table_create(&nodes, 0, 0, &nodes_ops)) 221 221 return false; 222 222 223 223 return true; 224 224 } … … 228 228 fs_node_t *rfn; 229 229 errno_t rc; 230 230 231 231 rc = tmpfs_create_node(&rfn, service_id, L_DIRECTORY); 232 232 if (rc != EOK || !rfn) … … 240 240 service_id_t sid = *(service_id_t*)arg; 241 241 tmpfs_node_t *node = hash_table_get_inst(item, tmpfs_node_t, nh_link); 242 242 243 243 if (node->service_id == sid) { 244 244 hash_table_remove_item(&nodes, &node->nh_link); … … 273 273 .index = index 274 274 }; 275 275 276 276 ht_link_t *lnk = hash_table_find(&nodes, &key); 277 277 278 278 if (lnk) { 279 279 tmpfs_node_t *nodep; … … 338 338 { 339 339 tmpfs_node_t *nodep = TMPFS_NODE(fn); 340 340 341 341 assert(!nodep->lnkcnt); 342 342 assert(list_empty(&nodep->cs_list)); 343 343 344 344 hash_table_remove_item(&nodes, &nodep->nh_link); 345 345 … … 406 406 if (!childp) 407 407 return ENOENT; 408 408 409 409 if ((childp->lnkcnt == 1) && !list_empty(&childp->cs_list)) 410 410 return ENOTEMPTY; … … 432 432 fs_node_t *rootfn; 433 433 errno_t rc; 434 434 435 435 /* Check if this device is not already mounted. */ 436 436 rc = tmpfs_root_get(&rootfn, service_id); … … 474 474 .index = index 475 475 }; 476 476 477 477 ht_link_t *hlp = hash_table_find(&nodes, &key); 478 478 if (!hlp) 479 479 return ENOENT; 480 480 481 481 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 482 482 483 483 /* 484 484 * Receive the read request. … … 499 499 tmpfs_dentry_t *dentryp; 500 500 link_t *lnk; 501 501 502 502 assert(nodep->type == TMPFS_DIRECTORY); 503 503 504 504 /* 505 505 * Yes, we really use O(n) algorithm here. … … 508 508 */ 509 509 lnk = list_nth(&nodep->cs_list, pos); 510 510 511 511 if (lnk == NULL) { 512 512 async_answer_0(callid, ENOENT); … … 536 536 .index = index 537 537 }; 538 538 539 539 ht_link_t *hlp = hash_table_find(&nodes, &key); 540 540 541 541 if (!hlp) 542 542 return ENOENT; 543 543 544 544 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 545 545 … … 599 599 .index = index 600 600 }; 601 601 602 602 ht_link_t *hlp = hash_table_find(&nodes, &key); 603 603 604 604 if (!hlp) 605 605 return ENOENT; 606 606 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 607 607 608 608 if (size == nodep->size) 609 609 return EOK; 610 610 611 611 if (size > SIZE_MAX) 612 612 return ENOMEM; 613 613 614 614 void *newdata = realloc(nodep->data, size); 615 615 if (!newdata) 616 616 return ENOMEM; 617 617 618 618 if (size > nodep->size) { 619 619 size_t delta = size - nodep->size; 620 620 memset(newdata + nodep->size, 0, delta); 621 621 } 622 622 623 623 nodep->size = size; 624 624 nodep->data = newdata; … … 637 637 .index = index 638 638 }; 639 639 640 640 ht_link_t *hlp = hash_table_find(&nodes, &key); 641 641 if (!hlp)
Note:
See TracChangeset
for help on using the changeset viewer.