Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt Clean up gpt(8) a bit more



details:   https://anonhg.NetBSD.org/src/rev/b1986d444a6a
branches:  trunk
changeset: 786069:b1986d444a6a
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Sat Apr 13 18:04:33 2013 +0000

description:
Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.

diffstat:

 sbin/gpt/add.c     |  13 ++++++++-----
 sbin/gpt/create.c  |   6 +++---
 sbin/gpt/gpt.c     |   4 +++-
 sbin/gpt/gpt.h     |   5 +++++
 sbin/gpt/label.c   |   4 ++--
 sbin/gpt/migrate.c |  16 ++++++++--------
 sbin/gpt/remove.c  |   9 +++++----
 sbin/gpt/show.c    |   4 ++--
 8 files changed, 36 insertions(+), 25 deletions(-)

diffs (286 lines):

diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/add.c
--- a/sbin/gpt/add.c    Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/add.c    Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,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.11 2011/08/27 17:38:16 joerg Exp $");
+__RCSID("$NetBSD: add.c,v 1.12 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -65,6 +65,7 @@
 static void
 add(int fd)
 {
+       uuid_t uuid;
        map_t *gpt, *tpg;
        map_t *tbl, *lbt;
        map_t *map;
@@ -105,7 +106,8 @@
                i = entry - 1;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
-               if (!uuid_is_nil((uuid_t *)&ent->ent_type, NULL)) {
+               le_uuid_dec(ent->ent_type, &uuid);
+               if (!uuid_is_nil(&uuid, NULL)) {
                        warnx("%s: error: entry at index %u is not free",
                            device_name, entry);
                        return;
@@ -115,7 +117,8 @@
                for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
                        ent = (void*)((char*)tbl->map_data + i *
                            le32toh(hdr->hdr_entsz));
-                       if (uuid_is_nil((uuid_t *)&ent->ent_type, NULL))
+                       le_uuid_dec(ent->ent_type, &uuid);
+                       if (uuid_is_nil(&uuid, NULL))
                                break;
                }
                if (i == le32toh(hdr->hdr_entries)) {
@@ -131,7 +134,7 @@
                return;
        }
 
-       le_uuid_enc((uuid_t *)&ent->ent_type, &type);
+       le_uuid_enc(ent->ent_type, &type);
        ent->ent_lba_start = htole64(map->map_start);
        ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
 
@@ -146,7 +149,7 @@
        hdr = tpg->map_data;
        ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz));
 
-       le_uuid_enc(&ent->ent_type, &type);
+       le_uuid_enc(ent->ent_type, &type);
        ent->ent_lba_start = htole64(map->map_start);
        ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
 
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/create.c
--- a/sbin/gpt/create.c Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/create.c Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,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.5 2011/08/27 17:38:16 joerg Exp $");
+__RCSID("$NetBSD: create.c,v 1.6 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -171,7 +171,7 @@
        hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
        hdr->hdr_lba_end = htole64(last - blocks - 1LL);
        uuid_create(&uuid, NULL);
-       le_uuid_enc((uuid_t *)&hdr->hdr_uuid, &uuid);
+       le_uuid_enc(hdr->hdr_uuid, &uuid);
        hdr->hdr_lba_table = htole64(tbl->map_start);
        hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent));
        if (le32toh(hdr->hdr_entries) > parts)
@@ -181,7 +181,7 @@
        ent = tbl->map_data;
        for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
                uuid_create(&uuid, NULL);
-               le_uuid_enc((uuid_t *)&ent[i].ent_uuid, &uuid);
+               le_uuid_enc(ent[i].ent_uuid, &uuid);
        }
 
        hdr->hdr_crc_table = htole32(crc32(ent, le32toh(hdr->hdr_entries) *
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/gpt.c    Sat Apr 13 18:04:33 2013 +0000
@@ -31,7 +31,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.18 2013/01/18 17:58:15 jakllsch Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.19 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/param.h>
@@ -241,6 +241,7 @@
        } while (c != 0);
 }
 
+#ifndef __NetBSD__
 void
 le_uuid_dec(void const *buf, uuid_t *uuid)
 {
@@ -273,6 +274,7 @@
                p[10 + i] = uuid->node[i];
 }
 
