Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 8060341a in mainline


Ignore:
Timestamp:
2012-05-15T13:27:43Z (9 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
master
Children:
15b794d
Parents:
f2eece1
Message:

filesystem code comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_filesystem.c

    rf2eece1 r8060341a  
    821821}
    822822
    823 /** TODO comment
    824  *
     823/** Set physical block address for the block logical address into the i-node.
     824 *
     825 * @param inode_ref             i-node to set block address to
     826 * @param iblock                logical index of block
     827 * @param fblock                physical block address
     828 * @return                              error code
    825829 */
    826830int ext4_filesystem_set_inode_data_block_index(ext4_inode_ref_t *inode_ref,
     
    831835        ext4_filesystem_t *fs = inode_ref->fs;
    832836
    833         /* Handle inode using extents */
     837        // Handle inode using extents
    834838        if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    835839                        ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
     
    838842        }
    839843
    840         /* Handle simple case when we are dealing with direct reference */
     844        // Handle simple case when we are dealing with direct reference
    841845        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    842846                ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock);
     
    845849        }
    846850
    847         /* Determine the indirection level needed to get the desired block */
     851        // Determine the indirection level needed to get the desired block
    848852        int level = -1;
    849853        for (int i = 1; i < 4; i++) {
     
    860864        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    861865
    862         /* Compute offsets for the topmost level */
     866        // Compute offsets for the topmost level
    863867        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    864868        uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
     
    868872        block_t *block, *new_block;
    869873
     874        // Is needed to allocate indirect block on the i-node level
    870875        if (current_block == 0) {
     876
     877                // Allocate new indirect block
    871878                rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    872879                if (rc != EOK) {
     
    874881                }
    875882
     883                // Update i-node
    876884                ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
    877 
    878885                inode_ref->dirty = true;
    879886
     887                // Load newly allocated block
    880888                rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    881889                if (rc != EOK) {
     
    884892                }
    885893
     894                // Initialize new block
    886895                memset(new_block->data, 0, block_size);
    887896                new_block->dirty = true;
    888897
     898                // Put back the allocated block
    889899                rc = block_put(new_block);
    890900                if (rc != EOK) {
     
    908918
    909919                if ((level > 1) && (current_block == 0)) {
     920
     921                        // Allocate new block
    910922                        rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    911923                        if (rc != EOK) {
     
    914926                        }
    915927
     928                        // Load newly allocated block
    916929                        rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    917930                        if (rc != EOK) {
     
    920933                        }
    921934
     935                        // Initialize allocated block
    922936                        memset(new_block->data, 0, block_size);
    923937                        new_block->dirty = true;
     
    929943                        }
    930944
     945                        // Write block address to the parent
    931946                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(new_block_addr);
    932947                        block->dirty = true;
     
    934949                }
    935950
     951                // Will be finished, write the fblock address
    936952                if (level == 1) {
    937953                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(fblock);
     
    961977}
    962978
    963 /** TODO comment
    964  *
     979/** Release data block from i-node
     980 *
     981 * @param inode_ref     i-node to release block from
     982 * @param iblock                logical block to be released
     983 * @return                              error code
    965984 */
    966985int ext4_filesystem_release_inode_block(
     
    973992        ext4_filesystem_t *fs = inode_ref->fs;
    974993
    975         // EXTENTS are handled otherwise
     994        // EXTENTS are handled otherwise = there is not support in this function
    976995        assert(! (ext4_superblock_has_feature_incompatible(fs->superblock,
    977996                        EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     
    980999        ext4_inode_t *inode = inode_ref->inode;
    9811000
    982         /* Handle simple case when we are dealing with direct reference */
     1001        // Handle simple case when we are dealing with direct reference
    9831002        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    9841003                fblock = ext4_inode_get_direct_block(inode, iblock);
     
    9931012
    9941013
    995         /* Determine the indirection level needed to get the desired block */
     1014        // Determine the indirection level needed to get the desired block
    9961015        int level = -1;
    9971016        for (int i = 1; i < 4; i++) {
     
    10061025        }
    10071026
    1008         /* Compute offsets for the topmost level */
     1027        // Compute offsets for the topmost level
    10091028        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    10101029        uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
     
    10231042                current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
    10241043
    1025                 // Set zero
     1044                // Set zero if physical data block address found
    10261045                if (level == 1) {
    10271046                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0);
     
    10531072                return EOK;
    10541073        }
     1074
     1075        // Physical block is not referenced, it can be released
    10551076
    10561077        return ext4_balloc_free_block(inode_ref, fblock);
Note: See TracChangeset for help on using the changeset viewer.