Changeset 528e5b3 in mainline
- Timestamp:
- 2011-11-18T17:06:12Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ae3d4f8
- Parents:
- d5ba17f
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_balloc.c
rd5ba17f r528e5b3 136 136 } 137 137 138 // EXT4FS_DBG("released block \%u (idx = \%u)", block_addr, index_in_group);139 138 return EOK; 140 139 } … … 191 190 192 191 goal++; 193 194 // EXT4FS_DBG("goal = \%u, inode_block_count == \%u", goal, inode_block_count);195 196 192 return goal; 197 193 } 198 199 // EXT4FS_DBG("Inode has no blocks");200 194 201 195 // Identify block group of inode … … 243 237 uint32_t allocated_block = 0; 244 238 245 uint32_t bitmap_block ;246 block_t *b lock;239 uint32_t bitmap_block_addr; 240 block_t *bitmap_block; 247 241 uint32_t rel_block_idx = 0; 248 242 … … 258 252 uint32_t block_group = ext4_balloc_get_bgid_of_block(fs->superblock, goal); 259 253 uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(fs->superblock, goal); 260 // EXT4FS_DBG("block_group = \%u, index_in_group = \%u", block_group, index_in_group);261 262 254 263 255 … … 273 265 bg_ref->block_group, block_group); 274 266 275 if (index_in_group < first_in_group) { 276 index_in_group = first_in_group; 267 uint32_t first_in_group_index = ext4_balloc_blockaddr2_index_in_group( 268 fs->superblock, first_in_group); 269 270 if (index_in_group < first_in_group_index) { 271 index_in_group = first_in_group_index; 277 272 } 278 273 279 274 // Load bitmap 280 bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);281 282 rc = block_get(&b lock, fs->device, bitmap_block, 0);275 bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group); 276 277 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0); 283 278 if (rc != EOK) { 284 279 ext4_filesystem_put_block_group_ref(bg_ref); … … 287 282 } 288 283 289 // EXT4FS_DBG("bitmap loaded");290 291 284 // Check if goal is free 292 if (ext4_bitmap_is_free_bit(b lock->data, index_in_group)) {293 ext4_bitmap_set_bit(b lock->data, index_in_group);294 b lock->dirty = true;295 rc = block_put(b lock);285 if (ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group)) { 286 ext4_bitmap_set_bit(bitmap_block->data, index_in_group); 287 bitmap_block->dirty = true; 288 rc = block_put(bitmap_block); 296 289 if (rc != EOK) { 297 290 // TODO error … … 308 301 uint32_t blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, block_group); 309 302 310 // EXT4FS_DBG("index = \%u (goal = \%u), blocks_in_group = \%u", index_in_group, goal, blocks_in_group);311 312 303 uint32_t end_idx = (index_in_group + 63) & ~63; 313 304 if (end_idx > blocks_in_group) { … … 317 308 // Try to find free block near to goal 318 309 for (uint32_t tmp_idx = index_in_group + 1; tmp_idx < end_idx; ++tmp_idx) { 319 if (ext4_bitmap_is_free_bit(b lock->data, tmp_idx)) {320 321 ext4_bitmap_set_bit(b lock->data, tmp_idx);322 b lock->dirty = true;323 rc = block_put(b lock);310 if (ext4_bitmap_is_free_bit(bitmap_block->data, tmp_idx)) { 311 312 ext4_bitmap_set_bit(bitmap_block->data, tmp_idx); 313 bitmap_block->dirty = true; 314 rc = block_put(bitmap_block); 324 315 if (rc != EOK) { 325 316 // TODO error … … 330 321 fs->superblock, tmp_idx, block_group); 331 322 332 333 // EXT4FS_DBG("block \%u (idx = \%u) allocated, goal = \%u", allocated_block, tmp_idx, goal);334 335 323 goto success; 336 324 } … … 339 327 340 328 // Find free BYTE in bitmap 341 // EXT4FS_DBG("try find free byte in own BG"); 342 rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group); 329 rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group); 343 330 if (rc == EOK) { 344 b lock->dirty = true;345 rc = block_put(b lock);331 bitmap_block->dirty = true; 332 rc = block_put(bitmap_block); 346 333 if (rc != EOK) { 347 334 // TODO error … … 352 339 fs->superblock, rel_block_idx, block_group); 353 340 354 // EXT4FS_DBG("block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);355 356 341 goto success; 357 342 } 358 343 359 344 // Find free bit in bitmap 360 EXT4FS_DBG("find free bit"); 361 rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group); 345 rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group); 362 346 if (rc == EOK) { 363 b lock->dirty = true;364 rc = block_put(b lock);347 bitmap_block->dirty = true; 348 rc = block_put(bitmap_block); 365 349 if (rc != EOK) { 366 350 // TODO error … … 371 355 fs->superblock, rel_block_idx, block_group); 372 356 373 EXT4FS_DBG("find free bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);374 375 357 goto success; 376 358 } 377 359 378 block_put(b lock);360 block_put(bitmap_block); 379 361 ext4_filesystem_put_block_group_ref(bg_ref); 380 362 … … 386 368 387 369 while (count > 0) { 388 EXT4FS_DBG("trying group \%u", bgid);389 390 370 rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref); 391 371 if (rc != EOK) { … … 395 375 396 376 // Load bitmap 397 bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);398 399 rc = block_get(&b lock, fs->device, bitmap_block, 0);377 bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group); 378 379 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0); 400 380 if (rc != EOK) { 401 381 ext4_filesystem_put_block_group_ref(bg_ref); … … 410 390 blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, bgid); 411 391 412 if (index_in_group < first_in_group) { 413 index_in_group = first_in_group; 414 } 415 416 // EXT4FS_DBG("trying free byte in bg \%u", bgid); 417 rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group); 392 first_in_group_index = ext4_balloc_blockaddr2_index_in_group( 393 fs->superblock, first_in_group); 394 395 if (index_in_group < first_in_group_index) { 396 index_in_group = first_in_group_index; 397 } 398 399 400 rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group); 418 401 if (rc == EOK) { 419 b lock->dirty = true;420 rc = block_put(b lock);402 bitmap_block->dirty = true; 403 rc = block_put(bitmap_block); 421 404 if (rc != EOK) { 422 405 // TODO error … … 427 410 fs->superblock, rel_block_idx, bgid); 428 411 429 EXT4FS_DBG("byte: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);430 431 412 goto success; 432 413 } 433 414 434 415 // Find free bit in bitmap 435 rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group); 436 // EXT4FS_DBG("trying free bit in bg \%u", bgid); 416 rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group); 437 417 if (rc == EOK) { 438 b lock->dirty = true;439 rc = block_put(b lock);418 bitmap_block->dirty = true; 419 rc = block_put(bitmap_block); 440 420 if (rc != EOK) { 441 421 // TODO error … … 446 426 fs->superblock, rel_block_idx, bgid); 447 427 448 EXT4FS_DBG("bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);449 450 428 goto success; 451 429 } … … 453 431 454 432 // Next group 455 block_put(b lock);433 block_put(bitmap_block); 456 434 ext4_filesystem_put_block_group_ref(bg_ref); 457 435 bgid = (bgid + 1) % block_group_count; … … 459 437 } 460 438 461 EXT4FS_DBG("No free block found");462 439 return ENOSPC; 463 440 464 441 success: 465 466 ; 467 // EXT4FS_DBG("returning block \%u", allocated_block); 468 442 ; // Empty command - because of syntax 443 469 444 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 470 445 … … 486 461 ext4_filesystem_put_block_group_ref(bg_ref); 487 462 488 // if (goal > 1980)489 // EXT4FS_DBG("block \%u allocated", allocated_block);490 491 463 *fblock = allocated_block; 492 464 return EOK; -
uspace/lib/ext4/libext4_bitmap.c
rd5ba17f r528e5b3 114 114 byte_part = true; 115 115 116 if ( *pos & (1 << (idx % 8))) {116 if ((*pos & (1 << (idx % 8))) == 0) { 117 117 *pos |= (1 << (idx % 8)); 118 118 *index = idx; -
uspace/srv/fs/ext4fs/ext4fs_ops.c
rd5ba17f r528e5b3 972 972 973 973 if (fblock == 0) { 974 975 974 rc = ext4_balloc_alloc_block(fs, inode_ref, &fblock); 976 975 if (rc != EOK) { 977 EXT4FS_DBG("allocation failed");978 976 ext4fs_node_put(fn); 979 977 async_answer_0(callid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.