Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt Add internal uuid support, since the linux+macos ve...



details:   https://anonhg.NetBSD.org/src/rev/852f29e6615d
branches:  trunk
changeset: 332606:852f29e6615d
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Sep 30 17:59:59 2014 +0000

description:
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.

diffstat:

 sbin/gpt/Makefile     |    4 +-
 sbin/gpt/add.c        |   25 ++---
 sbin/gpt/backup.c     |   26 ++---
 sbin/gpt/biosboot.c   |   12 +-
 sbin/gpt/create.c     |    9 +-
 sbin/gpt/gpt.c        |  112 +------------------------
 sbin/gpt/gpt.h        |   10 +-
 sbin/gpt/gpt_uuid.c   |  214 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sbin/gpt/gpt_uuid.h   |   96 ++++++++++++++++++++++
 sbin/gpt/label.c      |   17 +--
 sbin/gpt/migrate.c    |   83 ++++++------------
 sbin/gpt/remove.c     |   21 ++--
 sbin/gpt/resize.c     |    7 +-
 sbin/gpt/resizedisk.c |    7 +-
 sbin/gpt/restore.c    |   32 ++-----
 sbin/gpt/set.c        |    7 +-
 sbin/gpt/show.c       |  105 +++---------------------
 sbin/gpt/type.c       |   26 ++---
 sbin/gpt/unset.c      |    7 +-
 19 files changed, 441 insertions(+), 379 deletions(-)

diffs (truncated from 1580 to 300 lines):

diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/Makefile Tue Sep 30 17:59:59 2014 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.11 2014/09/29 21:04:34 christos Exp $
+# $NetBSD: Makefile,v 1.12 2014/09/30 17:59:59 christos Exp $
 # $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
 
 PROG=  gpt
 SRCS=  add.c biosboot.c create.c destroy.c gpt.c label.c map.c \
        migrate.c recover.c remove.c resize.c resizedisk.c \
-       set.c show.c type.c unset.c
+       set.c show.c type.c unset.c gpt_uuid.c
 MAN=   gpt.8
 
 .if (${HOSTPROG:U} == "")
diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/add.c
--- a/sbin/gpt/add.c    Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/add.c    Tue Sep 30 17:59:59 2014 +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.26 2014/09/30 02:12:55 christos Exp $");
+__RCSID("$NetBSD: add.c,v 1.27 2014/09/30 17:59:59 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -44,12 +44,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <inttypes.h>
 
 #include "map.h"
 #include "gpt.h"
 
-static uuid_t type;
+static gpt_uuid_t type;
 static off_t alignment, block, sectors, size;
 static unsigned int entry;
 static uint8_t *name;
@@ -71,7 +70,6 @@
 static void
 add(int fd)
 {
-       uuid_t uuid;
        map_t *gpt, *tpg;
        map_t *tbl, *lbt;
        map_t *map;
@@ -114,8 +112,7 @@
                i = entry - 1;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
-               uuid_dec_le(ent->ent_type, &uuid);
-               if (!uuid_is_nil(&uuid, NULL)) {
+               if (!gpt_uuid_is_nil(ent->ent_type)) {
                        warnx("%s: error: entry at index %u is not free",
                            device_name, entry);
                        return;
@@ -125,8 +122,7 @@
                for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
                        ent = (void*)((char*)tbl->map_data + i *
                            le32toh(hdr->hdr_entsz));
-                       uuid_dec_le(ent->ent_type, &uuid);
-                       if (uuid_is_nil(&uuid, NULL))
+                       if (gpt_uuid_is_nil(ent->ent_type))
                                break;
                }
                if (i == le32toh(hdr->hdr_entries)) {
@@ -153,7 +149,7 @@
                }
        }
 
-       uuid_enc_le(ent->ent_type, &type);
+       gpt_uuid_copy(ent->ent_type, type);
        ent->ent_lba_start = htole64(map->map_start);
        ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
        if (name != NULL)
@@ -170,7 +166,7 @@
        hdr = tpg->map_data;
        ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz));
 
-       uuid_enc_le(ent->ent_type, &type);
+       gpt_uuid_copy(ent->ent_type, type);
        ent->ent_lba_start = htole64(map->map_start);
        ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
        if (name != NULL)
@@ -257,9 +253,9 @@
                        sectors = 0;
                        break;
                case 't':
-                       if (!uuid_is_nil(&type, NULL))
+                       if (!gpt_uuid_is_nil(type))
                                usage_add();
-                       if (parse_uuid(optarg, &type) != 0)
+                       if (gpt_uuid_parse(optarg, type) != 0)
                                usage_add();
                        break;
                default:
@@ -271,9 +267,8 @@
                usage_add();
 
        /* Create NetBSD FFS partitions by default. */
