summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorTim van der Molen <tim@cvs.openbsd.org>2015-11-26 08:15:08 +0000
committerTim van der Molen <tim@cvs.openbsd.org>2015-11-26 08:15:08 +0000
commit819c28bad11945f374a53f146195e25957b1ed67 (patch)
tree0b030edba802d1a0d46fa1a0d2e9e67cb145e7ae /sbin/fdisk
parent9354e57444cd72254996f7b453c4fc24c50bb612 (diff)
When prompting for a GPT partition type, use the partition's current type as
default; OK krw@
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/cmd.c5
-rw-r--r--sbin/fdisk/gpt.c4
-rw-r--r--sbin/fdisk/misc.c4
-rw-r--r--sbin/fdisk/part.c30
-rw-r--r--sbin/fdisk/part.h5
5 files changed, 38 insertions, 10 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index 29a154ecfdc..07c47327266 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.91 2015/11/25 19:32:35 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.92 2015/11/26 08:15:07 tim Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -303,7 +303,8 @@ Xgsetpid(char *args)
GPT_print_part(pn, "s");
/* Ask for partition type or GUID. */
- num = ask_pid(0, &guid);
+ uuid_dec_le(&gg->gp_type, &guid);
+ num = ask_pid(PRT_uuid_to_type(&guid), &guid);
if (num <= 0xff)
guid = *(PRT_type_to_uuid(num));
uuid_enc_le(&gg->gp_type, &guid);
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c
index c1eae5145d6..f650dfbaa6f 100644
--- a/sbin/fdisk/gpt.c
+++ b/sbin/fdisk/gpt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpt.c,v 1.7 2015/11/19 16:14:08 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.8 2015/11/26 08:15:07 tim Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -290,7 +290,7 @@ GPT_print_part(int n, char *units)
printf("%12.0f%s\n", size, unit_types[u].abbr);
uuid_dec_le(&partn->gp_type, &guid);
- printf(" %-36s %-36s\n", PRT_uuid_to_type(&guid),
+ printf(" %-36s %-36s\n", PRT_uuid_to_typename(&guid),
utf16le_to_string(partn->gp_name));
}
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 4014ad26986..c4a8b979e20 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.60 2015/11/26 08:10:42 tim Exp $ */
+/* $OpenBSD: misc.c,v 1.61 2015/11/26 08:15:07 tim Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -151,7 +151,7 @@ ask_pid(int dflt, struct uuid *guid)
continue;
}
- if (guid) {
+ if (guid && strlen(lbuf) == UUID_STR_LEN) {
uuid_from_string(lbuf, guid, &status);
if (status == uuid_s_ok)
return (0x100);
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index b56ddb0f0f4..254f179d4e6 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.74 2015/11/19 16:14:08 krw Exp $ */
+/* $OpenBSD: part.c,v 1.75 2015/11/26 08:15:07 tim Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -376,7 +376,7 @@ PRT_fix_CHS(struct prt *part)
}
char *
-PRT_uuid_to_type(struct uuid *uuid)
+PRT_uuid_to_typename(struct uuid *uuid)
{
static char partition_type[37]; /* Room for a GUID if needed. */
char *uuidstr = NULL;
@@ -408,6 +408,32 @@ done:
return (partition_type);
}
+int
+PRT_uuid_to_type(struct uuid *uuid)
+{
+ char *uuidstr;
+ int entries, i, status, type;
+
+ type = 0;
+
+ uuid_to_string(uuid, &uuidstr, &status);
+ if (status != uuid_s_ok)
+ goto done;
+
+ entries = sizeof(part_types) / sizeof(struct part_type);
+ for (i = 0; i < entries; i++) {
+ if (memcmp(part_types[i].guid, uuidstr,
+ sizeof(part_types[i].guid)) == 0) {
+ type = part_types[i].type;
+ break;
+ }
+ }
+
+done:
+ free(uuidstr);
+ return (type);
+}
+
struct uuid *
PRT_type_to_uuid(int type)
{
diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h
index c1b2299f0ed..f075c113dd5 100644
--- a/sbin/fdisk/part.h
+++ b/sbin/fdisk/part.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.h,v 1.20 2015/10/26 15:08:26 krw Exp $ */
+/* $OpenBSD: part.h,v 1.21 2015/11/26 08:15:07 tim Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -34,7 +34,8 @@ void PRT_parse(struct dos_partition *, off_t, off_t,
struct prt *);
void PRT_make(struct prt *, off_t, off_t, struct dos_partition *);
void PRT_print(int, struct prt *, char *);
-char *PRT_uuid_to_type(struct uuid *);
+char *PRT_uuid_to_typename(struct uuid *);
+int PRT_uuid_to_type(struct uuid *);
struct uuid *PRT_type_to_uuid(int);
/* This does CHS -> bs/ns */