+#endif
 int
 parse_uuid(const char *s, uuid_t *uuid)
 {
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h    Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/gpt.h    Sat Apr 13 18:04:33 2013 +0000
@@ -47,8 +47,13 @@
 
 #include <uuid.h>
 
+#ifdef __NetBSD__
+#define le_uuid_dec uuid_dec_le
+#define le_uuid_enc uuid_enc_le
+#else
 void   le_uuid_dec(void const *, uuid_t *);
 void   le_uuid_enc(void *, uuid_t const *);
+#endif
 int    parse_uuid(const char *, uuid_t *);
 
 struct mbr_part {
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/label.c
--- a/sbin/gpt/label.c  Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/label.c  Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: label.c,v 1.9 2013/04/13 16:48:03 jakllsch Exp $");
+__RCSID("$NetBSD: label.c,v 1.10 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -113,7 +113,7 @@
                hdr = gpt->map_data;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
-               le_uuid_dec(&ent->ent_type, &uuid);
+               le_uuid_dec(ent->ent_type, &uuid);
                if (!uuid_is_nil(&type, NULL) &&
                    !uuid_equal(&type, &uuid, NULL))
                        continue;
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/migrate.c
--- a/sbin/gpt/migrate.c        Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/migrate.c        Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: migrate.c,v 1.5 2011/08/27 17:38:16 joerg Exp $");
+__RCSID("$NetBSD: migrate.c,v 1.6 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -107,21 +107,21 @@
                        continue;
                case FS_SWAP: {
                        uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP;
-                       le_uuid_enc(&ent->ent_type, &swap);
+                       le_uuid_enc(ent->ent_type, &swap);
                        utf8_to_utf16((const uint8_t *)"FreeBSD swap partition",
                            ent->ent_name, 36);
                        break;
                }
                case FS_BSDFFS: {
                        uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS;
-                       le_uuid_enc(&ent->ent_type, &ufs);
+                       le_uuid_enc(ent->ent_type, &ufs);
                        utf8_to_utf16((const uint8_t *)"FreeBSD UFS partition",
                            ent->ent_name, 36);
                        break;
                }
                case FS_VINUM: {
                        uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
-                       le_uuid_enc(&ent->ent_type, &vinum);
+                       le_uuid_enc(ent->ent_type, &vinum);
                        utf8_to_utf16((const uint8_t *)"FreeBSD vinum partition",
                            ent->ent_name, 36);
                        break;
@@ -234,7 +234,7 @@
        hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
        hdr->hdr_lba_end = htole64(lbt->map_start - 1LL);
        uuid_create(&uuid, NULL);
-       le_uuid_enc(&hdr->hdr_uuid, &uuid);
+       le_uuid_enc(hdr->hdr_uuid, &uuid);
        hdr->hdr_lba_table = htole64(tbl->map_start);
        hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent));
        if (le32toh(hdr->hdr_entries) > parts)
@@ -244,7 +244,7 @@
        ent = tbl->map_data;
        for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
                uuid_create(&uuid, NULL);
-               le_uuid_enc(&ent[i].ent_uuid, &uuid);
+               le_uuid_enc(ent[i].ent_uuid, &uuid);
        }
 
        /* Mirror partitions. */
@@ -260,7 +260,7 @@
                case 165: {     /* FreeBSD */
                        if (slice) {
                                uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
-                               le_uuid_enc(&ent->ent_type, &freebsd);
+                               le_uuid_enc(ent->ent_type, &freebsd);
                                ent->ent_lba_start = htole64((uint64_t)start);
                                ent->ent_lba_end = htole64(start + size - 1LL);
                                utf8_to_utf16((const uint8_t *)"FreeBSD disklabel partition",
@@ -272,7 +272,7 @@
                }
                case 239: {     /* EFI */
                        uuid_t efi_slice = GPT_ENT_TYPE_EFI;
-                       le_uuid_enc(&ent->ent_type, &efi_slice);
+                       le_uuid_enc(ent->ent_type, &efi_slice);
                        ent->ent_lba_start = htole64((uint64_t)start);
                        ent->ent_lba_end = htole64(start + size - 1LL);
                        utf8_to_utf16((const uint8_t *)"EFI system partition",
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/remove.c
--- a/sbin/gpt/remove.c Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/remove.c Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: remove.c,v 1.7 2013/04/13 16:48:03 jakllsch Exp $");
+__RCSID("$NetBSD: remove.c,v 1.8 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -112,13 +112,14 @@
                hdr = gpt->map_data;
                ent = (void*)((char*)tbl->map_data + i *
                    le32toh(hdr->hdr_entsz));
-               le_uuid_dec(&ent->ent_type, &uuid);
+               le_uuid_dec(ent->ent_type, &uuid);
                if (!uuid_is_nil(&type, NULL) &&
                    !uuid_equal(&type, &uuid, NULL))
                        continue;
 
                /* Remove the primary entry by clearing the partition type. */
-               uuid_create_nil((uuid_t *)&ent->ent_type, NULL);
+               uuid_create_nil(&uuid, NULL);
+               le_uuid_enc(ent->ent_type, &uuid);
 
                hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
                    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
@@ -133,7 +134,7 @@
                    le32toh(hdr->hdr_entsz));
 
                /* Remove the secondary entry. */
-               uuid_create_nil((uuid_t *)&ent->ent_type, NULL);
+               le_uuid_enc(ent->ent_type, &uuid);
 
                hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
                    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
diff -r 8f1d0bda17ab -r b1986d444a6a sbin/gpt/show.c
--- a/sbin/gpt/show.c   Sat Apr 13 16:48:03 2013 +0000
+++ b/sbin/gpt/show.c   Sat Apr 13 18:04:33 2013 +0000
@@ -29,7 +29,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: show.c,v 1.8 2013/01/18 17:58:15 jakllsch Exp $");
+__RCSID("$NetBSD: show.c,v 1.9 2013/04/13 18:04:33 jakllsch Exp $");
 #endif
 
 #include <sys/types.h>
@@ -193,7 +193,7 @@
                                printf("- \"%s\"",
                                    utf16_to_utf8(ent->ent_name));
                        } else {
-                               le_uuid_dec(&ent->ent_type, &type);
+                               le_uuid_dec(ent->ent_type, &type);
                                printf("- %s", friendly(&type));
                        }
                        break;



Home | Main Index | Thread Index | Old Index