SHA256
1
0
forked from pool/s390-tools
s390-tools/s390-tools-sles12sp3-dasdfmt-05-Refactor-do_format_dasd.patch
2017-02-21 11:14:26 +00:00

211 lines
6.8 KiB
Diff

Subject: [PATCH] [FEAT LS1501] dasdfmt: Add new formatting modes
From: Jan Höppner <hoeppner@linux.vnet.ibm.com>
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: Refactor do_format_dasd
In order to allow for new features to be integrated properly in the
existing code, certain parts of do_format_dasd() must be moved to
separate functions. This applies to setting VTOC information and
geometrical information.
Therefore, move the relevant bits to set_geo() and set_label().
Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
---
dasdfmt/dasdfmt.c | 132 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 76 insertions(+), 56 deletions(-)
--- a/dasdfmt/dasdfmt.c
+++ b/dasdfmt/dasdfmt.c
@@ -371,6 +371,73 @@ static int check_param(char *s, size_t b
}
/*
+ * Retrieve disk information and set cylinders and heads accordingly.
+ */
+static void set_geo(dasdfmt_info_t *info, unsigned int *cylinders,
+ unsigned int *heads)
+{
+ struct dasd_eckd_characteristics *characteristics;
+
+ if (info->verbosity > 0)
+ printf("Retrieving disk geometry...\n");
+
+ characteristics = (struct dasd_eckd_characteristics *)
+ &info->dasd_info.characteristics;
+ if (characteristics->no_cyl == LV_COMPAT_CYL &&
+ characteristics->long_no_cyl)
+ *cylinders = characteristics->long_no_cyl;
+ else
+ *cylinders = characteristics->no_cyl;
+ *heads = characteristics->trk_per_cyl;
+}
+
+/*
+ * Set VTOC label information
+ */
+static void set_label(dasdfmt_info_t *info, volume_label_t *vlabel,
+ format_data_t *p, unsigned int cylinders)
+{
+ char inp_buffer[5];
+
+ if (info->writenolabel) {
+ if (cylinders > LV_COMPAT_CYL && !info->withoutprompt) {
+ printf("\n--->> ATTENTION! <<---\n");
+ printf("You specified to write no labels to a"
+ " volume with more then %u cylinders.\n"
+ "Cylinders above this limit will not be"
+ " accessible as a linux partition!\n"
+ "Type \"yes\" to continue, no will leave"
+ " the disk untouched: ", LV_COMPAT_CYL);
+ if (fgets(inp_buffer, sizeof(inp_buffer), stdin) == NULL)
+ return;
+ if (strcasecmp(inp_buffer, "yes") &&
+ strcasecmp(inp_buffer, "yes\n")) {
+ printf("Omitting ioctl call (disk will "
+ "NOT be formatted).\n");
+ return;
+ }
+ }
+ } else {
+ if (!info->labelspec && !info->keep_volser) {
+ char buf[7];
+
+ sprintf(buf, "0X%04x", info->dasd_info.devno);
+ check_volser(buf, info->dasd_info.devno);
+ vtoc_volume_label_set_volser(vlabel, buf);
+ }
+
+ 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 {
+ vtoc_volume_label_set_label(vlabel, "LNX1");
+ }
+ }
+}
+
+/*
* ask the user to specify a blocksize
*/
static format_data_t ask_user_for_blksize(format_data_t params)
@@ -452,7 +519,7 @@ static int dasdfmt_get_volser(dasdfmt_in
ERRMSG_EXIT(EXIT_FAILURE, "%s: Unable to open device %s: %s\n",
prog_name, info->devname, strerror(errno));
- if (ioctl(f, BLKSSZGET, &blksize) != 0)
+ if (ioctl(filedes, BLKSSZGET, &blksize) != 0)
ERRMSG_EXIT(EXIT_FAILURE, "%s: (label pos) IOCTL BLKSSZGET "
"failed (%s).\n", prog_name, strerror(errno));
@@ -794,67 +861,16 @@ static void dasdfmt_prepare_and_format(d
disk_disabled = 0;
}
-static void do_format_dasd(dasdfmt_info_t *info, format_data_t *p,
- volume_label_t *vlabel)
+static void do_format_dasd(dasdfmt_info_t *info, volume_label_t *vlabel,
+ format_data_t *p, unsigned int cylinders,
+ unsigned int heads)
{
char inp_buffer[5];
- struct dasd_eckd_characteristics *characteristics;
- unsigned int cylinders, heads;
int count;
- if (info->verbosity > 0)
- printf("Retrieving disk geometry...\n");
-
- characteristics =
- (struct dasd_eckd_characteristics *)
- &info->dasd_info.characteristics;
- if (characteristics->no_cyl == LV_COMPAT_CYL &&
- characteristics->long_no_cyl)
- cylinders = characteristics->long_no_cyl;
- else
- cylinders = characteristics->no_cyl;
- heads = characteristics->trk_per_cyl;
-
p->start_unit = 0;
p->stop_unit = (cylinders * heads) - 1;
- if (info->writenolabel) {
- if (cylinders > LV_COMPAT_CYL && !info->withoutprompt) {
- printf("\n--->> ATTENTION! <<---\n");
- printf("You specified to write no labels to a"
- " volume with more then %u cylinders.\n"
- "Cylinders above this limit will not be"
- " accessible as a linux partition!\n"
- "Type \"yes\" to continue, no will leave"
- " the disk untouched: ", LV_COMPAT_CYL);
- if (fgets(inp_buffer, sizeof(inp_buffer), stdin) == NULL)
- return;
- if (strcasecmp(inp_buffer, "yes") &&
- strcasecmp(inp_buffer, "yes\n")) {
- printf("Omitting ioctl call (disk will "
- "NOT be formatted).\n");
- return;
- }
- }
- } else {
- if (!info->labelspec && !info->keep_volser) {
- char buf[7];
-
- sprintf(buf, "0X%04x", info->dasd_info.devno);
- check_volser(buf, info->dasd_info.devno);
- vtoc_volume_label_set_volser(vlabel, buf);
- }
-
- 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 {
- vtoc_volume_label_set_label(vlabel, "LNX1");
- }
- }
-
if ((info->verbosity > 0) || !info->withoutprompt || info->testmode)
dasdfmt_print_info(info, vlabel, cylinders, heads, p);
@@ -938,6 +954,7 @@ int main(int argc, char *argv[])
char *hashstep_str = NULL;
int rc, index, i;
+ unsigned int cylinders, heads;
int max_parallel=1;
int running=0;
@@ -1193,7 +1210,10 @@ int main(int argc, char *argv[])
if (check_param(str, ERR_LENGTH, &format_params) < 0)
ERRMSG_EXIT(EXIT_MISUSE, "%s: %s\n", prog_name, str);
- do_format_dasd(&info, &format_params, &vlabel);
+ set_geo(&info, &cylinders, &heads);
+ set_label(&info, &vlabel, &format_params, cylinders);
+ do_format_dasd(&info, &vlabel, &format_params,
+ cylinders, heads);
if (close(filedes) != 0)
ERRMSG("%s: error during close: %s\ncontinuing...\n",