History log of /freebsd-current/sys/geom/part/g_part_gpt.c
Revision Date Author Comments
# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 5c9f0f72 26-Oct-2023 Warner Losh <imp@FreeBSD.org>

gpart: Be less picky about GPT Tables in some cases

When we're recoverying a damangae GPT, or when we're restoring a backed
up partition tables, don't enforce the 4k alignment for start/end LBAs.
This is useful for 512e/4kn drives when we're creating a new partition
table or partition. However, when we're trying to fix / restore an old
partition, we shouldn't force this alignment, since in that case it's
more important to use the partition table as is than to optimize
performance by rounding (which isn't required by the standard).

MFC After: 1 week
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D42359


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# bd5d9037 28-Dec-2022 Zhenlei Huang <zlei@FreeBSD.org>

GEOM: Remove redundant NULL pointer check before g_free()

Reviewed by: melifaro, pjd, imp
Approved by: kp (mentor)
Differential Revision: https://reviews.freebsd.org/D37779


# 2e543af1 20-Dec-2022 Zhenlei Huang <zlei@FreeBSD.org>

geom_part: Fix potential integer overflow when checking size of the table

`hdr_entries` and `hdr_entsz` are both uint32_t as defined in UEFI spec.
Current spec does not have upper limit of the number of partition
entries and the size of partition entry, it is potential that malicious
or corrupted GPT header read from untrusted source contains large size of
entry number or size.

PR: 266548
Reviewed by: oshogbo, cem, imp, markj
Approved by: kp (mentor)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D36709


# 5be5d0d5 18-Oct-2022 Zhenlei Huang <zlei.huang@gmail.com>

geom_part: Check number of GPT entries and size of GPT entry

Current specification does not have upper limit of the number of
partition entries and the size of partition entry. In
799eac8c3df597179bbb3b078362f3ff03993a1a Andrey V. Elsukov introduced a
limit maximum number of GPT entries to 4k, but that is for write routine
(gpart create) only. When attaching disks that have large number of GPT
entries exceeding the limit, or disks with large size of partition
entry, it is still possible to exhaust kernel memory.

1. Reuse the limit of the maximum number of partition entries.
2. Limit the maximum size of GPT entry to 1k.

In current specification (2.10) the size of GPT entry is 128 *
2^n while n >= 0, and the size - 128 is reserved. 1k should be
sufficient enough for foreseen future.

PR: 266548
Discussed with: imp
Reviewed by: markj
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D36717


# 9c296a21 12-Oct-2021 Ed Maste <emaste@FreeBSD.org>

geom: Add HiFive boot partitions

As documented in the HiFive Unmatched Software Reference Manual.

Reviewed by: imp, mhorne
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34010


# e3ab141f 02-Nov-2021 Warner Losh <imp@FreeBSD.org>

gpart: Move GPT efimedia reporting to a separate routine

Move the efimedia reporting to g_part_gpt_efimedia and use that from
g_part_gpt_dumpconf to report it.

Sponsored by: Netflix
Reviewed by: mav
Differential Revision: https://reviews.freebsd.org/D32780


# cd853791 27-Nov-2020 Konstantin Belousov <kib@FreeBSD.org>

Make MAXPHYS tunable. Bump MAXPHYS to 1M.

Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.

Make b_pages[] array in struct buf flexible. Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*). Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.

Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys. Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight. Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.

Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.

Suggested by: mav (*)
Reviewed by: imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D27225


# cea05ed9 08-Sep-2020 Eugene Grosbein <eugen@FreeBSD.org>

geom_part: extend kern.geom.part.check_integrity to work on GPT

There are multiple USB/SATA bridges on the market that unconditionally
cut some LBAs off connected media. This could be a problem
for pre-partitioned drives so GEOM complains and does not create
devices in /dev for slices/partitions preventing access to existing data.

We have kern.geom.part.check_integrity that allows us to correct
partitioning if changed from default 1 to 0 but it works for MBR only.
If backup copy of GPT is unavailable due to decreases number of LBAs,
kernel still does not give access to partitions and prints to dmesg:

GEOM: md0: corrupt or invalid GPT detected.
GEOM: md0: GPT rejected -- may not be recoverable.

This change makes it work for GPT too, so it created partitions in /dev
and prints to dmesg this instead:

GEOM: md0: the secondary GPT table is corrupt or invalid.
GEOM: md0: using the primary only -- recovery suggested.

