Changeset 476bf2f6 in mainline for uspace/lib/ext4/libext4_directory.c


Ignore:
Timestamp:
2012-02-20T17:27:45Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f577058
Parents:
1ebb66f
Message:

duplicate code extraction

File:
1 edited

Legend:

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

    r1ebb66f r476bf2f6  
    260260}
    261261
     262int ext4_directory_append_block(ext4_filesystem_t *fs,
     263                ext4_inode_ref_t *inode_ref, uint32_t *fblock)
     264{
     265        int rc;
     266
     267        // Compute next block index and allocate data block
     268        uint64_t inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
     269        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
     270        uint32_t new_block_idx = inode_size / block_size;
     271
     272        uint32_t phys_block;
     273        rc =  ext4_balloc_alloc_block(fs, inode_ref, &phys_block);
     274        if (rc != EOK) {
     275                return rc;
     276        }
     277
     278        rc = ext4_filesystem_set_inode_data_block_index(fs, inode_ref, new_block_idx, phys_block);
     279        if (rc != EOK) {
     280                ext4_balloc_free_block(fs, inode_ref, phys_block);
     281                return rc;
     282        }
     283
     284        inode_size += block_size;
     285        ext4_inode_set_size(inode_ref->inode, inode_size);
     286
     287        inode_ref->dirty = true;
     288
     289        *fblock = phys_block;
     290        return EOK;
     291}
     292
    262293void ext4_directory_write_entry(ext4_superblock_t *sb,
    263294                ext4_directory_entry_ll_t *entry, uint16_t entry_len,
     
    374405        }
    375406
     407        // Destroy iterator
     408        ext4_directory_iterator_fini(&it);
     409
    376410        EXT4FS_DBG("NO FREE SPACE - needed to allocate block");
    377411
    378         // Save position and destroy iterator
    379         aoff64_t pos = it.current_offset;
    380         ext4_directory_iterator_fini(&it);
    381 
    382         // Compute next block index and allocate data block
    383         uint32_t block_idx = pos / block_size;
    384 
    385412        uint32_t fblock;
    386         rc = ext4_filesystem_get_inode_data_block_index(fs, parent->inode, block_idx, &fblock);
    387         if (rc != EOK) {
    388                 return rc;
    389         }
    390 
    391         if (fblock == 0) {
    392                 rc =  ext4_balloc_alloc_block(fs, parent, &fblock);
    393                 if (rc != EOK) {
    394                         return rc;
    395                 }
    396 
    397                 rc = ext4_filesystem_set_inode_data_block_index(fs, parent, block_idx, fblock);
    398                 if (rc != EOK) {
    399                         ext4_balloc_free_block(fs, parent, fblock);
    400                         return rc;
    401                 }
    402 
    403                 uint64_t inode_size = ext4_inode_get_size(fs->superblock, parent->inode);
    404                 inode_size += block_size;
    405                 ext4_inode_set_size(parent->inode, inode_size);
    406 
    407                 parent->dirty = true;
     413        rc = ext4_directory_append_block(fs, parent, &fblock);
     414        if (rc != EOK) {
     415                return rc;
    408416        }
    409417
Note: See TracChangeset for help on using the changeset viewer.