Changeset 260c052 in mainline for uspace/lib/ext2/libext2_filesystem.c
- Timestamp:
- 2011-06-02T08:01:34Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5bd1ffb
- Parents:
- 9bd5746
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext2/libext2_filesystem.c
r9bd5746 r260c052 117 117 int ext2_filesystem_check_flags(ext2_filesystem_t *fs, bool *o_read_only) 118 118 { 119 / / feature flags are present in rev 1 and later119 /* feature flags are present in rev 1 and later */ 120 120 if (ext2_superblock_get_rev_major(fs->superblock) == 0) { 121 121 *o_read_only = false; 122 return 0;122 return EOK; 123 123 } 124 124 … … 129 129 read_only = ext2_superblock_get_features_read_only(fs->superblock); 130 130 131 // unset any supported features 131 /* check whether we support all features 132 * first unset any supported feature flags 133 * and see whether any unspported feature remains */ 132 134 incompatible &= ~EXT2_SUPPORTED_INCOMPATIBLE_FEATURES; 133 135 read_only &= ~EXT2_SUPPORTED_READ_ONLY_FEATURES; … … 171 173 / EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE; 172 174 173 / / Block group descriptor table starts at the next block after superblock175 /* Block group descriptor table starts at the next block after superblock */ 174 176 block_id = ext2_superblock_get_first_block(fs->superblock) + 1; 175 177 176 / / Find the block containing the descriptor we are looking for178 /* Find the block containing the descriptor we are looking for */ 177 179 block_id += bgid / descriptors_per_block; 178 180 offset = (bgid % descriptors_per_block) * EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE; … … 240 242 inodes_per_group = ext2_superblock_get_inodes_per_group(fs->superblock); 241 243 242 // inode numbers are 1-based 244 /* inode numbers are 1-based, but it is simpler to work with 0-based 245 * when computing indices 246 */ 243 247 index -= 1; 244 248 block_group = index / inodes_per_group; … … 269 273 270 274 newref->inode = newref->block->data + offset_in_block; 271 newref->index = index+1; // we decremented index above 275 /* we decremented index above, but need to store the original value 276 * in the reference 277 */ 278 newref->index = index+1; 272 279 273 280 *ref = newref; … … 315 322 block_t *block; 316 323 324 /* Handle simple case when we are dealing with direct reference */ 317 325 if (iblock < EXT2_INODE_DIRECT_BLOCKS) { 318 326 current_block = ext2_inode_get_direct_block(inode, (uint32_t)iblock); … … 321 329 } 322 330 323 // Compute limits for indirect block levels 324 // TODO: compute this once when loading filesystem and store in ext2_filesystem_t 331 /* Compute limits for indirect block levels 332 * TODO: compute this once when loading filesystem and store in ext2_filesystem_t 333 */ 325 334 block_ids_per_block = ext2_superblock_get_block_size(fs->superblock) / sizeof(uint32_t); 326 335 limits[0] = EXT2_INODE_DIRECT_BLOCKS; … … 332 341 } 333 342 334 / / Determine the indirection level needed to get the desired block343 /* Determine the indirection level needed to get the desired block */ 335 344 level = -1; 336 345 for (i = 1; i < 4; i++) { … … 345 354 } 346 355 356 /* Compute offsets for the topmost level */ 347 357 block_offset_in_level = iblock - limits[level-1]; 348 358 current_block = ext2_inode_get_indirect_block(inode, level-1); 349 359 offset_in_block = block_offset_in_level / blocks_per_level[level-1]; 350 360 361 /* Navigate through other levels, until we find the block number 362 * or find null reference meaning we are dealing with sparse file 363 */ 351 364 while (level > 0) { 352 365 rc = block_get(&block, fs->device, current_block, 0); … … 364 377 365 378 if (current_block == 0) { 379 /* This is a sparse file */ 366 380 *fblock = 0; 367 381 return EOK; … … 370 384 level -= 1; 371 385 386 /* If we are on the last level, break here as 387 * there is no next level to visit 388 */ 372 389 if (level == 0) { 373 390 break; 374 391 } 375 392 393 /* Visit the next level */ 376 394 block_offset_in_level %= blocks_per_level[level]; 377 395 offset_in_block = block_offset_in_level / blocks_per_level[level-1]; … … 385 403 /** 386 404 * Allocate a given number of blocks and store their ids in blocks 405 * 406 * @todo TODO: This function is not finished and really has never been 407 * used (and tested) yet 387 408 * 388 409 * @param fs pointer to filesystem … … 420 441 idx = 0; 421 442 422 / / Read the block group descriptor443 /* Read the block group descriptor */ 423 444 rc = ext2_filesystem_get_block_group_ref(fs, block_group, &bg); 424 445 if (rc != EOK) { … … 444 465 } 445 466 446 / / We found a block group with free block, let's look at the block bitmap467 /* We found a block group with free block, let's look at the block bitmap */ 447 468 bb_block = ext2_block_group_get_block_bitmap_block(bg->block_group); 448 469 … … 452 473 } 453 474 454 / / Use all blocks from this block group475 /* Use all blocks from this block group */ 455 476 for (bb_idx = 0; bb_idx < block_size && idx < count; bb_idx++) { 456 477 uint8_t *data = (uint8_t *) block->data; … … 458 479 continue; 459 480 } 460 / / find an empty bit481 /* find an empty bit */ 461 482 uint8_t mask; 462 483 for (mask = 1, bb_bit = 0;
Note:
See TracChangeset
for help on using the changeset viewer.