Changeset 35f48f2 in mainline
- Timestamp:
- 2011-11-09T08:48:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e65444
- Parents:
- 0f09d4ea
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_bitmap.c
r0f09d4ea r35f48f2 167 167 rc = ext4_bitmap_find_free_bit_and_set(block->data, &rel_block_idx, block_size); 168 168 169 // if ENOSPC - try next block group - try next block groups170 169 170 if (rc != EOK) { 171 EXT4FS_DBG("no block found"); 172 // TODO if ENOSPC - try next block group - try next block groups 173 } 171 174 175 // TODO decrement superblock free blocks count 176 //uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb); 177 //sb_free_blocks--; 178 //ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 172 179 173 174 // TODO decrement superblock & block group free blocks count 180 uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count(bg_ref->block_group); 181 bg_free_blocks++; 182 ext4_block_group_set_free_blocks_count(bg_ref->block_group, bg_free_blocks); 183 bg_ref->dirty = true; 175 184 176 185 // return -
uspace/lib/ext4/libext4_filesystem.c
r0f09d4ea r35f48f2 363 363 364 364 365 int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *fs, 366 ext4_inode_t *inode, aoff64_t iblock, uint32_t fblock) 367 { 368 369 // int rc; 370 // uint32_t offset_in_block; 371 // uint32_t current_block; 372 // aoff64_t block_offset_in_level; 373 // int i; 374 // int level; 375 // block_t *block; 376 377 /* Handle inode using extents */ 378 if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 379 ext4_inode_has_flag(inode, EXT4_INODE_FLAG_EXTENTS)) { 380 // TODO 381 return ENOTSUP; 382 383 } 384 385 /* Handle simple case when we are dealing with direct reference */ 386 if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) { 387 ext4_inode_set_direct_block(inode, (uint32_t)iblock, fblock); 388 return EOK; 389 } 390 391 // /* Determine the indirection level needed to get the desired block */ 392 // level = -1; 393 // for (i = 1; i < 4; i++) { 394 // if (iblock < fs->inode_block_limits[i]) { 395 // level = i; 396 // break; 397 // } 398 // } 399 // 400 // if (level == -1) { 401 // return EIO; 402 // } 403 // 404 // /* Compute offsets for the topmost level */ 405 // block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 406 // current_block = ext4_inode_get_indirect_block(inode, level-1); 407 // offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 408 // 409 // /* Navigate through other levels, until we find the block number 410 // * or find null reference meaning we are dealing with sparse file 411 // */ 412 // while (level > 0) { 413 // rc = block_get(&block, fs->device, current_block, 0); 414 // if (rc != EOK) { 415 // return rc; 416 // } 417 // 418 // current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]); 419 // 420 // rc = block_put(block); 421 // if (rc != EOK) { 422 // return rc; 423 // } 424 // 425 // if (current_block == 0) { 426 // /* This is a sparse file */ 427 // *fblock = 0; 428 // return EOK; 429 // } 430 // 431 // level -= 1; 432 // 433 // /* If we are on the last level, break here as 434 // * there is no next level to visit 435 // */ 436 // if (level == 0) { 437 // break; 438 // } 439 // 440 // /* Visit the next level */ 441 // block_offset_in_level %= fs->inode_blocks_per_level[level]; 442 // offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 443 // } 444 // 445 // *fblock = current_block; 446 // 447 // return EOK; 448 // 449 // 450 451 return EOK; 452 } 453 365 454 int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs, 366 455 ext4_inode_ref_t *inode_ref, uint32_t iblock) -
uspace/lib/ext4/libext4_filesystem.h
r0f09d4ea r35f48f2 62 62 extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *, 63 63 ext4_inode_t *, aoff64_t iblock, uint32_t *); 64 extern int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *, 65 ext4_inode_t *, aoff64_t, uint32_t); 64 66 extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *, 65 67 ext4_inode_ref_t *, uint32_t); -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r0f09d4ea r35f48f2 929 929 930 930 int rc; 931 int flags = BLOCK_FLAGS_NONE; 931 932 fs_node_t *fn; 932 933 ext4fs_node_t *enode; … … 937 938 block_t *write_block; 938 939 uint32_t fblock, iblock; 940 uint32_t old_inode_size; 939 941 940 942 rc = ext4fs_node_get(&fn, service_id, index); … … 960 962 bytes = min(len, block_size - (pos % block_size)); 961 963 964 if (bytes == block_size) { 965 flags = BLOCK_FLAGS_NOREAD; 966 } 967 962 968 EXT4FS_DBG("bytes == \%u", bytes); 963 969 … … 966 972 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, iblock, &fblock); 967 973 968 969 // TODO allocation if fblock == 0970 974 if (fblock == 0) { 971 975 EXT4FS_DBG("Allocate block !!!"); 972 973 return ENOTSUP; 974 } 975 976 // TODO flags 977 rc = block_get(&write_block, service_id, fblock, 0); 976 rc = ext4_bitmap_alloc_block(fs, inode_ref, &fblock); 977 if (rc != EOK) { 978 ext4fs_node_put(fn); 979 async_answer_0(callid, rc); 980 return rc; 981 } 982 983 ext4_filesystem_set_inode_data_block_index(fs, inode_ref->inode, iblock, fblock); 984 inode_ref->dirty = true; 985 986 flags = BLOCK_FLAGS_NOREAD; 987 988 EXT4FS_DBG("block \%u allocated", fblock); 989 } 990 991 rc = block_get(&write_block, service_id, fblock, flags); 978 992 if (rc != EOK) { 979 993 ext4fs_node_put(fn); … … 982 996 } 983 997 984 /* 985 if (flags == BLOCK_FLAGS_NOREAD) 986 memset(b->data, 0, sbi->block_size); 987 */ 988 989 async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes); 998 EXT4FS_DBG("block loaded"); 999 1000 if (flags == BLOCK_FLAGS_NOREAD) { 1001 EXT4FS_DBG("fill block with zeros"); 1002 memset(write_block->data, 0, block_size); 1003 } 1004 1005 rc = async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes); 1006 if (rc != EOK) { 1007 EXT4FS_DBG("error in write finalize \%d", rc); 1008 } 1009 1010 char *data = write_block->data + (pos % block_size); 1011 for (uint32_t x = 0; x < bytes; ++x) { 1012 printf("%c", data[x]); 1013 } 1014 printf("\n"); 1015 990 1016 write_block->dirty = true; 991 1017 … … 996 1022 } 997 1023 998 /* 999 if (pos + bytes > ino_i->i_size) { 1000 ino_i->i_size = pos + bytes; 1001 ino_i->dirty = true; 1002 } 1003 *nsize = ino_i->i_size; 1024 EXT4FS_DBG("writing finished"); 1025 1026 old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 1027 if (pos + bytes > old_inode_size) { 1028 ext4_inode_set_size(inode_ref->inode, pos + bytes); 1029 inode_ref->dirty = true; 1030 } 1031 1032 *nsize = ext4_inode_get_size(fs->superblock, inode_ref->inode); 1004 1033 *wbytes = bytes; 1005 */ 1034 1006 1035 return ext4fs_node_put(fn); 1007 1036 } … … 1105 1134 static int ext4fs_sync(service_id_t service_id, fs_index_t index) 1106 1135 { 1107 EXT4FS_DBG("not supported"); 1108 1109 // TODO 1110 return ENOTSUP; 1136 EXT4FS_DBG(""); 1137 1138 int rc; 1139 fs_node_t *fn; 1140 ext4fs_node_t *enode; 1141 1142 rc = ext4fs_node_get(&fn, service_id, index); 1143 if (rc != EOK) { 1144 return rc; 1145 } 1146 1147 enode = EXT4FS_NODE(fn); 1148 enode->inode_ref->dirty = true; 1149 1150 return ext4fs_node_put(fn); 1111 1151 } 1112 1152
Note:
See TracChangeset
for help on using the changeset viewer.