summaryrefslogtreecommitdiff
path: root/sbin/fdisk
AgeCommit message (Collapse)Author
2022-05-12And the man page change too.Kenneth R Westerback
2022-05-12Prevent '-u' when operating on GPT formatted disks, as theKenneth R Westerback
equivalent 'update' editing command already is. Avoids the destruction of the GPT when the preventative MBR is overwritten with the default MBR. ok deraadt@
2022-05-10Align fdisk with the logic used in the kernel and allow theKenneth R Westerback
protective EFI GPT partition to be in MBR partitions 0-3, not just the default partition 0.
2022-05-09Replace a stray 0xA6 with DOSPTYP_OPENBSD. Tweak a ">= 2" to moreKenneth R Westerback
obvious "> 1". Use easier to spot 'ask_yn() == 0' instead of '!ask_yn()'. No functional change.
2022-05-08Rename gt_protected field of struct gpt_type to gt_attr andKenneth R Westerback
#define GTATTR_PROTECT and GTATTR_PROTECT_EFISYS as bits in it. Use GTATTR_PROTECT to replace the magic value of '1' indicating the partition is protected. Use GTATTR_PROTECT_EFISYS to replace hack of checking for "APFS" string in the names of partitions that want the EFI System (a.k.a. 0xEF) partition to be preserved. More flexible and easier to extend protections to new partition types or add new attributes to partition types. No intentional functional change.
2022-05-08Shuffle local helper function declarations and definitions intoKenneth R Westerback
one easy to find spot. Wrap the long lines of gpt_types[] to make room for future expansion. No functional change.
2022-05-07Now that the internal versions of GPT partitions are host-endian,Kenneth R Westerback
simplify PRT_protected_guid() by comparing GUID's with uuid_compare() rather than converting them to strings and using strncmp(). Further clarify logic by doing the EFI Sys dance only if the GUID being tested is not marked as protected. No intentional functional change.
2022-05-06Rename PRT_uuid_to_[protection|typename] to PRT_uuid_to_[protected|sname],Kenneth R Westerback
and PRT_type_to_uuid() to PRT_type_to_guid() so the names clearly match the field names being searched for. No intentional functional change.
2022-05-06When printing the GPT table, display "Microsoft basic data" instead ofKenneth R Westerback
"FAT12" for partition types that are mapped to GPT_UUID_MSDOS. No intentional functional change.
2022-05-03Rework display of partition types, removing unnecessary trailingKenneth R Westerback
blanks in the arrays of type names, simplifying the code and making better use of printf(). Along the way discover that "APFS Recovery" fits, so nuke the annoying "AFPS Recovry" contraction. No intentional functional change. Some "APFS Recovery" nits pointed out by jsg@
2022-04-28Convert the internal GPT partition entries into host-endian formKenneth R Westerback
on input/initialization and back to little-endian when writing to disk. Easier to read the code when letoh*() and uuid_[enc|dec]_* invocations are minimized. No intentional functional change. ok jmatthew@
2022-04-25Push DISK_[read|write]sectors() down to disk.c local functionsKenneth R Westerback
and expose new DISK_[read|write]bytes() functions. Eliminates many bytes <-> sector i/o dances and makes the code much easier to understand. Be a bit more careful to consistently write only bytes that checksums are calculated over. No intentional functional change.
2022-04-25gh_csum an gh_part_csum are not used between initializingKenneth R Westerback
the GPT and calculating them when writing the GPT to disk. No need to update them in add_partition(). Pointed out by jmatthew@
2022-04-24Use warnx() if errno is not relevant. close() after errno ofKenneth R Westerback
interest is checked, not before. Less confusing error messages.
2022-04-23Add missing uuid_dec_le() to init_gp() so -A works onKenneth R Westerback
big-endian architectures too.
2022-04-20Refine the GPT partition entry table validity check to ensureKenneth R Westerback
that the partition entry table associated with the primary GPT header at sector 1 doesn't overwrite the header or intrude into the sectors available for partitions. Similarly ensure that the partition entry table associated with the alternate header does not overwrite that header or intrude into the sectors available for partitions.
2022-04-20Wrap a long line.Kenneth R Westerback
2022-04-20Sigh. Another forgotten header file.Kenneth R Westerback
2022-04-20Simpify code manipulating GPT partition names by coalescingKenneth R Westerback
logic into GPT_get_name(), string_to_name() and name_to_string() functions. Remove unnecessarily abstract functions ask_string(), utf16le_to_string() and string_to_utf16le(). No intentional functional change.
2022-04-20Eliminate some local pointers to gp[pn] and just use gp[pn].Kenneth R Westerback
Fix some whitespace and memset() parameters in passing. No intentional functional change.
2022-04-19Forgot a file for previous commit.Kenneth R Westerback
No functional change.
2022-04-19Bring GPT_print_partition() into line with other functions being passedKenneth R Westerback
an index to the gp[] array by calling said parameter 'pn' and making it const unsigned int. No functional change.
2022-04-19Move declaration of DEBUG-only variable inside #ifdef DEBUG.Kenneth R Westerback
No functional change.
2022-04-19Eliminate superfluous intermediate variables 'pncnt' now thatKenneth R Westerback
gh.gh_part_num does not need a letoh32(). No functional change.
2022-04-18Convert the GPT header read from disk into a host-endian version,Kenneth R Westerback
and then back to little-endian when writing to disk. Reduces the number of invocations of the letoh*() and htole*() functions by 90 or so. Also makes that code much easier to read. No intentional functional change.
2022-04-14Move ((gh_part_size % d_secsize) == 0) validity checkKenneth R Westerback
to get_header() with the rest of the header validity checks. No functional change.
2022-04-13Correct a gh_part_csum calculation used in debug output.Kenneth R Westerback
Always calculate the GPT partition entries checksum over gh_part_num * gh_part_size bytes, not the maximal size of the internal partition entries array. No functional change.
2022-04-13Correct a gh_csum calculation used in debug output.Kenneth R Westerback
Always calculate the GPT header checksum over gh_size bytes (a.k.a. 92), not sizeof(struct gpt_header). Compilers in their wisdom may pad the struct to a nice round size, e.g. 96 bytes. No functional change.
2022-04-13Eliminate a couple of 'XXX' assumptions by calculating the actualKenneth R Westerback
number of sectors a given number of GPT partition entries require. No intentional functional change.
2022-03-31man pages: add missing commas between subordinate and main clausesChristian Weisgerber
jmc@ dislikes a comma before "then" in a conditional, so leave those untouched. ok jmc@
2022-03-16The 'status' parameter to uuid_* functions is uint32_t, not int.Kenneth R Westerback
No intentional functional change.
2022-03-15Always use letoh32(gh.gh_part_num) instead of NGPTPARTITIONS whenKenneth R Westerback
scanning the GPT partition table. gh.gh_part_num reflects the actual size of the table read from/written to the disk and scanning possible entries between this value and the maximum allowed size of a partition table is pointless. No intentional functional change.
2022-03-14Abstract duplicated code scanning gpt_types[] into a helperKenneth R Westerback
function find_gpt_type(). Use find_gpt_type() to simplify the functions obtaining information from gpt_types[]. Add not yet used PRT_uuid_to_protection() to allow simplification of GPT partition protection code.. No intentional functional change.
2022-03-14And the prototype too.Kenneth R Westerback
2022-03-14PRT_uuid_to_typename() can return const char *.Kenneth R Westerback
2022-03-14Nuke extraneous blank line.Kenneth R Westerback
2022-03-13Missing 'or'.Kenneth R Westerback
Pointed out by jmc@
2022-03-11Simple hack to preserve the EFI System partition whenKenneth R Westerback
auto-allocating the space on a disk whose GPT contains any of the magic Apple partitions. One step towards saving the firmware files on Apple M1 machines when installing OpenBSD. Tested & ok kettenis@
2022-02-04Wrap some annoyingly long lines.Kenneth R Westerback
2022-02-04%llu should be enough for anybody, no need to use %lld/(long long) forKenneth R Westerback
uint64_t values.
2022-02-04Remove CHS information from internal representation of MBR partitions. GenerateKenneth R Westerback
CHS information as required when writing MBR to disk, editing a partition in CHS mode or printing MBR. No intentional functional change.
2022-02-03fdisk(8): Make -A preserve BIOS boot partitionVisa Hankala
On PolarFire SoC, the HSS firmware loads HSS payload from BIOS boot partition. Typically the payload carries second-stage low-level boot code, such as U-Boot. If the payload is missing, the SoC is not able to boot normally. Hence automatic disk formatting should not delete the partition. OK krw@
2022-01-27Nuke single use function PRT_fix_BN() and just use the ATA/ATAPI LBA -> CHSKenneth R Westerback
conversion formula LBA = (C × HPC + H) × SPT + (S − 1) instead of the equivalent tortuous arithmetic used in PRT_fix_BN(). No intentional functional change.
2022-01-22Wrap some long lines.Kenneth R Westerback
2022-01-21Split PRT_print() into PRT_print_parthdr() and PRT_print_part()Kenneth R Westerback
to align with GPT functions. Simplifies logic and eliminates the magic invocations to print the header. No functional change.
2022-01-18PRT_make() can just zap the destination dos_partition if theKenneth R Westerback
source prt has prt_ns == 0 or prt_id == DOSPTYP_UNUSED. No functional change.
2022-01-02Stop writing big-endian checksums into the little-endian GPTKenneth R Westerback
header fields gh_csum and gh_part_csum. Constrain kernel to accepting only correct little-endian checksums. Temporarily allow fdisk(8) to read either endian GPTs so that big-endian GPTs can be made correct by a simple 'fdisk -e' && 'w'. Fixes inter-architecture, inter-OS GPT portability and GPT fdisk(8) on big-endian architectures. Broken since initial GPT implementation. Suggestions and ok kettenis@
2021-12-29Tweak some DEBUG output.Kenneth R Westerback
Always put '0x' prefix in front of displayed hex values, i.e. the checksums. Add missing letoh32() so bad endian checksum is clear. Be consistent when displaying 'expected' and 'got' checksums, i.e. 'expected' == calculated checksum and 'got' == checksum found in GPT.
2021-12-28Tweak some DEBUG output.Kenneth R Westerback
'EFI PART' reads better than "TRAP IFE" and checksums are easier to read/compare when shown in hex rather than decimal. Prompted by recent GPT vs disklabel misc@ thread concerning Rob Whitlock's problematic GPT.
2021-12-11Start the default OpenBSD partition either immediately followingKenneth R Westerback
any boot partition specified via '-b' or /usr/mdec/mbr; at the power of 2 block after the first track; or immediately following the MBR if there is only one track. Mark any non-EFISYS boot partition created by -b as DOSACTIVE. Suggested by kettenis@, better than a separate new option. Brings -b behaviour into line with many uses of -e to create boot partitions, allowing for the eventual elimination of said -e uses in the creation of the various boot media and in the install scripts.