CVS commit: src/sbin/gpt

2017-01-27 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Fri Jan 27 10:21:16 UTC 2017

Modified Files:
src/sbin/gpt: gpt.8

Log Message:
Fix spelling of partition.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sbin/gpt/gpt.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.50 src/sbin/gpt/gpt.8:1.51
--- src/sbin/gpt/gpt.8:1.50	Tue Nov  1 16:15:51 2016
+++ src/sbin/gpt/gpt.8	Fri Jan 27 10:21:16 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.50 2016/11/01 16:15:51 jdolecek Exp $
+.\" $NetBSD: gpt.8,v 1.51 2017/01/27 10:21:16 abhinav Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -638,7 +638,7 @@ nas# gpt show wd3
   3907029167   1 Sec GPT header
 nas# gpt add -s 10486224 -t swap -i 1 wd3
 nas# gpt label -i 1 -l swap_1 wd3
-parition 1 on rwd3d labeled swap_1
+partition 1 on rwd3d labeled swap_1
 nas# gpt show wd3
startsize  index  contents
0   1 PMBR



CVS commit: src/sbin/gpt

2017-02-12 Thread Aymeric Vincent
Module Name:src
Committed By:   aymeric
Date:   Sun Feb 12 16:54:06 UTC 2017

Modified Files:
src/sbin/gpt: main.c

Log Message:
Make gpt(8) work when compiled on a glibc-based OS.

This restores the ability to build amd64 install-image's under Linux.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/main.c
diff -u src/sbin/gpt/main.c:1.7 src/sbin/gpt/main.c:1.8
--- src/sbin/gpt/main.c:1.7	Tue Dec 29 16:45:04 2015
+++ src/sbin/gpt/main.c	Sun Feb 12 16:54:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.8 2017/02/12 16:54:06 aymeric Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.8 2017/02/12 16:54:06 aymeric Exp $");
 #endif
 
 #include 
@@ -145,8 +145,14 @@ main(int argc, char *argv[])
 		dev = argv[--argc];
 	}
 
+#ifdef __GLIBC__
+#define GETOPT_BE_POSIX		"+"
+#else
+#define GETOPT_BE_POSIX		""
+#endif
+
 	/* Get the generic options */
-	while ((ch = getopt(argc, argv, "m:nqrs:v")) != -1) {
+	while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "m:nqrs:v")) != -1) {
 		switch(ch) {
 		case 'm':
 			if (mediasz > 0)



CVS commit: src/sbin/gpt

2020-07-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul 27 20:54:18 UTC 2020

Modified Files:
src/sbin/gpt: gpt.8

Log Message:
catch up with source rename of fbsd-zfs -> zfs


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sbin/gpt/gpt.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.73 src/sbin/gpt/gpt.8:1.74
--- src/sbin/gpt/gpt.8:1.73	Sun May 24 16:59:16 2020
+++ src/sbin/gpt/gpt.8	Mon Jul 27 16:54:18 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.73 2020/05/24 20:59:16 wiz Exp $
+.\" $NetBSD: gpt.8,v 1.74 2020/07/27 20:54:18 christos Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd May 24, 2020
+.Dd July 27, 2020
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -203,8 +203,9 @@ UFS/UFS2
 .It Cm fbsd-vinum
 .Fx
 vinum
-.It Cm fbsd-zfs
-.Fx
+.It Cm zfs
+.Fx ,
+.Nx
 ZFS
 .It Cm linux-data
 Linux data



CVS commit: src/sbin/gpt

2020-03-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar 30 10:41:53 UTC 2020

Modified Files:
src/sbin/gpt: gpt_uuid.c

Log Message:
Now that we use the same UUID for ZFS as FreeBSD, drop the FreeBSD marker
from the description.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/gpt_uuid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt_uuid.c
diff -u src/sbin/gpt/gpt_uuid.c:1.18 src/sbin/gpt/gpt_uuid.c:1.19
--- src/sbin/gpt/gpt_uuid.c:1.18	Tue Jun 25 04:25:11 2019
+++ src/sbin/gpt/gpt_uuid.c	Mon Mar 30 10:41:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $	*/
+/*	$NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $");
 #endif
 
 #include 
@@ -73,7 +73,7 @@ static const struct {
 	{ 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_FREEBSD_ZFS, "zfs", "ZFS" },
 	{ GPT_ENT_TYPE_LINUX_DATA, "linux-data", "Linux data" },
 	{ GPT_ENT_TYPE_LINUX_RAID, "linux-raid", "Linux RAID" },
 	{ GPT_ENT_TYPE_LINUX_SWAP, "linux-swap", "Linux swap" },



CVS commit: src/sbin/gpt

2018-10-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Oct 14 20:10:49 UTC 2018

Modified Files:
src/sbin/gpt: gpt.c

Log Message:
When changing entries skip those that do not match the -L option.
Should fix PR 53668.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sbin/gpt/gpt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.c
diff -u src/sbin/gpt/gpt.c:1.75 src/sbin/gpt/gpt.c:1.76
--- src/sbin/gpt/gpt.c:1.75	Tue Jul  3 03:41:23 2018
+++ src/sbin/gpt/gpt.c	Sun Oct 14 20:10:49 2018
@@ -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.75 2018/07/03 03:41:23 jnemeth Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.76 2018/10/14 20:10:49 mlelstv Exp $");
 #endif
 
 #include 
@@ -1043,7 +1043,7 @@ gpt_change_ent(gpt_t gpt, const struct g
 			utf16_to_utf8(ent->ent_name,
 			__arraycount(ent->ent_name),
 			utfbuf, __arraycount(utfbuf));
-			if (strcmp((char *)find->label, (char *)utfbuf) == 0)
+			if (strcmp((char *)find->label, (char *)utfbuf) != 0)
 continue;
 		}
 



CVS commit: src/sbin/gpt

2018-12-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 20 14:58:10 UTC 2018

Modified Files:
src/sbin/gpt: gpt_uuid.c gpt_uuid.h

Log Message:
Add a query function (for external code) to enumerate the know guids.
Add recently added VMware GUIDs to the internal enum type.
Fix some short names (bogus + duplicate).


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/gpt_uuid.c
cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/gpt_uuid.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt_uuid.c
diff -u src/sbin/gpt/gpt_uuid.c:1.16 src/sbin/gpt/gpt_uuid.c:1.17
--- src/sbin/gpt/gpt_uuid.c:1.16	Tue Nov  6 04:04:33 2018
+++ src/sbin/gpt/gpt_uuid.c	Thu Dec 20 14:58:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $	*/
+/*	$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $");
 #endif
 
 #include 
@@ -87,9 +87,9 @@ static const struct {
 	{ GPT_ENT_TYPE_NETBSD_RAIDFRAME, "raid",
 	"NetBSD RAIDFrame component" },
 	{ GPT_ENT_TYPE_NETBSD_SWAP, "swap", "NetBSD swap" },
-	{ GPT_ENT_TYPE_VMWARE_VMKCORE, "swap", "VMware VMkernel core dump" },
-	{ GPT_ENT_TYPE_VMWARE_VMFS, "swap", "VMware VMFS" },
-	{ GPT_ENT_TYPE_VMWARE_RESERVED, "swap", "VMware reserved" },
+	{ GPT_ENT_TYPE_VMWARE_VMKCORE, "vmcore", "VMware VMkernel core dump" },
+	{ GPT_ENT_TYPE_VMWARE_VMFS, "vmfs", "VMware VMFS" },
+	{ GPT_ENT_TYPE_VMWARE_RESERVED, "vmresered", "VMware reserved" },
 };
 
 static void
@@ -234,6 +234,23 @@ gpt_uuid_parse(const char *s, gpt_uuid_t
 	return 0;
 }
 
+size_t
+gpt_uuid_query(
+void (*func)(const char *uuid, const char *short_name, const char *desc))
+{
+	size_t i;
+	char buf[64];
+
+	if (func != NULL) {
+		for (i = 0; i < __arraycount(gpt_nv); i++) {
+			gpt_uuid_numeric(buf, sizeof(buf), &gpt_nv[i].u);
+			(*func)(buf, gpt_nv[i].n, gpt_nv[i].d);
+		}
+	}
+	return __arraycount(gpt_nv);
+}
+
+#ifndef GPT_UUID_QUERY_ONLY
 void
 gpt_uuid_help(const char *prefix)
 {
@@ -323,3 +340,4 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t 
 	gpt_dce_to_uuid(&u, t);
 	return 0;
 }
+#endif

Index: src/sbin/gpt/gpt_uuid.h
diff -u src/sbin/gpt/gpt_uuid.h:1.7 src/sbin/gpt/gpt_uuid.h:1.8
--- src/sbin/gpt/gpt_uuid.h:1.7	Sun Dec  6 04:27:05 2015
+++ src/sbin/gpt/gpt_uuid.h	Thu Dec 20 14:58:10 2018
@@ -67,7 +67,10 @@ typedef enum {
 	GPT_TYPE_NETBSD_FFS,
 	GPT_TYPE_NETBSD_LFS,
 	GPT_TYPE_NETBSD_RAIDFRAME,
-	GPT_TYPE_NETBSD_SWAP
+	GPT_TYPE_NETBSD_SWAP,
+	GPT_TYPE_VMWARE_VMKCORE,
+	GPT_TYPE_VMWARE_VMFS,
+	GPT_TYPE_VMWARE_RESERVED
 } gpt_type_t;
 
 typedef uint8_t gpt_uuid_t[16];
@@ -98,6 +101,10 @@ int gpt_uuid_parse(const char *, gpt_uui
 struct gpt;
 int gpt_uuid_generate(struct gpt *, gpt_uuid_t);
 
+/* returns number of entries, callback func may be NULL */
+size_t gpt_uuid_query(
+void (*func)(const char *uuid, const char *short_name, const char *desc));
+
 void gpt_uuid_help(const char *);
 
 __END_DECLS



CVS commit: src/sbin/gpt

2019-01-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 27 13:16:05 UTC 2019

Modified Files:
src/sbin/gpt: gpt.c

Log Message:
Fix three MBR extended partition related bugs:
 1) when walking an extended MBR chain, do not assign duplicate indices
 2) the pointer to the next MBR may be any of the MBR_PTYPE_EXT* variants
 3) the ext MBR chain links are relative to the primary extended partition,
