Changeset d5a78e28 in mainline for uspace/srv/fs/ext4fs
- Timestamp:
- 2011-11-05T17:09:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3569955
- Parents:
- a9a0982
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext4fs/ext4fs_ops.c
ra9a0982 rd5a78e28 934 934 935 935 static 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; 936 ext4fs_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; 942 1006 } 943 1007
Note:
See TracChangeset
for help on using the changeset viewer.