Then "gpart recover" re-created backup copy of GPT
and allows further manipulations with partitions.

This change is no-op for default configuration having
kern.geom.part.check_integrity=1

Reported by: Alex Korchmar
MFC after: 3 days.


# cb1480f8 17-Aug-2020 Conrad Meyer <cem@FreeBSD.org>

gpart(8): Recognize apple-zfs and solaris-reserved partition ids

Introduce G_PART_ALIAS_SOLARIS_RESERVED, GPT_ENT_TYPE_SOLARIS_RESERVED et al.,
to make gpart show output more convenient on systems with illumos/openindiana
disks visible.

Submitted by: Juraj Lutter <otis AT sk.FreeBSD.org>
Reviewed by: bcr(manpages), delphij, myself
Differential Revision: https://reviews.freebsd.org/D26012


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# ef03f57d 03-Sep-2019 Kyle Evans <kevans@FreeBSD.org>

Allow more nesting of GEOM partitioning schemes

GEOM is supposed to be topology-agnostic, but the GPT and BSD partition code
has arbitrary restrictions on nesting that are annoying in cases such as
running VMs on raw partitions (since the VM's partitioning scheme is not
visible to the host).

This patch adds sysctls to disable the restrictions except in the case of
BSD label (and similar) partitions with offset 0 (where we need to avoid
recursively recognizing the label).

Submitted by: Andrew Gierth
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D21350


# 49ee0fce 19-Jun-2019 Alexander Motin <mav@FreeBSD.org>

Use sbuf_cat() in GEOM confxml generation.

When it comes to megabytes of text, difference between sbuf_printf() and
sbuf_cat() becomes substantial.

MFC after: 2 weeks
Sponsored by: iXsystems, Inc.


# f89d2072 17-Jun-2019 Xin LI <delphij@FreeBSD.org>

Separate kernel crc32() implementation to its own header (gsb_crc32.h) and
rename the source to gsb_crc32.c.

This is a prerequisite of unifying kernel zlib instances.

PR: 229763
Submitted by: Yoshihiro Ota <ota at j.email.ne.jp>
Differential Revision: https://reviews.freebsd.org/D20193


# 96937e3b 04-Mar-2019 Marcel Moolenaar <marcel@FreeBSD.org>

Revert revision 254095

In revision 254095, gpt_entries is not set to match the on-disk
hdr_entries, but rather is computed based on available space.
There are 2 problems with this:

1. The GPT backend respects hdr_entries and only reads and writes
that number of partition entries. On top of that, CRC32 is
computed over the table that has hdr_entries elements. When
the common code works on what is possibly a larger number, the
behaviour becomes inconsistent and problematic. In particular,
it would be possible to add a new partition that on a reboot
isn't there anymore.
2. The calculation of gpt_entries is based on flawed assumptions.
The GPT specification does not dictate that sectors are layed
out in a particular way that the available space can be
determined by looking at LBAs. In practice, implementations
do the same thing, because there's no reason to do it any
other way. Still, GPT allows certain freedoms that can be
exploited in some form or shape if the need arises.

PR: 229977
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D19438


# 74d6c131 10-Apr-2018 Kyle Evans <kevans@FreeBSD.org>

Annotate geom modules with MODULE_VERSION

GEOM ELI may double ask the password during boot. Once at loader time, and
once at init time.

This happens due a module loading bug. By default GEOM ELI caches the
password in the kernel, but without the MODULE_VERSION annotation, the
kernel loads over the kernel module, even if the GEOM ELI was compiled into
the kernel. In this case, the newly loaded module
purges/invalidates/overwrites the GEOM ELI's password cache, which causes
the double asking.

MFC Note: There's a pc98 component to the original submission that is
omitted here due to pc98 removal in head. This part will need to be revived
upon MFC.

Reviewed by: imp
Submitted by: op
Obtained from: opBSD
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D14992


# ee4d316f 06-Mar-2018 Conrad Meyer <cem@FreeBSD.org>

g_part_gpt: Fix memory leak in error path

If g_part_gpt_read() encountered a disk with bad primary and secondary
tables, it could leak memory.

Reported by: Coverity
Sponsored by: Dell EMC Isilon


# b42712a8 10-Feb-2018 Conrad Meyer <cem@FreeBSD.org>

Add GUID and alias for Apple APFS partition

PR: 225813
Submitted by: James Wright <james.wright AT jigsawdezign.com>