-       if (uuid_is_nil(&type, NULL)) {
-               static const uuid_t nb_ffs = GPT_ENT_TYPE_NETBSD_FFS;
-               type = nb_ffs;
+       if (gpt_uuid_is_nil(type)) {
+               gpt_uuid_create(GPT_TYPE_NETBSD_FFS, type, NULL, 0);
        }
 
        while (optind < argc) {
diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/backup.c
--- a/sbin/gpt/backup.c Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/backup.c Tue Sep 30 17:59:59 2014 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: backup.c,v 1.7 2014/09/30 02:12:55 christos Exp $");
+__RCSID("$NetBSD: backup.c,v 1.8 2014/09/30 17:59:59 christos Exp $");
 #endif
 
 #include <sys/bootblock.h>
@@ -70,7 +70,6 @@
 static void
 backup(void)
 {
-       uuid_t u;
        map_t *m;
        struct mbr *mbr;
        struct gpt_ent *ent;
@@ -81,7 +80,7 @@
        prop_data_t propdata;
        prop_number_t propnum;
        prop_string_t propstr;
-       char *propext, *s;
+       char *propext, *s, buf[128];
        bool rc;
 
        props = prop_dictionary_create();
@@ -201,10 +200,9 @@
                        rc = prop_dictionary_set(type_dict, "revision",
                            propnum);
                        PROP_ERR(rc);
-                       uuid_dec_le(hdr->hdr_guid, &u);
-                       uuid_to_string(&u, &s, NULL);
-                       propstr = prop_string_create_cstring(s);
-                       free(s);
+                       gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+                           hdr->hdr_guid);
+                       propstr = prop_string_create_cstring(buf);
                        PROP_ERR(propstr);
                        rc = prop_dictionary_set(type_dict, "guid", propstr);
                        PROP_ERR(rc);
@@ -232,17 +230,15 @@
                                rc = prop_dictionary_set(gpt_dict, "index",
                                    propnum);
                                PROP_ERR(propnum);
-                               uuid_dec_le(ent->ent_type, &u);
-                               uuid_to_string(&u, &s, NULL);
-                               propstr = prop_string_create_cstring(s);
-                               free(s);
+                               gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+                                   ent->ent_type);
+                               propstr = prop_string_create_cstring(buf);
                                PROP_ERR(propstr);
                                rc = prop_dictionary_set(gpt_dict, "type",
                                    propstr);
-                               uuid_dec_le(ent->ent_guid, &u);
-                               uuid_to_string(&u, &s, NULL);
-                               propstr = prop_string_create_cstring(s);
-                               free(s);
+                               gpt_uuid_snprintf(buf, sizeof(buf), "%d",
+                                   ent->ent_guid);
+                               propstr = prop_string_create_cstring(buf);
                                PROP_ERR(propstr);
                                rc = prop_dictionary_set(gpt_dict, "guid",
                                    propstr);
diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c       Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/biosboot.c       Tue Sep 30 17:59:59 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosboot.c,v 1.11 2014/09/29 21:04:34 christos Exp $ */
+/*     $NetBSD: biosboot.c,v 1.12 2014/09/30 17:59:59 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.11 2014/09/29 21:04:34 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.12 2014/09/30 17:59:59 christos Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -49,18 +49,12 @@
 
 #include <err.h>
 #include <fcntl.h>
-#include <inttypes.h>
 #include <paths.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#ifndef NBTOOL_CONFIG_H
-#include <util.h>
-#else
-#include "opendisk.h"
-#endif
 
 #include "map.h"
 #include "gpt.h"
@@ -274,7 +268,9 @@
 int
 cmd_biosboot(int argc, char *argv[])
 {
+#ifdef DIOCGWEDGEINFO
        struct dkwedge_info dkw;
+#endif
        struct stat sb;
        char devpath[MAXPATHLEN];
        char *dev, *p;
diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/create.c
--- a/sbin/gpt/create.c Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/create.c Tue Sep 30 17:59:59 2014 +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.9 2014/09/30 02:12:55 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.10 2014/09/30 17:59:59 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -66,7 +66,6 @@
 static void
 create(int fd)
 {
-       uuid_t uuid;
        off_t blocks, last;
        map_t *gpt, *tpg;
        map_t *tbl, *lbt;
@@ -175,8 +174,7 @@
        hdr->hdr_lba_alt = htole64(last);
        hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
        hdr->hdr_lba_end = htole64(last - blocks - 1LL);
-       uuid_create(&uuid, NULL);
-       uuid_enc_le(hdr->hdr_guid, &uuid);
+       gpt_uuid_copy(hdr->hdr_guid, gpt_uuid_nil);
        hdr->hdr_lba_table = htole64(tbl->map_start);
        hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent));
        if (le32toh(hdr->hdr_entries) > parts)
@@ -185,8 +183,7 @@
 
        ent = tbl->map_data;
        for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
-               uuid_create(&uuid, NULL);
-               uuid_enc_le(ent[i].ent_guid, &uuid);
+               gpt_uuid_copy(ent[i].ent_guid, gpt_uuid_nil);
        }
 
        hdr->hdr_crc_table = htole32(crc32(ent, le32toh(hdr->hdr_entries) *
diff -r 7693f6b10335 -r 852f29e6615d sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Tue Sep 30 17:59:06 2014 +0000
+++ b/sbin/gpt/gpt.c    Tue Sep 30 17:59:59 2014 +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.33 2014/09/30 02:12:55 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.34 2014/09/30 17:59:59 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -56,11 +56,8 @@
 #include <unistd.h>
 #include <ctype.h>
 #ifndef HAVE_NBTOOL_CONFIG_H
-#include <util.h>
 #include <prop/proplib.h>
 #include <sys/drvctlio.h>
-#else
-#include "opendisk.h"
 #endif
 
 #include "map.h"
@@ -248,98 +245,6 @@
        } while (c != 0);
 }
 
-int
-parse_uuid(const char *s, uuid_t *uuid)
-{
-       uint32_t status;
-
-       uuid_from_string(s, uuid, &status);



Home | Main Index | Thread Index | Old Index