aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-31 17:35:02 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-31 17:35:02 +0000
commit65225df2dc656d3c038b22e82b2865c1db333cb2 (patch)
tree3a7d4d8bae522a66881a39ba53a6f0ba83840d60
parent53cfb7e23145dc192c75d207cee50be1581f8dda (diff)
downloadbusybox-w32-65225df2dc656d3c038b22e82b2865c1db333cb2.tar.gz
busybox-w32-65225df2dc656d3c038b22e82b2865c1db333cb2.tar.bz2
busybox-w32-65225df2dc656d3c038b22e82b2865c1db333cb2.zip
Cleanup patch from Vladimir N. Oleynik.
* mkdir: remove 3 lines in source code. * mkfs_minix: save 32 bytes, remove 4 bugs. * mkswap: save 64 bytes, remove 1 bug.
-rw-r--r--coreutils/mkdir.c12
-rw-r--r--mkdir.c12
-rw-r--r--mkfs_minix.c62
-rw-r--r--mkswap.c24
-rw-r--r--util-linux/mkfs_minix.c62
-rw-r--r--util-linux/mkswap.c24
6 files changed, 76 insertions, 120 deletions
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 2345d8831..07b18713a 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -52,8 +52,7 @@ extern int mkdir_main(int argc, char **argv)
52 /* Find the specified modes */ 52 /* Find the specified modes */
53 mode = 0; 53 mode = 0;
54 if (parse_mode(*(++argv), &mode) == FALSE) { 54 if (parse_mode(*(++argv), &mode) == FALSE) {
55 error_msg("Unknown mode: %s\n", *argv); 55 error_msg_and_die("Unknown mode: %s\n", *argv);
56 return EXIT_FAILURE;
57 } 56 }
58 /* Set the umask for this process so it doesn't 57 /* Set the umask for this process so it doesn't
59 * screw up whatever the user just entered. */ 58 * screw up whatever the user just entered. */
@@ -81,22 +80,19 @@ extern int mkdir_main(int argc, char **argv)
81 char buf[BUFSIZ + 1]; 80 char buf[BUFSIZ + 1];
82 81
83 if (strlen(*argv) > BUFSIZ - 1) { 82 if (strlen(*argv) > BUFSIZ - 1) {
84 error_msg(name_too_long); 83 error_msg_and_die(name_too_long);
85 return EXIT_FAILURE;
86 } 84 }
87 strcpy(buf, *argv); 85 strcpy(buf, *argv);
88 status = stat(buf, &statBuf); 86 status = stat(buf, &statBuf);
89 if (parentFlag == FALSE && status != -1 && errno != ENOENT) { 87 if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
90 error_msg("%s: File exists\n", buf); 88 error_msg_and_die("%s: File exists\n", buf);
91 return EXIT_FAILURE;
92 } 89 }
93 if (parentFlag == TRUE) { 90 if (parentFlag == TRUE) {
94 strcat(buf, "/"); 91 strcat(buf, "/");
95 create_path(buf, mode); 92 create_path(buf, mode);
96 } else { 93 } else {
97 if (mkdir(buf, mode) != 0 && parentFlag == FALSE) { 94 if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
98 perror(buf); 95 perror_msg_and_die(buf);
99 return EXIT_FAILURE;
100 } 96 }
101 } 97 }
102 argc--; 98 argc--;
diff --git a/mkdir.c b/mkdir.c
index 2345d8831..07b18713a 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -52,8 +52,7 @@ extern int mkdir_main(int argc, char **argv)
52 /* Find the specified modes */ 52 /* Find the specified modes */
53 mode = 0; 53 mode = 0;
54 if (parse_mode(*(++argv), &mode) == FALSE) { 54 if (parse_mode(*(++argv), &mode) == FALSE) {
55 error_msg("Unknown mode: %s\n", *argv); 55 error_msg_and_die("Unknown mode: %s\n", *argv);
56 return EXIT_FAILURE;
57 } 56 }
58 /* Set the umask for this process so it doesn't 57 /* Set the umask for this process so it doesn't
59 * screw up whatever the user just entered. */ 58 * screw up whatever the user just entered. */
@@ -81,22 +80,19 @@ extern int mkdir_main(int argc, char **argv)
81 char buf[BUFSIZ + 1]; 80 char buf[BUFSIZ + 1];
82 81
83 if (strlen(*argv) > BUFSIZ - 1) { 82 if (strlen(*argv) > BUFSIZ - 1) {
84 error_msg(name_too_long); 83 error_msg_and_die(name_too_long);
85 return EXIT_FAILURE;
86 } 84 }
87 strcpy(buf, *argv); 85 strcpy(buf, *argv);
88 status = stat(buf, &statBuf); 86 status = stat(buf, &statBuf);
89 if (parentFlag == FALSE && status != -1 && errno != ENOENT) { 87 if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
90 error_msg("%s: File exists\n", buf); 88 error_msg_and_die("%s: File exists\n", buf);
91 return EXIT_FAILURE;
92 } 89 }
93 if (parentFlag == TRUE) { 90 if (parentFlag == TRUE) {
94 strcat(buf, "/"); 91 strcat(buf, "/");
95 create_path(buf, mode); 92 create_path(buf, mode);
96 } else { 93 } else {
97 if (mkdir(buf, mode) != 0 && parentFlag == FALSE) { 94 if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
98 perror(buf); 95 perror_msg_and_die(buf);
99 return EXIT_FAILURE;
100 } 96 }
101 } 97 }
102 argc--; 98 argc--;
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/* 258static __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 */
263static volatile void die(char *str)
264{
265 error_msg("%s\n", str);
266 exit(8);
267}
268
269static volatile void show_usage() __attribute__ ((noreturn));
270static 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
297static long valid_offset(int fd, int offset) 285static 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
367static void write_block(int blk, char *buffer) 355static 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
375static int get_free_block(void) 363static 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();
diff --git a/mkswap.c b/mkswap.c
index 5b908daa3..8a3c900f3 100644
--- a/mkswap.c
+++ b/mkswap.c
@@ -173,12 +173,6 @@ static int bit_test_and_clear(unsigned int *addr, unsigned int nr)
173} 173}
174 174
175 175
176static void die(const char *str)
177{
178 error_msg("%s\n", str);
179 exit(EXIT_FAILURE);
180}
181
182static void page_ok(int page) 176static void page_ok(int page)
183{ 177{
184 if (version == 0) 178 if (version == 0)
@@ -191,7 +185,7 @@ static void page_bad(int page)
191 bit_test_and_clear(signature_page, page); 185 bit_test_and_clear(signature_page, page);
192 else { 186 else {
193 if (badpages == MAX_BADPAGES) 187 if (badpages == MAX_BADPAGES)
194 die("too many bad pages"); 188 error_msg_and_die("too many bad pages\n");
195 p->badpages[badpages] = page; 189 p->badpages[badpages] = page;
196 } 190 }
197 badpages++; 191 badpages++;
@@ -212,7 +206,7 @@ static void check_blocks(void)
212 } 206 }
213 if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != 207 if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) !=
214 current_page * pagesize) 208 current_page * pagesize)
215 die("seek failed in check_blocks"); 209 error_msg_and_die("seek failed in check_blocks\n");
216 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { 210 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) {
217 page_bad(current_page++); 211 page_bad(current_page++);
218 continue; 212 continue;
@@ -369,7 +363,7 @@ int mkswap_main(int argc, char **argv)
369 if (!S_ISBLK(statbuf.st_mode)) 363 if (!S_ISBLK(statbuf.st_mode))
370 check = 0; 364 check = 0;
371 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 365 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
372 die("Will not try to make swapdevice on '%s'"); 366 error_msg_and_die("Will not try to make swapdevice on '%s'\n", device_name);
373 367
374#ifdef __sparc__ 368#ifdef __sparc__
375 if (!force && version == 0) { 369 if (!force && version == 0) {
@@ -378,7 +372,7 @@ int mkswap_main(int argc, char **argv)
378 unsigned short *q, sum; 372 unsigned short *q, sum;
379 373
380 if (read(DEV, buffer, 512) != 512) 374 if (read(DEV, buffer, 512) != 512)
381 die("fatal: first page unreadable"); 375 error_msg_and_die("fatal: first page unreadable\n");
382 if (buffer[508] == 0xDA && buffer[509] == 0xBE) { 376 if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
383 q = (unsigned short *) (buffer + 510); 377 q = (unsigned short *) (buffer + 510);
384 for (sum = 0; q >= (unsigned short *) buffer;) 378 for (sum = 0; q >= (unsigned short *) buffer;)
@@ -397,7 +391,7 @@ int mkswap_main(int argc, char **argv)
397 if (version == 0 || check) 391 if (version == 0 || check)
398 check_blocks(); 392 check_blocks();
399 if (version == 0 && !bit_test_and_clear(signature_page, 0)) 393 if (version == 0 && !bit_test_and_clear(signature_page, 0))
400 die("fatal: first page unreadable"); 394 error_msg_and_die("fatal: first page unreadable\n");
401 if (version == 1) { 395 if (version == 1) {
402 p->version = version; 396 p->version = version;
403 p->last_page = PAGES - 1; 397 p->last_page = PAGES - 1;
@@ -406,23 +400,23 @@ int mkswap_main(int argc, char **argv)
406 400
407 goodpages = PAGES - badpages - 1; 401 goodpages = PAGES - badpages - 1;
408 if (goodpages <= 0) 402 if (goodpages <= 0)
409 die("Unable to set up swap-space: unreadable"); 403 error_msg_and_die("Unable to set up swap-space: unreadable\n");
410 printf("Setting up swapspace version %d, size = %ld bytes\n", 404 printf("Setting up swapspace version %d, size = %ld bytes\n",
411 version, (long) (goodpages * pagesize)); 405 version, (long) (goodpages * pagesize));
412 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); 406 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");
413 407
414 offset = ((version == 0) ? 0 : 1024); 408 offset = ((version == 0) ? 0 : 1024);
415 if (lseek(DEV, offset, SEEK_SET) != offset) 409 if (lseek(DEV, offset, SEEK_SET) != offset)
416 die("unable to rewind swap-device"); 410 error_msg_and_die("unable to rewind swap-device\n");
417 if (write(DEV, (char *) signature_page + offset, pagesize - offset) 411 if (write(DEV, (char *) signature_page + offset, pagesize - offset)
418 != pagesize - offset) 412 != pagesize - offset)
419 die("unable to write signature page"); 413 error_msg_and_die("unable to write signature page\n");
420 414
421 /* 415 /*
422 * A subsequent swapon() will fail if the signature 416 * A subsequent swapon() will fail if the signature
423 * is not actually on disk. (This is a kernel bug.) 417 * is not actually on disk. (This is a kernel bug.)
424 */ 418 */
425 if (fsync(DEV)) 419 if (fsync(DEV))
426 die("fsync failed"); 420 error_msg_and_die("fsync failed\n");
427 return EXIT_SUCCESS; 421 return EXIT_SUCCESS;
428} 422}
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index e1ede6caa..21965d3b1 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/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/* 258static __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 */
263static volatile void die(char *str)
264{
265 error_msg("%s\n", str);
266 exit(8);
267}
268
269static volatile void show_usage() __attribute__ ((noreturn));
270static 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
297static long valid_offset(int fd, int offset) 285static 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
367static void write_block(int blk, char *buffer) 355static 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
375static int get_free_block(void) 363static 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();
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 5b908daa3..8a3c900f3 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -173,12 +173,6 @@ static int bit_test_and_clear(unsigned int *addr, unsigned int nr)
173} 173}
174 174
175 175
176static void die(const char *str)
177{
178 error_msg("%s\n", str);
179 exit(EXIT_FAILURE);
180}
181
182static void page_ok(int page) 176static void page_ok(int page)
183{ 177{
184 if (version == 0) 178 if (version == 0)
@@ -191,7 +185,7 @@ static void page_bad(int page)
191 bit_test_and_clear(signature_page, page); 185 bit_test_and_clear(signature_page, page);
192 else { 186 else {
193 if (badpages == MAX_BADPAGES) 187 if (badpages == MAX_BADPAGES)
194 die("too many bad pages"); 188 error_msg_and_die("too many bad pages\n");
195 p->badpages[badpages] = page; 189 p->badpages[badpages] = page;
196 } 190 }
197 badpages++; 191 badpages++;
@@ -212,7 +206,7 @@ static void check_blocks(void)
212 } 206 }
213 if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != 207 if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) !=
214 current_page * pagesize) 208 current_page * pagesize)
215 die("seek failed in check_blocks"); 209 error_msg_and_die("seek failed in check_blocks\n");
216 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { 210 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) {
217 page_bad(current_page++); 211 page_bad(current_page++);
218 continue; 212 continue;
@@ -369,7 +363,7 @@ int mkswap_main(int argc, char **argv)
369 if (!S_ISBLK(statbuf.st_mode)) 363 if (!S_ISBLK(statbuf.st_mode))
370 check = 0; 364 check = 0;
371 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 365 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
372 die("Will not try to make swapdevice on '%s'"); 366 error_msg_and_die("Will not try to make swapdevice on '%s'\n", device_name);
373 367
374#ifdef __sparc__ 368#ifdef __sparc__
375 if (!force && version == 0) { 369 if (!force && version == 0) {
@@ -378,7 +372,7 @@ int mkswap_main(int argc, char **argv)
378 unsigned short *q, sum; 372 unsigned short *q, sum;
379 373
380 if (read(DEV, buffer, 512) != 512) 374 if (read(DEV, buffer, 512) != 512)
381 die("fatal: first page unreadable"); 375 error_msg_and_die("fatal: first page unreadable\n");
382 if (buffer[508] == 0xDA && buffer[509] == 0xBE) { 376 if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
383 q = (unsigned short *) (buffer + 510); 377 q = (unsigned short *) (buffer + 510);
384 for (sum = 0; q >= (unsigned short *) buffer;) 378 for (sum = 0; q >= (unsigned short *) buffer;)
@@ -397,7 +391,7 @@ int mkswap_main(int argc, char **argv)
397 if (version == 0 || check) 391 if (version == 0 || check)
398 check_blocks(); 392 check_blocks();
399 if (version == 0 && !bit_test_and_clear(signature_page, 0)) 393 if (version == 0 && !bit_test_and_clear(signature_page, 0))
400 die("fatal: first page unreadable"); 394 error_msg_and_die("fatal: first page unreadable\n");
401 if (version == 1) { 395 if (version == 1) {
402 p->version = version; 396 p->version = version;
403 p->last_page = PAGES - 1; 397 p->last_page = PAGES - 1;
@@ -406,23 +400,23 @@ int mkswap_main(int argc, char **argv)
406 400
407 goodpages = PAGES - badpages - 1; 401 goodpages = PAGES - badpages - 1;
408 if (goodpages <= 0) 402 if (goodpages <= 0)
409 die("Unable to set up swap-space: unreadable"); 403 error_msg_and_die("Unable to set up swap-space: unreadable\n");
410 printf("Setting up swapspace version %d, size = %ld bytes\n", 404 printf("Setting up swapspace version %d, size = %ld bytes\n",
411 version, (long) (goodpages * pagesize)); 405 version, (long) (goodpages * pagesize));
412 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); 406 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");
413 407
414 offset = ((version == 0) ? 0 : 1024); 408 offset = ((version == 0) ? 0 : 1024);
415 if (lseek(DEV, offset, SEEK_SET) != offset) 409 if (lseek(DEV, offset, SEEK_SET) != offset)
416 die("unable to rewind swap-device"); 410 error_msg_and_die("unable to rewind swap-device\n");
417 if (write(DEV, (char *) signature_page + offset, pagesize - offset) 411 if (write(DEV, (char *) signature_page + offset, pagesize - offset)
418 != pagesize - offset) 412 != pagesize - offset)
419 die("unable to write signature page"); 413 error_msg_and_die("unable to write signature page\n");
420 414
421 /* 415 /*
422 * A subsequent swapon() will fail if the signature 416 * A subsequent swapon() will fail if the signature
423 * is not actually on disk. (This is a kernel bug.) 417 * is not actually on disk. (This is a kernel bug.)
424 */ 418 */
425 if (fsync(DEV)) 419 if (fsync(DEV))
426 die("fsync failed"); 420 error_msg_and_die("fsync failed\n");
427 return EXIT_SUCCESS; 421 return EXIT_SUCCESS;
428} 422}