File s390-tools-sles15-Implement-Y-yast_mode.patch of Package s390-tools.10760

From eabcb26fa4a91d410a6f75a9915a9ebb9f702c6b Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 6 Oct 2017 09:55:40 +0200
Subject: [PATCH] dasdfmt: Implement '-Y/--yast_mode'

Implement an option '-Y' to suppress most output.

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 dasdfmt/dasdfmt.8 |  7 ++++++-
 dasdfmt/dasdfmt.c | 27 ++++++++++++++++++++-------
 dasdfmt/dasdfmt.h |  1 +
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/dasdfmt/dasdfmt.8 b/dasdfmt/dasdfmt.8
index 07c674b..3fd10a2 100644
--- a/dasdfmt/dasdfmt.8
+++ b/dasdfmt/dasdfmt.8
@@ -7,7 +7,7 @@
 dasdfmt \- formatting of DASD (ECKD) disk drives.
 
 .SH SYNOPSIS
-\fBdasdfmt\fR [-h] [-t] [-v] [-y] [-p] [-Q] [-P] [-m \fIstep\fR]
+\fBdasdfmt\fR [-h] [-t] [-v] [-y] [-p] [-Q] [-P] [-Y] [-m \fIstep\fR]
 .br
         [-r \fIcylinder\fR] [-b \fIblksize\fR] [-l \fIvolser\fR] [-d \fIlayout\fR]
 .br
@@ -113,6 +113,11 @@ The value will be at least as big as the -r or --requestsize value.
 .br
 
 .TP
+\fB-Y\fR or \fB--yast_mode\fR
+YaST mode; suppress most output.
+.br
+
+.TP
 \fB-M\fR \fImode\fR or \fB--mode\fR=\fImode\fR
 Specify the \fImode\fR to be used to format the device. Valid modes are:
 .RS
diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c
index 6dd28fa..5b6023a 100644
--- a/dasdfmt/dasdfmt.c
+++ b/dasdfmt/dasdfmt.c
@@ -129,6 +129,10 @@ static struct util_opt opt_vec[] = {
 		.option = { "percentage", no_argument, NULL, 'Q' },
 		.desc = "Show progress in percent",
 	},
+	{
+		.option = { "yast_mode", no_argument, NULL, 'Y' },
+		.desc = "YaST mode",
+	},
 	UTIL_OPT_SECTION("MISC"),
 	{
 		.option = { "check_host_count", no_argument, NULL, 'C' },
@@ -351,7 +355,8 @@ static void evaluate_format_error(dasdfmt_info_t *info, format_check_t *cdata,
 	unsigned int kl = 0;
 	int blksize = cdata->expect.blksize;
 
-	if (info->print_progressbar || info->print_hashmarks)
+	if ((info->print_progressbar || info->print_hashmarks) &&
+	    !info->yast_mode)
 		printf("\n");
 
 	/*
@@ -758,9 +763,9 @@ static void check_hashmarks(dasdfmt_info_t *info)
 			       "using the default.\n");
 			info->hashstep = 10;
 		}
-
-		printf("Printing hashmark every %d cylinders.\n",
-		       info->hashstep);
+		if (!info->yast_mode)
+			printf("Printing hashmark every %d cylinders.\n",
+			       info->hashstep);
 	}
 }
 
@@ -1445,16 +1450,18 @@ static void do_format_dasd(dasdfmt_info_t *info, char *devname,
 			break;
 		}
 
-		printf("Finished formatting the device.\n");
+		if (!info->yast_mode)
+			printf("Finished formatting the device.\n");
 
 		if (!(info->writenolabel || mode == EXPAND))
 			dasdfmt_write_labels(info, vlabel, cylinders, heads);
 
-		printf("Rereading the partition table... ");
+		if (!info->yast_mode)
+			printf("Rereading the partition table... ");
 		if (reread_partition_table()) {
 			ERRMSG("%s: error during rereading the partition "
 			       "table: %s.\n", prog_name, strerror(errno));
-		} else {
+		} else if (!info->yast_mode) {
 			printf("ok\n");
 		}
 	}
@@ -1511,6 +1518,8 @@ void do_dasdfmt(char *dev_filename, dasdfmt_info_t *info,
 		ERRMSG_EXIT(EXIT_MISUSE, "%s: %s\n", prog_name, str);
 
 	set_geo(info, &cylinders, &heads);
+	if (info->yast_mode)
+		printf("%d\n", cylinders);
 	set_label(info, &vlabel, &format_params, cylinders);
 
 	if (info->check)
@@ -1665,6 +1674,10 @@ int main(int argc, char *argv[])
 					    "more information.\n",
 					    prog_name, optarg);
 			break;
+		case 'Y':
+			/* YaST mode */
+			info.yast_mode = 1;
+			break;
 		case 'P':
 			max_parallel = atoi(optarg);
 			break;
diff --git a/dasdfmt/dasdfmt.h b/dasdfmt/dasdfmt.h
index fb6fc34..fe0cc7f 100644
--- a/dasdfmt/dasdfmt.h
+++ b/dasdfmt/dasdfmt.h
@@ -308,6 +308,7 @@ typedef struct dasdfmt_info {
 	int   layout_specified;
 	int   check;
 	int   procnum;
+	int   yast_mode;
 } dasdfmt_info_t;
 
 
-- 
1.7.12.4