Home | History | Annotate | only in /src/sbin/gpt
History log of /src/sbin/gpt
RevisionDateAuthorComments
 1.19 25-Jun-2019  jnemeth 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.
 1.18 03-Dec-2015  christos branches: 1.18.16;
WARNS=6
 1.17 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.16 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.15 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.14 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.13 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.12 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.11 29-Sep-2014  christos more toolification
 1.10 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.9 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.8 10-Aug-2014  jnemeth branches: 1.8.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.7 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.6 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.5 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.4 06-Jan-2011  jakllsch branches: 1.4.6; 1.4.12;
Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.3 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.2 15-Oct-2006  christos branches: 1.2.28;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.4.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.8.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.18.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.46 23-Feb-2025  christos Pass some lint.
 1.45 02-Nov-2024  kre PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.44 03-Jul-2018  jnemeth branches: 1.44.2; 1.44.10; 1.44.12;
Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.43 29-Dec-2015  christos branches: 1.43.14; 1.43.16;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.42 03-Dec-2015  christos CID 1341561: Argument memory leak
 1.41 03-Dec-2015  christos CID 1341560: Free arg.
 1.40 03-Dec-2015  christos CID 1341548: Check error returns
 1.39 03-Dec-2015  christos WARNS=6
 1.38 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.37 02-Dec-2015  jnemeth hrmm...

i386devel: {245} ./gpt add -b 1000 -s 1000 disk
Segmentation fault (core dumped)

Where's my flyswatter? .......zzzzzzzap
 1.36 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.35 02-Dec-2015  christos - write a function to set the entity, so that we don't reset to guid.
- entry 0 means create entry.
 1.34 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.33 01-Dec-2015  christos refactor more duplicated code.
 1.32 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.31 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.30 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.29 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.28 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.27 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.26 30-Sep-2014  christos remove compat defines.
 1.25 29-Sep-2014  christos minor toolification: need libprop...
 1.24 10-Dec-2013  jnemeth branches: 1.24.4;
Explicitly state which partition was added/modified.
 1.23 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.22 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.21 28-Nov-2013  jnemeth when calling dehumanize_number() make sure the resulting number is >= 1
 1.20 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.19 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.18 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.17 19-Nov-2013  jnemeth delete an errant where it is obvious what the code is doing
 1.16 19-Nov-2013  jnemeth When setting a label on the new partition, be sure to set the label
in the secondary partition table as well.
 1.15 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.14 26-May-2013  wiz Instead of 'no space', say 'not enough space' in error message.
 1.13 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.12 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.11 27-Aug-2011  joerg branches: 1.11.2; 1.11.8;
Use __dead
 1.10 06-Jan-2011  riz Clarify the 'dkctl addwedge' usage message after creating a GPT
partition.
 1.9 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.8 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.7 07-Feb-2009  uebayasi Make manual and usage consistent. No functional changes.
 1.6 28-Dec-2007  riz As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 16-Feb-2007  riz branches: 1.4.4; 1.4.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3 17-Oct-2006  he branches: 1.3.2;
