Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/libext2_directory.c

    r911ee54 r18626b3  
    4040#include <assert.h>
    4141
    42 static int ext2_directory_iterator_set(ext2_directory_iterator_t *it,
    43     uint32_t block_size);
    44 
    4542/**
    4643 * Get inode number for the directory entry
     
    9390        int rc;
    9491        uint32_t block_id;
    95         uint32_t block_size;
    96        
    9792        it->inode_ref = inode_ref;
    9893        it->fs = fs;
    9994       
    100         /* Get the first data block, so we can get the first entry */
     95        // Get the first data block, so we can get first entry
    10196        rc = ext2_filesystem_get_inode_data_block_index(fs, inode_ref->inode, 0,
    10297            &block_id);
     
    110105        }
    111106       
    112         block_size = ext2_superblock_get_block_size(fs->superblock);
    113        
    114         it->current_offset = 0;
    115         return ext2_directory_iterator_set(it, block_size);
     107        it->current = it->current_block->data;
     108        it->current_offset = 0;
     109       
     110        return EOK;
    116111}
    117112
     
    131126        uint32_t next_block_phys_idx;
    132127        uint32_t block_size;
     128        uint32_t offset_in_block;
    133129       
    134130        assert(it->current != NULL);
     
    137133        size = ext2_inode_get_size(it->fs->superblock, it->inode_ref->inode);
    138134       
    139         /* Are we at the end? */
     135        // Are we at the end?
    140136        if (it->current_offset + skip >= size) {
    141137                rc = block_put(it->current_block);
     
    154150        next_block_idx = (it->current_offset + skip) / block_size;
    155151       
    156         /* If we are moving accross block boundary,
    157          * we need to get another block
    158          */
     152        // If we are moving accross block boundary,
     153        // we need to get another block
    159154        if (current_block_idx != next_block_idx) {
    160155                rc = block_put(it->current_block);
     
    179174        }
    180175       
     176        offset_in_block = (it->current_offset + skip) % block_size;
     177       
     178        // Ensure proper alignment
     179        if ((offset_in_block % 4) != 0) {
     180                it->current = NULL;
     181                return EIO;
     182        }
     183       
     184        // Ensure that the core of the entry does not overflow the block
     185        if (offset_in_block > block_size - 8) {
     186                it->current = NULL;
     187                return EIO;
     188        }
     189               
     190        it->current = it->current_block->data + offset_in_block;
    181191        it->current_offset += skip;
    182         return ext2_directory_iterator_set(it, block_size);
    183 }
    184 
    185 static int ext2_directory_iterator_set(ext2_directory_iterator_t *it,
    186     uint32_t block_size)
    187 {
    188         uint32_t offset_in_block = it->current_offset % block_size;
    189        
    190         it->current = NULL;
    191        
    192         /* Ensure proper alignment */
    193         if ((offset_in_block % 4) != 0) {
    194                 return EIO;
    195         }
    196        
    197         /* Ensure that the core of the entry does not overflow the block */
    198         if (offset_in_block > block_size - 8) {
    199                 return EIO;
    200         }
    201        
    202         ext2_directory_entry_ll_t *entry = it->current_block->data + offset_in_block;
    203        
    204         /* Ensure that the whole entry does not overflow the block */
    205         uint16_t length = ext2_directory_entry_ll_get_entry_length(entry);
    206         if (offset_in_block + length > block_size) {
    207                 return EIO;
    208         }
    209        
    210         /* Ensure the name length is not too large */
     192       
     193        // Ensure that the whole entry does not overflow the block
     194        skip = ext2_directory_entry_ll_get_entry_length(it->current);
     195        if (offset_in_block + skip > block_size) {
     196                it->current = NULL;
     197                return EIO;
     198        }
     199       
     200        // Ensure the name length is not too large
    211201        if (ext2_directory_entry_ll_get_name_length(it->fs->superblock,
    212             entry) > length-8) {
    213                 return EIO;
    214         }
    215        
    216         it->current = entry;
     202            it->current) > skip-8) {
     203                it->current = NULL;
     204                return EIO;
     205        }
     206       
    217207        return EOK;
    218208}
Note: See TracChangeset for help on using the changeset viewer.