From 8833b3ec51079efbaf93ae6322c8ada0d9242af2 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 17 Jun 2007 08:15:08 +0000 Subject: [PATCH] Adjust gpt to use the new UUID lookup functions via /etc/[defaults/]uuids. Change the default partition type to the DragonFly Label type and add a shortcut -t name 'dfly' as well. --- sbin/gpt/add.c | 10 +++++++--- sbin/gpt/gpt.8 | 5 +++-- sbin/gpt/gpt.c | 16 +++++++++++++++- sbin/gpt/show.c | 47 ++++++++++++----------------------------------- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/sbin/gpt/add.c b/sbin/gpt/add.c index 75be6a21eb..668e0cf08c 100644 --- a/sbin/gpt/add.c +++ b/sbin/gpt/add.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sbin/gpt/add.c,v 1.15 2006/10/04 18:20:25 marcel Exp $ - * $DragonFly: src/sbin/gpt/add.c,v 1.1 2007/06/16 22:29:27 dillon Exp $ + * $DragonFly: src/sbin/gpt/add.c,v 1.2 2007/06/17 08:15:08 dillon Exp $ */ #include @@ -102,6 +102,7 @@ add(int fd) } } else { /* Find empty slot in GPT table. */ + ent = NULL; for (i = 0; i < le32toh(hdr->hdr_entries); i++) { ent = (void*)((char*)tbl->map_data + i * le32toh(hdr->hdr_entsz)); @@ -197,8 +198,11 @@ cmd_add(int argc, char *argv[]) /* Create UFS partitions by default. */ if (uuid_is_nil(&type, NULL)) { - uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - type = ufs; + uint32_t status; + + uuid_name_lookup(&type, "DragonFly Label", &status); + if (status != uuid_s_ok) + usage_add(); } while (optind < argc) { diff --git a/sbin/gpt/gpt.8 b/sbin/gpt/gpt.8 index fa2499a00c..92c1fafe0d 100644 --- a/sbin/gpt/gpt.8 +++ b/sbin/gpt/gpt.8 @@ -23,7 +23,7 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $ -.\" $DragonFly: src/sbin/gpt/gpt.8,v 1.1 2007/06/16 22:29:27 dillon Exp $ +.\" $DragonFly: src/sbin/gpt/gpt.8,v 1.2 2007/06/17 08:15:08 dillon Exp $ .\" .Dd June 22, 2006 .Os @@ -131,10 +131,11 @@ option allows the user to specify the partition type. The type is given as an UUID, but .Nm accepts -.Cm efi , swap , ufs , hfs , linux +.Cm efi , swap , ufs , hfs , linux , dfly , and .Cm windows as aliases for the most commonly used partition types. +You may also specify any symbolic name in the system uuids file. .\" ==== create ==== .It Nm Ic create Oo Fl fp Oc Ar device ... The diff --git a/sbin/gpt/gpt.c b/sbin/gpt/gpt.c index ca72cd3c21..133a1b2b1f 100644 --- a/sbin/gpt/gpt.c +++ b/sbin/gpt/gpt.c @@ -26,7 +26,7 @@ * CRC32 code derived from work by Gary S. Brown. * * $FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $ - * $DragonFly: src/sbin/gpt/gpt.c,v 1.1 2007/06/16 22:29:27 dillon Exp $ + * $DragonFly: src/sbin/gpt/gpt.c,v 1.2 2007/06/17 08:15:08 dillon Exp $ */ #include @@ -263,12 +263,19 @@ int parse_uuid(const char *s, uuid_t *uuid) { uint32_t status; + uuid_t tmp; uuid_from_string(s, uuid, &status); if (status == uuid_s_ok) return (0); switch (*s) { + case 'd': + if (strcmp(s, "dfly") == 0 || strcmp(s, "dragonfly") == 0) { + s = "DragonFly Label"; + /* fall through to lookup at end */ + } + break; case 'e': if (strcmp(s, "efi") == 0) { uuid_t efi = GPT_ENT_TYPE_EFI; @@ -312,6 +319,13 @@ parse_uuid(const char *s, uuid_t *uuid) } break; } + + uuid_name_lookup(&tmp, s, &status); + if (status == uuid_s_ok) { + *uuid = tmp; + return(0); + } + return (EINVAL); } diff --git a/sbin/gpt/show.c b/sbin/gpt/show.c index 54751f9554..1fd3444ce4 100644 --- a/sbin/gpt/show.c +++ b/sbin/gpt/show.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $ - * $DragonFly: src/sbin/gpt/show.c,v 1.1 2007/06/16 22:29:27 dillon Exp $ + * $DragonFly: src/sbin/gpt/show.c,v 1.2 2007/06/17 08:15:08 dillon Exp $ */ #include @@ -54,46 +54,23 @@ usage_show(void) static const char * friendly(uuid_t *t) { - static uuid_t efi_slice = GPT_ENT_TYPE_EFI; - static uuid_t mslinux = GPT_ENT_TYPE_MS_BASIC_DATA; - static uuid_t freebsd = GPT_ENT_TYPE_FREEBSD; - static uuid_t hfs = GPT_ENT_TYPE_APPLE_HFS; - static uuid_t linuxswap = GPT_ENT_TYPE_LINUX_SWAP; - static uuid_t msr = GPT_ENT_TYPE_MS_RESERVED; - static uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP; - static uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - static uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM; - static char buf[80]; - char *s; + static char *save_name1 /*= NULL*/; + static char *save_name2 /*= NULL*/; if (show_uuid) goto unfriendly; - if (uuid_equal(t, &efi_slice, NULL)) - return ("EFI System"); - if (uuid_equal(t, &swap, NULL)) - return ("FreeBSD swap"); - if (uuid_equal(t, &ufs, NULL)) - return ("FreeBSD UFS/UFS2"); - if (uuid_equal(t, &vinum, NULL)) - return ("FreeBSD vinum"); - - if (uuid_equal(t, &freebsd, NULL)) - return ("FreeBSD legacy"); - if (uuid_equal(t, &mslinux, NULL)) - return ("Linux/Windows"); - if (uuid_equal(t, &linuxswap, NULL)) - return ("Linux swap"); - if (uuid_equal(t, &msr, NULL)) - return ("Windows reserved"); - if (uuid_equal(t, &hfs, NULL)) - return ("Apple HFS"); + uuid_addr_lookup(t, &save_name1, NULL); + if (save_name1) + return (save_name1); unfriendly: - uuid_to_string(t, &s, NULL); - strlcpy(buf, s, sizeof buf); - free(s); - return (buf); + if (save_name2) { + free(save_name2); + save_name2 = NULL; + } + uuid_to_string(t, &save_name2, NULL); + return (save_name2); } static void -- 2.11.4.GIT