Subject: [PATCH] [FEAT LS1501] dasdfmt: Add new formatting modes From: Jan Höppner Summary: dasdfmt: Add new formatting modes Description: Introduce new formatting modes 'quick' and 'expand' to either format an earlier formatted DASD that could potentially be re-initialized very easily or format unformatted tracks at the end of a device that was previously extended. Also add the command line argument --check to provide a function that checks a DASD volume for correct formatting. Upstream-ID: - Problem-ID: LS1501 Upstream-Description: dasdfmt: Apply coding convention Improve the overall readability of the code by applying the Kernel coding convention. Signed-off-by: Jan Höppner Signed-off-by: Stefan Haberland Signed-off-by: Jan Höppner --- dasdfmt/dasdfmt.c | 362 +++++++++++++++++++++++++----------------------------- 1 file changed, 171 insertions(+), 191 deletions(-) --- a/dasdfmt/dasdfmt.c +++ b/dasdfmt/dasdfmt.c @@ -37,11 +37,10 @@ int reqsize; /* * Print version information. */ -static void -print_version (void) +static void print_version(void) { - printf ("%s version %s\n", tool_name, RELEASE_STRING); - printf ("%s\n", copyright_notice); + printf("%s version %s\n", tool_name, RELEASE_STRING); + printf("%s\n", copyright_notice); } /* @@ -54,7 +53,7 @@ static void exit_usage(int exitcode) " [-b | --blocksize=]\n" " [-d | --disk_layout=]\n" " [-r | --requestsize=]\n" - " \n\n",prog_name); + " \n\n", prog_name); printf(" -t or --test means testmode\n" " -V or --version means print version\n" @@ -71,13 +70,13 @@ static void exit_usage(int exitcode) " -C or --check_host_count means force dasdfmt to check\n" " the host access open count to ensure the device\n" " is not online on another operating system instance\n" - " --norecordzero prevent storage server from modifying" - " record 0\n\n" + " --norecordzero prevent storage server from modifying" + " record 0\n\n" " is the volume identifier, which is converted\n" - " to EBCDIC and written to disk. \n" + " to EBCDIC and written to disk.\n" " (6 characters, e.g. LNX001\n" " has to be power of 2 and at least 512\n" - " is either \n" + " is either\n" " 'cdl' for compatible disk layout (default) or\n" " 'ldl' for linux disk layout\n" " device node of the device to format\n"); @@ -106,38 +105,39 @@ static int reread_partition_table(void) * signal handler: * enables the disk again in case of SIGTERM, SIGINT and SIGQUIT */ -static void program_interrupt_signal (int sig) +static void program_interrupt_signal(int sig) { int rc; if (program_interrupt_in_progress) - raise (sig); + raise(sig); program_interrupt_in_progress = 1; if (disk_disabled) { - printf("Re-accessing the device... \n"); + printf("Re-accessing the device...\n"); rc = ioctl(filedes, BIODASDENABLE, &format_params); if (rc) - ERRMSG_EXIT(EXIT_FAILURE, - "%s: (signal handler) IOCTL BIODASDENABLE " - "failed (%s)\n",prog_name,strerror(errno)); + ERRMSG_EXIT(EXIT_FAILURE, "%s: (signal handler) IOCTL " + "BIODASDENABLE failed (%s)\n", prog_name, + strerror(errno)); } - printf("Rereading the partition table... \n"); + printf("Rereading the partition table...\n"); rc = reread_partition_table(); if (rc) { ERRMSG("%s: (signal handler) Re-reading partition table " "failed. (%s)\n", prog_name, strerror(errno)); - } else + } else { printf("Exiting...\n"); + } rc = close(filedes); if (rc) ERRMSG("%s: (signal handler) Unable to close device (%s)\n", prog_name, strerror(errno)); - signal (sig, SIG_DFL); - raise (sig); + signal(sig, SIG_DFL); + raise(sig); } @@ -171,13 +171,13 @@ static void get_device_name(dasdfmt_info char* device; int i; - if ((strchr(name, ' ') != NULL)||(strchr(name, '#') != NULL)|| - (strchr(name, '[') != NULL)||(strchr(name, ']') != NULL)|| - (strchr(name, '!') != NULL)||(strchr(name, '>') != NULL)|| - (strchr(name, '(') != NULL)||(strchr(name, '<') != NULL)|| - (strchr(name, ')') != NULL)||(strchr(name, ':') != NULL)|| - (strchr(name, '&') != NULL)||(strchr(name, ';') != NULL)) - ERRMSG_EXIT(EXIT_MISUSE,"%s: Your filename contains " + if ((strchr(name, ' ') != NULL) || (strchr(name, '#') != NULL) || + (strchr(name, '[') != NULL) || (strchr(name, ']') != NULL) || + (strchr(name, '!') != NULL) || (strchr(name, '>') != NULL) || + (strchr(name, '(') != NULL) || (strchr(name, '<') != NULL) || + (strchr(name, ')') != NULL) || (strchr(name, ':') != NULL) || + (strchr(name, '&') != NULL) || (strchr(name, ';') != NULL)) + ERRMSG_EXIT(EXIT_MISUSE, "%s: Your filename contains " "blanks or special characters!\n", prog_name); @@ -215,14 +215,14 @@ static void get_device_name(dasdfmt_info info->devname[PATH_MAX - 1] = '\0'; if (stat(info->devname, &dev_stat) != 0) - ERRMSG_EXIT(EXIT_MISUSE, - "%s: Could not get information for device node %s: %s\n", - prog_name, info->devname, strerror(errno)); + ERRMSG_EXIT(EXIT_MISUSE, "%s: Could not get information for " + "device node %s: %s\n", prog_name, info->devname, + strerror(errno)); if (minor(dev_stat.st_rdev) & PARTN_MASK) { - ERRMSG_EXIT(EXIT_MISUSE, - "%s: Unable to format partition %s. Please specify a device.\n", - prog_name, info->devname); + ERRMSG_EXIT(EXIT_MISUSE, "%s: Unable to format partition %s. " + "Please specify a device.\n", prog_name, + info->devname); } if (util_proc_dev_get_entry(dev_stat.st_rdev, 1, &dev_entry) == 0) { @@ -253,7 +253,7 @@ static void init_info(dasdfmt_info_t *in info->force = 0; info->writenolabel = 0; info->labelspec = 0; - info->cdl_format = 0; + info->cdl_format = 0; info->blksize_specified = 0; info->reqsize_specified = 0; info->node_specified = 0; @@ -263,7 +263,6 @@ static void init_info(dasdfmt_info_t *in info->yast_mode = 0; } - /* * check for disk type and set some variables (e.g. usage count) */ @@ -280,9 +279,9 @@ static void check_disk(dasdfmt_info_t *i "status information failed (%s)\n", prog_name, strerror(errno_save)); } - if (ro) { + if (ro) ERRMSG_EXIT(EXIT_FAILURE, "Disk is read only!\n"); - } + retry: if (ioctl(filedes, BIODASDINFO, &dasd_info) != 0) { errno_save = errno; @@ -314,7 +313,7 @@ retry: info->usage_count = dasd_info.open_count; info->devno = dasd_info.devno; - if (strncmp(dasd_info.type, "ECKD",4) != 0) { + if (strncmp(dasd_info.type, "ECKD", 4) != 0) { ERRMSG_EXIT(EXIT_FAILURE, "%s: Unsupported disk type\n%s is not an " "ECKD disk!\n", prog_name, info->devname); @@ -327,29 +326,28 @@ retry: } } - /* * check the volume serial for special * characters and move blanks to the end */ static int check_volser(char *s, int devno) { - int i,j; + int i, j; - for (i=0; i<6; i++) { + for (i = 0; i < 6; i++) { if ((s[i] < 0x20) || (s[i] > 0x7a) || - ((s[i] >= 0x21)&&(s[i] <= 0x22)) || /* !" */ - ((s[i] >= 0x26)&&(s[i] <= 0x2f)) || /* &'()*+,-./ */ - ((s[i] >= 0x3a)&&(s[i] <= 0x3f)) || /* :;<=>? */ - ((s[i] >= 0x5b)&&(s[i] <= 0x60))) /* \]^_` */ + ((s[i] >= 0x21) && (s[i] <= 0x22)) || /* !" */ + ((s[i] >= 0x26) && (s[i] <= 0x2f)) || /* &'()*+,-./ */ + ((s[i] >= 0x3a) && (s[i] <= 0x3f)) || /* :;<=>? */ + ((s[i] >= 0x5b) && (s[i] <= 0x60))) /* \]^_` */ s[i] = ' '; s[i] = toupper(s[i]); } s[6] = 0x00; - for (i=0; i<6; i++) { + for (i = 0; i < 6; i++) { if (s[i] == ' ') - for (j=i; j<6; j++) + for (j = i; j < 6; j++) if (s[j] != ' ') { s[i] = s[j]; s[j] = ' '; @@ -360,7 +358,7 @@ static int check_volser(char *s, int dev if (s[0] == ' ') { printf("Usage error, switching to default.\n"); sprintf(s, "0X%04x", devno); - for (i=0; i<6; i++) + for (i = 0; i < 6; i++) s[i] = toupper(s[i]); return -1; } @@ -368,7 +366,6 @@ static int check_volser(char *s, int dev return 0; } - /* * do some blocksize checks */ @@ -377,7 +374,7 @@ static int check_param(char *s, size_t b int tmp = data->blksize; if ((tmp < 512) || (tmp > 4096)) { - strncpy(s,"Blocksize must be one of the following positive " + strncpy(s, "Blocksize must be one of the following positive " "integers:\n512, 1024, 2048, 4096.", buffsize); if (buffsize > 0) s[buffsize - 1] = '\0'; @@ -386,7 +383,7 @@ static int check_param(char *s, size_t b while (tmp > 0) { if ((tmp % 2) && (tmp != 1)) { - strncpy(s,"Blocksize must be a power of 2.", buffsize); + strncpy(s, "Blocksize must be a power of 2.", buffsize); if (buffsize > 0) s[buffsize - 1] = '\0'; return -1; @@ -397,7 +394,6 @@ static int check_param(char *s, size_t b return 0; } - /* * ask the user to specify a blocksize */ @@ -415,7 +411,7 @@ static format_data_t ask_user_for_blksiz if (fgets(buffer, sizeof(buffer), stdin) == NULL) break; - rc = sscanf(buffer,"%d%c", ¶ms.blksize, &c); + rc = sscanf(buffer, "%d%c", ¶ms.blksize, &c); if ((rc == 2) && (c == '\n')) rc = 1; if (rc == -1) @@ -424,7 +420,7 @@ static format_data_t ask_user_for_blksiz printf(" -- wrong input, try again.\n"); if (check_param(str, ERR_LENGTH, ¶ms) < 0) { - printf(" -- %s\n",str); + printf(" -- %s\n", str); rc = 0; } } while (rc != 1); @@ -432,7 +428,6 @@ static format_data_t ask_user_for_blksiz return params; } - /* * print all information needed to format the device */ @@ -449,7 +444,7 @@ static void dasdfmt_print_info(dasdfmt_i printf("%s in the following way:\n", info->devname); printf(" Device number of device : 0x%x\n", info->devno); printf(" Labelling device : %s\n", - (info->writenolabel)?"no":"yes"); + (info->writenolabel) ? "no" : "yes"); if (!info->writenolabel) { vtoc_volume_label_get_label(vlabel, vollbl); @@ -460,31 +455,31 @@ static void dasdfmt_print_info(dasdfmt_i printf(" Extent start (trk no) : %u\n", p->start_unit); printf(" Extent end (trk no) : %u\n", p->stop_unit); printf(" Compatible Disk Layout : %s\n", - (p->intensity & DASD_FMT_INT_COMPAT)?"yes":"no"); + (p->intensity & DASD_FMT_INT_COMPAT) ? "yes" : "no"); printf(" Blocksize : %d\n", p->blksize); if (info->testmode) printf("Test mode active, omitting ioctl.\n"); } - /* * get volser */ -static int dasdfmt_get_volser(char * devname, char * volser) +static int dasdfmt_get_volser(char *devname, char *volser) { - dasd_information_t dasd_info; + dasd_information_t dasd_info; int blksize; int f; volume_label_t vlabel; - if ((f = open(devname, O_RDONLY)) == -1) - ERRMSG_EXIT(EXIT_FAILURE,"%s: Unable to open device %s: %s\n", + f = open(devname, O_RDONLY); + if (f == -1) + ERRMSG_EXIT(EXIT_FAILURE, "%s: Unable to open device %s: %s\n", prog_name, devname, strerror(errno)); if (ioctl(f, BIODASDINFO, &dasd_info) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (label pos) IOCTL BIODASD" - "INFO failed (%s).\n",prog_name, strerror(errno)); + "INFO failed (%s).\n", prog_name, strerror(errno)); if (ioctl(f, BLKSSZGET, &blksize) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (label pos) IOCTL BLKSSZGET " @@ -500,8 +495,7 @@ static int dasdfmt_get_volser(char * dev vtoc_read_volume_label(devname, dasd_info.label_block * blksize, &vlabel); vtoc_volume_label_get_volser(&vlabel, volser); return 0; - } - else { + } else { return -1; } } @@ -512,22 +506,24 @@ static int dasdfmt_get_volser(char * dev static void dasdfmt_write_labels(dasdfmt_info_t *info, volume_label_t *vlabel, unsigned int cylinders, unsigned int heads) { - int label_position; - dasd_information_t dasd_info; - struct hd_geometry geo; - format4_label_t f4; - format5_label_t f5; - format7_label_t f7; + int label_position; + dasd_information_t dasd_info; + struct hd_geometry geo; + format4_label_t f4; + format5_label_t f5; + format7_label_t f7; int rc, blksize; void *ipl1_record, *ipl2_record; int ipl1_record_len, ipl2_record_len; - if (info->verbosity > 0) printf("Retrieving dasd information... "); + if (info->verbosity > 0) + printf("Retrieving dasd information... "); if (ioctl(filedes, BIODASDINFO, &dasd_info) != 0) - ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL BIODASD" - "INFO failed (%s).\n",prog_name, strerror(errno)); + ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL " + "BIODASDINFO failed (%s).\n", + prog_name, strerror(errno)); if (ioctl(filedes, BLKSSZGET, &blksize) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL BLKSSZGET " @@ -539,13 +535,16 @@ static void dasdfmt_write_labels(dasdfmt * vary depending on the format. */ if (ioctl(filedes, HDIO_GETGEO, &geo) != 0) - ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL HDIO_GET" - "GEO failed (%s).\n", prog_name, strerror(errno)); + ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL " + "HDIO_GETGEO failed (%s).\n", + prog_name, strerror(errno)); - if (info->verbosity > 0) printf("ok\n"); + if (info->verbosity > 0) + printf("ok\n"); /* write empty bootstrap (initial IPL records) */ - if (info->verbosity > 0) printf("Writing empty bootstrap...\n"); + if (info->verbosity > 0) + printf("Writing empty bootstrap...\n"); /* * Note: ldl labels do not contain the key field @@ -596,7 +595,8 @@ static void dasdfmt_write_labels(dasdfmt label_position = dasd_info.label_block * blksize; - if (info->verbosity > 0) printf("Writing label...\n"); + if (info->verbosity > 0) + printf("Writing label...\n"); rc = lseek(filedes, label_position, SEEK_SET); if (rc != label_position) @@ -608,10 +608,10 @@ static void dasdfmt_write_labels(dasdfmt * Note: cdl volume labels do not contain the 'formatted_blocks' part * and ldl labels do not contain the key field */ - if (info->cdl_format) + if (info->cdl_format) { rc = write(filedes, vlabel, (sizeof(*vlabel) - sizeof(vlabel->formatted_blocks))); - else { + } else { vlabel->ldl_version = 0xf2; /* EBCDIC '2' */ vlabel->formatted_blocks = cylinders * heads * geo.sectors; rc = write(filedes, &vlabel->vollbl, (sizeof(*vlabel) @@ -625,7 +625,8 @@ static void dasdfmt_write_labels(dasdfmt ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing volume label " "(%d).\n", prog_name, rc); - if (info->verbosity > 0) printf("Writing VTOC... "); + if (info->verbosity > 0) + printf("Writing VTOC... "); label_position = (VTOC_START_CC * heads + VTOC_START_HH) * geo.sectors * blksize; @@ -673,10 +674,10 @@ static void dasdfmt_write_labels(dasdfmt fsync(filedes); - if (info->verbosity > 0) printf("ok\n"); + if (info->verbosity > 0) + printf("ok\n"); } - /* * formats the disk cylinderwise */ @@ -720,21 +721,20 @@ static void dasdfmt_format(dasdfmt_info_ format_step.start_unit += 1; if (ioctl(filedes, BIODASDFMT, &format_step) != 0) - ERRMSG_EXIT(EXIT_FAILURE,"%s: (format cylinder) IOCTL " + ERRMSG_EXIT(EXIT_FAILURE, "%s: (format cylinder) IOCTL " "BIODASDFMT failed. (%s)\n", prog_name, strerror(errno)); if (info->print_progressbar) { printf("cyl %7d of %7d |", cyl, cylinders); p2 = p1; - p1 = cyl*100/cylinders; - if (p1 != p2) - { + p1 = cyl * 100 / cylinders; + if (p1 != p2) { /* percent value has changed */ - tmp = cyl*50/cylinders; - for (j=1; j<=tmp; j++) + tmp = cyl * 50 / cylinders; + for (j = 1; j <= tmp; j++) printf("#"); - for (j=tmp+1; j<=50; j++) + for (j = tmp + 1; j <= 50; j++) printf("-"); printf("|%3d%%", p1); } @@ -748,6 +748,7 @@ static void dasdfmt_format(dasdfmt_info_ fflush(stdout); hashcount++; } + if (info->print_percentage) { printf("cyl %7d of %7d |%3d%%\n", cyl, cylinders, cyl*100/cylinders); @@ -757,9 +758,9 @@ static void dasdfmt_format(dasdfmt_info_ if (k % heads == 0) { k += reqsize * heads; cyl += reqsize; - } - else + } else { k += format_params->stop_unit % heads; + } if (k > format_params->stop_unit) break; @@ -769,14 +770,9 @@ static void dasdfmt_format(dasdfmt_info_ printf("\n\n"); } - -/* - * - */ -static void dasdfmt_prepare_and_format (dasdfmt_info_t *info, - unsigned int cylinders, - unsigned int heads, - format_data_t *p) +static void dasdfmt_prepare_and_format(dasdfmt_info_t *info, + unsigned int cylinders, + unsigned int heads, format_data_t *p) { format_data_t temp = { start_unit: 0, @@ -786,7 +782,8 @@ static void dasdfmt_prepare_and_format ( | DASD_FMT_INT_INVAL) }; - if (info->verbosity > 0) printf("Detaching the device...\n"); + if (info->verbosity > 0) + printf("Detaching the device...\n"); if (ioctl(filedes, BIODASDDISABLE, p) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL " @@ -794,7 +791,8 @@ static void dasdfmt_prepare_and_format ( strerror(errno)); disk_disabled = 1; - if (info->verbosity > 0) printf("Invalidate first track...\n"); + if (info->verbosity > 0) + printf("Invalidate first track...\n"); if (ioctl(filedes, BIODASDFMT, &temp) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (invalidate first track) IOCTL " @@ -806,18 +804,21 @@ static void dasdfmt_prepare_and_format ( dasdfmt_format(info, cylinders, heads, p); - if (info->verbosity > 0) printf("formatting tracks complete...\n"); + if (info->verbosity > 0) + printf("formatting tracks complete...\n"); temp.intensity = p->intensity; - if (info->verbosity > 0) printf("Revalidate first track...\n"); + if (info->verbosity > 0) + printf("Revalidate first track...\n"); if (ioctl(filedes, BIODASDFMT, &temp) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (re-validate first track) IOCTL" " BIODASDFMT failed (%s)\n", prog_name, strerror(errno)); - if (info->verbosity > 0) printf("Re-accessing the device...\n"); + if (info->verbosity > 0) + printf("Re-accessing the device...\n"); if (ioctl(filedes, BIODASDENABLE, p) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL " @@ -826,20 +827,17 @@ static void dasdfmt_prepare_and_format ( disk_disabled = 0; } - -/* - * - */ static void do_format_dasd(dasdfmt_info_t *info, format_data_t *p, volume_label_t *vlabel) { - char inp_buffer[5]; + char inp_buffer[5]; dasd_information_t dasd_info; struct dasd_eckd_characteristics *characteristics; unsigned int cylinders, heads; int count; - if (info->verbosity > 0) printf("Retrieving disk geometry...\n"); + if (info->verbosity > 0) + printf("Retrieving disk geometry...\n"); if (ioctl(filedes, BIODASDINFO, &dasd_info) != 0) ERRMSG_EXIT(EXIT_FAILURE, "%s: (retrieving disk information) " @@ -877,22 +875,23 @@ static void do_format_dasd(dasdfmt_info_ } } } else { - if (!info->labelspec && !info->keep_volser) { + if (!info->labelspec && !info->keep_volser) { char buf[7]; - sprintf(buf, "0X%04x", info->devno); + sprintf(buf, "0X%04x", info->devno); check_volser(buf, info->devno); vtoc_volume_label_set_volser(vlabel, buf); } - if (p->intensity & DASD_FMT_INT_COMPAT) { + if (p->intensity & DASD_FMT_INT_COMPAT) { info->cdl_format = 1; vtoc_volume_label_set_label(vlabel, "VOL1"); vtoc_volume_label_set_key(vlabel, "VOL1"); vtoc_set_cchhb(&vlabel->vtoc, 0x0000, 0x0001, 0x01); - } else + } else { vtoc_volume_label_set_label(vlabel, "LNX1"); - } + } + } if ((info->verbosity > 0) || !info->withoutprompt || info->testmode) dasdfmt_print_info(info, vlabel, cylinders, heads, p); @@ -926,15 +925,15 @@ static void do_format_dasd(dasdfmt_info_ "untouched: "); if (fgets(inp_buffer, sizeof(inp_buffer), stdin) == NULL) return; - if (strcasecmp(inp_buffer,"yes") && - strcasecmp(inp_buffer,"yes\n")) { + if (strcasecmp(inp_buffer, "yes") && + strcasecmp(inp_buffer, "yes\n")) { printf("Omitting ioctl call (disk will " "NOT be formatted).\n"); return; } } - if (!((info->withoutprompt)&&(info->verbosity<1))) + if (!((info->withoutprompt) && (info->verbosity < 1))) printf("Formatting the device. This may take a " "while (get yourself a coffee).\n"); @@ -954,12 +953,11 @@ static void do_format_dasd(dasdfmt_info_ } else { if (!info->yast_mode) printf("ok\n"); - } + } } } - -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { dasdfmt_info_t info; volume_label_t vlabel; @@ -980,9 +978,9 @@ int main(int argc,char *argv[]) int running=0; /* Establish a handler for interrupt signals. */ - signal (SIGTERM, program_interrupt_signal); - signal (SIGINT, program_interrupt_signal); - signal (SIGQUIT, program_interrupt_signal); + signal(SIGTERM, program_interrupt_signal); + signal(SIGINT, program_interrupt_signal); + signal(SIGQUIT, program_interrupt_signal); /******************* initialization ********************/ prog_name = argv[0]; @@ -996,102 +994,81 @@ int main(int argc,char *argv[]) /*************** parse parameters **********************/ - while (1) - { - rc=getopt_long(argc, argv, dasdfmt_getopt_string, - dasdfmt_getopt_long_options, &index); + while (1) { + rc = getopt_long(argc, argv, dasdfmt_getopt_string, + dasdfmt_getopt_long_options, &index); - switch (rc) - { + switch (rc) { case 'F': - info.force=1; + info.force = 1; break; - - case 'd' : - if (strncmp(optarg,"cdl",3)==0) - { + case 'd': + if (strncmp(optarg, "cdl", 3) == 0) { format_params.intensity |= DASD_FMT_INT_COMPAT; - if (info.writenolabel) - { - printf("WARNING: using the cdl " \ - "format without writing a " \ - "label doesn't make much " \ + if (info.writenolabel) { + printf("WARNING: using the cdl " + "format without writing a " + "label doesn't make much " "sense!\n"); exit(1); } - } - else if (strncmp(optarg,"ldl",3)==0) + } else if (strncmp(optarg, "ldl", 3) == 0) { format_params.intensity &= ~DASD_FMT_INT_COMPAT; - else - { + } else { printf("%s is not a valid option!\n", optarg); exit(1); } - break; - + break; case 'y': - info.withoutprompt=1; + info.withoutprompt = 1; break; - case 'z': - format_params.intensity |= DASD_FMT_INT_FMT_NOR0; + format_params.intensity |= DASD_FMT_INT_FMT_NOR0; break; - case 't': - info.testmode=1; + info.testmode = 1; break; - case 'p': if (!(info.print_hashmarks || info.print_percentage)) info.print_progressbar = 1; break; - case 'm': - if (!(info.print_progressbar || info.print_percentage)) - { - hashstep_str=optarg; - info.print_hashmarks=1; + if (!(info.print_progressbar || info.print_percentage)) { + hashstep_str = optarg; + info.print_hashmarks = 1; } break; - case 'Q': if (!(info.print_hashmarks || info.print_progressbar)) info.print_percentage = 1; break; - case 'v': - info.verbosity=1; + info.verbosity = 1; break; - case 'h': exit_usage(0); - case 'V': print_version(); exit(0); - case 'l': - strncpy(buf, optarg, 6); + strncpy(buf, optarg, 6); if (check_volser(buf, 0) < 0) break; - vtoc_volume_label_set_volser(&vlabel,buf); - info.labelspec=1; + vtoc_volume_label_set_volser(&vlabel, buf); + info.labelspec = 1; break; - case 'L': - if (format_params.intensity & DASD_FMT_INT_COMPAT) - { - printf("WARNING: using the cdl format " \ - "without writing a label doesn't " \ + if (format_params.intensity & DASD_FMT_INT_COMPAT) { + printf("WARNING: using the cdl format " + "without writing a label doesn't " "make much sense!\n"); exit(1); } - info.writenolabel=1; + info.writenolabel = 1; break; - - case 'b' : - blksize_param_str=optarg; - info.blksize_specified=1; + case 'b': + blksize_param_str = optarg; + info.blksize_specified = 1; break; case 'r': reqsize_param_str = optarg; @@ -1102,7 +1079,7 @@ int main(int argc,char *argv[]) ERRMSG_EXIT(EXIT_MISUSE,"%s: too many devices specified.\n", prog_name); dev_filename[dev_count++]=strdup(optarg); - info.node_specified=1; + info.node_specified = 1; break; case 'Y' : /* YaST mode */ info.yast_mode=1; @@ -1110,8 +1087,8 @@ int main(int argc,char *argv[]) case 'P' : /* max parallel formatting processes */ max_parallel=atoi(optarg); break; - case 'k' : - info.keep_volser=1; + case 'k': + info.keep_volser = 1; break; case 'C': info.force_host = 1; @@ -1121,11 +1098,12 @@ int main(int argc,char *argv[]) info.device_id = optind; break; default: - ERRMSG_EXIT(EXIT_MISUSE, - "Try '%s --help' for more" - " information.\n",prog_name); + ERRMSG_EXIT(EXIT_MISUSE, "Try '%s --help' for more" + " information.\n", prog_name); } - if (rc==-1) break; // exit loop if finished + + if (rc == -1) + break; /* exit loop if finished */ } CHECK_SPEC_MAX_ONCE(info.blksize_specified, "blocksize"); @@ -1222,7 +1200,7 @@ int main(int argc,char *argv[]) } else reqsize = DEFAULT_REQUESTSIZE; if (info.print_hashmarks) - PARSE_PARAM_INTO(info.hashstep, hashstep_str,10,"hashstep"); + PARSE_PARAM_INTO(info.hashstep, hashstep_str, 10, "hashstep"); get_device_name(&info, dev_filename[i]); @@ -1230,22 +1208,24 @@ int main(int argc,char *argv[]) format_params = ask_user_for_blksize(format_params); if (info.keep_volser) { - if(format_params.intensity == 0x00) { - printf("WARNING: VOLSER cannot be kept " \ + if (format_params.intensity == 0x00) { + printf("WARNING: VOLSER cannot be kept " "when using the ldl format!\n"); exit(1); } - if(dasdfmt_get_volser(info.devname, old_volser) == 0) + if (dasdfmt_get_volser(info.devname, old_volser) == 0) vtoc_volume_label_set_volser(&vlabel, old_volser); else - ERRMSG_EXIT(EXIT_FAILURE,"%s: VOLSER not found on device %s\n", + ERRMSG_EXIT(EXIT_FAILURE, + "%s: VOLSER not found on device %s\n", prog_name, info.devname); } - if ((filedes = open(info.devname, O_RDWR)) == -1) - ERRMSG_EXIT(EXIT_FAILURE,"%s: Unable to open device %s: %s\n", + filedes = open(info.devname, O_RDWR); + if (filedes == -1) + ERRMSG_EXIT(EXIT_FAILURE, "%s: Unable to open device %s: %s\n", prog_name, info.devname, strerror(errno)); check_disk(&info);