unlike the contained partitions which are relative to the extended MBR
block address.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sbin/gpt/gpt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.c
diff -u src/sbin/gpt/gpt.c:1.76 src/sbin/gpt/gpt.c:1.77
--- src/sbin/gpt/gpt.c:1.76	Sun Oct 14 20:10:49 2018
+++ src/sbin/gpt/gpt.c	Sun Jan 27 13:16:05 2019
@@ -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.76 2018/10/14 20:10:49 mlelstv Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.77 2019/01/27 13:16:05 martin Exp $");
 #endif
 
 #include 
@@ -279,7 +279,7 @@ gpt_write(gpt_t gpt, map_t map)
 }
 
 static int
-gpt_mbr(gpt_t gpt, off_t lba)
+gpt_mbr(gpt_t gpt, off_t lba, unsigned int *next_index, off_t ext_offset)
 {
 	struct mbr *mbr;
 	map_t m, p;
@@ -345,20 +345,22 @@ gpt_mbr(gpt_t gpt, off_t lba)
 			(uintmax_t)lba);
 			continue;
 		}
-		/* start is relative to the offset of the MBR itself. */
-		start += lba;
 		if (gpt->verbose > 2)
 			gpt_msg(gpt, "MBR part: flag=%#x type=%d, start=%ju, "
 			"size=%ju", mbr->mbr_part[i].part_flag,
 			mbr->mbr_part[i].part_typ,
 			(uintmax_t)start, (uintmax_t)size);
-		if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) {
+		if (!MBR_IS_EXTENDED(mbr->mbr_part[i].part_typ)) {
+			start += lba;
 			m = map_add(gpt, start, size, MAP_TYPE_MBR_PART, p, 0);
 			if (m == NULL)
 return -1;
-			m->map_index = i + 1;
+			m->map_index = *next_index;
+			(*next_index)++;
 		} else {
-			if (gpt_mbr(gpt, start) == -1)
+			start += ext_offset;
+			if (gpt_mbr(gpt, start, next_index,
+			ext_offset ? ext_offset : start) == -1)
 return -1;
 		}
 	}
