Changeset f66d903 in mainline
- Timestamp:
- 2011-03-15T20:20:07Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 953a823
- Parents:
- 245eb02d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkminix/mkminix.c
r245eb02d rf66d903 58 58 #define UPPER(n, size) (((n) / (size)) + (((n) % (size)) != 0)) 59 59 #define NEXT_DENTRY(p, dirsize) (p += dirsize) 60 #define FIRST_ZONE(bs) (1 + (bs) / MFS_MIN_BLOCKSIZE)61 #define CONVERT_1K_OFF(off, bs) ((off) * ((bs) / MFS_MIN_BLOCKSIZE))62 60 63 61 typedef enum { … … 97 95 static int insert_dentries(const struct mfs_sb_info *sb); 98 96 99 static inline int write_ 1k_block(aoff64_t off, size_t size, const void *data);97 static inline int write_block(aoff64_t off, size_t size, const void *data); 100 98 101 99 static devmap_handle_t handle; 100 static int shift; 102 101 103 102 static struct option const long_options[] = { … … 193 192 } 194 193 194 if (sb.block_size == MFS_MIN_BLOCKSIZE) 195 shift = 1; 196 else if (sb.block_size == MFS_MAX_BLOCKSIZE) 197 shift = 3; 198 else 199 shift = 2; 200 195 201 argv += optind; 196 202 … … 208 214 } 209 215 210 rc = block_init(handle, MFS_MIN_BLOCKSIZE);216 rc = block_init(handle, 2048); 211 217 if (rc != EOK) { 212 218 printf(NAME ": Error initializing libblock.\n"); … … 280 286 void *root_block; 281 287 int rc; 282 const long root_dblock = CONVERT_1K_OFF(sb->first_data_zone, sb->block_size);283 284 root_block = (void *) malloc( MFS_MIN_BLOCKSIZE);285 memset(root_block, 0x00, MFS_MIN_BLOCKSIZE);288 const long root_dblock = sb->first_data_zone; 289 290 root_block = (void *) malloc(sb->block_size); 291 memset(root_block, 0x00, sb->block_size); 286 292 287 293 if (!root_block) … … 312 318 } 313 319 314 rc = write_ 1k_block(root_dblock, 1, root_block);320 rc = write_block(root_dblock, 1, root_block); 315 321 316 322 free(root_block); … … 323 329 uint8_t *itable_buf; 324 330 int rc; 325 long itable_off; 326 unsigned long itable_size; 327 328 itable_off = sb->zbmap_blocks + sb->ibmap_blocks; 329 330 /*Convert to 1K offset*/ 331 itable_off = CONVERT_1K_OFF(itable_off, sb->block_size) + 332 FIRST_ZONE(sb->block_size); 333 itable_size = CONVERT_1K_OFF(sb->itable_size, sb->block_size); 334 335 itable_buf = malloc(MFS_MIN_BLOCKSIZE); 331 332 long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2; 333 unsigned long itable_size = sb->itable_size; 334 335 itable_buf = malloc(sb->block_size); 336 336 337 337 if (!itable_buf) 338 338 return ENOMEM; 339 339 340 memset(itable_buf, 0x00, MFS_MIN_BLOCKSIZE);340 memset(itable_buf, 0x00, sb->block_size); 341 341 342 342 for (i = 0; i < itable_size; ++i, ++itable_off) { 343 rc = write_ 1k_block(itable_off, 1, itable_buf);343 rc = write_block(itable_off, 1, itable_buf); 344 344 345 345 if (rc != EOK) … … 354 354 { 355 355 struct mfs_inode *ino_buf; 356 long itable_off; 357 int rc; 358 359 itable_off = FIRST_ZONE(MFS_BLOCKSIZE); 360 itable_off += sb->zbmap_blocks + sb->ibmap_blocks; 356 int rc; 357 358 const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2; 361 359 362 360 const time_t sec = time(NULL); … … 377 375 ino_buf[MFS_ROOT_INO].i_dzone[0] = sb->first_data_zone; 378 376 379 rc = write_ 1k_block(itable_off, 1, ino_buf);377 rc = write_block(itable_off, 1, ino_buf); 380 378 381 379 free(ino_buf); … … 386 384 { 387 385 struct mfs2_inode *ino_buf; 388 long itable_off;389 386 int rc; 390 387 391 388 /*Compute offset of the first inode table block*/ 392 itable_off = sb->zbmap_blocks + sb->ibmap_blocks; 393 394 /*Convert to 1K block offset*/ 395 itable_off = CONVERT_1K_OFF(itable_off, sb->block_size) + 396 FIRST_ZONE(sb->block_size); 389 const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2; 397 390 398 391 const time_t sec = time(NULL); 399 392 400 ino_buf = (struct mfs2_inode *) malloc( MFS_MIN_BLOCKSIZE);393 ino_buf = (struct mfs2_inode *) malloc(sb->block_size); 401 394 402 395 if (!ino_buf) 403 396 return ENOMEM; 404 397 405 memset(ino_buf, 0x00, MFS_MIN_BLOCKSIZE);398 memset(ino_buf, 0x00, sb->block_size); 406 399 407 400 ino_buf[MFS_ROOT_INO].i_mode = S_IFDIR; … … 415 408 ino_buf[MFS_ROOT_INO].i_dzone[0] = sb->first_data_zone; 416 409 417 rc = write_ 1k_block(itable_off, 1, ino_buf);410 rc = write_block(itable_off, 1, ino_buf); 418 411 419 412 free(ino_buf); … … 520 513 sb->s_state = MFS_VALID_FS; 521 514 522 rc = write_ 1k_block(MFS_SUPERBLOCK, 1, sb);515 rc = write_block(MFS_SUPERBLOCK, 1, sb); 523 516 free(sb); 524 517 … … 547 540 sb->s_disk_version = 3; 548 541 549 rc = write_1k_block(MFS_SUPERBLOCK, 1, sb);542 rc = block_write_direct(handle, MFS_SUPERBLOCK << 1, 1 << 1, sb); 550 543 free(sb); 551 544 … … 557 550 uint32_t *ibmap_buf, *zbmap_buf; 558 551 uint8_t *ibmap_buf8, *zbmap_buf8; 559 unsigned int ibmap_nblocks = sb->ibmap_blocks;560 unsigned int zbmap_nblocks = sb->zbmap_blocks;552 const unsigned int ibmap_nblocks = sb->ibmap_blocks; 553 const unsigned int zbmap_nblocks = sb->zbmap_blocks; 561 554 unsigned int i; 562 555 int rc; … … 578 571 579 572 /*Convert to 1K block offsets*/ 580 ibmap_nblocks = CONVERT_1K_OFF(ibmap_nblocks, sb->block_size);581 zbmap_nblocks = CONVERT_1K_OFF(zbmap_nblocks, sb->block_size);582 573 583 574 ibmap_buf8 = (uint8_t *) ibmap_buf; 584 575 zbmap_buf8 = (uint8_t *) zbmap_buf; 585 576 586 int start_block = FIRST_ZONE(sb->block_size);577 int start_block = 2; 587 578 588 579 for (i = 0; i < ibmap_nblocks; ++i) { 589 if ((rc = write_ 1k_block(start_block + i,590 1, (ibmap_buf8 + i * MFS_BLOCKSIZE))) != EOK)580 if ((rc = write_block(start_block + i, 581 1, (ibmap_buf8 + i * sb->block_size))) != EOK) 591 582 return rc; 592 583 } 593 584 594 start_block = FIRST_ZONE(sb->block_size)+ ibmap_nblocks;585 start_block = 2 + ibmap_nblocks; 595 586 596 587 for (i = 0; i < zbmap_nblocks; ++i) { 597 if ((rc = write_ 1k_block(start_block + i,598 1, (zbmap_buf8 + i * MFS_BLOCKSIZE))) != EOK)588 if ((rc = write_block(start_block + i, 589 1, (zbmap_buf8 + i * sb->block_size))) != EOK) 599 590 return rc; 600 591 } … … 614 605 } 615 606 616 static inline int write_1k_block(aoff64_t off, size_t size, const void *data) 617 { 618 return block_write_direct(handle, off * 2, size * 2, data); 607 static inline int write_block(aoff64_t off, size_t size, const void *data) 608 { 609 if (shift == 3) { 610 int rc; 611 aoff64_t tmp_off = off << 1; 612 uint8_t *data_ptr = (uint8_t *) data; 613 614 rc = block_write_direct(handle, tmp_off << 2, size << 2, data_ptr); 615 616 if (rc != EOK) 617 return rc; 618 619 data_ptr += 2048; 620 tmp_off++; 621 622 return block_write_direct(handle, tmp_off << 2, size << 2, data_ptr); 623 } 624 return block_write_direct(handle, off << shift, size << shift, data); 619 625 } 620 626
Note:
See TracChangeset
for help on using the changeset viewer.