# 3728855a 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/geom: adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 2ab96835 20-Nov-2017 Warner Losh <imp@FreeBSD.org>

Remove trailing whitespace (one I just introduced and a bunch of
others in the same directory).

Sponsored by: Netflix


# a905e396 02-Sep-2017 Warner Losh <imp@FreeBSD.org>

The hard drive media device path contains the size of the partition,
not its end. This makes the GEOM efimedia attribute match the
FreeBSD:Boot1Device environment variable now.

Sponsored by: Netflix


# ab4effdc 01-Sep-2017 Warner Losh <imp@FreeBSD.org>

Add efimedia attribute for all GPT partitions.

Sposnored by: Netflix
Differential Revision: https://reviews.freebsd.org/D12206


# 9ef60043 03-Feb-2017 Andrey V. Elsukov <ae@FreeBSD.org>

Check that primary GPT header is valid before wiping partitioning.

This allows safely destroy corrupted GPT when primary header was
rewritten by some data, that do not want to destroy.

MFC after: 1 week


# 55e0987a 26-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: extend use of the howmany() macro when available.

We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.


# 9c0c355f 27-Dec-2015 Allan Jude <allanjude@FreeBSD.org>

Add some additional GPT partition types

4 ChromeOS GPT types
2 Microsoft partition types
the new OpenBSD partition type

Approved by: marcel (mentor)
MFC after: 1 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D3841


# af90a872 10-Dec-2015 Andrey V. Elsukov <ae@FreeBSD.org>

Make detection of GPT a bit more reliable.

When we are detecting a partition table and didn't find PMBR, try to
read backup GPT header from the last sector and if it is correct,
assume that we have GPT.

Reviewed by: rpokala
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D4282


# ce808c7a 14-Jul-2015 Allan Jude <allanjude@FreeBSD.org>

Add a new option to gpart(8) to fix Lenovo BIOS boot issue

PR: 184910
Reviewed by: ae, wblock
Approved by: marcel
MFC after: 3 days
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D3065


# e7d0c7e4 07-Jun-2015 Andrey V. Elsukov <ae@FreeBSD.org>

Teach G_PART_GPT class to handle g_resize_provider event.

MFC after: 10 days


# 4fb4ebe0 12-Mar-2015 Andrey V. Elsukov <ae@FreeBSD.org>

Add GUID and alias for Apple Core Storage partition.

PR: 196241
MFC after: 1 week


# 1ee0f089 04-Jul-2014 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

After EFI support was added to the installer, it needed to allow boot
partitions of types other than "freebsd-boot" (in particular, "efi").
This allows the removal of some nasty hacks for supporting PowerPC systems,
in particular aliasing freebsd-boot to apple-boot on APM and an IBM-specific
code on MBR.

This changes the installer to use the correct names, which also breaks a
degeneracy in the meaning of "freebsd-boot" that allows the addition
of support for some newer IBM systems that can boot from GPT in addition to
MBR. Since I have no idea how to detect which those systems are, leave
the default on IBM PPC systems as MBR for now.


# 4042ab48 11-Jun-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Allow swapping to DragonFlyBSD's swap partition.

MFC after: 2 weeks


# 0640b71d 11-Jun-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Add aliases for DragonFlyBSD's partition types.

MFC after: 2 weeks


# 39dcac84 30-May-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Use g_conf_printf_escaped() to escape symbols, which can break
an XML tree.

MFC after: 1 week


# 4787115d 12-Apr-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Align and round the partitionable disk space to 4K by default.
Since this would also apply when recovering, make sure not to
align or round when that would have a partition fall outside
the partitionable area.


# 5cc596c4 26-Dec-2013 Dmitry Morozovsky <marck@FreeBSD.org>

Add GPT UUID for VMware vSAN meta-data partition.

Approved by: ae
MFC after: 2 weeks


# 3e5a0a6b 21-Nov-2013 Marcel Moolenaar <marcel@FreeBSD.org>

Have the GPT probe return a lower priority when the MBR is not a PMBR
The purpose of the PMBR is to have the disk appear in use to GPT
unaware utilities (like fdisk). However, if the PMBR has been changed
by a GPT unaware utlity then we must assume that this was deliberate
(as it involved removal of the special slice) and we should not treat
the unmodified GPT-specific sectors as being valid. By lowering the
probe priority in that case, the MBR scheme will take precedence and
the kernel will end up using the MBR and not the GPT. We will still
use the GPT if the kernel does not support the MBR scheme.