@@ -479,7 +481,7 @@ gpt_open(const char *dev, int flags, int
 	int mode, found;
 	off_t devsz;
 	gpt_t gpt;
-
+	unsigned int index;
 
 	if ((gpt = calloc(1, sizeof(*gpt))) == NULL) {
 		if (!(flags & GPT_QUIET))
@@ -567,7 +569,8 @@ gpt_open(const char *dev, int flags, int
 	if (map_init(gpt, devsz) == -1)
 		goto close;
 
-	if (gpt_mbr(gpt, 0LL) == -1)
+	index = 1;
+	if (gpt_mbr(gpt, 0LL, &index, 0U) == -1)
 		goto close;
 	if ((found = gpt_gpt(gpt, 1LL, 1)) == -1)
 		goto close;



CVS commit: src/sbin/gpt

2019-02-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 10 10:35:51 UTC 2019

Modified Files:
src/sbin/gpt: migrate.c

Log Message:
Make "gpt migrate" work for disks with FAT32 and NTFS partitions


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sbin/gpt/migrate.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/migrate.c
diff -u src/sbin/gpt/migrate.c:1.33 src/sbin/gpt/migrate.c:1.34
--- src/sbin/gpt/migrate.c:1.33	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/migrate.c	Sun Feb 10 10:35:51 2019
@@ -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.33 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: migrate.c,v 1.34 2019/02/10 10:35:51 martin Exp $");
 #endif
 
 #include 
@@ -289,6 +289,16 @@ migrate(gpt_t gpt, u_int parts, int forc
 			type = GPT_TYPE_EFI;
 			break;
 
+		case MBR_PTYPE_NTFS:
+		case MBR_PTYPE_FAT12:
+		case MBR_PTYPE_FAT16S:
+		case MBR_PTYPE_FAT16B:
+		case MBR_PTYPE_FAT32:
+		case MBR_PTYPE_FAT32L:
+		case MBR_PTYPE_FAT16L:
+			type = GPT_TYPE_MS_BASIC_DATA;
+			break;
+
 		default:
 			if (!force) {
 gpt_warnx(gpt, "unknown partition type (%d)",



CVS commit: src/sbin/gpt

2018-08-27 Thread Sevan Janiyan
Module Name:src
Committed By:   sevan
Date:   Mon Aug 27 15:50:39 UTC 2018

Modified Files:
src/sbin/gpt: main.c

Log Message:
Add the -T flag to usage()


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/main.c
diff -u src/sbin/gpt/main.c:1.11 src/sbin/gpt/main.c:1.12
--- src/sbin/gpt/main.c:1.11	Mon Mar 19 09:06:20 2018
+++ src/sbin/gpt/main.c	Mon Aug 27 15:50:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $	*/
+/*	$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $");
+__RCSID("$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $");
 #endif
 
 #include 
@@ -105,7 +105,7 @@ usage(void)
 {
 	const char *p = getprogname();
 	const char *f =
-	"[-nrqv] [-m mediasize] [-s sectorsize]";
+	"[-nrqv] [-m mediasize] [-s sectorsize] [-T timestamp]";
 	size_t i;
 
 	if (strcmp(p, "gpt") == 0)



CVS commit: src/sbin/gpt

2019-03-02 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Sun Mar  3 02:28:14 UTC 2019

Modified Files:
src/sbin/gpt: migrate.c

Log Message:
add some more FAT file system types


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sbin/gpt/migrate.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/migrate.c
diff -u src/sbin/gpt/migrate.c:1.34 src/sbin/gpt/migrate.c:1.35
--- src/sbin/gpt/migrate.c:1.34	Sun Feb 10 10:35:51 2019
+++ src/sbin/gpt/migrate.c	Sun Mar  3 02:28:14 2019
@@ -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.34 2019/02/10 10:35:51 martin Exp $");
+__RCSID("$NetBSD: migrate.c,v 1.35 2019/03/03 02:28:14 jnemeth Exp $");
 #endif
 
 #include 
@@ -289,13 +289,20 @@ migrate(gpt_t gpt, u_int parts, int forc
 			type = GPT_TYPE_EFI;
 			break;
 
-		case MBR_PTYPE_NTFS:
 		case MBR_PTYPE_FAT12:
 		case MBR_PTYPE_FAT16S:
 		case MBR_PTYPE_FAT16B:
+		case MBR_PTYPE_NTFS:
 		case MBR_PTYPE_FAT32:
 		case MBR_PTYPE_FAT32L:
 		case MBR_PTYPE_FAT16L:
+		case MBR_PTYPE_OS2_DOS12:
+		case MBR_PTYPE_OS2_DOS16S:
+		case MBR_PTYPE_OS2_DOS16B:
+		case MBR_PTYPE_OS2_IFS:
+		case MBR_PTYPE_HID_FAT32:
+		case MBR_PTYPE_HID_FAT32_LBA:
+		case MBR_PTYPE_HID_FAT16_LBA:
 			type = GPT_TYPE_MS_BASIC_DATA;
 			break;
 



CVS commit: src/sbin/gpt

2019-03-02 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Sun Mar  3 03:20:43 UTC 2019

Modified Files:
src/sbin/gpt: show.c

Log Message:
Make it clear when displaying data from the MBR.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/show.c
diff -u src/sbin/gpt/show.c:1.41 src/sbin/gpt/show.c:1.42
--- src/sbin/gpt/show.c:1.41	Thu Sep  7 10:23:33 2017
+++ src/sbin/gpt/show.c	Sun Mar  3 03:20:42 2019
@@ -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.41 2017/09/07 10:23:33 christos Exp $");
+__RCSID("$NetBSD: show.c,v 1.42 2019/03/03 03:20:42 jnemeth Exp $");
 #endif
 
 #include 
@@ -344,6 +344,9 @@ cmd_show(gpt_t gpt, int argc, char *argv
 	if (argc != optind)
 		return usage();
 
+	if (map_find(gpt, MAP_TYPE_PRI_GPT_HDR) == NULL)
+		printf("GPT not found, displaying data from MBR.\n\n");
+
 	if (xshow & SHOW_ALL)
 		return show_all(gpt);
 



CVS commit: src/sbin/gpt

2019-03-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Mar 14 10:26:10 UTC 2019

Modified Files:
src/sbin/gpt: header.c

Log Message:
print little-endian header fields correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/header.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/header.c
diff -u src/sbin/gpt/header.c:1.9 src/sbin/gpt/header.c:1.10
--- src/sbin/gpt/header.c:1.9	Tue May  1 08:17:13 2018
+++ src/sbin/gpt/header.c	Thu Mar 14 10:26:10 2019
@@ -33,7 +33,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: header.c,v 1.9 2018/05/01 08:17:13 martin Exp $");
+__RCSID("$NetBSD: header.c,v 1.10 2019/03/14 10:26:10 mlelstv Exp $");
 #endif
 
 #include 
@@ -90,11 +90,11 @@ header(gpt_t gpt)
 	revision = le32toh(hdr->hdr_revision);
 	printf("- GPT Header Revision: %u.%u\n", revision >> 16,
 	 revision & 0x);
-	gpt_show_num("- First Data Sector", hdr->hdr_lba_start);
-	gpt_show_num("- Last Data Sector", hdr->hdr_lba_end);
+	gpt_show_num("- First Data Sector", le64toh(hdr->hdr_lba_start));
+	gpt_show_num("- Last Data Sector", le64toh(hdr->hdr_lba_end));
 	gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
 	printf("- Media GUID: %s\n", buf);
-	printf("- Number of GPT Entries: %u\n", hdr->hdr_entries);
+	printf("- Number of GPT Entries: %u\n", le32toh(hdr->hdr_entries));
 	return 0;
 }
 



CVS commit: src/sbin/gpt

2019-03-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar 24 13:31:00 UTC 2019

Modified Files:
src/sbin/gpt: gpt.8 resize.c

Log Message:
Add support for specifying the partition to resize via -b startsec
(similar to label and other subcommands). Do not fully add gpt_find
functionality here, as resizing multiple partitions in one go does not
make sense.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.23 -r1.24 src/sbin/gpt/resize.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.63 src/sbin/gpt/gpt.8:1.64
--- src/sbin/gpt/gpt.8:1.63	Tue May  1 21:16:02 2018
+++ src/sbin/gpt/gpt.8	Sun Mar 24 13:31:00 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.63 2018/05/01 21:16:02 kre Exp $
+.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd May 1, 2018
+.Dd March 24, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -466,7 +466,7 @@ See above for a description of these opt
 Partitions are removed by clearing the partition type.
 No other information is changed.
 .\"  resize 
-.It Nm Ic resize Fl i Ar index Oo Fl a Ar alignment Oc \
+.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \
 Oo Fl s Ar size Oc
 The
 .Ic resize

Index: src/sbin/gpt/resize.c
diff -u src/sbin/gpt/resize.c:1.23 src/sbin/gpt/resize.c:1.24
--- src/sbin/gpt/resize.c:1.23	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/resize.c	Sun Mar 24 13:31:00 2019
@@ -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.23 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: resize.c,v 1.24 2019/03/24 13:31:00 martin Exp $");
 #endif
 
 #include 
@@ -52,7 +52,7 @@ __RCSID("$NetBSD: resize.c,v 1.23 2018/0
 static int cmd_resize(gpt_t, int, char *[]);
 
 static const char *resizehelp[] = {
-	"-i index [-a alignment] [-s size]",
+	"[-i index | -b blocknr] [-a alignment] [-s size]",
 };
 
 struct gpt_cmd c_resize = {
@@ -131,17 +131,32 @@ static int
 cmd_resize(gpt_t gpt, int argc, char *argv[])
 {
 	int ch;
-	off_t alignment = 0, sectors, size = 0;
+	off_t alignment = 0, sectors, start = 0, size = 0;
 	unsigned int entry = 0;
+	map_t m;
 
-	while ((ch = getopt(argc, argv, GPT_AIS)) != -1) {
-		if (gpt_add_ais(gpt, &alignment, &entry, &size, ch) == -1)
+	while ((ch = getopt(argc, argv, GPT_AIS "b:")) != -1) {
+		if (ch == 'b')
+			gpt_human_get(gpt, &start);
+		else if (gpt_add_ais(gpt, &alignment, &entry, &size, ch) == -1)
 			return usage();
 	}
 
 	if (argc != optind)
 		return usage();
 
+	if (start > 0) {
+		for (m = map_first(gpt); m != NULL; m = m->map_next) {
+			if (m->map_type != MAP_TYPE_GPT_PART ||
+			m->map_index < 1)
+continue;
+			if (start != m->map_start)
+continue;
+			entry = m->map_index;
+			break;
+		}
+	}
+
 	if ((sectors = gpt_check_ais(gpt, alignment, entry, size)) == -1)
 		return -1;
 



CVS commit: src/sbin/gpt

2019-03-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar 24 13:45:35 UTC 2019

Modified Files:
src/sbin/gpt: gpt.8 show.c

Log Message:
Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.64 src/sbin/gpt/gpt.8:1.65
--- src/sbin/gpt/gpt.8:1.64	Sun Mar 24 13:31:00 2019
+++ src/sbin/gpt/gpt.8	Sun Mar 24 13:45:35 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin Exp $
+.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -466,7 +466,7 @@ See above for a description of these opt
 Partitions are removed by clearing the partition type.
 No other information is changed.
 .\"  resize 
-.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \
+.It Nm Ic resize Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc Oo Fl a Ar alignment Oc \
 Oo Fl s Ar size Oc
 The
 .Ic resize
@@ -592,7 +592,7 @@ They may be used by
 .Nx
 in the future.
 .\"  show 
-.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc
+.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc
 The
 .Ic show
 command displays the current partitioning on the listed devices and gives
@@ -611,6 +611,8 @@ option the GPT partition type is display
 user friendly form.
 With the
 .Fl i
+or the
+.Fl b
 option, all the details of a particular GPT partition will be displayed.
 The format of this display is subject to change.
 With the

Index: src/sbin/gpt/show.c
diff -u src/sbin/gpt/show.c:1.42 src/sbin/gpt/show.c:1.43
--- src/sbin/gpt/show.c:1.42	Sun Mar  3 03:20:42 2019
+++ src/sbin/gpt/show.c	Sun Mar 24 13:45:35 2019
@@ -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.42 2019/03/03 03:20:42 jnemeth Exp $");
+__RCSID("$NetBSD: show.c,v 1.43 2019/03/24 13:45:35 martin Exp $");
 #endif
 
 #include 
@@ -317,8 +317,10 @@ cmd_show(gpt_t gpt, int argc, char *argv
 	int ch;
 	int xshow = 0;
 	unsigned int entry = 0;
+	off_t start = 0;
+	map_t m;
 
-	while ((ch = getopt(argc, argv, "gi:lua")) != -1) {
+	while ((ch = getopt(argc, argv, "gi:b:lua")) != -1) {
 		switch(ch) {
 		case 'a':
 			xshow |= SHOW_ALL;
@@ -330,6 +332,10 @@ cmd_show(gpt_t gpt, int argc, char *argv
 			if (gpt_uint_get(gpt, &entry) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt_human_get(gpt, &start) == -1)
+return usage();
+			break;
 		case 'l':
 			xshow |= SHOW_LABEL;
 			break;
@@ -350,5 +356,17 @@ cmd_show(gpt_t gpt, int argc, char *argv
 	if (xshow & SHOW_ALL)
 		return show_all(gpt);
 
+	if (start > 0) {
+		for (m = map_first(gpt); m != NULL; m = m->map_next) {
+			if (m->map_type != MAP_TYPE_GPT_PART ||
+			m->map_index < 1)
+continue;
+			if (start != m->map_start)
+continue;
+			entry = m->map_index;
+			break;
+		}
+	}
+
 	return entry > 0 ? show_one(gpt, entry) : show(gpt, xshow);
 }



CVS commit: src/sbin/gpt

2019-03-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar 25 20:15:49 UTC 2019

Modified Files:
src/sbin/gpt: gpt.8 set.c

Log Message:
Allow -b startsec to specify the partition to change for the set subcommand
as well.
Add another option, -N, as a quick way to remove all attributes.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/set.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.65 src/sbin/gpt/gpt.8:1.66
--- src/sbin/gpt/gpt.8:1.65	Sun Mar 24 13:45:35 2019
+++ src/sbin/gpt/gpt.8	Mon Mar 25 20:15:49 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $
+.\" $NetBSD: gpt.8,v 1.66 2019/03/25 20:15:49 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd March 24, 2019
+.Dd March 25, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -555,7 +555,8 @@ the partitions fit, as
 will automatically adjust.
 However, the new disk must use the same sector size as the old disk.
 .\"  set 
-.It Nm Ic set Fl a Ar attribute Fl i Ar index
+.It Nm Ic set Oo Fl a Ar attribute Oc Oo Fl N Oc Oo Fl i Ar index Oc \
+Oo Fl b Ar startsec Oc
 .It Nm Ic set Fl l
 The
 .Ic set
@@ -567,9 +568,16 @@ The
 .Fl a
 option specifies which attributes to set and may be specified more than once,
 or the attributes can be comma-separated.
+If the
+.Fl N
+option and no
+.Fl a
+option are specified, all attributes are removed.
 The
 .Fl i
-option specifies which entry to update.
+or the
+.Fl b
+option specify which entry to update.
 The possible attributes are
 .Do biosboot Dc ,
 .Do bootme Dc ,

Index: src/sbin/gpt/set.c
diff -u src/sbin/gpt/set.c:1.14 src/sbin/gpt/set.c:1.15
--- src/sbin/gpt/set.c:1.14	Mon Mar 19 09:06:20 2018
+++ src/sbin/gpt/set.c	Mon Mar 25 20:15:49 2019
@@ -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.14 2018/03/19 09:06:20 mlelstv Exp $");
+__RCSID("$NetBSD: set.c,v 1.15 2019/03/25 20:15:49 martin Exp $");
 #endif
 
 #include 
@@ -52,7 +52,8 @@ __RCSID("$NetBSD: set.c,v 1.14 2018/03/1
 static int cmd_set(gpt_t, int, char *[]);
 
 static const char *sethelp[] = {
-	"-a attribute -i index",
+	"-a attribute [-i index] [-b startsec]",
+	"-N [-i index] [-b startsec]",
 	"-l",
 };
 
@@ -70,14 +71,20 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 {
 	int ch;
 	unsigned int entry = 0;
-	uint64_t attributes = 0;
+	uint64_t attributes = 0, clear = 0;
+	off_t start = 0;
+	map_t m;
 
-	while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
+	while ((ch = getopt(argc, argv, "a:b:i:lN")) != -1) {
 		switch(ch) {
 		case 'a':
 			if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt == NULL || gpt_human_get(gpt, &start) == -1)
+return usage();
+			break;
 		case 'i':
 			if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
 return usage();
@@ -85,13 +92,28 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 		case 'l':
 			gpt_attr_help("\t");
 			return 0;
+		case 'N':
+			clear = ~clear;
+			break;
 		default:
 			return usage();
 		}
 	}
 
-	if (gpt == NULL || argc != optind)
+	if (start > 0) {
+		for (m = map_first(gpt); m != NULL; m = m->map_next) {
+			if (m->map_type != MAP_TYPE_GPT_PART ||
+			m->map_index < 1)
+continue;
+			if (start != m->map_start)
+continue;
+			entry = m->map_index;
+			break;
+		}
+	}
+
+	if (gpt == NULL || argc != optind || (attributes != 0 && clear != 0))
 		return usage();
 
-	return gpt_attr_update(gpt, entry, attributes, 0);
+	return gpt_attr_update(gpt, entry, attributes, clear);
 }



CVS commit: src/sbin/gpt

2019-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar 26 11:23:55 UTC 2019

Modified Files:
src/sbin/gpt: show.c

Log Message:
When displaying a single partition (gpt show -i ...) display offset
and size in sectors (instead of the totally confusing bytes),
followed by the humanized byte offset/size.

This makes the numbers match the "gpt show" or "gpt show -a"
output.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/show.c
diff -u src/sbin/gpt/show.c:1.43 src/sbin/gpt/show.c:1.44
--- src/sbin/gpt/show.c:1.43	Sun Mar 24 13:45:35 2019
+++ src/sbin/gpt/show.c	Tue Mar 26 11:23:55 2019
@@ -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.43 2019/03/24 13:45:35 martin Exp $");
+__RCSID("$NetBSD: show.c,v 1.44 2019/03/26 11:23:55 martin Exp $");
 #endif
 
 #include 
@@ -186,6 +186,24 @@ show(gpt_t gpt, int xshow)
 	return 0;
 }
 
+static void
+gpt_show_sec_num(const char *prompt, int64_t secsize, off_t num)
+{
+#ifdef HN_AUTOSCALE
+	char human_num[5];
+	if (humanize_number(human_num, sizeof(human_num),
+	(int64_t)num*secsize,
+	"", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0)
+		human_num[0] = '\0';
+#endif
+	printf("%s: %" PRIu64, prompt, (uint64_t)num);
+#ifdef HN_AUTOSCALE
+	if (human_num[0] != '\0')
+		printf(" (%s)", human_num);
+#endif
+	printf("\n");
+}
+
 static int
 show_one(gpt_t gpt, unsigned int entry)
 {
@@ -204,8 +222,8 @@ show_one(gpt_t gpt, unsigned int entry)
 	ent = m->map_data;
 
 	printf("Details for index %d:\n", entry);
-	gpt_show_num("Start", (uintmax_t)(m->map_start * gpt->secsz));
-	gpt_show_num("Size", (uintmax_t)(m->map_size * gpt->secsz));
+	gpt_show_sec_num("Start", gpt->secsz, m->map_start);
+	gpt_show_sec_num("Size", gpt->secsz, m->map_size);
 
 	gpt_uuid_snprintf(s1, sizeof(s1), "%s", ent->ent_type);
 	gpt_uuid_snprintf(s2, sizeof(s2), "%d", ent->ent_type);



CVS commit: src/sbin/gpt

2019-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar 26 14:55:02 UTC 2019

Modified Files:
src/sbin/gpt: gpt.8 unset.c

Log Message:
Allow -b to specify a partition for "gpt unset" as well.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/unset.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.66 src/sbin/gpt/gpt.8:1.67
--- src/sbin/gpt/gpt.8:1.66	Mon Mar 25 20:15:49 2019
+++ src/sbin/gpt/gpt.8	Tue Mar 26 14:55:02 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.66 2019/03/25 20:15:49 martin Exp $
+.\" $NetBSD: gpt.8,v 1.67 2019/03/26 14:55:02 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd March 25, 2019
+.Dd March 26, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -653,7 +653,7 @@ The
 .Fl l
 flag lists available types.
 .\"  unset 
-.It Nm Ic unset Fl a Ar attribute Fl i Ar index
+.It Nm Ic unset Fl a Ar attribute Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc
 .It Nm Ic unset Fl l
 The
 .Ic unset
@@ -664,8 +664,11 @@ flag lists all available attributes.
 The
 .Fl a
 option specifies which attributes to unset and may be specified more than once.
+Alternatively a comma separated list of attributes can be used.
 The
 .Fl i
+or the
+.Fl b
 option specifies which entry to update.
 The possible attributes are
 .Do biosboot Dc ,

Index: src/sbin/gpt/unset.c
diff -u src/sbin/gpt/unset.c:1.14 src/sbin/gpt/unset.c:1.15
--- src/sbin/gpt/unset.c:1.14	Mon Mar 19 09:06:20 2018
+++ src/sbin/gpt/unset.c	Tue Mar 26 14:55:02 2019
@@ -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.14 2018/03/19 09:06:20 mlelstv Exp $");
+__RCSID("$NetBSD: unset.c,v 1.15 2019/03/26 14:55:02 martin Exp $");
 #endif
 
 #include 
@@ -53,6 +53,7 @@ static int cmd_unset(gpt_t, int, char *[
 
 static const char *unsethelp[] = {
 	"-a attribute -i index",
+	"-a attribute -b startsec",
 	"-l",
 };
 
@@ -71,13 +72,19 @@ cmd_unset(gpt_t gpt, int argc, char *arg
 	int ch;
 	unsigned int entry = 0;
 	uint64_t attributes = 0;
+	off_t start = 0;
+	map_t m;
 
-	while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
+	while ((ch = getopt(argc, argv, "a:b:i:l")) != -1) {
 		switch(ch) {
 		case 'a':
 			if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt == NULL || gpt_human_get(gpt, &start) == -1)
+return usage();
+			break;
 		case 'i':
 			if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
 return usage();
@@ -90,6 +97,18 @@ cmd_unset(gpt_t gpt, int argc, char *arg
 		}
 	}
 
+	if (start > 0) {
+		for (m = map_first(gpt); m != NULL; m = m->map_next) {
+			if (m->map_type != MAP_TYPE_GPT_PART ||
+			m->map_index < 1)
+continue;
+			if (start != m->map_start)
+continue;
+			entry = m->map_index;
+			break;
+		}
+	}
+
 	if (gpt == NULL || argc != optind)
 		return usage();
 



CVS commit: src/sbin/gpt

2019-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr  4 13:55:40 UTC 2019

Modified Files:
src/sbin/gpt: biosboot.c gpt.8

Log Message:
Allow specifying the partition via -b startsec for the biosboot cmd.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sbin/gpt/biosboot.c
cvs rdiff -u -r1.67 -r1.68 src/sbin/gpt/gpt.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/biosboot.c
diff -u src/sbin/gpt/biosboot.c:1.30 src/sbin/gpt/biosboot.c:1.31
--- src/sbin/gpt/biosboot.c:1.30	Thu Sep  7 10:23:33 2017
+++ src/sbin/gpt/biosboot.c	Thu Apr  4 13:55:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $ */
+/*	$NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $");
 #endif
 
 #include 
@@ -72,7 +72,7 @@ __RCSID("$NetBSD: biosboot.c,v 1.30 2017
 static int cmd_biosboot(gpt_t, int, char *[]);
 
 static const char *biosboothelp[] = {
-	"[-A] [-c bootcode] [-i index] [-L label]",
+	"[-A] [-c bootcode] [-i index] [-L label] [-b startsec]",
 #if notyet
 	"[-a alignment] [-b blocknr] [-i index] [-l label]",
 	"[-s size] [-t type]",
@@ -230,6 +230,10 @@ biosboot(gpt_t gpt, daddr_t start, uint6
 		if (entry < 1 && label == NULL && size > 0 &&
 		m->map_start == start && m->map_size == (off_t)size)
 			break;
+		/* next could be start sector specified by -b option */
+		if (entry < 1 && label == NULL && size == 0 &&
+		m->map_start == start)
+			break;
 	}
 
 	if (m == NULL) {
@@ -270,7 +274,7 @@ cmd_biosboot(gpt_t gpt, int argc, char *
 	uint8_t *label = NULL;
 	char *bootpath = NULL;
 
-	while ((ch = getopt(argc, argv, "Ac:i:L:")) != -1) {
+	while ((ch = getopt(argc, argv, "Ac:i:L:b:")) != -1) {
 		switch(ch) {
 		case 'A':
 			active = 1;
@@ -287,6 +291,10 @@ cmd_biosboot(gpt_t gpt, int argc, char *
 			if (gpt_name_get(gpt, &label) == -1)
 goto usage;
 			break;
+		case 'b':
+			if (gpt_human_get(gpt, &start) == -1)
+goto usage;
+			break;
 		default:
 			goto usage;
 		}

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.67 src/sbin/gpt/gpt.8:1.68
--- src/sbin/gpt/gpt.8:1.67	Tue Mar 26 14:55:02 2019
+++ src/sbin/gpt/gpt.8	Thu Apr  4 13:55:40 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.67 2019/03/26 14:55:02 martin Exp $
+.\" $NetBSD: gpt.8,v 1.68 2019/04/04 13:55:40 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd March 26, 2019
+.Dd April 4, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -249,8 +249,8 @@ command.
 The format is a plist.
 It should not be modified.
 .\"  biosboot 
-.It Nm Ic biosboot Oo Fl A Oc Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \
-Oo Fl L Ar label Oc
+.It Nm Ic biosboot Oo Fl A Oc Oo Fl c Ar bootcode Oc Oo Fl b Ar startsec Oc \
+Oo Fl i Ar index Oc Oo Fl L Ar label Oc
 The
 .Ic biosboot
 command allows the user to configure the partition that contains the
@@ -279,6 +279,9 @@ The
 option selects the partition by label.
 If there are multiple partitions with the same label, the
 first one found will be used.
+The
+.Fl b
+options selects the partition by start block.
 .\"  create 
 .It Nm Ic create Oo Fl AfP Oc Oo Fl p Ar partitions Oc
 The



CVS commit: src/sbin/gpt

2019-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr  4 13:58:20 UTC 2019

Modified Files:
src/sbin/gpt: destroy.c

Log Message:
Ignore -f with the "destroy" command completely (it was effectively
ignored already, so no functional change). Leave it as valid option
for compatibility.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/destroy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/destroy.c
diff -u src/sbin/gpt/destroy.c:1.10 src/sbin/gpt/destroy.c:1.11
--- src/sbin/gpt/destroy.c:1.10	Thu Dec  3 01:07:28 2015
+++ src/sbin/gpt/destroy.c	Thu Apr  4 13:58:20 2019
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: destroy.c,v 1.10 2015/12/03 01:07:28 christos Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.11 2019/04/04 13:58:20 martin Exp $");
 #endif
 
 #include 
@@ -52,7 +52,7 @@ __RCSID("$NetBSD: destroy.c,v 1.10 2015/
 static int cmd_destroy(gpt_t, int, char *[]);
 
 static const char *destroyhelp[] = {
-	"[-rf]",
+	"[-r]",
 };
 
 struct gpt_cmd c_destroy = {
@@ -107,12 +107,10 @@ cmd_destroy(gpt_t gpt, int argc, char *a
 {
 	int ch;
 	int recoverable = 0;
-	int force = 0;
 
 	while ((ch = getopt(argc, argv, "fr")) != -1) {
 		switch(ch) {
 		case 'f':
-			force = 1;
 			break;
 		case 'r':
 			recoverable = 1;
@@ -125,5 +123,5 @@ cmd_destroy(gpt_t gpt, int argc, char *a
 	if (argc != optind)
 		return usage();
 
-	return destroy(gpt, force, recoverable);
+	return destroy(gpt, 0, recoverable);
 }



CVS commit: src/sbin/gpt

2019-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr  4 14:03:40 UTC 2019

Modified Files:
src/sbin/gpt: destroy.c

Log Message:
PR bin/54088: make "destroy" remove the protective MBR too.
We could make this optional if someone comes up with a good reason
to leave it intact.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/destroy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/destroy.c
diff -u src/sbin/gpt/destroy.c:1.11 src/sbin/gpt/destroy.c:1.12
--- src/sbin/gpt/destroy.c:1.11	Thu Apr  4 13:58:20 2019
+++ src/sbin/gpt/destroy.c	Thu Apr  4 14:03:40 2019
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: destroy.c,v 1.11 2019/04/04 13:58:20 martin Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.12 2019/04/04 14:03:40 martin Exp $");
 #endif
 
 #include 
@@ -68,10 +68,11 @@ struct gpt_cmd c_destroy = {
 static int
 destroy(gpt_t gpt, int force, int recoverable)
 {
-	map_t pri_hdr, sec_hdr;
+	map_t pri_hdr, sec_hdr, pmbr;
 
 	pri_hdr = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
 	sec_hdr = map_find(gpt, MAP_TYPE_SEC_GPT_HDR);
+	pmbr = map_find(gpt, MAP_TYPE_PMBR);
 
 	if (pri_hdr == NULL && sec_hdr == NULL) {
 		gpt_warnx(gpt, "Device doesn't contain a GPT");
@@ -99,6 +100,14 @@ destroy(gpt_t gpt, int force, int recove
 		}
 	}
 
+	if (!recoverable && pmbr != NULL) {
+		memset(pmbr->map_data, 0, gpt->secsz);
+		if (gpt_write(gpt, pmbr) == -1) {
+			gpt_warnx(gpt, "Error deleting PMBR");
+			return -1;
+		}
+	}
+
 	return 0;
 }
 



CVS commit: src/sbin/gpt

2020-05-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May 24 14:42:44 UTC 2020

Modified Files:
src/sbin/gpt: gpt.8 map.c resize.c resizedisk.c

Log Message:
Exit gracefully when auto-expanding a partition and it is already the
correct size. Add a -q flag to "resize" and "resizedisk" commands to skip
printing warnings in the already resize paths.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/map.c
cvs rdiff -u -r1.24 -r1.25 src/sbin/gpt/resize.c
cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/resizedisk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.70 src/sbin/gpt/gpt.8:1.71
--- src/sbin/gpt/gpt.8:1.70	Fri Jul 26 07:22:05 2019
+++ src/sbin/gpt/gpt.8	Sun May 24 14:42:44 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.70 2019/07/26 07:22:05 martin Exp $
+.\" $NetBSD: gpt.8,v 1.71 2020/05/24 14:42:44 jmcneill Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd July 26, 2019
+.Dd May 24, 2020
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -470,7 +470,7 @@ Partitions are removed by clearing the p
 No other information is changed.
 .\"  resize 
 .It Nm Ic resize Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc Oo Fl a Ar alignment Oc \
-Oo Fl s Ar size Oc
+Oo Fl s Ar size Oc Oo Fl q Oc
 The
 .Ic resize
 command allows the user to resize a partition.
@@ -500,8 +500,12 @@ If the
 .Fl a
 option is specified then the size will be adjusted to be a multiple of
 alignment if possible.
+If the
+.Fl q
+option is specified then the utility will not print output when a
+resize is not required.
 .\"  resizedisk 
-.It Nm Ic resizedisk Oo Fl s Ar size Oc
+.It Nm Ic resizedisk Oo Fl s Ar size Oc Oo Fl q Oc
 The
 .Ic resizedisk
 command allows the user to resize a disk.
@@ -537,6 +541,10 @@ Using the
 .Fl s
 option allows you to move the backup copy prior to resizing the medium.
 This is primarily useful when shrinking the medium.
+If the
+.Fl q
+option is specified then the utility will not print output when a
+resize is not required.
 .\"  restore 
 .It Nm Ic restore Oo Fl F Oc Oo Fl i Ar infile Oc
 The

Index: src/sbin/gpt/map.c
diff -u src/sbin/gpt/map.c:1.14 src/sbin/gpt/map.c:1.15
--- src/sbin/gpt/map.c:1.14	Wed Apr 11 07:14:23 2018
+++ src/sbin/gpt/map.c	Sun May 24 14:42:44 2020
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/map.c,v 1.6 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: map.c,v 1.14 2018/04/11 07:14:23 mrg Exp $");
+__RCSID("$NetBSD: map.c,v 1.15 2020/05/24 14:42:44 jmcneill Exp $");
 #endif
 
 #include 
@@ -280,7 +280,10 @@ map_resize(gpt_t gpt, map_t m, off_t siz
 			prevsize = m->map_size;
 			size = ((m->map_size + n->map_size) / alignment)
 			* alignment;
-			if (size <= prevsize) {
+			if (size == prevsize) {
+m->map_size = size;
+return size;
+			} else if (size < prevsize) {
 gpt_warnx(gpt, "Can't coalesce %ju <= %ju",
 (uintmax_t)prevsize, (uintmax_t)size);
 return -1;

Index: src/sbin/gpt/resize.c
diff -u src/sbin/gpt/resize.c:1.24 src/sbin/gpt/resize.c:1.25
--- src/sbin/gpt/resize.c:1.24	Sun Mar 24 13:31:00 2019
+++ src/sbin/gpt/resize.c	Sun May 24 14:42:44 2020
@@ -33,12 +33,13 @@
 __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.24 2019/03/24 13:31:00 martin Exp $");
+__RCSID("$NetBSD: resize.c,v 1.25 2020/05/24 14:42:44 jmcneill Exp $");
 #endif
 
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -52,7 +53,7 @@ __RCSID("$NetBSD: resize.c,v 1.24 2019/0
 static int cmd_resize(gpt_t, int, char *[]);
 
 static const char *resizehelp[] = {
-	"[-i index | -b blocknr] [-a alignment] [-s size]",
+	"[-i index | -b blocknr] [-a alignment] [-s size] [-q]",
 };
 
 struct gpt_cmd c_resize = {
@@ -65,13 +66,13 @@ struct gpt_cmd c_resize = {
 #define usage() gpt_usage(NULL, &c_resize)
 
 static int
-resize(gpt_t gpt, u_int entry, off_t alignment, off_t sectors, off_t size)
+resize(gpt_t gpt, u_int entry, off_t alignment, off_t sectors, off_t size, bool quiet)
 {
 	map_t map;
 	struct gpt_hdr *hdr;
 	struct gpt_ent *ent;
 	unsigned int i;
-	off_t alignsecs, newsize;
+	off_t alignsecs, newsize, oldsize;
 	uint64_t end;
 	
 
@@ -101,14 +102,25 @@ resize(gpt_t gpt, u_int entry, off_t ali
 		if (alignment == 0 ||
 		(alignment > 0 && sectors % alignsecs == 0)) {
 			/* nothing to do */
-			gpt_warnx(gpt, "partition does not need resizing");
+			if (!quiet)
+gpt_warnx(gpt,
+"partition does not need resizing");
 			return 0;
 		}
 
+	oldsize = map->map_size;
 	newsize = map_resize(gpt, map, sectors, alignsecs);
 	if (newsize == -1)
 		return -1;
 
+	if (oldsize == newsize) {

CVS commit: src/sbin/gpt

2020-05-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May 24 18:42:20 UTC 2020

Modified Files:
src/sbin/gpt: gpt.8 gpt.c gpt.h main.c

Log Message:
Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.81 -r1.82 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.71 src/sbin/gpt/gpt.8:1.72
--- src/sbin/gpt/gpt.8:1.71	Sun May 24 14:42:44 2020
+++ src/sbin/gpt/gpt.8	Sun May 24 18:42:20 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.71 2020/05/24 14:42:44 jmcneill Exp $
+.\" $NetBSD: gpt.8,v 1.72 2020/05/24 18:42:20 jmcneill Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .Nd GUID partition table maintenance utility
 .Sh SYNOPSIS
 .Nm
-.Op Fl nrqv
+.Op Fl Hnrqv
 .Op Fl m Ar mediasize
 .Op Fl s Ar sectorsize
 .Op Fl T Ar timestamp
@@ -83,6 +83,8 @@ have an effect on all commands.
 Override the default media size for the device (obtained
 from the kernel if possible) or defaulting to the file size for
 plain files.
+.If Fl H
+Ignore existing MBR (Hybrid MBR/GPT mode).
 .It Fl n
 Do not update the wedge information that
 .Nm

Index: src/sbin/gpt/gpt.c
diff -u src/sbin/gpt/gpt.c:1.81 src/sbin/gpt/gpt.c:1.82
--- src/sbin/gpt/gpt.c:1.81	Fri Oct 11 23:04:52 2019
+++ src/sbin/gpt/gpt.c	Sun May 24 18:42:20 2020
@@ -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.81 2019/10/11 23:04:52 christos Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.82 2020/05/24 18:42:20 jmcneill Exp $");
 #endif
 
 #include 
@@ -311,7 +311,7 @@ gpt_mbr(gpt_t gpt, off_t lba, unsigned i
 			continue;
 		if (mbr->mbr_part[i].part_typ == MBR_PTYPE_PMBR)
 			pmbr++;
-		else
+		else if ((gpt->flags & GPT_HYBRID) == 0)
 			break;
 	}
 	if (pmbr && i == 4 && lba == 0) {

Index: src/sbin/gpt/gpt.h
diff -u src/sbin/gpt/gpt.h:1.41 src/sbin/gpt/gpt.h:1.42
--- src/sbin/gpt/gpt.h:1.41	Sun Jun 30 11:38:16 2019
+++ src/sbin/gpt/gpt.h	Sun May 24 18:42:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt.h,v 1.41 2019/06/30 11:38:16 sevan Exp $	*/
+/*	$NetBSD: gpt.h,v 1.42 2020/05/24 18:42:20 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -84,6 +84,7 @@ gpt_t	gpt_open(const char *, int, int, o
 #define GPT_FILE	0x10
 #define GPT_TIMESTAMP	0x20
 #define GPT_SYNC	0x40
+#define GPT_HYBRID	0x80
 #define GPT_OPTDEV  0x8000
 
 void*	gpt_read(gpt_t, off_t, size_t);

Index: src/sbin/gpt/main.c
diff -u src/sbin/gpt/main.c:1.13 src/sbin/gpt/main.c:1.14
--- src/sbin/gpt/main.c:1.13	Tue Jun 25 04:53:40 2019
+++ src/sbin/gpt/main.c	Sun May 24 18:42:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $	*/
+/*	$NetBSD: main.c,v 1.14 2020/05/24 18:42:20 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $");
+__RCSID("$NetBSD: main.c,v 1.14 2020/05/24 18:42:20 jmcneill Exp $");
 #endif
 
 #include 
@@ -185,8 +185,11 @@ main(int argc, char *argv[])
 #endif
 
 	/* Get the generic options */
-	while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "m:nqrs:T:v")) != -1) {
+	while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "Hm:nqrs:T:v")) != -1) {
 		switch(ch) {
+		case 'H':
+			flags |= GPT_HYBRID;
+			break;
 		case 'm':
 			if (mediasz > 0)
 usage();



CVS commit: src/sbin/gpt

2020-05-24 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun May 24 20:59:16 UTC 2020

Modified Files:
src/sbin/gpt: gpt.8

Log Message:
Fix typo in macro. Sort option descriptions.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sbin/gpt/gpt.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.72 src/sbin/gpt/gpt.8:1.73
--- src/sbin/gpt/gpt.8:1.72	Sun May 24 18:42:20 2020
+++ src/sbin/gpt/gpt.8	Sun May 24 20:59:16 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.72 2020/05/24 18:42:20 jmcneill Exp $
+.\" $NetBSD: gpt.8,v 1.73 2020/05/24 20:59:16 wiz Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .Nd GUID partition table maintenance utility
 .Sh SYNOPSIS
 .Nm
-.Op Fl Hnrqv
+.Op Fl Hnqrv
 .Op Fl m Ar mediasize
 .Op Fl s Ar sectorsize
 .Op Fl T Ar timestamp
@@ -79,12 +79,12 @@ change the behaviour that is applicable 
 Not all commands use all default settings, so some general options may not
 have an effect on all commands.
 .Bl -tag -width 
+.It Fl H
+Ignore existing MBR (Hybrid MBR/GPT mode).
 .It Fl m Ar mediasize
 Override the default media size for the device (obtained
 from the kernel if possible) or defaulting to the file size for
 plain files.
-.If Fl H
-Ignore existing MBR (Hybrid MBR/GPT mode).
 .It Fl n
 Do not update the wedge information that
 .Nm
@@ -92,15 +92,15 @@ changed.
 You need to use the
 .Xr dkctl 8
 command manually update the device's wedge configuration if you do that.
+.It Fl q
+Do not print error messages.
+This is not implemented completely yet.
 .It Fl r
 Open the device for reading only.
 .Nm
 Currently this option is primarily useful for the
 .Ic show
 command, but the intent is to use it to implement dry-run behaviour.
-.It Fl q
-Do not print error messages.
-This is not implemented completely yet.
 .It Fl s Ar sectorsize
 Override the default sector size for the device (obtained
 from the kernel if possible) or



CVS commit: src/sbin/gpt

2020-06-06 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Jun  7 05:42:25 UTC 2020

Modified Files:
src/sbin/gpt: backup.c restore.c

Log Message:
Update for proplib(3) API changes.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/backup.c
cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/restore.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/backup.c
diff -u src/sbin/gpt/backup.c:1.18 src/sbin/gpt/backup.c:1.19
--- src/sbin/gpt/backup.c:1.18	Thu Sep  7 10:23:33 2017
+++ src/sbin/gpt/backup.c	Sun Jun  7 05:42:25 2020
@@ -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.18 2017/09/07 10:23:33 christos Exp $");
+__RCSID("$NetBSD: backup.c,v 1.19 2020/06/07 05:42:25 thorpej Exp $");
 #endif
 
 #include 
@@ -68,79 +68,46 @@ struct gpt_cmd c_backup = {
 
 #define PROP_ERR(x)	if (!(x)) goto cleanup
 
-#define prop_uint(a) prop_number_create_unsigned_integer(a)
-
 static int
 store_mbr(gpt_t gpt, unsigned int i, const struct mbr *mbr,
 prop_array_t *mbr_array)
 {
 	prop_dictionary_t mbr_dict;
-	prop_number_t propnum;
 	const struct mbr_part *par = &mbr->mbr_part[i];
-	bool rc;
 
 	if (mbr->mbr_part[i].part_typ == MBR_PTYPE_UNUSED)
 		return 0;
 
 	mbr_dict = prop_dictionary_create();
 	PROP_ERR(mbr_dict);
-	propnum = prop_number_create_integer(i);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "index", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_flag);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "flag", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_shd);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "start_head", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_ssect);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "start_sector", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_scyl);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "start_cylinder", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_typ);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "type", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_ehd);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "end_head", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_esect);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "end_sector", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(par->part_ecyl);
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "end_cylinder", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(le16toh(par->part_start_lo));
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "lba_start_low", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(le16toh(par->part_start_hi));
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "lba_start_high", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(le16toh(par->part_size_lo));
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "lba_size_low", propnum);
-	PROP_ERR(rc);
-	propnum = prop_uint(le16toh(par->part_size_hi));
-	PROP_ERR(propnum);
-	rc = prop_dictionary_set(mbr_dict, "lba_size_high", propnum);
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head",
+	  par->part_shd));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_sector",
+	  par->part_ssect));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_cylinder",
+	  par->part_scyl));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "type", par->part_typ));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_head", par->part_ehd));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_sector",
+	  par->part_esect));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_cylinder",
+	  par->part_ecyl));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_low",
+	  le16toh(par->part_start_lo)));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_high",
+	  le16toh(par->part_start_hi)));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_low",
+	  le16toh(par->part_size_lo)));
+	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_high",
+	  le16toh(par->part_size_hi)));
+
 	if (*mbr_array == NULL) {
 		*mbr_array = prop_array_create();
 		PROP_ERR(*mbr_array);
 	}
