Changes in uspace/srv/fs/mfs/mfs_ops.c [df3caec5:36cb22f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
rdf3caec5 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 fs_index_t index); 69 static int mfs_instance_get(service_id_t service_id, 70 struct mfs_instance **instance); 71 static int mfs_check_sanity(struct mfs_sb_info *sbi); 72 static bool is_power_of_two(uint32_t n); 70 fs_index_t index); 71 static int 72 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance); 73 73 74 74 75 static hash_table_t open_nodes; … … 95 96 96 97 /* Hash table interface for open nodes hash table */ 97 static hash_index_t 98 open_nodes_hash(unsigned long key[]) 98 static hash_index_t open_nodes_hash(unsigned long key[]) 99 99 { 100 100 /* TODO: This is very simple and probably can be improved */ … … 102 102 } 103 103 104 static int 105 open_nodes_compare(unsigned long key[], hash_count_t keys, 106 link_t *item) 104 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 105 link_t *item) 107 106 { 108 107 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); … … 119 118 } 120 119 121 static void 122 open_nodes_remove_cb(link_t *link) 120 static void open_nodes_remove_cb(link_t *link) 123 121 { 124 122 /* We don't use remove callback for this hash table */ … … 131 129 }; 132 130 133 int 134 mfs_global_init(void) 131 int mfs_global_init(void) 135 132 { 136 133 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 137 134 OPEN_NODES_KEYS, &open_nodes_ops)) { 138 135 return ENOMEM; 139 136 } … … 143 140 static int 144 141 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index, 145 142 aoff64_t *size, unsigned *linkcnt) 146 143 { 147 144 enum cache_mode cmode; … … 166 163 return rc; 167 164 168 /* Allocate space for generic MFS superblock*/165 /*Allocate space for generic MFS superblock*/ 169 166 sbi = malloc(sizeof(*sbi)); 170 167 if (!sbi) { … … 173 170 } 174 171 175 /* Allocate space for filesystem instance*/172 /*Allocate space for filesystem instance*/ 176 173 instance = malloc(sizeof(*instance)); 177 174 if (!instance) { … … 194 191 195 192 if (check_magic_number(sb->s_magic, &native, &version, &longnames)) { 196 /* This is a V1 or V2 Minix filesystem*/193 /*This is a V1 or V2 Minix filesystem*/ 197 194 magic = sb->s_magic; 198 195 } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) { 199 /* This is a V3 Minix filesystem*/196 /*This is a V3 Minix filesystem*/ 200 197 magic = sb3->s_magic; 201 198 } else { 202 /* Not recognized*/199 /*Not recognized*/ 203 200 mfsdebug("magic number not recognized\n"); 204 201 rc = ENOTSUP; … … 208 205 mfsdebug("magic number recognized = %04x\n", magic); 209 206 210 /* Fill superblock info structure*/207 /*Fill superblock info structure*/ 211 208 212 209 sbi->fs_version = version; … … 246 243 sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE; 247 244 sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN : 248 MFS_MAX_NAME_LEN;245 MFS_MAX_NAME_LEN; 249 246 } 250 247 … … 262 259 263 260 sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks; 264 if ((rc = mfs_check_sanity(sbi)) != EOK) {265 fprintf(stderr, "Filesystem corrupted, invalid superblock");266 goto out_error;267 }268 261 269 262 rc = block_cache_init(service_id, sbi->block_size, 0, cmode); … … 274 267 } 275 268 276 /* Initialize the instance structure and remember it*/269 /*Initialize the instance structure and remember it*/ 277 270 instance->service_id = service_id; 278 271 instance->sbi = sbi; … … 280 273 rc = fs_instance_create(service_id, instance); 281 274 if (rc != EOK) { 275 free(instance); 276 free(sbi); 282 277 block_cache_fini(service_id); 278 block_fini(service_id); 283 279 mfsdebug("fs instance creation failed\n"); 284 goto out_error;280 return rc; 285 281 } 286 282 … … 335 331 } 336 332 337 service_id_t 338 mfs_service_get(fs_node_t *fsnode) 333 service_id_t mfs_service_get(fs_node_t *fsnode) 339 334 { 340 335 struct mfs_node *node = fsnode->data; … … 342 337 } 343 338 344 static int 345 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) 346 340 { 347 341 int r; … … 357 351 return r; 358 352 359 /* Alloc a new inode*/353 /*Alloc a new inode*/ 360 354 r = mfs_alloc_inode(inst, &inum); 361 355 if (r != EOK) … … 384 378 if (flags & L_DIRECTORY) { 385 379 ino_i->i_mode = S_IFDIR; 386 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry*/380 ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/ 387 381 } else { 388 382 ino_i->i_mode = S_IFREG; … … 437 431 } 438 432 439 static int 440 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) 441 434 { 442 435 struct mfs_node *mnode = pfn->data; … … 460 453 461 454 if (!d_info.d_inum) { 462 /* This entry is not used*/455 /*This entry is not used*/ 463 456 continue; 464 457 } … … 467 460 468 461 if (comp_size == dentry_name_size && 469 470 /* Hit!*/462 !bcmp(component, d_info.d_name, dentry_name_size)) { 463 /*Hit!*/ 471 464 mfs_node_core_get(rfn, mnode->instance, 472 465 d_info.d_inum); 473 466 goto found; 474 467 } … … 479 472 } 480 473 481 static aoff64_t 482 mfs_size_get(fs_node_t *node) 474 static aoff64_t mfs_size_get(fs_node_t *node) 483 475 { 484 476 const struct mfs_node *mnode = node->data; … … 488 480 static int 489 481 mfs_node_get(fs_node_t **rfn, service_id_t service_id, 490 482 fs_index_t index) 491 483 { 492 484 int rc; … … 532 524 } 533 525 534 static int 535 mfs_node_open(fs_node_t *fsnode) 526 static int mfs_node_open(fs_node_t *fsnode) 536 527 { 537 528 /* … … 542 533 } 543 534 544 static fs_index_t 545 mfs_index_get(fs_node_t *fsnode) 535 static fs_index_t mfs_index_get(fs_node_t *fsnode) 546 536 { 547 537 struct mfs_node *mnode = fsnode->data; … … 549 539 } 550 540 551 static unsigned 552 mfs_lnkcnt_get(fs_node_t *fsnode) 541 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode) 553 542 { 554 543 struct mfs_node *mnode = fsnode->data; … … 565 554 } 566 555 567 static int 568 mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 569 fs_index_t index) 556 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 557 fs_index_t index) 570 558 { 571 559 fs_node_t *node = NULL; … … 639 627 } 640 628 641 static bool 642 mfs_is_directory(fs_node_t *fsnode) 629 static bool mfs_is_directory(fs_node_t *fsnode) 643 630 { 644 631 const struct mfs_node *node = fsnode->data; … … 646 633 } 647 634 648 static bool 649 mfs_is_file(fs_node_t *fsnode) 635 static bool mfs_is_file(fs_node_t *fsnode) 650 636 { 651 637 struct mfs_node *node = fsnode->data; … … 653 639 } 654 640 655 static int 656 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) 657 642 { 658 643 int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO); … … 660 645 } 661 646 662 static int 663 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) 664 648 { 665 649 struct mfs_node *parent = pfn->data; … … 736 720 } 737 721 738 static int 739 mfs_has_children(bool *has_children, fs_node_t *fsnode) 722 static int mfs_has_children(bool *has_children, fs_node_t *fsnode) 740 723 { 741 724 struct mfs_node *mnode = fsnode->data; … … 758 741 759 742 if (d_info.d_inum) { 760 /* A valid entry has been found*/743 /*A valid entry has been found*/ 761 744 *has_children = true; 762 745 break; … … 770 753 static int 771 754 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 772 755 size_t *rbytes) 773 756 { 774 757 int rc; … … 800 783 801 784 if (pos < 2) { 802 /* Skip the first two dentries ('.' and '..')*/785 /*Skip the first two dentries ('.' and '..')*/ 803 786 pos = 2; 804 787 } … … 810 793 811 794 if (d_info.d_inum) { 812 /* Dentry found!*/795 /*Dentry found!*/ 813 796 goto found; 814 797 } … … 826 809 827 810 if (pos >= (size_t) ino_i->i_size) { 828 /* Trying to read beyond the end of file*/811 /*Trying to read beyond the end of file*/ 829 812 bytes = 0; 830 813 (void) async_data_read_finalize(callid, NULL, 0); … … 843 826 844 827 if (zone == 0) { 845 /* sparse file*/828 /*sparse file*/ 846 829 uint8_t *buf = malloc(sbi->block_size); 847 830 if (!buf) { … … 851 834 memset(buf, 0, sizeof(sbi->block_size)); 852 835 async_data_read_finalize(callid, 853 836 buf + pos % sbi->block_size, bytes); 854 837 free(buf); 855 838 goto out_success; … … 861 844 862 845 async_data_read_finalize(callid, b->data + 863 846 pos % sbi->block_size, bytes); 864 847 865 848 rc = block_put(b); … … 882 865 static int 883 866 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 884 867 size_t *wbytes, aoff64_t *nsize) 885 868 { 886 869 fs_node_t *fn; … … 917 900 918 901 if (block == 0) { 902 /*Writing in a sparse block*/ 919 903 uint32_t dummy; 920 904 … … 974 958 return ENOENT; 975 959 976 /* Destroy the inode*/960 /*Destroy the inode*/ 977 961 return mfs_destroy_node(fn); 978 962 } … … 993 977 assert(!has_children); 994 978 995 /* Free the entire inode content*/979 /*Free the entire inode content*/ 996 980 r = mfs_inode_shrink(mnode, mnode->ino_i->i_size); 997 981 if (r != EOK) 998 982 goto out; 999 983 1000 /* Mark the inode as free in the bitmap*/984 /*Mark the inode as free in the bitmap*/ 1001 985 r = mfs_free_inode(mnode->instance, mnode->ino_i->index); 1002 986 … … 1037 1021 1038 1022 rc = fs_instance_get(service_id, &data); 1039 if (rc == EOK) 1023 if (rc == EOK) { 1040 1024 *instance = (struct mfs_instance *) data; 1041 else {1025 } else { 1042 1026 mfsdebug("instance not found\n"); 1043 1027 } … … 1046 1030 } 1047 1031 1048 static bool 1049 check_magic_number(uint16_t magic, bool *native, 1050 mfs_version_t *version, bool *longfilenames) 1032 static bool check_magic_number(uint16_t magic, bool *native, 1033 mfs_version_t *version, bool *longfilenames) 1051 1034 { 1052 1035 bool rc = true; … … 1076 1059 } 1077 1060 1078 /** Filesystem sanity check1079 *1080 * @param Pointer to the MFS superblock.1081 *1082 * @return EOK on success, ENOTSUP otherwise.1083 */1084 static int1085 mfs_check_sanity(struct mfs_sb_info *sbi)1086 {1087 if (!is_power_of_two(sbi->block_size) ||1088 sbi->block_size < MFS_MIN_BLOCKSIZE ||1089 sbi->block_size > MFS_MAX_BLOCKSIZE)1090 return ENOTSUP;1091 else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0)1092 return ENOTSUP;1093 else if (sbi->ninodes == 0 || sbi->nzones == 0)1094 return ENOTSUP;1095 else if (sbi->firstdatazone == 0)1096 return ENOTSUP;1097 1098 return EOK;1099 }1100 1101 1061 static int 1102 1062 mfs_close(service_id_t service_id, fs_index_t index) … … 1119 1079 1120 1080 return mfs_node_put(fn); 1121 }1122 1123 /** Check if a given number is a power of two.1124 *1125 * @param n The number to check.1126 *1127 * @return true if it is a power of two, false otherwise.1128 */1129 static bool1130 is_power_of_two(uint32_t n)1131 {1132 if (n == 0)1133 return false;1134 1135 return (n & (n - 1)) == 0;1136 1081 } 1137 1082
Note:
See TracChangeset
for help on using the changeset viewer.