CVS commit: src/sbin/gpt

2024-06-10 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Jun 10 09:17:29 UTC 2024

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

Log Message:
Revert unintended commit.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.88 -r1.89 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.8
diff -u src/sbin/gpt/gpt.8:1.81 src/sbin/gpt/gpt.8:1.82
--- src/sbin/gpt/gpt.8:1.81	Mon Jun 10 08:04:44 2024
+++ src/sbin/gpt/gpt.8	Mon Jun 10 09:17:29 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.81 2024/06/10 08:04:44 kre Exp $
+.\" $NetBSD: gpt.8,v 1.82 2024/06/10 09:17:29 kre Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -629,15 +629,6 @@ and are not currently used by
 They may be used by
 .Nx
 in the future.
-In addition, the notation
-.Ar bit Ns NN ,
-where NN is an integer in the range 48..63 (inclusive)
-allows any of the file-system type specific attribute bits
-to be set.
-This is a hack, and is likely to be changed in a later
-revision, when the ability to set (and decode) attributes
-that are specific to a specific owning partition type is
-added.
 .\"  show 
 .It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc
 The

Index: src/sbin/gpt/gpt.c
diff -u src/sbin/gpt/gpt.c:1.88 src/sbin/gpt/gpt.c:1.89
--- src/sbin/gpt/gpt.c:1.88	Mon Jun 10 08:04:44 2024
+++ src/sbin/gpt/gpt.c	Mon Jun 10 09:17:29 2024
@@ -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.88 2024/06/10 08:04:44 kre Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.89 2024/06/10 09:17:29 kre Exp $");
 #endif
 
 #include 
@@ -1221,30 +1221,8 @@ gpt_attr_get(gpt_t gpt, uint64_t *attrib
 			if (strcmp(gpt_attr[i].name, ptr) == 0)
 break;
 		if (i == __arraycount(gpt_attr)) {
-			long bit;
-			char *ep;
-
-			/*
-			 * XXX
-			 * Allow bitNN for 48 <= NN <= 63
-			 * so the partition type specific bits
-			 * can be accessed (set/cleared) 
-			 *
-			 * This should be fixed so the partition type
-			 * specific bits can be given names, which apply
-			 * only for the appropriate partition type.
-			 */
-			if (strncasecmp(ptr, "bit", 3) == 0 &&
-			isdigit((int)(unsigned char)ptr[3]) &&
-			(bit = strtol(ptr + 3, , 10)) >= 48 &&
-			bit <= 63 &&
-			*ep == '\0') {
-*attributes |= 1ULL << (unsigned)bit;
-			} else {
-gpt_warnx(gpt,
-"Unrecognized attribute `%s'", ptr);
-rv = -1;
-			}
+			gpt_warnx(gpt, "Unrecognized attribute `%s'", ptr);
+			rv = -1;
 		} else
 			*attributes |= gpt_attr[i].mask;
 	}