-	rc = prop_array_add(*mbr_array, mbr_dict);
-	PROP_ERR(rc);
+	PROP_ERR(prop_array_add_and_rel(*mbr_array, mbr_dict));
 	return 0;
 cleanup:
 	if (mbr_dict)
@@ -152,26 +119,16 @@ cleanup:
 static int
 store_gpt(gpt_t gpt, const struct gpt_hdr *hdr, prop_dictionary_t *type_dict)
 {
-	prop_number_t propnum;
-	prop_string_t propstr;
 	char buf[128];
-	bool rc;
 
 	*type_dict = prop_dictionary_create();
 	PROP_ERR(type_dict);
-	propnum = prop_uint(le32toh(hdr->hdr_revision));
-	PROP_ERR(propnum);

CVS commit: src/sbin/gpt

2020-06-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun  8 22:52:09 UTC 2020

Modified Files:
src/sbin/gpt: backup.c

Log Message:
When we add "entries", "index", and "sector_size" values to the dictionary,
add them as signed valaues, rather than unsigned (which is how we keep them
in memory).  This causes them be serialized in base-10 (rather than base-16,
which is the default for unsigned).  This behavior is documented in
prop_number(3).  Fixes t_gpt::backup_2part unit test.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/backup.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/backup.c
diff -u src/sbin/gpt/backup.c:1.19 src/sbin/gpt/backup.c:1.20
--- src/sbin/gpt/backup.c:1.19	Sun Jun  7 05:42:25 2020
+++ src/sbin/gpt/backup.c	Mon Jun  8 22:52:09 2020
@@ -33,13 +33,15 @@
 __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.19 2020/06/07 05:42:25 thorpej Exp $");
+__RCSID("$NetBSD: backup.c,v 1.20 2020/06/08 22:52:09 thorpej Exp $");
 #endif
 
 #include 
 #include 
 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -80,7 +82,8 @@ store_mbr(gpt_t gpt, unsigned int i, con
 
 	mbr_dict = prop_dictionary_create();
 	PROP_ERR(mbr_dict);
-	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i));
+	assert(i <= INT_MAX);
+	PROP_ERR(prop_dictionary_set_int(mbr_dict, "index", (int)i));
 	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag));
 	PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head",
 	  par->part_shd));
