Changeset d5a78e28 in mainline


Ignore:
Timestamp:
2011-11-05T17:09:25Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3569955
Parents:
a9a0982
Message:

file truncate skeleton, but non functional

Location:
uspace
Files:
5 edited

Legend:

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

    ra9a0982 rd5a78e28  
    354354}
    355355
     356
     357int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs, ext4_inode_t *inode, uint32_t iblock)
     358{
     359        int rc;
     360        uint32_t fblock;
     361
     362        // TODO handle with extents
     363
     364        rc = ext4_filesystem_get_inode_data_block_index(fs, inode, iblock, &fblock);
     365        if (rc != EOK) {
     366                // TODO error
     367                return rc;
     368        }
     369
     370        // Sparse file
     371        if (fblock == 0) {
     372
     373                //
     374                return EOK;
     375        }
     376
     377
     378        // TODO vyhledat policko s ukazatelem a nastavit nulu
     379
     380
     381        // TODO uvolnit blok v bitmape
     382
     383        // TODO return
     384
     385
     386        return EOK;
     387}
     388
     389
    356390/**
    357391 * @}
  • uspace/lib/ext4/libext4_filesystem.h

    ra9a0982 rd5a78e28  
    6262extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *,
    6363        ext4_inode_t *, aoff64_t iblock, uint32_t *);
    64 
     64extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *,
     65                ext4_inode_t *, uint32_t);
    6566#endif
    6667
  • uspace/lib/ext4/libext4_inode.c

    ra9a0982 rd5a78e28  
    9898}
    9999
     100void ext4_inode_set_direct_block(ext4_inode_t *inode, uint8_t idx, uint32_t fblock)
     101{
     102        assert(idx < EXT4_INODE_DIRECT_BLOCK_COUNT);
     103        inode->blocks[idx] = host2uint32_t_le(fblock);
     104}
     105
    100106uint32_t ext4_inode_get_indirect_block(ext4_inode_t *inode, uint8_t idx)
    101107{
  • uspace/lib/ext4/libext4_inode.h

    ra9a0982 rd5a78e28  
    166166extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
    167167
    168 uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
    169 uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
    170 uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
     168extern uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
     169extern void ext4_inode_set_direct_block(ext4_inode_t *, uint8_t, uint32_t);
     170extern uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
     171extern uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
    171172/*
    172173uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    ra9a0982 rd5a78e28  
    934934
    935935static int
    936 ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
    937 {
    938         EXT4FS_DBG("not supported");
    939 
    940         // TODO
    941         return ENOTSUP;
     936ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t new_size)
     937{
     938        EXT4FS_DBG("");
     939        fs_node_t *fn;
     940        ext4fs_node_t *enode;
     941        ext4_inode_t *inode;
     942        ext4_filesystem_t* fs;
     943        aoff64_t old_size;
     944        aoff64_t size_diff;
     945        int rc;
     946
     947        rc = ext4fs_node_get(&fn, service_id, index);
     948        if (rc != EOK) {
     949                return rc;
     950        }
     951
     952        enode = EXT4FS_NODE(fn);
     953        inode = enode->inode_ref->inode;
     954        fs = enode->instance->filesystem;
     955
     956        old_size = ext4_inode_get_size(fs->superblock, inode);
     957
     958        printf("old size = \%llu, new size = \%llu\n", old_size, new_size);
     959
     960        if (old_size == new_size) {
     961                rc = EOK;
     962        } else {
     963                /** AAAAAAAAAAAAAAAAAAAA */
     964
     965                //int rc;
     966                uint32_t block_size;
     967                uint32_t blocks_count, total_blocks;
     968                uint32_t i;
     969
     970                block_size  = ext4_superblock_get_block_size(fs->superblock);
     971
     972                if (old_size < new_size) {
     973                        // TODO don't return immediately
     974                        EXT4FS_DBG("expand the file");
     975                        return EINVAL;
     976                }
     977
     978                EXT4FS_DBG("cut the end of the file !");
     979
     980                size_diff = old_size - new_size;
     981                blocks_count = size_diff / block_size;
     982                if (size_diff % block_size != 0) {
     983                        blocks_count++;
     984                }
     985
     986                total_blocks = old_size / block_size;
     987                if (old_size % block_size != 0) {
     988                        total_blocks++;
     989                }
     990
     991                // TODO dirty add to inode_ref_t
     992                //ino_i->dirty = true;
     993
     994                for (i = 0; i< blocks_count; ++i) {
     995                        // TODO check retval
     996                        ext4_filesystem_release_inode_block(fs, inode, total_blocks - i);
     997                        // TODO subtract inode->size
     998                }
     999
     1000                /** BBBBBBBBBBBBBBBBBBBB */
     1001
     1002        }
     1003
     1004        ext4fs_node_put(fn);
     1005        return rc;
    9421006}
    9431007
Note: See TracChangeset for help on using the changeset viewer.