Changeset 5b26747 in mainline


Ignore:
Timestamp:
2012-05-08T08:03:02Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bed78cb
Parents:
3169f3b0
Message:

More comments - mostly by filesystem operations

Location:
uspace/lib/ext4
Files:
3 edited

Legend:

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

    r3169f3b0 r5b26747  
    4141#include "libext4.h"
    4242
    43 /** TODO comment
    44  *
     43/** Initialize filesystem and read all needed data.
     44 *
     45 * @param fs                            filesystem instance to be initialized
     46 * @param service_id            identifier if device with the filesystem
     47 * @return                                      error code
    4548 */
    4649int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id)
     
    5053        fs->device = service_id;
    5154
     55        // Initialize block library (4096 is size of communication channel)
    5256        rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096);
    5357        if (rc != EOK) {
     
    5559        }
    5660
    57         /* Read superblock from device */
     61        // Read superblock from device to memory
    5862        ext4_superblock_t *temp_superblock;
    5963        rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
     
    6367        }
    6468
    65         /* Read block size from superblock and check */
     69        // Read block size from superblock and check
    6670        uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
    6771        if (block_size > EXT4_MAX_BLOCK_SIZE) {
     
    7074        }
    7175
    72         /* Initialize block caching */
     76        // Initialize block caching by libblock
    7377        rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
    7478        if (rc != EOK) {
     
    7781        }
    7882
     83        // Compute limits for indirect block levels
    7984        uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
    8085        fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
     
    8792        }
    8893
    89         /* Return loaded superblock */
     94        // Return loaded superblock
    9095        fs->superblock = temp_superblock;
    9196
     
    9398}
    9499
    95 /** TODO comment
    96  *
     100/** Destroy filesystem instance (used by unmount operation).
     101 *
     102 * @param fs            filesystem to be destroyed
     103 * @param write_sb      flag if superblock should be written to device
     104 * @return                      error code
    97105 */
    98106int ext4_filesystem_fini(ext4_filesystem_t *fs, bool write_sb)
     
    100108        int rc = EOK;
    101109
     110        // If needed, write the superblock to the device
    102111        if (write_sb) {
    103112                rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    104113        }
    105114
     115        // Release memory space for superblock
    106116        free(fs->superblock);
     117
     118        // Finish work with block library
    107119        block_fini(fs->device);
    108120
     
    110122}
    111123
    112 /** TODO comment
    113  *
     124/** Check sanity of the filesystem.
     125 *
     126 * Main is the check of the superblock structure.
     127 *
     128 * @param fs            filesystem to be checked
     129 * @return                      error code
    114130 */
    115131int ext4_filesystem_check_sanity(ext4_filesystem_t *fs)
     
    117133        int rc;
    118134
     135        // Check superblock
    119136        rc = ext4_superblock_check_sanity(fs->superblock);
    120137        if (rc != EOK) {
     
    125142}
    126143
    127 /** TODO comment
    128  *
    129  */
    130 int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only)
    131 {
    132         /* Feature flags are present in rev 1 and later */
     144/** Check filesystem's features, if supported by this driver
     145 *
     146 * Function can return EOK and set read_only flag. It mean's that
     147 * there are some not-supported features, that can cause problems
     148 * during some write operations.
     149 *
     150 * @param fs                    filesystem to be checked
     151 * @param read_only             flag if filesystem should be mounted only for reading
     152 * @return                              error code
     153 */
     154int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only)
     155{
     156        // Feature flags are present only in higher revisions
    133157        if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
    134                 *o_read_only = false;
     158                *read_only = false;
    135159                return EOK;
    136160        }
    137161
     162        // Check incompatible features - if filesystem has some,
     163        // volume can't be mounted
    138164        uint32_t incompatible_features;
    139165        incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
    140166        incompatible_features &= ~EXT4_FEATURE_INCOMPAT_SUPP;
    141167        if (incompatible_features > 0) {
    142                 *o_read_only = true;
    143168                return ENOTSUP;
    144169        }
    145170
     171        // Check read-only features, if filesystem has some,
     172        // volume can be mount only in read-only mode
    146173        uint32_t compatible_read_only;
    147174        compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
    148175        compatible_read_only &= ~EXT4_FEATURE_RO_COMPAT_SUPP;
    149176        if (compatible_read_only > 0) {
    150                 *o_read_only = true;
    151         }
    152 
    153         return EOK;
    154 }
    155 
    156 /** TODO comment
    157  *
     177                *read_only = true;
     178                return EOK;
     179        }
     180
     181        return EOK;
     182}
     183
     184/** Get reference to block group specified by index.
     185 *
     186 * @param fs            filesystem to find block group on
     187 * @param bgid          index of block group to load
     188 * @oaram ref           output pointer for reference
     189 * @return                      error code
    158190 */
    159191int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid,
     
    162194        int rc;
    163195
     196        // Allocate memory for new structure
    164197        ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
    165198        if (newref == NULL) {
     
    167200        }
    168201
     202        // Compute number of descriptors, that fits in one data block
    169203        uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
    170204            / ext4_superblock_get_desc_size(fs->superblock);
    171205
    172         /* Block group descriptor table starts at the next block after superblock */
     206        // Block group descriptor table starts at the next block after superblock
    173207        aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
    174208
    175         /* Find the block containing the descriptor we are looking for */
     209        // Find the block containing the descriptor we are looking for
    176210        block_id += bgid / descriptors_per_block;
    177211        uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
    178212
     213        // Load block with descriptors
    179214        rc = block_get(&newref->block, fs->device, block_id, 0);
    180215        if (rc != EOK) {
     
    183218        }
    184219
     220        // Inititialize in-memory representation
    185221        newref->block_group = newref->block->data + offset;
    186222        newref->fs = fs;
     
    228264}
    229265
    230 /** TODO comment
    231  *
     266/** Put reference to block group.
     267 *
     268 * @oaram ref           pointer for reference to be put back
     269 * @return                      error code
    232270 */
    233271int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *ref)
     
    235273        int rc;
    236274
     275        // Check if reference modified
    237276        if (ref->dirty) {
     277
     278                // Compute new checksum of block group
    238279                uint16_t checksum = ext4_filesystem_bg_checksum(
    239280                                ref->fs->superblock, ref->index, ref->block_group);
    240 
    241281                ext4_block_group_set_checksum(ref->block_group, checksum);
    242282
     283                // Mark block dirty for writing changes to physical device
    243284                ref->block->dirty = true;
    244285        }
    245286
     287        // Put back block, that contains block group descriptor
    246288        rc = block_put(ref->block);
    247289        free(ref);
     
    250292}
    251293
    252 /** TODO comment
    253  *
     294/** Get reference to i-node specified by index.
     295 *
     296 * @param fs            filesystem to find i-node on
     297 * @param index         index of i-node to load
     298 * @oaram ref           output pointer for reference
     299 * @return                      error code
    254300 */
    255301int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index,
     
    258304        int rc;
    259305
     306        // Allocate memory for new structure
    260307        ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
    261308        if (newref == NULL) {
     
    263310        }
    264311
     312        // Compute number of i-nodes, that fits in one data block
    265313        uint32_t inodes_per_group =
    266314                        ext4_superblock_get_inodes_per_group(fs->superblock);
    267315
    268         /* inode numbers are 1-based, but it is simpler to work with 0-based
     316        /*
     317         * inode numbers are 1-based, but it is simpler to work with 0-based
    269318         * when computing indices
    270319         */
     
    273322        uint32_t offset_in_group = index % inodes_per_group;
    274323
     324        // Load block group, where i-node is located
    275325        ext4_block_group_ref_t *bg_ref;
    276326        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     
    280330        }
    281331
     332        // Load block address, where i-node table is located
    282333        uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
    283334            bg_ref->block_group, fs->superblock);
    284335
     336        // Put back block group reference (not needed more)
    285337        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    286338        if (rc != EOK) {
     
    289341        }
    290342
     343        // Compute position of i-node in the block group
    291344        uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
    292345        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    293346        uint32_t byte_offset_in_group = offset_in_group * inode_size;
    294347
     348        // Compute block address
    295349        aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
    296350        rc = block_get(&newref->block, fs->device, block_id, 0);
     
    300354        }
    301355
     356        // Compute position of i-node in the data block
    302357        uint32_t offset_in_block = byte_offset_in_group % block_size;
    303358        newref->inode = newref->block->data + offset_in_block;
    304         /* we decremented index above, but need to store the original value
    305          * in the reference
    306          */
     359
     360        // We need to store the original value of index in the reference
    307361        newref->index = index + 1;
    308362        newref->fs = fs;
  • uspace/lib/ext4/libext4_inode.c

    r3169f3b0 r5b26747  
    188188}
    189189
    190 /** TODO comment
    191  *
     190/** Get time, when i-node was deleted.
     191 *
     192 * @param inode         i-node
     193 * @return                      time of the delete action (POSIX)
    192194 */
    193195uint32_t ext4_inode_get_deletion_time(ext4_inode_t *inode)
     
    196198}
    197199
    198 /** TODO comment
    199  *
     200/** Set time, when i-node was deleted.
     201 *
     202 * @param inode         i-node
     203 * @param time          time of the delete action (POSIX)
    200204 */
    201205void ext4_inode_set_deletion_time(ext4_inode_t *inode, uint32_t time)
  • uspace/lib/ext4/libext4_superblock.c

    r3169f3b0 r5b26747  
    964964}
    965965
    966 /** TODO comment
    967  *
     966/** Check sanity of the superblock.
     967 *
     968 * This check is performed at mount time.
     969 * Checks are described by one-line comments in the code.
     970 *
     971 * @param sb            superblock to check
     972 * @return                      error code
    968973 */
    969974int ext4_superblock_check_sanity(ext4_superblock_t *sb)
Note: See TracChangeset for help on using the changeset viewer.