@@ -127,8 +130,9 @@ store_gpt(gpt_t gpt, const struct gpt_hd
 	  le32toh(hdr->hdr_revision)));
 	gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
 	PROP_ERR(prop_dictionary_set_string(*type_dict, "guid", buf));
-	PROP_ERR(prop_dictionary_set_uint(*type_dict, "entries",
-	  le32toh(hdr->hdr_entries)));
+	assert(le32toh(hdr->hdr_entries) <= INT32_MAX);
+	PROP_ERR(prop_dictionary_set_int32(*type_dict, "entries",
+	   (int32_t)le32toh(hdr->hdr_entries)));
 	return 0;
 cleanup:
 	if (*type_dict)
@@ -161,7 +165,8 @@ store_tbl(gpt_t gpt, const map_t m, prop
 	m->map_size * gpt->secsz; i++, ent++) {
 		gpt_dict = prop_dictionary_create();
 		PROP_ERR(gpt_dict);
-		PROP_ERR(prop_dictionary_set_uint(gpt_dict, "index", i));
+		assert(i <= INT_MAX);
+		PROP_ERR(prop_dictionary_set_int(gpt_dict, "index", (int)i));
 		gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_type);
 		PROP_ERR(prop_dictionary_set_string(gpt_dict, "type", buf));
 		gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_guid);