# 884c8e4f 17-Oct-2013 Andrey V. Elsukov <ae@FreeBSD.org>

Add an automatic resize support to the GEOM_PART class.

When parent provider has been resized, the scheme specific G_PART_RESIZE
method does an update of scheme's metadata. But all changes are not saved
to disk, until `gpart commit` will be called.

Discussed with: trasz
MFC after: 1 month


# b74dd6c7 08-Aug-2013 Andrey V. Elsukov <ae@FreeBSD.org>

gpt_entries is used as limit for the number of partition entries in
the GEOM_PART. Instead of just using number of entries from the GPT
header, calculate this limit based on the reserved space between
GPT header and first available LBA.

MFC after: 2 weeks


# 3bd22a9c 09-Jun-2013 Marcel Moolenaar <marcel@FreeBSD.org>

Change the set and unset ctlreqs by making the index argument optional.
This allows setting attributes on tables. One simply does not provide
an index in that case. Otherwise the entry corresponding the index has
the attribute set or unset.

Use this change to fix a relatively longstanding bug in our GPT scheme
that's the result of rev 198097 (relatively harmless) followed by rev
237057 (damaging). The damaging part being that our GPT scheme always
has the active flag set on the PMBR slice. This is in violation with
EFI. Existing EFI implementions for both x86 and ia64 reject the GPT.
As such, GPT disks created by us aren't usable under EFI because of
that.

After this change, GPT disks never have the active flag set on the PMBR
slice. In order to make the GPT disk bootable under some x86 BIOSes,
the reason of rev 198097, one must now set the active attribute on the
gpt table. The kernel will apply this to the PMBR slice For (S)ATA:
gpart set -a active ada0

To fix an existing GPT disk that has the active flag set in the PMBR,
and that does not need the flag, use (again for (S)ATA):
gpart unset -a active ada0

The EBR, MBR & PC98 schemes, which also impement at least 1 attribute,
now check to make sure the entry passed is valid. They do not have
attributes that apply to the table.


# d4746e10 14-Jun-2012 Andrey V. Elsukov <ae@FreeBSD.org>

Always reconstruct partition entries in the PMBR when Boot Camp is
disabled. This helps to easily recover from situations when PMBR is
damaged and contains no entries.

MFC after: 1 week


# f24a8224 25-May-2012 Marcel Moolenaar <marcel@FreeBSD.org>

Add a partition type for nandfs to the apm, bsd, gpt and vtoc8 schemes.
The gpart alias for these partition types is "freebsd-nandfs".


# b20e4de3 18-Apr-2012 Dmitry Morozovsky <marck@FreeBSD.org>

VMware environments are not unusual now. Add VMware partitions recognition
(both MBR for ESXi <= 4.1 and GPT for ESXi 5) to g_part.

Reviewed by: ae
Approved by: ae
MFC after: 2 weeks


# 369fe59d 22-Oct-2011 Marcel Moolenaar <marcel@FreeBSD.org>

Add support for Boot Camp. The support is defined as follows:
o Detect when Boot Camp is enabled (i.e. the MBR mirrors the GPT).
o When Boot Camp is enabled, update the MBR whenever we write the GPT.
o Creation of a Boot Camp enabled GPT is not supported.
o Automatically disable Boot Camp when the GPT has been changed so that
there's either no EFI partition or no HFS+ partition.
o The first 4 partitions (by index) get mirrored in the MBR.

Requested by, discussed with and tested by: kris@pcbsd.org
MFC after: 1 week


# 2b9be055 28-Jun-2011 Andrey V. Elsukov <ae@FreeBSD.org>

Initialize elements of state array when creating the GPT table.
This fixes the problem, when the secondary GPT header is not erased when
partition table destroyed. Move equal operations from g_part_gpt_create
and g_part_gpt_recover to the separate function g_gpt_set_defaults.

Reported by: dwhite
MFC after: 1 week


# cb08c2cc 25-Feb-2011 Alexander Leidinger <netchild@FreeBSD.org>

Add some FEATURE macros for various GEOM classes.

No FreeBSD version bump, the userland application to query the features will
be committed last and can serve as an indication of the availablility if
needed.

Sponsored by: Google Summer of Code 2010
Submitted by: kibab
Reviewed by: silence on geom@ during 2 weeks
X-MFC after: to be determined in last commit with code from this project


