Changeset b7e0260 in mainline


Ignore:
Timestamp:
2012-01-22T12:29:41Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d9bbe45
Parents:
c38e417
Message:

Completed code for adding directory entry without index

File:
1 edited

Legend:

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

    rc38e417 rb7e0260  
    239239}
    240240
     241/**
     242 * Fill data block with invalid directory entry.
     243 */
     244static int ext4_directory_init_block(ext4_filesystem_t *fs, uint32_t fblock)
     245{
     246        int rc;
     247
     248        block_t *block;
     249        rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NOREAD);
     250        if (rc != EOK) {
     251                return rc;
     252        }
     253
     254        ext4_directory_entry_ll_t *entry = block->data;
     255        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
     256
     257        ext4_directory_entry_ll_set_entry_length(entry, block_size);
     258        ext4_directory_entry_ll_set_inode(entry, 0);
     259        ext4_directory_entry_ll_set_name_length(fs->superblock, entry, 0);
     260        entry->name[0] = 0;
     261
     262        block->dirty = true;
     263        return block_put(block);
     264}
     265
    241266int ext4_directory_add_entry(ext4_filesystem_t *fs, ext4_inode_ref_t * inode_ref,
    242267                const char *entry_name, uint32_t child_inode)
     
    306331        }
    307332
    308         // TODO - no free space found - alloc data block
    309         // and fill the whole block with new entry
    310 
    311         // TODO
    312         return EOK;
     333        // Save position and destroy iterator
     334        aoff64_t pos = it.current_offset;
     335        ext4_directory_iterator_fini(&it);
     336
     337        // Compute next block index and allocate data block
     338        uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
     339        uint32_t block_idx = pos / block_size;
     340
     341        uint32_t fblock;
     342        rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, block_idx, &fblock);
     343        if (rc != EOK) {
     344                return rc;
     345        }
     346
     347        if (fblock == 0) {
     348                rc =  ext4_balloc_alloc_block(fs, inode_ref, &fblock);
     349                if (rc != EOK) {
     350                        return rc;
     351                }
     352
     353                rc = ext4_filesystem_set_inode_data_block_index(fs, inode_ref, block_idx, fblock);
     354                if (rc != EOK) {
     355                        ext4_balloc_free_block(fs, inode_ref, fblock);
     356                        return rc;
     357                }
     358
     359                inode_ref->dirty = true;
     360
     361                rc = ext4_directory_init_block(fs, fblock);
     362                if (rc != EOK) {
     363                        return rc;
     364                }
     365        }
     366
     367        rc = ext4_directory_iterator_init(&it, fs, inode_ref, pos);
     368        if (rc != EOK) {
     369                return rc;
     370        }
     371
     372        // Entry length is not affected
     373        ext4_directory_entry_ll_set_inode(it.current, child_inode);
     374        ext4_directory_entry_ll_set_name_length(fs->superblock, it.current, name_len);
     375        memcpy(it.current->name, entry_name, name_len);
     376
     377        it.current_block->dirty = true;
     378
     379        return ext4_directory_iterator_fini(&it);
    313380}
    314381
Note: See TracChangeset for help on using the changeset viewer.