@@ -206,7 +211,9 @@ backup(gpt_t gpt, const char *outfile)
 
 	props = prop_dictionary_create();
 	PROP_ERR(props);
-	PROP_ERR(prop_dictionary_set_uint(props, "sector_size", gpt->secsz));
+	assert(gpt->secsz <= INT_MAX);
+	PROP_ERR(prop_dictionary_set_int(props, "sector_size",
+	 (int)gpt->secsz));
 	m = map_first(gpt);
 	while (m != NULL) {
 		switch (m->map_type) {



Re: CVS commit: src/sbin/gpt

2015-11-30 Thread John Nemeth
On Nov 30,  9:03pm, "Christos Zoulas" wrote:
}
} This is a multi-part message in MIME format.
} 
} --_--=_1448935435147560
} Content-Disposition: inline
} Content-Transfer-Encoding: 8bit
} Content-Type: text/plain; charset="US-ASCII"
} 
} Module Name:  src
} Committed By: christos
} Date: Tue Dec  1 02:03:55 UTC 2015
} 
} Modified Files:
}   src/sbin/gpt: add.c gpt.c resize.c
} 
} Log Message:
} - use gpt_msg to print informational messages (perhaps these should be printed
}   only with -v)
} - don't print any messages with gpt_msg if quiet
} - print a message if we didn't reconfigure the wedges
} 
} 
} To generate a diff of this commit:
} cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/add.c
} cvs rdiff -u -r1.47 -r1.48 src/sbin/gpt/gpt.c
} cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/resize.c
} 
} Please note that diffs are not public domain; they are subject to the
} copyright notices on the relevant files.
} 
} 
} --_--=_1448935435147560
} Content-Disposition: inline
} Content-Length: 2767
} Content-Transfer-Encoding: binary
} Content-Type: text/x-diff; charset=us-ascii
} 
} Modified files:
} 
} Index: src/sbin/gpt/gpt.c
} diff -u src/sbin/gpt/gpt.c:1.47 src/sbin/gpt/gpt.c:1.48
} --- src/sbin/gpt/gpt.c:1.47   Mon Nov 30 20:49:23 2015
} +++ src/sbin/gpt/gpt.cMon Nov 30 21:03:55 2015
} @@ -573,15 +573,22 @@ void
}  gpt_close(int fd)
}  {
}  
} - if (modified && !nosync) {
} + if (!modified)
} + goto out;
} +
} + if (!nosync) {
}  #ifdef DIOCMWEDGES
}   int bits;
}   if (ioctl(fd, DIOCMWEDGES, &bits) == -1)
}   warn("Can't update wedge information");
} + else
} + goto out;
}  #endif
}   }
} + gpt_msg("You need to run \"dkctl %s makewedges\""
} + " for the changes to take effect\n", device_name);

 dkctl makewedges is just ioctl(DIOCMWEDGES), so if DIOCMWEDGES
doesn't exist or it fails, then dkctl makewedges won't do anything,
which means that the user would either need to use dkctl add, etc.,
or reboot.

}  
} - /* XXX post processing? */
} +out:
}   close(fd);
}  }
}  
} --_--=_1448935435147560--
} 
}-- End of excerpt from "Christos Zoulas"


<    1   2   3