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