Changeset 5614c7f in mainline
- Timestamp:
- 2012-01-21T12:52:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 47a89fe
- Parents:
- 73196d2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext4fs/ext4fs_ops.c
r73196d2 r5614c7f 169 169 int ext4fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst) 170 170 { 171 ext4fs_instance_t *tmp;172 173 171 fibril_mutex_lock(&instance_list_mutex); 174 172 … … 178 176 } 179 177 178 ext4fs_instance_t *tmp; 180 179 list_foreach(instance_list, link) { 181 180 tmp = list_get_instance(link, ext4fs_instance_t, link); … … 201 200 int ext4fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 202 201 { 202 int rc; 203 203 204 ext4fs_node_t *eparent = EXT4FS_NODE(pfn); 204 ext4_filesystem_t *fs; 205 ext4_directory_iterator_t it; 206 int rc; 207 208 fs = eparent->instance->filesystem; 205 ext4_filesystem_t *fs = eparent->instance->filesystem; 209 206 210 207 if (!ext4_inode_is_type(fs->superblock, eparent->inode_ref->inode, … … 213 210 } 214 211 212 ext4_directory_iterator_t it; 215 213 rc = ext4_directory_iterator_init(&it, fs, eparent->inode_ref, 0); 216 214 if (rc != EOK) { … … 239 237 int ext4fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 240 238 { 241 ext4fs_instance_t *inst = NULL;242 int rc; 243 239 int rc; 240 241 ext4fs_instance_t *inst; 244 242 rc = ext4fs_instance_get(service_id, &inst); 245 243 if (rc != EOK) { … … 255 253 { 256 254 int rc; 257 fs_node_t *node = NULL;258 ext4fs_node_t *enode = NULL;259 260 ext4_inode_ref_t *inode_ref = NULL;261 255 262 256 fibril_mutex_lock(&open_nodes_lock); … … 267 261 [OPEN_NODES_INODE_KEY] = index, 268 262 }; 263 269 264 link_t *already_open = hash_table_find(&open_nodes, key); 270 265 ext4fs_node_t *enode = NULL; 271 266 if (already_open) { 272 267 enode = hash_table_get_instance(already_open, ext4fs_node_t, link); … … 284 279 } 285 280 286 node = malloc(sizeof(fs_node_t));287 if ( node == NULL) {281 fs_node_t *fs_node = malloc(sizeof(fs_node_t)); 282 if (fs_node == NULL) { 288 283 free(enode); 289 284 fibril_mutex_unlock(&open_nodes_lock); 290 285 return ENOMEM; 291 286 } 292 fs_node_initialize(node); 293 287 fs_node_initialize(fs_node); 288 289 ext4_inode_ref_t *inode_ref; 294 290 rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref); 295 291 if (rc != EOK) { 296 292 free(enode); 297 free( node);293 free(fs_node); 298 294 fibril_mutex_unlock(&open_nodes_lock); 299 295 return rc; … … 303 299 enode->instance = inst; 304 300 enode->references = 1; 305 enode->fs_node = node;301 enode->fs_node = fs_node; 306 302 link_initialize(&enode->link); 307 303 308 node->data = enode;309 *rfn = node;304 fs_node->data = enode; 305 *rfn = fs_node; 310 306 311 307 hash_table_insert(&open_nodes, key, &enode->link); … … 351 347 { 352 348 int rc; 349 350 fibril_mutex_lock(&open_nodes_lock); 351 353 352 ext4fs_node_t *enode = EXT4FS_NODE(fn); 354 355 fibril_mutex_lock(&open_nodes_lock);356 357 353 assert(enode->references > 0); 358 354 enode->references--; … … 412 408 } 413 409 414 415 410 // TODO set real deletion time 416 411 // time_t now = time(NULL); … … 511 506 int ext4fs_has_children(bool *has_children, fs_node_t *fn) 512 507 { 508 int rc; 509 513 510 ext4fs_node_t *enode = EXT4FS_NODE(fn); 514 ext4_directory_iterator_t it; 515 ext4_filesystem_t *fs; 516 int rc; 517 bool found = false; 518 size_t name_size; 519 520 fs = enode->instance->filesystem; 511 ext4_filesystem_t *fs = enode->instance->filesystem; 521 512 522 513 if (!ext4_inode_is_type(fs->superblock, enode->inode_ref->inode, … … 526 517 } 527 518 519 ext4_directory_iterator_t it; 528 520 rc = ext4_directory_iterator_init(&it, fs, enode->inode_ref, 0); 529 521 if (rc != EOK) { … … 532 524 533 525 /* Find a non-empty directory entry */ 526 bool found = false; 534 527 while (it.current != NULL) { 535 528 if (it.current->inode != 0) { 536 name_size = ext4_directory_entry_ll_get_name_length(fs->superblock,529 uint16_t name_size = ext4_directory_entry_ll_get_name_length(fs->superblock, 537 530 it.current); 538 531 if (!ext4fs_is_dots(it.current->name, name_size)) { … … 570 563 { 571 564 ext4fs_node_t *enode = EXT4FS_NODE(fn); 572 aoff64_t size = ext4_inode_get_size( 573 enode->instance->filesystem->superblock, enode->inode_ref->inode); 574 return size; 565 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 566 return ext4_inode_get_size(sb, enode->inode_ref->inode); 575 567 } 576 568 … … 597 589 { 598 590 ext4fs_node_t *enode = EXT4FS_NODE(fn); 599 bool is_dir = ext4_inode_is_type(enode->instance->filesystem->superblock,600 enode->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY);601 return is_dir;591 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 592 return ext4_inode_is_type( 593 sb, enode->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY); 602 594 } 603 595 … … 606 598 { 607 599 ext4fs_node_t *enode = EXT4FS_NODE(fn); 608 bool is_file = ext4_inode_is_type(enode->instance->filesystem->superblock,609 enode->inode_ref->inode, EXT4_INODE_MODE_FILE);610 return is_file;600 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 601 return ext4_inode_is_type( 602 sb, enode->inode_ref->inode, EXT4_INODE_MODE_FILE); 611 603 } 612 604 … … 649 641 { 650 642 int rc; 643 644 /* Allocate libext4 filesystem structure */ 651 645 ext4_filesystem_t *fs; 652 ext4fs_instance_t *inst;653 bool read_only;654 655 /* Allocate libext4 filesystem structure */656 646 fs = (ext4_filesystem_t *) malloc(sizeof(ext4_filesystem_t)); 657 647 if (fs == NULL) { … … 660 650 661 651 /* Allocate instance structure */ 652 ext4fs_instance_t *inst; 662 653 inst = (ext4fs_instance_t *) malloc(sizeof(ext4fs_instance_t)); 663 654 if (inst == NULL) { … … 684 675 685 676 /* Check flags */ 677 bool read_only; 686 678 rc = ext4_filesystem_check_features(fs, &read_only); 687 679 if (rc != EOK) { … … 726 718 { 727 719 int rc; 720 728 721 ext4fs_instance_t *inst; 729 730 722 rc = ext4fs_instance_get(service_id, &inst); 731 732 723 if (rc != EOK) { 733 724 return rc; … … 755 746 aoff64_t pos, size_t *rbytes) 756 747 { 757 ext4fs_instance_t *inst;758 ext4_inode_ref_t *inode_ref;759 748 int rc; 760 749 … … 769 758 } 770 759 760 ext4fs_instance_t *inst; 771 761 rc = ext4fs_instance_get(service_id, &inst); 772 762 if (rc != EOK) { … … 775 765 } 776 766 767 ext4_inode_ref_t *inode_ref; 777 768 rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref); 778 769 if (rc != EOK) { … … 816 807 ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes) 817 808 { 809 int rc; 810 818 811 ext4_directory_iterator_t it; 819 aoff64_t next;820 uint8_t *buf;821 size_t name_size;822 int rc;823 bool found = false;824 825 812 rc = ext4_directory_iterator_init(&it, inst->filesystem, inode_ref, pos); 826 813 if (rc != EOK) { … … 833 820 * as these are not used in HelenOS 834 821 */ 822 bool found = false; 835 823 while (it.current != NULL) { 836 824 … … 839 827 } 840 828 841 name_size = ext4_directory_entry_ll_get_name_length(829 uint16_t name_size = ext4_directory_entry_ll_get_name_length( 842 830 inst->filesystem->superblock, it.current); 843 831 … … 851 839 * and add the \0 at the end 852 840 */ 853 buf = malloc(name_size+1);841 uint8_t *buf = malloc(name_size+1); 854 842 if (buf == NULL) { 855 843 ext4_directory_iterator_fini(&it); … … 873 861 } 874 862 863 uint64_t next; 875 864 if (found) { 876 865 rc = ext4_directory_iterator_next(&it); … … 899 888 { 900 889 int rc; 901 uint32_t block_size; 902 aoff64_t file_block; 903 uint64_t file_size; 904 uint32_t fs_block; 905 size_t offset_in_block; 906 size_t bytes; 907 block_t *block; 908 uint8_t *buffer; 909 910 file_size = ext4_inode_get_size(inst->filesystem->superblock, 911 inode_ref->inode); 890 891 ext4_superblock_t *sb = inst->filesystem->superblock; 892 uint64_t file_size = ext4_inode_get_size(sb, inode_ref->inode); 912 893 913 894 if (pos >= file_size) { … … 919 900 920 901 /* For now, we only read data from one block at a time */ 921 block_size = ext4_superblock_get_block_size(inst->filesystem->superblock);922 file_block = pos / block_size;923 offset_in_block = pos % block_size;924 bytes = min(block_size - offset_in_block, size);902 uint32_t block_size = ext4_superblock_get_block_size(sb); 903 aoff64_t file_block = pos / block_size; 904 uint32_t offset_in_block = pos % block_size; 905 uint32_t bytes = min(block_size - offset_in_block, size); 925 906 926 907 /* Handle end of file */ … … 930 911 931 912 /* Get the real block number */ 913 uint32_t fs_block; 932 914 rc = ext4_filesystem_get_inode_data_block_index(inst->filesystem, 933 915 inode_ref->inode, file_block, &fs_block); … … 942 924 * file and we need to return a buffer of zeros 943 925 */ 926 uint8_t *buffer; 944 927 if (fs_block == 0) { 945 928 buffer = malloc(bytes); … … 960 943 961 944 /* Usual case - we need to read a block from device */ 945 block_t *block; 962 946 rc = block_get(&block, inst->service_id, fs_block, BLOCK_FLAGS_NONE); 963 947 if (rc != EOK) { … … 982 966 { 983 967 int rc; 984 int flags = BLOCK_FLAGS_NONE; 968 985 969 fs_node_t *fn; 986 ext4fs_node_t *enode; 987 ext4_filesystem_t *fs; 988 ext4_inode_ref_t *inode_ref; 970 rc = ext4fs_node_get(&fn, service_id, index); 971 if (rc != EOK) { 972 EXT4FS_DBG("node get error"); 973 return rc; 974 } 975 989 976 ipc_callid_t callid; 990 size_t len, bytes, block_size; 991 block_t *write_block; 992 uint32_t fblock, iblock; 993 uint32_t old_inode_size; 994 995 rc = ext4fs_node_get(&fn, service_id, index); 996 if (rc != EOK) { 997 EXT4FS_DBG("node get error"); 998 return rc; 999 } 1000 977 size_t len; 1001 978 if (!async_data_write_receive(&callid, &len)) { 1002 979 rc = EINVAL; … … 1008 985 1009 986 1010 enode = EXT4FS_NODE(fn); 1011 inode_ref = enode->inode_ref; 1012 fs = enode->instance->filesystem; 1013 1014 block_size = ext4_superblock_get_block_size(fs->superblock); 987 ext4fs_node_t *enode = EXT4FS_NODE(fn); 988 ext4_filesystem_t *fs = enode->instance->filesystem; 989 990 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 1015 991 1016 992 // Prevent writing to more than one block 1017 bytes = min(len, block_size - (pos % block_size)); 1018 993 uint32_t bytes = min(len, block_size - (pos % block_size)); 994 995 int flags = BLOCK_FLAGS_NONE; 1019 996 if (bytes == block_size) { 1020 997 flags = BLOCK_FLAGS_NOREAD; 1021 998 } 1022 999 1023 iblock = pos / block_size; 1024 1000 uint32_t iblock = pos / block_size; 1001 uint32_t fblock; 1002 1003 ext4_inode_ref_t *inode_ref = enode->inode_ref; 1025 1004 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, iblock, &fblock); 1026 1005 if (rc != EOK) { … … 1048 1027 } 1049 1028 1029 block_t *write_block; 1050 1030 rc = block_get(&write_block, service_id, fblock, flags); 1051 1031 if (rc != EOK) { … … 1075 1055 } 1076 1056 1077 old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);1057 uint32_t old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 1078 1058 if (pos + bytes > old_inode_size) { 1079 1059 ext4_inode_set_size(inode_ref->inode, pos + bytes); … … 1092 1072 { 1093 1073 int rc; 1074 1094 1075 fs_node_t *fn; 1095 1096 1076 rc = ext4fs_node_get(&fn, service_id, index); 1097 1077 if (rc != EOK) { … … 1119 1099 { 1120 1100 int rc; 1101 1121 1102 fs_node_t *fn; 1122 1123 1103 rc = ext4fs_node_get(&fn, service_id, index); 1124 1104 if (rc != EOK) { … … 1134 1114 { 1135 1115 int rc; 1116 1136 1117 fs_node_t *fn; 1137 ext4fs_node_t *enode;1138 1139 1118 rc = ext4fs_node_get(&fn, service_id, index); 1140 1119 if (rc != EOK) { … … 1142 1121 } 1143 1122 1144 e node = EXT4FS_NODE(fn);1123 ext4fs_node_t *enode = EXT4FS_NODE(fn); 1145 1124 enode->inode_ref->dirty = true; 1146 1125
Note:
See TracChangeset
for help on using the changeset viewer.