gpt(8): Improve "show" command to print a disk summary line
Before print the partition entries, print a disk summary line like:
"Disk /dev/da0: 50.0GB (104857600 512-byte sectors)".
In addition, add a blank line between disks.
Example new output:
```
$ sudo gpt show /dev/da0 ad0
Disk /dev/da0: 50.0GB (104857600 512-byte sectors)
start size index contents
0 1 - PMBR
1 1 - Pri GPT header
2 32 - Pri GPT table
34 2014 - Unused
2048 262144 0 GPT part - EFI System
264192 104591360 1 GPT part - DragonFly Label64
104855552 2015 - Unused
[14 lines not shown]
gpt(8): Print a warning message when gpt_write() fails
gpt_write() is used in many places and all of them don't handle the
writing failure, so update gpt_write() to print a warning message when
it fails.
gpt(8): Fix surrogate pair handling bug in utf16_to_utf8()
* The old code mishandled surrogate pairs and thus failed to recognize
valid UTF-16 characters and would replace them with 0xFFFD. Fix the
code to correctly handle the surrogate pairs.
* Fix an out-of-bound access in the old code when it tried to handle the
surrogate pairs. Check `s16idx < s16len` before accessing it with
`le16toh(s16[s16idx])`.
* Remove the `if (utfchar < 0x200000)` branch, because it's impossible
for `utfchar` exceeding 0x200000.
* Tweak the `while` loop conditional to clean up the code.
Credit: ChatGPT (https://chatgpt.com/)
gpt(8): Change utf8_to_utf16/utf16_to_utf8() to use 'char *'
Use 'char *' instead of 'uint8_t *' for NUL-terminated UTF-8 strings,
making it easier for callers.
gpt(8): Fix bugs in utf8_to_utf16()
- The 'utfchar' was incorrectly reinitialized to zero on every loop
iteration and thus destroyed the decoding state of multi-byte UTF-8
sequences. Fix it.
- Fix the endianness by adding the missing htole16() calls.
Obtained-from: NetBSD
gpt(8): Improve utf8_to_utf16()
- No need to NUL-terminate the UTF-16 string when it needs truncation.
- Pad the remaining characters with zeros. (obtained from NetBSD)
gpt(8): Improve utf16_to_utf8()
- Let caller pass the buffer and thus avoid memory allocation.
- Handle the case that there is no NUL termination, i.e., the partition
name is exactly 36 characters, which is allowed by the specification.
Obtained-from: NetBSD
gpt(8): Fix gpt_read() to report partial read error
A partial read() wouldn't touch 'errno', so the caller was unable to
know the error reason. This caused the program to print an error
message like:
```
gpt show: unable to open device 'vn4': Undefined error: 0
```
Fix gpt_read() to return E2BIG (I couldn't find a better choice) for a
partial read(), so the above error becomes:
```
gpt show: unable to open device 'vn4': Argument list too long
```
Still a bit weird, but better, I guess.
gpt(8): Clear errno before retrying open() in gpt_open()
Otherwise, the stale errno would go through gpt_read() when it failed
with a partial read, and the program would print a weird error message
like:
```
gpt show: unable to open device 'vn4': No such file or directory
```
Suggested-by: swildner
gpt(8): Remove the wrong "-r" option for "recover" command
It doesn't make sense that the "recover" command takes the "-r"
(recoverable) option, so just remove it. I believe it was copied from
the "destroy" command.
kernel: Clean the disklabel packname similar to serno
Reuse the disk_cleanserial() function to clean the disklabel's packname,
which is used to create the device aliases under /dev/by-label/ and
/dev/part-by-label/.
Meanwhile, rename disk_cleanserial() to disk_cleanname() to make it more
intuitive.
kernel: Fix disk_probe() to find device by the same name as creation
The name passed to devfs_find_device_by_name() previously did not check
for DSO_DEVICEMAPPER, which might be different from the name passed to
make_dev_covering(). Introduce the 'name_buf' to store the name with
DSO_DEVICEMAPPER accounted, and pass it to both functions.
gpt.8: Add back the old hybrid MBR example using disklabels
In addition, improve the old example:
- Update to use HAMMER2 instead of the deprecated HAMMER;
- Add a note about the hybrid MBR/GPT setup;
- Add steps to remove unwanted files copied from an installation CD;
- Add steps to update password and remove the 'installer' user.
Requested-by: peeterm
gpt.8: Improve comments for the UEFI booting example
Add partition/slice numbers to the comments, and add the example
'vfs.root.mountfrom' configuration to the comment.
Suggested-by: peeterm
kernel/rman: Fix error return in sysctl_rman().
Matt changed the error handling in 869748ea0626d3966a0b0e1a8223de70ef05
but forgot to return 'error' from now on.
This fixes devinfo -r (show hardware resource information).
fdisk(8): Silence "invalid fdisk partition table" warning
When we're initializing the disk (i.e., with -i or -I flag), silence the
"invalid fdisk partition table found" warning.
gpt(8): Fix "create" on MBR-formatted disk without free space at end
When to invoke "create" on MBR-formatted disk without free space at the
end, gpt(8) would fail with error of "no room for the backup header";
e.g.,
$ sudo gpt show vn5
Disk vn5: 1024MB (2097152 512-byte sectors)
Start Sectors Size Index Contents
0 1 512B - MBR
1 31 15.5KB - Unused
32 2097120 1024MB 0 MBR part 108 (active)
$ sudo gpt -vvv create -f vn5
gpt create: vn5: mediasize=1073741824; sectorsize=512; blocks=2097152
gpt create: vn5: MBR at sector 0
gpt create: vn5: MBR part: type=108, start=32, size=2097120
gpt create: vn5: error: no room for the backup header
[2 lines not shown]