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.
This commit is contained in:
parent
6eac8b28cf
commit
21c34dbb1d
|
@ -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} == "")
|
||||
|
|
|
@ -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 @@ __RCSID("$NetBSD: add.c,v 1.26 2014/09/30 02:12:55 christos Exp $");
|
|||
#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 @@ usage_add(void)
|
|||
static void
|
||||
add(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *map;
|
||||
|
@ -114,8 +112,7 @@ add(int fd)
|
|||
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 @@ add(int fd)
|
|||
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 @@ add(int fd)
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ add(int fd)
|
|||
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 @@ cmd_add(int argc, char *argv[])
|
|||
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 @@ cmd_add(int argc, char *argv[])
|
|||
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) {
|
||||
|
|
|
@ -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 @@ usage_backup(void)
|
|||
static void
|
||||
backup(void)
|
||||
{
|
||||
uuid_t u;
|
||||
map_t *m;
|
||||
struct mbr *mbr;
|
||||
struct gpt_ent *ent;
|
||||
|
@ -81,7 +80,7 @@ backup(void)
|
|||
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 @@ backup(void)
|
|||
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 @@ backup(void)
|
|||
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);
|
||||
|
|
|
@ -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 @@ __RCSID("$NetBSD: biosboot.c,v 1.11 2014/09/29 21:04:34 christos Exp $");
|
|||
|
||||
#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 @@ biosboot(int fd)
|
|||
int
|
||||
cmd_biosboot(int argc, char *argv[])
|
||||
{
|
||||
#ifdef DIOCGWEDGEINFO
|
||||
struct dkwedge_info dkw;
|
||||
#endif
|
||||
struct stat sb;
|
||||
char devpath[MAXPATHLEN];
|
||||
char *dev, *p;
|
||||
|
|
|
@ -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 @@ usage_create(void)
|
|||
static void
|
||||
create(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
off_t blocks, last;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
|
@ -175,8 +174,7 @@ create(int fd)
|
|||
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 @@ create(int fd)
|
|||
|
||||
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) *
|
||||
|
|
112
sbin/gpt/gpt.c
112
sbin/gpt/gpt.c
|
@ -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 @@ __RCSID("$NetBSD: gpt.c,v 1.33 2014/09/30 02:12:55 christos Exp $");
|
|||
#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 @@ utf8_to_utf16(const uint8_t *s8, uint16_t *s16, size_t s16len)
|
|||
} while (c != 0);
|
||||
}
|
||||
|
||||
int
|
||||
parse_uuid(const char *s, uuid_t *uuid)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
uuid_from_string(s, uuid, &status);
|
||||
if (status == uuid_s_ok)
|
||||
return (0);
|
||||
|
||||
switch (*s) {
|
||||
case 'b':
|
||||
if (strcmp(s, "bios") == 0) {
|
||||
static const uuid_t bios = GPT_ENT_TYPE_BIOS;
|
||||
*uuid = bios;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if (strcmp(s, "ccd") == 0) {
|
||||
static const uuid_t ccd = GPT_ENT_TYPE_NETBSD_CCD;
|
||||
*uuid = ccd;
|
||||
return (0);
|
||||
} else if (strcmp(s, "cgd") == 0) {
|
||||
static const uuid_t cgd = GPT_ENT_TYPE_NETBSD_CGD;
|
||||
*uuid = cgd;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
if (strcmp(s, "efi") == 0) {
|
||||
static const uuid_t efi = GPT_ENT_TYPE_EFI;
|
||||
*uuid = efi;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (strcmp(s, "ffs") == 0) {
|
||||
static const uuid_t nb_ffs = GPT_ENT_TYPE_NETBSD_FFS;
|
||||
*uuid = nb_ffs;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
if (strcmp(s, "hfs") == 0) {
|
||||
static const uuid_t hfs = GPT_ENT_TYPE_APPLE_HFS;
|
||||
*uuid = hfs;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (strcmp(s, "lfs") == 0) {
|
||||
static const uuid_t lfs = GPT_ENT_TYPE_NETBSD_LFS;
|
||||
*uuid = lfs;
|
||||
return (0);
|
||||
} else if (strcmp(s, "linux") == 0) {
|
||||
static const uuid_t lnx = GPT_ENT_TYPE_LINUX_DATA;
|
||||
*uuid = lnx;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (strcmp(s, "raid") == 0) {
|
||||
static const uuid_t raid = GPT_ENT_TYPE_NETBSD_RAIDFRAME;
|
||||
*uuid = raid;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (strcmp(s, "swap") == 0) {
|
||||
static const uuid_t sw = GPT_ENT_TYPE_NETBSD_SWAP;
|
||||
*uuid = sw;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (strcmp(s, "ufs") == 0) {
|
||||
static const uuid_t ufs = GPT_ENT_TYPE_NETBSD_FFS;
|
||||
*uuid = ufs;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case 'w':
|
||||
if (strcmp(s, "windows") == 0) {
|
||||
static const uuid_t win = GPT_ENT_TYPE_MS_BASIC_DATA;
|
||||
*uuid = win;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
void*
|
||||
gpt_read(int fd, off_t lba, size_t count)
|
||||
{
|
||||
|
@ -547,11 +452,10 @@ out:
|
|||
int
|
||||
gpt_gpt(int fd, off_t lba, int found)
|
||||
{
|
||||
uuid_t type;
|
||||
off_t size;
|
||||
struct gpt_ent *ent;
|
||||
struct gpt_hdr *hdr;
|
||||
char *p, *s;
|
||||
char *p;
|
||||
map_t *m;
|
||||
size_t blocks, tblsz;
|
||||
unsigned int i;
|
||||
|
@ -616,19 +520,19 @@ gpt_gpt(int fd, off_t lba, int found)
|
|||
|
||||
for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
|
||||
ent = (void*)(p + i * le32toh(hdr->hdr_entsz));
|
||||
if (uuid_is_nil((uuid_t *)&ent->ent_type, NULL))
|
||||
if (gpt_uuid_is_nil(ent->ent_type))
|
||||
continue;
|
||||
|
||||
size = le64toh(ent->ent_lba_end) - le64toh(ent->ent_lba_start) +
|
||||
1LL;
|
||||
if (verbose > 2) {
|
||||
uuid_dec_le(&ent->ent_type, &type);
|
||||
uuid_to_string(&type, &s, NULL);
|
||||
warnx(
|
||||
"%s: GPT partition: type=%s, start=%llu, size=%llu", device_name, s,
|
||||
char buf[128];
|
||||
gpt_uuid_snprintf(buf, sizeof(buf), "%s",
|
||||
ent->ent_type);
|
||||
warnx("%s: GPT partition: type=%s, start=%llu, "
|
||||
"size=%llu", device_name, buf,
|
||||
(long long)le64toh(ent->ent_lba_start),
|
||||
(long long)size);
|
||||
free(s);
|
||||
}
|
||||
m = map_add(le64toh(ent->ent_lba_start), size,
|
||||
MAP_TYPE_GPT_PART, ent);
|
||||
|
|
|
@ -29,16 +29,14 @@
|
|||
#ifndef _GPT_H_
|
||||
#define _GPT_H_
|
||||
|
||||
#include <sys/endian.h>
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
#include <sys/disklabel_gpt.h>
|
||||
#include <util.h>
|
||||
#else
|
||||
#include <nbinclude/sys/disklabel_gpt.h>
|
||||
#include "opendisk.h"
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
int parse_uuid(const char *, uuid_t *);
|
||||
#include "gpt_uuid.h"
|
||||
|
||||
struct mbr_part {
|
||||
uint8_t part_flag; /* bootstrap flags */
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
/* $NetBSD: gpt_uuid.c,v 1.1 2014/09/30 17:59:59 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: gpt_uuid.c,v 1.1 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
||||
#ifndef HAVE_NBTOOLS_CONFIG_H
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
const gpt_uuid_t gpt_uuid_nil;
|
||||
|
||||
struct dce_uuid {
|
||||
uint32_t time_low;
|
||||
uint16_t time_mid;
|
||||
uint16_t time_hi_and_version;
|
||||
uint8_t clock_seq_hi_and_reserved;
|
||||
uint8_t clock_seq_low;
|
||||
uint8_t node[6];
|
||||
};
|
||||
|
||||
static const struct {
|
||||
struct dce_uuid u;
|
||||
const char *n;
|
||||
const char *d;
|
||||
} gpt_nv[] = {
|
||||
{ GPT_ENT_TYPE_APPLE_HFS, "apple", "Apple HFS" },
|
||||
{ GPT_ENT_TYPE_BIOS, "bios", "BIOS Boot" },
|
||||
{ GPT_ENT_TYPE_EFI, "efi", "EFI System" },
|
||||
{ GPT_ENT_TYPE_FREEBSD, "fbsd-legacy", "FreeBSD legacy" },
|
||||
{ GPT_ENT_TYPE_FREEBSD_SWAP, "fbsd-swap", "FreeBSD swap" },
|
||||
{ GPT_ENT_TYPE_FREEBSD_UFS, "fbsd-ufs", "FreeBSD UFS/UFS2" },
|
||||
{ GPT_ENT_TYPE_FREEBSD_VINUM, "fbsd-vinum", "FreeBSD vinum" },
|
||||
{ GPT_ENT_TYPE_FREEBSD_ZFS, "fbsd-zfs", "FreeBSD ZFS" },
|
||||
{ GPT_ENT_TYPE_LINUX_DATA, "linux-data", "Linux data" },
|
||||
{ GPT_ENT_TYPE_LINUX_SWAP, "linux-swap", "Linux swap" },
|
||||
{ GPT_ENT_TYPE_MS_BASIC_DATA, "windows", "Windows basic data" },
|
||||
{ GPT_ENT_TYPE_MS_RESERVED, "windows-reserved", "Windows reserved" },
|
||||
{ GPT_ENT_TYPE_NETBSD_CCD, "ccd", "NetBSD ccd component" },
|
||||
{ GPT_ENT_TYPE_NETBSD_CGD, "cgd", "NetBSD Cryptographic Disk" },
|
||||
{ GPT_ENT_TYPE_NETBSD_FFS, "ffs", "NetBSD FFSv1/FFSv2" },
|
||||
{ GPT_ENT_TYPE_NETBSD_LFS, "lfs", "NetBSD LFS" },
|
||||
{ GPT_ENT_TYPE_NETBSD_RAIDFRAME, "raid",
|
||||
"NetBSD RAIDFrame component" },
|
||||
{ GPT_ENT_TYPE_NETBSD_SWAP, "swap", "NetBSD swap" },
|
||||
};
|
||||
|
||||
static void
|
||||
gpt_uuid_to_dce(const gpt_uuid_t buf, struct dce_uuid *uuid)
|
||||
{
|
||||
const uint8_t *p = buf;
|
||||
size_t i;
|
||||
|
||||
uuid->time_low = le32dec(p);
|
||||
uuid->time_mid = le16dec(p + 4);
|
||||
uuid->time_hi_and_version = le16dec(p + 6);
|
||||
uuid->clock_seq_hi_and_reserved = p[8];
|
||||
uuid->clock_seq_low = p[9];
|
||||
for (i = 0; i < sizeof(uuid->node); i++)
|
||||
uuid->node[i] = p[10 + i];
|
||||
}
|
||||
|
||||
static void
|
||||
gpt_dce_to_uuid(const struct dce_uuid *uuid, uint8_t *buf)
|
||||
{
|
||||
uint8_t *p = buf;
|
||||
size_t i;
|
||||
|
||||
le32enc(p, uuid->time_low);
|
||||
le16enc(p + 4, uuid->time_mid);
|
||||
le16enc(p + 6, uuid->time_hi_and_version);
|
||||
p[8] = uuid->clock_seq_hi_and_reserved;
|
||||
p[9] = uuid->clock_seq_low;
|
||||
for (i = 0; i < sizeof(uuid->node); i++)
|
||||
p[10 + i] = uuid->node[i];
|
||||
}
|
||||
|
||||
static int
|
||||
gpt_uuid_numeric(char *buf, size_t bufsiz, const struct dce_uuid *u)
|
||||
{
|
||||
return snprintf(buf, bufsiz,
|
||||
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
u->time_low, u->time_mid, u->time_hi_and_version,
|
||||
u->clock_seq_hi_and_reserved, u->clock_seq_low, u->node[0],
|
||||
u->node[1], u->node[2], u->node[3], u->node[4], u->node[5]);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
gpt_uuid_symbolic(char *buf, size_t bufsiz, const struct dce_uuid *u)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < __arraycount(gpt_nv); i++)
|
||||
if (memcmp(&gpt_nv[i].u, u, sizeof(*u)) == 0)
|
||||
return strlcpy(buf, gpt_nv[i].n, bufsiz);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
gpt_uuid_snprintf(char *buf, size_t bufsiz, const char *fmt,
|
||||
const gpt_uuid_t uu)
|
||||
{
|
||||
struct dce_uuid u;
|
||||
gpt_uuid_to_dce(uu, &u);
|
||||
|
||||
if (fmt[1] == 's') {
|
||||
int r;
|
||||
if ((r = gpt_uuid_symbolic(buf, bufsiz, &u)) != -1)
|
||||
return r;
|
||||
}
|
||||
return gpt_uuid_numeric(buf, bufsiz, &u);
|
||||
}
|
||||
|
||||
static int
|
||||
gpt_uuid_parse_numeric(const char *s, struct dce_uuid *u)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (s == NULL || *s == '\0') {
|
||||
memset(u, 0, sizeof(*u));
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = sscanf(s,
|
||||
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
&u->time_low, &u->time_mid, &u->time_hi_and_version,
|
||||
&u->clock_seq_hi_and_reserved, &u->clock_seq_low, &u->node[0],
|
||||
&u->node[1], &u->node[2], &u->node[3], &u->node[4], &u->node[5]);
|
||||
|
||||
/* Make sure we have all conversions. */
|
||||
if (n != 11)
|
||||
return -1;
|
||||
|
||||
/* We have a successful scan. Check semantics... */
|
||||
n = u->clock_seq_hi_and_reserved;
|
||||
if ((n & 0x80) != 0x00 && /* variant 0? */
|
||||
(n & 0xc0) != 0x80 && /* variant 1? */
|
||||
(n & 0xe0) != 0xc0) /* variant 2? */
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
gpt_uuid_parse_symbolic(const char *s, struct dce_uuid *u)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < __arraycount(gpt_nv); i++)
|
||||
if (strcmp(gpt_nv[i].n, s) == 0) {
|
||||
*u = gpt_nv[i].u;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
gpt_uuid_parse(const char *s, gpt_uuid_t uuid)
|
||||
{
|
||||
struct dce_uuid u;
|
||||
|
||||
if (gpt_uuid_parse_numeric(s, &u) != -1)
|
||||
return 0;
|
||||
|
||||
if (gpt_uuid_parse_symbolic(s, &u) == -1)
|
||||
return -1;
|
||||
|
||||
gpt_dce_to_uuid(&u, uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
gpt_uuid_create(gpt_type_t t, gpt_uuid_t u, uint16_t *b, size_t s)
|
||||
{
|
||||
gpt_dce_to_uuid(&gpt_nv[t].u, u);
|
||||
if (b)
|
||||
utf8_to_utf16((const uint8_t *)gpt_nv[t].d, b, s / sizeof(*b));
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _GPT_UUID_H
|
||||
#define _GPT_UUID_H
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
#include <sys/disklabel_gpt.h>
|
||||
#else
|
||||
#include <nbinclude/sys/disklabel_gpt.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We define our own uuid type so that we don't have to mess around
|
||||
* with different uuid implementation (linux+macosx which use an
|
||||
* array, and {Free,Net}BSD who use a struct. We just need minimal
|
||||
* support anyway
|
||||
*/
|
||||
|
||||
// Must match the array in gpt_uuid.c
|
||||
typedef enum {
|
||||
GPT_TYPE_APPLE_HFS = 0,
|
||||
GPT_TYPE_BIOS,
|
||||
GPT_TYPE_EFI,
|
||||
GPT_TYPE_FREEBSD,
|
||||
GPT_TYPE_FREEBSD_SWAP,
|
||||
GPT_TYPE_FREEBSD_UFS,
|
||||
GPT_TYPE_FREEBSD_VINUM,
|
||||
GPT_TYPE_FREEBSD_ZFS,
|
||||
GPT_TYPE_LINUX_DATA,
|
||||
GPT_TYPE_LINUX_SWAP,
|
||||
GPT_TYPE_MS_BASIC_DATA,
|
||||
GPT_TYPE_MS_RESERVED,
|
||||
GPT_TYPE_NETBSD_CCD,
|
||||
GPT_TYPE_NETBSD_CGD,
|
||||
GPT_TYPE_NETBSD_FFS,
|
||||
GPT_TYPE_NETBSD_LFS,
|
||||
GPT_TYPE_NETBSD_RAIDFRAME,
|
||||
GPT_TYPE_NETBSD_SWAP
|
||||
} gpt_type_t;
|
||||
|
||||
typedef uint8_t gpt_uuid_t[16];
|
||||
extern const gpt_uuid_t gpt_uuid_nil;
|
||||
|
||||
__BEGIN_DECLS
|
||||
static inline int
|
||||
gpt_uuid_is_nil(const gpt_uuid_t u) {
|
||||
return memcmp(u, gpt_uuid_nil, sizeof(gpt_uuid_t)) == 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
gpt_uuid_equal(const gpt_uuid_t u1, const gpt_uuid_t u2) {
|
||||
return memcmp(u1, u2, sizeof(gpt_uuid_t)) == 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
gpt_uuid_copy(gpt_uuid_t u1, const gpt_uuid_t u2) {
|
||||
memcpy(u1, u2, sizeof(gpt_uuid_t));
|
||||
}
|
||||
|
||||
int gpt_uuid_snprintf(char *, size_t, const char *, const gpt_uuid_t);
|
||||
|
||||
void gpt_uuid_create(gpt_type_t, gpt_uuid_t, uint16_t *, size_t);
|
||||
|
||||
int gpt_uuid_parse(const char *, gpt_uuid_t);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _GPT_UUID_T */
|
|
@ -33,7 +33,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.17 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: label.c,v 1.18 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -47,9 +47,10 @@ __RCSID("$NetBSD: label.c,v 1.17 2014/09/30 02:12:55 christos Exp $");
|
|||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
#include "gpt_uuid.h"
|
||||
|
||||
static int all;
|
||||
static uuid_t type;
|
||||
static gpt_uuid_t type;
|
||||
static off_t block, size;
|
||||
static unsigned int entry;
|
||||
static uint8_t *name, *xlabel;
|
||||
|
@ -73,7 +74,6 @@ usage_label(void)
|
|||
static void
|
||||
label(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *m;
|
||||
|
@ -124,9 +124,8 @@ label(int fd)
|
|||
(char *)utf16_to_utf8(ent->ent_name)) != 0)
|
||||
continue;
|
||||
|
||||
uuid_dec_le(ent->ent_type, &uuid);
|
||||
if (!uuid_is_nil(&type, NULL) &&
|
||||
!uuid_equal(&type, &uuid, NULL))
|
||||
if (!gpt_uuid_is_nil(type) &&
|
||||
!gpt_uuid_equal(type, ent->ent_type))
|
||||
continue;
|
||||
|
||||
/* Label the primary entry. */
|
||||
|
@ -241,9 +240,9 @@ cmd_label(int argc, char *argv[])
|
|||
usage_label();
|
||||
break;
|
||||
case 't':
|
||||
if (!uuid_is_nil(&type, NULL))
|
||||
if (!gpt_uuid_is_nil(type))
|
||||
usage_label();
|
||||
if (parse_uuid(optarg, &type) != 0)
|
||||
if (gpt_uuid_parse(optarg, type) != 0)
|
||||
usage_label();
|
||||
break;
|
||||
default:
|
||||
|
@ -253,7 +252,7 @@ cmd_label(int argc, char *argv[])
|
|||
|
||||
if (!all ^
|
||||
(block > 0 || entry > 0 || xlabel != NULL || size > 0 ||
|
||||
!uuid_is_nil(&type, NULL)))
|
||||
!gpt_uuid_is_nil(type)))
|
||||
usage_label();
|
||||
|
||||
if (name == NULL || argc == optind)
|
||||
|
|
|
@ -33,7 +33,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.18 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: migrate.c,v 1.19 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -125,31 +125,23 @@ migrate_disklabel(int fd, off_t start, struct gpt_ent *ent)
|
|||
case FS_UNUSED:
|
||||
continue;
|
||||
case FS_SWAP: {
|
||||
static const uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP;
|
||||
uuid_enc_le(ent->ent_type, &swap);
|
||||
utf8_to_utf16((const uint8_t *)"FreeBSD swap partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_FREEBSD_SWAP, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_BSDFFS: {
|
||||
static const uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS;
|
||||
uuid_enc_le(ent->ent_type, &ufs);
|
||||
utf8_to_utf16((const uint8_t *)"FreeBSD UFS partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_FREEBSD_UFS, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FREEBSD_FS_VINUM: {
|
||||
static const uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
|
||||
uuid_enc_le(ent->ent_type, &vinum);
|
||||
utf8_to_utf16((const uint8_t *)"FreeBSD vinum partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_FREEBSD_VINUM, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FREEBSD_FS_ZFS: {
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_FREEBSD_ZFS;
|
||||
uuid_enc_le(ent->ent_type, &zfs);
|
||||
utf8_to_utf16((const uint8_t *)"FreeBSD ZFS partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_FREEBSD_ZFS, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -207,45 +199,33 @@ migrate_netbsd_disklabel(int fd, off_t start, struct gpt_ent *ent)
|
|||
case FS_UNUSED:
|
||||
continue;
|
||||
case FS_SWAP: {
|
||||
static const uuid_t swap = GPT_ENT_TYPE_NETBSD_SWAP;
|
||||
uuid_enc_le(ent->ent_type, &swap);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD swap partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_SWAP, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_BSDFFS: {
|
||||
static const uuid_t ufs = GPT_ENT_TYPE_NETBSD_FFS;
|
||||
uuid_enc_le(ent->ent_type, &ufs);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD FFS partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_FFS, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_BSDLFS: {
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_NETBSD_LFS;
|
||||
uuid_enc_le(ent->ent_type, &zfs);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD LFS partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_LFS, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_RAID: {
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_NETBSD_RAIDFRAME;
|
||||
uuid_enc_le(ent->ent_type, &zfs);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD RAIDframe partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_RAIDFRAME, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_CCD: {
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_NETBSD_CCD;
|
||||
uuid_enc_le(ent->ent_type, &zfs);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD CCD partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_CCD, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
case FS_CGD: {
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_NETBSD_CGD;
|
||||
uuid_enc_le(ent->ent_type, &zfs);
|
||||
utf8_to_utf16((const uint8_t *)"NetBSD CGD partition",
|
||||
ent->ent_name, 36);
|
||||
gpt_uuid_create(GPT_TYPE_NETBSD_CGD, ent->ent_type,
|
||||
ent->ent_name, sizeof(ent->ent_name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -270,7 +250,6 @@ migrate_netbsd_disklabel(int fd, off_t start, struct gpt_ent *ent)
|
|||
static void
|
||||
migrate(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
off_t blocks, last;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
|
@ -356,8 +335,7 @@ migrate(int fd)
|
|||
hdr->hdr_lba_alt = htole64(tpg->map_start);
|
||||
hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
|
||||
hdr->hdr_lba_end = htole64(lbt->map_start - 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)
|
||||
|
@ -366,8 +344,7 @@ migrate(int fd)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
/* Mirror partitions. */
|
||||
|
@ -382,12 +359,11 @@ migrate(int fd)
|
|||
continue;
|
||||
case MBR_PTYPE_386BSD: { /* FreeBSD */
|
||||
if (slice) {
|
||||
static const uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
|
||||
uuid_enc_le(ent->ent_type, &freebsd);
|
||||
gpt_uuid_create(GPT_TYPE_FREEBSD,
|
||||
ent->ent_type, ent->ent_name,
|
||||
sizeof(ent->ent_name));
|
||||
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",
|
||||
ent->ent_name, 36);
|
||||
ent++;
|
||||
} else
|
||||
ent = migrate_disklabel(fd, start, ent);
|
||||
|
@ -397,12 +373,11 @@ migrate(int fd)
|
|||
ent = migrate_netbsd_disklabel(fd, start, ent);
|
||||
break;
|
||||
case MBR_PTYPE_EFI: {
|
||||
static const uuid_t efi_slice = GPT_ENT_TYPE_EFI;
|
||||
uuid_enc_le(ent->ent_type, &efi_slice);
|
||||
gpt_uuid_create(GPT_TYPE_EFI,
|
||||
ent->ent_type, ent->ent_name,
|
||||
sizeof(ent->ent_name));
|
||||
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",
|
||||
ent->ent_name, 36);
|
||||
ent++;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,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.15 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: remove.c,v 1.16 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -49,7 +49,7 @@ __RCSID("$NetBSD: remove.c,v 1.15 2014/09/30 02:12:55 christos Exp $");
|
|||
#include "gpt.h"
|
||||
|
||||
static int all;
|
||||
static uuid_t type;
|
||||
static gpt_uuid_t type;
|
||||
static off_t block, size;
|
||||
static unsigned int entry;
|
||||
static uint8_t *label;
|
||||
|
@ -72,7 +72,6 @@ usage_remove(void)
|
|||
static void
|
||||
rem(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *m;
|
||||
|
@ -123,14 +122,12 @@ rem(int fd)
|
|||
(char *)utf16_to_utf8(ent->ent_name)) != 0)
|
||||
continue;
|
||||
|
||||
uuid_dec_le(ent->ent_type, &uuid);
|
||||
if (!uuid_is_nil(&type, NULL) &&
|
||||
!uuid_equal(&type, &uuid, NULL))
|
||||
if (!gpt_uuid_is_nil(type) &&
|
||||
!gpt_uuid_equal(type, ent->ent_type))
|
||||
continue;
|
||||
|
||||
/* Remove the primary entry by clearing the partition type. */
|
||||
uuid_create_nil(&uuid, NULL);
|
||||
uuid_enc_le(ent->ent_type, &uuid);
|
||||
gpt_uuid_copy(ent->ent_type, gpt_uuid_nil);
|
||||
|
||||
hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
|
||||
le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
|
||||
|
@ -145,7 +142,7 @@ rem(int fd)
|
|||
le32toh(hdr->hdr_entsz));
|
||||
|
||||
/* Remove the secondary entry. */
|
||||
uuid_enc_le(ent->ent_type, &uuid);
|
||||
gpt_uuid_copy(ent->ent_type, gpt_uuid_nil);
|
||||
|
||||
hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
|
||||
le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
|
||||
|
@ -203,9 +200,9 @@ cmd_remove(int argc, char *argv[])
|
|||
usage_remove();
|
||||
break;
|
||||
case 't':
|
||||
if (!uuid_is_nil(&type, NULL))
|
||||
if (!gpt_uuid_is_nil(type))
|
||||
usage_remove();
|
||||
if (parse_uuid(optarg, &type) != 0)
|
||||
if (gpt_uuid_parse(optarg, type) != 0)
|
||||
usage_remove();
|
||||
break;
|
||||
default:
|
||||
|
@ -215,7 +212,7 @@ cmd_remove(int argc, char *argv[])
|
|||
|
||||
if (!all ^
|
||||
(block > 0 || entry > 0 || label != NULL || size > 0 ||
|
||||
!uuid_is_nil(&type, NULL)))
|
||||
!gpt_uuid_is_nil(type)))
|
||||
usage_remove();
|
||||
|
||||
if (argc == optind)
|
||||
|
|
|
@ -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: resize.c,v 1.10 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: resize.c,v 1.11 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -44,7 +44,6 @@ __RCSID("$NetBSD: resize.c,v 1.10 2014/09/30 02:12:55 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
@ -66,7 +65,6 @@ usage_resize(void)
|
|||
static void
|
||||
resize(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *map;
|
||||
|
@ -108,8 +106,7 @@ resize(int fd)
|
|||
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 unused",
|
||||
device_name, entry);
|
||||
return;
|
||||
|
|
|
@ -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: resizedisk.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: resizedisk.c,v 1.5 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/bootblock.h>
|
||||
|
@ -45,7 +45,6 @@ __RCSID("$NetBSD: resizedisk.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
@ -77,7 +76,6 @@ usage_resizedisk(void)
|
|||
static void
|
||||
resizedisk(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *mbrmap;
|
||||
|
@ -139,8 +137,7 @@ resizedisk(int fd)
|
|||
for (ent = tbl->map_data; ent <
|
||||
(struct gpt_ent *)((char *)tbl->map_data +
|
||||
le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)); ent++) {
|
||||
uuid_dec_le(ent->ent_type, &uuid);
|
||||
if (!uuid_is_nil(&uuid, NULL) &&
|
||||
if (!gpt_uuid_is_nil(ent->ent_type) &&
|
||||
(le64toh(ent->ent_lba_end) > lastdata)) {
|
||||
lastdata = le64toh(ent->ent_lba_end);
|
||||
}
|
||||
|
|
|
@ -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: restore.c,v 1.5 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: restore.c,v 1.6 2014/09/30 17:59:59 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -72,7 +72,7 @@ usage_restore(void)
|
|||
static void
|
||||
restore(int fd)
|
||||
{
|
||||
uuid_t gpt_guid, uuid;
|
||||
gpt_uuid_t uuid;
|
||||
off_t firstdata, last, lastdata, gpe_start, gpe_end;
|
||||
map_t *map;
|
||||
struct mbr *mbr;
|
||||
|
@ -85,10 +85,9 @@ restore(int fd)
|
|||
prop_array_t mbr_array, gpt_array;
|
||||
prop_number_t propnum;
|
||||
prop_string_t propstr;
|
||||
int entries, gpt_size, rc;
|
||||
int entries, gpt_size;
|
||||
const char *s;
|
||||
void *secbuf;
|
||||
uint32_t status;
|
||||
|
||||
last = mediasz / secsz - 1LL;
|
||||
|
||||
|
@ -146,13 +145,10 @@ restore(int fd)
|
|||
propstr = prop_dictionary_get(gpt_dict, "guid");
|
||||
PROP_ERR(propstr);
|
||||
s = prop_string_cstring_nocopy(propstr);
|
||||
uuid_from_string(s, &uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
if (gpt_uuid_parse(s, uuid) != 0) {
|
||||
warnx("%s: not able to convert to an UUID\n", s);
|
||||
return;
|
||||
}
|
||||
uuid_enc_le(&gpt_guid, &uuid);
|
||||
|
||||
firstdata = gpt_size + 2; /* PMBR and GPT header */
|
||||
lastdata = last - gpt_size - 1; /* alt. GPT table and header */
|
||||
|
||||
|
@ -166,17 +162,11 @@ restore(int fd)
|
|||
propstr = prop_dictionary_get(gpt_dict, "type");
|
||||
PROP_ERR(propstr);
|
||||
s = prop_string_cstring_nocopy(propstr);
|
||||
uuid_from_string(s, &uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
if (gpt_uuid_parse(s, uuid) != 0) {
|
||||
warnx("%s: not able to convert to an UUID\n", s);
|
||||
return;
|
||||
}
|
||||
rc = uuid_is_nil(&uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
warnx("%s: not able to convert to an UUID\n", s);
|
||||
return;
|
||||
}
|
||||
if (rc == 1)
|
||||
if (gpt_uuid_is_nil(uuid))
|
||||
continue;
|
||||
propnum = prop_dictionary_get(gpt_dict, "start");
|
||||
PROP_ERR(propnum);
|
||||
|
@ -310,21 +300,17 @@ restore(int fd)
|
|||
propstr = prop_dictionary_get(gpt_dict, "type");
|
||||
PROP_ERR(propstr);
|
||||
s = prop_string_cstring_nocopy(propstr);
|
||||
uuid_from_string(s, &uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
if (gpt_uuid_parse(s, ent.ent_type) != 0) {
|
||||
warnx("%s: not able to convert to an UUID\n", s);
|
||||
return;
|
||||
}
|
||||
uuid_enc_le(&ent.ent_type, &uuid);
|
||||
propstr = prop_dictionary_get(gpt_dict, "guid");
|
||||
PROP_ERR(propstr);
|
||||
s = prop_string_cstring_nocopy(propstr);
|
||||
uuid_from_string(s, &uuid, &status);
|
||||
if (status != uuid_s_ok) {
|
||||
if (gpt_uuid_parse(s, ent.ent_guid) != 0) {
|
||||
warnx("%s: not able to convert to an UUID\n", s);
|
||||
return;
|
||||
}
|
||||
uuid_enc_le(&ent.ent_guid, &uuid);
|
||||
propnum = prop_dictionary_get(gpt_dict, "start");
|
||||
PROP_ERR(propnum);
|
||||
ent.ent_lba_start =
|
||||
|
@ -369,7 +355,7 @@ restore(int fd)
|
|||
hdr->hdr_lba_alt = htole64(last);
|
||||
hdr->hdr_lba_start = htole64(firstdata);
|
||||
hdr->hdr_lba_end = htole64(lastdata);
|
||||
memcpy(hdr->hdr_guid, &gpt_guid, sizeof(hdr->hdr_guid));
|
||||
gpt_uuid_copy(hdr->hdr_guid, uuid);
|
||||
hdr->hdr_lba_table = htole64(2);
|
||||
hdr->hdr_entries = htole32(entries);
|
||||
hdr->hdr_entsz = htole32(sizeof(struct gpt_ent));
|
||||
|
|
|
@ -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: set.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: set.c,v 1.5 2014/09/30 18:00:00 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -44,7 +44,6 @@ __RCSID("$NetBSD: set.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
@ -66,7 +65,6 @@ usage_set(void)
|
|||
static void
|
||||
set(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
struct gpt_hdr *hdr;
|
||||
|
@ -106,8 +104,7 @@ set(int fd)
|
|||
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 unused",
|
||||
device_name, entry);
|
||||
return;
|
||||
|
|
105
sbin/gpt/show.c
105
sbin/gpt/show.c
|
@ -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: show.c,v 1.18 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: show.c,v 1.19 2014/09/30 18:00:00 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -64,87 +64,14 @@ usage_show(void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
static const char *
|
||||
friendly(uuid_t *t)
|
||||
{
|
||||
static const uuid_t efi_slice = GPT_ENT_TYPE_EFI;
|
||||
static const uuid_t bios_boot = GPT_ENT_TYPE_BIOS;
|
||||
static const uuid_t msdata = GPT_ENT_TYPE_MS_BASIC_DATA;
|
||||
static const uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
|
||||
static const uuid_t hfs = GPT_ENT_TYPE_APPLE_HFS;
|
||||
static const uuid_t linuxdata = GPT_ENT_TYPE_LINUX_DATA;
|
||||
static const uuid_t linuxswap = GPT_ENT_TYPE_LINUX_SWAP;
|
||||
static const uuid_t msr = GPT_ENT_TYPE_MS_RESERVED;
|
||||
static const uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP;
|
||||
static const uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS;
|
||||
static const uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
|
||||
static const uuid_t zfs = GPT_ENT_TYPE_FREEBSD_ZFS;
|
||||
static const uuid_t nb_swap = GPT_ENT_TYPE_NETBSD_SWAP;
|
||||
static const uuid_t nb_ffs = GPT_ENT_TYPE_NETBSD_FFS;
|
||||
static const uuid_t nb_lfs = GPT_ENT_TYPE_NETBSD_LFS;
|
||||
static const uuid_t nb_raid = GPT_ENT_TYPE_NETBSD_RAIDFRAME;
|
||||
static const uuid_t nb_ccd = GPT_ENT_TYPE_NETBSD_CCD;
|
||||
static const uuid_t nb_cgd = GPT_ENT_TYPE_NETBSD_CGD;
|
||||
static char buf[80];
|
||||
char *s;
|
||||
|
||||
if (show_uuid)
|
||||
goto unfriendly;
|
||||
|
||||
if (uuid_equal(t, &efi_slice, NULL))
|
||||
return ("EFI System");
|
||||
if (uuid_equal(t, &bios_boot, NULL))
|
||||
return ("BIOS Boot");
|
||||
if (uuid_equal(t, &nb_swap, NULL))
|
||||
return ("NetBSD swap");
|
||||
if (uuid_equal(t, &nb_ffs, NULL))
|
||||
return ("NetBSD FFSv1/FFSv2");
|
||||
if (uuid_equal(t, &nb_lfs, NULL))
|
||||
return ("NetBSD LFS");
|
||||
if (uuid_equal(t, &nb_raid, NULL))
|
||||
return ("NetBSD RAIDFrame component");
|
||||
if (uuid_equal(t, &nb_ccd, NULL))
|
||||
return ("NetBSD ccd component");
|
||||
if (uuid_equal(t, &nb_cgd, NULL))
|
||||
return ("NetBSD Cryptographic Disk");
|
||||
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, &zfs, NULL))
|
||||
return ("FreeBSD ZFS");
|
||||
if (uuid_equal(t, &freebsd, NULL))
|
||||
return ("FreeBSD legacy");
|
||||
if (uuid_equal(t, &msdata, NULL))
|
||||
return ("Windows basic data");
|
||||
if (uuid_equal(t, &msr, NULL))
|
||||
return ("Windows reserved");
|
||||
if (uuid_equal(t, &linuxdata, NULL))
|
||||
return ("Linux data");
|
||||
if (uuid_equal(t, &linuxswap, NULL))
|
||||
return ("Linux swap");
|
||||
if (uuid_equal(t, &hfs, NULL))
|
||||
return ("Apple HFS");
|
||||
|
||||
unfriendly:
|
||||
uuid_to_string(t, &s, NULL);
|
||||
strlcpy(buf, s, sizeof buf);
|
||||
free(s);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static void
|
||||
show(void)
|
||||
{
|
||||
uuid_t guid, type;
|
||||
off_t start;
|
||||
map_t *m, *p;
|
||||
struct mbr *mbr;
|
||||
struct gpt_ent *ent;
|
||||
unsigned int i;
|
||||
char *s;
|
||||
|
||||
printf(" %*s", lbawidth, "start");
|
||||
printf(" %*s", lbawidth, "size");
|
||||
|
@ -202,13 +129,15 @@ show(void)
|
|||
printf("- \"%s\"",
|
||||
utf16_to_utf8(ent->ent_name));
|
||||
} else if (show_guid) {
|
||||
uuid_dec_le(ent->ent_guid, &guid);
|
||||
uuid_to_string(&guid, &s, NULL);
|
||||
printf("- %s", s);
|
||||
free(s);
|
||||
char buf[128];
|
||||
gpt_uuid_snprintf(
|
||||
buf, sizeof(buf), "%d", ent->ent_guid);
|
||||
printf("- %s", buf);
|
||||
} else {
|
||||
uuid_dec_le(ent->ent_type, &type);
|
||||
printf("- %s", friendly(&type));
|
||||
char buf[128];
|
||||
gpt_uuid_snprintf(
|
||||
buf, sizeof(buf), "%s", ent->ent_type);
|
||||
printf("- %s", buf);
|
||||
}
|
||||
break;
|
||||
case MAP_TYPE_PMBR:
|
||||
|
@ -223,11 +152,9 @@ show(void)
|
|||
static void
|
||||
show_one(void)
|
||||
{
|
||||
uuid_t guid, type;
|
||||
map_t *m;
|
||||
struct gpt_ent *ent;
|
||||
const char *s1;
|
||||
char *s2;
|
||||
char s1[128], s2[128];
|
||||
#ifdef HN_AUTOSCALE
|
||||
char human_num[5];
|
||||
#endif
|
||||
|
@ -263,18 +190,14 @@ show_one(void)
|
|||
#endif
|
||||
printf("Size: %llu\n", (long long)m->map_size);
|
||||
|
||||
uuid_dec_le(ent->ent_type, &type);
|
||||
s1 = friendly(&type);
|
||||
uuid_to_string(&type, &s2, NULL);
|
||||
gpt_uuid_snprintf(s1, sizeof(s1), "%s", ent->ent_type);
|
||||
gpt_uuid_snprintf(s2, sizeof(s1), "%d", ent->ent_type);
|
||||
if (strcmp(s1, s2) == 0)
|
||||
s1 = "unknown";
|
||||
strlcpy(s1, "unknown", sizeof(s1));
|
||||
printf("Type: %s (%s)\n", s1, s2);
|
||||
free(s2);
|
||||
|
||||
uuid_dec_le(ent->ent_guid, &guid);
|
||||
uuid_to_string(&guid, &s2, NULL);
|
||||
gpt_uuid_snprintf(s2, sizeof(s1), "%d", ent->ent_guid);
|
||||
printf("GUID: %s\n", s2);
|
||||
free(s2);
|
||||
|
||||
printf("Label: %s\n", utf16_to_utf8(ent->ent_name));
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
__FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
|
||||
#endif
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: type.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: type.c,v 1.5 2014/09/30 18:00:00 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -49,7 +49,7 @@ __RCSID("$NetBSD: type.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
|||
#include "gpt.h"
|
||||
|
||||
static int all;
|
||||
static uuid_t type, newtype;
|
||||
static gpt_uuid_t type, newtype;
|
||||
static off_t block, size;
|
||||
static unsigned int entry;
|
||||
static uint8_t *label;
|
||||
|
@ -74,7 +74,6 @@ usage_type(void)
|
|||
static void
|
||||
chtype(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
map_t *m;
|
||||
|
@ -125,13 +124,12 @@ chtype(int fd)
|
|||
(char *)utf16_to_utf8(ent->ent_name)) != 0)
|
||||
continue;
|
||||
|
||||
uuid_dec_le(ent->ent_type, &uuid);
|
||||
if (!uuid_is_nil(&type, NULL) &&
|
||||
!uuid_equal(&type, &uuid, NULL))
|
||||
if (!gpt_uuid_is_nil(ent->ent_type) &&
|
||||
!gpt_uuid_equal(type, ent->ent_type))
|
||||
continue;
|
||||
|
||||
/* Change the primary entry. */
|
||||
uuid_enc_le(ent->ent_type, &newtype);
|
||||
gpt_uuid_copy(ent->ent_type, newtype);
|
||||
|
||||
hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
|
||||
le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
|
||||
|
@ -146,7 +144,7 @@ chtype(int fd)
|
|||
le32toh(hdr->hdr_entsz));
|
||||
|
||||
/* Change the secondary entry. */
|
||||
uuid_enc_le(ent->ent_type, &newtype);
|
||||
gpt_uuid_copy(ent->ent_type, newtype);
|
||||
|
||||
hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
|
||||
le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
|
||||
|
@ -203,15 +201,15 @@ cmd_type(int argc, char *argv[])
|
|||
usage_type();
|
||||
break;
|
||||
case 't':
|
||||
if (!uuid_is_nil(&type, NULL))
|
||||
if (!gpt_uuid_is_nil(type))
|
||||
usage_type();
|
||||
if (parse_uuid(optarg, &type) != 0)
|
||||
if (gpt_uuid_parse(optarg, type) != 0)
|
||||
usage_type();
|
||||
break;
|
||||
case 'T':
|
||||
if (!uuid_is_nil(&newtype, NULL))
|
||||
if (!gpt_uuid_is_nil(newtype))
|
||||
usage_type();
|
||||
if (parse_uuid(optarg, &newtype) != 0)
|
||||
if (gpt_uuid_parse(optarg, newtype) != 0)
|
||||
usage_type();
|
||||
break;
|
||||
default:
|
||||
|
@ -221,9 +219,9 @@ cmd_type(int argc, char *argv[])
|
|||
|
||||
if (!all ^
|
||||
(block > 0 || entry > 0 || label != NULL || size > 0 ||
|
||||
!uuid_is_nil(&type, NULL)))
|
||||
!gpt_uuid_is_nil(type)))
|
||||
usage_type();
|
||||
if (uuid_is_nil(&newtype, NULL))
|
||||
if (gpt_uuid_is_nil(newtype))
|
||||
usage_type();
|
||||
|
||||
if (argc == optind)
|
||||
|
|
|
@ -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: unset.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
||||
__RCSID("$NetBSD: unset.c,v 1.5 2014/09/30 18:00:00 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -44,7 +44,6 @@ __RCSID("$NetBSD: unset.c,v 1.4 2014/09/30 02:12:55 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
@ -66,7 +65,6 @@ usage_unset(void)
|
|||
static void
|
||||
unset(int fd)
|
||||
{
|
||||
uuid_t uuid;
|
||||
map_t *gpt, *tpg;
|
||||
map_t *tbl, *lbt;
|
||||
struct gpt_hdr *hdr;
|
||||
|
@ -106,8 +104,7 @@ unset(int fd)
|
|||
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 unused",
|
||||
device_name, entry);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue