mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
dasdfmt: Replace ERRMSG_EXIT macro with an error handling function
The ERRMSG_EXIT macro is a bit clunky in its usage and a change is necessary in order to free memory in error cases. Create a new function error() that takes only a format string and adds all other relevant information by itself. This function frees memory before terminating the program with the EXIT_FAILURE exit code. This simplifies the error handling for pretty much all calls and makes the code a bit cleaner. While at it, the defines EXIT_MISUSE and EXIT_BUSY don't provide any value. Neither are they documented nor are these standardized. Also, a parent process is mostly interessted in success or failure only anyway. Replace these by using only EXIT_FAILURE in the error() function. Also, change multiline output to a combination of warnx and error to have a uniformed output. So this: WARNING: Device is formatted with a different blocksize (4096). Use --mode=full to perform a clean format. becomes this: dasdfmt: WARNING: Device is formatted with a different blocksize (4096). dasdfmt: Use --mode=full to perform a clean format. Reviewed-by: Stefan Haberland <sth@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
@@ -186,6 +187,23 @@ static struct util_opt opt_vec[] = {
|
|||||||
UTIL_OPT_END
|
UTIL_OPT_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Report error, free memory, and exit */
|
||||||
|
static void error(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
fprintf(stderr, "%s: ", prog_name);
|
||||||
|
va_start(args, format);
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
|
free(g.dev_node);
|
||||||
|
free(g.dev_path);
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to calculate the days, hours, minutes, and seconds
|
* Helper function to calculate the days, hours, minutes, and seconds
|
||||||
* for a given timestamp in seconds
|
* for a given timestamp in seconds
|
||||||
@@ -439,9 +457,7 @@ static void disk_enable(void)
|
|||||||
|
|
||||||
err = dasd_disk_enable(filedes);
|
err = dasd_disk_enable(filedes);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL "
|
error("(prepare device) IOCTL BIODASDENABLE failed: %s", strerror(err));
|
||||||
"BIODASDENABLE failed (%s)\n", prog_name,
|
|
||||||
strerror(err));
|
|
||||||
disk_disabled = 0;
|
disk_disabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,9 +467,7 @@ static void disk_disable(const char *device)
|
|||||||
|
|
||||||
err = dasd_disk_disable(device, &filedes);
|
err = dasd_disk_disable(device, &filedes);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL "
|
error("(prepare device) IOCTL BIODASDDISABLE failed: %s", strerror(err));
|
||||||
"BIODASDDISABLE failed. (%s)\n", prog_name,
|
|
||||||
strerror(err));
|
|
||||||
disk_disabled = 1;
|
disk_disabled = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,36 +513,27 @@ static void get_device_name(int optind, int argc, char *argv[])
|
|||||||
struct stat dev_stat;
|
struct stat dev_stat;
|
||||||
|
|
||||||
if (optind + 1 < argc)
|
if (optind + 1 < argc)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE,
|
error("More than one device specified!");
|
||||||
"%s: More than one device specified!\n", prog_name);
|
|
||||||
|
|
||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: No device specified!\n",
|
error("No device specified!");
|
||||||
prog_name);
|
|
||||||
|
|
||||||
if (strlen(argv[optind]) >= PATH_MAX)
|
if (strlen(argv[optind]) >= PATH_MAX)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: device name too long!\n",
|
error("device name too long!");
|
||||||
prog_name);
|
|
||||||
util_asprintf(&g.dev_path, argv[optind]);
|
util_asprintf(&g.dev_path, argv[optind]);
|
||||||
|
|
||||||
if (stat(g.dev_path, &dev_stat) != 0)
|
if (stat(g.dev_path, &dev_stat) != 0)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: Could not get information for "
|
error("Could not get information for device node %s: %s",
|
||||||
"device node %s: %s\n", prog_name, g.dev_path,
|
g.dev_path, strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
|
|
||||||
maj = major(dev_stat.st_rdev);
|
maj = major(dev_stat.st_rdev);
|
||||||
min = minor(dev_stat.st_rdev);
|
min = minor(dev_stat.st_rdev);
|
||||||
if (min & PARTN_MASK) {
|
if (min & PARTN_MASK)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: Unable to format partition %s. "
|
error("Unable to format partition %s. Please specify a device.", g.dev_path);
|
||||||
"Please specify a device.\n", prog_name,
|
|
||||||
g.dev_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (util_proc_dev_get_entry(dev_stat.st_rdev, 1, &dev_entry) == 0) {
|
if (util_proc_dev_get_entry(dev_stat.st_rdev, 1, &dev_entry) == 0) {
|
||||||
if (strncmp(dev_entry.name, "dasd", 4) != 0)
|
if (strncmp(dev_entry.name, "dasd", 4) != 0)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE,
|
error("Unsupported device type '%s'.", dev_entry.name);
|
||||||
"%s: Unsupported device type '%s'.\n",
|
|
||||||
prog_name, dev_entry.name);
|
|
||||||
} else {
|
} else {
|
||||||
printf("%s WARNING: Unable to get driver name for device node %s",
|
printf("%s WARNING: Unable to get driver name for device node %s",
|
||||||
prog_name, g.dev_path);
|
prog_name, g.dev_path);
|
||||||
@@ -543,9 +548,7 @@ static void get_blocksize(unsigned int *blksize)
|
|||||||
|
|
||||||
err = dasd_get_blocksize(g.dev_node, blksize);
|
err = dasd_get_blocksize(g.dev_node, blksize);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl to get the blocksize "
|
error("the ioctl to get the blocksize of the device failed: %s", strerror(err));
|
||||||
"of the device failed (%s).\n", prog_name,
|
|
||||||
strerror(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -561,9 +564,8 @@ static void check_blocksize(unsigned int blksize)
|
|||||||
|
|
||||||
get_blocksize(&dev_blksize);
|
get_blocksize(&dev_blksize);
|
||||||
if (dev_blksize != blksize) {
|
if (dev_blksize != blksize) {
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "WARNING: Device is formatted with a "
|
warnx("WARNING: Device is formatted with a different blocksize (%d).", dev_blksize);
|
||||||
"different blocksize (%d).\nUse --mode=full to "
|
error("Use --mode=full to perform a clean format.");
|
||||||
"perform a clean format.\n", dev_blksize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,8 +594,7 @@ static void check_layout(unsigned int intensity)
|
|||||||
if (g.dasd_info.format == DASD_FORMAT_LDL)
|
if (g.dasd_info.format == DASD_FORMAT_LDL)
|
||||||
sprintf(layout, "LDL");
|
sprintf(layout, "LDL");
|
||||||
|
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "WARNING: Device is formatted with a "
|
error("WARNING: Device is formatted with a different layout (%s).", layout);
|
||||||
"different layout (%s).\n", layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -606,29 +607,20 @@ static void check_disk(void)
|
|||||||
|
|
||||||
err = dasd_is_ro(g.dev_node, &ro);
|
err = dasd_is_ro(g.dev_node, &ro);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
error("the ioctl call to retrieve read/write status information failed: %s",
|
||||||
"%s: the ioctl call to retrieve read/write "
|
strerror(err));
|
||||||
"status information failed (%s)\n",
|
|
||||||
prog_name, strerror(err));
|
|
||||||
|
|
||||||
if (ro)
|
if (ro)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "Disk is read only!\n");
|
error("Disk is read only!");
|
||||||
|
if (!g.force) {
|
||||||
if (!g.force)
|
|
||||||
if (g.dasd_info.open_count > 1)
|
if (g.dasd_info.open_count > 1)
|
||||||
ERRMSG_EXIT(EXIT_BUSY, "Disk in use!\n");
|
error("Disk in use!");
|
||||||
|
}
|
||||||
if (strncmp(g.dasd_info.type, "ECKD", 4) != 0) {
|
if (strncmp(g.dasd_info.type, "ECKD", 4) != 0) {
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
warnx("Unsupported disk type");
|
||||||
"%s: Unsupported disk type\n%s is not an "
|
error("%s is not an ECKD disk!", g.dev_path);
|
||||||
"ECKD disk!\n", prog_name, g.dev_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dasd_sys_raw_track_access(g.dev_node)) {
|
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
|
||||||
"%s: Device '%s' is in raw-track access mode\n",
|
|
||||||
prog_name, g.dev_path);
|
|
||||||
}
|
}
|
||||||
|
if (dasd_sys_raw_track_access(g.dev_node))
|
||||||
|
error("Device '%s' is in raw-track access mode", g.dev_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -811,10 +803,9 @@ static format_check_t check_track_format(format_data_t *p)
|
|||||||
} else if (!g.check) {
|
} else if (!g.check) {
|
||||||
ERRMSG(" (--force to override)");
|
ERRMSG(" (--force to override)");
|
||||||
}
|
}
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, ".\n");
|
error(".");
|
||||||
}
|
}
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Could no check format: %s\n",
|
error("Could not check format: %s", strerror(err));
|
||||||
prog_name, strerror(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cdata;
|
return cdata;
|
||||||
@@ -855,9 +846,7 @@ static int process_tracks(unsigned int cylinders, unsigned int heads,
|
|||||||
} else {
|
} else {
|
||||||
err = dasd_format_disk(filedes, &step);
|
err = dasd_format_disk(filedes, &step);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl call "
|
error("the ioctl call to format tracks failed: %s", strerror(err));
|
||||||
"to format tracks failed. (%s)\n",
|
|
||||||
prog_name, strerror(err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cyl = cur_trk / heads + 1;
|
cyl = cur_trk / heads + 1;
|
||||||
@@ -905,10 +894,8 @@ static void check_disk_format(unsigned int cylinders, unsigned int heads,
|
|||||||
check_params->intensity &= ~DASD_FMT_INT_COMPAT;
|
check_params->intensity &= ~DASD_FMT_INT_COMPAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process_tracks(cylinders, heads, check_params)) {
|
if (process_tracks(cylinders, heads, check_params))
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform a "
|
error("Use --mode=full to perform a clean format.");
|
||||||
"clean format.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Done. Disk is fine.\n");
|
printf("Done. Disk is fine.\n");
|
||||||
}
|
}
|
||||||
@@ -1037,9 +1024,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
*/
|
*/
|
||||||
rc = dasd_get_geo(g.dev_node, &geo);
|
rc = dasd_get_geo(g.dev_node, &geo);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL "
|
error("(write labels) IOCTL HDIO_GETGEO failed: %s", strerror(rc));
|
||||||
"HDIO_GETGEO failed (%s).\n",
|
|
||||||
prog_name, strerror(rc));
|
|
||||||
|
|
||||||
if (g.verbosity > 0)
|
if (g.verbosity > 0)
|
||||||
printf("ok\n");
|
printf("ok\n");
|
||||||
@@ -1067,37 +1052,30 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
|
|
||||||
fd = open(g.dev_node, O_RDWR);
|
fd = open(g.dev_node, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Unable to open device "
|
error("Unable to open device '%s': %s", g.dev_path, strerror(errno));
|
||||||
"'%s' (%s)\n", prog_name, g.dev_path,
|
|
||||||
strerror(errno));
|
|
||||||
|
|
||||||
if (lseek(fd, 0, SEEK_SET) != 0) {
|
if (lseek(fd, 0, SEEK_SET) != 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command 0 failed "
|
error("lseek command 0 failed: %s", strerror(errno));
|
||||||
"(%s)\n", prog_name, strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = write(fd, ipl1_record, ipl1_record_len);
|
rc = write(fd, ipl1_record, ipl1_record_len);
|
||||||
if (rc != ipl1_record_len) {
|
if (rc != ipl1_record_len) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Writing the bootstrap IPL1 "
|
error("Writing the bootstrap IPL1 failed, only wrote %d bytes.", rc);
|
||||||
"failed, only wrote %d bytes.\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
label_position = blksize;
|
label_position = blksize;
|
||||||
rc = lseek(fd, label_position, SEEK_SET);
|
rc = lseek(fd, label_position, SEEK_SET);
|
||||||
if (rc != label_position) {
|
if (rc != label_position) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
|
error("lseek command to %i failed: %s", label_position, strerror(errno));
|
||||||
"(%s).\n", prog_name, label_position,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = write(fd, ipl2_record, ipl2_record_len);
|
rc = write(fd, ipl2_record, ipl2_record_len);
|
||||||
if (rc != ipl2_record_len) {
|
if (rc != ipl2_record_len) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Writing the bootstrap IPL2 "
|
error("Writing the bootstrap IPL2 failed, only wrote %d bytes.", rc);
|
||||||
"failed, only wrote %d bytes.\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write VTOC */
|
/* write VTOC */
|
||||||
@@ -1117,9 +1095,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
rc = lseek(fd, label_position, SEEK_SET);
|
rc = lseek(fd, label_position, SEEK_SET);
|
||||||
if (rc != label_position) {
|
if (rc != label_position) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
|
error("lseek command to %i failed: %s", label_position, strerror(errno));
|
||||||
"(%s).\n", prog_name, label_position,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1141,8 +1117,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
((rc != (sizeof(*vlabel) - sizeof(vlabel->volkey))) &&
|
((rc != (sizeof(*vlabel) - sizeof(vlabel->volkey))) &&
|
||||||
!g.cdl_format)) {
|
!g.cdl_format)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing volume label "
|
error("Error writing volume label (%d).", rc);
|
||||||
"(%d).\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g.verbosity > 0)
|
if (g.verbosity > 0)
|
||||||
@@ -1154,17 +1129,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
rc = lseek(fd, label_position, SEEK_SET);
|
rc = lseek(fd, label_position, SEEK_SET);
|
||||||
if (rc != label_position) {
|
if (rc != label_position) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
|
error("lseek command to %i failed: %s", label_position, strerror(errno));
|
||||||
"(%s).\n", prog_name, label_position,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write VTOC FMT4 DSCB */
|
/* write VTOC FMT4 DSCB */
|
||||||
rc = write(fd, &f4, sizeof(format4_label_t));
|
rc = write(fd, &f4, sizeof(format4_label_t));
|
||||||
if (rc != sizeof(format4_label_t)) {
|
if (rc != sizeof(format4_label_t)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT4 label "
|
error("Error writing FMT4 label (%d).", rc);
|
||||||
"(%d).\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
label_position += blksize;
|
label_position += blksize;
|
||||||
@@ -1172,16 +1144,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
rc = lseek(fd, label_position, SEEK_SET);
|
rc = lseek(fd, label_position, SEEK_SET);
|
||||||
if (rc != label_position) {
|
if (rc != label_position) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek to %i failed (%s).\n",
|
error("lseek to %i failed: %s", label_position, strerror(errno));
|
||||||
prog_name, label_position, strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write VTOC FMT5 DSCB */
|
/* write VTOC FMT5 DSCB */
|
||||||
rc = write(fd, &f5, sizeof(format5_label_t));
|
rc = write(fd, &f5, sizeof(format5_label_t));
|
||||||
if (rc != sizeof(format5_label_t)) {
|
if (rc != sizeof(format5_label_t)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT5 label "
|
error("Error writing FMT5 label (%d).", rc);
|
||||||
"(%d).\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cylinders * heads) > BIG_DISK_SIZE) {
|
if ((cylinders * heads) > BIG_DISK_SIZE) {
|
||||||
@@ -1190,17 +1160,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
|
|||||||
rc = lseek(fd, label_position, SEEK_SET);
|
rc = lseek(fd, label_position, SEEK_SET);
|
||||||
if (rc != label_position) {
|
if (rc != label_position) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek to %i failed "
|
error("lseek to %i failed: %s", label_position, strerror(errno));
|
||||||
"(%s).\n", prog_name, label_position,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write VTOC FMT 7 DSCB (only on big disks) */
|
/* write VTOC FMT 7 DSCB (only on big disks) */
|
||||||
rc = write(fd, &f7, sizeof(format7_label_t));
|
rc = write(fd, &f7, sizeof(format7_label_t));
|
||||||
if (rc != sizeof(format7_label_t)) {
|
if (rc != sizeof(format7_label_t)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT7 "
|
error("Error writing FMT7 label (rc=%d).", rc);
|
||||||
"label (rc=%d).\n", prog_name, rc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1235,8 +1202,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
|
|||||||
|
|
||||||
if (cdata.result) {
|
if (cdata.result) {
|
||||||
evaluate_format_error(&cdata, heads);
|
evaluate_format_error(&cdata, heads);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform a "
|
error("Use --mode=full to perform a clean format.");
|
||||||
"clean format.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Expansion mode active. Searching for starting position...\n");
|
printf("Expansion mode active. Searching for starting position...\n");
|
||||||
@@ -1257,8 +1223,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (first == 2 && cdata.blksize == format_params->blksize)
|
if (first == 2 && cdata.blksize == format_params->blksize)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
error("No unformatted part found, aborting.");
|
||||||
"No unformatted part found, aborting.\n");
|
|
||||||
|
|
||||||
printf("Done. Unformatted part starts at track %d.\n", first);
|
printf("Done. Unformatted part starts at track %d.\n", first);
|
||||||
|
|
||||||
@@ -1280,10 +1245,8 @@ static void dasdfmt_release_space(void)
|
|||||||
|
|
||||||
printf("Releasing space for the entire device...\n");
|
printf("Releasing space for the entire device...\n");
|
||||||
err = dasd_release_space(g.dev_node, &r);
|
err = dasd_release_space(g.dev_node, &r);
|
||||||
if (err) {
|
if (err)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: Could not release space (%s)\n",
|
error("Could not release space: %s", strerror(err));
|
||||||
prog_name, strerror(err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int heads,
|
static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int heads,
|
||||||
@@ -1312,9 +1275,7 @@ static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int head
|
|||||||
|
|
||||||
err = dasd_format_disk(filedes, &temp);
|
err = dasd_format_disk(filedes, &temp);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: (invalidate first track) IOCTL "
|
error("(invalidate first track) IOCTL BIODASDFMT failed: %s", strerror(err));
|
||||||
"BIODASDFMT failed. (%s)\n", prog_name,
|
|
||||||
strerror(err));
|
|
||||||
|
|
||||||
/* except track 0 from standard formatting procss */
|
/* except track 0 from standard formatting procss */
|
||||||
p->start_unit = 1;
|
p->start_unit = 1;
|
||||||
@@ -1331,9 +1292,7 @@ static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int head
|
|||||||
|
|
||||||
err = dasd_format_disk(filedes, &temp);
|
err = dasd_format_disk(filedes, &temp);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: (re-validate first track) IOCTL"
|
error("(re-validate first track) IOCTL BIODASDFMT failed: %s", strerror(err));
|
||||||
" BIODASDFMT failed (%s)\n", prog_name,
|
|
||||||
strerror(err));
|
|
||||||
|
|
||||||
if (g.verbosity > 0)
|
if (g.verbosity > 0)
|
||||||
printf("Re-accessing the device...\n");
|
printf("Re-accessing the device...\n");
|
||||||
@@ -1398,8 +1357,7 @@ static void dasdfmt_quick_format(unsigned int cylinders, unsigned int heads,
|
|||||||
}
|
}
|
||||||
if (cdata.result) {
|
if (cdata.result) {
|
||||||
evaluate_format_error(&cdata, heads);
|
evaluate_format_error(&cdata, heads);
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform "
|
error("Use --mode=full to perform a clean format.");
|
||||||
"a clean format.\n");
|
|
||||||
} else {
|
} else {
|
||||||
printf("Done. Disk seems fine.\n");
|
printf("Done. Disk seems fine.\n");
|
||||||
}
|
}
|
||||||
@@ -1414,8 +1372,7 @@ static void dasdfmt_quick_format(unsigned int cylinders, unsigned int heads,
|
|||||||
/* Now do the actual formatting of our first two tracks */
|
/* Now do the actual formatting of our first two tracks */
|
||||||
err = dasd_format_disk(filedes, p);
|
err = dasd_format_disk(filedes, p);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl to format the device "
|
error("the ioctl to format the device failed: %s", strerror(err));
|
||||||
"failed. (%s)\n", prog_name, strerror(err));
|
|
||||||
|
|
||||||
/* Re-Enable the device so that we can continue working with it */
|
/* Re-Enable the device so that we can continue working with it */
|
||||||
disk_enable();
|
disk_enable();
|
||||||
@@ -1448,11 +1405,11 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
|
|||||||
count = dasd_get_host_access_count(g.dev_node);
|
count = dasd_get_host_access_count(g.dev_node);
|
||||||
if (g.force_host) {
|
if (g.force_host) {
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
printf("\n");
|
||||||
"\n%s: Disk %s is online on OS instances in %d different LPARs.\n"
|
warnx("Disk %s is online on OS instances in %d different LPARs.",
|
||||||
"Note: Your installation might include z/VM systems that are configured to\n"
|
g.dev_path, count);
|
||||||
"automatically vary on disks, regardless of whether they are subsequently used.\n\n",
|
warnx("Note: Your installation might include z/VM systems that are configured to");
|
||||||
prog_name, g.dev_path, count);
|
error("automatically vary on disks, regardless of whether they are subsequently used.\n");
|
||||||
} else if (count < 0) {
|
} else if (count < 0) {
|
||||||
ERRMSG("\nHosts access information not available for disk %s.\n\n",
|
ERRMSG("\nHosts access information not available for disk %s.\n\n",
|
||||||
g.dev_path);
|
g.dev_path);
|
||||||
@@ -1516,10 +1473,9 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
|
|||||||
static void eval_format_mode(void)
|
static void eval_format_mode(void)
|
||||||
{
|
{
|
||||||
if (!g.force && g.mode_specified && g.ese && mode == EXPAND) {
|
if (!g.force && g.mode_specified && g.ese && mode == EXPAND) {
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
warnx("WARNING: The specified device is thin-provisioned");
|
||||||
"WARNING: The specified device is thin-provisioned\n"
|
warnx("Format mode 'expand' is not feasible.");
|
||||||
"Format mode 'expand' is not feasible.\n"
|
error("Use --mode=full or --mode=quick to perform a clean format");
|
||||||
"Use --mode=full or --mode=quick to perform a clean format\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g.mode_specified)
|
if (!g.mode_specified)
|
||||||
@@ -1571,17 +1527,15 @@ int main(int argc, char *argv[])
|
|||||||
if (strcasecmp(optarg, "cdl") == 0) {
|
if (strcasecmp(optarg, "cdl") == 0) {
|
||||||
format_params.intensity |= DASD_FMT_INT_COMPAT;
|
format_params.intensity |= DASD_FMT_INT_COMPAT;
|
||||||
if (g.writenolabel) {
|
if (g.writenolabel) {
|
||||||
printf("WARNING: using the cdl "
|
error("WARNING: using the cdl "
|
||||||
"format without writing a "
|
"format without writing a "
|
||||||
"label doesn't make much "
|
"label doesn't make much "
|
||||||
"sense!\n");
|
"sense!");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(optarg, "ldl") == 0) {
|
} else if (strcasecmp(optarg, "ldl") == 0) {
|
||||||
format_params.intensity &= ~DASD_FMT_INT_COMPAT;
|
format_params.intensity &= ~DASD_FMT_INT_COMPAT;
|
||||||
} else {
|
} else {
|
||||||
printf("%s is not a valid option!\n", optarg);
|
error("%s is not a valid option!", optarg);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
g.layout_specified = 1;
|
g.layout_specified = 1;
|
||||||
break;
|
break;
|
||||||
@@ -1627,10 +1581,9 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
if (format_params.intensity & DASD_FMT_INT_COMPAT) {
|
if (format_params.intensity & DASD_FMT_INT_COMPAT) {
|
||||||
printf("WARNING: using the cdl format "
|
error("WARNING: using the cdl format "
|
||||||
"without writing a label doesn't "
|
"without writing a label doesn't "
|
||||||
"make much sense!\n");
|
"make much sense!");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
g.writenolabel = 1;
|
g.writenolabel = 1;
|
||||||
break;
|
break;
|
||||||
@@ -1656,11 +1609,9 @@ int main(int argc, char *argv[])
|
|||||||
else if (strcasecmp(optarg, "expand") == 0)
|
else if (strcasecmp(optarg, "expand") == 0)
|
||||||
mode = EXPAND;
|
mode = EXPAND;
|
||||||
else
|
else
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
error("The specified mode '%s' is invalid. "
|
||||||
"%s: The specified mode '%s' is "
|
"Consult the man page for more information.",
|
||||||
"invalid. Consult the man page for "
|
optarg);
|
||||||
"more information.\n",
|
|
||||||
prog_name, optarg);
|
|
||||||
g.mode_specified = 1;
|
g.mode_specified = 1;
|
||||||
break;
|
break;
|
||||||
case OPT_NODISCARD:
|
case OPT_NODISCARD:
|
||||||
@@ -1673,8 +1624,7 @@ int main(int argc, char *argv[])
|
|||||||
/* End of options string - start of devices list */
|
/* End of options string - start of devices list */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "Try '%s --help' for more"
|
error("Try '%s --help' for more information.");
|
||||||
" information.\n", prog_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
@@ -1691,9 +1641,7 @@ int main(int argc, char *argv[])
|
|||||||
if (g.reqsize_specified) {
|
if (g.reqsize_specified) {
|
||||||
PARSE_PARAM_INTO(reqsize, reqsize_param_str, 10, "requestsize");
|
PARSE_PARAM_INTO(reqsize, reqsize_param_str, 10, "requestsize");
|
||||||
if (reqsize < 1 || reqsize > 255)
|
if (reqsize < 1 || reqsize > 255)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
error("invalid requestsize %d specified", reqsize);
|
||||||
"invalid requestsize %d specified\n",
|
|
||||||
reqsize);
|
|
||||||
} else {
|
} else {
|
||||||
reqsize = DEFAULT_REQUESTSIZE;
|
reqsize = DEFAULT_REQUESTSIZE;
|
||||||
}
|
}
|
||||||
@@ -1705,9 +1653,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
rc = dasd_get_info(g.dev_node, &g.dasd_info);
|
rc = dasd_get_info(g.dev_node, &g.dasd_info);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl call to retrieve "
|
error("the ioctl call to retrieve device information failed: %s", strerror(rc));
|
||||||
"device information failed (%s).\n",
|
|
||||||
prog_name, strerror(rc));
|
|
||||||
|
|
||||||
g.ese = dasd_sys_ese(g.dev_node);
|
g.ese = dasd_sys_ese(g.dev_node);
|
||||||
eval_format_mode();
|
eval_format_mode();
|
||||||
@@ -1722,28 +1668,21 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g.keep_volser) {
|
if (g.keep_volser) {
|
||||||
if (g.labelspec) {
|
if (g.labelspec)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: The -k and -l options "
|
error("The -k and -l options are mutually exclusive");
|
||||||
"are mutually exclusive\n", prog_name);
|
if (!(format_params.intensity & DASD_FMT_INT_COMPAT))
|
||||||
}
|
error("WARNING: VOLSER cannot be kept when using the ldl format!");
|
||||||
if (!(format_params.intensity & DASD_FMT_INT_COMPAT)) {
|
|
||||||
printf("WARNING: VOLSER cannot be kept "
|
|
||||||
"when using the ldl format!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dasdfmt_get_volser(old_volser) == 0)
|
if (dasdfmt_get_volser(old_volser) == 0)
|
||||||
vtoc_volume_label_set_volser(&vlabel, old_volser);
|
vtoc_volume_label_set_volser(&vlabel, old_volser);
|
||||||
else
|
else
|
||||||
ERRMSG_EXIT(EXIT_FAILURE,
|
error("VOLSER not found on device %s", g.dev_path);
|
||||||
"%s: VOLSER not found on device %s\n",
|
|
||||||
prog_name, g.dev_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_disk();
|
check_disk();
|
||||||
|
|
||||||
if (check_param(str, ERR_LENGTH, &format_params) < 0)
|
if (check_param(str, ERR_LENGTH, &format_params) < 0)
|
||||||
ERRMSG_EXIT(EXIT_MISUSE, "%s: %s\n", prog_name, str);
|
error("%s", str);
|
||||||
|
|
||||||
set_geo(&cylinders, &heads);
|
set_geo(&cylinders, &heads);
|
||||||
set_label(&vlabel, &format_params, cylinders);
|
set_label(&vlabel, &format_params, cylinders);
|
||||||
|
|||||||
Reference in New Issue
Block a user