Changeset 6088193 in mainline
- Timestamp:
- 2011-11-10T19:59:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 27ca3a3
- Parents:
- b3d7277
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_bitmap.c
rb3d7277 r6088193 95 95 } 96 96 97 int ext4_bitmap_free_block(ext4_filesystem_t *fs, uint32_t block_index)97 int ext4_bitmap_free_block(ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, uint32_t block_index) 98 98 { 99 99 int rc; … … 102 102 uint32_t index_in_group; 103 103 uint32_t bitmap_block; 104 uint32_t block_size; 104 105 ext4_block_group_ref_t *bg_ref; 105 106 block_t *block; 107 108 block_size = ext4_superblock_get_block_size(fs->superblock); 106 109 107 110 blocks_per_group = ext4_superblock_get_blocks_per_group(fs->superblock); … … 128 131 return rc; 129 132 } 133 134 uint64_t ino_blocks = ext4_inode_get_blocks_count(fs->superblock, inode_ref->inode); 135 ino_blocks -= block_size / EXT4_INODE_BLOCK_SIZE; 136 ext4_inode_set_blocks_count(fs->superblock, inode_ref->inode, ino_blocks); 137 inode_ref->dirty = true; 130 138 131 139 uint32_t free_blocks = ext4_block_group_get_free_blocks_count(bg_ref->block_group); … … 138 146 rc = ext4_filesystem_put_block_group_ref(bg_ref); 139 147 if (rc != EOK) { 148 EXT4FS_DBG("error in saving bg_ref \%d", rc); 140 149 // TODO error 141 150 return rc; 142 151 } 143 152 144 EXT4FS_DBG("block \%u released", block_index);153 // EXT4FS_DBG("block \%u released", block_index); 145 154 146 155 return EOK; … … 177 186 rc = ext4_bitmap_find_free_bit_and_set(block->data, &rel_block_idx, block_size); 178 187 if (rc != EOK) { 179 EXT4FS_DBG("no block found");180 // TODO if ENOSPC - try next block group - try next block groups188 EXT4FS_DBG("no free block found"); 189 // TODO if ENOSPC - try next block groups 181 190 } 182 191 183 192 block->dirty = true; 184 193 185 // TODO check retval 186 block_put(block); 194 rc = block_put(block); 195 if (rc != EOK) { 196 // TODO error 197 EXT4FS_DBG("error in saving bitmap \%d", rc); 198 } 187 199 188 200 // TODO decrement superblock free blocks count … … 191 203 //ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 192 204 205 uint64_t ino_blocks = ext4_inode_get_blocks_count(fs->superblock, inode_ref->inode); 206 ino_blocks += block_size / EXT4_INODE_BLOCK_SIZE; 207 ext4_inode_set_blocks_count(fs->superblock, inode_ref->inode, ino_blocks); 208 inode_ref->dirty = true; 209 193 210 uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count(bg_ref->block_group); 194 211 bg_free_blocks--; … … 200 217 blocks_per_group = ext4_superblock_get_blocks_per_group(fs->superblock); 201 218 202 EXT4FS_DBG("block \%u allocated", blocks_per_group * block_group + rel_block_idx + 1);219 // EXT4FS_DBG("block \%u allocated", blocks_per_group * block_group + rel_block_idx + 1); 203 220 204 221 *fblock = blocks_per_group * block_group + rel_block_idx + 1; -
uspace/lib/ext4/libext4_bitmap.h
rb3d7277 r6088193 37 37 #include "libext4_filesystem.h" 38 38 39 extern int ext4_bitmap_free_block(ext4_filesystem_t *, uint32_t); 39 extern int ext4_bitmap_free_block(ext4_filesystem_t *, 40 ext4_inode_ref_t *, uint32_t); 40 41 extern int ext4_bitmap_alloc_block(ext4_filesystem_t *, 41 42 ext4_inode_ref_t *, uint32_t *); -
uspace/lib/ext4/libext4_filesystem.c
rb3d7277 r6088193 82 82 fs->inode_blocks_per_level[0] = 1; 83 83 for (i = 1; i < 4; i++) { 84 fs->inode_blocks_per_level[i] 84 fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] * 85 85 block_ids_per_block; 86 86 fs->inode_block_limits[i] = fs->inode_block_limits[i-1] + … … 321 321 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 322 322 323 if (current_block == 0) { 324 *fblock = 0; 325 return EOK; 326 } 327 323 328 /* Navigate through other levels, until we find the block number 324 329 * or find null reference meaning we are dealing with sparse file … … 415 420 if (rc != EOK) { 416 421 // TODO error 417 } 418 EXT4FS_DBG("AAA: new addr \%u, level = \%u", new_block_addr, level); 422 EXT4FS_DBG("error in allocation"); 423 } 424 // EXT4FS_DBG("AAA: new addr \%u, level = \%u", new_block_addr, level); 419 425 420 426 ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr); … … 435 441 EXT4FS_DBG("block put error"); 436 442 } 443 444 // EXT4FS_DBG("allocated indirect block for level \%u, during setting iblock \%u", level, (uint32_t)iblock); 437 445 438 446 current_block = new_block_addr; … … 462 470 if (rc != EOK) { 463 471 // TODO error 472 473 EXT4FS_DBG("BBB: error block loading"); 474 464 475 } 465 476 memset(new_block->data, 0, block_size); … … 524 535 525 536 ext4_inode_set_direct_block(inode, iblock, 0); 526 return ext4_bitmap_free_block(fs, fblock);537 return ext4_bitmap_free_block(fs, inode_ref, fblock); 527 538 } 528 539 … … 588 599 } 589 600 590 return ext4_bitmap_free_block(fs, fblock);601 return ext4_bitmap_free_block(fs, inode_ref, fblock); 591 602 592 603 } -
uspace/lib/ext4/libext4_inode.h
rb3d7277 r6088193 39 39 #include "libext4_superblock.h" 40 40 41 #define EXT4_INODE_BLOCK_SIZE 512 41 42 42 43 #define EXT4_INODE_DIRECT_BLOCK_COUNT 12 -
uspace/srv/fs/ext4fs/ext4fs_ops.c
rb3d7277 r6088193 935 935 rc = ext4fs_node_get(&fn, service_id, index); 936 936 if (rc != EOK) { 937 EXT4FS_DBG("node get error"); 937 938 return rc; 938 939 } … … 942 943 ext4fs_node_put(fn); 943 944 async_answer_0(callid, rc); 945 EXT4FS_DBG("data write recv"); 944 946 return rc; 945 947 } … … 962 964 963 965 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, iblock, &fblock); 966 if (rc != EOK) { 967 // TODO error 968 ext4fs_node_put(fn); 969 EXT4FS_DBG("error loading block addr"); 970 return rc; 971 } 964 972 965 973 if (fblock == 0) { 974 966 975 rc = ext4_bitmap_alloc_block(fs, inode_ref, &fblock); 967 976 if (rc != EOK) { 977 EXT4FS_DBG("allocation failed"); 968 978 ext4fs_node_put(fn); 969 979 async_answer_0(callid, rc); … … 980 990 rc = block_get(&write_block, service_id, fblock, flags); 981 991 if (rc != EOK) { 992 EXT4FS_DBG("error in loading block \%d", rc); 982 993 ext4fs_node_put(fn); 983 994 async_answer_0(callid, rc); … … 999 1010 rc = block_put(write_block); 1000 1011 if (rc != EOK) { 1012 EXT4FS_DBG("error in writing block \%d", rc); 1001 1013 ext4fs_node_put(fn); 1002 1014 return rc; … … 1019 1031 ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t new_size) 1020 1032 { 1021 EXT4FS_DBG("");1022 1033 fs_node_t *fn; 1023 1034 ext4fs_node_t *enode; … … 1112 1123 static int ext4fs_sync(service_id_t service_id, fs_index_t index) 1113 1124 { 1114 EXT4FS_DBG("");1115 1116 1125 int rc; 1117 1126 fs_node_t *fn;
Note:
See TracChangeset
for help on using the changeset viewer.