diff options
Diffstat (limited to 'mkfs_minix.c')
-rw-r--r-- | mkfs_minix.c | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/mkfs_minix.c b/mkfs_minix.c index e1ede6caa..21965d3b1 100644 --- a/mkfs_minix.c +++ b/mkfs_minix.c | |||
@@ -255,19 +255,7 @@ static inline int bit(char * a,unsigned int i) | |||
255 | #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) | 255 | #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) |
256 | #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) | 256 | #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) |
257 | 257 | ||
258 | /* | 258 | static __attribute__ ((noreturn)) void show_usage() |
259 | * Volatile to let gcc know that this doesn't return. When trying | ||
260 | * to compile this under minix, volatile gives a warning, as | ||
261 | * exit() isn't defined as volatile under minix. | ||
262 | */ | ||
263 | static volatile void die(char *str) | ||
264 | { | ||
265 | error_msg("%s\n", str); | ||
266 | exit(8); | ||
267 | } | ||
268 | |||
269 | static volatile void show_usage() __attribute__ ((noreturn)); | ||
270 | static volatile void show_usage() | ||
271 | { | 259 | { |
272 | usage(mkfs_minix_usage); | 260 | usage(mkfs_minix_usage); |
273 | } | 261 | } |
@@ -291,7 +279,7 @@ static void check_mount(void) | |||
291 | if (!mnt) | 279 | if (!mnt) |
292 | return; | 280 | return; |
293 | 281 | ||
294 | die("%s is mounted; will not make a filesystem here!"); | 282 | error_msg_and_die("%s is mounted; will not make a filesystem here!\n", device_name); |
295 | } | 283 | } |
296 | 284 | ||
297 | static long valid_offset(int fd, int offset) | 285 | static long valid_offset(int fd, int offset) |
@@ -348,28 +336,28 @@ static void write_tables(void) | |||
348 | Super.s_state &= ~MINIX_ERROR_FS; | 336 | Super.s_state &= ~MINIX_ERROR_FS; |
349 | 337 | ||
350 | if (lseek(DEV, 0, SEEK_SET)) | 338 | if (lseek(DEV, 0, SEEK_SET)) |
351 | die("seek to boot block failed in write_tables"); | 339 | error_msg_and_die("seek to boot block failed in write_tables\n"); |
352 | if (512 != write(DEV, boot_block_buffer, 512)) | 340 | if (512 != write(DEV, boot_block_buffer, 512)) |
353 | die("unable to clear boot sector"); | 341 | error_msg_and_die("unable to clear boot sector\n"); |
354 | if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) | 342 | if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) |
355 | die("seek failed in write_tables"); | 343 | error_msg_and_die("seek failed in write_tables\n"); |
356 | if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) | 344 | if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) |
357 | die("unable to write super-block"); | 345 | error_msg_and_die("unable to write super-block\n"); |
358 | if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE)) | 346 | if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE)) |
359 | die("unable to write inode map"); | 347 | error_msg_and_die("unable to write inode map\n"); |
360 | if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE)) | 348 | if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE)) |
361 | die("unable to write zone map"); | 349 | error_msg_and_die("unable to write zone map\n"); |
362 | if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE)) | 350 | if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE)) |
363 | die("unable to write inodes"); | 351 | error_msg_and_die("unable to write inodes\n"); |
364 | 352 | ||
365 | } | 353 | } |
366 | 354 | ||
367 | static void write_block(int blk, char *buffer) | 355 | static void write_block(int blk, char *buffer) |
368 | { | 356 | { |
369 | if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET)) | 357 | if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET)) |
370 | die("seek failed in write_block"); | 358 | error_msg_and_die("seek failed in write_block\n"); |
371 | if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) | 359 | if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) |
372 | die("write failed in write_block"); | 360 | error_msg_and_die("write failed in write_block\n"); |
373 | } | 361 | } |
374 | 362 | ||
375 | static int get_free_block(void) | 363 | static int get_free_block(void) |
@@ -377,7 +365,7 @@ static int get_free_block(void) | |||
377 | int blk; | 365 | int blk; |
378 | 366 | ||
379 | if (used_good_blocks + 1 >= MAX_GOOD_BLOCKS) | 367 | if (used_good_blocks + 1 >= MAX_GOOD_BLOCKS) |
380 | die("too many bad blocks"); | 368 | error_msg_and_die("too many bad blocks\n"); |
381 | if (used_good_blocks) | 369 | if (used_good_blocks) |
382 | blk = good_blocks_table[used_good_blocks - 1] + 1; | 370 | blk = good_blocks_table[used_good_blocks - 1] + 1; |
383 | else | 371 | else |
@@ -385,7 +373,7 @@ static int get_free_block(void) | |||
385 | while (blk < ZONES && zone_in_use(blk)) | 373 | while (blk < ZONES && zone_in_use(blk)) |
386 | blk++; | 374 | blk++; |
387 | if (blk >= ZONES) | 375 | if (blk >= ZONES) |
388 | die("not enough good blocks"); | 376 | error_msg_and_die("not enough good blocks\n"); |
389 | good_blocks_table[used_good_blocks] = blk; | 377 | good_blocks_table[used_good_blocks] = blk; |
390 | used_good_blocks++; | 378 | used_good_blocks++; |
391 | return blk; | 379 | return blk; |
@@ -451,7 +439,7 @@ static void make_bad_inode(void) | |||
451 | goto end_bad; | 439 | goto end_bad; |
452 | } | 440 | } |
453 | } | 441 | } |
454 | die("too many bad blocks"); | 442 | error_msg_and_die("too many bad blocks\n"); |
455 | end_bad: | 443 | end_bad: |
456 | if (ind) | 444 | if (ind) |
457 | write_block(ind, (char *) ind_block); | 445 | write_block(ind, (char *) ind_block); |
@@ -501,7 +489,7 @@ static void make_bad_inode2(void) | |||
501 | } | 489 | } |
502 | } | 490 | } |
503 | /* Could make triple indirect block here */ | 491 | /* Could make triple indirect block here */ |
504 | die("too many bad blocks"); | 492 | error_msg_and_die("too many bad blocks\n"); |
505 | end_bad: | 493 | end_bad: |
506 | if (ind) | 494 | if (ind) |
507 | write_block(ind, (char *) ind_block); | 495 | write_block(ind, (char *) ind_block); |
@@ -602,7 +590,7 @@ static void setup_tables(void) | |||
602 | * /sbin/mkfs.minix -i 200 test.fs | 590 | * /sbin/mkfs.minix -i 200 test.fs |
603 | * */ | 591 | * */ |
604 | if (i >= 999) { | 592 | if (i >= 999) { |
605 | die("unable to allocate buffers for maps"); | 593 | error_msg_and_die("unable to allocate buffers for maps\n"); |
606 | } | 594 | } |
607 | FIRSTZONE = NORM_FIRSTZONE; | 595 | FIRSTZONE = NORM_FIRSTZONE; |
608 | inode_map = xmalloc(IMAPS * BLOCK_SIZE); | 596 | inode_map = xmalloc(IMAPS * BLOCK_SIZE); |
@@ -633,7 +621,7 @@ long do_check(char *buffer, int try, unsigned int current_block) | |||
633 | /* Seek to the correct loc. */ | 621 | /* Seek to the correct loc. */ |
634 | if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != | 622 | if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != |
635 | current_block * BLOCK_SIZE) { | 623 | current_block * BLOCK_SIZE) { |
636 | die("seek failed during testing of blocks"); | 624 | error_msg_and_die("seek failed during testing of blocks\n"); |
637 | } | 625 | } |
638 | 626 | ||
639 | 627 | ||
@@ -673,7 +661,7 @@ static void check_blocks(void) | |||
673 | while (currently_testing < ZONES) { | 661 | while (currently_testing < ZONES) { |
674 | if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) != | 662 | if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) != |
675 | currently_testing * BLOCK_SIZE) | 663 | currently_testing * BLOCK_SIZE) |
676 | die("seek failed in check_blocks"); | 664 | error_msg_and_die("seek failed in check_blocks\n"); |
677 | try = TEST_BUFFER_BLOCKS; | 665 | try = TEST_BUFFER_BLOCKS; |
678 | if (currently_testing + try > ZONES) | 666 | if (currently_testing + try > ZONES) |
679 | try = ZONES - currently_testing; | 667 | try = ZONES - currently_testing; |
@@ -682,7 +670,7 @@ static void check_blocks(void) | |||
682 | if (got == try) | 670 | if (got == try) |
683 | continue; | 671 | continue; |
684 | if (currently_testing < FIRSTZONE) | 672 | if (currently_testing < FIRSTZONE) |
685 | die("bad blocks before data-area: cannot make fs"); | 673 | error_msg_and_die("bad blocks before data-area: cannot make fs\n"); |
686 | mark_zone(currently_testing); | 674 | mark_zone(currently_testing); |
687 | badblocks++; | 675 | badblocks++; |
688 | currently_testing++; | 676 | currently_testing++; |
@@ -702,7 +690,7 @@ char *filename; | |||
702 | 690 | ||
703 | listfile = fopen(filename, "r"); | 691 | listfile = fopen(filename, "r"); |
704 | if (listfile == (FILE *) NULL) { | 692 | if (listfile == (FILE *) NULL) { |
705 | die("can't open file of bad blocks"); | 693 | error_msg_and_die("can't open file of bad blocks\n"); |
706 | } | 694 | } |
707 | while (!feof(listfile)) { | 695 | while (!feof(listfile)) { |
708 | fscanf(listfile, "%ld\n", &blockno); | 696 | fscanf(listfile, "%ld\n", &blockno); |
@@ -724,10 +712,10 @@ extern int mkfs_minix_main(int argc, char **argv) | |||
724 | int stopIt=FALSE; | 712 | int stopIt=FALSE; |
725 | 713 | ||
726 | if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) | 714 | if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) |
727 | die("bad inode size"); | 715 | error_msg_and_die("bad inode size\n"); |
728 | #ifdef BB_FEATURE_MINIX2 | 716 | #ifdef BB_FEATURE_MINIX2 |
729 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) | 717 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) |
730 | die("bad inode size"); | 718 | error_msg_and_die("bad inode size\n"); |
731 | #endif | 719 | #endif |
732 | 720 | ||
733 | /* Parse options */ | 721 | /* Parse options */ |
@@ -844,13 +832,13 @@ goodbye: | |||
844 | strcpy(tmp + 2, ".badblocks"); | 832 | strcpy(tmp + 2, ".badblocks"); |
845 | DEV = open(device_name, O_RDWR); | 833 | DEV = open(device_name, O_RDWR); |
846 | if (DEV < 0) | 834 | if (DEV < 0) |
847 | die("unable to open %s"); | 835 | error_msg_and_die("unable to open %s\n", device_name); |
848 | if (fstat(DEV, &statbuf) < 0) | 836 | if (fstat(DEV, &statbuf) < 0) |
849 | die("unable to stat %s"); | 837 | error_msg_and_die("unable to stat %s\n", device_name); |
850 | if (!S_ISBLK(statbuf.st_mode)) | 838 | if (!S_ISBLK(statbuf.st_mode)) |
851 | check = 0; | 839 | check = 0; |
852 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 840 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) |
853 | die("will not try to make filesystem on '%s'"); | 841 | error_msg_and_die("will not try to make filesystem on '%s'\n", device_name); |
854 | setup_tables(); | 842 | setup_tables(); |
855 | if (check) | 843 | if (check) |
856 | check_blocks(); | 844 | check_blocks(); |