@@ -1296,7 +1274,7 @@ gpt_attr_list(char *buf, size_t len, uin
 	 * (it does build however).
 	 */
 			if (gpt_attr[i].mask & (gpt_attr[i].mask - 1)) {
-/* This only happens in bits 48..63 */
+/* This only happens in bits 46..63 */
 
 /*
  * xbuf is big enough for "=65535\0"



CVS commit: src/sbin/gpt

2024-06-10 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Jun 10 09:17:29 UTC 2024

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

Log Message:
Revert unintended commit.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.88 -r1.89 src/sbin/gpt/gpt.c

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



CVS commit: src/sbin/gpt

2024-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb  6 20:25:11 UTC 2024

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

Log Message:
check the right variable


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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/resizedisk.c
diff -u src/sbin/gpt/resizedisk.c:1.20 src/sbin/gpt/resizedisk.c:1.21
--- src/sbin/gpt/resizedisk.c:1.20	Mon Nov 21 19:25:52 2022
+++ src/sbin/gpt/resizedisk.c	Tue Feb  6 15:25:11 2024
@@ -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.20 2022/11/22 00:25:52 mlelstv Exp $");
+__RCSID("$NetBSD: resizedisk.c,v 1.21 2024/02/06 20:25:11 christos Exp $");
 #endif
 
 #include 
@@ -107,7 +107,7 @@ resizedisk(gpt_t gpt, off_t sector, off_
 mbr = mbrmap->map_data;
 
 	gpt->gpt = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
-	if (gpt == NULL) {
+	if (gpt->gpt == NULL) {
 		gpt_warnx(gpt, "No primary GPT header; run create or recover");
 		return -1;
 	}



CVS commit: src/sbin/gpt

2024-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb  6 20:25:11 UTC 2024

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

Log Message:
check the right variable


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

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



CVS commit: src/sbin/gpt

2023-12-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 13 06:51:57 UTC 2023

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

Log Message:
avoid use after free.  skip the QUIET check already in gpt_warn().


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/sbin/gpt/gpt.c:1.87
--- src/sbin/gpt/gpt.c:1.86	Mon Dec 11 12:45:22 2023
+++ src/sbin/gpt/gpt.c	Wed Dec 13 06:51:57 2023
@@ -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.86 2023/12/11 12:45:22 mlelstv Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.87 2023/12/13 06:51:57 mrg Exp $");
 #endif
 
 #include 
@@ -604,9 +604,8 @@ gpt_open(const char *dev, int flags, int
  close:
 	if (gpt->fd != -1)
 		close(gpt->fd);
+	gpt_warn(gpt, "No GPT found");
 	free(gpt);
-	if (!(flags & GPT_QUIET))
-		gpt_warn(gpt, "No GPT found");
 	return NULL;
 }
 



CVS commit: src/sbin/gpt

2023-12-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 13 06:51:57 UTC 2023

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

Log Message:
avoid use after free.  skip the QUIET check already in gpt_warn().


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

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



CVS commit: src/sbin/gpt

2023-12-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Dec 11 12:45:22 UTC 2023

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

Log Message:
Be verbose about errors.


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

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



CVS commit: src/sbin/gpt

2023-12-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Dec 11 12:45:22 UTC 2023

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

Log Message:
Be verbose about errors.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 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.85 src/sbin/gpt/gpt.c:1.86
--- src/sbin/gpt/gpt.c:1.85	Tue Sep 26 15:55:46 2023
+++ src/sbin/gpt/gpt.c	Mon Dec 11 12:45:22 2023
@@ -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.85 2023/09/26 15:55:46 kre Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.86 2023/12/11 12:45:22 mlelstv Exp $");
 #endif
 
 #include 
@@ -386,8 +386,10 @@ gpt_gpt(gpt_t gpt, off_t lba, int found)
 	uint32_t crc;
 
 	hdr = gpt_read(gpt, lba, 1);
-	if (hdr == NULL)
+	if (hdr == NULL) {
+		gpt_warn(gpt, "Read failed");
 		return -1;
+	}
 
 	if (memcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)))
 		goto fail_hdr;
@@ -540,6 +542,7 @@ gpt_open(const char *dev, int flags, int
 			gpt->secsz = 512;	/* Fixed size for files. */
 		if (gpt->mediasz == 0) {
 			if (gpt->sb.st_size % gpt->secsz) {
+gpt_warn(gpt, "Media size not a multiple of sector size (%u)\n", gpt->secsz);
 errno = EINVAL;
 goto close;
 			}
@@ -602,6 +605,8 @@ gpt_open(const char *dev, int flags, int
 	if (gpt->fd != -1)
 		close(gpt->fd);
 	free(gpt);
+	if (!(flags & GPT_QUIET))
+		gpt_warn(gpt, "No GPT found");
 	return NULL;
 }
 



CVS commit: src/sbin/gpt

2023-12-05 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Tue Dec  5 17:23:20 UTC 2023

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

Log Message:
Fix an incorrect comment.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/map.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/map.c
diff -u src/sbin/gpt/map.c:1.15 src/sbin/gpt/map.c:1.16
--- src/sbin/gpt/map.c:1.15	Sun May 24 14:42:44 2020
+++ src/sbin/gpt/map.c	Tue Dec  5 17:23:19 2023
@@ -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.15 2020/05/24 14:42:44 jmcneill Exp $");
+__RCSID("$NetBSD: map.c,v 1.16 2023/12/05 17:23:19 tsutsui Exp $");
 #endif
 
 #include 
@@ -257,7 +257,7 @@ map_resize(gpt_t gpt, map_t m, off_t siz
 		gpt_warnx(gpt, "negative size or alignment");
 		return -1;
 	}
-	/* Size == 0 means delete, if the next map is unused */
+	/* Size == 0 means to use whole region of the following unused map */
 	if (size == 0) { 
 		if (n == NULL) {
 			// XXX: we could just turn the map to UNUSED!



CVS commit: src/sbin/gpt

2023-12-05 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Tue Dec  5 17:23:20 UTC 2023

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

Log Message:
Fix an incorrect comment.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/map.c

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



CVS commit: src/sbin/gpt

2023-11-06 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Nov  7 00:53:39 UTC 2023

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

Log Message:
gpt.8: fix grammar in a sentence


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sbin/gpt/gpt.8:1.80
--- src/sbin/gpt/gpt.8:1.79	Tue Oct 31 12:09:48 2023
+++ src/sbin/gpt/gpt.8	Tue Nov  7 00:53:39 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.79 2023/10/31 12:09:48 martin Exp $
+.\" $NetBSD: gpt.8,v 1.80 2023/11/07 00:53:39 gutteridge Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -659,7 +659,7 @@ option, all information for all GPT part
 .Fl i Ar index )
 will be printed.
 None of the options have any effect on non-GPT partitions.
-The order of precedence for the options are:
+The order of precedence for the options is:
 .Fl a ,
 .Fl i ,
 .Fl l ,



CVS commit: src/sbin/gpt

2023-11-06 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Nov  7 00:53:39 UTC 2023

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

Log Message:
gpt.8: fix grammar in a sentence


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

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



CVS commit: src/sbin/gpt

2023-10-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct 31 12:09:48 UTC 2023

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

Log Message:
Apply patch from Thierry Laronde: add missing suffixes for size values
and clarify that they are case independant.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sbin/gpt/gpt.8:1.79
--- src/sbin/gpt/gpt.8:1.78	Sat Jul 15 21:18:06 2023
+++ src/sbin/gpt/gpt.8	Tue Oct 31 12:09:48 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.78 2023/07/15 21:18:06 gutteridge Exp $
+.\" $NetBSD: gpt.8,v 1.79 2023/10/31 12:09:48 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -160,7 +160,7 @@ or
 .Sq S
 then size is in sectors, otherwise size is in bytes which must be
 a multiple of the device's sector size.
-Accepted suffix units are
+Accepted suffix units (case insensitive) are
 .Sq b
 to denote bytes,
 .Sq k
@@ -168,7 +168,13 @@ to denote kilobytes,
 .Sq m
 to denote megabytes and
 .Sq g
-to denote gigabytes.
+to denote gigabytes,
+.Sq t
+to denote terabytes,
+.Sq p
+to denote petabytes, and
+.Sq e
+to denote exabytes.
 The minimum size is 1 sector.
 .Pp
 The



CVS commit: src/sbin/gpt

2023-10-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct 31 12:09:48 UTC 2023

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

Log Message:
Apply patch from Thierry Laronde: add missing suffixes for size values
and clarify that they are case independant.


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

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



Re: CVS commit: src/sbin/gpt

2023-09-27 Thread Robert Elz
Date:Wed, 27 Sep 2023 09:44:10 +
From:"Taylor R Campbell" 
Message-ID:  <20230927094410.b9257f...@cvs.netbsd.org>

  | gpt(8): Make gpt type array and enum match again.

Thanks, and apologies for not checking that better - I did test
that it recognised the new one properly...

kre




CVS commit: src/sbin/gpt

2023-09-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Sep 27 09:44:10 UTC 2023

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

Log Message:
gpt(8): Make gpt type array and enum match again.

Add cross-referencing comment to reduce the probability of these
getting out of sync again.

Should fix a slew of failing tests since kre's recent change to add
windows-recovery to the array but not to the enum:

sbin/gpt/t_gpt:create_2part
sbin/gpt/t_gpt:migrate_disklabel
sbin/gpt/t_gpt:recover_backup
sbin/gpt/t_gpt:recover_primary
sbin/gpt/t_gpt:remove_2part
sbin/gpt/t_gpt:resize_2part
sbin/gpt/t_gpt:restore_2part

Fail: stdout does not match golden output
--- /usr/tests/sbin/gpt/gpt.2part.show.normal   2023-09-26 15:48:30.0 
+
+++ /tmp/check.sc6ylB/stdout2023-09-26 23:30:42.388157924 
+
@@ -3,6 +3,6 @@
   1  1 Pri GPT header
   2 32 Pri GPT table
  34   1024  1  GPT part - EFI System
-   1058   9150  2  GPT part - NetBSD FFSv1/FFSv2
+   1058   9150  2  GPT part - NetBSD Cryptographic Disk
   10208 32 Sec GPT table
   10240  1 Sec GPT header

https://releng.netbsd.org/b5reports/i386/commits-2023.09.html#build-2023.09.26.15.47.11


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sbin/gpt/gpt_uuid.c
cvs rdiff -u -r1.9 -r1.10 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.



CVS commit: src/sbin/gpt

2023-09-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Sep 27 09:44:10 UTC 2023

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

Log Message:
gpt(8): Make gpt type array and enum match again.

Add cross-referencing comment to reduce the probability of these
getting out of sync again.

Should fix a slew of failing tests since kre's recent change to add
windows-recovery to the array but not to the enum:

sbin/gpt/t_gpt:create_2part
sbin/gpt/t_gpt:migrate_disklabel
sbin/gpt/t_gpt:recover_backup
sbin/gpt/t_gpt:recover_primary
sbin/gpt/t_gpt:remove_2part
sbin/gpt/t_gpt:resize_2part
sbin/gpt/t_gpt:restore_2part

Fail: stdout does not match golden output
--- /usr/tests/sbin/gpt/gpt.2part.show.normal   2023-09-26 15:48:30.0 
+
+++ /tmp/check.sc6ylB/stdout2023-09-26 23:30:42.388157924 
+
@@ -3,6 +3,6 @@
   1  1 Pri GPT header
   2 32 Pri GPT table
  34   1024  1  GPT part - EFI System
-   1058   9150  2  GPT part - NetBSD FFSv1/FFSv2
+   1058   9150  2  GPT part - NetBSD Cryptographic Disk
   10208 32 Sec GPT table
   10240  1 Sec GPT header

https://releng.netbsd.org/b5reports/i386/commits-2023.09.html#build-2023.09.26.15.47.11


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sbin/gpt/gpt_uuid.c
cvs rdiff -u -r1.9 -r1.10 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.20 src/sbin/gpt/gpt_uuid.c:1.21
--- src/sbin/gpt/gpt_uuid.c:1.20	Tue Sep 26 15:48:30 2023
+++ src/sbin/gpt/gpt_uuid.c	Wed Sep 27 09:44:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.c,v 1.20 2023/09/26 15:48:30 kre Exp $	*/
+/*	$NetBSD: gpt_uuid.c,v 1.21 2023/09/27 09:44:10 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.20 2023/09/26 15:48:30 kre Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.21 2023/09/27 09:44:10 riastradh Exp $");
 #endif
 
 #include 
@@ -65,6 +65,7 @@ static const struct {
 	const char *n;
 	const char *d;
 } gpt_nv[] = {
+	/* Must match the gpt_type_t enum in gpt_uuid.h */
 	{ GPT_ENT_TYPE_APPLE_HFS, "apple", "Apple HFS" },
 	{ GPT_ENT_TYPE_APPLE_UFS, "apple-ufs", "Apple UFS" },
 	{ GPT_ENT_TYPE_BIOS, "bios", "BIOS Boot" },

Index: src/sbin/gpt/gpt_uuid.h
diff -u src/sbin/gpt/gpt_uuid.h:1.9 src/sbin/gpt/gpt_uuid.h:1.10
--- src/sbin/gpt/gpt_uuid.h:1.9	Sun Jun 30 11:38:16 2019
+++ src/sbin/gpt/gpt_uuid.h	Wed Sep 27 09:44:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.h,v 1.9 2019/06/30 11:38:16 sevan Exp $	*/
+/*	$NetBSD: gpt_uuid.h,v 1.10 2023/09/27 09:44:10 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  * support anyway
  */
 
-// Must match the array in gpt_uuid.c
+/* Must match the gpt_nv array in gpt_uuid.c */
 typedef enum {
 	GPT_TYPE_INVALID = -1,
 	GPT_TYPE_APPLE_HFS = 0,
@@ -64,6 +64,7 @@ typedef enum {
 	GPT_TYPE_LINUX_LVM,
 	GPT_TYPE_MS_BASIC_DATA,
 	GPT_TYPE_MS_RESERVED,
+	GPT_TYPE_MS_RECOVERY,
 	GPT_TYPE_NETBSD_CCD,
 	GPT_TYPE_NETBSD_CGD,
 	GPT_TYPE_NETBSD_FFS,



CVS commit: src/sbin/gpt

2023-09-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Sep 26 15:55:46 UTC 2023

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

Log Message:
When extracting the attributes (to printable form), avoid simply ignoring
any attribute bits which are unknown, print them as a hex value.  This
avoids "Attributes: " for most windows filesystem types, which all seem
to have but 63 set (which is supposed to mean "don't assign a drive letter"
which is akin to "noauto" in fstab - except it is set even on partitions
which do get mounted, so must mean something subtly different).

These upper 16 attribute bits are supposed to be file system type speficic
(in practice, they seem to be common to all filesystem types from one vendor)
but we don't have the info (yet anyway) to treat them like that.

ChromeOS seems to treat some of the bits as bit fields containing numeric
values - add #if 0'd (but compile tested) code to deal with those (maybe,
compile tested - but not execution tested) should someone ever get an
environment where these things occur, and could add the missing definitions
to actually test this.


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

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



CVS commit: src/sbin/gpt

2023-09-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Sep 26 15:55:46 UTC 2023

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

Log Message:
When extracting the attributes (to printable form), avoid simply ignoring
any attribute bits which are unknown, print them as a hex value.  This
avoids "Attributes: " for most windows filesystem types, which all seem
to have but 63 set (which is supposed to mean "don't assign a drive letter"
which is akin to "noauto" in fstab - except it is set even on partitions
which do get mounted, so must mean something subtly different).

These upper 16 attribute bits are supposed to be file system type speficic
(in practice, they seem to be common to all filesystem types from one vendor)
but we don't have the info (yet anyway) to treat them like that.

ChromeOS seems to treat some of the bits as bit fields containing numeric
values - add #if 0'd (but compile tested) code to deal with those (maybe,
compile tested - but not execution tested) should someone ever get an
environment where these things occur, and could add the missing definitions
to actually test this.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/sbin/gpt/gpt.c:1.85
--- src/sbin/gpt/gpt.c:1.84	Tue Nov 22 00:25:52 2022
+++ src/sbin/gpt/gpt.c	Tue Sep 26 15:55:46 2023
@@ -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.84 2022/11/22 00:25:52 mlelstv Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.85 2023/09/26 15:55:46 kre Exp $");
 #endif
 
 #include 
@@ -1239,13 +1239,62 @@ const char *
 gpt_attr_list(char *buf, size_t len, uint64_t attributes)
 {
 	size_t i;
+	/*
+	 * a uint64_t (attributes) has at most 16 hex digits
+	 * in its representation, add 2 for "0x", and 2 more
+	 * for surrounding [ ], plus one for a trailing \0,
+	 * and we need 21 bytes, round that up to 24
+	 */
+	char xbuf[24];
+
 	strlcpy(buf, "", len);	
 
-	for (i = 0; i < __arraycount(gpt_attr); i++)
+	for (i = 0; i < __arraycount(gpt_attr); i++) {
+		/*
+		 * if the attribute is specified in one of bits
+		 * 48..63, it should depend upon the defining
+		 * partition type for that attribute.   Currently
+		 * we have no idea what that is, so...
+		 *
+		 * Also note that for some partition types, these
+		 * fields are not a single bit boolean, but several
+		 * bits to form a numeric value.  That we could handle.
+		 */
+
 		if (attributes & gpt_attr[i].mask) {
 			strlcat(buf, buf[0] ? ", " : "", len); 
 			strlcat(buf, gpt_attr[i].name, len);
+#if 0
+	/*
+	 * there are none currently defined, so this is untestable
+	 * (it does build however).
+	 */
+			if (gpt_attr[i].mask & (gpt_attr[i].mask - 1)) {
+/* This only happens in bits 46..63 */
+
+/*
+ * xbuf is big enough for "=65535\0"
+ * which is the biggest possible value
+ */
+snprintf(xbuf, sizeof xbuf, "=%ju",
+(uintmax_t) (
+  (attributes & gpt_attr[i].mask) >>
+  (ffs((int)(gpt_attr[i].mask >> 48)) + 47)
+));
+
+strlcat(buf, xbuf, len);
+			}
+#endif
+			attributes &=~ gpt_attr[i].mask;
 		}
+	}
+
+	if (attributes != 0) {
+		snprintf(xbuf, sizeof xbuf, "[%#jx]", (uintmax_t)attributes);
+		strlcat(buf, buf[0] ? ", " : "", len);
+		strlcat(buf, xbuf, len);
+	}
+
 	return buf;
 }
 



CVS commit: src/sbin/gpt

2023-09-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Sep 26 15:48:31 UTC 2023

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

Log Message:
Recognise Windows Recovery partitions.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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.19 src/sbin/gpt/gpt_uuid.c:1.20
--- src/sbin/gpt/gpt_uuid.c:1.19	Mon Mar 30 10:41:53 2020
+++ src/sbin/gpt/gpt_uuid.c	Tue Sep 26 15:48:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $	*/
+/*	$NetBSD: gpt_uuid.c,v 1.20 2023/09/26 15:48:30 kre Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.20 2023/09/26 15:48:30 kre Exp $");
 #endif
 
 #include 
@@ -80,6 +80,7 @@ static const struct {
 	{ GPT_ENT_TYPE_LINUX_LVM, "linux-lvm", "Linux LVM" },
 	{ GPT_ENT_TYPE_MS_BASIC_DATA, "windows", "Windows basic data" },
 	{ GPT_ENT_TYPE_MS_RESERVED, "windows-reserved", "Windows reserved" },
+	{ GPT_ENT_TYPE_MS_RECOVERY, "windows-recovery", "Windows recovery" },
 	{ 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" },



CVS commit: src/sbin/gpt

2023-09-26 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Sep 26 15:48:31 UTC 2023

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

Log Message:
Recognise Windows Recovery partitions.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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.



CVS commit: src/sbin/gpt

2023-07-15 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sat Jul 15 21:18:07 UTC 2023

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

Log Message:
gpt.8: fix some grammar

(The BUGS section seems perhaps a little outdated in its warnings of
potential incompatible changes.)


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sbin/gpt/gpt.8:1.78
--- src/sbin/gpt/gpt.8:1.77	Sat Jul 15 21:11:58 2023
+++ src/sbin/gpt/gpt.8	Sat Jul 15 21:18:06 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.77 2023/07/15 21:11:58 gutteridge Exp $
+.\" $NetBSD: gpt.8,v 1.78 2023/07/15 21:18:06 gutteridge Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -174,7 +174,7 @@ The minimum size is 1 sector.
 The
 .Fl t Ar type
 option allows the user to specify the partition type.
-The type is given as an UUID, but
+The type is given as a UUID, but
 .Nm
 accepts
 .Bl -tag -width "windows-reserved" -compact -offset indent
@@ -381,7 +381,7 @@ This can cause multiple partitions to be
 The
 .Fl t Ar type
 option selects all partitions that have the given type.
-The type is given as an UUID or by the aliases that the
+The type is given as a UUID or by the aliases that the
 .Ic add
 command accepts.
 This can cause multiple partitions to be labeled.
@@ -639,7 +639,7 @@ option the GPT partition label will be d
 type.
 With the
 .Fl u
-option the GPT partition type is displayed as an UUID instead of in a
+option the GPT partition type is displayed as a UUID instead of in a
 user friendly form.
 With the
 .Fl i
@@ -826,7 +826,7 @@ However, it is believed that the current
 and stable enough that this tool can be used without bullet-proof footware if
 one thinks one does not make mistakes.
 .Pp
-It is expected that the basic usage model does not change, but it is
+It is expected that the basic usage model will not change, but it is
 possible that future versions will not be compatible in the strictest sense
 of the word.
 Also, options primarily intended for diagnostic or debug purposes may be



CVS commit: src/sbin/gpt

2023-07-15 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sat Jul 15 21:18:07 UTC 2023

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

Log Message:
gpt.8: fix some grammar

(The BUGS section seems perhaps a little outdated in its warnings of
potential incompatible changes.)


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

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



CVS commit: src/sbin/gpt

2023-07-15 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sat Jul 15 21:11:58 UTC 2023

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

Log Message:
gpt.8: drop cross-reference to cvs(1)

It's no more useful to reference cvs(1) than, say, openssl(1), and
should be self-evident, anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 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.76 src/sbin/gpt/gpt.8:1.77
--- src/sbin/gpt/gpt.8:1.76	Thu Apr  7 13:57:44 2022
+++ src/sbin/gpt/gpt.8	Sat Jul 15 21:11:58 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.76 2022/04/07 13:57:44 kre Exp $
+.\" $NetBSD: gpt.8,v 1.77 2023/07/15 21:11:58 gutteridge 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 April 7, 2022
+.Dd July 15, 2023
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -59,11 +59,6 @@ tables
 but see
 .Sx BUGS
 below for how and where functionality is missing.
-The basic usage model of the
-.Nm
-tool follows that of the
-.Xr cvs 1
-tool.
 The general options are described in the following paragraph.
 The remaining paragraphs describe the individual commands with their options.
 Here we conclude by mentioning that a



CVS commit: src/sbin/gpt

2023-07-15 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sat Jul 15 21:11:58 UTC 2023

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

Log Message:
gpt.8: drop cross-reference to cvs(1)

It's no more useful to reference cvs(1) than, say, openssl(1), and
should be self-evident, anyway.


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

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



CVS commit: src/sbin/gpt

2022-11-21 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Nov 22 00:25:52 UTC 2022

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

Log Message:
Big-Endian fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.19 -r1.20 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.c
diff -u src/sbin/gpt/gpt.c:1.83 src/sbin/gpt/gpt.c:1.84
--- src/sbin/gpt/gpt.c:1.83	Sun Nov 20 11:57:02 2022
+++ src/sbin/gpt/gpt.c	Tue Nov 22 00:25:52 2022
@@ -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.83 2022/11/20 11:57:02 mlelstv Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.84 2022/11/22 00:25:52 mlelstv Exp $");
 #endif
 
 #include 
@@ -578,6 +578,7 @@ gpt_open(const char *dev, int flags, int
 	if (found) {
 		struct map *map;
 		struct gpt_hdr *hdr;
+		uint64_t lba;
 
 		/*
 		 * read secondary GPT from position stored in primary header
@@ -585,8 +586,9 @@ gpt_open(const char *dev, int flags, int
 		 */
 		map = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
 		hdr = map ? map->map_data : NULL;
-		if (hdr && hdr->hdr_lba_alt > 0 && hdr->hdr_lba_alt < (uint64_t)devsz) {
-			if (gpt_gpt(gpt, (off_t)hdr->hdr_lba_alt, found) == -1)
+		lba = le64toh(hdr->hdr_lba_alt);
+		if (hdr && lba > 0 && lba < (uint64_t)devsz) {
+			if (gpt_gpt(gpt, (off_t)lba, found) == -1)
 goto close;
 		}
 	} else {

Index: src/sbin/gpt/resizedisk.c
diff -u src/sbin/gpt/resizedisk.c:1.19 src/sbin/gpt/resizedisk.c:1.20
--- src/sbin/gpt/resizedisk.c:1.19	Sun Nov 20 11:57:02 2022
+++ src/sbin/gpt/resizedisk.c	Tue Nov 22 00:25:52 2022
@@ -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.19 2022/11/20 11:57:02 mlelstv Exp $");
+__RCSID("$NetBSD: resizedisk.c,v 1.20 2022/11/22 00:25:52 mlelstv Exp $");
 #endif
 
 #include 
@@ -194,7 +194,7 @@ resizedisk(gpt_t gpt, off_t sector, off_
 	}
 
 	hdr = gpt->gpt->map_data;
-	hdr->hdr_lba_alt = (uint64_t)gpt->tpg->map_start;
+	hdr->hdr_lba_alt = htole64((uint64_t)gpt->tpg->map_start);
 	hdr->hdr_crc_self = 0;
 	hdr->hdr_lba_end = htole64((uint64_t)(gpt->lbt->map_start - 1));
 	hdr->hdr_crc_self =



CVS commit: src/sbin/gpt

2022-11-21 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Nov 22 00:25:52 UTC 2022

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

Log Message:
Big-Endian fixes.


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

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



CVS commit: src/sbin/gpt

2022-11-20 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov 20 11:57:02 UTC 2022

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

Log Message:
Fix destroying and moving GPT header also for truncated/extended
images.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/destroy.c
cvs rdiff -u -r1.82 -r1.83 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.18 -r1.19 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/destroy.c
diff -u src/sbin/gpt/destroy.c:1.13 src/sbin/gpt/destroy.c:1.14
--- src/sbin/gpt/destroy.c:1.13	Wed Oct 16 19:03:53 2019
+++ src/sbin/gpt/destroy.c	Sun Nov 20 11:57:02 2022
@@ -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.13 2019/10/16 19:03:53 jnemeth Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.14 2022/11/20 11:57:02 mlelstv Exp $");
 #endif
 
 #include 
@@ -59,7 +59,7 @@ struct gpt_cmd c_destroy = {
 	"destroy",
 	cmd_destroy,
 	destroyhelp, __arraycount(destroyhelp),
-	GPT_SYNC,
+	GPT_OPTGPT | GPT_SYNC,
 };
 
 #define usage() gpt_usage(NULL, _destroy)

Index: src/sbin/gpt/gpt.c
diff -u src/sbin/gpt/gpt.c:1.82 src/sbin/gpt/gpt.c:1.83
--- src/sbin/gpt/gpt.c:1.82	Sun May 24 18:42:20 2020
+++ src/sbin/gpt/gpt.c	Sun Nov 20 11:57:02 2022
@@ -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.82 2020/05/24 18:42:20 jmcneill Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.83 2022/11/20 11:57:02 mlelstv Exp $");
 #endif
 
 #include 
@@ -574,8 +574,25 @@ gpt_open(const char *dev, int flags, int
 		goto close;
 	if ((found = gpt_gpt(gpt, 1LL, 1)) == -1)
 		goto close;
-	if (gpt_gpt(gpt, devsz - 1LL, found) == -1)
-		goto close;
+
+	if (found) {
+		struct map *map;
+		struct gpt_hdr *hdr;
+
+		/*
+		 * read secondary GPT from position stored in primary header
+		 * when possible
+		 */
+		map = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
+		hdr = map ? map->map_data : NULL;
+		if (hdr && hdr->hdr_lba_alt > 0 && hdr->hdr_lba_alt < (uint64_t)devsz) {
+			if (gpt_gpt(gpt, (off_t)hdr->hdr_lba_alt, found) == -1)
+goto close;
+		}
+	} else {
+		if (gpt_gpt(gpt, devsz - 1LL, found) == -1)
+			goto close;
+	}
 
 	return gpt;
 

Index: src/sbin/gpt/gpt.h
diff -u src/sbin/gpt/gpt.h:1.43 src/sbin/gpt/gpt.h:1.44
--- src/sbin/gpt/gpt.h:1.43	Sat Jul 16 12:57:14 2022
+++ src/sbin/gpt/gpt.h	Sun Nov 20 11:57:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt.h,v 1.43 2022/07/16 12:57:14 mlelstv Exp $	*/
+/*	$NetBSD: gpt.h,v 1.44 2022/11/20 11:57:02 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -85,6 +85,7 @@ gpt_t	gpt_open(const char *, int, int, o
 #define GPT_TIMESTAMP	0x20
 #define GPT_SYNC	0x40
 #define GPT_HYBRID	0x80
+#define GPT_OPTGPT	0x4000
 #define GPT_OPTDEV	0x8000
 
 void*	gpt_read(gpt_t, off_t, size_t);

Index: src/sbin/gpt/resizedisk.c
diff -u src/sbin/gpt/resizedisk.c:1.18 src/sbin/gpt/resizedisk.c:1.19
--- src/sbin/gpt/resizedisk.c:1.18	Sun May 24 14:42:44 2020
+++ src/sbin/gpt/resizedisk.c	Sun Nov 20 11:57:02 2022
@@ -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.18 2020/05/24 14:42:44 jmcneill Exp $");
+__RCSID("$NetBSD: resizedisk.c,v 1.19 2022/11/20 11:57:02 mlelstv Exp $");
 #endif
 
 #include 
@@ -62,7 +62,7 @@ struct gpt_cmd c_resizedisk = {
 	"resizedisk",
 	cmd_resizedisk,
 	resizediskhelp, __arraycount(resizediskhelp),
-	0,
+	GPT_OPTGPT,
 };
 
 #define usage() gpt_usage(NULL, _resizedisk)
@@ -123,25 +123,9 @@ resizedisk(gpt_t gpt, off_t sector, off_
 
 	gpt->tpg = map_find(gpt, MAP_TYPE_SEC_GPT_HDR);
 	gpt->lbt = map_find(gpt, MAP_TYPE_SEC_GPT_TBL);
-	if (gpt->tpg == NULL || gpt->lbt == NULL) {
-		if (gpt_gpt(gpt, oldloc, 1) == -1) {
-			gpt_warnx(gpt,
-			"Error reading backup GPT information at %#jx",
-			oldloc);
-			return -1;
-		}
-	}
 
-	gpt->tpg = map_find(gpt, MAP_TYPE_SEC_GPT_HDR);
-	if (gpt->tpg == NULL) {
-		gpt_warnx(gpt, "No secondary GPT header; Run recover");
-		return -1;
-	}
-	gpt->lbt = map_find(gpt, MAP_TYPE_SEC_GPT_TBL);
-	if (gpt->lbt == NULL) {
-		gpt_warnx(gpt, "No secondary GPT table; Run recover");
-		return -1;
-	}
+	if (gpt->tpg == NULL || gpt->lbt == NULL)
+		gpt_warnx(gpt, "No secondary GPT table");
 
 	gpt_size = gpt->tbl->map_size;
 	if (sector == oldloc) {
@@ -153,7 +137,8 @@ resizedisk(gpt_t gpt, off_t sector, off_
 	if (sector == 0 && last == oldloc) {
 		if (!quiet)
 			gpt_warnx(gpt, "Device hasn't changed size");
-		return 0;
+		if (gpt->tpg != NULL && gpt->lbt != NULL)
+			return 0;
 	}
 
 	for (ent = gpt->tbl->map_data; ent <
@@ -183,18 +168,14 @@ resizedisk(gpt_t gpt, off_t sector, off_
 	if (sector == 0 && last > 

CVS commit: src/sbin/gpt

2022-11-20 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov 20 11:57:02 UTC 2022

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

Log Message:
Fix destroying and moving GPT header also for truncated/extended
images.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/destroy.c
cvs rdiff -u -r1.82 -r1.83 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/resizedisk.c

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



CVS commit: src/sbin/gpt

2022-07-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jul 16 12:57:14 UTC 2022

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

Log Message:
Whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/gpt.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.h
diff -u src/sbin/gpt/gpt.h:1.42 src/sbin/gpt/gpt.h:1.43
--- src/sbin/gpt/gpt.h:1.42	Sun May 24 18:42:20 2020
+++ src/sbin/gpt/gpt.h	Sat Jul 16 12:57:14 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt.h,v 1.42 2020/05/24 18:42:20 jmcneill Exp $	*/
+/*	$NetBSD: gpt.h,v 1.43 2022/07/16 12:57:14 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -85,7 +85,7 @@ gpt_t	gpt_open(const char *, int, int, o
 #define GPT_TIMESTAMP	0x20
 #define GPT_SYNC	0x40
 #define GPT_HYBRID	0x80
-#define GPT_OPTDEV  0x8000
+#define GPT_OPTDEV	0x8000
 
 void*	gpt_read(gpt_t, off_t, size_t);
 off_t	gpt_last(gpt_t);



CVS commit: src/sbin/gpt

2022-07-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jul 16 12:57:14 UTC 2022

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

Log Message:
Whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/gpt.h

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



CVS commit: src/sbin/gpt

2022-04-07 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Apr  7 13:57:44 UTC 2022

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

Log Message:
Note that biosboot without -A clears the PMBR "active" flag.
While here, fix some grammar and make the selection options
for biosboot a little clearer.

Ride nia@'s Dd bump.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/sbin/gpt/gpt.8:1.76
--- src/sbin/gpt/gpt.8:1.75	Thu Apr  7 09:06:01 2022
+++ src/sbin/gpt/gpt.8	Thu Apr  7 13:57:44 2022
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.75 2022/04/07 09:06:01 nia Exp $
+.\" $NetBSD: gpt.8,v 1.76 2022/04/07 13:57:44 kre Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -263,28 +263,43 @@ primary bootstrap program, used during
 The
 .Fl A
 options sets the PMBR partition active.
+This should not normally be necessary,
+but some firmware might require it.
+If
+.Fl A
+is omitted, the active flag will be cleared from the PMBR label.
 .Pp
 The
 .Fl c
-option allows the user to specify the filename that
+option allows the user to specify the filename from which
 .Nm
-should read the bootcode from.
+should read the bootcode.
 The default is to read from
 .Pa /usr/mdec/gptmbr.bin .
 .Pp
+The partition that should contain the primary bootstrap code,
+.Pq similar to that installed via Xr installboot 8
+is selected using the
+.Fl i ,
+.Fl L
+and
+.Fl b
+options.
+One of these three options is required.
 The
 .Fl i
-option selects the partition that should contain the primary
-bootstrap code, as installed via
-.Xr installboot 8 .
+option selects the partition given by the
+.Ar index .
 The
 .Fl L
-option selects the partition by label.
-If there are multiple partitions with the same label, the
-first one found will be used.
+option selects the partition by
+.Ar 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.
+option selects the partition starting at block
+.Ar startsec .
 .\"  create 
 .It Nm Ic create Oo Fl AfP Oc Oo Fl p Ar partitions Oc
 The



CVS commit: src/sbin/gpt

2022-04-07 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Apr  7 13:57:44 UTC 2022

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

Log Message:
Note that biosboot without -A clears the PMBR "active" flag.
While here, fix some grammar and make the selection options
for biosboot a little clearer.

Ride nia@'s Dd bump.


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

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



CVS commit: src/sbin/gpt

2022-04-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Apr  7 09:06:01 UTC 2022

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

Log Message:
gpt.8: Clarify that "windows" partition types are also used for FAT32
("msdos" in NetBSD terms), and UDF partitions. Use the same name as
Wikipedia, "Microsoft basic data".


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 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.74 src/sbin/gpt/gpt.8:1.75
--- src/sbin/gpt/gpt.8:1.74	Mon Jul 27 20:54:18 2020
+++ src/sbin/gpt/gpt.8	Thu Apr  7 09:06:01 2022
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.74 2020/07/27 20:54:18 christos Exp $
+.\" $NetBSD: gpt.8,v 1.75 2022/04/07 09:06:01 nia 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 27, 2020
+.Dd April 7, 2022
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -216,9 +216,9 @@ Linux swap
 .It Cm linux-lvm
 Linux LVM
 .It Cm windows
-Windows basic data
+Microsoft basic data - NTFS, FAT32 ("msdos"), FAT16, also used for UDF
 .It Cm windows-reserved
-Windows reserved
+Microsoft reserved
 .It Cm ccd
 .Nx
 ccd component



CVS commit: src/sbin/gpt

2022-04-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Thu Apr  7 09:06:01 UTC 2022

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

Log Message:
gpt.8: Clarify that "windows" partition types are also used for FAT32
("msdos" in NetBSD terms), and UDF partitions. Use the same name as
Wikipedia, "Microsoft basic data".


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

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



CVS commit: src/sbin/gpt

2020-12-13 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Sun Dec 13 21:55:25 UTC 2020

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

Log Message:
PR/55875 - Valentin -- "gpt recover -r" does nothing

Delete do nothing undocumented option, that was there from initial
import.  No idea what it was intended to do and there is no longer
an "upstream".


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/recover.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/recover.c
diff -u src/sbin/gpt/recover.c:1.18 src/sbin/gpt/recover.c:1.19
--- src/sbin/gpt/recover.c:1.18	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/recover.c	Sun Dec 13 21:55:25 2020
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: recover.c,v 1.18 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: recover.c,v 1.19 2020/12/13 21:55:25 jnemeth Exp $");
 #endif
 
 #include 
@@ -149,7 +149,7 @@ recover_gpt_tbl(gpt_t gpt, int type, off
 }
 
 static int
-recover(gpt_t gpt, int recoverable)
+recover(gpt_t gpt)
 {
 	off_t last = gpt_last(gpt);
 	map_t map;
@@ -233,13 +233,9 @@ static int
 cmd_recover(gpt_t gpt, int argc, char *argv[])
 {
 	int ch;
-	int recoverable = 0;
 
 	while ((ch = getopt(argc, argv, "r")) != -1) {
 		switch(ch) {
-		case 'r':
-			recoverable = 1;
-			break;
 		default:
 			return usage();
 		}
@@ -248,5 +244,5 @@ cmd_recover(gpt_t gpt, int argc, char *a
 	if (argc != optind)
 		return usage();
 
-	return recover(gpt, recoverable);
+	return recover(gpt);
 }



CVS commit: src/sbin/gpt

2020-12-13 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Sun Dec 13 21:55:25 UTC 2020

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

Log Message:
PR/55875 - Valentin -- "gpt recover -r" does nothing

Delete do nothing undocumented option, that was there from initial
import.  No idea what it was intended to do and there is no longer
an "upstream".


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

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



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-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.



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.



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) {



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_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-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.



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.



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-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 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.



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.



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, _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-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

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.



CVS commit: src/sbin/gpt

2019-10-16 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Wed Oct 16 19:03:53 UTC 2019

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

Log Message:
Do the 'dkctl makewedges' dance to drop any wedges assoicated the
destroyed GPT.


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

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



CVS commit: src/sbin/gpt

2019-10-16 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Wed Oct 16 19:03:53 UTC 2019

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

Log Message:
Do the 'dkctl makewedges' dance to drop any wedges assoicated the
destroyed GPT.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 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.12 src/sbin/gpt/destroy.c:1.13
--- src/sbin/gpt/destroy.c:1.12	Thu Apr  4 14:03:40 2019
+++ src/sbin/gpt/destroy.c	Wed Oct 16 19:03:53 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.12 2019/04/04 14:03:40 martin Exp $");
+__RCSID("$NetBSD: destroy.c,v 1.13 2019/10/16 19:03:53 jnemeth Exp $");
 #endif
 
 #include 
@@ -59,7 +59,7 @@ struct gpt_cmd c_destroy = {
 	"destroy",
 	cmd_destroy,
 	destroyhelp, __arraycount(destroyhelp),
-	0,
+	GPT_SYNC,
 };
 
 #define usage() gpt_usage(NULL, _destroy)



CVS commit: src/sbin/gpt

2019-10-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 11 23:04:52 UTC 2019

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

Log Message:
gpt_uuid_parse does not set errno ...


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

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



CVS commit: src/sbin/gpt

2019-10-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 11 23:04:52 UTC 2019

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

Log Message:
gpt_uuid_parse does not set errno ...


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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.80 src/sbin/gpt/gpt.c:1.81
--- src/sbin/gpt/gpt.c:1.80	Mon Jun 24 23:50:18 2019
+++ src/sbin/gpt/gpt.c	Fri Oct 11 19:04:52 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.80 2019/06/25 03:50:18 jnemeth Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.81 2019/10/11 23:04:52 christos Exp $");
 #endif
 
 #include 
@@ -1293,7 +1293,7 @@ gpt_uuid_get(gpt_t gpt, gpt_uuid_t *uuid
 	if (!gpt_uuid_is_nil(*uuid))
 		return -1;
 	if (gpt_uuid_parse(optarg, *uuid) != 0) {
-		gpt_warn(gpt, "Can't parse uuid");
+		gpt_warnx(gpt, "Can't parse uuid/type `%s'", optarg);
 		return -1;
 	}
 	return 0;



CVS commit: src/sbin/gpt

2019-07-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 26 07:22:05 UTC 2019

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

Log Message:
Remove outdated note about sysinst restrictions


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 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.69 src/sbin/gpt/gpt.8:1.70
--- src/sbin/gpt/gpt.8:1.69	Tue Jun 25 04:53:40 2019
+++ src/sbin/gpt/gpt.8	Fri Jul 26 07:22:05 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.69 2019/06/25 04:53:40 jnemeth Exp $
+.\" $NetBSD: gpt.8,v 1.70 2019/07/26 07:22:05 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 June 22, 2019
+.Dd July 26, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -758,11 +758,7 @@ nas# gpt show -l wd3
 nas#
 .Ed
 .Pp
-Booting from GPT on an BIOS system.
-This creates a bootable partition that can be manually installed to.
-Note that
-.Xr sysinst 8
-does not yet properly support this setup.
+Booting from GPT on a BIOS system: this creates a bootable partition.
 .Bd -literal
 xotica# gpt create wd1
 xotica# gpt add -b 1024 -l bootroot -t ffs -s 1g wd1
@@ -776,6 +772,10 @@ xotica# installboot /dev/rdk0 /usr/mdec/
 xotica# mount /dev/dk0 /mnt
 xotica# cp /usr/mdec/boot /mnt
 .Ed
+.Pp
+Note that
+.Ic biosboot
+is not needed for UEFI systems.
 .Sh SEE ALSO
 .Xr boot 8 ,
 .Xr dkctl 8 ,



CVS commit: src/sbin/gpt

2019-07-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 26 07:22:05 UTC 2019

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

Log Message:
Remove outdated note about sysinst restrictions


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

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



Re: CVS commit: src/sbin/gpt

2019-06-25 Thread Christos Zoulas
In article <201906250354.x5p3suvz009...@server.cornerstoneservice.ca>,
John Nemeth   wrote:
>On Jun 25,  3:42am, "John Nemeth" wrote:
>} 
>} Module Name: src
>} Committed By:jnemeth
>} Date:Tue Jun 25 03:42:46 UTC 2019
>} 
>} Modified Files:
>}  src/sbin/gpt: gpt.h
>} 
>} Log Message:
>} gpt.c
>
> ARGH!  Message should have read:
>
>Add gpt_change_hdr() similar to gpt_change_ent() for changing
>arbitrary header fields.
>
>Updated in repository.

If you did, then the git sync is broken :-( I guess it is time to turn
off "cvs admin -m"...

christos



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 04:53:41 UTC 2019

Modified Files:
src/sbin/gpt: Makefile gpt.8 main.c
Added Files:
src/sbin/gpt: uuid.c

Log Message:
Add an "uuid" command to generate a new UUID for a portion.  The
primary intention is for use for after cloning disks to prevent
collisions.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/Makefile
cvs rdiff -u -r1.68 -r1.69 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/main.c
cvs rdiff -u -r0 -r1.1 src/sbin/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/Makefile
diff -u src/sbin/gpt/Makefile:1.18 src/sbin/gpt/Makefile:1.19
--- src/sbin/gpt/Makefile:1.18	Thu Dec  3 02:02:43 2015
+++ src/sbin/gpt/Makefile	Tue Jun 25 04:53:40 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.18 2015/12/03 02:02:43 christos Exp $
+# $NetBSD: Makefile,v 1.19 2019/06/25 04:53:40 jnemeth Exp $
 # $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
 
 .include 
@@ -7,7 +7,7 @@ WARNS=6
 PROG=	gpt
 SRCS=	add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \
 	main.c migrate.c recover.c remove.c resize.c resizedisk.c \
-	set.c show.c type.c unset.c gpt_uuid.c
+	set.c show.c type.c unset.c gpt_uuid.c uuid.c
 MAN=	gpt.8
 
 #LINKS=  ${BINDIR}/gpt ${BINDIR}/gptlabel

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.68 src/sbin/gpt/gpt.8:1.69
--- src/sbin/gpt/gpt.8:1.68	Thu Apr  4 13:55:40 2019
+++ src/sbin/gpt/gpt.8	Tue Jun 25 04:53:40 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.68 2019/04/04 13:55:40 martin Exp $
+.\" $NetBSD: gpt.8,v 1.69 2019/06/25 04:53:40 jnemeth 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 April 4, 2019
+.Dd June 22, 2019
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -693,6 +693,25 @@ code.
 They may be used by
 .Nx
 code in the future.
+.\"  uuid 
+.It Nm Ic uuid Oo Fl a Oc
+.It Nm Ic uuid Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \
+Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc
+The
+.Ic uuid
+command allows the user to change the UUID of any and all partitions
+that match the selection.
+It uses the same selection options as the
+.Ic label
+command.
+See above for a description of these options.
+If
+.Fl a
+is used, then the header UUID is changed as well.
+.Pp
+The primary purpose of this command is for use after cloning a disk to
+prevent collisions when both disks are used in the same system.
+.\"  end of commands 
 .El
 .Sh EXIT STATUS
 The

Index: src/sbin/gpt/main.c
diff -u src/sbin/gpt/main.c:1.12 src/sbin/gpt/main.c:1.13
--- src/sbin/gpt/main.c:1.12	Mon Aug 27 15:50:39 2018
+++ src/sbin/gpt/main.c	Tue Jun 25 04:53:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $	*/
+/*	$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $	*/
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $");
+__RCSID("$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $");
 #endif
 
 #include 
@@ -73,7 +73,8 @@ extern const struct gpt_cmd
 	c_set,
 	c_show,
 	c_type,
-	c_unset;
+	c_unset,
+	c_uuid;
 
 static const struct gpt_cmd *cmdsw[] = {
 	_add,
@@ -97,6 +98,7 @@ static const struct gpt_cmd *cmdsw[] = {
 	_show,
 	_type,
 	_unset,
+	_uuid,
 	_null,
 };
 

Added files:

Index: src/sbin/gpt/uuid.c
diff -u /dev/null src/sbin/gpt/uuid.c:1.1
--- /dev/null	Tue Jun 25 04:53:41 2019
+++ src/sbin/gpt/uuid.c	Tue Jun 25 04:53:40 2019
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2004 Marcel Moolenaar
+ * 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 AUTHOR ``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 AUTHOR 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 

CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 04:53:41 UTC 2019

Modified Files:
src/sbin/gpt: Makefile gpt.8 main.c
Added Files:
src/sbin/gpt: uuid.c

Log Message:
Add an "uuid" command to generate a new UUID for a portion.  The
primary intention is for use for after cloning disks to prevent
collisions.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/Makefile
cvs rdiff -u -r1.68 -r1.69 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/main.c
cvs rdiff -u -r0 -r1.1 src/sbin/gpt/uuid.c

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



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 04:25:12 UTC 2019

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

Log Message:
adjust gpt_uuid_generate() to accept gpt==NULL


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/sbin/gpt/gpt_uuid.c:1.18
--- src/sbin/gpt/gpt_uuid.c:1.17	Thu Dec 20 14:58:10 2018
+++ src/sbin/gpt/gpt_uuid.c	Tue Jun 25 04:25:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $	*/
+/*	$NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $");
+__RCSID("$NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $");
 #endif
 
 #include 
@@ -321,7 +321,7 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t 
 {
 	int rv;
 	struct dce_uuid u;
-	if (gpt->flags & GPT_TIMESTAMP)
+	if (gpt && (gpt->flags & GPT_TIMESTAMP))
 		rv = gpt_uuid_tstamp(gpt, , sizeof(u));
 	else
 		rv = gpt_uuid_random(gpt, , sizeof(u));



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 04:25:12 UTC 2019

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

Log Message:
adjust gpt_uuid_generate() to accept gpt==NULL


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.



Re: CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
On Jun 25,  3:42am, "John Nemeth" wrote:
} 
} Module Name:  src
} Committed By: jnemeth
} Date: Tue Jun 25 03:42:46 UTC 2019
} 
} Modified Files:
}   src/sbin/gpt: gpt.h
} 
} Log Message:
} gpt.c

 ARGH!  Message should have read:

Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.

Updated in repository.

}-- End of excerpt from "John Nemeth"


CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 03:50:18 UTC 2019

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

Log Message:
Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.


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

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



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 03:50:18 UTC 2019

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

Log Message:
Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sbin/gpt/gpt.c:1.80
--- src/sbin/gpt/gpt.c:1.79	Fri Jun 21 02:14:59 2019
+++ src/sbin/gpt/gpt.c	Tue Jun 25 03:50:18 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.79 2019/06/21 02:14:59 jnemeth Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.80 2019/06/25 03:50:18 jnemeth Exp $");
 #endif
 
 #include 
@@ -1076,6 +1076,33 @@ gpt_change_ent(gpt_t gpt, const struct g
 }
 
 int
+gpt_change_hdr(gpt_t gpt, const struct gpt_find *find,
+void (*cfn)(struct gpt_hdr *, void *, int), void *v)
+{
+	struct gpt_hdr *hdr;
+
+	if ((hdr = gpt_hdr(gpt)) == NULL)
+		return -1;
+
+	/* Change the primary header. */
+	(*cfn)(hdr, v, 0);
+
+	if (gpt_write_primary(gpt) == -1)
+		return -1;
+
+	hdr = gpt->tpg->map_data;
+	/* Change the secondary header. */
+	(*cfn)(hdr, v, 1);
+
+	if (gpt_write_backup(gpt) == -1)
+		return -1;
+
+	gpt_msg(gpt, "Header %s", find->msg);
+
+	return 0;
+}
+
+int
 gpt_add_ais(gpt_t gpt, off_t *alignment, u_int *entry, off_t *size, int ch)
 {
 	switch (ch) {



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 03:42:46 UTC 2019

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

Log Message:
gpt.c


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sbin/gpt/gpt.h

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



CVS commit: src/sbin/gpt

2019-06-24 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Tue Jun 25 03:42:46 UTC 2019

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

Log Message:
gpt.c


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sbin/gpt/gpt.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.h
diff -u src/sbin/gpt/gpt.h:1.39 src/sbin/gpt/gpt.h:1.40
--- src/sbin/gpt/gpt.h:1.39	Fri Jun 21 02:14:59 2019
+++ src/sbin/gpt/gpt.h	Tue Jun 25 03:42:45 2019
@@ -116,6 +116,8 @@ struct gpt_find {
 };
 int	gpt_change_ent(gpt_t, const struct gpt_find *,
 void (*)(struct gpt_ent *, void *, int), void *);
+int	gpt_change_hdr(gpt_t, const struct gpt_find *,
+void (*)(struct gpt_hdr *, void *, int), void *);
 int	gpt_add_find(gpt_t, struct gpt_find *, int);
 
 #define GPT_AIS "a:i:s:"



CVS commit: src/sbin/gpt

2019-06-20 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Fri Jun 21 02:14:59 UTC 2019

Modified Files:
src/sbin/gpt: gpt.c gpt.h label.c remove.c type.c

Log Message:
Add a third argument to the "cfn" function that is an argument to
gpt_change_ent().  The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry.  It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.38 -r1.39 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/label.c
cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/remove.c
cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/type.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.78 src/sbin/gpt/gpt.c:1.79
--- src/sbin/gpt/gpt.c:1.78	Thu Jun 20 10:41:58 2019
+++ src/sbin/gpt/gpt.c	Fri Jun 21 02:14:59 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.78 2019/06/20 10:41:58 martin Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.79 2019/06/21 02:14:59 jnemeth Exp $");
 #endif
 
 #include 
@@ -1015,7 +1015,7 @@ gpt_add_find(gpt_t gpt, struct gpt_find 
 
 int
 gpt_change_ent(gpt_t gpt, const struct gpt_find *find,
-void (*cfn)(struct gpt_ent *, void *), void *v)
+void (*cfn)(struct gpt_ent *, void *, int), void *v)
 {
 	map_t m;
 	struct gpt_hdr *hdr;
@@ -1058,14 +1058,14 @@ gpt_change_ent(gpt_t gpt, const struct g
 			continue;
 
 		/* Change the primary entry. */
-		(*cfn)(ent, v);
+		(*cfn)(ent, v, 0);
 
 		if (gpt_write_primary(gpt) == -1)
 			return -1;
 
 		ent = gpt_ent_backup(gpt, i);
 		/* Change the secondary entry. */
-		(*cfn)(ent, v);
+		(*cfn)(ent, v, 1);
 
 		if (gpt_write_backup(gpt) == -1)
 			return -1;

Index: src/sbin/gpt/gpt.h
diff -u src/sbin/gpt/gpt.h:1.38 src/sbin/gpt/gpt.h:1.39
--- src/sbin/gpt/gpt.h:1.38	Tue Jul  3 03:41:23 2018
+++ src/sbin/gpt/gpt.h	Fri Jun 21 02:14:59 2019
@@ -115,7 +115,7 @@ struct gpt_find {
 	const char *msg;
 };
 int	gpt_change_ent(gpt_t, const struct gpt_find *,
-void (*)(struct gpt_ent *, void *), void *);
+void (*)(struct gpt_ent *, void *, int), void *);
 int	gpt_add_find(gpt_t, struct gpt_find *, int);
 
 #define GPT_AIS "a:i:s:"

Index: src/sbin/gpt/label.c
diff -u src/sbin/gpt/label.c:1.29 src/sbin/gpt/label.c:1.30
--- src/sbin/gpt/label.c:1.29	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/label.c	Fri Jun 21 02:14:59 2019
@@ -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.29 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: label.c,v 1.30 2019/06/21 02:14:59 jnemeth Exp $");
 #endif
 
 #include 
@@ -68,7 +68,7 @@ struct gpt_cmd c_label = {
 #define usage() gpt_usage(NULL, _label)
 
 static void
-change(struct gpt_ent *ent, void *v)
+change(struct gpt_ent *ent, void *v, int backup)
 {
 	uint8_t *name = v;
 	utf8_to_utf16(name, ent->ent_name, __arraycount(ent->ent_name));

Index: src/sbin/gpt/remove.c
diff -u src/sbin/gpt/remove.c:1.22 src/sbin/gpt/remove.c:1.23
--- src/sbin/gpt/remove.c:1.22	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/remove.c	Fri Jun 21 02:14:59 2019
@@ -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.22 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: remove.c,v 1.23 2019/06/21 02:14:59 jnemeth Exp $");
 #endif
 
 #include 
@@ -66,7 +66,7 @@ struct gpt_cmd c_remove = {
 #define usage() gpt_usage(NULL, _remove)
 
 static void
-change(struct gpt_ent *ent, void *v)
+change(struct gpt_ent *ent, void *v, int backup)
 {
 	/* Remove the primary entry by clearing the partition type. */
 	gpt_uuid_copy(ent->ent_type, gpt_uuid_nil);

Index: src/sbin/gpt/type.c
diff -u src/sbin/gpt/type.c:1.15 src/sbin/gpt/type.c:1.16
--- src/sbin/gpt/type.c:1.15	Tue Jul  3 03:41:24 2018
+++ src/sbin/gpt/type.c	Fri Jun 21 02:14:59 2019
@@ -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.15 2018/07/03 03:41:24 jnemeth Exp $");
+__RCSID("$NetBSD: type.c,v 1.16 2019/06/21 02:14:59 jnemeth Exp $");
 #endif
 
 #include 
@@ -67,7 +67,7 @@ struct gpt_cmd c_type = {
 #define usage() gpt_usage(NULL, _type)
 
 static void
-change(struct gpt_ent *ent, void *v)
+change(struct gpt_ent *ent, void *v, int backup)
 {
 	gpt_uuid_t *newtype = v;
 	gpt_uuid_copy(ent->ent_type, *newtype);



CVS commit: src/sbin/gpt

2019-06-20 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Fri Jun 21 02:14:59 UTC 2019

Modified Files:
src/sbin/gpt: gpt.c gpt.h label.c remove.c type.c

Log Message:
Add a third argument to the "cfn" function that is an argument to
gpt_change_ent().  The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry.  It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sbin/gpt/gpt.c
cvs rdiff -u -r1.38 -r1.39 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/label.c
cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/remove.c
cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/type.c

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



CVS commit: src/sbin/gpt

2019-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 20 10:56:38 UTC 2019

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

Log Message:
When biosboot is used on an existing wedge and we are switching to
the gpt of the parent device, do not pass the size of the wedge to
gpt_open, it certainly is smaller than the whole device.
Fixes bin/54312.


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

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



CVS commit: src/sbin/gpt

2019-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 20 10:56:38 UTC 2019

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

Log Message:
When biosboot is used on an existing wedge and we are switching to
the gpt of the parent device, do not pass the size of the wedge to
gpt_open, it certainly is smaller than the whole device.
Fixes bin/54312.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sbin/gpt/biosboot.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/biosboot.c
diff -u src/sbin/gpt/biosboot.c:1.31 src/sbin/gpt/biosboot.c:1.32
--- src/sbin/gpt/biosboot.c:1.31	Thu Apr  4 13:55:40 2019
+++ src/sbin/gpt/biosboot.c	Thu Jun 20 10:56:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $ */
+/*	$NetBSD: biosboot.c,v 1.32 2019/06/20 10:56:38 martin Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.32 2019/06/20 10:56:38 martin Exp $");
 #endif
 
 #include 
@@ -312,7 +312,7 @@ cmd_biosboot(gpt_t gpt, int argc, char *
 		start = dkw.dkw_offset;
 		size = dkw.dkw_size;
 		ngpt = gpt_open(dkw.dkw_parent, gpt->flags, gpt->verbose,
-		gpt->mediasz, gpt->secsz, gpt->timestamp);
+		0, 0, 0);
 		if (ngpt == NULL)
 			goto cleanup;
 	}



CVS commit: src/sbin/gpt

2019-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 20 10:41:58 UTC 2019

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

Log Message:
Do not try to close a NULL gpt. Fixes the core dump part of PR bin/54312


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sbin/gpt/gpt.c:1.78
--- src/sbin/gpt/gpt.c:1.77	Sun Jan 27 13:16:05 2019
+++ src/sbin/gpt/gpt.c	Thu Jun 20 10:41:58 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.77 2019/01/27 13:16:05 martin Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.78 2019/06/20 10:41:58 martin Exp $");
 #endif
 
 #include 
@@ -590,6 +590,9 @@ void
 gpt_close(gpt_t gpt)
 {
 
+	if (gpt == NULL)
+		return;
+
 	if (!(gpt->flags & GPT_MODIFIED) || !(gpt->flags & GPT_SYNC))
 		goto out;
 



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

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.



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 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.



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, ) == -1)
 goto usage;
 			break;
+		case 'b':
+			if (gpt_human_get(gpt, ) == -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: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.



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, ) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt == NULL || gpt_human_get(gpt, ) == -1)
+return usage();
+			break;
 		case 'i':
 			if (gpt == NULL || gpt_uint_get(gpt, ) == -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-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.



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.



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-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, ) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt == NULL || gpt_human_get(gpt, ) == -1)
+return usage();
+			break;
 		case 'i':
 			if (gpt == NULL || gpt_uint_get(gpt, ) == -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-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.



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.



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, ) == -1)
 return usage();
 			break;
+		case 'b':
+			if (gpt_human_get(gpt, ) == -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-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, , , , ch) == -1)
+	while ((ch = getopt(argc, argv, GPT_AIS "b:")) != -1) {
+		if (ch == 'b')
+			gpt_human_get(gpt, );
+		else if (gpt_add_ais(gpt, , , , 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: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.



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-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.



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-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.



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 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.



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.



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

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.



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, , 0U) == -1)
 		goto close;
 	if ((found = gpt_gpt(gpt, 1LL, 1)) == -1)
 		goto close;



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), _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(, 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

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.



  1   2   3   4   5   6   >