# 88007f61 28-Jan-2011 Andrey V. Elsukov <ae@FreeBSD.org>

Add new user-friendly aliases for partition types for the MBR and
EBR schemes: fat32, ebr, linux-data, linux-raid, linux-swap and
linux-lvm. Add bios-boot GUID and alias for the GPT scheme. It used by
GRUB 2 loader. Also do sorting definitions of types in diskmbr.h
and in g_part.c.

PR: bin/120990, kern/147664
MFC after: 2 weeks


# 799eac8c 18-Jan-2011 Andrey V. Elsukov <ae@FreeBSD.org>

Limit maximum number of GPT entries to 4k. It is most realistic value
and can prevent kernel memory exhausting when big value is specified
from command line.

Split reading and writing operation to several iteration to do not
trigger KASSERT when data length is greater than MAXPHYS.

PR: kern/144962, kern/147851
MFC after: 2 weeks


# ed7beddc 07-Jan-2011 Matthew D Fleming <mdf@FreeBSD.org>

Fix a memory overflow where the input length to g_gpt_utf8_to_utf16()
was specified incorrectly, causing the bzero to run past the end of a
malloc(9)'d object.

Submitted by: Eric Youngblut < eyoungblut AT isilon DOT com >
MFC after: 3 days


# e7926a37 25-Oct-2010 Andrey V. Elsukov <ae@FreeBSD.org>

Reimplemented "gpart destroy -F". Now it does all work in kernel.
This was needed for recover implementation.

Implement the recover command for GPT. Now GPT will marked as
corrupt when any of three types of corruption will be detected:
1. Damaged primary GPT header or table
2. Damaged secondary GPT header or table
3. Secondary header is not located in the last LBA
Marked GPT becomes read-only. Any changes with corrupt table
are prohibited. Only "destroy" and "recover" commands are allowed.

Discussed with: geom@ (mostly silence)
Tested by: Ilya A. Arhipov
Approved by: mav (mentor)
MFC after: 2 weeks


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# cec283ba 24-Sep-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Allow to configure GPT attributes. It shouldn't be allowed to set bootfailed
attribute (it should be allowed only to unset it), but for test purposes it
might be useful, so the current code allows it.

Reviewed by: arch@ (Message-ID: <20100917234542.GE1902@garage.freebsd.pl>)
MFC after: 2 weeks


# 2ff16af0 11-Jun-2010 Marius Strobl <marius@FreeBSD.org>

MFC: r208746

Don't leak memory on destruction.

Reviewed by: marcel
Approved by: re (kib)


# 36066952 02-Jun-2010 Marius Strobl <marius@FreeBSD.org>

Don't leak memory on destruction.

Reviewed by: marcel
MFC after: 3 days


# 84ba62ee 31-May-2010 Andriy Gapon <avg@FreeBSD.org>

MFC r201374: g_part_gpt: Properly return the UUID represented by the alias

PR: kern/142174
Approved by: re (kib)
Approved by: marcel


# f85c1a35 23-May-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

MFC r200534,200535:

Simplify partition type parsing by using a data-oriented model.
While there add more Apple and Linux partition types.

This unbreaks the build after r208341.

Reported by: many
Pointy hat to: me


# 3f71c319 22-Apr-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Implement the resize verb and add support for resizing partitions
for all schemes but EBR. Quality work by Andrey!

Submitted by: "Andrey V. Elsukov" <bu7cher@yandex.ru>


# cd18ad83 30-Jan-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Export the UUID of the partition in the XML. The partition UUID is used
by EFI's device path to identify a partition. In order for FreeBSD to
add EFI boot options, proper device paths need to be constructed.


# 665bb830 01-Jan-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Properly return the UUID represented by the alias.

PR: 142174
Submitted by: Przemyslaw Laczynski <torindel@gmail.com>
Pointy hat to: rpaulo


# 33f7a412 14-Dec-2009 Rui Paulo <rpaulo@FreeBSD.org>

Add Microsoft and NetBSD partition types handling.


# f1317430 14-Dec-2009 Rui Paulo <rpaulo@FreeBSD.org>

Simplify partition type parsing by using a data-oriented model.
While there add more Apple and Linux partition types.


# 4cb9493f 21-Nov-2009 Robert Noland <rnoland@FreeBSD.org>

MFC r199017,199228

Fix handling of GPT headers when size is > 92 bytes.

