Changeset 06d85e5 in mainline for uspace/lib/ext4/libext4_filesystem.c


Ignore:
Timestamp:
2012-06-18T11:09:34Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2616a75b
Parents:
9a487cc
Message:

Most of comments modified by current coding style

File:
1 edited

Legend:

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

    r9a487cc r06d85e5  
    5353        fs->device = service_id;
    5454
    55         // Initialize block library (4096 is size of communication channel)
     55        /* Initialize block library (4096 is size of communication channel) */
    5656        rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096);
    5757        if (rc != EOK) {
     
    6060        }
    6161
    62         // Read superblock from device to memory
     62        /* Read superblock from device to memory */
    6363        ext4_superblock_t *temp_superblock;
    6464        rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
     
    6969        }
    7070
    71         // Read block size from superblock and check
     71        /* Read block size from superblock and check */
    7272        uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
    7373        if (block_size > EXT4_MAX_BLOCK_SIZE) {
     
    7777        }
    7878
    79         // Initialize block caching by libblock
     79        /* Initialize block caching by libblock */
    8080        rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
    8181        if (rc != EOK) {
     
    8585        }
    8686
    87         // Compute limits for indirect block levels
     87        /* Compute limits for indirect block levels */
    8888        uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
    8989        fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
     
    9696        }
    9797
    98         // Return loaded superblock
     98        /* Return loaded superblock */
    9999        fs->superblock = temp_superblock;
    100100
     
    108108        }
    109109
    110         // Mark system as mounted
     110        /* Mark system as mounted */
    111111        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);
    112112        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
     
    131131        int rc = EOK;
    132132
    133         // Write the superblock to the device
     133        /* Write the superblock to the device */
    134134        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_VALID_FS);
    135135        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    136136
    137         // Release memory space for superblock
     137        /* Release memory space for superblock */
    138138        free(fs->superblock);
    139139
    140         // Finish work with block library
     140        /* Finish work with block library */
    141141        block_fini(fs->device);
    142142
     
    155155        int rc;
    156156
    157         // Check superblock
     157        /* Check superblock */
    158158        rc = ext4_superblock_check_sanity(fs->superblock);
    159159        if (rc != EOK) {
     
    176176int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only)
    177177{
    178         // Feature flags are present only in higher revisions
     178        /* Feature flags are present only in higher revisions */
    179179        if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
    180180                *read_only = false;
     
    182182        }
    183183
    184         // Check incompatible features - if filesystem has some,
    185         // volume can't be mounted
     184        /* Check incompatible features - if filesystem has some,
     185         * volume can't be mounted
     186         */
    186187        uint32_t incompatible_features;
    187188        incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
     
    191192        }
    192193
    193         // Check read-only features, if filesystem has some,
    194         // volume can be mount only in read-only mode
     194        /* Check read-only features, if filesystem has some,
     195         * volume can be mount only in read-only mode
     196         */
    195197        uint32_t compatible_read_only;
    196198        compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
     
    216218        int rc;
    217219
    218         // Allocate memory for new structure
     220        /* Allocate memory for new structure */
    219221        ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t));
    220222        if (newref == NULL) {
     
    222224        }
    223225
    224         // Compute number of descriptors, that fits in one data block
     226        /* Compute number of descriptors, that fits in one data block */
    225227        uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
    226228            / ext4_superblock_get_desc_size(fs->superblock);
    227229
    228         // Block group descriptor table starts at the next block after superblock
     230        /* Block group descriptor table starts at the next block after superblock */
    229231        aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
    230232
    231         // Find the block containing the descriptor we are looking for
     233        /* Find the block containing the descriptor we are looking for */
    232234        block_id += bgid / descriptors_per_block;
    233235        uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock);
    234236
    235         // Load block with descriptors
     237        /* Load block with descriptors */
    236238        rc = block_get(&newref->block, fs->device, block_id, 0);
    237239        if (rc != EOK) {
     
    240242        }
    241243
    242         // Inititialize in-memory representation
     244        /* Inititialize in-memory representation */
    243245        newref->block_group = newref->block->data + offset;
    244246        newref->fs = fs;
     
    263265                            ext4_block_group_t *bg)
    264266{
    265         // If checksum not supported, 0 will be returned
     267        /* If checksum not supported, 0 will be returned */
    266268        uint16_t crc = 0;
    267269
    268         // Compute the checksum only if the filesystem supports it
     270        /* Compute the checksum only if the filesystem supports it */
    269271        if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
    270272
     
    274276                uint32_t offset = (uint32_t)(checksum - base);
    275277
    276                 // Convert block group index to little endian
     278                /* Convert block group index to little endian */
    277279                uint32_t le_group = host2uint32_t_le(bgid);
    278280
    279                 // Initialization
     281                /* Initialization */
    280282                crc = crc16(~0, sb->uuid, sizeof(sb->uuid));
    281283
    282                 // Include index of block group
     284                /* Include index of block group */
    283285                crc = crc16(crc, (uint8_t *)&le_group, sizeof(le_group));
    284286
    285                 // Compute crc from the first part (stop before checksum field)
     287                /* Compute crc from the first part (stop before checksum field) */
    286288                crc = crc16(crc, (uint8_t *)bg, offset);
    287289
    288                 // Skip checksum
     290                /* Skip checksum */
    289291                offset += sizeof(bg->checksum);
    290292
    291                 // Checksum of the rest of block group descriptor
     293                /* Checksum of the rest of block group descriptor */
    292294                if ((ext4_superblock_has_feature_incompatible(sb, EXT4_FEATURE_INCOMPAT_64BIT)) &&
    293295                        offset < ext4_superblock_get_desc_size(sb)) {
     
    310312        int rc;
    311313
    312         // Check if reference modified
     314        /* Check if reference modified */
    313315        if (ref->dirty) {
    314316
    315                 // Compute new checksum of block group
     317                /* Compute new checksum of block group */
    316318                uint16_t checksum = ext4_filesystem_bg_checksum(
    317319                                ref->fs->superblock, ref->index, ref->block_group);
    318320                ext4_block_group_set_checksum(ref->block_group, checksum);
    319321
    320                 // Mark block dirty for writing changes to physical device
     322                /* Mark block dirty for writing changes to physical device */
    321323                ref->block->dirty = true;
    322324        }
    323325
    324         // Put back block, that contains block group descriptor
     326        /* Put back block, that contains block group descriptor */
    325327        rc = block_put(ref->block);
    326328        free(ref);
     
    341343        int rc;
    342344
    343         // Allocate memory for new structure
     345        /* Allocate memory for new structure */
    344346        ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t));
    345347        if (newref == NULL) {
     
    347349        }
    348350
    349         // Compute number of i-nodes, that fits in one data block
     351        /* Compute number of i-nodes, that fits in one data block */
    350352        uint32_t inodes_per_group =
    351353                        ext4_superblock_get_inodes_per_group(fs->superblock);
    352354
    353         /*
    354          * inode numbers are 1-based, but it is simpler to work with 0-based
     355        /* Inode numbers are 1-based, but it is simpler to work with 0-based
    355356         * when computing indices
    356357         */
     
    359360        uint32_t offset_in_group = index % inodes_per_group;
    360361
    361         // Load block group, where i-node is located
     362        /* Load block group, where i-node is located */
    362363        ext4_block_group_ref_t *bg_ref;
    363364        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     
    367368        }
    368369
    369         // Load block address, where i-node table is located
     370        /* Load block address, where i-node table is located */
    370371        uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block(
    371372            bg_ref->block_group, fs->superblock);
    372373
    373         // Put back block group reference (not needed more)
     374        /* Put back block group reference (not needed more) */
    374375        rc = ext4_filesystem_put_block_group_ref(bg_ref);
    375376        if (rc != EOK) {
     
    378379        }
    379380
    380         // Compute position of i-node in the block group
     381        /* Compute position of i-node in the block group */
    381382        uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock);
    382383        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    383384        uint32_t byte_offset_in_group = offset_in_group * inode_size;
    384385
    385         // Compute block address
     386        /* Compute block address */
    386387        aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
    387388        rc = block_get(&newref->block, fs->device, block_id, 0);
     
    391392        }
    392393
    393         // Compute position of i-node in the data block
     394        /* Compute position of i-node in the data block */
    394395        uint32_t offset_in_block = byte_offset_in_group % block_size;
    395396        newref->inode = newref->block->data + offset_in_block;
    396397
    397         // We need to store the original value of index in the reference
     398        /* We need to store the original value of index in the reference */
    398399        newref->index = index + 1;
    399400        newref->fs = fs;
     
    414415        int rc;
    415416
    416         // Check if reference modified
     417        /* Check if reference modified */
    417418        if (ref->dirty) {
    418419
    419                 // Mark block dirty for writing changes to physical device
     420                /* Mark block dirty for writing changes to physical device */
    420421                ref->block->dirty = true;
    421422        }
    422423
    423         // Put back block, that contains i-node
     424        /* Put back block, that contains i-node */
    424425        rc = block_put(ref->block);
    425426        free(ref);
     
    440441        int rc;
    441442
    442         // Check if newly allocated i-node will be a directory
     443        /* Check if newly allocated i-node will be a directory */
    443444        bool is_dir = false;
    444445        if (flags & L_DIRECTORY) {
     
    446447        }
    447448
    448         // Allocate inode by allocation algorithm
     449        /* Allocate inode by allocation algorithm */
    449450        uint32_t index;
    450451        rc = ext4_ialloc_alloc_inode(fs, &index, is_dir);
     
    453454        }
    454455
    455         // Load i-node from on-disk i-node table
     456        /* Load i-node from on-disk i-node table */
    456457        rc = ext4_filesystem_get_inode_ref(fs, index, inode_ref);
    457458        if (rc != EOK) {
     
    460461        }
    461462
    462         // Initialize i-node
     463        /* Initialize i-node */
    463464        ext4_inode_t *inode = (*inode_ref)->inode;
    464465
    465466        if (is_dir) {
    466467                ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_DIRECTORY);
    467                 ext4_inode_set_links_count(inode, 1); // '.' entry
     468                ext4_inode_set_links_count(inode, 1); /* '.' entry */
    468469        } else {
    469470                ext4_inode_set_mode(fs->superblock, inode, EXT4_INODE_MODE_FILE);
     
    482483        ext4_inode_set_generation(inode, 0);
    483484
    484         // Reset blocks array
     485        /* Reset blocks array */
    485486        for (uint32_t i = 0; i < EXT4_INODE_BLOCKS; i++) {
    486487                inode->blocks[i] = 0;
    487488        }
    488489
    489         // Initialize extents if needed
     490        /* Initialize extents if needed */
    490491        if (ext4_superblock_has_feature_incompatible(
    491492                        fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
     
    493494                ext4_inode_set_flag(inode, EXT4_INODE_FLAG_EXTENTS);
    494495
    495                 // Initialize extent root header
     496                /* Initialize extent root header */
    496497                ext4_extent_header_t *header = ext4_inode_get_extent_header(inode);
    497498                ext4_extent_header_set_depth(header, 0);
     
    522523        ext4_filesystem_t *fs = inode_ref->fs;
    523524
    524         // For extents must be data block destroyed by other way
     525        /* For extents must be data block destroyed by other way */
    525526        if (ext4_superblock_has_feature_incompatible(
    526527                        fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    527528                                ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    528529
    529                 // Data structures are released during truncate operation...
     530                /* Data structures are released during truncate operation... */
    530531                goto finish;
    531532        }
    532533
    533         // Release all indirect (no data) blocks
    534 
    535         // 1) Single indirect
     534        /* Release all indirect (no data) blocks */
     535
     536        /* 1) Single indirect */
    536537        uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0);
    537538        if (fblock != 0) {
     
    548549        uint32_t count = block_size / sizeof(uint32_t);
    549550
    550         // 2) Double indirect
     551        /* 2) Double indirect */
    551552        fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);
    552553        if (fblock != 0) {
     
    579580
    580581
    581         // 3) Tripple indirect
     582        /* 3) Tripple indirect */
    582583        block_t *subblock;
    583584        fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);
     
    637638finish:
    638639
    639         // Mark inode dirty for writing to the physical device
     640        /* Mark inode dirty for writing to the physical device */
    640641        inode_ref->dirty = true;
    641642
    642         // Free inode by allocator
     643        /* Free inode by allocator */
    643644        if (ext4_inode_is_type(fs->superblock, inode_ref->inode,
    644645                        EXT4_INODE_MODE_DIRECTORY)) {
     
    667668        ext4_superblock_t *sb = inode_ref->fs->superblock;
    668669
    669         // Check flags, if i-node can be truncated
     670        /* Check flags, if i-node can be truncated */
    670671        if (! ext4_inode_can_truncate(sb, inode_ref->inode)) {
    671672                return EINVAL;
    672673        }
    673674
    674         // If sizes are equal, nothing has to be done.
     675        /* If sizes are equal, nothing has to be done. */
    675676        aoff64_t old_size = ext4_inode_get_size(sb, inode_ref->inode);
    676677        if (old_size == new_size) {
     
    678679        }
    679680
    680         // It's not suppported to make the larger file by truncate operation
     681        /* It's not suppported to make the larger file by truncate operation */
    681682        if (old_size < new_size) {
    682683                return EINVAL;
    683684        }
    684685
    685         // Compute how many blocks will be released
     686        /* Compute how many blocks will be released */
    686687        aoff64_t size_diff = old_size - new_size;
    687688        uint32_t block_size  = ext4_superblock_get_block_size(sb);
     
    700701                                ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    701702
    702                 // Extents require special operation
     703                /* Extents require special operation */
    703704
    704705                rc = ext4_extent_release_blocks_from(inode_ref,
     
    709710        } else {
    710711
    711                 // Release data blocks from the end of file
    712 
    713                 // Starting from 1 because of logical blocks are numbered from 0
     712                /* Release data blocks from the end of file */
     713
     714                /* Starting from 1 because of logical blocks are numbered from 0 */
    714715                for (uint32_t i = 1; i <= diff_blocks_count; ++i) {
    715716                        rc = ext4_filesystem_release_inode_block(inode_ref, old_blocks_count - i);
     
    720721        }
    721722
    722         // Update i-node
     723        /* Update i-node */
    723724        ext4_inode_set_size(inode_ref->inode, new_size);
    724725        inode_ref->dirty = true;
     
    741742        ext4_filesystem_t *fs = inode_ref->fs;
    742743
    743         // For empty file is situation simple
     744        /* For empty file is situation simple */
    744745        if (ext4_inode_get_size(fs->superblock, inode_ref->inode) == 0) {
    745746                *fblock = 0;
     
    749750        uint32_t current_block;
    750751
    751         // Handle i-node using extents
     752        /* Handle i-node using extents */
    752753        if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    753754                        ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
     
    766767        ext4_inode_t *inode = inode_ref->inode;
    767768
    768         // Direct block are read directly from array in i-node structure
     769        /* Direct block are read directly from array in i-node structure */
    769770        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    770771                current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
     
    773774        }
    774775
    775         // Determine indirection level of the target block
     776        /* Determine indirection level of the target block */
    776777        int level = -1;
    777778        for (int i = 1; i < 4; i++) {
     
    786787        }
    787788
    788         // Compute offsets for the topmost level
     789        /* Compute offsets for the topmost level */
    789790        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    790791        current_block = ext4_inode_get_indirect_block(inode, level-1);
    791792        uint32_t offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
    792793
    793         // Sparse file
     794        /* Sparse file */
    794795        if (current_block == 0) {
    795796                *fblock = 0;
     
    804805        while (level > 0) {
    805806
    806                 // Load indirect block
     807                /* Load indirect block */
    807808                rc = block_get(&block, fs->device, current_block, 0);
    808809                if (rc != EOK) {
     
    810811                }
    811812
    812                 // Read block address from indirect block
     813                /* Read block address from indirect block */
    813814                current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
    814815
    815                 // Put back indirect block untouched
     816                /* Put back indirect block untouched */
    816817                rc = block_put(block);
    817818                if (rc != EOK) {
     
    819820                }
    820821
    821                 // Check for sparse file
     822                /* Check for sparse file */
    822823                if (current_block == 0) {
    823824                        *fblock = 0;
     
    825826                }
    826827
    827                 // Jump to the next level
     828                /* Jump to the next level */
    828829                level -= 1;
    829830
    830                 // Termination condition - we have address of data block loaded
     831                /* Termination condition - we have address of data block loaded */
    831832                if (level == 0) {
    832833                        break;
    833834                }
    834835
    835                 // Visit the next level
     836                /* Visit the next level */
    836837                block_offset_in_level %= fs->inode_blocks_per_level[level];
    837838                offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     
    857858        ext4_filesystem_t *fs = inode_ref->fs;
    858859
    859         // Handle inode using extents
     860        /* Handle inode using extents */
    860861        if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
    861862                        ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
    862                 // not reachable !!!
     863                /* not reachable !!! */
    863864                return ENOTSUP;
    864865        }
    865866
    866         // Handle simple case when we are dealing with direct reference
     867        /* Handle simple case when we are dealing with direct reference */
    867868        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    868869                ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock);
     
    871872        }
    872873
    873         // Determine the indirection level needed to get the desired block
     874        /* Determine the indirection level needed to get the desired block */
    874875        int level = -1;
    875876        for (int i = 1; i < 4; i++) {
     
    886887        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
    887888
    888         // Compute offsets for the topmost level
     889        /* Compute offsets for the topmost level */
    889890        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    890891        uint32_t current_block = ext4_inode_get_indirect_block(inode_ref->inode, level-1);
     
    894895        block_t *block, *new_block;
    895896
    896         // Is needed to allocate indirect block on the i-node level
     897        /* Is needed to allocate indirect block on the i-node level */
    897898        if (current_block == 0) {
    898899
    899                 // Allocate new indirect block
     900                /* Allocate new indirect block */
    900901                rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    901902                if (rc != EOK) {
     
    903904                }
    904905
    905                 // Update i-node
     906                /* Update i-node */
    906907                ext4_inode_set_indirect_block(inode_ref->inode, level - 1, new_block_addr);
    907908                inode_ref->dirty = true;
    908909
    909                 // Load newly allocated block
     910                /* Load newly allocated block */
    910911                rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    911912                if (rc != EOK) {
     
    914915                }
    915916
    916                 // Initialize new block
     917                /* Initialize new block */
    917918                memset(new_block->data, 0, block_size);
    918919                new_block->dirty = true;
    919920
    920                 // Put back the allocated block
     921                /* Put back the allocated block */
    921922                rc = block_put(new_block);
    922923                if (rc != EOK) {
     
    941942                if ((level > 1) && (current_block == 0)) {
    942943
    943                         // Allocate new block
     944                        /* Allocate new block */
    944945                        rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr);
    945946                        if (rc != EOK) {
     
    948949                        }
    949950
    950                         // Load newly allocated block
     951                        /* Load newly allocated block */
    951952                        rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD);
    952953                        if (rc != EOK) {
     
    955956                        }
    956957
    957                         // Initialize allocated block
     958                        /* Initialize allocated block */
    958959                        memset(new_block->data, 0, block_size);
    959960                        new_block->dirty = true;
     
    965966                        }
    966967
    967                         // Write block address to the parent
     968                        /* Write block address to the parent */
    968969                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(new_block_addr);
    969970                        block->dirty = true;
     
    971972                }
    972973
    973                 // Will be finished, write the fblock address
     974                /* Will be finished, write the fblock address */
    974975                if (level == 1) {
    975976                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(fblock);
     
    10141015        ext4_filesystem_t *fs = inode_ref->fs;
    10151016
    1016         // EXTENTS are handled otherwise = there is not support in this function
     1017        /* EXTENTS are handled otherwise = there is not support in this function */
    10171018        assert(! (ext4_superblock_has_feature_incompatible(fs->superblock,
    10181019                        EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     
    10211022        ext4_inode_t *inode = inode_ref->inode;
    10221023
    1023         // Handle simple case when we are dealing with direct reference
     1024        /* Handle simple case when we are dealing with direct reference */
    10241025        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    10251026                fblock = ext4_inode_get_direct_block(inode, iblock);
    1026                 // Sparse file
     1027                /* Sparse file */
    10271028                if (fblock == 0) {
    10281029                        return EOK;
     
    10341035
    10351036
    1036         // Determine the indirection level needed to get the desired block
     1037        /* Determine the indirection level needed to get the desired block */
    10371038        int level = -1;
    10381039        for (int i = 1; i < 4; i++) {
     
    10471048        }
    10481049
    1049         // Compute offsets for the topmost level
     1050        /* Compute offsets for the topmost level */
    10501051        aoff64_t block_offset_in_level = iblock - fs->inode_block_limits[level-1];
    10511052        uint32_t current_block = ext4_inode_get_indirect_block(inode, level-1);
     
    10641065                current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
    10651066
    1066                 // Set zero if physical data block address found
     1067                /* Set zero if physical data block address found */
    10671068                if (level == 1) {
    10681069                        ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0);
     
    10951096        }
    10961097
    1097         // Physical block is not referenced, it can be released
     1098        /* Physical block is not referenced, it can be released */
    10981099
    10991100        return ext4_balloc_free_block(inode_ref, fblock);
     
    11131114        int rc;
    11141115
    1115         // Handle extents separately
     1116        /* Handle extents separately */
    11161117        if (ext4_superblock_has_feature_incompatible(
    11171118                        inode_ref->fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     
    11241125        ext4_superblock_t *sb = inode_ref->fs->superblock;
    11251126
    1126         // Compute next block index and allocate data block
     1127        /* Compute next block index and allocate data block */
    11271128        uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
    11281129        uint32_t block_size = ext4_superblock_get_block_size(sb);
    11291130
    1130         // Align size i-node size
     1131        /* Align size i-node size */
    11311132        if ((inode_size % block_size) != 0) {
    11321133                inode_size += block_size - (inode_size % block_size);
    11331134        }
    11341135
    1135         // Logical blocks are numbered from 0
     1136        /* Logical blocks are numbered from 0 */
    11361137        uint32_t new_block_idx = inode_size / block_size;
    11371138
    1138         // Allocate new physical block
     1139        /* Allocate new physical block */
    11391140        uint32_t phys_block;
    11401141        rc =  ext4_balloc_alloc_block(inode_ref, &phys_block);
     
    11431144        }
    11441145
    1145         // Add physical block address to the i-node
     1146        /* Add physical block address to the i-node */
    11461147        rc = ext4_filesystem_set_inode_data_block_index(inode_ref, new_block_idx, phys_block);
    11471148        if (rc != EOK) {
     
    11501151        }
    11511152
    1152         // Update i-node
     1153        /* Update i-node */
    11531154        ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
    11541155        inode_ref->dirty = true;
     
    11731174                        inode_ref->fs->superblock);
    11741175
    1175         // Deletion time is used for holding next item of the list
     1176        /* Deletion time is used for holding next item of the list */
    11761177        ext4_inode_set_deletion_time(inode_ref->inode, next_orphan);
    11771178
    1178         // Head of the list is in the superblock
     1179        /* Head of the list is in the superblock */
    11791180        ext4_superblock_set_last_orphan(
    11801181                        inode_ref->fs->superblock, inode_ref->index);
     
    11961197        int rc;
    11971198
    1198         // Get head of the linked list
     1199        /* Get head of the linked list */
    11991200        uint32_t last_orphan = ext4_superblock_get_last_orphan(
    12001201                        inode_ref->fs->superblock);
     
    12101211        uint32_t next_orphan = ext4_inode_get_deletion_time(current->inode);
    12111212
    1212         // Check if the head is the target
     1213        /* Check if the head is the target */
    12131214        if (last_orphan == inode_ref->index) {
    12141215                ext4_superblock_set_last_orphan(inode_ref->fs->superblock, next_orphan);
    1215 //              ext4_inode_set_deletion_time(inode_ref->inode, 0);
    1216 //              inode_ref->dirty = true;
    12171216                return EOK;
    12181217        }
     
    12201219        bool found = false;
    12211220
    1222         // Walk thourgh the linked list
     1221        /* Walk thourgh the linked list */
    12231222        while (next_orphan != 0) {
    12241223
    1225                 // Found?
     1224                /* Found? */
    12261225                if (next_orphan == inode_ref->index) {
    12271226                        next_orphan = ext4_inode_get_deletion_time(inode_ref->inode);
    12281227                        ext4_inode_set_deletion_time(current->inode, next_orphan);
    1229 //                      ext4_inode_set_deletion_time(inode_ref->inode, 0);
    1230 //                      inode_ref->dirty = true;
    12311228                        current->dirty = true;
    12321229                        found = true;
Note: See TracChangeset for help on using the changeset viewer.