Changes in uspace/srv/fs/mfs/mfs_ops.c [6d4d883:36cb22f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r6d4d883 r36cb22f 43 43 44 44 static bool check_magic_number(uint16_t magic, bool *native, 45 mfs_version_t *version, bool *longfilenames);45 mfs_version_t *version, bool *longfilenames); 46 46 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 47 fs_index_t index); 47 fs_index_t index); 48 48 49 static int mfs_node_put(fs_node_t *fsnode); 49 50 static int mfs_node_open(fs_node_t *fsnode); … … 63 64 static hash_index_t open_nodes_hash(unsigned long key[]); 64 65 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 65 66 link_t *item); 66 67 static void open_nodes_remove_cb(link_t *link); 68 67 69 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 68 69 static int mfs_instance_get(service_id_t service_id,70 70 fs_index_t index); 71 static int 72 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance); 71 73 72 74 … … 94 96 95 97 /* Hash table interface for open nodes hash table */ 96 static hash_index_t 97 open_nodes_hash(unsigned long key[]) 98 static hash_index_t open_nodes_hash(unsigned long key[]) 98 99 { 99 100 /* TODO: This is very simple and probably can be improved */ … … 101 102 } 102 103 103 static int 104 open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 104 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 106 106 { 107 107 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); … … 118 118 } 119 119 120 static void 121 open_nodes_remove_cb(link_t *link) 120 static void open_nodes_remove_cb(link_t *link) 122 121 { 123 122 /* We don't use remove callback for this hash table */ … … 130 129 }; 131 130 132 int 133 mfs_global_init(void) 131 int mfs_global_init(void) 134 132 { 135 133 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 136 134 OPEN_NODES_KEYS, &open_nodes_ops)) { 137 135 return ENOMEM; 138 136 } … … 142 140 static int 143 141 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index, 144 142 aoff64_t *size, unsigned *linkcnt) 145 143 { 146 144 enum cache_mode cmode; … … 165 163 return rc; 166 164 167 /* Allocate space for generic MFS superblock*/165 /*Allocate space for generic MFS superblock*/ 168 166 sbi = malloc(sizeof(*sbi)); 169 167 if (!sbi) { … … 172 170 } 173 171 174 /* Allocate space for filesystem instance*/172 /*Allocate space for filesystem instance*/ 175 173 instance = malloc(sizeof(*instance)); 176 174 if (!instance) { … … 193 191 194 192 if (check_magic_number(sb->s_magic, &native, &version, &longnames)) { 195 /* This is a V1 or V2 Minix filesystem*/193 /*This is a V1 or V2 Minix filesystem*/ 196 194 magic = sb->s_magic; 197 195 } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) { 198 /* This is a V3 Minix filesystem*/196 /*This is a V3 Minix filesystem*/ 199 197 magic = sb3->s_magic; 200 198 } else { 201 /* Not recognized*/199 /*Not recognized*/ 202 200 mfsdebug("magic number not recognized\n"); 203 201 rc = ENOTSUP; … … 207 205 mfsdebug("magic number recognized = %04x\n", magic); 208 206 209 /* Fill superblock info structure*/207 /*Fill superblock info structure*/ 210 208 211 209 sbi->fs_version = version; … … 245 243 sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE; 246 244 sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN : 247 MFS_MAX_NAME_LEN;245 MFS_MAX_NAME_LEN; 248 246 } 249 247 … … 269 267 } 270 268 271 /* Initialize the instance structure and remember it*/269 /*Initialize the instance structure and remember it*/ 272 270 instance->service_id = service_id; 273 271 instance->sbi = sbi; … … 275 273 rc = fs_instance_create(service_id, instance); 276 274 if (rc != EOK) { 275 free(instance); 276 free(sbi); 277 277 block_cache_fini(service_id); 278 block_fini(service_id); 278 279 mfsdebug("fs instance creation failed\n"); 279 goto out_error;280 return rc; 280 281 } 281 282 … … 330 331 } 331 332 332 service_id_t 333 mfs_service_get(fs_node_t *fsnode) 333 service_id_t mfs_service_get(fs_node_t *fsnode) 334 334 { 335 335 struct mfs_node *node = fsnode->data; … … 337 337 } 338 338 339 static int 340 mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 339 static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 341 340 { 342 341 int r; … … 352 351 return r; 353 352 354 /* Alloc a new inode*/353 /*Alloc a new inode*/ 355 354 r = mfs_alloc_inode(inst, &inum); 356 355 if (r != EOK) … … 379 378 if (flags & L_DIRECTORY) { 380 379 ino_i->i_mode = S_IFDIR; 381 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry*/380 ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/ 382 381 } else { 383 382 ino_i->i_mode = S_IFREG; … … 432 431 } 433 432 434 static int 435 mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 433 static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 436 434 { 437 435 struct mfs_node *mnode = pfn->data; … … 455 453 456 454 if (!d_info.d_inum) { 457 /* This entry is not used*/455 /*This entry is not used*/ 458 456 continue; 459 457 } … … 462 460 463 461 if (comp_size == dentry_name_size && 464 465 /* Hit!*/462 !bcmp(component, d_info.d_name, dentry_name_size)) { 463 /*Hit!*/ 466 464 mfs_node_core_get(rfn, mnode->instance, 467 465 d_info.d_inum); 468 466 goto found; 469 467 } … … 474 472 } 475 473 476 static aoff64_t 477 mfs_size_get(fs_node_t *node) 474 static aoff64_t mfs_size_get(fs_node_t *node) 478 475 { 479 476 const struct mfs_node *mnode = node->data; … … 483 480 static int 484 481 mfs_node_get(fs_node_t **rfn, service_id_t service_id, 485 482 fs_index_t index) 486 483 { 487 484 int rc; … … 527 524 } 528 525 529 static int 530 mfs_node_open(fs_node_t *fsnode) 526 static int mfs_node_open(fs_node_t *fsnode) 531 527 { 532 528 /* … … 537 533 } 538 534 539 static fs_index_t 540 mfs_index_get(fs_node_t *fsnode) 535 static fs_index_t mfs_index_get(fs_node_t *fsnode) 541 536 { 542 537 struct mfs_node *mnode = fsnode->data; … … 544 539 } 545 540 546 static unsigned 547 mfs_lnkcnt_get(fs_node_t *fsnode) 541 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode) 548 542 { 549 543 struct mfs_node *mnode = fsnode->data; … … 560 554 } 561 555 562 static int 563 mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 564 fs_index_t index) 556 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 557 fs_index_t index) 565 558 { 566 559 fs_node_t *node = NULL; … … 634 627 } 635 628 636 static bool 637 mfs_is_directory(fs_node_t *fsnode) 629 static bool mfs_is_directory(fs_node_t *fsnode) 638 630 { 639 631 const struct mfs_node *node = fsnode->data; … … 641 633 } 642 634 643 static bool 644 mfs_is_file(fs_node_t *fsnode) 635 static bool mfs_is_file(fs_node_t *fsnode) 645 636 { 646 637 struct mfs_node *node = fsnode->data; … … 648 639 } 649 640 650 static int 651 mfs_root_get(fs_node_t **rfn, service_id_t service_id) 641 static int mfs_root_get(fs_node_t **rfn, service_id_t service_id) 652 642 { 653 643 int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO); … … 655 645 } 656 646 657 static int 658 mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 647 static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 659 648 { 660 649 struct mfs_node *parent = pfn->data; … … 731 720 } 732 721 733 static int 734 mfs_has_children(bool *has_children, fs_node_t *fsnode) 722 static int mfs_has_children(bool *has_children, fs_node_t *fsnode) 735 723 { 736 724 struct mfs_node *mnode = fsnode->data; … … 753 741 754 742 if (d_info.d_inum) { 755 /* A valid entry has been found*/743 /*A valid entry has been found*/ 756 744 *has_children = true; 757 745 break; … … 765 753 static int 766 754 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 767 755 size_t *rbytes) 768 756 { 769 757 int rc; … … 795 783 796 784 if (pos < 2) { 797 /* Skip the first two dentries ('.' and '..')*/785 /*Skip the first two dentries ('.' and '..')*/ 798 786 pos = 2; 799 787 } … … 805 793 806 794 if (d_info.d_inum) { 807 /* Dentry found!*/795 /*Dentry found!*/ 808 796 goto found; 809 797 } … … 821 809 822 810 if (pos >= (size_t) ino_i->i_size) { 823 /* Trying to read beyond the end of file*/811 /*Trying to read beyond the end of file*/ 824 812 bytes = 0; 825 813 (void) async_data_read_finalize(callid, NULL, 0); … … 838 826 839 827 if (zone == 0) { 840 /* sparse file*/828 /*sparse file*/ 841 829 uint8_t *buf = malloc(sbi->block_size); 842 830 if (!buf) { … … 846 834 memset(buf, 0, sizeof(sbi->block_size)); 847 835 async_data_read_finalize(callid, 848 836 buf + pos % sbi->block_size, bytes); 849 837 free(buf); 850 838 goto out_success; … … 856 844 857 845 async_data_read_finalize(callid, b->data + 858 846 pos % sbi->block_size, bytes); 859 847 860 848 rc = block_put(b); … … 877 865 static int 878 866 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 879 867 size_t *wbytes, aoff64_t *nsize) 880 868 { 881 869 fs_node_t *fn; … … 912 900 913 901 if (block == 0) { 902 /*Writing in a sparse block*/ 914 903 uint32_t dummy; 915 904 … … 969 958 return ENOENT; 970 959 971 /* Destroy the inode*/960 /*Destroy the inode*/ 972 961 return mfs_destroy_node(fn); 973 962 } … … 988 977 assert(!has_children); 989 978 990 /* Free the entire inode content*/979 /*Free the entire inode content*/ 991 980 r = mfs_inode_shrink(mnode, mnode->ino_i->i_size); 992 981 if (r != EOK) 993 982 goto out; 994 983 995 /* Mark the inode as free in the bitmap*/984 /*Mark the inode as free in the bitmap*/ 996 985 r = mfs_free_inode(mnode->instance, mnode->ino_i->index); 997 986 … … 1032 1021 1033 1022 rc = fs_instance_get(service_id, &data); 1034 if (rc == EOK) 1023 if (rc == EOK) { 1035 1024 *instance = (struct mfs_instance *) data; 1036 else {1025 } else { 1037 1026 mfsdebug("instance not found\n"); 1038 1027 } … … 1041 1030 } 1042 1031 1043 static bool 1044 check_magic_number(uint16_t magic, bool *native, 1045 mfs_version_t *version, bool *longfilenames) 1032 static bool check_magic_number(uint16_t magic, bool *native, 1033 mfs_version_t *version, bool *longfilenames) 1046 1034 { 1047 1035 bool rc = true;
Note:
See TracChangeset
for help on using the changeset viewer.