Changeset 6d4d883 in mainline for uspace/srv/fs/mfs/mfs_ops.c
- Timestamp:
- 2011-10-14T19:39:02Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2ac7af3
- Parents:
- 9269c88
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r9269c88 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; … … 328 330 } 329 331 330 service_id_t mfs_service_get(fs_node_t *fsnode) 332 service_id_t 333 mfs_service_get(fs_node_t *fsnode) 331 334 { 332 335 struct mfs_node *node = fsnode->data; … … 334 337 } 335 338 336 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) 337 341 { 338 342 int r; … … 348 352 return r; 349 353 350 /* Alloc a new inode*/354 /* Alloc a new inode */ 351 355 r = mfs_alloc_inode(inst, &inum); 352 356 if (r != EOK) … … 375 379 if (flags & L_DIRECTORY) { 376 380 ino_i->i_mode = S_IFDIR; 377 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry*/381 ino_i->i_nlinks = 2; /* This accounts for the '.' dentry */ 378 382 } else { 379 383 ino_i->i_mode = S_IFREG; … … 428 432 } 429 433 430 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) 431 436 { 432 437 struct mfs_node *mnode = pfn->data; … … 450 455 451 456 if (!d_info.d_inum) { 452 /* This entry is not used*/457 /* This entry is not used */ 453 458 continue; 454 459 } … … 457 462 458 463 if (comp_size == dentry_name_size && 459 460 /* Hit!*/464 !bcmp(component, d_info.d_name, dentry_name_size)) { 465 /* Hit! */ 461 466 mfs_node_core_get(rfn, mnode->instance, 462 467 d_info.d_inum); 463 468 goto found; 464 469 } … … 469 474 } 470 475 471 static aoff64_t mfs_size_get(fs_node_t *node) 476 static aoff64_t 477 mfs_size_get(fs_node_t *node) 472 478 { 473 479 const struct mfs_node *mnode = node->data; … … 477 483 static int 478 484 mfs_node_get(fs_node_t **rfn, service_id_t service_id, 479 485 fs_index_t index) 480 486 { 481 487 int rc; … … 521 527 } 522 528 523 static int mfs_node_open(fs_node_t *fsnode) 529 static int 530 mfs_node_open(fs_node_t *fsnode) 524 531 { 525 532 /* … … 530 537 } 531 538 532 static fs_index_t mfs_index_get(fs_node_t *fsnode) 539 static fs_index_t 540 mfs_index_get(fs_node_t *fsnode) 533 541 { 534 542 struct mfs_node *mnode = fsnode->data; … … 536 544 } 537 545 538 static unsigned mfs_lnkcnt_get(fs_node_t *fsnode) 546 static unsigned 547 mfs_lnkcnt_get(fs_node_t *fsnode) 539 548 { 540 549 struct mfs_node *mnode = fsnode->data; … … 551 560 } 552 561 553 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst, 554 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) 555 565 { 556 566 fs_node_t *node = NULL; … … 624 634 } 625 635 626 static bool mfs_is_directory(fs_node_t *fsnode) 636 static bool 637 mfs_is_directory(fs_node_t *fsnode) 627 638 { 628 639 const struct mfs_node *node = fsnode->data; … … 630 641 } 631 642 632 static bool mfs_is_file(fs_node_t *fsnode) 643 static bool 644 mfs_is_file(fs_node_t *fsnode) 633 645 { 634 646 struct mfs_node *node = fsnode->data; … … 636 648 } 637 649 638 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) 639 652 { 640 653 int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO); … … 642 655 } 643 656 644 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) 645 659 { 646 660 struct mfs_node *parent = pfn->data; … … 717 731 } 718 732 719 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) 720 735 { 721 736 struct mfs_node *mnode = fsnode->data; … … 738 753 739 754 if (d_info.d_inum) { 740 /* A valid entry has been found*/755 /* A valid entry has been found */ 741 756 *has_children = true; 742 757 break; … … 750 765 static int 751 766 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 752 767 size_t *rbytes) 753 768 { 754 769 int rc; … … 780 795 781 796 if (pos < 2) { 782 /* Skip the first two dentries ('.' and '..')*/797 /* Skip the first two dentries ('.' and '..') */ 783 798 pos = 2; 784 799 } … … 790 805 791 806 if (d_info.d_inum) { 792 /* Dentry found!*/807 /* Dentry found! */ 793 808 goto found; 794 809 } … … 806 821 807 822 if (pos >= (size_t) ino_i->i_size) { 808 /* Trying to read beyond the end of file*/823 /* Trying to read beyond the end of file */ 809 824 bytes = 0; 810 825 (void) async_data_read_finalize(callid, NULL, 0); … … 823 838 824 839 if (zone == 0) { 825 /* sparse file*/840 /* sparse file */ 826 841 uint8_t *buf = malloc(sbi->block_size); 827 842 if (!buf) { … … 831 846 memset(buf, 0, sizeof(sbi->block_size)); 832 847 async_data_read_finalize(callid, 833 848 buf + pos % sbi->block_size, bytes); 834 849 free(buf); 835 850 goto out_success; … … 841 856 842 857 async_data_read_finalize(callid, b->data + 843 858 pos % sbi->block_size, bytes); 844 859 845 860 rc = block_put(b); … … 862 877 static int 863 878 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 864 879 size_t *wbytes, aoff64_t *nsize) 865 880 { 866 881 fs_node_t *fn; … … 954 969 return ENOENT; 955 970 956 /* Destroy the inode*/971 /* Destroy the inode */ 957 972 return mfs_destroy_node(fn); 958 973 } … … 973 988 assert(!has_children); 974 989 975 /* Free the entire inode content*/990 /* Free the entire inode content */ 976 991 r = mfs_inode_shrink(mnode, mnode->ino_i->i_size); 977 992 if (r != EOK) 978 993 goto out; 979 994 980 /* Mark the inode as free in the bitmap*/995 /* Mark the inode as free in the bitmap */ 981 996 r = mfs_free_inode(mnode->instance, mnode->ino_i->index); 982 997 … … 1017 1032 1018 1033 rc = fs_instance_get(service_id, &data); 1019 if (rc == EOK) {1034 if (rc == EOK) 1020 1035 *instance = (struct mfs_instance *) data; 1021 }else {1036 else { 1022 1037 mfsdebug("instance not found\n"); 1023 1038 } … … 1026 1041 } 1027 1042 1028 static bool check_magic_number(uint16_t magic, bool *native, 1029 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) 1030 1046 { 1031 1047 bool rc = true;
Note:
See TracChangeset
for help on using the changeset viewer.