summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2013-08-30 16:12:16 +0200
committerKarel Zak2013-09-16 16:47:09 +0200
commita41309c2277aa5cc623288b3ea54516a80f7f6d2 (patch)
tree0c26484e17c70afcc2109c1a3baec9a75074caf2
parentfdisk: use fdisk_info() to print geometry (diff)
downloadkernel-qcow2-util-linux-a41309c2277aa5cc623288b3ea54516a80f7f6d2.tar.gz
kernel-qcow2-util-linux-a41309c2277aa5cc623288b3ea54516a80f7f6d2.tar.xz
kernel-qcow2-util-linux-a41309c2277aa5cc623288b3ea54516a80f7f6d2.zip
fdisk: improve info output
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--fdisks/fdisk-ask.c18
-rw-r--r--fdisks/fdisk.c4
2 files changed, 18 insertions, 4 deletions
diff --git a/fdisks/fdisk-ask.c b/fdisks/fdisk-ask.c
index ad96ab1f2..6c10a48c3 100644
--- a/fdisks/fdisk-ask.c
+++ b/fdisks/fdisk-ask.c
@@ -12,6 +12,8 @@
#include "fdisk.h"
+static unsigned int info_count;
+
int get_user_reply(struct fdisk_context *cxt, const char *prompt,
char *buf, size_t bufsz)
{
@@ -190,6 +192,14 @@ static int ask_offset(struct fdisk_context *cxt,
return -1;
}
+static void fputs_info(const char *msg, FILE *out)
+{
+ if (info_count == 1)
+ fputc('\n', out);
+ fputs(msg, out);
+ fputc('\n', out);
+}
+
int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
void *data __attribute__((__unused__)))
{
@@ -199,14 +209,17 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
assert(cxt);
assert(ask);
+ if (fdisk_ask_get_type(ask) != FDISK_ASKTYPE_INFO)
+ info_count = 0;
+
switch(fdisk_ask_get_type(ask)) {
case FDISK_ASKTYPE_NUMBER:
return ask_number(cxt, ask, buf, sizeof(buf));
case FDISK_ASKTYPE_OFFSET:
return ask_offset(cxt, ask, buf, sizeof(buf));
case FDISK_ASKTYPE_INFO:
- fputs(fdisk_ask_print_get_mesg(ask), stdout);
- fputc('\n', stdout);
+ info_count++;
+ fputs_info(fdisk_ask_print_get_mesg(ask), stdout);
break;
case FDISK_ASKTYPE_WARNX:
fputs(fdisk_ask_print_get_mesg(ask), stderr);
@@ -226,6 +239,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
DBG(ASK, dbgprint("yes-no ask: reply '%s' [rc=%d]", buf, rc));
break;
case FDISK_ASKTYPE_TABLE:
+ fputc('\n', stdout);
tt_print_table(fdisk_ask_get_table(ask));
break;
case FDISK_ASKTYPE_STRING:
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 3fe7d1906..05f4ccb58 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -201,7 +201,7 @@ void list_disk_geometry(struct fdisk_context *cxt)
char *strsz = size_to_human_string(SIZE_SUFFIX_SPACE
| SIZE_SUFFIX_3LETTER, bytes);
- fdisk_info(cxt, _("\nDisk %s: %s, %llu bytes, %llu sectors"),
+ fdisk_info(cxt, _("Disk %s: %s, %llu bytes, %llu sectors"),
cxt->dev_path, strsz, bytes, cxt->total_sectors);
free(strsz);
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
err(EXIT_FAILURE, _("cannot open %s"), argv[optind]);
/* Here starts interactive mode, use fdisk_{warn,info,..} functions */
- fdisk_info(cxt, _("\nWelcome to fdisk (%s).\n\n"
+ fdisk_info(cxt, _("Welcome to fdisk (%s).\n\n"
"Changes will remain in memory only, until you decide to write them.\n"
"Be careful before using the write command.\n"), PACKAGE_STRING);
fflush(stdout);