Changeset 95afd72 in mainline


Ignore:
Timestamp:
2011-06-03T21:51:10Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
911ee54
Parents:
d7c3367
Message:

Refactor checks in ext2_directory_iterator_next into a separate function

File:
1 edited

Legend:

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

    rd7c3367 r95afd72  
    4040#include <assert.h>
    4141
     42static int ext2_directory_iterator_set(ext2_directory_iterator_t *it,
     43    uint32_t block_size);
     44
    4245/**
    4346 * Get inode number for the directory entry
     
    126129        uint32_t next_block_phys_idx;
    127130        uint32_t block_size;
    128         uint32_t offset_in_block;
    129131       
    130132        assert(it->current != NULL);
     
    175177        }
    176178       
    177         offset_in_block = (it->current_offset + skip) % block_size;
     179        it->current_offset += skip;
     180       
     181        return ext2_directory_iterator_set(it, block_size);
     182}
     183
     184static int ext2_directory_iterator_set(ext2_directory_iterator_t *it,
     185    uint32_t block_size)
     186{
     187        uint32_t offset_in_block = it->current_offset % block_size;
     188       
     189        it->current = NULL;
    178190       
    179191        /* Ensure proper alignment */
    180192        if ((offset_in_block % 4) != 0) {
    181                 it->current = NULL;
    182193                return EIO;
    183194        }
     
    185196        /* Ensure that the core of the entry does not overflow the block */
    186197        if (offset_in_block > block_size - 8) {
    187                 it->current = NULL;
    188                 return EIO;
    189         }
    190                
    191         it->current = it->current_block->data + offset_in_block;
    192         it->current_offset += skip;
     198                return EIO;
     199        }
     200       
     201        ext2_directory_entry_ll_t *entry = it->current_block->data + offset_in_block;
    193202       
    194203        /* Ensure that the whole entry does not overflow the block */
    195         skip = ext2_directory_entry_ll_get_entry_length(it->current);
    196         if (offset_in_block + skip > block_size) {
    197                 it->current = NULL;
     204        uint16_t length = ext2_directory_entry_ll_get_entry_length(entry);
     205        if (offset_in_block + length > block_size) {
    198206                return EIO;
    199207        }
     
    201209        /* Ensure the name length is not too large */
    202210        if (ext2_directory_entry_ll_get_name_length(it->fs->superblock,
    203             it->current) > skip-8) {
    204                 it->current = NULL;
    205                 return EIO;
    206         }
    207        
     211            entry) > length-8) {
     212                return EIO;
     213        }
     214       
     215        it->current = entry;
    208216        return EOK;
    209217}
Note: See TracChangeset for help on using the changeset viewer.