Add initialization of a variable where gcc for some archs thinks
that it may be used un-initialized. From cursory inspection it is
not obvious that gcc is wrong.
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.2.3 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.3.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.3.2.1 20-Feb-2007  tron branches: 1.3.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.11.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.8.1 23-Jun-2013  tls resync from head
 1.11.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.24.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.43.16.1 10-Jun-2019  christos Sync with HEAD
 1.43.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.44.12.1 02-Aug-2025  perseant Sync with HEAD
 1.44.10.1 17-Nov-2024  martin Pull up following revision(s) (requested by kre in ticket #1005):

sbin/gpt/add.c: revision 1.45

PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.44.2.1 17-Nov-2024  martin Pull up following revision(s) (requested by kre in ticket #1920):

sbin/gpt/add.c: revision 1.45

PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.21 23-Feb-2025  christos Pass some lint.
 1.20 08-Jun-2020  thorpej branches: 1.20.8;
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.
 1.19 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.18 07-Sep-2017  christos use __arraycount
 1.17 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.16 03-Dec-2015  christos branches: 1.16.8;
CID 1341558: Fix proplib memory leaks
 1.15 03-Dec-2015  christos compare to stdout, thanks kre
 1.14 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.13 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.12 02-Dec-2015  christos split out into smaller functions.
 1.11 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.10 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.9 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.8 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.7 30-Sep-2014  christos remove compat defines.
 1.6 29-Sep-2014  christos more toolification changes
 1.5 29-Sep-2014  christos more toolification
 1.4 29-Sep-2014  christos minor toolification: need libprop...
 1.3 10-Sep-2014  jnemeth - dump all partitions, not just ones that are in use
- while here, squash a memory leak

It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
 1.2 09-Sep-2014  jnemeth - record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
 1.1 19-Dec-2013  jnemeth branches: 1.1.4; 1.1.6; 1.1.8;
Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 19-Dec-2013  tls file backup.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.1.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 19-Dec-2013  yamt file backup.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.16.8.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.20.8.1 02-Aug-2025  perseant Sync with HEAD
 1.34 23-Feb-2025  christos Pass some lint.
 1.33 13-Sep-2024  mlelstv Don't use kernel type daddr_t for disk offsets.
 1.32 20-Jun-2019  martin branches: 1.32.2; 1.32.10; 1.32.12;
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.
 1.31 04-Apr-2019  martin Allow specifying the partition via -b startsec for the biosboot cmd.
 1.30 07-Sep-2017  christos branches: 1.30.4;
use __arraycount
 1.29 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.28 03-Jul-2017  mrg only do wedges if not the tools version. fixes build on netbsd-4,
and any other place that might have the same ioctl name while having
something not quite right (in this case, cpuid_t in headers not
working properly..)

XXX: pullup-8
 1.27 16-Feb-2017  christos branches: 1.27.4;
Add -T timestamp for reproducible builds.
 1.26 09-Jun-2016  christos branches: 1.26.2; 1.26.4;
Rename 'a' to set the active PMBR flag to 'A'
 1.25 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.24 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.23 03-Dec-2015  christos more leak
 1.22 03-Dec-2015  christos WARNS=6
 1.21 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.20 02-Dec-2015  christos don't advertise stuff we don't support.
 1.19 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.18 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.17 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.16 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.15 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.14 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.13 02-Oct-2014  joerg Fix tools build on !NetBSD.
 1.12 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.11 29-Sep-2014  christos more toolification
 1.10 29-Sep-2014  christos minor toolification: need libprop...
 1.9 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.8 26-Sep-2014  jnemeth no C99isms in tool code
 1.7 27-Nov-2013  jnemeth branches: 1.7.4;
Remove FreeBSD specific code as per message to tech-userlevel.
 1.6 13-Apr-2013  jakllsch drop trailing whitespace
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 17-Aug-2011  martin Fix sign compare bugs
 1.3 17-Aug-2011  jakllsch Ajdust bootcode file name from mbr_gpt to gptmbr.bin.
 1.2 17-Aug-2011  jakllsch Switch 'gpt biosboot' to support T13 EDD-4 annex A GPT hybrid MBR instead
of a home-grown MBR/VBR hand off protocol.

'biosboot' now will set the legacy BIOS boot flag instead of patching a
GUID into the MBR.
 1.1 06-Jan-2011  jakllsch Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.7.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.26.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.27.4.2 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.27.4.1 05-Jul-2017  snj Pull up following revision(s) (requested by mrg in ticket #93):
sbin/gpt/biosboot.c: revision 1.28
only do wedges if not the tools version. fixes build on netbsd-4,
and any other place that might have the same ioctl name while having
something not quite right (in this case, cpuid_t in headers not
working properly..)
 1.30.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.30.4.1 10-Jun-2019  christos Sync with HEAD
 1.32.12.1 02-Aug-2025  perseant Sync with HEAD
 1.32.10.1 02-Oct-2024  martin Pull up following revision(s) (requested by lloyd in ticket #911):

sbin/gpt/biosboot.c: revision 1.33

Don't use kernel type daddr_t for disk offsets.
 1.32.2.1 02-Oct-2024  martin Pull up following revision(s) (requested by lloyd in ticket #1889):

sbin/gpt/biosboot.c: revision 1.33

Don't use kernel type daddr_t for disk offsets.
 1.24 23-Feb-2025  christos Pass some lint.
 1.23 23-Sep-2016  christos branches: 1.23.26;
PR/51497: Clare: Allow gpt -p <n> create to work.
 1.22 09-Jun-2016  christos branches: 1.22.2;
Rename 'a' to set the active PMBR flag to 'A'
 1.21 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.20 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.19 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.18 03-Dec-2015  christos WARNS=6
 1.17 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.16 01-Dec-2015  christos refactor more duplicated code.
 1.15 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.14 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.13 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.12 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.11 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.10 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.9 30-Sep-2014  christos remove compat defines.
 1.8 29-Sep-2014  christos minor toolification: need libprop...
 1.7 04-Dec-2013  jakllsch branches: 1.7.4;
Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 06-Jan-2011  jakllsch Use less bogus CHS addresses in PMBR.
With the ending head set at 0xff one machine I have will never leave
the initial startup screen if such a disk is present. Additionally,
Wikipedia suggests without citiation that 254 is the maximium allowable
value for the head, and this seems to be the case.
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.7.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.22.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.23.26.1 02-Aug-2025  perseant Sync with HEAD
 1.15 23-Feb-2025  christos Pass some lint.
 1.14 20-Nov-2022  mlelstv branches: 1.14.4;
Fix destroying and moving GPT header also for truncated/extended
images.
 1.13 16-Oct-2019  jnemeth Do the 'dkctl makewedges' dance to drop any wedges assoicated the
destroyed GPT.
 1.12 04-Apr-2019  martin 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.
 1.11 04-Apr-2019  martin Ignore -f with the "destroy" command completely (it was effectively
ignored already, so no functional change). Leave it as valid option
for compatibility.
 1.10 03-Dec-2015  christos branches: 1.10.16;
eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 29-Sep-2014  christos more toolification
 1.5 29-Sep-2014  christos minor toolification: need libprop...
 1.4 27-Aug-2011  joerg branches: 1.4.20;
Use __dead
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.20.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.4.20.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.10.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10.16.1 10-Jun-2019  christos Sync with HEAD
 1.14.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.1 29-Dec-2014  christos branches: 1.1.2;
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.2.1 29-Dec-2014  snj file drvctl.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.86 09-Feb-2025  pgoyette Minor cleanups.
 1.85 12-Jan-2025  christos Add missing "to" (Anon Ymous)
 1.84 04-Nov-2024  christos Additions to guid printing and an option to print start/size in hex
(from Anon Ymous)
 1.83 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.82 10-Jun-2024  kre branches: 1.82.2;

Revert unintended commit.
 1.81 10-Jun-2024  kre Note need to deal with old libarchive.so files in cdrom images when doing
an update build.
 1.80 07-Nov-2023  gutteridge gpt.8: fix grammar in a sentence
 1.79 31-Oct-2023  martin Apply patch from Thierry Laronde: add missing suffixes for size values
and clarify that they are case independant.
 1.78 15-Jul-2023  gutteridge gpt.8: fix some grammar

(The BUGS section seems perhaps a little outdated in its warnings of
potential incompatible changes.)
 1.77 15-Jul-2023  gutteridge 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.
 1.76 07-Apr-2022  kre branches: 1.76.2;

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.
 1.75 07-Apr-2022  nia 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".
 1.74 27-Jul-2020  christos catch up with source rename of fbsd-zfs -> zfs
 1.73 24-May-2020  wiz Fix typo in macro. Sort option descriptions.
 1.72 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.71 24-May-2020  jmcneill 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.
 1.70 26-Jul-2019  martin Remove outdated note about sysinst restrictions
 1.69 25-Jun-2019  jnemeth 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.
 1.68 04-Apr-2019  martin Allow specifying the partition via -b startsec for the biosboot cmd.
 1.67 26-Mar-2019  martin Allow -b to specify a partition for "gpt unset" as well.
 1.66 25-Mar-2019  martin 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.
 1.65 24-Mar-2019  martin Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).
 1.64 24-Mar-2019  martin 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.
 1.63 01-May-2018  kre branches: 1.63.2;

Spello. (it is "existence").

ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.

I also left a correct spelling that no-one has bothered to mangle!
 1.62 01-May-2018  wiz Bump date for new EXIT STATUS section.
 1.61 01-May-2018  wiz Sort sections.
 1.60 01-May-2018  martin Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
 1.59 11-Apr-2018  mrg add information about how to boot from gpt. mostly taken from the wiki.
 1.58 19-Mar-2018  mlelstv Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.57 15-Jan-2018  sborrill branches: 1.57.2;
Explain what suffixes are accepted when specifying a size.
 1.56 03-Oct-2017  mlelstv clarify that alignment is the number of bytes to align to.
 1.55 05-Aug-2017  wiz Use Fx/Nx.
 1.54 04-Aug-2017  kre Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...
 1.53 03-Aug-2017  msaitoh Add note about bootme flag:

The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.
 1.52 16-Feb-2017  christos branches: 1.52.4;
Add -T timestamp for reproducible builds.
 1.51 27-Jan-2017  abhinav Fix spelling of partition.
 1.50 01-Nov-2016  jdolecek branches: 1.50.2;
remove dup line
 1.49 11-Sep-2016  sevan Document the version gpt first appeared.
Replace contractions.
Bump date.
 1.48 09-Jun-2016  christos branches: 1.48.2;
Rename 'a' to set the active PMBR flag to 'A'
 1.47 09-Jun-2016  kre Fix rendering of biosboot command synopsis.
 1.46 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.45 25-Dec-2015  wiz Simplify usage for gpt show.
 1.44 25-Dec-2015  martin Add a -a flag to the show command, so we can display the full GPT with
all information in one go.
 1.43 06-Dec-2015  wiz Bump date for previous.
Remove trailing whitespace.
 1.42 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.41 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.40 01-Dec-2015  christos Reflect reality better; we don't handle multiple devices anymore, and
the partitions option is only for the commands that support it.
 1.39 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.38 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.37 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.36 06-Dec-2014  wiz Bump date for previous.
 1.35 06-Dec-2014  mlelstv Add some more common partition types.
 1.34 04-Oct-2014  wiz Remove trailing whitespace.
 1.33 04-Oct-2014  christos Allow specifying sector and media size on the command line.
 1.32 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.31 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.30 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.29 20-Sep-2014  jnemeth document the new restore subcommand
 1.28 19-Dec-2013  wiz branches: 1.28.4;
Bump date for previous.
 1.27 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.26 09-Dec-2013  wiz Fix typo.
 1.25 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.24 09-Dec-2013  jnemeth For the "show -i <entry>" subcommand, print Start and Size both in
terms of number of sectors and bytes.
 1.23 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.22 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.21 30-Nov-2013  jnemeth Add two new options:

-g which shows the GUID for a partition
-i which shows all the gory details for a particular option

XXX the output format of -i is subject to change
 1.20 22-Nov-2013  jnemeth bump date
 1.19 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.18 20-Nov-2013  wiz shrunk.
 1.17 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.16 19-Nov-2013  jnemeth update synopsis for add subcommand
 1.15 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.14 24-Oct-2013  jnemeth - markup
- typo; the label command labels partitions, not remove them
- migrate -s isn't applicable to NetBSD
- add information about the space required for migration
- add a "gpt show -l" example
 1.13 20-Oct-2013  jnemeth revert typo fix; teach me to blindly take changes from upstream
 1.12 19-Oct-2013  jnemeth type fix: accommodate. -> accomodate.
 1.11 02-May-2012  jakllsch branches: 1.11.2;
Bump date to date of previous change.
 1.10 09-Mar-2012  drochner fix a path
 1.9 11-Nov-2011  wiz branches: 1.9.2;
Add an EXAMPLE section showing how to add a swap file system using gpt. Bump date.
 1.8 19-Sep-2011  wiz branches: 1.8.2;
Minimally document gpt recover. Bump date.
 1.7 27-Mar-2011  jym Document biosboot. Xref boot(8) and installboot(8).
 1.6 09-Feb-2011  schnoebe List all the aliases supported for GPT partition types.
 1.5 11-Mar-2009  joerg branches: 1.5.2;
Don't workaround ancient macro argument limit with .Xo/.Xc.
 1.4 09-Mar-2009  joerg Fix preamble to match order set out by mdoc(7). Discussed with wiz.
 1.3 24-Nov-2006  christos branches: 1.3.28;
fix spelling of accommodate; from Zapher.
 1.2 17-Oct-2006  wiz Serial comma. Add RCS Id. Remove superfluous quotes.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.5.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.8.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.2.2 23-May-2012  yamt sync with head.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.9.2.1 07-May-2012  riz Pull up following revision(s) (requested by jakllsch in ticket #210):
sbin/gpt/gpt.8: revision 1.10
sbin/gpt/gpt.8: revision 1.11
fix a path
Bump date to date of previous change.
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.28.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.48.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.48.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.50.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.52.4.3 07-May-2018  snj Pull up following revision(s) (requested by martin in ticket #797):
sbin/gpt/gpt.8: 1.60-1.63
sbin/gpt/header.c: 1.9
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
--
Sort sections.
--
Bump date for new EXIT STATUS section.
--
Spello. (it is "existence").
ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.
I also left a correct spelling that no-one has bothered to mangle!
 1.52.4.2 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.52.4.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.57.2.3 02-May-2018  pgoyette Synch with HEAD
 1.57.2.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.57.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.63.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.2.1 10-Jun-2019  christos Sync with HEAD
 1.76.2.1 02-Nov-2023  sborrill Pull up the following revisions(s) (requested by martin in ticket #441):
sbin/gpt/gpt.8: revision 1.79

Add missing suffixes for size values and clarify that they are
case-independent.
 1.82.2.1 02-Aug-2025  perseant Sync with HEAD
 1.91 23-Feb-2025  christos Pass some lint.
 1.90 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.89 10-Jun-2024  kre branches: 1.89.2;

Revert unintended commit.
 1.88 10-Jun-2024  kre Note need to deal with old libarchive.so files in cdrom images when doing
an update build.
 1.87 13-Dec-2023  mrg avoid use after free. skip the QUIET check already in gpt_warn().
 1.86 11-Dec-2023  mlelstv Be verbose about errors.
 1.85 26-Sep-2023  kre 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.
 1.84 22-Nov-2022  mlelstv Big-Endian fixes.
 1.83 20-Nov-2022  mlelstv Fix destroying and moving GPT header also for truncated/extended
images.
 1.82 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.81 11-Oct-2019  christos gpt_uuid_parse does not set errno ...
 1.80 25-Jun-2019  jnemeth Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.
 1.79 21-Jun-2019  jnemeth 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.
 1.78 20-Jun-2019  martin Do not try to close a NULL gpt. Fixes the core dump part of PR bin/54312
 1.77 27-Jan-2019  martin 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.
 1.76 14-Oct-2018  mlelstv When changing entries skip those that do not match the -L option.
Should fix PR 53668.
 1.75 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.74 13-Feb-2018  sevan branches: 1.74.2; 1.74.4;
Spelling
 1.73 07-Sep-2017  christos use __arraycount
 1.72 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.71 05-Sep-2017  christos PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
XXX: pullup-8
 1.70 16-Feb-2017  christos branches: 1.70.4;
Add -T timestamp for reproducible builds.
 1.69 24-Sep-2016  christos branches: 1.69.2;
say that you need to destroy it first.
 1.68 09-Jun-2016  christos branches: 1.68.2;
PR/51230: Add the ability to set the active flag in the PMBR.
 1.67 08-Jan-2016  joerg gpt_vwarnx is printf-like.
 1.66 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.65 26-Dec-2015  jnemeth pretty up attribute display a bit
 1.64 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.63 04-Dec-2015  christos Fix resizedisk.
 1.62 04-Dec-2015  christos don't print dkctl message for files
fix typo
 1.61 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.60 03-Dec-2015  christos Add a space.
 1.59 03-Dec-2015  christos WARNS=6
 1.58 02-Dec-2015  christos annotate map additions with non-allocated memory.
 1.57 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.56 02-Dec-2015  christos Always set NOSYNC if regular file, even if we got the size from the command
line.
 1.55 02-Dec-2015  jnemeth - dereferencing NULL is generally bad, found by visual inspection
- automatically set nosync when opening a file to avoid spurious errors
 1.54 02-Dec-2015  christos print the old and the new style usage.
 1.53 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.52 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.51 01-Dec-2015  christos refactor more duplicated code.
 1.50 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.49 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.48 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.47 01-Dec-2015  christos only update the wedge information if it is supported.
 1.46 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.45 29-Nov-2015  christos Do division once
 1.44 29-Nov-2015  christos Only use the ioctl's if we have them.
 1.43 29-Nov-2015  jnemeth fix build breakage for systems that do not have DIOCG{SECTOR,MEDIA}SIZE
 1.42 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.41 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.40 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.39 17-Nov-2014  mlelstv handle constness better
 1.38 17-Nov-2014  mlelstv handle constness
 1.37 17-Nov-2014  mlelstv Report the argument instead of (null) when opendisk fails.
 1.36 04-Oct-2014  christos Allow specifying sector and media size on the command line.
 1.35 02-Oct-2014  joerg Fix tools build on !NetBSD.
 1.34 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.33 30-Sep-2014  christos remove compat defines.
 1.32 29-Sep-2014  christos more toolification
 1.31 29-Sep-2014  christos minor toolification: need libprop...
 1.30 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.29 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.28 10-Aug-2014  jnemeth branches: 1.28.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.27 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.26 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.25 04-Dec-2013  jakllsch Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.24 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.23 23-Nov-2013  jnemeth Only skip past _PATH_DEV if it is actually present.
 1.22 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.21 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.20 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.19 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.18 18-Jan-2013  jakllsch Now that GPT_ENT_TYPE_LINUX_DATA is diffrent from the Windows one, use it.
 1.17 30-Jul-2012  matt branches: 1.17.2;
Fix a few straggling BE/LE problems.
 1.16 25-Jul-2012  matt Make sure utf-16 strings are written as little endian words.
 1.15 27-Aug-2011  joerg branches: 1.15.2; 1.15.4;
Use __dead
 1.14 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.13 06-Jan-2011  jakllsch Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.12 02-Apr-2010  christos fix printf format.
 1.11 02-Apr-2010  christos PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
 1.10 20-Feb-2010  mlelstv Initialize device_name before opendisk to avoid
"unable to open device '(null)'" error messages
when the opendisk fails.
 1.9 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.8 24-Feb-2008  christos branches: 1.8.6;
PR/38094: Robert Millan: support "BIOS Boot" partition type in gpt(8)
 1.7 28-Dec-2007  riz branches: 1.7.2; 1.7.4;
As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.6 19-Dec-2007  dogcow Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 11-Jun-2007  dyoung branches: 1.4.4; 1.4.6;
Produce more useful error messages.
 1.3 16-Feb-2007  riz Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2 15-Oct-2006  christos branches: 1.2.2;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.2.3 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.2.2.1 20-Feb-2007  tron branches: 1.2.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.2 23-Mar-2008  matt sync with HEAD
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.7.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.2.1 24-Mar-2008  keiichi sync with head.
 1.8.6.2 24-Nov-2010  riz Pull up following revision(s) (requested by christos in ticket #1464):
sbin/gpt/gpt.c: revision 1.11
sbin/gpt/gpt.c: revision 1.12
PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
fix printf format.
 1.8.6.1 21-Nov-2010  riz Pull up following revision(s) (requested by christos in ticket #1464):
sbin/gpt/gpt.c: revision 1.11
PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
 1.15.4.1 26-Oct-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #619):
sbin/gpt/gpt.c: revision 1.16-1.17

Endianness fixes.
 1.15.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.2.2 23-Jan-2013  yamt sync with head
 1.15.2.1 30-Oct-2012  yamt sync with head
 1.17.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.2.2 23-Jun-2013  tls resync from head
 1.17.2.1 25-Feb-2013  tls resync with head
 1.28.2.3 15-Oct-2018  sborrill Pull up the following revisions(s) (requested by mlelstv in ticket #1643):
sbin/gpt/gpt.c: revision 1.76

When changing entries skip those that do not match the -L option.
Should fix PR 53668.
 1.28.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.28.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.68.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.68.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.69.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.70.4.3 15-Oct-2018  sborrill Pull up the following revisions(s) (requested by mlelstv in ticket #1063):
sbin/gpt/gpt.c: revision 1.76

When changing entries, skip those that do not match the -L option.
Should fix PR 53668.
 1.70.4.2 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.70.4.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.74.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.74.4.1 10-Jun-2019  christos Sync with HEAD
 1.74.2.2 20-Oct-2018  pgoyette Sync with head
 1.74.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.89.2.1 02-Aug-2025  perseant Sync with HEAD
 1.45 23-Feb-2025  christos Pass some lint.
 1.44 20-Nov-2022  mlelstv branches: 1.44.4;
Fix destroying and moving GPT header also for truncated/extended
images.
 1.43 16-Jul-2022  mlelstv Whitespace
 1.42 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.41 30-Jun-2019  sevan Add rcsid
 1.40 25-Jun-2019  jnemeth Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.
 1.39 21-Jun-2019  jnemeth 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.
 1.38 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.37 19-Mar-2018  mlelstv branches: 1.37.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.36 06-Sep-2017  christos branches: 1.36.2;
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.35 16-Feb-2017  christos branches: 1.35.4;
allow 0 timestamp
 1.34 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.33 09-Jun-2016  christos branches: 1.33.2; 1.33.4;
PR/51230: Add the ability to set the active flag in the PMBR.
 1.32 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.31 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.30 04-Dec-2015  christos Fix resizedisk.
 1.29 04-Dec-2015  christos don't print dkctl message for files
fix typo
 1.28 03-Dec-2015  christos WARNS=6
 1.27 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.26 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.25 01-Dec-2015  christos refactor more duplicated code.
 1.24 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.23 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.22 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.21 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.20 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.19 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.18 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.17 17-Nov-2014  mlelstv handle constness better
 1.16 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.15 30-Sep-2014  christos remove compat defines.
 1.14 29-Sep-2014  christos more toolification changes
 1.13 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.12 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.11 10-Aug-2014  jnemeth branches: 1.11.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.10 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.9 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.8 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.7 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 06-Jan-2011  jakllsch branches: 1.5.6; 1.5.12;
Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.4 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.3 12-Nov-2008  thorpej Don't use sizeof(struct gpt_hdr). It will pad the structure on x86-64,
which causes some systems to reject the GPT.

kern/38997
 1.2 15-Oct-2006  christos branches: 1.2.18; 1.2.26;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.26.1 26-Jan-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #311):
sbin/gpt/gpt.h: revision 1.3
sys/sys/disklabel_gpt.h: revision 1.7
Don't use sizeof(struct gpt_hdr). It will pad the structure on x86-64,
which causes some systems to reject the GPT.
kern/38997
 1.2.18.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.12.1 23-Jun-2013  tls resync from head
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.11.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.33.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.33.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.35.4.2 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.35.4.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.36.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.36.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.37.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.37.2.1 10-Jun-2019  christos Sync with HEAD
 1.44.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.3 30-Jun-2019  sevan branches: 1.3.12;
Add rcsid
 1.2 16-Feb-2017  christos branches: 1.2.12; 1.2.14;
Add -T timestamp for reproducible builds.
 1.1 01-Dec-2015  christos branches: 1.1.2; 1.1.4;
Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.14.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.14.1 16-Feb-2017  martin file gpt_private.h was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.2.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.12.1 02-Aug-2025  perseant Sync with HEAD
 1.26 11-Oct-2025  thorpej Add a couple of GPT partition type GUIDs one might encounter when
fiddling around with RISC-V systems (Linux XBOOTLDR, SiFive BBL).
 1.25 23-Feb-2025  christos Pass some lint.
 1.24 18-Dec-2024  andvar s/reproducable/reproducible/ in comment.
 1.23 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.22 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.21 27-Sep-2023  riastradh branches: 1.21.2;
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.000000000 +0000
+++ /tmp/check.sc6ylB/stdout 2023-09-26 23:30:42.388157924 +0000
@@ -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
 1.20 26-Sep-2023  kre Recognise Windows Recovery partitions.
 1.19 30-Mar-2020  martin Now that we use the same UUID for ZFS as FreeBSD, drop the FreeBSD marker
from the description.
 1.18 25-Jun-2019  jnemeth adjust gpt_uuid_generate() to accept gpt==NULL
 1.17 20-Dec-2018  martin 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).
 1.16 06-Nov-2018  mrg add support to detect the 3 vmware GPT partition types:

- VMKcore (dump partition)
- VMFS
- VMware reserved

this enables vmkcore partitions for netbsd swap or dump, as well
as naming all of them.
 1.15 16-Feb-2017  christos branches: 1.15.10; 1.15.12;
allow 0 timestamp
 1.14 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.13 06-Dec-2015  christos branches: 1.13.2; 1.13.4;
Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.12 03-Dec-2015  christos WARNS=6
 1.11 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.10 06-Dec-2014  mlelstv branches: 1.10.2;
Add some more common partition types.
 1.9 04-Oct-2014  riastradh Paranoia: choke noisily on EOF from /dev/urandom.
 1.8 04-Oct-2014  riastradh Make gpt(8) generate v4 (random) uuids.

Don't needlessly leak your date/time and MAC address when you edit
the disk.

Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)

ok apb
 1.7 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.6 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.5 02-Oct-2014  apb include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.

Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
 1.4 01-Oct-2014  apb It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
 1.3 01-Oct-2014  jnemeth actually return the uuid when parsing one that is in numeric format
 1.2 30-Sep-2014  jnemeth correctly show partition type in the new world order
 1.1 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.10.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.10.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.10.2.1 06-Dec-2014  snj file gpt_uuid.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.13.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.15.12.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.15.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15.12.1 10-Jun-2019  christos Sync with HEAD
 1.15.10.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.15.10.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 11-Oct-2025  thorpej Add a couple of GPT partition type GUIDs one might encounter when
fiddling around with RISC-V systems (Linux XBOOTLDR, SiFive BBL).
 1.11 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.10 27-Sep-2023  riastradh branches: 1.10.2;
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.000000000 +0000
+++ /tmp/check.sc6ylB/stdout 2023-09-26 23:30:42.388157924 +0000
@@ -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
 1.9 30-Jun-2019  sevan Add rcsid
 1.8 20-Dec-2018  martin 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).
 1.7 06-Dec-2015  christos branches: 1.7.14; 1.7.16;
remove more duplicated code.
 1.6 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.5 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.4 04-Sep-2015  mlelstv A change to the GPT_TYPE list also requires a change to the GPT_TYPE
index constants.
 1.3 03-Oct-2014  christos branches: 1.3.2;
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.2 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.1 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.3.2.4 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.3.2.3 08-Sep-2015  martin Pull up following revision(s) (requested by mlelstv in ticket #969):
sbin/gpt/gpt_uuid.h: revision 1.4
A change to the GPT_TYPE list also requires a change to the GPT_TYPE
index constants.
 1.3.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.3.2.1 03-Oct-2014  snj file gpt_uuid.h was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.7.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.16.1 10-Jun-2019  christos Sync with HEAD
 1.7.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 23-Feb-2025  christos Pass some lint.
 1.10 14-Mar-2019  mlelstv branches: 1.10.12;
print little-endian header fields correctly.
 1.9 01-May-2018  martin branches: 1.9.2; 1.9.4;
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
 1.8 24-Dec-2015  martin branches: 1.8.8; 1.8.14;
Fix output in an error case
 1.7 03-Dec-2015  christos WARNS=6
 1.6 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.5 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.4 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.3 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.2 16-Nov-2015  jnemeth correctly print the gpt header revision as a "float"
 1.1 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.8.14.1 02-May-2018  pgoyette Synch with HEAD
 1.8.8.1 07-May-2018  snj Pull up following revision(s) (requested by martin in ticket #797):
sbin/gpt/gpt.8: 1.60-1.63
sbin/gpt/header.c: 1.9
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
--
Sort sections.
--
Bump date for new EXIT STATUS section.
--
Spello. (it is "existence").
ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.
I also left a correct spelling that no-one has bothered to mangle!
 1.9.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.9.4.1 01-May-2018  martin file header.c was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.9.2.1 10-Jun-2019  christos Sync with HEAD
 1.10.12.1 02-Aug-2025  perseant Sync with HEAD
 1.31 23-Feb-2025  christos Pass some lint.
 1.30 21-Jun-2019  jnemeth branches: 1.30.12;
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.
 1.29 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.28 04-Dec-2015  christos branches: 1.28.14; 1.28.16;
put back usage from kre
 1.27 03-Dec-2015  christos CID 1341564: Arg memory leak
 1.26 03-Dec-2015  christos CID 1341563: fix leak
 1.25 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.24 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.23 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.22 01-Dec-2015  christos refactor more duplicated code.
 1.21 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.20 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.19 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.18 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.17 30-Sep-2014  christos remove compat defines.
 1.16 29-Sep-2014  christos minor toolification: need libprop...
 1.15 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.14 28-Nov-2013  jnemeth branches: 1.14.4;
when calling dehumanize_number() make sure the resulting number is >= 1
 1.13 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.12 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.11 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.10 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.9 13-Apr-2013  jakllsch Use correct spelling of "secondary" in comments.
 1.8 27-Aug-2011  joerg branches: 1.8.2; 1.8.8;
Use __dead
 1.7 12-Mar-2009  dyoung Fix spelling: s/parition/partition/.
 1.6 19-Dec-2007  dogcow branches: 1.6.12;
Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 16-Feb-2007  riz branches: 1.4.4; 1.4.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3 15-Oct-2006  christos branches: 1.3.2;
add casts
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.3.2.1 20-Feb-2007  tron branches: 1.3.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.6.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.8.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.8.1 23-Jun-2013  tls resync from head
 1.8.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.14.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.28.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.28.16.1 10-Jun-2019  christos Sync with HEAD
 1.28.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.30.12.1 02-Aug-2025  perseant Sync with HEAD
 1.15 23-Feb-2025  christos Pass some lint.
 1.14 24-May-2020  jmcneill branches: 1.14.8;
Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.13 25-Jun-2019  jnemeth 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.
 1.12 27-Aug-2018  sevan Add the -T flag to usage()
 1.11 19-Mar-2018  mlelstv branches: 1.11.2; 1.11.4;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.10 16-Feb-2017  christos branches: 1.10.4; 1.10.10;
allow 0 timestamp
 1.9 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.8 12-Feb-2017  aymeric Make gpt(8) work when compiled on a glibc-based OS.

This restores the ability to build amd64 install-image's under Linux.
 1.7 29-Dec-2015  christos branches: 1.7.2; 1.7.4;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.6 03-Dec-2015  christos WARNS=6
 1.5 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.4 01-Dec-2015  christos automatically enforce readonly for the commands that don't need to write.
 1.3 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.2 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.1 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.7.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.7.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10.10.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.10.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.10.4.2 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #992):

external/bsd/top/dist/top.1.in: revision 1.11
sbin/gpt/main.c: revision 1.12
sbin/amrctl/amrctl.c: revision 1.11
bin/df/df.c: revision 1.93
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.21
sbin/fsck_ext2fs/main.c: revision 1.38
bin/ksh/ksh.Man: revision 1.26
bin/ln/ln.c: revision 1.40
bin/df/df.1: revision 1.48
bin/df/df.1: revision 1.49

Document the WCPU field.

Match SYNOPSIS with usage()

-G cannot be specified alongside -i or -P.
Heads up by <leot>

Add -l to SYNOPSIS

Update usage to include -w

Match sequence as per SYNOPSIS in manual

Remove reference to -c flag which was never implemented.

Remove references to -c flag which was never included.

Add the -T flag to usage()
 1.10.4.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.11.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.11.4.1 19-Mar-2018  martin file main.c was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.11.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11.2.1 10-Jun-2019  christos Sync with HEAD
 1.14.8.1 02-Aug-2025  perseant Sync with HEAD
 1.16 05-Dec-2023  tsutsui Fix an incorrect comment.
 1.15 24-May-2020  jmcneill 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.
 1.14 11-Apr-2018  mrg if a new map entry doesn't fit, be more verbose about the sizes.
 1.13 03-Dec-2015  christos branches: 1.13.8; 1.13.14;
CID 1341556: Don't leak map info
 1.12 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.11 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.10 29-Nov-2015  christos Add some debugging.
 1.9 29-Nov-2015  christos print the current map type.
 1.8 29-Nov-2015  christos - use snprintf
- fix bogus logic on map_type
 1.7 29-Sep-2014  christos minor toolification: need libprop...
 1.6 27-Nov-2013  christos branches: 1.6.4;
CID 1132762: Add error check for negative, to make zero-divide in module
impossible.
 1.5 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.4 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.3 26-Oct-2013  jnemeth cosmetic fix from drochner@
 1.2 15-Oct-2006  christos branches: 1.2.42; 1.2.48;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.48.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.42.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.13.14.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.13.8.1 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.7 30-Jun-2019  sevan Add rcsid
 1.6 03-Dec-2015  christos branches: 1.6.16;
CID 1341556: Don't leak map info
 1.5 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.4 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.3 20-Nov-2013  jnemeth branches: 1.3.4;
Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.2 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos branches: 1.1.1.1.42; 1.1.1.1.48;
Import the gpt tool from FreeBSD
 1.1.1.1.48.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.1.1.42.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.4.1 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36 23-Feb-2025  christos Pass some lint.
 1.35 03-Mar-2019  jnemeth branches: 1.35.12;
add some more FAT file system types
 1.34 10-Feb-2019  martin Make "gpt migrate" work for disks with FAT32 and NTFS partitions
 1.33 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.32 09-Jun-2016  christos branches: 1.32.14; 1.32.16;
Rename 'a' to set the active PMBR flag to 'A'
 1.31 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.30 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.29 06-Dec-2015  christos remove more duplicated code.
 1.28 05-Dec-2015  christos Add debugging and more to migration
 1.27 03-Dec-2015  christos WARNS=6
 1.26 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.25 01-Dec-2015  christos refactor more duplicated code.
 1.24 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.23 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.22 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.21 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.20 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.19 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.18 30-Sep-2014  christos remove compat defines.
 1.17 29-Sep-2014  christos more toolification changes
 1.16 29-Sep-2014  christos more toolification
 1.15 29-Sep-2014  christos minor toolification: need libprop...
 1.14 04-Dec-2013  jakllsch branches: 1.14.4;
Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.13 04-Dec-2013  jakllsch Mirror my changes of src/sbin/gpt/create.c 1.4 in migrate.c;

Use less bogus CHS addresses in PMBR.
With the ending head set at 0xff one machine I have will never leave
the initial startup screen if such a disk is present. Additionally,
Wikipedia suggests without citiation that 254 is the maximium allowable
value for the head, and this seems to be the case.
 1.12 13-Nov-2013  christos CID 1125874: Fix memory leak
 1.11 22-Oct-2013  jnemeth In a NetBSD disklabel, p_offset is from the beginning of the disk,
not the beginning of the NetBSD partition.
 1.10 19-Oct-2013  jnemeth Convert FreeBSD numeric FS_<type>s to labels by request.
 1.9 19-Oct-2013  jnemeth - convert FreeBSD FS_<type> to numbers where they don't match NetBSD
- add support for migrating NetBSD disklabel'ed disks (only 7 years late)
- use labels for partition types
 1.8 19-Oct-2013  jnemeth Add code for detecting FreeBSD ZFS partitions.

XXX Need to add code for migrating NetBSD disklabel'ed disks.
 1.7 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.3 17-Oct-2006  he branches: 1.3.2; 1.3.4; 1.3.8; 1.3.10;
Some of our ports want <sys/param.h> in order to have DEV_BSIZE defined,
needed for LABELSECTOR expansion.
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.8.1 09-Jan-2008  matt sync with HEAD
 1.3.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.3.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.14.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.32.16.1 10-Jun-2019  christos Sync with HEAD
 1.32.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35.12.1 02-Aug-2025  perseant Sync with HEAD
 1.21 24-Feb-2025  christos remove getopt call (noted by rillig@)
 1.20 23-Feb-2025  christos Pass some lint.
 1.19 13-Dec-2020  jnemeth branches: 1.19.8;
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".
 1.18 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.17 22-Mar-2017  martin branches: 1.17.10; 1.17.12;
Add missing endianes swap to make the "recover" command work on big endian
machines.
 1.16 12-Jun-2016  jnemeth branches: 1.16.2; 1.16.4;
- fix setting of hdr_lba_alt which was broken in revision 1.10 on 2015/12/2
- switch to using gpt_last
- PR/51230 -- recreate the PMBR if it was lost
 1.15 04-Dec-2015  christos Fix resizedisk.
 1.14 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.13 03-Dec-2015  christos WARNS=6
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos don't hard-code the program name
 1.10 02-Dec-2015  christos merge duplicated code and check allocations.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 18-Jun-2015  jnemeth Instruct user to use resizedisk if media size has changed, as
resizedisk will adjust the media size in the headers, whereas
recover simply copies the existing header over the missing one.

XXX recover and resizedisk should probably be merged (even if just
partially, so that recover can properly handle media size changes).
Also, reading in the GPT should probably be centralised so that
error handling can be centralised, and users aren't given misleading
messages (i.e. they aren't told to run recover when they should be
running resizedisk). However, something that can be quickly pulled
up to netbsd-7 was needed, and there isn't time for a major overhaul
or rewrite.
 1.5 29-Sep-2014  christos minor toolification: need libprop...
 1.4 27-Aug-2011  joerg branches: 1.4.20;
Use __dead
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.20.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.4.20.2 29-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #847):
sbin/gpt/recover.c: revision 1.6
Instruct user to use resizedisk if media size has changed, as
resizedisk will adjust the media size in the headers, whereas
recover simply copies the existing header over the missing one.
XXX recover and resizedisk should probably be merged (even if just
partially, so that recover can properly handle media size changes).
Also, reading in the GPT should probably be centralised so that
error handling can be centralised, and users aren't given misleading
messages (i.e. they aren't told to run recover when they should be
running resizedisk). However, something that can be quickly pulled
up to netbsd-7 was needed, and there isn't time for a major overhaul
or rewrite.
 1.4.20.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.16.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.16.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.17.12.1 10-Jun-2019  christos Sync with HEAD
 1.17.10.1 28-Jul-2018  pgoyette Sync with HEAD
 1.19.8.1 02-Aug-2025  perseant Sync with HEAD
 1.24 23-Feb-2025  christos Pass some lint.
 1.23 21-Jun-2019  jnemeth branches: 1.23.12;
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.
 1.22 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.21 03-Dec-2015  christos branches: 1.21.14; 1.21.16;
eliminate static globals so that commands can be re-used.
 1.20 01-Dec-2015  christos refactor more duplicated code.
 1.19 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.18 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.17 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.16 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.15 30-Sep-2014  christos remove compat defines.
 1.14 29-Sep-2014  christos minor toolification: need libprop...
 1.13 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.12 28-Nov-2013  jnemeth branches: 1.12.4;
when calling dehumanize_number() make sure the resulting number is >= 1
 1.11 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.10 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.9 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.8 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.7 13-Apr-2013  jakllsch Use correct spelling of "secondary" in comments.
 1.6 27-Aug-2011  joerg branches: 1.6.2; 1.6.8;
Use __dead
 1.5 07-Feb-2009  uebayasi Make manual and usage consistent. No functional changes.
 1.4 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.3 16-Feb-2007  riz branches: 1.3.4; 1.3.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2 15-Oct-2006  christos branches: 1.2.2;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.2.2.1 20-Feb-2007  tron branches: 1.2.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.3.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.4.1 09-Jan-2008  matt sync with HEAD
 1.6.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 23-Jun-2013  tls resync from head
 1.6.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.12.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.21.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.21.16.1 10-Jun-2019  christos Sync with HEAD
 1.21.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.23.12.1 02-Aug-2025  perseant Sync with HEAD
 1.26 23-Feb-2025  christos Pass some lint.
 1.25 24-May-2020  jmcneill branches: 1.25.8;
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.
 1.24 24-Mar-2019  martin 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.
 1.23 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.22 04-Dec-2015  christos branches: 1.22.14; 1.22.16;
Kill newline
 1.21 03-Dec-2015  christos WARNS=6
 1.20 03-Dec-2015  christos remove extra assignment
 1.19 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.18 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.17 01-Dec-2015  christos refactor more duplicated code.
 1.16 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.15 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.14 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.13 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.12 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.11 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.10 30-Sep-2014  christos remove compat defines.
 1.9 29-Sep-2014  christos minor toolification: need libprop...
 1.8 10-Dec-2013  jnemeth branches: 1.8.4; 1.8.6; 1.8.8;
Explicitly state which partition was added/modified.
 1.7 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.6 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.5 28-Nov-2013  jnemeth when calling dehumanize_number() make sure the resulting number is >= 1
 1.4 27-Nov-2013  christos CID 1132764: Bogus test
 1.3 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.2 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.1 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.8.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.8.1 10-Dec-2013  tls file resize.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.8.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.8.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.8.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.4.1 10-Dec-2013  yamt file resize.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.22.16.1 10-Jun-2019  christos Sync with HEAD
 1.22.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.25.8.1 02-Aug-2025  perseant Sync with HEAD
 1.22 23-Feb-2025  christos Pass some lint.
 1.21 06-Feb-2024  christos branches: 1.21.2;
check the right variable
 1.20 22-Nov-2022  mlelstv Big-Endian fixes.
 1.19 20-Nov-2022  mlelstv Fix destroying and moving GPT header also for truncated/extended
images.
 1.18 24-May-2020  jmcneill 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.
 1.17 04-Dec-2015  christos type confusion
 1.16 04-Dec-2015  christos Fix resizedisk.
 1.15 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.14 03-Dec-2015  christos Fix stray paste, noted by kre.
 1.13 03-Dec-2015  christos WARNS=6
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos check allocations
 1.10 01-Dec-2015  christos refactor more duplicated code.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 01-Oct-2014  jnemeth branches: 1.6.2;
oops, forgot to update end of data area
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 23-Sep-2014  msaitoh Fix compile error observed on i386. Use PRIu64.
 1.1 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.6.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.6.2.1 01-Oct-2014  snj file resizedisk.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 23-Feb-2025  christos Pass some lint.
 1.20 07-Jun-2020  thorpej branches: 1.20.8;
Update for proplib(3) API changes.
 1.19 14-May-2020  msaitoh Remove extra semicolon.
 1.18 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.17 07-Sep-2017  christos branches: 1.17.2; 1.17.4;
use __arraycount
 1.16 03-Dec-2015  christos branches: 1.16.8;
WARNS=6
 1.15 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.14 02-Dec-2015  christos - factor out into smaller separate functions
- fix signed/unsigned confusion
- do proper write checks
- fix some memory leaks
 1.13 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.12 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.11 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.10 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.9 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.8 16-Jun-2015  christos fix error messages containing \n
 1.7 01-Oct-2014  jnemeth using random values for hdr->hdr_guid does not work very well
 1.6 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.5 30-Sep-2014  christos remove compat defines.
 1.4 29-Sep-2014  christos minor toolification: need libprop...
 1.3 26-Sep-2014  jnemeth - handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
 1.2 20-Sep-2014  jnemeth Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
 1.1 10-Aug-2014  jnemeth branches: 1.1.2; 1.1.4;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file restore.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.1.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.16.8.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.17.4.1 10-Jun-2019  christos Sync with HEAD
 1.17.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.20.8.1 02-Aug-2025  perseant Sync with HEAD
 1.16 23-Feb-2025  christos Pass some lint.
 1.15 25-Mar-2019  martin branches: 1.15.12;
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.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 29-Dec-2015  christos branches: 1.13.8; 1.13.14;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.12 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.11 03-Dec-2015  christos WARNS=6
 1.10 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos refactor more duplicated code.
 1.8 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.7 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.6 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 10-Dec-2013  jnemeth branches: 1.2.4; 1.2.6; 1.2.8;
Explicitly state which partition was added/modified.
 1.1 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 10-Dec-2013  tls file set.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.2.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 10-Dec-2013  yamt file set.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.15.12.1 02-Aug-2025  perseant Sync with HEAD
 1.47 23-Feb-2025  christos Pass some lint.
 1.46 04-Nov-2024  christos Additions to guid printing and an option to print start/size in hex
(from Anon Ymous)
 1.45 13-Sep-2024  mlelstv Use destination variable also to determine size. No binary change, both
buffers are of the same size.
 1.44 26-Mar-2019  martin branches: 1.44.12;
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.
 1.43 24-Mar-2019  martin Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).
 1.42 03-Mar-2019  jnemeth Make it clear when displaying data from the MBR.
 1.41 07-Sep-2017  christos branches: 1.41.4;
use __arraycount
 1.40 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.39 05-Oct-2016  kre branches: 1.39.6;

Avoiding having parameter name shadow its own function's name.
Strictly this shouldnt be (and hasn't been for almost a year) a problem,
but there are compilers that warn about locals shadowing globals (which
this is/was) and it is easy to avoid, so ... No functinal difference.
 1.38 09-Jun-2016  kre branches: 1.38.2;

Make "gpt show" add an "(active)" annotation to the PMBR output line
when it has been marked active for legacy (non UEFI) booting.
This was (kind of obviously) intended by the previous commit, but...
 1.37 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.36 31-May-2016  dholland PR 50756 David Binderman: avoid running off the end of an array in case
thing we're looking for isn't there. Which is probably impossible, but
that's not obvious.
 1.35 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.34 26-Dec-2015  martin Improve "show -a" display: split human readable Type: field from the Type-GUID
to avoid wrapping in the common case; add a human readable Size: display.
 1.33 25-Dec-2015  wiz Simplify usage for gpt show.
 1.32 25-Dec-2015  martin Add a -a flag to the show command, so we can display the full GPT with
all information in one go.
 1.31 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.30 04-Dec-2015  christos fix label printing.
 1.29 03-Dec-2015  christos WARNS=6
 1.28 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.27 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.26 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.25 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.24 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.23 29-Nov-2015  christos Add the missing cases.
 1.22 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.21 30-Sep-2014  jnemeth correctly show partition type in the new world order
 1.20 30-Sep-2014  jnemeth Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
 1.19 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.18 30-Sep-2014  christos remove compat defines.
 1.17 29-Sep-2014  christos more toolification changes
 1.16 29-Sep-2014  christos minor toolification: need libprop...
 1.15 18-Dec-2013  jnemeth branches: 1.15.4;
If we want to GUIDs to display with correct endian, it helps to decode it first.
 1.14 09-Dec-2013  jnemeth For the "show -i <entry>" subcommand, print Start and Size both in
terms of number of sectors and bytes.
 1.13 08-Dec-2013  jnemeth fix off-by-one error
 1.12 30-Nov-2013  jnemeth Add two new options:

-g which shows the GUID for a partition
-i which shows all the gory details for a particular option

XXX the output format of -i is subject to change
 1.11 19-Oct-2013  jnemeth recognize FreeBSD ZFS partition
 1.10 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.9 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.8 18-Jan-2013  jakllsch Now that GPT_ENT_TYPE_LINUX_DATA is diffrent from the Windows one, use it.
 1.7 27-Aug-2011  joerg branches: 1.7.2; 1.7.8;
Use __dead
 1.6 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.5 24-Feb-2008  christos PR/38094: Robert Millan: support "BIOS Boot" partition type in gpt(8)
 1.4 28-Dec-2007  riz branches: 1.4.2; 1.4.4;
As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.2 23-Mar-2008  matt sync with HEAD
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.2.1 24-Mar-2008  keiichi sync with head.
 1.7.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.8.2 23-Jun-2013  tls resync from head
 1.7.8.1 25-Feb-2013  tls resync with head
 1.7.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.2.1 23-Jan-2013  yamt sync with head
 1.15.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.15.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.38.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.39.6.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.41.4.1 10-Jun-2019  christos Sync with HEAD
 1.44.12.1 02-Aug-2025  perseant Sync with HEAD
 1.17 23-Feb-2025  christos Pass some lint.
 1.16 21-Jun-2019  jnemeth branches: 1.16.12;
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.
 1.15 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 06-Dec-2015  christos branches: 1.13.8; 1.13.14;
Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos use the utility function.
 1.10 01-Dec-2015  christos refactor more duplicated code.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 07-Dec-2014  mlelstv branches: 1.6.2;
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.1 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.6.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.6.2.1 07-Dec-2014  snj file type.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.13.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.16.12.1 02-Aug-2025  perseant Sync with HEAD
 1.16 23-Feb-2025  christos Pass some lint.
 1.15 26-Mar-2019  martin branches: 1.15.12;
Allow -b to specify a partition for "gpt unset" as well.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 29-Dec-2015  christos branches: 1.13.8; 1.13.14;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.12 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.11 03-Dec-2015  christos WARNS=6
 1.10 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos refactor more duplicated code.
 1.8 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.7 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.6 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 10-Dec-2013  jnemeth branches: 1.2.4; 1.2.6; 1.2.8;
Explicitly state which partition was added/modified.
 1.1 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 10-Dec-2013  tls file unset.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.2.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 10-Dec-2013  yamt file unset.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.15.12.1 02-Aug-2025  perseant Sync with HEAD
 1.4 23-Feb-2025  christos Pass some lint.
 1.3 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.2 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.1 25-Jun-2019  jnemeth branches: 1.1.6; 1.1.14;
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.
 1.1.14.1 02-Aug-2025  perseant Sync with HEAD
 1.1.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.6.1 25-Jun-2019  martin file uuid.c was added on branch phil-wifi on 2020-04-13 08:03:20 +0000

RSS XML Feed