Changeset 052e82d in mainline
- Timestamp:
- 2011-11-07T11:50:31Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 12b4a7f
- Parents:
- 5664cf64
- Location:
- uspace
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/Makefile
r5664cf64 r052e82d 33 33 34 34 SOURCES = \ 35 libext4_bitmap.c \ 35 36 libext4_block_group.c \ 36 37 libext4_directory.c \ -
uspace/lib/ext4/libext4.h
r5664cf64 r052e82d 34 34 #define LIBEXT4_LIBEXT4_H_ 35 35 36 #include "libext4_bitmap.h" 36 37 #include "libext4_block_group.h" 37 38 #include "libext4_directory.h" -
uspace/lib/ext4/libext4_block_group.c
r5664cf64 r052e82d 63 63 } 64 64 65 void ext4_block_group_set_free_blocks_count(ext4_block_group_t *bg, uint32_t value) { 66 bg->free_blocks_count_lo = host2uint16_t_le((value << 16) >> 16); 67 bg->free_blocks_count_hi = host2uint16_t_le(value >> 16); 68 } 69 65 70 uint32_t ext4_block_group_get_free_inodes_count(ext4_block_group_t *bg) 66 71 { -
uspace/lib/ext4/libext4_block_group.h
r5664cf64 r052e82d 73 73 extern uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *); 74 74 extern uint32_t ext4_block_group_get_free_blocks_count(ext4_block_group_t *); 75 extern void ext4_block_group_set_free_blocks_count(ext4_block_group_t *, uint32_t); 75 76 extern uint32_t ext4_block_group_get_free_inodes_count(ext4_block_group_t *); 76 77 extern uint32_t ext4_block_group_get_used_dirs_count(ext4_block_group_t *); -
uspace/lib/ext4/libext4_filesystem.c
r5664cf64 r052e82d 251 251 */ 252 252 newref->index = index+1; 253 newref->dirty = false; 253 254 254 255 *ref = newref; … … 261 262 { 262 263 int rc; 264 265 if (ref->dirty) { 266 ref->block->dirty = true; 267 } 263 268 264 269 rc = block_put(ref->block); … … 355 360 356 361 357 int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs, ext4_inode_t *inode, uint32_t iblock) 362 int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs, 363 ext4_inode_ref_t *inode_ref, uint32_t iblock) 358 364 { 359 365 int rc; 360 366 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; 367 int i; 368 int level; 369 aoff64_t block_offset_in_level; 370 uint32_t current_block; 371 uint32_t offset_in_block; 372 block_t *block; 373 ext4_inode_t *inode = inode_ref->inode; 374 375 /* TODO handle extents */ 376 377 /* Handle simple case when we are dealing with direct reference */ 378 if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) { 379 EXT4FS_DBG("direct block"); 380 fblock = ext4_inode_get_direct_block(inode, (uint32_t)iblock); 381 // Sparse file 382 if (fblock == 0) { 383 return EOK; 384 } 385 386 ext4_inode_set_direct_block(inode, iblock, 0); 387 return ext4_bitmap_free_block(fs, fblock); 388 } else { 389 390 /* Determine the indirection level needed to get the desired block */ 391 level = -1; 392 for (i = 1; i < 4; i++) { 393 if (iblock < fs->inode_block_limits[i]) { 394 level = i; 395 break; 396 } 397 } 398 399 if (level == -1) { 400 return EIO; 401 } 402 403 /* Compute offsets for the topmost level */ 404 block_offset_in_level = iblock - fs->inode_block_limits[level-1]; 405 current_block = ext4_inode_get_indirect_block(inode, level-1); 406 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 407 408 /* Navigate through other levels, until we find the block number 409 * or find null reference meaning we are dealing with sparse file 410 */ 411 while (level > 0) { 412 rc = block_get(&block, fs->device, current_block, 0); 413 if (rc != EOK) { 414 return rc; 415 } 416 417 current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]); 418 419 // Set zero 420 if (level == 1) { 421 ((uint32_t*)block->data)[offset_in_block] = host2uint32_t_le(0); 422 block->dirty = true; 423 } 424 425 rc = block_put(block); 426 if (rc != EOK) { 427 return rc; 428 } 429 430 level -= 1; 431 432 /* If we are on the last level, break here as 433 * there is no next level to visit 434 */ 435 if (level == 0) { 436 break; 437 } 438 439 /* Visit the next level */ 440 block_offset_in_level %= fs->inode_blocks_per_level[level]; 441 offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1]; 442 } 443 444 fblock = current_block; 445 446 if (fblock == 0) { 447 return EOK; 448 } 449 } 450 451 return ext4_bitmap_free_block(fs, fblock); 452 387 453 } 388 454 -
uspace/lib/ext4/libext4_filesystem.h
r5664cf64 r052e82d 63 63 ext4_inode_t *, aoff64_t iblock, uint32_t *); 64 64 extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *, 65 ext4_inode_ t *, uint32_t);65 ext4_inode_ref_t *, uint32_t); 66 66 #endif 67 67 -
uspace/lib/ext4/libext4_inode.c
r5664cf64 r052e82d 67 67 return ((uint64_t)uint32_t_le2host(inode->size_hi)) << 32 | 68 68 ((uint64_t)uint32_t_le2host(inode->size_lo)); 69 69 } 70 70 return uint32_t_le2host(inode->size_lo); 71 } 72 73 void ext4_inode_set_size(ext4_inode_t *inode, uint64_t value) { 74 inode->size_lo = host2uint32_t_le((value << 32) >> 32); 75 inode->size_hi = host2uint32_t_le(value >> 32); 71 76 } 72 77 -
uspace/lib/ext4/libext4_inode.h
r5664cf64 r052e82d 144 144 ext4_inode_t *inode; 145 145 uint32_t index; // Index number of this inode 146 bool dirty; 146 147 } ext4_inode_ref_t; 147 148 … … 153 154 */ 154 155 extern uint64_t ext4_inode_get_size(ext4_superblock_t *, ext4_inode_t *); 156 extern void ext4_inode_set_size(ext4_inode_t *, uint64_t); 155 157 /* 156 158 extern uint32_t ext4_inode_get_access_time(ext4_inode_t *); -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r5664cf64 r052e82d 939 939 fs_node_t *fn; 940 940 ext4fs_node_t *enode; 941 ext4_inode_ t *inode;941 ext4_inode_ref_t *inode_ref; 942 942 ext4_filesystem_t* fs; 943 943 aoff64_t old_size; … … 951 951 952 952 enode = EXT4FS_NODE(fn); 953 inode = enode->inode_ref->inode;953 inode_ref = enode->inode_ref; 954 954 fs = enode->instance->filesystem; 955 955 956 old_size = ext4_inode_get_size(fs->superblock, inode );956 old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 957 957 958 958 printf("old size = \%llu, new size = \%llu\n", old_size, new_size); … … 961 961 rc = EOK; 962 962 } else { 963 /** AAAAAAAAAAAAAAAAAAAA */964 963 965 964 //int rc; … … 989 988 } 990 989 991 // TODO dirty add to inode_ref_t 992 //ino_i->dirty = true; 990 inode_ref->dirty = true; 993 991 994 992 for (i = 0; i< blocks_count; ++i) { 995 993 // TODO check retval 996 ext4_filesystem_release_inode_block(fs, inode, total_blocks - i); 997 // TODO subtract inode->size 998 } 999 1000 /** BBBBBBBBBBBBBBBBBBBB */ 994 ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i); 995 } 996 997 ext4_inode_set_size(inode_ref->inode, new_size); 1001 998 1002 999 }
Note:
See TracChangeset
for help on using the changeset viewer.