This should address reading GPT headers written by opensolaris.


# bbe1ae35 19-Nov-2009 Rui Paulo <rpaulo@FreeBSD.org>

MFC 199232:
Add a missing check for Apple HFS partitions.


# f9d551f7 12-Nov-2009 Rui Paulo <rpaulo@FreeBSD.org>

Add a missing check for Apple HFS partitions.

MFC after: 1 week


# a59a1310 12-Nov-2009 Robert Noland <rnoland@FreeBSD.org>

We need to allocate space for the header in the create path also.

This fixes a null pointer dereference with "gpart create -s GPT" after
the previous commit.

Reported by: Yuri Pankov
Pointyhat to: me
MFC after: 1 week


# 1c2dee3c 07-Nov-2009 Robert Noland <rnoland@FreeBSD.org>

Fix handling of GPT headers when size is > 92 bytes.

It is valid for an on-disk GPT header to report a header size which is
greater than 92 bytes. Previously, we would read in the sector and copy
only the 92 bytes that we know how to deal with before calculating the
checksum for comparison. This meant that when we did the checksum, we
overshot the buffer and took in random memory, so the checksum would fail.

We now determine the size of the header and allocate enough space to
preserve the entire on-disk contents. This allows us to be correctly
calculate the checksum and be able to modify and write the header back
to the disk, while preserving data that we might not understand.

Reported by: Kris Weston
Approved by: marcel@
MFC after: 2 weeks


# 713444a9 30-Oct-2009 Robert Noland <rnoland@FreeBSD.org>

MFC r198097

Set the active flag in the PMBR when we install bootcode on a GPT
partitioned disk. Some BIOS require this to be set before they will
boot the device.


# e80d42dd 14-Oct-2009 Robert Noland <rnoland@FreeBSD.org>

Set the active flag in the PMBR when we install bootcode on a GPT
partitioned disk. Some BIOS require this to be set before they will
boot the device.

Approved by: marcel
MFC after: 2 weeks


# 87b51e53 17-Aug-2009 Marcel Moolenaar <marcel@FreeBSD.org>

MFC rev 196333:
The start of the EFI GPT partition in the PMBR can always be represented
by CHS addressing. Don't define these fields as 0xff, but rather define
them correctly. This prevents boot problems on PCs where GPT is being
used.

PR: 115406
Submitted by: Kent Hauser <kent@khauser.net>
Approved by: re (kib)


# 85301372 17-Aug-2009 Marcel Moolenaar <marcel@FreeBSD.org>

The start of the EFI GPT partition in the PMBR can always be represented
by CHS addressing. Don't define these fields as 0xff, but rather define
them correctly. This prevents boot problems on PCs where GPT is being
used.

PR: 115406
Submitted by: Kent Hauser <kent@khauser.net>
Approved by: re (kib)


# 2a1c00ff 29-Mar-2009 Marcel Moolenaar <marcel@FreeBSD.org>

Sharpen the saw:
o Don't create a GPT scheme underneath another scheme when
the probe doesn't allow it.


# 51f53a08 09-Feb-2009 Warner Losh <imp@FreeBSD.org>

Fix g_part_dumpconf and g_part_name prototpyes.

Submitted by: marcel@


# 66477112 30-Nov-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Allow boot code to be smaller than what the scheme expects.
This effectively changes the boot code size to be an upper
bound and makes the interface more flexible.


# dd0db05d 06-Nov-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Fix a panic caused by a corrupted table when the header is
still valid. We were checking the state of the header and
not the table.

PR: 119868
Based on a patch from: Jaakko Heinonen <jh@saunalahti.fi>
MFC after: 1 week


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 87662ab3 05-Sep-2008 Rui Paulo <rpaulo@FreeBSD.org>

Keep entries sorted.


# d7255ff4 04-Sep-2008 Rui Paulo <rpaulo@FreeBSD.org>

Detect Apple HFS GPT slices.


# d3532631 12-Jun-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Finish the support for partition labels and add it to the XML.


# 0c132595 11-Jun-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Add the raw partiton type to the XML.


# 5db67052 23-Apr-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Implement the G_PART_DUMPCONF method for all 6 schemes. Also call
the method for the (indent == NULL) case (i.e. the kern.geom.conftxt
sysctl). The purpose is to extend the conftxt output with scheme-
specific fields which can be used by libdisk. In particular, have
the schemes dump the xs and xt fields, which contain the backward
compatible values for class type and partition type. This allows
libdisk to work with the legacy slicers as well as with gpart and
helps/promotes migration.


