Changeset 476bf2f6 in mainline


Ignore:
Timestamp:
2012-02-20T17:27:45Z (12 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

Location:
uspace/lib/ext4
Files:
3 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
  • uspace/lib/ext4/libext4_directory.h

    r1ebb66f r476bf2f6  
    9393extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
    9494
     95extern int ext4_directory_append_block(ext4_filesystem_t *,
     96                ext4_inode_ref_t *, uint32_t *);
     97
    9598extern void ext4_directory_write_entry(ext4_superblock_t *,
    9699                ext4_directory_entry_ll_t *, uint16_t, ext4_inode_ref_t *,
  • uspace/lib/ext4/libext4_directory_index.c

    r1ebb66f r476bf2f6  
    580580                }
    581581
    582                 // Compute next block index and allocate data block
    583                 uint64_t parent_size = ext4_inode_get_size(fs->superblock, parent->inode);
    584                 uint32_t new_block_idx = parent_size / block_size;
    585 
    586582                uint32_t fblock;
    587                 rc = ext4_filesystem_get_inode_data_block_index(fs, parent->inode, new_block_idx, &fblock);
     583                rc =  ext4_directory_append_block(fs, parent, &fblock);
    588584                if (rc != EOK) {
    589                         return rc;
    590                 }
    591 
    592                 if (fblock == 0) {
    593                         rc =  ext4_balloc_alloc_block(fs, parent, &fblock);
    594                         if (rc != EOK) {
    595                                 return rc;
    596                         }
    597 
    598                         rc = ext4_filesystem_set_inode_data_block_index(fs, parent, new_block_idx, fblock);
    599                         if (rc != EOK) {
    600                                 ext4_balloc_free_block(fs, parent, fblock);
    601                                 return rc;
    602                         }
    603 
    604                         parent_size += block_size;
    605                         ext4_inode_set_size(parent->inode, parent_size);
    606 
    607                         parent->dirty = true;
     585                        // TODO error
    608586                }
    609587
Note: See TracChangeset for help on using the changeset viewer.