Changeset a9a0982 in mainline
- Timestamp:
- 2011-11-01T13:52:19Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d5a78e28
- Parents:
- c25e39b
- Location:
- uspace/lib/ext4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_filesystem.c
rc25e39b ra9a0982 43 43 int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id) 44 44 { 45 46 45 int rc; 47 46 ext4_superblock_t *temp_superblock; 48 47 size_t block_size; 48 uint32_t block_ids_per_block; 49 int i; 49 50 50 51 fs->device = service_id; … … 75 76 block_fini(fs->device); 76 77 return rc; 78 } 79 80 block_ids_per_block = block_size / sizeof(uint32_t); 81 fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT; 82 fs->inode_blocks_per_level[0] = 1; 83 for (i = 1; i < 4; i++) { 84 fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i-1] * 85 block_ids_per_block; 86 fs->inode_block_limits[i] = fs->inode_block_limits[i-1] + 87 fs->inode_blocks_per_level[i]; 77 88 } 78 89 … … 261 272 { 262 273 int rc; 263 aoff64_t limits[4];264 uint32_t block_ids_per_block;265 aoff64_t blocks_per_level[4];266 274 uint32_t offset_in_block; 267 275 uint32_t current_block; … … 287 295 } 288 296 289 /* Compute limits for indirect block levels290 * TODO: compute this once when loading filesystem and store in ext2_filesystem_t291 */292 block_ids_per_block = ext4_superblock_get_block_size(fs->superblock) / sizeof(uint32_t);293 limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;294 blocks_per_level[0] = 1;295 for (i = 1; i < 4; i++) {296 blocks_per_level[i] = blocks_per_level[i-1] *297 block_ids_per_block;298 limits[i] = limits[i-1] + blocks_per_level[i];299 }300 301 297 /* Determine the indirection level needed to get the desired block */ 302 298 level = -1; 303 299 for (i = 1; i < 4; i++) { 304 if (iblock < limits[i]) {300 if (iblock < fs->inode_block_limits[i]) { 305 301 level = i; 306 302 break; … … 313 309 314 310 /* Compute offsets for the topmost level */ 315 block_offset_in_level = iblock - limits[level-1];311 block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 316 312 current_block = ext4_inode_get_indirect_block(inode, level-1); 317 offset_in_block = block_offset_in_level / blocks_per_level[level-1];313 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 318 314 319 315 /* Navigate through other levels, until we find the block number … … 326 322 } 327 323 328 assert(offset_in_block < block_ids_per_block);329 324 current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]); 330 325 … … 350 345 351 346 /* Visit the next level */ 352 block_offset_in_level %= blocks_per_level[level];353 offset_in_block = block_offset_in_level / blocks_per_level[level-1];347 block_offset_in_level %= fs->inode_blocks_per_level[level]; 348 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 354 349 } 355 350 -
uspace/lib/ext4/libext4_filesystem.h
rc25e39b ra9a0982 42 42 service_id_t device; 43 43 ext4_superblock_t * superblock; 44 aoff64_t inode_block_limits[4]; 45 aoff64_t inode_blocks_per_level[4]; 44 46 } ext4_filesystem_t; 45 47
Note:
See TracChangeset
for help on using the changeset viewer.