This patch is the first in the series to add support for v3 and massive cleanups. From: Davidlohr Bueso <dave@xxxxxxx> Date: Thu, 7 Apr 2011 15:41:30 -0300 This patch gets rid of the die() function and replaces it with errx(3). The exit code continues to be 8. Signed-off-by: Davidlohr Bueso <dave@xxxxxxx> --- disk-utils/mkfs.minix.c | 70 +++++++++++++++++++++-------------------------- 1 files changed, 31 insertions(+), 39 deletions(-) diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index 807a571..53b5900 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -141,14 +141,6 @@ static unsigned long req_nr_inodes = 0; #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) -static void -die(char *str) { - fprintf(stderr, "%s: ", program_name); - fprintf(stderr, str, device_name); - fprintf(stderr, "\n"); - exit(8); -} - static void __attribute__((__noreturn__)) usage(void) { errx(16, _("Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]"), @@ -174,7 +166,7 @@ check_mount(void) { if (!mnt) return; - die(_("%s is mounted; will not make a filesystem here!")); + errx(8, _("%s is mounted; will not make a filesystem here!"), device_name); } static void @@ -184,28 +176,28 @@ write_tables(void) { Super.s_state &= ~MINIX_ERROR_FS; if (lseek(DEV, 0, SEEK_SET)) - die(_("seek to boot block failed in write_tables")); + errx(8, _("seek to boot block failed in write_tables"), device_name); if (512 != write(DEV, boot_block_buffer, 512)) - die(_("unable to clear boot sector")); + errx(8, _("unable to clear boot sector"), device_name); if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) - die(_("seek failed in write_tables")); + errx(8, _("seek failed in write_tables"), device_name); if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) - die(_("unable to write super-block")); + errx(8, _("unable to write super-block"), device_name); if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE)) - die(_("unable to write inode map")); + errx(8, _("unable to write inode map"), device_name); if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE)) - die(_("unable to write zone map")); + errx(8, _("unable to write zone map"), device_name); if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE)) - die(_("unable to write inodes")); + errx(8, _("unable to write inodes"), device_name); } static void write_block(int blk, char * buffer) { if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET)) - die(_("seek failed in write_block")); + errx(8, _("seek failed in write_block"), device_name); if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) - die(_("write failed in write_block")); + errx(8, _("write failed in write_block"), device_name); } static int @@ -213,7 +205,7 @@ get_free_block(void) { int blk; if (used_good_blocks+1 >= MAX_GOOD_BLOCKS) - die(_("too many bad blocks")); + errx(8, _("too many bad blocks"), device_name); if (used_good_blocks) blk = good_blocks_table[used_good_blocks-1]+1; else @@ -221,7 +213,7 @@ get_free_block(void) { while (blk < ZONES && zone_in_use(blk)) blk++; if (blk >= ZONES) - die(_("not enough good blocks")); + errx(8, _("not enough good blocks"), device_name); good_blocks_table[used_good_blocks] = blk; used_good_blocks++; return blk; @@ -287,7 +279,7 @@ make_bad_inode(void) { goto end_bad; } } - die(_("too many bad blocks")); + errx(8, _("too many bad blocks"), device_name); end_bad: if (ind) write_block(ind, (char *) ind_block); @@ -336,7 +328,7 @@ make_bad_inode2 (void) { } } /* Could make triple indirect block here */ - die (_("too many bad blocks")); + errx(8, _("too many bad blocks"), device_name); end_bad: if (ind) write_block (ind, (char *) ind_block); @@ -395,7 +387,7 @@ setup_tables(void) { super_block_buffer = calloc(1, BLOCK_SIZE); if (!super_block_buffer) - die(_("unable to alloc buffer for superblock")); + errx(8, _("unable to alloc buffer for superblock"), device_name); memset(boot_block_buffer,0,512); Super.s_magic = magic; @@ -436,7 +428,7 @@ setup_tables(void) { inode_map = malloc(IMAPS * BLOCK_SIZE); zone_map = malloc(ZMAPS * BLOCK_SIZE); if (!inode_map || !zone_map) - die(_("unable to allocate buffers for maps")); + errx(8, _("unable to allocate buffers for maps"), device_name); memset(inode_map,0xff,IMAPS * BLOCK_SIZE); memset(zone_map,0xff,ZMAPS * BLOCK_SIZE); for (i = FIRSTZONE ; i<ZONES ; i++) @@ -445,7 +437,7 @@ setup_tables(void) { unmark_inode(i); inode_buffer = malloc(INODE_BUFFER_SIZE); if (!inode_buffer) - die(_("unable to allocate buffer for inodes")); + errx(8, _("unable to allocate buffer for inodes"), device_name); memset(inode_buffer,0,INODE_BUFFER_SIZE); printf(_("%ld inodes\n"),INODES); printf(_("%ld blocks\n"),ZONES); @@ -465,7 +457,7 @@ do_check(char * buffer, int try, unsigned int current_block) { /* Seek to the correct loc. */ if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != current_block * BLOCK_SIZE ) { - die(_("seek failed during testing of blocks")); + errx(8, _("seek failed during testing of blocks"), device_name); } @@ -504,7 +496,7 @@ check_blocks(void) { while (currently_testing < ZONES) { if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) != currently_testing*BLOCK_SIZE) - die(_("seek failed in check_blocks")); + errx(8, _("seek failed in check_blocks"), device_name); try = TEST_BUFFER_BLOCKS; if (currently_testing + try > ZONES) try = ZONES-currently_testing; @@ -513,7 +505,7 @@ check_blocks(void) { if (got == try) continue; if (currently_testing < FIRSTZONE) - die(_("bad blocks before data-area: cannot make fs")); + errx(8, _("bad blocks before data-area: cannot make fs"), device_name); mark_zone(currently_testing); badblocks++; currently_testing++; @@ -531,12 +523,12 @@ get_list_blocks(char *filename) { listfile = fopen(filename,"r"); if (listfile == NULL) - die(_("can't open file of bad blocks")); + errx(8, _("can't open file of bad blocks"), device_name); while (!feof(listfile)) { if (fscanf(listfile,"%ld\n", &blockno) != 1) { printf(_("badblock number input error on line %d\n"), badblocks + 1); - die(_("cannot read badblocks file")); + errx(8, _("cannot read badblocks file"), device_name); } mark_zone(blockno); badblocks++; @@ -573,9 +565,9 @@ main(int argc, char ** argv) { } if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) - die(_("bad inode size")); + errx(8, _("bad inode size"), device_name); if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) - die(_("bad inode size")); + errx(8, _("bad inode size"), device_name); opterr = 0; while ((i = getopt(argc, argv, "ci:l:n:v")) != -1) @@ -635,23 +627,23 @@ main(int argc, char ** argv) { *(short *)tmp = 2; strcpy(tmp+2,".badblocks"); if (stat(device_name, &statbuf) < 0) - die(_("unable to stat %s")); + errx(8, _("unable to stat %s"), device_name); if (S_ISBLK(statbuf.st_mode)) DEV = open(device_name,O_RDWR | O_EXCL); else DEV = open(device_name,O_RDWR); if (DEV<0) - die(_("unable to open %s")); + errx(8, _("unable to open %s"), device_name); if (S_ISBLK(statbuf.st_mode)) { int sectorsize; if (blkdev_get_sector_size(DEV, §orsize) == -1) - die(_("cannot determine sector size for %s")); + errx(8, _("cannot determine sector size for %s"), device_name); if (BLOCK_SIZE < sectorsize) - die(_("block size smaller than physical sector size of %s")); + errx(8, _("block size smaller than physical sector size of %s"), device_name); if (!BLOCKS) { if (blkdev_get_size(DEV, &BLOCKS) == -1) - die(_("cannot determine size of %s")); + errx(8, _("cannot determine size of %s"), device_name); BLOCKS /= BLOCK_SIZE; } } else if (!S_ISBLK(statbuf.st_mode)) { @@ -659,9 +651,9 @@ main(int argc, char ** argv) { BLOCKS = statbuf.st_size / BLOCK_SIZE; check=0; } else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) - die(_("will not try to make filesystem on '%s'")); + errx(8, _("will not try to make filesystem on '%s'"), device_name); if (BLOCKS < 10) - die(_("number of blocks too small")); + errx(8, _("number of blocks too small"), device_name); if (version2) { if (namelen == 14) magic = MINIX2_SUPER_MAGIC; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html