Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt - add more informational messages



details:   https://anonhg.NetBSD.org/src/rev/fd2918f0f235
branches:  trunk
changeset: 812719:fd2918f0f235
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Dec 29 16:45:04 2015 +0000

description:
- add more informational messages
- handle case where last argument is an option not a device (set -l)

diffstat:

 sbin/gpt/add.c      |   4 +-
 sbin/gpt/biosboot.c |   6 ++--
 sbin/gpt/create.c   |   4 +-
 sbin/gpt/gpt.c      |  77 +++++++++++++++++++++++++++++++++-------------------
 sbin/gpt/gpt.h      |   4 +-
 sbin/gpt/main.c     |  21 +++++++++----
 sbin/gpt/migrate.c  |   4 +-
 sbin/gpt/set.c      |   4 +-
 sbin/gpt/show.c     |   4 +-
 sbin/gpt/unset.c    |   4 +-
 10 files changed, 80 insertions(+), 52 deletions(-)

diffs (truncated from 409 to 300 lines):

diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/add.c
--- a/sbin/gpt/add.c    Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/add.c    Tue Dec 29 16:45:04 2015 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: add.c,v 1.42 2015/12/03 21:46:22 christos Exp $");
+__RCSID("$NetBSD: add.c,v 1.43 2015/12/29 16:45:04 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -167,7 +167,7 @@
        while ((ch = getopt(argc, argv, GPT_AIS "b:l:t:")) != -1) {
                switch(ch) {
                case 'b':
-                       if (gpt_human_get(&block) == -1)
+                       if (gpt_human_get(gpt, &block) == -1)
                                goto usage;
                        break;
                case 'l':
diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c       Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/biosboot.c       Tue Dec 29 16:45:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $ */
+/*     $NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -266,7 +266,7 @@
                                goto usage;
                        break;
                case 'i':
-                       if (gpt_uint_get(&entry) == -1)
+                       if (gpt_uint_get(gpt, &entry) == -1)
                                goto usage;
                        break;
                case 'L':
diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/create.c
--- a/sbin/gpt/create.c Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/create.c Tue Dec 29 16:45:04 2015 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: create.c,v 1.19 2015/12/03 21:30:54 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.20 2015/12/29 16:45:04 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -138,7 +138,7 @@
                        primary_only = 1;
                        break;
                case 'p':
-                       if (gpt_uint_get(&parts) == -1)
+                       if (gpt_uint_get(gpt, &parts) == -1)
                                return -1;
                        break;
                default:
diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/gpt.c    Tue Dec 29 16:45:04 2015 +0000
@@ -35,7 +35,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.65 2015/12/26 13:12:16 jnemeth Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.66 2015/12/29 16:45:04 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -592,34 +592,39 @@
        close(gpt->fd);
 }
 
+static void
+gpt_vwarnx(gpt_t gpt, const char *fmt, va_list ap, const char *e)
+{
+       if (gpt && (gpt->flags & GPT_QUIET))
+               return;
+       fprintf(stderr, "%s: ", getprogname());
+       if (gpt)
+               fprintf(stderr, "%s: ", gpt->device_name);
+       vfprintf(stderr, fmt, ap);
+       if (e)
+               fprintf(stderr, " (%s)\n", e);
+       else
+               fputc('\n', stderr);
+}
+
 void
 gpt_warnx(gpt_t gpt, const char *fmt, ...)
 {
        va_list ap;
 
-       if (gpt->flags & GPT_QUIET)
-               return;
-       fprintf(stderr, "%s: %s: ", getprogname(), gpt->device_name);
        va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
+       gpt_vwarnx(gpt, fmt, ap, NULL);
        va_end(ap);
-       fprintf(stderr, "\n");
 }
 
 void
 gpt_warn(gpt_t gpt, const char *fmt, ...)
 {
        va_list ap;
-       int e = errno;
 
-       if (gpt->flags & GPT_QUIET)
-               return;
-       fprintf(stderr, "%s: %s: ", getprogname(), gpt->device_name);
        va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
+       gpt_vwarnx(gpt, fmt, ap, strerror(errno));
        va_end(ap);
-       fprintf(stderr, " (%s)\n", strerror(e));
-       errno = e;
 }
 
 void
@@ -627,9 +632,10 @@
 {
        va_list ap;
 
-       if (gpt->flags & GPT_QUIET)
+       if (gpt && (gpt->flags & GPT_QUIET))
                return;
-       printf("%s: ", gpt->device_name);
+       if (gpt)
+               printf("%s: ", gpt->device_name);
        va_start(ap, fmt);
        vprintf(fmt, ap);
        va_end(ap);
@@ -922,17 +928,24 @@
 }
 
 int
-gpt_human_get(off_t *human)
+gpt_human_get(gpt_t gpt, off_t *human)
 {
        int64_t human_num;
 
-       if (*human > 0)
-               return -1;
-       if (dehumanize_number(optarg, &human_num) < 0)
+       if (*human > 0) {
+               gpt_warn(gpt, "Already set to %jd new `%s'", (intmax_t)*human,
+                   optarg);
                return -1;
+       }
+       if (dehumanize_number(optarg, &human_num) < 0) {
+               gpt_warn(gpt, "Bad number `%s'", optarg);
+               return -1;
+       }
        *human = human_num;
-       if (*human < 1)
+       if (*human < 1) {
+               gpt_warn(gpt, "Number `%s' < 1", optarg);
                return -1;
+       }
        return 0;
 }
 
@@ -941,16 +954,18 @@
 {
        switch (ch) {
        case 'a':
-               if (find->all > 0)
+               if (find->all > 0) {
+                       gpt_warn(gpt, "-a is already set");
                        return -1;
+               }
                find->all = 1;
                break;
        case 'b':
-               if (gpt_human_get(&find->block) == -1)
+               if (gpt_human_get(gpt, &find->block) == -1)
                        return -1;
                break;
        case 'i':
-               if (gpt_uint_get(&find->entry) == -1)
+               if (gpt_uint_get(gpt, &find->entry) == -1)
                        return -1;
                break;
        case 'L':
@@ -968,6 +983,7 @@
                        return -1;
                break;
        default:
+               gpt_warn(gpt, "Unknown find option `%c'", ch);
                return -1;
        }
        return 0;
@@ -1038,11 +1054,11 @@
 {
        switch (ch) {
        case 'a':
-               if (gpt_human_get(alignment) == -1)
+               if (gpt_human_get(gpt, alignment) == -1)
                        return -1;
                return 0;
        case 'i':
-               if (gpt_uint_get(entry) == -1)
+               if (gpt_uint_get(gpt, entry) == -1)
                        return -1;
                return 0;
        case 's':
@@ -1050,6 +1066,7 @@
                        return -1;
                return 0;
        default:
+               gpt_warn(gpt, "Unknown alignment/index/size option `%c'", ch);
                return -1;
        }
 }
@@ -1167,8 +1184,10 @@
        struct gpt_ent *ent;
        unsigned int i;
        
-       if (entry == 0 || (set == 0 && clr == 0))
+       if (entry == 0 || (set == 0 && clr == 0)) {
+               gpt_warnx(gpt, "Nothing to set");
                return -1;
+       }
 
        if ((hdr = gpt_hdr(gpt)) == NULL)
                return -1;
@@ -1203,14 +1222,16 @@
 }
 
 int
-gpt_uint_get(u_int *entry)
+gpt_uint_get(gpt_t gpt, u_int *entry)
 {
        char *p;
        if (*entry > 0)
                return -1;
        *entry = (u_int)strtoul(optarg, &p, 10);
-       if (*p != 0 || *entry < 1)
+       if (*p != 0 || *entry < 1) {
+               gpt_warn(gpt, "Bad number `%s'", optarg);
                return -1;
+       }
        return 0;
 }
 int
diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h    Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/gpt.h    Tue Dec 29 16:45:04 2015 +0000
@@ -123,8 +123,8 @@
 const char *gpt_attr_list(char *, size_t, uint64_t);
 void   gpt_attr_help(const char *);
 int    gpt_attr_update(gpt_t, u_int, uint64_t, uint64_t);
-int    gpt_uint_get(u_int *);
-int    gpt_human_get(off_t *);
+int    gpt_uint_get(gpt_t, u_int *);
+int    gpt_human_get(gpt_t, off_t *);
 int    gpt_uuid_get(gpt_t, gpt_uuid_t *);
 int    gpt_name_get(gpt_t, void *);
 int    gpt_add_hdr(gpt_t, int, off_t);
diff -r e8e229c9cdd9 -r fd2918f0f235 sbin/gpt/main.c
--- a/sbin/gpt/main.c   Tue Dec 29 16:02:37 2015 +0000
+++ b/sbin/gpt/main.c   Tue Dec 29 16:45:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.6 2015/12/03 02:02:43 christos Exp $        */
+/*     $NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $        */
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.6 2015/12/03 02:02:43 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $");
 #endif
 
 #include <stdio.h>
@@ -165,7 +165,7 @@
                        flags |= GPT_QUIET;
                        break;
                case 's':
-                       if (gpt_uint_get(&secsz) == -1)
+                       if (gpt_uint_get(NULL, &secsz) == -1)
                                usage();
                        break;
                case 'v':



Home | Main Index | Thread Index | Old Index