From owner-svn-src-head@FreeBSD.ORG Mon Dec 14 20:04:06 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D7DC106568B; Mon, 14 Dec 2009 20:04:06 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8C0BF8FC12; Mon, 14 Dec 2009 20:04:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBEK468u036728; Mon, 14 Dec 2009 20:04:06 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBEK462J036724; Mon, 14 Dec 2009 20:04:06 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200912142004.nBEK462J036724@svn.freebsd.org> From: Rui Paulo Date: Mon, 14 Dec 2009 20:04:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200534 - head/sys/geom/part X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2009 20:04:06 -0000 Author: rpaulo Date: Mon Dec 14 20:04:06 2009 New Revision: 200534 URL: http://svn.freebsd.org/changeset/base/200534 Log: Simplify partition type parsing by using a data-oriented model. While there add more Apple and Linux partition types. Modified: head/sys/geom/part/g_part.c head/sys/geom/part/g_part.h head/sys/geom/part/g_part_gpt.c Modified: head/sys/geom/part/g_part.c ============================================================================== --- head/sys/geom/part/g_part.c Mon Dec 14 19:53:57 2009 (r200533) +++ head/sys/geom/part/g_part.c Mon Dec 14 20:04:06 2009 (r200534) @@ -69,7 +69,13 @@ struct g_part_alias_list { const char *lexeme; enum g_part_alias alias; } g_part_alias_list[G_PART_ALIAS_COUNT] = { + { "apple-boot", G_PART_ALIAS_APPLE_BOOT }, { "apple-hfs", G_PART_ALIAS_APPLE_HFS }, + { "apple-label", G_PART_ALIAS_APPLE_LABEL }, + { "apple-raid", G_PART_ALIAS_APPLE_RAID }, + { "apple-raid-offline", G_PART_ALIAS_APPLE_RAID_OFFLINE }, + { "apple-tv-recovery", G_PART_ALIAS_APPLE_TV_RECOVERY }, + { "apple-ufs", G_PART_ALIAS_APPLE_UFS }, { "efi", G_PART_ALIAS_EFI }, { "freebsd", G_PART_ALIAS_FREEBSD }, { "freebsd-boot", G_PART_ALIAS_FREEBSD_BOOT }, @@ -77,6 +83,10 @@ struct g_part_alias_list { { "freebsd-ufs", G_PART_ALIAS_FREEBSD_UFS }, { "freebsd-vinum", G_PART_ALIAS_FREEBSD_VINUM }, { "freebsd-zfs", G_PART_ALIAS_FREEBSD_ZFS }, + { "linux-data", G_PART_ALIAS_LINUX_DATA }, + { "linux-lvm", G_PART_ALIAS_LINUX_LVM }, + { "linux-raid", G_PART_ALIAS_LINUX_RAID }, + { "linux-swap", G_PART_ALIAS_LINUX_SWAP }, { "mbr", G_PART_ALIAS_MBR } }; Modified: head/sys/geom/part/g_part.h ============================================================================== --- head/sys/geom/part/g_part.h Mon Dec 14 19:53:57 2009 (r200533) +++ head/sys/geom/part/g_part.h Mon Dec 14 20:04:06 2009 (r200534) @@ -36,7 +36,13 @@ #define G_PART_PROBE_PRI_HIGH 0 enum g_part_alias { - G_PART_ALIAS_APPLE_HFS, /* An HFS file system entry. */ + G_PART_ALIAS_APPLE_BOOT, /* An Apple boot partition entry. */ + G_PART_ALIAS_APPLE_HFS, /* An HFS+ file system entry. */ + G_PART_ALIAS_APPLE_LABEL, /* An Apple label partition entry. */ + G_PART_ALIAS_APPLE_RAID, /* An Apple RAID partition entry. */ + G_PART_ALIAS_APPLE_RAID_OFFLINE,/* An Apple RAID (offline) part entry.*/ + G_PART_ALIAS_APPLE_TV_RECOVERY, /* An Apple TV recovery part entry. */ + G_PART_ALIAS_APPLE_UFS, /* An Apple UFS partition entry. */ G_PART_ALIAS_EFI, /* A EFI system partition entry. */ G_PART_ALIAS_FREEBSD, /* A BSD labeled partition entry. */ G_PART_ALIAS_FREEBSD_BOOT, /* A FreeBSD boot partition entry. */ @@ -45,6 +51,10 @@ enum g_part_alias { G_PART_ALIAS_FREEBSD_VINUM, /* A Vinum partition entry. */ G_PART_ALIAS_FREEBSD_ZFS, /* A ZFS file system entry. */ G_PART_ALIAS_MBR, /* A MBR (extended) partition entry. */ + G_PART_ALIAS_LINUX_DATA, /* A Linux data partition entry. */ + G_PART_ALIAS_LINUX_LVM, /* A Linux LVM partition entry. */ + G_PART_ALIAS_LINUX_RAID, /* A Linux RAID partition entry. */ + G_PART_ALIAS_LINUX_SWAP, /* A Linux swap partition entry. */ /* Keep the following last */ G_PART_ALIAS_COUNT }; Modified: head/sys/geom/part/g_part_gpt.c ============================================================================== --- head/sys/geom/part/g_part_gpt.c Mon Dec 14 19:53:57 2009 (r200533) +++ head/sys/geom/part/g_part_gpt.c Mon Dec 14 20:04:06 2009 (r200534) @@ -131,7 +131,13 @@ static struct g_part_scheme g_part_gpt_s }; G_PART_SCHEME_DECLARE(g_part_gpt); +static struct uuid gpt_uuid_apple_boot = GPT_ENT_TYPE_APPLE_BOOT; static struct uuid gpt_uuid_apple_hfs = GPT_ENT_TYPE_APPLE_HFS; +static struct uuid gpt_uuid_apple_label = GPT_ENT_TYPE_APPLE_LABEL; +static struct uuid gpt_uuid_apple_raid = GPT_ENT_TYPE_APPLE_RAID; +static struct uuid gpt_uuid_apple_raid_offline = GPT_ENT_TYPE_APPLE_RAID_OFFLINE; +static struct uuid gpt_uuid_apple_tv_recovery = GPT_ENT_TYPE_APPLE_TV_RECOVERY; +static struct uuid gpt_uuid_apple_ufs = GPT_ENT_TYPE_APPLE_UFS; static struct uuid gpt_uuid_efi = GPT_ENT_TYPE_EFI; static struct uuid gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD; static struct uuid gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT; @@ -139,10 +145,39 @@ static struct uuid gpt_uuid_freebsd_swap static struct uuid gpt_uuid_freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS; static struct uuid gpt_uuid_freebsd_vinum = GPT_ENT_TYPE_FREEBSD_VINUM; static struct uuid gpt_uuid_freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS; +static struct uuid gpt_uuid_linux_data = GPT_ENT_TYPE_LINUX_DATA; +static struct uuid gpt_uuid_linux_lvm = GPT_ENT_TYPE_LINUX_LVM; +static struct uuid gpt_uuid_linux_raid = GPT_ENT_TYPE_LINUX_RAID; static struct uuid gpt_uuid_linux_swap = GPT_ENT_TYPE_LINUX_SWAP; static struct uuid gpt_uuid_mbr = GPT_ENT_TYPE_MBR; static struct uuid gpt_uuid_unused = GPT_ENT_TYPE_UNUSED; +static struct g_part_uuid_alias { + struct uuid *uuid; + int alias; +} gpt_uuid_alias_match[] = { + { &gpt_uuid_apple_boot, G_PART_ALIAS_APPLE_BOOT }, + { &gpt_uuid_apple_hfs, G_PART_ALIAS_APPLE_HFS }, + { &gpt_uuid_apple_label, G_PART_ALIAS_APPLE_LABEL }, + { &gpt_uuid_apple_raid, G_PART_ALIAS_APPLE_RAID }, + { &gpt_uuid_apple_raid_offline, G_PART_ALIAS_APPLE_RAID_OFFLINE }, + { &gpt_uuid_apple_tv_recovery, G_PART_ALIAS_APPLE_TV_RECOVERY }, + { &gpt_uuid_apple_ufs, G_PART_ALIAS_APPLE_UFS }, + { &gpt_uuid_efi, G_PART_ALIAS_EFI }, + { &gpt_uuid_freebsd, G_PART_ALIAS_FREEBSD }, + { &gpt_uuid_freebsd_boot, G_PART_ALIAS_FREEBSD_BOOT }, + { &gpt_uuid_freebsd_swap, G_PART_ALIAS_FREEBSD_SWAP }, + { &gpt_uuid_freebsd_ufs, G_PART_ALIAS_FREEBSD_UFS }, + { &gpt_uuid_freebsd_vinum, G_PART_ALIAS_FREEBSD_VINUM }, + { &gpt_uuid_freebsd_zfs, G_PART_ALIAS_FREEBSD_ZFS }, + { &gpt_uuid_linux_data, G_PART_ALIAS_LINUX_DATA }, + { &gpt_uuid_linux_lvm, G_PART_ALIAS_LINUX_LVM }, + { &gpt_uuid_linux_raid, G_PART_ALIAS_LINUX_RAID }, + { &gpt_uuid_linux_swap, G_PART_ALIAS_LINUX_SWAP }, + { &gpt_uuid_mbr, G_PART_ALIAS_MBR }, + { NULL, 0 } +}; + static struct gpt_hdr * gpt_read_hdr(struct g_part_gpt_table *table, struct g_consumer *cp, enum gpt_elt elt) @@ -305,6 +340,7 @@ gpt_parse_type(const char *type, struct struct uuid tmp; const char *alias; int error; + struct g_part_uuid_alias *uap; if (type[0] == '!') { error = parse_uuid(type + 1, &tmp); @@ -315,50 +351,12 @@ gpt_parse_type(const char *type, struct *uuid = tmp; return (0); } - alias = g_part_alias_name(G_PART_ALIAS_EFI); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_efi; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_BOOT); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd_boot; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_SWAP); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd_swap; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_UFS); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd_ufs; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_VINUM); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd_vinum; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_ZFS); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_freebsd_zfs; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_MBR); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_mbr; - return (0); - } - alias = g_part_alias_name(G_PART_ALIAS_APPLE_HFS); - if (!strcasecmp(type, alias)) { - *uuid = gpt_uuid_apple_hfs; - return (0); + for (uap = &gpt_uuid_alias_match[0]; uap->uuid; uap++) { + alias = g_part_alias_name(uap->alias); + if (!strcasecmp(type, alias)) { + uuid = uap->uuid; + return (0); + } } return (EINVAL); } @@ -717,29 +715,16 @@ g_part_gpt_type(struct g_part_table *bas { struct g_part_gpt_entry *entry; struct uuid *type; + struct g_part_uuid_alias *uap; entry = (struct g_part_gpt_entry *)baseentry; type = &entry->ent.ent_type; - if (EQUUID(type, &gpt_uuid_efi)) - return (g_part_alias_name(G_PART_ALIAS_EFI)); - if (EQUUID(type, &gpt_uuid_freebsd)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD)); - if (EQUUID(type, &gpt_uuid_freebsd_boot)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD_BOOT)); - if (EQUUID(type, &gpt_uuid_freebsd_swap)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD_SWAP)); - if (EQUUID(type, &gpt_uuid_freebsd_ufs)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD_UFS)); - if (EQUUID(type, &gpt_uuid_freebsd_vinum)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD_VINUM)); - if (EQUUID(type, &gpt_uuid_freebsd_zfs)) - return (g_part_alias_name(G_PART_ALIAS_FREEBSD_ZFS)); - if (EQUUID(type, &gpt_uuid_mbr)) - return (g_part_alias_name(G_PART_ALIAS_MBR)); - if (EQUUID(type, &gpt_uuid_apple_hfs)) - return (g_part_alias_name(G_PART_ALIAS_APPLE_HFS)); + for (uap = &gpt_uuid_alias_match[0]; uap->uuid; uap++) + if (EQUUID(type, uap->uuid)) + return (g_part_alias_name(uap->alias)); buf[0] = '!'; snprintf_uuid(buf + 1, bufsz - 1, type); + return (buf); }