summaryrefslogtreecommitdiff
path: root/sbin/fdisk/cmd.c
AgeCommit message (Collapse)Author
2024-03-01Allow fdisk(8) to add GPT partitions of protected types.Kenneth R Westerback
This makes it possible to provision virtual machine images that need a "BIOS Boot" partition. Report, original diff and testing by Christian Ludwig. Thanks! ok miod@
2023-11-18Scan past whitespace before checking if flag string startsKenneth R Westerback
with "0x". Pointed out by Philippe Meunier.
2023-11-10GPT partitions have many attributes. Don't stomp on them all whenKenneth R Westerback
using 'flag <part #>' to make a partition the only bootable partition. Just turn off the bootable bit in the other partitions. ok dlg@
2023-11-10Enhance 'flag' to accept hex values in addition to the current 0Kenneth R Westerback
.. INT64_MAX decimal values.. Easier to specify the 64 bits of GPT partition attributes and 0x8000000000000000 (a.k.a. MS_NOAUTOMOUNT, a.k.a. 1 << 63) becomes accessable. Prompted by bug report and testing by Philippe Meunier. Thanks! ok dlg@
2023-04-10Make GPT display of menu hex octet the same as the MBR display.Kenneth R Westerback
i.e. two digits.
2023-04-09Refactor and simplify GPT menu selection logic.Kenneth R Westerback
No intentional functional change.
2023-04-07Oops. Missed files in last commit.Kenneth R Westerback
2023-03-31Be more consistent in function naming. Functions taking orKenneth R Westerback
returning struct uuid's use 'uuid' in their names. Lengthen a pointlessly short line. No functional change.
2023-03-29Change 'type' to 'menuid' in various struct's, functions andKenneth R Westerback
variables related to gpt partitions. Makes it clear that there is no required tie between mbr partition types and gpt partition types. No functional change.
2023-03-29Simplify code by having PRT_uuid_to_type() return -1 whenKenneth R Westerback
no type can be found. 0 is a valid type! No functional change.
2023-03-26Pass lbuf/lbuflen to PRT_print_[mbr|gpt]_menu() to allow changesKenneth R Westerback
to the original input. Just zap it for now. No functional change.
2023-03-25Make *_name fields char * instead of char[]. Specify desiredKenneth R Westerback
width of output in printf() rather than "%-*s" and sizeof(name) + 1. Clearer, may even save some bytes as many names are shorter than the max. Rename PRT_print_mbrtypes() to PRT_print_mbrmenu() and PRT_print_gpttypes() to PRT_print_gptmenu() to remove implied completeness of list presented in menu. No functional change.
2023-03-25Rename *_sname fields/functions to *_name to remove impliedKenneth R Westerback
shortness of the names. No functional change.
2023-03-04Use nitems() in the simple iterations over mbr->mbr_prt[].Kenneth R Westerback
No intentional functional change.
2023-03-04Toss in some const's to ensure that static data pointed toKenneth R Westerback
by function return values is not fiddled with. No intentional functional change.
2022-09-11Add #define's for GPT partition attribute bits REQUIRED, IGNOREKenneth R Westerback
and BOOTABLE, set BOOTABLE attribute bit instead of using the incorrect GPTDOSACTIVE value, have 'fdisk -v' print out GPT partition attributes if any of the 64 bits are set, don't spoof any partition with REQUIRED bit set. Prompted by kettenis@ stumbling across a machine with 40+ (!!) REQUIRED GPT partitions. Tested & ok kettenis@
2022-07-25Only MBR and GPT structures can be edited by fdisk.Kenneth R Westerback
If neither are found, restrict user actions to printing basic information on the disk, reading the man page, initializing an MBR or GPT, or terminating fdisk without changing anything. Feedback on earlier attempt by miod@ and brynet@.
2022-07-10Add some anti-feline input protection by refusing to processKenneth R Westerback
input of excessive length. Make 'args' parameter to Xfuncs const char * and do the multiple argument parsing in Xswap() and Xflag() on a local copy.
2022-07-10Use nice #define's for input buf size and output help buf size.Kenneth R Westerback
No functional change.
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-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-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-24Use warnx() if errno is not relevant. close() after errno ofKenneth R Westerback
interest is checked, not before. Less confusing error messages.
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-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-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-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-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.
2021-10-21Remove 'disk' editing command. Determining the disk geometry on startup (fromKenneth R Westerback
-l, -c/-h/-s or DIOCGPDINFO) should be enough for anyone.
2021-09-10Stop using NULL as a synonym for "s" (SECTORS). Just use "s".Kenneth R Westerback
Remove now pointless NULL check in unit_lookup(). No intentional functional change.
2021-09-09Simplify logic in USER_edit() loop to eliminate unnecessaryKenneth R Westerback
goto's. Rename CMD_SAVE to CMD_QUIT to reflect actual command (Xquit) and help and man page verbiage. No intentional functional change.
2021-09-02Split part_type into separate types 'mbr_type' and 'gpt_type',Kenneth R Westerback
shrinking static data demands. Split PRT_printall() into PRT_print_mbrtypes() and PRT_print_gpttypes() to eliminate pointless 'pseudo' MBR partition types and pointless display of MBR partition types with no associated GPT GUIDs. Eases future MBR and GPT partition type editing improvements. ok kettenis@
2021-09-01Improve editing GPT partition type GUID's by rejecting partitionKenneth R Westerback
id's that have no associated GUID, rather than disabling the partition. If the current partition type is a GUID with no corresponding partition id, display and use that GUID as the default value. Less surprising behaviour all round.
2021-08-29Nuke unused variable and unnecessary initialization.Kenneth R Westerback
2021-08-28Add hex_octet() so the strtol(..,16) dance is done in just oneKenneth R Westerback
place. Allows single-digit partition id's in '-b' as a side benefit.
2021-08-24Trim leading/trailing whitespace from -e input to make commandKenneth R Westerback
parsing more robust (e.g. 'edit 0 ' is now accepted) and strict (e.g. 'reinit gptx' is now rejected). Input which may want that whitespace is not trimmed (e.g. GPT partition names). Use consistent definition of whitespace corresponding to that used by isspace().
2021-08-15Don't check & errx() after each and every invocation ofKenneth R Westerback
string_from_line(). Just errx() inside string_from_line() if getline() fails. Use strcspn() idiom to nuke '\n' returned by getline(). No functional change.
2021-08-12Further reduce cross-file confusion by adding USER_help() andKenneth R Westerback
calling it from Xhelp(). Move declaration of struct cmd to nestle next to its only instantiation (cmd_table) and use nitems() when scanning cmd_table. No functional change.
2021-08-07Nuke a few Capt. Obvious comments.Kenneth R Westerback
2021-08-06Cleanup, clarify and generally polish the MBR/GPT initializationKenneth R Westerback
code. '-g' is promoted to be independant of '-i'. This makes it clearer that there are four mutually exclusive initialization options. '-i' puts the default MBR on disk, '-g' puts the default GPT on disk, '-u' updates the MBR boot code on disk and '-A' puts a new set of GPT partitions on disk without overwriting 'protected' partitions. The last initialization option specified is the one executed, so existing '-i -g' finger memory, etc. continue to work as before. man page/usage feedback/tweaks from jmc@
2021-07-21A couple of missed 'const'.Kenneth R Westerback
2021-07-21Use a dedicated struct mbr to hold the GPT protective MBR,Kenneth R Westerback
either the one read from disk or the default one created when initializing GPT. Simplifies logic, eliminates MBR_init_GPT() and demotes MBR_protective_mbr() to a helper function called from GPT_read(). Nuke an unused variable in passing. No intentional functional change.
2021-07-19An MBR knows (mbr_lba_self) where it is supposed to go, noKenneth R Westerback
need to pass the value to MBR_write(). Let MBR_write() do the translation from struct mbr to the struct dos_mbr that will be written to the disk. Thus eliminating unnecessary struct dos_mbr variables and the parsing thereof. No intentional functional change.
2021-07-17The first think MBR_init() does is memset(0) the gpt header and gptKenneth R Westerback
partition array. So no need to memset(0) the gpt header before each MBR_init() invocation. No functional change.
2021-07-17Nuke a bunch of Capt. Obvious or misleading comments.Kenneth R Westerback
No functional change.