Changeset 1ac1ab4 in mainline
- Timestamp:
- 2012-03-31T20:00:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2fa350
- Parents:
- 38384ae
- Location:
- uspace
- Files:
-
- 2 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/Makefile
r38384ae r1ac1ab4 36 36 libext4_bitmap.c \ 37 37 libext4_block_group.c \ 38 libext4_crc.c \ 38 39 libext4_directory.c \ 39 40 libext4_directory_index.c \ -
uspace/lib/ext4/libext4.h
r38384ae r1ac1ab4 37 37 #include "libext4_bitmap.h" 38 38 #include "libext4_block_group.h" 39 #include "libext4_crc.h" 39 40 #include "libext4_directory.h" 40 41 #include "libext4_directory_index.h" -
uspace/lib/ext4/libext4_balloc.c
r38384ae r1ac1ab4 82 82 83 83 84 int ext4_balloc_free_block(ext4_ filesystem_t *fs, ext4_inode_ref_t *inode_ref, uint32_t block_addr)84 int ext4_balloc_free_block(ext4_inode_ref_t *inode_ref, uint32_t block_addr) 85 85 { 86 86 int rc; 87 87 88 uint32_t block_group = ext4_balloc_get_bgid_of_block(fs->superblock, block_addr); 89 uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(fs->superblock, block_addr); 88 ext4_filesystem_t *fs = inode_ref->fs; 89 ext4_superblock_t *sb = fs->superblock; 90 91 uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, block_addr); 92 uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, block_addr); 90 93 91 94 ext4_block_group_ref_t *bg_ref; … … 97 100 98 101 uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap( 99 bg_ref->block_group, fs->superblock);102 bg_ref->block_group, sb); 100 103 block_t *bitmap_block; 101 104 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0); … … 116 119 } 117 120 118 uint32_t block_size = ext4_superblock_get_block_size( fs->superblock);121 uint32_t block_size = ext4_superblock_get_block_size(sb); 119 122 120 123 // Update superblock free blocks count 121 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count( fs->superblock);124 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb); 122 125 sb_free_blocks--; 123 ext4_superblock_set_free_blocks_count( fs->superblock, sb_free_blocks);126 ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 124 127 125 128 // Update inode blocks count 126 uint64_t ino_blocks = ext4_inode_get_blocks_count( fs->superblock, inode_ref->inode);129 uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode); 127 130 ino_blocks -= block_size / EXT4_INODE_BLOCK_SIZE; 128 ext4_inode_set_blocks_count( fs->superblock, inode_ref->inode, ino_blocks);131 ext4_inode_set_blocks_count(sb, inode_ref->inode, ino_blocks); 129 132 inode_ref->dirty = true; 130 133 131 134 // Update block group free blocks count 132 135 uint32_t free_blocks = ext4_block_group_get_free_blocks_count( 133 bg_ref->block_group, fs->superblock);136 bg_ref->block_group, sb); 134 137 free_blocks++; 135 138 ext4_block_group_set_free_blocks_count(bg_ref->block_group, 136 fs->superblock, free_blocks);139 sb, free_blocks); 137 140 bg_ref->dirty = true; 138 141 … … 178 181 179 182 180 static uint32_t ext4_balloc_find_goal(ext4_ filesystem_t *fs, ext4_inode_ref_t *inode_ref)183 static uint32_t ext4_balloc_find_goal(ext4_inode_ref_t *inode_ref) 181 184 { 182 185 int rc; 183 186 uint32_t goal = 0; 184 187 185 uint64_t inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode); 186 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 188 ext4_superblock_t *sb = inode_ref->fs->superblock; 189 190 uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode); 191 uint32_t block_size = ext4_superblock_get_block_size(sb); 187 192 uint32_t inode_block_count = inode_size / block_size; 188 193 … … 193 198 if (inode_block_count > 0) { 194 199 // TODO check retval 195 ext4_filesystem_get_inode_data_block_index( fs,inode_ref, inode_block_count - 1, &goal);200 ext4_filesystem_get_inode_data_block_index(inode_ref, inode_block_count - 1, &goal); 196 201 197 202 // TODO … … 203 208 204 209 // Identify block group of inode 205 uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group( fs->superblock);210 uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb); 206 211 uint32_t block_group = (inode_ref->index - 1) / inodes_per_group; 207 block_size = ext4_superblock_get_block_size( fs->superblock);212 block_size = ext4_superblock_get_block_size(sb); 208 213 209 214 ext4_block_group_ref_t *bg_ref; 210 rc = ext4_filesystem_get_block_group_ref( fs, block_group, &bg_ref);215 rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref); 211 216 if (rc != EOK) { 212 217 return 0; 213 218 } 214 219 215 uint32_t block_group_count = ext4_superblock_get_block_group_count( fs->superblock);220 uint32_t block_group_count = ext4_superblock_get_block_group_count(sb); 216 221 uint32_t inode_table_first_block = ext4_block_group_get_inode_table_first_block( 217 bg_ref->block_group, fs->superblock);218 uint16_t inode_table_item_size = ext4_superblock_get_inode_size( fs->superblock);222 bg_ref->block_group, sb); 223 uint16_t inode_table_item_size = ext4_superblock_get_inode_size(sb); 219 224 uint32_t inode_table_bytes; 220 225 … … 223 228 } else { 224 229 // last block group could be smaller 225 uint32_t inodes_count_total = ext4_superblock_get_inodes_count( fs->superblock);230 uint32_t inodes_count_total = ext4_superblock_get_inodes_count(sb); 226 231 inode_table_bytes = 227 232 (inodes_count_total - ((block_group_count - 1) * inodes_per_group)) … … 242 247 } 243 248 244 int ext4_balloc_alloc_block( ext4_filesystem_t *fs,249 int ext4_balloc_alloc_block( 245 250 ext4_inode_ref_t *inode_ref, uint32_t *fblock) 246 251 { … … 253 258 254 259 // Find GOAL 255 uint32_t goal = ext4_balloc_find_goal( fs,inode_ref);260 uint32_t goal = ext4_balloc_find_goal(inode_ref); 256 261 if (goal == 0) { 257 262 // TODO … … 260 265 } 261 266 267 ext4_superblock_t *sb = inode_ref->fs->superblock; 268 262 269 // Load block group number for goal and relative index 263 uint32_t block_group = ext4_balloc_get_bgid_of_block( fs->superblock, goal);264 uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group( fs->superblock, goal);270 uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, goal); 271 uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, goal); 265 272 266 273 267 274 ext4_block_group_ref_t *bg_ref; 268 rc = ext4_filesystem_get_block_group_ref( fs, block_group, &bg_ref);275 rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref); 269 276 if (rc != EOK) { 270 277 EXT4FS_DBG("initial BG ref not loaded"); … … 273 280 274 281 uint32_t first_in_group = 275 ext4_balloc_get_first_data_block_in_group( fs->superblock,282 ext4_balloc_get_first_data_block_in_group(sb, 276 283 bg_ref->block_group, block_group); 277 284 278 285 uint32_t first_in_group_index = ext4_balloc_blockaddr2_index_in_group( 279 fs->superblock, first_in_group);286 sb, first_in_group); 280 287 281 288 if (index_in_group < first_in_group_index) { … … 285 292 // Load bitmap 286 293 bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group, 287 fs->superblock);288 289 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);294 sb); 295 296 rc = block_get(&bitmap_block, inode_ref->fs->device, bitmap_block_addr, 0); 290 297 if (rc != EOK) { 291 298 ext4_filesystem_put_block_group_ref(bg_ref); … … 311 318 } 312 319 313 uint32_t blocks_in_group = ext4_superblock_get_blocks_in_group( fs->superblock, block_group);320 uint32_t blocks_in_group = ext4_superblock_get_blocks_in_group(sb, block_group); 314 321 315 322 uint32_t end_idx = (index_in_group + 63) & ~63; … … 331 338 332 339 allocated_block = ext4_balloc_index_in_group2blockaddr( 333 fs->superblock, tmp_idx, block_group);340 sb, tmp_idx, block_group); 334 341 335 342 goto success; … … 349 356 350 357 allocated_block = ext4_balloc_index_in_group2blockaddr( 351 fs->superblock, rel_block_idx, block_group);358 sb, rel_block_idx, block_group); 352 359 353 360 goto success; … … 365 372 366 373 allocated_block = ext4_balloc_index_in_group2blockaddr( 367 fs->superblock, rel_block_idx, block_group);374 sb, rel_block_idx, block_group); 368 375 369 376 goto success; … … 375 382 376 383 // Try other block groups 377 uint32_t block_group_count = ext4_superblock_get_block_group_count( fs->superblock);384 uint32_t block_group_count = ext4_superblock_get_block_group_count(sb); 378 385 379 386 uint32_t bgid = (block_group + 1) % block_group_count; … … 381 388 382 389 while (count > 0) { 383 rc = ext4_filesystem_get_block_group_ref( fs, bgid, &bg_ref);390 rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, bgid, &bg_ref); 384 391 if (rc != EOK) { 385 392 EXT4FS_DBG("errrrrrrrrrrr"); … … 389 396 // Load bitmap 390 397 bitmap_block_addr = ext4_block_group_get_block_bitmap( 391 bg_ref->block_group, fs->superblock);392 393 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);398 bg_ref->block_group, sb); 399 400 rc = block_get(&bitmap_block, inode_ref->fs->device, bitmap_block_addr, 0); 394 401 if (rc != EOK) { 395 402 ext4_filesystem_put_block_group_ref(bg_ref); … … 399 406 400 407 first_in_group = ext4_balloc_get_first_data_block_in_group( 401 fs->superblock, bg_ref->block_group, bgid);402 index_in_group = ext4_balloc_blockaddr2_index_in_group( fs->superblock,408 sb, bg_ref->block_group, bgid); 409 index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, 403 410 first_in_group); 404 blocks_in_group = ext4_superblock_get_blocks_in_group( fs->superblock, bgid);411 blocks_in_group = ext4_superblock_get_blocks_in_group(sb, bgid); 405 412 406 413 first_in_group_index = ext4_balloc_blockaddr2_index_in_group( 407 fs->superblock, first_in_group);414 sb, first_in_group); 408 415 409 416 if (index_in_group < first_in_group_index) { … … 422 429 423 430 allocated_block = ext4_balloc_index_in_group2blockaddr( 424 fs->superblock, rel_block_idx, bgid);431 sb, rel_block_idx, bgid); 425 432 426 433 goto success; … … 438 445 439 446 allocated_block = ext4_balloc_index_in_group2blockaddr( 440 fs->superblock, rel_block_idx, bgid);447 sb, rel_block_idx, bgid); 441 448 442 449 goto success; … … 456 463 ; // Empty command - because of syntax 457 464 458 uint32_t block_size = ext4_superblock_get_block_size( fs->superblock);465 uint32_t block_size = ext4_superblock_get_block_size(sb); 459 466 460 467 // Update superblock free blocks count 461 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count( fs->superblock);468 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb); 462 469 sb_free_blocks--; 463 ext4_superblock_set_free_blocks_count( fs->superblock, sb_free_blocks);470 ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 464 471 465 472 // Update inode blocks (different block size!) count 466 473 467 uint64_t ino_blocks = ext4_inode_get_blocks_count( fs->superblock, inode_ref->inode);474 uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode); 468 475 ino_blocks += block_size / EXT4_INODE_BLOCK_SIZE; 469 ext4_inode_set_blocks_count( fs->superblock, inode_ref->inode, ino_blocks);476 ext4_inode_set_blocks_count(sb, inode_ref->inode, ino_blocks); 470 477 inode_ref->dirty = true; 471 478 472 479 // Update block group free blocks count 473 480 uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count( 474 bg_ref->block_group, fs->superblock);481 bg_ref->block_group, sb); 475 482 bg_free_blocks--; 476 ext4_block_group_set_free_blocks_count(bg_ref->block_group, 477 fs->superblock, bg_free_blocks); 483 ext4_block_group_set_free_blocks_count(bg_ref->block_group, sb, bg_free_blocks); 478 484 bg_ref->dirty = true; 479 485 -
uspace/lib/ext4/libext4_balloc.h
r38384ae r1ac1ab4 37 37 #include "libext4_types.h" 38 38 39 extern int ext4_balloc_free_block(ext4_filesystem_t *, 40 ext4_inode_ref_t *, uint32_t); 41 extern int ext4_balloc_alloc_block(ext4_filesystem_t *, 42 ext4_inode_ref_t *, uint32_t *); 39 extern int ext4_balloc_free_block(ext4_inode_ref_t *, uint32_t); 40 extern int ext4_balloc_alloc_block(ext4_inode_ref_t *, uint32_t *); 43 41 44 42 #endif -
uspace/lib/ext4/libext4_directory.c
r38384ae r1ac1ab4 186 186 187 187 uint32_t next_block_phys_idx; 188 rc = ext4_filesystem_get_inode_data_block_index(it-> fs,189 it->inode_ref,next_block_idx, &next_block_phys_idx);188 rc = ext4_filesystem_get_inode_data_block_index(it->inode_ref, 189 next_block_idx, &next_block_phys_idx); 190 190 if (rc != EOK) { 191 191 return rc; … … 260 260 } 261 261 262 int ext4_directory_append_block(ext4_ filesystem_t *fs,263 ext4_inode_ref_t *inode_ref,uint32_t *fblock, uint32_t *iblock)262 int ext4_directory_append_block(ext4_inode_ref_t *inode_ref, 263 uint32_t *fblock, uint32_t *iblock) 264 264 { 265 265 int rc; 266 266 267 ext4_superblock_t *sb = inode_ref->fs->superblock; 268 267 269 // Compute next block index and allocate data block 268 uint64_t inode_size = ext4_inode_get_size( fs->superblock, inode_ref->inode);269 uint32_t block_size = ext4_superblock_get_block_size( fs->superblock);270 uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode); 271 uint32_t block_size = ext4_superblock_get_block_size(sb); 270 272 271 273 assert(inode_size % block_size == 0); … … 275 277 276 278 uint32_t phys_block; 277 rc = ext4_balloc_alloc_block( fs,inode_ref, &phys_block);279 rc = ext4_balloc_alloc_block(inode_ref, &phys_block); 278 280 if (rc != EOK) { 279 281 return rc; 280 282 } 281 283 282 rc = ext4_filesystem_set_inode_data_block_index( fs,inode_ref, new_block_idx, phys_block);284 rc = ext4_filesystem_set_inode_data_block_index(inode_ref, new_block_idx, phys_block); 283 285 if (rc != EOK) { 284 ext4_balloc_free_block( fs,inode_ref, phys_block);286 ext4_balloc_free_block(inode_ref, phys_block); 285 287 return rc; 286 288 } … … 313 315 } 314 316 315 int ext4_directory_add_entry(ext4_ filesystem_t *fs, ext4_inode_ref_t * parent,317 int ext4_directory_add_entry(ext4_inode_ref_t * parent, 316 318 const char *name, ext4_inode_ref_t *child) 317 319 { … … 319 321 320 322 EXT4FS_DBG("adding entry to directory \%u [ino = \%u, name = \%s]", parent->index, child->index, name); 323 324 ext4_filesystem_t *fs = parent->fs; 321 325 322 326 // Index adding (if allowed) … … 324 328 ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) { 325 329 326 rc = ext4_directory_dx_add_entry( fs,parent, child, name);330 rc = ext4_directory_dx_add_entry(parent, child, name); 327 331 328 332 // Check if index is not corrupted … … 356 360 for (iblock = 0; iblock < total_blocks; ++iblock) { 357 361 358 rc = ext4_filesystem_get_inode_data_block_index( fs,parent, iblock, &fblock);362 rc = ext4_filesystem_get_inode_data_block_index(parent, iblock, &fblock); 359 363 if (rc != EOK) { 360 364 return rc; … … 384 388 // No free block found - needed to allocate next block 385 389 386 rc = ext4_directory_append_block( fs,parent, &fblock, &iblock);390 rc = ext4_directory_append_block(parent, &fblock, &iblock); 387 391 if (rc != EOK) { 388 392 return rc; … … 411 415 } 412 416 413 int ext4_directory_find_entry(ext4_filesystem_t *fs, 414 ext4_directory_search_result_t *result, ext4_inode_ref_t *parent, 415 const char *name) 417 int ext4_directory_find_entry(ext4_directory_search_result_t *result, 418 ext4_inode_ref_t *parent, const char *name) 416 419 { 417 420 int rc; 418 421 uint32_t name_len = strlen(name); 419 422 423 ext4_superblock_t *sb = parent->fs->superblock; 424 420 425 // Index search 421 if (ext4_superblock_has_feature_compatible( fs->superblock, EXT4_FEATURE_COMPAT_DIR_INDEX) &&426 if (ext4_superblock_has_feature_compatible(sb, EXT4_FEATURE_COMPAT_DIR_INDEX) && 422 427 ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) { 423 428 424 rc = ext4_directory_dx_find_entry(result, fs,parent, name_len, name);429 rc = ext4_directory_dx_find_entry(result, parent, name_len, name); 425 430 426 431 // Check if index is not corrupted … … 437 442 438 443 uint32_t iblock, fblock; 439 uint32_t block_size = ext4_superblock_get_block_size( fs->superblock);440 uint32_t inode_size = ext4_inode_get_size( fs->superblock, parent->inode);444 uint32_t block_size = ext4_superblock_get_block_size(sb); 445 uint32_t inode_size = ext4_inode_get_size(sb, parent->inode); 441 446 uint32_t total_blocks = inode_size / block_size; 442 447 443 448 for (iblock = 0; iblock < total_blocks; ++iblock) { 444 449 445 rc = ext4_filesystem_get_inode_data_block_index( fs,parent, iblock, &fblock);450 rc = ext4_filesystem_get_inode_data_block_index(parent, iblock, &fblock); 446 451 if (rc != EOK) { 447 452 return rc; … … 449 454 450 455 block_t *block; 451 rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);456 rc = block_get(&block, parent->fs->device, fblock, BLOCK_FLAGS_NONE); 452 457 if (rc != EOK) { 453 458 return rc; … … 456 461 // find block entry 457 462 ext4_directory_entry_ll_t *res_entry; 458 rc = ext4_directory_find_in_block(block, fs->superblock, name_len, name, &res_entry);463 rc = ext4_directory_find_in_block(block, sb, name_len, name, &res_entry); 459 464 if (rc == EOK) { 460 465 result->block = block; … … 476 481 477 482 478 int ext4_directory_remove_entry(ext4_filesystem_t* fs, 479 ext4_inode_ref_t *parent, const char *name) 483 int ext4_directory_remove_entry(ext4_inode_ref_t *parent, const char *name) 480 484 { 481 485 int rc; 482 486 483 if (!ext4_inode_is_type( fs->superblock, parent->inode,487 if (!ext4_inode_is_type(parent->fs->superblock, parent->inode, 484 488 EXT4_INODE_MODE_DIRECTORY)) { 485 489 return ENOTDIR; … … 487 491 488 492 ext4_directory_search_result_t result; 489 rc = ext4_directory_find_entry( fs,&result, parent, name);493 rc = ext4_directory_find_entry(&result, parent, name); 490 494 if (rc != EOK) { 491 495 return rc; -
uspace/lib/ext4/libext4_directory.h
r38384ae r1ac1ab4 58 58 extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *); 59 59 60 extern int ext4_directory_append_block(ext4_ filesystem_t *,61 ext4_inode_ref_t *,uint32_t *, uint32_t *);60 extern int ext4_directory_append_block(ext4_inode_ref_t *, 61 uint32_t *, uint32_t *); 62 62 63 63 extern void ext4_directory_write_entry(ext4_superblock_t *, 64 64 ext4_directory_entry_ll_t *, uint16_t, ext4_inode_ref_t *, 65 65 const char *, size_t); 66 extern int ext4_directory_add_entry(ext4_ filesystem_t *, ext4_inode_ref_t *,66 extern int ext4_directory_add_entry(ext4_inode_ref_t *, 67 67 const char *, ext4_inode_ref_t *); 68 extern int ext4_directory_find_entry(ext4_filesystem_t *, 69 ext4_directory_search_result_t *, ext4_inode_ref_t *, const char *); 70 extern int ext4_directory_remove_entry(ext4_filesystem_t* , 68 extern int ext4_directory_find_entry(ext4_directory_search_result_t *, 71 69 ext4_inode_ref_t *, const char *); 70 extern int ext4_directory_remove_entry(ext4_inode_ref_t *, const char *); 72 71 73 72 extern int ext4_directory_try_insert_entry(ext4_superblock_t *, -
uspace/lib/ext4/libext4_directory_index.c
r38384ae r1ac1ab4 189 189 190 190 static int ext4_directory_dx_get_leaf(ext4_hash_info_t *hinfo, 191 ext4_ filesystem_t *fs, ext4_inode_ref_t *inode_ref, block_t *root_block,191 ext4_inode_ref_t *inode_ref, block_t *root_block, 192 192 ext4_directory_dx_block_t **dx_block, ext4_directory_dx_block_t *dx_blocks) 193 193 { … … 239 239 240 240 uint32_t fblock; 241 rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref, next_block, &fblock); 241 rc = ext4_filesystem_get_inode_data_block_index( 242 inode_ref, next_block, &fblock); 242 243 if (rc != EOK) { 243 244 return rc; 244 245 } 245 246 246 rc = block_get(&tmp_block, fs->device, fblock, BLOCK_FLAGS_NONE);247 rc = block_get(&tmp_block, inode_ref->fs->device, fblock, BLOCK_FLAGS_NONE); 247 248 if (rc != EOK) { 248 249 return rc; … … 250 251 251 252 entries = ((ext4_directory_dx_node_t *) tmp_block->data)->entries; 252 limit = ext4_directory_dx_countlimit_get_limit((ext4_directory_dx_countlimit_t *)entries); 253 254 uint16_t entry_space = ext4_superblock_get_block_size(fs->superblock) 253 limit = ext4_directory_dx_countlimit_get_limit( 254 (ext4_directory_dx_countlimit_t *)entries); 255 256 uint16_t entry_space = ext4_superblock_get_block_size(inode_ref->fs->superblock) 255 257 - sizeof(ext4_directory_dx_dot_entry_t); 256 258 entry_space = entry_space / sizeof(ext4_directory_dx_entry_t); … … 270 272 271 273 272 static int ext4_directory_dx_next_block(ext4_filesystem_t *fs, 273 ext4_inode_ref_t *inode_ref, uint32_t hash, 274 static int ext4_directory_dx_next_block(ext4_inode_ref_t *inode_ref, uint32_t hash, 274 275 ext4_directory_dx_block_t *handle, ext4_directory_dx_block_t *handles) 275 276 { … … 310 311 uint32_t block_idx = ext4_directory_dx_entry_get_block(p->position); 311 312 uint32_t block_addr; 312 rc = ext4_filesystem_get_inode_data_block_index( fs,inode_ref, block_idx, &block_addr);313 rc = ext4_filesystem_get_inode_data_block_index(inode_ref, block_idx, &block_addr); 313 314 if (rc != EOK) { 314 315 return rc; … … 316 317 317 318 block_t *block; 318 rc = block_get(&block, fs->device, block_addr, BLOCK_FLAGS_NONE);319 rc = block_get(&block, inode_ref->fs->device, block_addr, BLOCK_FLAGS_NONE); 319 320 if (rc != EOK) { 320 321 return rc; … … 334 335 335 336 int ext4_directory_dx_find_entry(ext4_directory_search_result_t *result, 336 ext4_ filesystem_t *fs, ext4_inode_ref_t *inode_ref, size_t name_len, const char *name)337 ext4_inode_ref_t *inode_ref, size_t name_len, const char *name) 337 338 { 338 339 int rc; … … 340 341 // get direct block 0 (index root) 341 342 uint32_t root_block_addr; 342 rc = ext4_filesystem_get_inode_data_block_index( fs,inode_ref, 0, &root_block_addr);343 rc = ext4_filesystem_get_inode_data_block_index(inode_ref, 0, &root_block_addr); 343 344 if (rc != EOK) { 344 345 return rc; 345 346 } 347 348 ext4_filesystem_t *fs = inode_ref->fs; 346 349 347 350 block_t *root_block; … … 361 364 ext4_directory_dx_block_t dx_blocks[2]; 362 365 ext4_directory_dx_block_t *dx_block, *tmp; 363 rc = ext4_directory_dx_get_leaf(&hinfo, fs,inode_ref, root_block, &dx_block, dx_blocks);366 rc = ext4_directory_dx_get_leaf(&hinfo, inode_ref, root_block, &dx_block, dx_blocks); 364 367 if (rc != EOK) { 365 368 block_put(root_block); … … 372 375 uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position); 373 376 uint32_t leaf_block_addr; 374 rc = ext4_filesystem_get_inode_data_block_index( fs,inode_ref, leaf_block_idx, &leaf_block_addr);377 rc = ext4_filesystem_get_inode_data_block_index(inode_ref, leaf_block_idx, &leaf_block_addr); 375 378 if (rc != EOK) { 376 379 goto cleanup; … … 400 403 } 401 404 402 rc = ext4_directory_dx_next_block( fs,inode_ref, hinfo.hash, dx_block, &dx_blocks[0]);405 rc = ext4_directory_dx_next_block(inode_ref, hinfo.hash, dx_block, &dx_blocks[0]); 403 406 if (rc < 0) { 404 407 goto cleanup; … … 524 527 uint32_t new_fblock; 525 528 uint32_t new_iblock; 526 rc = ext4_directory_append_block( fs,inode_ref, &new_fblock, &new_iblock);529 rc = ext4_directory_append_block(inode_ref, &new_fblock, &new_iblock); 527 530 if (rc != EOK) { 528 531 free(sort_array); … … 648 651 uint32_t new_fblock; 649 652 uint32_t new_iblock; 650 rc = ext4_directory_append_block( fs,inode_ref, &new_fblock, &new_iblock);653 rc = ext4_directory_append_block(inode_ref, &new_fblock, &new_iblock); 651 654 if (rc != EOK) { 652 655 return rc; … … 740 743 } 741 744 742 int ext4_directory_dx_add_entry(ext4_ filesystem_t *fs,743 ext4_inode_ref_t * parent, ext4_inode_ref_t *child, const char *name)745 int ext4_directory_dx_add_entry(ext4_inode_ref_t *parent, 746 ext4_inode_ref_t *child, const char *name) 744 747 { 745 748 int rc = EOK; … … 748 751 // get direct block 0 (index root) 749 752 uint32_t root_block_addr; 750 rc = ext4_filesystem_get_inode_data_block_index( fs,parent, 0, &root_block_addr);753 rc = ext4_filesystem_get_inode_data_block_index(parent, 0, &root_block_addr); 751 754 if (rc != EOK) { 752 755 return rc; 753 756 } 757 758 ext4_filesystem_t *fs = parent->fs; 754 759 755 760 block_t *root_block; … … 770 775 ext4_directory_dx_block_t dx_blocks[2]; 771 776 ext4_directory_dx_block_t *dx_block, *dx_it; 772 rc = ext4_directory_dx_get_leaf(&hinfo, fs,parent, root_block, &dx_block, dx_blocks);777 rc = ext4_directory_dx_get_leaf(&hinfo, parent, root_block, &dx_block, dx_blocks); 773 778 if (rc != EOK) { 774 779 rc = EXT4_ERR_BAD_DX_DIR; … … 780 785 uint32_t leaf_block_idx = ext4_directory_dx_entry_get_block(dx_block->position); 781 786 uint32_t leaf_block_addr; 782 rc = ext4_filesystem_get_inode_data_block_index( fs,parent, leaf_block_idx, &leaf_block_addr);787 rc = ext4_filesystem_get_inode_data_block_index(parent, leaf_block_idx, &leaf_block_addr); 783 788 if (rc != EOK) { 784 789 goto release_index; -
uspace/lib/ext4/libext4_directory_index.h
r38384ae r1ac1ab4 67 67 68 68 extern int ext4_directory_dx_find_entry(ext4_directory_search_result_t *, 69 ext4_ filesystem_t *, ext4_inode_ref_t *, size_t, const char *);70 extern int ext4_directory_dx_add_entry( ext4_filesystem_t *,69 ext4_inode_ref_t *, size_t, const char *); 70 extern int ext4_directory_dx_add_entry( 71 71 ext4_inode_ref_t *, ext4_inode_ref_t *, const char *); 72 72 -
uspace/lib/ext4/libext4_extent.c
r38384ae r1ac1ab4 218 218 } 219 219 220 // Reading routine without saving blocks to path 221 //static int ext4_extent_find_extent(ext4_filesystem_t *fs, 222 // ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_t *extent) 223 //{ 224 // int rc; 225 // 226 // block_t* block = NULL; 227 // 228 // ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode); 229 // while (ext4_extent_header_get_depth(header) != 0) { 230 // 231 // ext4_extent_index_t *index; 232 // ext4_extent_binsearch_idx(header, &index, iblock); 233 // 234 // uint64_t child = ext4_extent_index_get_leaf(index); 235 // 236 // if (block != NULL) { 237 // block_put(block); 238 // } 239 // 240 // rc = block_get(&block, fs->device, child, BLOCK_FLAGS_NONE); 241 // if (rc != EOK) { 242 // return rc; 243 // } 244 // 245 // header = (ext4_extent_header_t *)block->data; 246 // } 247 // 248 // 249 // ext4_extent_t* tmp_extent; 250 // ext4_extent_binsearch(header, &tmp_extent, iblock); 251 // 252 // memcpy(extent, tmp_extent, sizeof(ext4_extent_t)); 253 // 254 // return EOK; 255 //} 256 257 static int ext4_extent_find_extent(ext4_filesystem_t *fs, 258 ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path) 220 // Reading routine without saving blocks to path - for saving memory during finding block 221 int ext4_extent_find_block(ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock) 259 222 { 260 223 int rc; 261 224 262 ext4_extent_header_t *eh = 263 ext4_inode_get_extent_header(inode_ref->inode); 264 265 uint16_t depth = ext4_extent_header_get_depth(eh); 266 267 ext4_extent_path_t *tmp_path; 268 269 // Added 2 for possible tree growing 270 tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2)); 271 if (tmp_path == NULL) { 272 return ENOMEM; 273 } 274 275 tmp_path[0].block = inode_ref->block; 276 tmp_path[0].header = eh; 277 278 uint16_t pos = 0; 279 while (ext4_extent_header_get_depth(eh) != 0) { 280 281 ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock); 282 283 tmp_path[pos].depth = depth; 284 tmp_path[pos].extent = NULL; 285 286 assert(tmp_path[pos].index != NULL); 287 288 uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index); 289 290 block_t *block; 291 rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE); 225 block_t* block = NULL; 226 227 ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode); 228 while (ext4_extent_header_get_depth(header) != 0) { 229 230 ext4_extent_index_t *index; 231 ext4_extent_binsearch_idx(header, &index, iblock); 232 233 uint64_t child = ext4_extent_index_get_leaf(index); 234 235 if (block != NULL) { 236 block_put(block); 237 } 238 239 rc = block_get(&block, inode_ref->fs->device, child, BLOCK_FLAGS_NONE); 292 240 if (rc != EOK) { 293 // TODO cleanup294 EXT4FS_DBG("ERRRR");295 241 return rc; 296 242 } 297 243 298 pos++; 299 300 eh = (ext4_extent_header_t *)block->data; 301 tmp_path[pos].block = block; 302 tmp_path[pos].header = eh; 303 304 } 305 306 tmp_path[pos].depth = 0; 307 tmp_path[pos].extent = NULL; 308 tmp_path[pos].index = NULL; 309 310 /* find extent */ 311 ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock); 312 313 *ret_path = tmp_path; 314 315 return EOK; 316 } 317 318 319 int ext4_extent_find_block(ext4_filesystem_t *fs, 320 ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock) 321 { 322 int rc; 323 324 ext4_extent_path_t *path; 325 rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path); 326 if (rc != EOK) { 327 return rc; 328 } 329 330 uint16_t depth = path->depth; 331 332 ext4_extent_t *extent = path[depth].extent; 244 header = (ext4_extent_header_t *)block->data; 245 } 246 247 248 ext4_extent_t* extent; 249 ext4_extent_binsearch(header, &extent, iblock); 250 333 251 334 252 uint32_t phys_block; … … 338 256 *fblock = phys_block; 339 257 340 // Put loaded blocks 341 // From 1 -> 0 is a block with inode data 342 for (uint16_t i = 1; i < depth; ++i) { 343 if (path[i].block) { 344 block_put(path[i].block); 345 } 346 } 347 348 // Destroy temporary data structure 349 free(path); 258 if (block != NULL) { 259 block_put(block); 260 } 261 350 262 351 263 return EOK; 352 353 } 264 } 265 266 //static int ext4_extent_find_extent(ext4_filesystem_t *fs, 267 // ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path) 268 //{ 269 // int rc; 270 // 271 // ext4_extent_header_t *eh = 272 // ext4_inode_get_extent_header(inode_ref->inode); 273 // 274 // uint16_t depth = ext4_extent_header_get_depth(eh); 275 // 276 // ext4_extent_path_t *tmp_path; 277 // 278 // // Added 2 for possible tree growing 279 // tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2)); 280 // if (tmp_path == NULL) { 281 // return ENOMEM; 282 // } 283 // 284 // tmp_path[0].block = inode_ref->block; 285 // tmp_path[0].header = eh; 286 // 287 // uint16_t pos = 0; 288 // while (ext4_extent_header_get_depth(eh) != 0) { 289 // 290 // ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock); 291 // 292 // tmp_path[pos].depth = depth; 293 // tmp_path[pos].extent = NULL; 294 // 295 // assert(tmp_path[pos].index != NULL); 296 // 297 // uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index); 298 // 299 // block_t *block; 300 // rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE); 301 // if (rc != EOK) { 302 // // TODO cleanup 303 // EXT4FS_DBG("ERRRR"); 304 // return rc; 305 // } 306 // 307 // pos++; 308 // 309 // eh = (ext4_extent_header_t *)block->data; 310 // tmp_path[pos].block = block; 311 // tmp_path[pos].header = eh; 312 // 313 // } 314 // 315 // tmp_path[pos].depth = 0; 316 // tmp_path[pos].extent = NULL; 317 // tmp_path[pos].index = NULL; 318 // 319 // /* find extent */ 320 // ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock); 321 // 322 // *ret_path = tmp_path; 323 // 324 // return EOK; 325 //} 326 327 328 //int ext4_extent_find_block(ext4_filesystem_t *fs, 329 // ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock) 330 //{ 331 // int rc; 332 // 333 // ext4_extent_path_t *path; 334 // rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path); 335 // if (rc != EOK) { 336 // return rc; 337 // } 338 // 339 // uint16_t depth = path->depth; 340 // 341 // ext4_extent_t *extent = path[depth].extent; 342 // 343 // uint32_t phys_block; 344 // phys_block = ext4_extent_get_start(extent) + iblock; 345 // phys_block -= ext4_extent_get_first_block(extent); 346 // 347 // *fblock = phys_block; 348 // 349 // // Put loaded blocks 350 // // From 1 -> 0 is a block with inode data 351 // for (uint16_t i = 1; i < depth; ++i) { 352 // if (path[i].block) { 353 // block_put(path[i].block); 354 // } 355 // } 356 // 357 // // Destroy temporary data structure 358 // free(path); 359 // 360 // return EOK; 361 // 362 //} 354 363 355 364 /** -
uspace/lib/ext4/libext4_extent.h
r38384ae r1ac1ab4 61 61 extern void ext4_extent_header_set_generation(ext4_extent_header_t *, uint32_t); 62 62 63 extern int ext4_extent_find_block(ext4_filesystem_t *, ext4_inode_ref_t *, 64 uint32_t, uint32_t *); 63 extern int ext4_extent_find_block(ext4_inode_ref_t *, uint32_t, uint32_t *); 65 64 #endif 66 65 -
uspace/lib/ext4/libext4_filesystem.c
r38384ae r1ac1ab4 169 169 170 170 newref->block_group = newref->block->data + offset; 171 newref->fs = fs; 172 newref->index = bgid; 171 173 newref->dirty = false; 172 174 … … 176 178 } 177 179 180 static uint16_t ext4_filesystem_bg_checksum(ext4_superblock_t *sb, uint32_t bgid, 181 ext4_block_group_t *bg) 182 { 183 uint16_t crc = 0; 184 185 if (ext4_superblock_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 186 187 void *base = bg; 188 void *checksum = &bg->checksum; 189 190 uint32_t offset = (uint32_t)(checksum - base); 191 192 uint32_t le_group = host2uint32_t_le(bgid); 193 194 crc = crc16(~0, sb->uuid, sizeof(sb->uuid)); 195 crc = crc16(crc, (uint8_t *)&le_group, sizeof(le_group)); 196 crc = crc16(crc, (uint8_t *)bg, offset); 197 198 offset += sizeof(bg->checksum); /* skip checksum */ 199 200 /* for checksum of struct ext4_group_desc do the rest...*/ 201 if ((ext4_superblock_has_feature_incompatible(sb, EXT4_FEATURE_INCOMPAT_64BIT)) && 202 offset < ext4_superblock_get_desc_size(sb)) { 203 204 crc = crc16(crc, ((uint8_t *)bg) + offset, ext4_superblock_get_desc_size(sb) - offset); 205 } 206 } 207 208 return crc; 209 210 } 211 212 178 213 int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *ref) 179 214 { … … 181 216 182 217 if (ref->dirty) { 218 uint16_t checksum = ext4_filesystem_bg_checksum( 219 ref->fs->superblock, ref->index, ref->block_group); 220 221 ext4_block_group_set_checksum(ref->block_group, checksum); 222 183 223 ref->block->dirty = true; 184 224 } … … 242 282 * in the reference 243 283 */ 244 newref->index = index+1; 284 newref->index = index + 1; 285 newref->fs = fs; 245 286 newref->dirty = false; 246 287 … … 321 362 } 322 363 323 int ext4_filesystem_free_inode(ext4_ filesystem_t *fs, ext4_inode_ref_t *inode_ref)364 int ext4_filesystem_free_inode(ext4_inode_ref_t *inode_ref) 324 365 { 325 366 int rc; … … 330 371 uint32_t fblock = ext4_inode_get_indirect_block(inode_ref->inode, 0); 331 372 if (fblock != 0) { 332 rc = ext4_balloc_free_block( fs,inode_ref, fblock);373 rc = ext4_balloc_free_block(inode_ref, fblock); 333 374 if (rc != EOK) { 334 375 return rc; … … 337 378 ext4_inode_set_indirect_block(inode_ref->inode, 0, 0); 338 379 } 380 381 ext4_filesystem_t *fs = inode_ref->fs; 339 382 340 383 block_t *block; … … 355 398 356 399 if (ind_block != 0) { 357 rc = ext4_balloc_free_block( fs,inode_ref, ind_block);400 rc = ext4_balloc_free_block(inode_ref, ind_block); 358 401 if (rc != EOK) { 359 402 block_put(block); … … 364 407 365 408 block_put(block); 366 rc = ext4_balloc_free_block( fs,inode_ref, fblock);409 rc = ext4_balloc_free_block(inode_ref, fblock); 367 410 if (rc != EOK) { 368 411 return rc; … … 398 441 399 442 if (ind_subblock != 0) { 400 rc = ext4_balloc_free_block( fs,inode_ref, ind_subblock);443 rc = ext4_balloc_free_block(inode_ref, ind_subblock); 401 444 if (rc != EOK) { 402 445 block_put(subblock); … … 411 454 } 412 455 413 rc = ext4_balloc_free_block( fs,inode_ref, ind_block);456 rc = ext4_balloc_free_block(inode_ref, ind_block); 414 457 if (rc != EOK) { 415 458 block_put(block); … … 421 464 422 465 block_put(block); 423 rc = ext4_balloc_free_block( fs,inode_ref, fblock);466 rc = ext4_balloc_free_block(inode_ref, fblock); 424 467 if (rc != EOK) { 425 468 return rc; … … 445 488 } 446 489 447 int ext4_filesystem_truncate_inode( ext4_filesystem_t *fs,490 int ext4_filesystem_truncate_inode( 448 491 ext4_inode_ref_t *inode_ref, aoff64_t new_size) 449 492 { 450 493 int rc; 451 494 452 if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) { 495 ext4_superblock_t *sb = inode_ref->fs->superblock; 496 497 if (! ext4_inode_can_truncate(sb, inode_ref->inode)) { 453 498 // Unable to truncate 454 499 return EINVAL; 455 500 } 456 501 457 aoff64_t old_size = ext4_inode_get_size( fs->superblock, inode_ref->inode);502 aoff64_t old_size = ext4_inode_get_size(sb, inode_ref->inode); 458 503 if (old_size == new_size) { 459 504 // Nothing to do … … 467 512 468 513 aoff64_t size_diff = old_size - new_size; 469 uint32_t block_size = ext4_superblock_get_block_size( fs->superblock);514 uint32_t block_size = ext4_superblock_get_block_size(sb); 470 515 uint32_t diff_blocks_count = size_diff / block_size; 471 516 if (size_diff % block_size != 0) { … … 480 525 // starting from 1 because of logical blocks are numbered from 0 481 526 for (uint32_t i = 1; i <= diff_blocks_count; ++i) { 482 rc = ext4_filesystem_release_inode_block( fs,inode_ref, old_blocks_count - i);527 rc = ext4_filesystem_release_inode_block(inode_ref, old_blocks_count - i); 483 528 if (rc != EOK) { 484 529 return rc; … … 493 538 } 494 539 495 int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *fs, 496 ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t* fblock) 497 { 498 int rc; 499 540 int ext4_filesystem_get_inode_data_block_index(ext4_inode_ref_t *inode_ref, 541 aoff64_t iblock, uint32_t* fblock) 542 { 543 int rc; 544 545 ext4_filesystem_t *fs = inode_ref->fs; 500 546 501 547 uint32_t current_block; … … 504 550 if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 505 551 ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) { 506 rc = ext4_extent_find_block( fs,inode_ref, iblock, ¤t_block);552 rc = ext4_extent_find_block(inode_ref, iblock, ¤t_block); 507 553 508 554 if (rc != EOK) { … … 591 637 592 638 593 int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *fs, 594 ext4_inode_ref_t *inode_ref, aoff64_t iblock, uint32_t fblock) 595 { 596 int rc; 597 639 int ext4_filesystem_set_inode_data_block_index(ext4_inode_ref_t *inode_ref, 640 aoff64_t iblock, uint32_t fblock) 641 { 642 int rc; 643 644 ext4_filesystem_t *fs = inode_ref->fs; 598 645 599 646 /* Handle inode using extents */ … … 635 682 636 683 if (current_block == 0) { 637 rc = ext4_balloc_alloc_block( fs,inode_ref, &new_block_addr);684 rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr); 638 685 if (rc != EOK) { 639 686 return rc; … … 646 693 rc = block_get(&new_block, fs->device, new_block_addr, BLOCK_FLAGS_NOREAD); 647 694 if (rc != EOK) { 648 ext4_balloc_free_block( fs,inode_ref, new_block_addr);695 ext4_balloc_free_block(inode_ref, new_block_addr); 649 696 return rc; 650 697 } … … 674 721 675 722 if ((level > 1) && (current_block == 0)) { 676 rc = ext4_balloc_alloc_block( fs,inode_ref, &new_block_addr);723 rc = ext4_balloc_alloc_block(inode_ref, &new_block_addr); 677 724 if (rc != EOK) { 678 725 block_put(block); … … 727 774 } 728 775 729 int ext4_filesystem_release_inode_block( ext4_filesystem_t *fs,776 int ext4_filesystem_release_inode_block( 730 777 ext4_inode_ref_t *inode_ref, uint32_t iblock) 731 778 { … … 733 780 734 781 uint32_t fblock; 782 783 ext4_filesystem_t *fs = inode_ref->fs; 735 784 736 785 /* TODO Handle extents */ … … 772 821 773 822 ext4_inode_set_direct_block(inode, iblock, 0); 774 return ext4_balloc_free_block( fs,inode_ref, fblock);823 return ext4_balloc_free_block(inode_ref, fblock); 775 824 } 776 825 … … 837 886 } 838 887 839 return ext4_balloc_free_block( fs,inode_ref, fblock);840 841 } 842 843 int ext4_filesystem_add_orphan(ext4_ filesystem_t *fs,844 ext4_inode_ref_t *inode_ref) 845 { 846 uint32_t next_orphan = ext4_superblock_get_last_orphan(fs->superblock);888 return ext4_balloc_free_block(inode_ref, fblock); 889 890 } 891 892 int ext4_filesystem_add_orphan(ext4_inode_ref_t *inode_ref) 893 { 894 uint32_t next_orphan = ext4_superblock_get_last_orphan( 895 inode_ref->fs->superblock); 847 896 ext4_inode_set_deletion_time(inode_ref->inode, next_orphan); 848 ext4_superblock_set_last_orphan(fs->superblock, inode_ref->index); 897 ext4_superblock_set_last_orphan( 898 inode_ref->fs->superblock, inode_ref->index); 849 899 inode_ref->dirty = true; 850 900 … … 852 902 } 853 903 854 int ext4_filesystem_delete_orphan(ext4_ filesystem_t *fs,855 ext4_inode_ref_t *inode_ref) 856 { 857 int rc; 858 859 uint32_t last_orphan = ext4_superblock_get_last_orphan(fs->superblock);904 int ext4_filesystem_delete_orphan(ext4_inode_ref_t *inode_ref) 905 { 906 int rc; 907 908 uint32_t last_orphan = ext4_superblock_get_last_orphan( 909 inode_ref->fs->superblock); 860 910 assert(last_orphan > 0); 861 911 … … 863 913 864 914 if (last_orphan == inode_ref->index) { 865 ext4_superblock_set_last_orphan( fs->superblock, next_orphan);915 ext4_superblock_set_last_orphan(inode_ref->fs->superblock, next_orphan); 866 916 ext4_inode_set_deletion_time(inode_ref->inode, 0); 867 917 inode_ref->dirty = true; … … 870 920 871 921 ext4_inode_ref_t *current; 872 rc = ext4_filesystem_get_inode_ref( fs, last_orphan, ¤t);922 rc = ext4_filesystem_get_inode_ref(inode_ref->fs, last_orphan, ¤t); 873 923 if (rc != EOK) { 874 924 return rc; … … 889 939 ext4_filesystem_put_inode_ref(current); 890 940 891 rc = ext4_filesystem_get_inode_ref( fs, next_orphan, ¤t);941 rc = ext4_filesystem_get_inode_ref(inode_ref->fs, next_orphan, ¤t); 892 942 if (rc != EOK) { 893 943 return rc; -
uspace/lib/ext4/libext4_filesystem.h
r38384ae r1ac1ab4 49 49 extern int ext4_filesystem_alloc_inode(ext4_filesystem_t *, 50 50 ext4_inode_ref_t **, int); 51 extern int ext4_filesystem_free_inode(ext4_filesystem_t *, ext4_inode_ref_t *); 52 extern int ext4_filesystem_truncate_inode(ext4_filesystem_t *, 53 ext4_inode_ref_t *, aoff64_t); 54 extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *, 55 ext4_inode_ref_t *, aoff64_t iblock, uint32_t *); 56 extern int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *, 57 ext4_inode_ref_t *, aoff64_t, uint32_t); 58 extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *, 51 extern int ext4_filesystem_free_inode(ext4_inode_ref_t *); 52 extern int ext4_filesystem_truncate_inode(ext4_inode_ref_t *, aoff64_t); 53 extern int ext4_filesystem_get_inode_data_block_index(ext4_inode_ref_t *, 54 aoff64_t iblock, uint32_t *); 55 extern int ext4_filesystem_set_inode_data_block_index(ext4_inode_ref_t *, 56 aoff64_t, uint32_t); 57 extern int ext4_filesystem_release_inode_block( 59 58 ext4_inode_ref_t *, uint32_t); 60 extern int ext4_filesystem_add_orphan(ext4_filesystem_t *, 61 ext4_inode_ref_t *); 62 extern int ext4_filesystem_delete_orphan(ext4_filesystem_t *, 63 ext4_inode_ref_t *); 59 extern int ext4_filesystem_add_orphan(ext4_inode_ref_t *); 60 extern int ext4_filesystem_delete_orphan(ext4_inode_ref_t *); 61 62 extern uint16_t ext4_group_desc_csum(ext4_superblock_t *, uint32_t, 63 ext4_block_group_t *); 64 64 #endif 65 65 -
uspace/lib/ext4/libext4_ialloc.c
r38384ae r1ac1ab4 111 111 ext4_block_group_set_free_inodes_count(bg_ref->block_group, 112 112 sb, free_inodes); 113 114 uint32_t unused_inodes = ext4_block_group_get_itable_unused( 115 bg_ref->block_group, sb); 116 unused_inodes++; 117 ext4_block_group_set_itable_unused(bg_ref->block_group, sb, unused_inodes); 118 119 113 120 bg_ref->dirty = true; 114 121 … … 186 193 ext4_block_group_set_free_inodes_count(bg, sb, free_inodes); 187 194 195 uint16_t unused_inodes = ext4_block_group_get_itable_unused(bg, sb); 196 unused_inodes--; 197 ext4_block_group_set_itable_unused(bg, sb, unused_inodes); 198 188 199 if (is_dir) { 189 200 used_dirs++; -
uspace/lib/ext4/libext4_types.h
r38384ae r1ac1ab4 194 194 195 195 /*****************************************************************************/ 196 197 typedef struct ext4_filesystem { 198 service_id_t device; 199 ext4_superblock_t * superblock; 200 aoff64_t inode_block_limits[4]; 201 aoff64_t inode_blocks_per_level[4]; 202 } ext4_filesystem_t; 203 204 205 /*****************************************************************************/ 206 207 196 208 /* 197 209 * Structure of a blocks group descriptor … … 222 234 block_t *block; // Reference to a block containing this block group descr 223 235 ext4_block_group_t *block_group; 236 ext4_filesystem_t *fs; 237 uint32_t index; 224 238 bool dirty; 225 239 } ext4_block_group_ref_t; … … 229 243 #define EXT4_BLOCK_MAX_GROUP_DESCRIPTOR_SIZE 64 230 244 231 232 /*****************************************************************************/ 233 234 typedef struct ext4_filesystem { 235 service_id_t device; 236 ext4_superblock_t * superblock; 237 aoff64_t inode_block_limits[4]; 238 aoff64_t inode_blocks_per_level[4]; 239 } ext4_filesystem_t; 245 /*****************************************************************************/ 246 240 247 241 248 #define EXT4_MIN_BLOCK_SIZE 1024 //1 KiB 242 249 #define EXT4_MAX_BLOCK_SIZE 65536 //64 KiB 243 250 #define EXT4_REV0_INODE_SIZE 128 244 245 /*****************************************************************************/246 247 251 248 252 #define EXT4_INODE_BLOCK_SIZE 512 … … 346 350 block_t *block; // Reference to a block containing this inode 347 351 ext4_inode_t *inode; 352 ext4_filesystem_t *fs; 348 353 uint32_t index; // Index number of this inode 349 354 bool dirty; -
uspace/srv/fs/ext4fs/ext4fs.c
r38384ae r1ac1ab4 61 61 ext4fs_vfs_info.instance = strtol(argv[2], NULL, 10); 62 62 else { 63 printf(NAME " Unrecognized parameters ");63 printf(NAME " Unrecognized parameters\n"); 64 64 return -1; 65 65 } -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r38384ae r1ac1ab4 211 211 212 212 ext4_directory_search_result_t result; 213 rc = ext4_directory_find_entry( fs,&result, eparent->inode_ref, component);213 rc = ext4_directory_find_entry(&result, eparent->inode_ref, component); 214 214 if (rc != EOK) { 215 215 if (rc == ENOENT) { … … 448 448 ext4_inode_ref_t *inode_ref = enode->inode_ref; 449 449 450 rc = ext4_filesystem_truncate_inode( fs,inode_ref, 0);450 rc = ext4_filesystem_truncate_inode(inode_ref, 0); 451 451 if (rc != EOK) { 452 452 ext4fs_node_put(fn); … … 456 456 uint32_t rev_level = ext4_superblock_get_rev_level(fs->superblock); 457 457 if (rev_level > 0) { 458 ext4_filesystem_delete_orphan( fs,inode_ref);458 ext4_filesystem_delete_orphan(inode_ref); 459 459 } 460 460 … … 465 465 inode_ref->dirty = true; 466 466 467 rc = ext4_filesystem_free_inode( fs,inode_ref);467 rc = ext4_filesystem_free_inode(inode_ref); 468 468 if (rc != EOK) { 469 469 ext4fs_node_put(fn); … … 489 489 490 490 // Add entry to parent directory 491 rc = ext4_directory_add_entry( fs,parent->inode_ref, name, child->inode_ref);491 rc = ext4_directory_add_entry(parent->inode_ref, name, child->inode_ref); 492 492 if (rc != EOK) { 493 493 return rc; … … 497 497 if (ext4_inode_is_type(fs->superblock, child->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY)) { 498 498 499 rc = ext4_directory_add_entry( fs,child->inode_ref, ".", child->inode_ref);499 rc = ext4_directory_add_entry(child->inode_ref, ".", child->inode_ref); 500 500 if (rc != EOK) { 501 ext4_directory_remove_entry( fs,parent->inode_ref, name);501 ext4_directory_remove_entry(parent->inode_ref, name); 502 502 return rc; 503 503 } 504 504 505 rc = ext4_directory_add_entry( fs,child->inode_ref, "..", parent->inode_ref);505 rc = ext4_directory_add_entry(child->inode_ref, "..", parent->inode_ref); 506 506 if (rc != EOK) { 507 ext4_directory_remove_entry( fs,parent->inode_ref, name);508 ext4_directory_remove_entry( fs,child->inode_ref, ".");507 ext4_directory_remove_entry(parent->inode_ref, name); 508 ext4_directory_remove_entry(child->inode_ref, "."); 509 509 return rc; 510 510 } … … 546 546 ext4_inode_ref_t *parent = EXT4FS_NODE(pfn)->inode_ref; 547 547 ext4_filesystem_t *fs = EXT4FS_NODE(pfn)->instance->filesystem; 548 rc = ext4_directory_remove_entry( fs,parent, name);548 rc = ext4_directory_remove_entry(parent, name); 549 549 if (rc != EOK) { 550 550 return rc; … … 576 576 uint32_t rev_level = ext4_superblock_get_rev_level(fs->superblock); 577 577 if ((rev_level > 0) && (lnk_count == 0)) { 578 ext4_filesystem_add_orphan( fs,child_inode_ref);578 ext4_filesystem_add_orphan(child_inode_ref); 579 579 } 580 580 … … 1002 1002 /* Get the real block number */ 1003 1003 uint32_t fs_block; 1004 rc = ext4_filesystem_get_inode_data_block_index(inst->filesystem, 1005 inode_ref, file_block, &fs_block); 1004 rc = ext4_filesystem_get_inode_data_block_index(inode_ref, file_block, &fs_block); 1006 1005 if (rc != EOK) { 1007 1006 async_answer_0(callid, rc); … … 1090 1089 1091 1090 ext4_inode_ref_t *inode_ref = enode->inode_ref; 1092 rc = ext4_filesystem_get_inode_data_block_index( fs,inode_ref, iblock, &fblock);1091 rc = ext4_filesystem_get_inode_data_block_index(inode_ref, iblock, &fblock); 1093 1092 if (rc != EOK) { 1094 1093 ext4fs_node_put(fn); … … 1098 1097 1099 1098 if (fblock == 0) { 1100 rc = ext4_balloc_alloc_block( fs,inode_ref, &fblock);1099 rc = ext4_balloc_alloc_block(inode_ref, &fblock); 1101 1100 if (rc != EOK) { 1102 1101 ext4fs_node_put(fn); … … 1105 1104 } 1106 1105 1107 rc = ext4_filesystem_set_inode_data_block_index( fs,inode_ref, iblock, fblock);1106 rc = ext4_filesystem_set_inode_data_block_index(inode_ref, iblock, fblock); 1108 1107 if (rc != EOK) { 1109 ext4_balloc_free_block( fs,inode_ref, fblock);1108 ext4_balloc_free_block(inode_ref, fblock); 1110 1109 ext4fs_node_put(fn); 1111 1110 async_answer_0(callid, rc); … … 1169 1168 ext4fs_node_t *enode = EXT4FS_NODE(fn); 1170 1169 ext4_inode_ref_t *inode_ref = enode->inode_ref; 1171 ext4_filesystem_t *fs = enode->instance->filesystem; 1172 1173 rc = ext4_filesystem_truncate_inode(fs, inode_ref, new_size); 1170 1171 rc = ext4_filesystem_truncate_inode(inode_ref, new_size); 1174 1172 ext4fs_node_put(fn); 1175 1173
Note:
See TracChangeset
for help on using the changeset viewer.