# 4d32fcb4 13-Apr-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Add the bootcode verb for installing boot code. Boot code
is supported for the MBR, GPT and PC98 schemes, where GPT
installs boot code into the PMBR.


# 4ffca444 22-Mar-2008 Marcel Moolenaar <marcel@FreeBSD.org>

Redefine G_PART_SCHEME_DECLARE() from populating a private linker set
to declaring a proper module. The module event handler is part of the
gpart core and will add the scheme to an internal list on module load
and will remove the scheme from the internal list on module unload.
This makes it possible to dynamically load and unload partitioning
schemes.


# f352a0d4 24-Oct-2007 John Baldwin <jhb@FreeBSD.org>

First cut at support for booting a GPT labeled disk via the BIOS bootstrap
on i386 and amd64 machines. The overall process is that /boot/pmbr lives
in the PMBR (similar to /boot/mbr for MBR disks) and is responsible for
locating and loading /boot/gptboot. /boot/gptboot is similar to /boot/boot
except that it groks GPT rather than MBR + bsdlabel. Unlike /boot/boot,
/boot/gptboot lives in its own dedicated GPT partition with a new
"FreeBSD boot" type. This partition does not have a fixed size in that
/boot/pmbr will load the entire partition into the lower 640k. However,
it is limited in that it can only be 545k. That's still a lot better than
the current 7.5k limit for boot2 on MBR. gptboot mostly acts just like
boot2 in that it reads /boot.config and loads up /boot/loader. Some more
details:
- Include uuid_equal() and uuid_is_nil() in libstand.
- Add a new 'boot' command to gpt(8) which makes a GPT disk bootable using
/boot/pmbr and /boot/gptboot. Note that the disk must have some free
space for the boot partition.
- This required exposing the backend of the 'add' function as a
gpt_add_part() function to the rest of gpt(8). 'boot' uses this to
create a boot partition if needed.
- Don't cripple cgbase() in the UFS boot code for /boot/gptboot so that
it can handle a filesystem > 1.5 TB.
- /boot/gptboot has a simple loader (gptldr) that doesn't do any I/O
unlike boot1 since /boot/pmbr loads all of gptboot up front. The
C portion of gptboot (gptboot.c) has been repocopied from boot2.c.
The primary changes are to parse the GPT to find a root filesystem
and to use 64-bit disk addresses. Currently gptboot assumes that the
first UFS partition on the disk is the / filesystem, but this algorithm
will likely be improved in the future.
- Teach the biosdisk driver in /boot/loader to understand GPT tables.
GPT partitions are identified as 'disk0pX:' (e.g. disk0p2:) which is
similar to the /dev names the kernel uses (e.g. /dev/ad0p2).
- Add a new "freebsd-boot" alias to g_part() for the new boot UUID.

MFC after: 1 month
Discussed with: marcel (some things might still change, but am committing
what I have so far)


# a1fedf91 21-Oct-2007 Marcel Moolenaar <marcel@FreeBSD.org>

Add the freebsd-zfs alias. Both APM and GPT have ZFS partition
types.


# cf231470 05-Jun-2007 Marcel Moolenaar <marcel@FreeBSD.org>

Prefix unknown (i.e. un-aliased) partition types with '!'. This is
how they had to be given with ctlreq.


# d287f590 08-May-2007 Marcel Moolenaar <marcel@FreeBSD.org>

MFp4:
119373: o Remove the query verb, along with the request and response
parameters.
o Add the version and output parameters.
119390: [APM,GPT] Properly clear deleted entries.
119394: o Make the alias the standard and use the '!' to prefix
literal partition types.
o Treat schemes and partition types as case insensitive.
119462: [GPT] Fix a page fault caused when modifying a partition entry
without a new partition type.


# 1d3aed33 07-Feb-2007 Marcel Moolenaar <marcel@FreeBSD.org>

Evolve the ctlreq interface added to geom_gpt into a generic
partitioning class that supports multiple schemes. Current
schemes supported are APM (Apple Partition Map) and GPT.
Change all GEOM_APPLE anf GEOM_GPT options into GEOM_PART_APM
and GEOM_PART_GPT (resp).

The ctlreq interface supports verbs to create and destroy
partitioning schemes on a disk; to add, delete and modify
partitions; and to commit or undo changes made.