Changeset 0b07acd in mainline
- Timestamp:
- 2011-03-08T21:21:38Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6cda025
- Parents:
- 4727a97a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkminix/mkminix.c
r4727a97a r0b07acd 88 88 static void help_cmd_mkminix(help_level_t level); 89 89 static int num_of_set_bits(uint32_t n); 90 static voidinit_superblock(struct mfs_sb_info *sb);91 static voidwrite_superblock(struct mfs_sb_info *sbi);92 static voidwrite_superblock3(struct mfs_sb_info *sbi);93 static voidinit_bitmaps(struct mfs_sb_info *sb);94 static voidinit_inode_table(struct mfs_sb_info *sb);95 static voidmake_root_ino(struct mfs_sb_info *sb);96 static voidmake_root_ino3(struct mfs_sb_info *sb);90 static int init_superblock(struct mfs_sb_info *sb); 91 static int write_superblock(struct mfs_sb_info *sbi); 92 static int write_superblock3(struct mfs_sb_info *sbi); 93 static int init_bitmaps(struct mfs_sb_info *sb); 94 static int init_inode_table(struct mfs_sb_info *sb); 95 static int make_root_ino(struct mfs_sb_info *sb); 96 static int make_root_ino3(struct mfs_sb_info *sb); 97 97 static void mark_bmap(uint32_t *bmap, int idx, int v); 98 static voidinsert_dentries(struct mfs_sb_info *sb);98 static int insert_dentries(struct mfs_sb_info *sb); 99 99 100 100 static struct option const long_options[] = { … … 233 233 234 234 /*Initialize superblock*/ 235 init_superblock(&sb); 235 if (init_superblock(&sb) != EOK) { 236 printf(NAME ": Error. Superblock initialization failed\n"); 237 return 2; 238 } 236 239 237 240 /*Initialize bitmaps*/ 238 init_bitmaps(&sb); 241 if (init_bitmaps(&sb) != EOK) { 242 printf(NAME ": Error. Bitmaps initialization failed\n"); 243 return 2; 244 } 239 245 240 246 /*Init inode table*/ 241 init_inode_table(&sb); 247 if (init_inode_table(&sb) != EOK) { 248 printf(NAME ": Error. Inode table initialization failed\n"); 249 return 2; 250 } 242 251 243 252 /*Make the root inode*/ 244 253 if (sb.fs_version == 3) 245 make_root_ino3(&sb);254 rc = make_root_ino3(&sb); 246 255 else 247 make_root_ino(&sb); 256 rc = make_root_ino(&sb); 257 258 if (rc != EOK) { 259 printf(NAME ": Error. Root inode initialization failed\n"); 260 return 2; 261 } 248 262 249 263 /*Insert directory entries . and ..*/ 250 insert_dentries(&sb); 264 if (insert_dentries(&sb) != EOK) { 265 printf(NAME ": Error. Root directory initialization failed\n"); 266 return 2; 267 } 251 268 252 269 return 0; 253 270 } 254 271 255 static voidinsert_dentries(struct mfs_sb_info *sb)272 static int insert_dentries(struct mfs_sb_info *sb) 256 273 { 257 274 void *root_block; 275 int rc; 258 276 const long root_dblock = sb->first_data_zone * (sb->block_size / MFS_MIN_BLOCKSIZE); 259 277 260 278 root_block = (void *) malloc(MFS_MIN_BLOCKSIZE); 279 280 if (!root_block) 281 return ENOMEM; 261 282 262 283 if (sb->fs_version != 3) { … … 284 305 } 285 306 286 block_write_direct(sb->handle, root_dblock, 1, root_block);307 rc = block_write_direct(sb->handle, root_dblock, 1, root_block); 287 308 288 309 free(root_block); 289 } 290 291 static void init_inode_table(struct mfs_sb_info *sb) 310 return rc; 311 } 312 313 static int init_inode_table(struct mfs_sb_info *sb) 292 314 { 293 315 unsigned int i; 294 316 uint8_t *itable_buf; 317 int rc; 295 318 long itable_pos = 2 + sb->zbmap_blocks + sb->ibmap_blocks; 296 319 297 320 itable_buf = malloc(sb->block_size); 321 322 if (!itable_buf) 323 return ENOMEM; 324 298 325 memset(itable_buf, 0x00, sb->block_size); 299 326 300 327 const int chunks = sb->block_size / MFS_BLOCKSIZE; 301 328 302 for (i = 0; i < sb->itable_size; ++i, itable_pos += chunks) 303 block_write_direct(sb->handle, itable_pos, chunks, itable_buf); 329 for (i = 0; i < sb->itable_size; ++i, itable_pos += chunks) { 330 rc = block_write_direct(sb->handle, itable_pos, chunks, itable_buf); 331 332 if (rc != EOK) 333 break; 334 } 304 335 305 336 free(itable_buf); 306 } 307 308 static void make_root_ino(struct mfs_sb_info *sb) 337 return rc; 338 } 339 340 static int make_root_ino(struct mfs_sb_info *sb) 309 341 { 310 342 struct mfs_inode *ino_buf; 311 343 const long itable_pos = 2 + sb->zbmap_blocks + sb->ibmap_blocks; 344 int rc; 312 345 313 346 const time_t sec = time(NULL); 314 347 315 348 ino_buf = (struct mfs_inode *) malloc(MFS_BLOCKSIZE); 349 350 if (!ino_buf) 351 return ENOMEM; 352 316 353 memset(ino_buf, 0x00, MFS_BLOCKSIZE); 317 354 … … 324 361 ino_buf[MFS_ROOT_INO].i_dzone[0] = sb->first_data_zone; 325 362 326 block_write_direct(sb->handle, itable_pos, 1, ino_buf);363 rc = block_write_direct(sb->handle, itable_pos, 1, ino_buf); 327 364 328 365 free(ino_buf); 329 } 330 331 static void make_root_ino3(struct mfs_sb_info *sb) 366 return rc; 367 } 368 369 static int make_root_ino3(struct mfs_sb_info *sb) 332 370 { 333 371 struct mfs2_inode *ino_buf; 334 372 const size_t bufsize = MFS_MIN_BLOCKSIZE; 335 373 const long itable_pos = 2 + sb->zbmap_blocks + sb->ibmap_blocks; 374 int rc; 336 375 337 376 const time_t sec = time(NULL); 338 377 339 378 ino_buf = (struct mfs2_inode *) malloc(bufsize); 379 380 if (!ino_buf) 381 return ENOMEM; 382 340 383 memset(ino_buf, 0x00, bufsize); 341 384 … … 350 393 ino_buf[MFS_ROOT_INO].i_dzone[0] = sb->first_data_zone; 351 394 352 block_write_direct(sb->handle, itable_pos * (sb->block_size / MFS_MIN_BLOCKSIZE), 1, ino_buf);395 rc = block_write_direct(sb->handle, itable_pos * (sb->block_size / MFS_MIN_BLOCKSIZE), 1, ino_buf); 353 396 354 397 free(ino_buf); 355 } 356 357 static void init_superblock(struct mfs_sb_info *sb) 398 return rc; 399 } 400 401 static int init_superblock(struct mfs_sb_info *sb) 358 402 { 359 403 aoff64_t inodes; 404 int rc; 360 405 361 406 if (sb->longnames) … … 409 454 sb->log2_zone_size = 0; 410 455 456 /*Check for errors*/ 457 if (sb->first_data_zone >= sb->n_zones) { 458 printf(NAME ": Error! Insufficient disk space"); 459 return ENOMEM; 460 } 461 411 462 /*Superblock is now ready to be written on disk*/ 412 463 printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes); … … 419 470 420 471 if (sb->fs_version == 3) 421 write_superblock3(sb);472 rc = write_superblock3(sb); 422 473 else 423 write_superblock(sb); 424 } 425 426 static void write_superblock(struct mfs_sb_info *sbi) 474 rc = write_superblock(sb); 475 476 return rc; 477 } 478 479 static int write_superblock(struct mfs_sb_info *sbi) 427 480 { 428 481 struct mfs_superblock *sb; 482 int rc; 429 483 430 484 sb = (struct mfs_superblock *) malloc(MFS_SUPERBLOCK_SIZE);; 485 486 if (!sb) 487 return ENOMEM; 431 488 432 489 sb->s_ninodes = (uint16_t) sbi->n_inodes; … … 441 498 sb->s_state = MFS_VALID_FS; 442 499 443 block_write_direct(sbi->handle, MFS_SUPERBLOCK, 1, sb);500 rc = block_write_direct(sbi->handle, MFS_SUPERBLOCK, 1, sb); 444 501 free(sb); 445 } 446 447 static void write_superblock3(struct mfs_sb_info *sbi) 502 503 return rc; 504 } 505 506 static int write_superblock3(struct mfs_sb_info *sbi) 448 507 { 449 508 struct mfs3_superblock *sb; 509 int rc; 450 510 451 511 sb = (struct mfs3_superblock *) malloc(MFS_SUPERBLOCK_SIZE); 512 513 if (!sb) 514 return ENOMEM; 452 515 453 516 sb->s_ninodes = (uint32_t) sbi->n_inodes; … … 462 525 sb->s_disk_version = 3; 463 526 464 block_write_direct(sbi->handle, MFS_SUPERBLOCK, 1, sb);527 rc = block_write_direct(sbi->handle, MFS_SUPERBLOCK, 1, sb); 465 528 free(sb); 466 } 467 468 static void init_bitmaps(struct mfs_sb_info *sb) 529 530 return rc; 531 } 532 533 static int init_bitmaps(struct mfs_sb_info *sb) 469 534 { 470 535 uint32_t *ibmap_buf, *zbmap_buf; … … 472 537 int zbmap_nblocks = 1 + (sb->n_zones / 8) / sb->block_size; 473 538 unsigned int i; 539 int rc; 474 540 475 541 ibmap_buf = (uint32_t *) malloc(ibmap_nblocks * sb->block_size); 476 542 zbmap_buf = (uint32_t *) malloc(zbmap_nblocks * sb->block_size); 477 543 544 if (!ibmap_buf || !zbmap_buf) 545 return ENOMEM; 546 478 547 memset(ibmap_buf, 0xFF, ibmap_nblocks * sb->block_size); 479 548 memset(zbmap_buf, 0xFF, zbmap_nblocks * sb->block_size); … … 488 557 zbmap_nblocks *= sb->block_size / MFS_BLOCKSIZE; 489 558 490 block_write_direct(sb->handle, 2, ibmap_nblocks, ibmap_buf); 491 block_write_direct(sb->handle, 2 + ibmap_nblocks, zbmap_nblocks, zbmap_buf); 492 493 free(ibmap_buf); 494 free(zbmap_buf); 559 if ((rc = block_write_direct(sb->handle, 2, ibmap_nblocks, ibmap_buf)) != EOK) 560 return rc; 561 if ((rc = block_write_direct(sb->handle, 2 + ibmap_nblocks, zbmap_nblocks, zbmap_buf)) != EOK) 562 return rc; 563 564 return rc; 495 565 } 496 566
Note:
See TracChangeset
for help on using the changeset viewer.