mount(8): Detect known filesystem types in raw GPT partitions
mount(8) previously only guessed the filesystem from the disklabel
fstype. DIOCGPART already puts the GPT partition type UUID in
partinfo.fstype_uuid, but mount(8) never looked at it. A raw GPT
partition has fstype 0, so mount(8) would warn and fall back to ufs.
Update checkdisklabel() to look the fstype_uuid up in a table of known
GPT partition types (EFI -> msdos, the DragonFly/FreeBSD native types ->
ufs/hammer/hammer2) if the disklabel fstype does not map. Unknown GPT
partition types keep the old warning and ufs fallback.
Bug: #3401
efi/loader: Improve the linker script and LDFLAGS
* Remove the stale comment of `.hash`, which is empty under the default
`--hash-style=gnu`. The image base is also pinned by
`. = 0; ImageBase = .`.
* Fold the remaining linker-generated PLT sections (`.plt.*` and `.iplt`)
into `.text` so the `objcopy -j .text` can never drop them.
* Add `-Wl,-z,defs` to fail the link if there are unresolved symbols,
instead of generating PLT entries for them.
* Add `-Wl,--no-eh-frame-hdr` to skip generating the `.eh_frame_hdr`
section because it's never copied into the final `loader.efi`
executable. What's worse, the generation sidesteps a bug in
bintuils/bfd that produced the misleading overlapping FDEs error, as
observed in the previous commit.
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
mount(8): Detect known filesystem types in raw GPT partitions
mount(8) previously only guessed the filesystem from the disklabel
fstype. DIOCGPART already puts the GPT partition type UUID in
partinfo.fstype_uuid, but mount(8) never looked at it. A raw GPT
partition has fstype 0, so mount(8) would warn and fall back to ufs.
Update checkdisklabel() to look the fstype_uuid up in a table of known
GPT partition types (EFI -> msdos, the DragonFly/FreeBSD native types ->
ufs/hammer/hammer2) if the disklabel fstype does not map. Unknown GPT
partition types keep the old warning and ufs fallback.
Bug: #3401
efi/loader: Improve the linker script and LDFLAGS
* Remove the stale comment of `.hash`, which is empty under the default
`--hash-style=gnu`. The image base is also pinned by
`. = 0; ImageBase = .`.
* Fold the remaining linker-generated PLT sections (`.plt.*` and `.iplt`)
into `.text` so the `objcopy -j .text` can never drop them.
* Add `-Wl,-z,defs` to fail the link if there are unresolved symbols,
instead of generating PLT entries for them.
* Add `-Wl,--no-eh-frame-hdr` to skip generating the `.eh_frame_hdr`
section because it's never copied into the final `loader.efi`
executable. What's worse, the generation sidesteps a bug in
bintuils/bfd that produced the misleading overlapping FDEs error, as
observed in the previous commit.
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
kern: Fix mmioctl() to return ENOTTY for unknown devices
The default case for unknown devices handles /dev/null and previously
returned ENODEV for tcsetattr/tcgetattr/tc* requests, which should be
ENOTTY as specified by POSIX (as well as documented in the man pages).
Fix the bug by correcting mmioctl() to return ENOTTY in the default
case.
Patch-by: jpikin, sigttou (David Bidner)
Bug: https://bugs.dragonflybsd.org/issues/3252
w(1) - Do not warn about non-existent tty lines
ttystat() called warn() when stat("/dev/<line>") failed, so X11 sessions
(ut_line like ":16") printed a spurious
"w: /dev/:16: No such file or directory".
Return NULL silently unless the line is an existing character device.
Matches FreeBSD (see commits 21632754d652d20a4618cac0b52ebe7d8e790865,
d0d0355e4dd9fa060443d3f1b1a223118ff68827).
Fixes #3298
loader: Clear CR0.WP during EFI kernel relocation
Firmware on an HP ProDesk 600 G4 leaves relocation destination pages
read-only. efi_copy_finish() faults at 0x1001000 with page-fault error
code 3 (supervisor write, protection violation) while CR0.WP is set.
Save CR0 and clear WP around the relocation copy after ExitBootServices,
with interrupts disabled. Restore CR0 before entering the kernel. Reject
active CET before leaving boot services, since it prevents clearing WP.
Bug: https://bugs.dragonflybsd.org/issues/3427
w(1) - Do not warn about non-existent tty lines
ttystat() called warn() when stat("/dev/<line>") failed, so X11 sessions
(ut_line like ":16") printed a spurious
"w: /dev/:16: No such file or directory".
Return NULL silently unless the line is an existing character device.
Matches FreeBSD (see commits 21632754d652d20a4618cac0b52ebe7d8e790865,
d0d0355e4dd9fa060443d3f1b1a223118ff68827).
Fixes #3298
loader: Clear CR0.WP during EFI kernel relocation
Firmware on an HP ProDesk 600 G4 leaves relocation destination pages
read-only. efi_copy_finish() faults at 0x1001000 with page-fault error
code 3 (supervisor write, protection violation) while CR0.WP is set.
Save CR0 and clear WP around the relocation copy after ExitBootServices,
with interrupts disabled. Restore CR0 before entering the kernel. Reject
active CET before leaving boot services, since it prevents clearing WP.
Bug: https://bugs.dragonflybsd.org/issues/3427
kern: Fix mmioctl() to return ENOTTY for unknown devices
The default case for unknown devices handles /dev/null and previously
returned ENODEV for tcsetattr/tcgetattr/tc* requests, which should be
ENOTTY as specified by POSIX (as well as documented in the man pages).
Fix the bug by correcting mmioctl() to return ENOTTY in the default
case.
Patch-by: jpikin, sigttou (David Bidner)
Bug: https://bugs.dragonflybsd.org/issues/3252
contrib/flex: Guard against int overflow in sko_push().
sko_sz is an int; doubling it unchecked could overflow and produce a
huge size_t for realloc(). Bail out if it would overflow.
It's sad that the upstream project hasn't had a new release since 2017,
so we decided to directly patch the contributed source.
Bug: #3426
contrib/flex: Guard against int overflow in sko_push().
sko_sz is an int; doubling it unchecked could overflow and produce a
huge size_t for realloc(). Bail out if it would overflow.
It's sad that the upstream project hasn't had a new release since 2017,
so we decided to directly patch the contributed source.
Bug: #3426
libc: reject a negative wchar_t in the UTF-8 encoder
_UTF8_wcrtomb() and _UTF8_wcrtombin() pick the four byte form with
"wc <= 0x10ffff". wchar_t is signed, so every negative value passes
that test and is encoded from its low bits: wcrtomb() of (wchar_t)-1
returns 4 and writes ff bf bf bf, and printf("%lc", -1) prints those
bytes instead of failing with EILSEQ as it does for 0x110000.
Add "wc >= 0 &&" to both tests, as FreeBSD's utf8.c has.
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/57
FreeBSD: https://github.com/freebsd/freebsd-src/commit/8bb93485fb51aac423ec000aa292815cf50bb02c
libc: type a positional %F argument in __find_arguments()
When a format uses positional arguments, __find_arguments() walks it
first to learn the type of every argument, and lists the floating
point conversions as a A e E f g G. F is missing, so a double that
is only referred to through %F never gets a type, its slot in the
argument table stays unset, and the conversion reads whatever is
there:
printf("[%1$F]\n", -INFINITY); [0.000000]
printf("[%1$F]\n", 1.5); [0.000000]
printf("[%F]\n", 1.5); [1.500000]
The same format with %1$f, or with any other conversion of the same
argument, works because those give it a type. abseil's str_format
test compares against the C library and caught it.
Add F next to f in both __find_arguments() and __find_warguments().
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/56
gpt(8): Fix "expand" command to update 'hdr_lba_end'
Update the usuable LBA by fixing the 'hdr_lba_end' after expanding.
Otherwise, the extended partition may extend beyond the usuable LBA.
Bugs: #3276, #3423
libc: reject a negative wchar_t in the UTF-8 encoder
_UTF8_wcrtomb() and _UTF8_wcrtombin() pick the four byte form with
"wc <= 0x10ffff". wchar_t is signed, so every negative value passes
that test and is encoded from its low bits: wcrtomb() of (wchar_t)-1
returns 4 and writes ff bf bf bf, and printf("%lc", -1) prints those
bytes instead of failing with EILSEQ as it does for 0x110000.
Add "wc >= 0 &&" to both tests, as FreeBSD's utf8.c has.
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/57
FreeBSD: https://github.com/freebsd/freebsd-src/commit/8bb93485fb51aac423ec000aa292815cf50bb02c
libc: type a positional %F argument in __find_arguments()
When a format uses positional arguments, __find_arguments() walks it
first to learn the type of every argument, and lists the floating
point conversions as a A e E f g G. F is missing, so a double that
is only referred to through %F never gets a type, its slot in the
argument table stays unset, and the conversion reads whatever is
there:
printf("[%1$F]\n", -INFINITY); [0.000000]
printf("[%1$F]\n", 1.5); [0.000000]
printf("[%F]\n", 1.5); [1.500000]
The same format with %1$f, or with any other conversion of the same
argument, works because those give it a type. abseil's str_format
test compares against the C library and caught it.
Add F next to f in both __find_arguments() and __find_warguments().
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/56
gpt(8): Add '-n' to "expand" to not auto extend the last partition
Add the '-n' option to the "expand" command to not auto extend the last
partition, so only the GPT itself is expanded.
Rewrite the "expand" command description in the man page to read more
clear and fluent.
Bug: #3276
gpt(8): Fix two bugs in "expand" command
* Commit f4b4c056f1 introduced a regression to the "expand" command that
the existing secondary GPT header and table were not relocated to the
new end of the expanded disk, leaving the primary GPT header pointing
at a non-existent secondary GPT. A second run would then creates it.
Fix the regression by always setting the 'map_start' of the existing
secondary GPT header and table to correctly relocate them.
It's actually a hack to directly modify the 'map_start' field instead
of deleting the map entry and then readding it, because there is no
map_delete(). However, this is okay because we don't call map_add()
afterwards.
* Update the usuable LBA by fixing the 'hdr_lba_end' after expanding.
This fixes the warning revealed by the previous commit.
Bugs: #3422, #3423
gpt(8): Add warnings about invalid partition LBA range
* Check the partition LBA range against the disk's usuable LBA range and
warn the invalid LBA ranges. This helps catch errors in GPT header
(e.g., the hdr_lba_end) and table.
* Add a verbose message printing the disk's usuable LBA range.
* Don't hide the CRC errors behind the verbose flag.
Bugs: #3276, #3423
cpdup: Don't pass an uninitialized pointer to getgroups(0, ...).
getmygroups() passed *gidlist to the size-only getgroups() query
before it was initialized. The list argument is ignored when the
size is 0, so pass NULL instead.
Bug: #3425
libevtr: Fix off-by-one in string namespace indexing.
evtr_dump_string() indexed evtr->strings[ns] although the array is
sized EVTR_NS_MAX - 1. The namespace IDs are EVTR_NS_PATH=1,
EVTR_NS_FUNC=2 and EVTR_NS_DSTR=3, so ns == 3 runs one past the array
and aliases the following union member (fmts): the dynamic-string
namespace and the format-string table then share a hashtable, and the
table allocated for that slot by evtr_open_write() leaks.
The read side already uses maps[ns - 1], so make the write side
consistent and only allocate/free the EVTR_NS_MAX - 1 entries.
Also reject ns == 0 in evtr_load_string(); the old check let it
through and maps[ns - 1] would read before the array on corrupt input.
Bug: #3424