summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.c
AgeCommit message (Collapse)Author
2022-07-17Modernize and cleanse fdisk.8, making it more concise andKenneth R Westerback
aligned with the code. Tweak usage() to stay in step. Usual cogent feedback, tweaks and ok jmc@
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-04-24Use warnx() if errno is not relevant. close() after errno ofKenneth R Westerback
interest is checked, not before. Less confusing error messages.
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
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.
2021-10-19Move get_default_mbr() invocation before DISK_open() invocation and removeKenneth R Westerback
"rpath wpath" from the pledge() invocation. Makes default_dmbr information available to DISK_open(). No intentional functional change.
2021-10-13Nuke builtin_mbr.Kenneth R Westerback
Those architectures needing either MBR boot code (amd64, i386, landisk) or special boot partitions (macppc, loongson) have long used /usr/mdec/mbr to provide that information. Other architectures should not blindly write i386/amd64 boot code into the MBR. Fail quickly if the desired default MBR file is missing. Prompted by deraadt@, tweak from kettenis@.
2021-09-29Don't constrain -b specified block count or block size to be greater than 63.Kenneth R Westerback
Allow any value from 1 to UINT32_MAX. MBR boot partition sizes/offsets are completely machine dependent. Pointed out by loongson.
2021-09-26Revert '-b' change. Forgot required bsd.rd tweak.Kenneth R Westerback
2021-09-26MBR partitions created with '-b' should be marked DOSACTIVE.Kenneth R Westerback
That's what 'bootable' means in the MBR world. GPT partitions created by '-b' are unaffected. Pointed out by kettenis@, obviating need for new option.
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-10Go back to using Xwrite() during initialization phase to makeKenneth R Westerback
sure the same verbiage is emitted as previously. i.e. "Writing MBR at offset 0". Fixes regress complaints.
2021-08-07style(9) says sort getopt() options and the following switch {}Kenneth R Westerback
cases. Make it so. In passing nuke a single use 'error' variable and move an *errstr declaration nearer to its friends. No intentional functional change.
2021-08-07Nuke unneeded #include's, one param.h -> types.h.Kenneth R Westerback
2021-08-07Nuke 'p' that r1.97 snuck into getopt() invocation back in 2015.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-22mbrfile can be 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-19Abstract reading the built-in MBR or MBR file intoKenneth R Westerback
a separate function. No functional change.
2021-07-18Make GPT_read() obtain and validate the on-disk MBR itself, viaKenneth R Westerback
MBR_read(), and report success/failure. Simplifies logic and makes clearer that the protective MBR is a required part of a GPT. With the standardization on 0/-1 return values for helper functions, rename 'valid' to 'error' in GPT_read() to make logic less mind bending. No functional change.
2021-07-18Put MBR_parse() invocation inside MBR_read() instead of alwaysKenneth R Westerback
following an invocation of MBR_read() with a call to MBR_parse(). No 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.
2021-07-15Nuke unused variable.Kenneth R Westerback
2021-07-15No need for separate b_sectors, b_offset and b_type variables. We have structKenneth R Westerback
prt to hold this info in one place. Construct a struct prt to hold the boot partition information and stash it in the struct disk for both MBR and GPT to access as needed. Move the blocks to sectors conversions into DISK_open() with all of its geometry friends. No intentional functional change.
2021-07-15Consolidate disk geometry fiddling, turning -l/-c/-h/-s values into MBRKenneth R Westerback
partition geometry info, into DISK_open(). Resulting in clearer logic. No intentional functional change.
2021-07-12Add 'dk_' prefix to struct disk field names.Kenneth R Westerback
No functional change.
2021-07-11Add 'mbr_' prefix to struct mbr field names.Kenneth R Westerback
Change 'offset' to mbr_lba_self and 'reloffset' to mbr_lba_firstembr to make their use more evident. Adjust a few parameter names to match. Change 'part[]' to mbr_prt[] to reflect that it is an array of struct prt. No functional change.
2021-07-11Move ask_cmd(), ask_num(), ask_pid(), ask_string(), parse_b()Kenneth R Westerback
and crc32(). No functional change.
2021-07-11Add tabs to make variable declarations easierKenneth R Westerback
to read. No functional change.
2021-07-11'return' is not a function call.Kenneth R Westerback
No functional change.
2021-06-28Add another epicycle to -A processing that ensures ONLY theKenneth R Westerback
partition table is changed. Not the GPT header. Not the MBR. And only write back as much partition table information as the header claims to have room for. At a minimum should make -A safer when operating on the Apple M1 GPT. A major overhaul of this code is urgently needed before someone sneezes too hard in its vicinity. Feedback kettenis@ & ok deraadt@
2021-06-25Replace instances of the magic number '64' with a nice #defineKenneth R Westerback
BLOCKALIGNMENT. This will make it more obvious where this 512-byte block count could/should be converted to a disk sector count. No functional change.
2021-06-23The value of -l should be treated as a 512-byte block count.Kenneth R Westerback
Tweak man page.
2021-06-22The values for blocks and offset in -b should be treated as 512-byte blockKenneth R Westerback
counts. Tweak man page accordingly. Requested by deraadt@ and kettenis@.
2021-06-21Add -A option to "safely" initialize a GPT without removingKenneth R Westerback
special boot partitions needed by some hardware. Make it difficult to add, delete or modify those partitions with 'fdisk -e'. Trim back and correct syntax in usage(). Whack at man page verbiage. Suggestions and ok deraadt@
2021-06-20Make -b available to architectures other than amd64 and i386.Kenneth R Westerback
Extend the syntax to allow the boot partition offset and boot partition type to be specified if needed. ok deraadt@ kettenis@
2021-06-14Only use of 'reinited' died in cmd.c r1.100. It is now set in aKenneth R Westerback
couple of places but never checked. Retire it. No functional change.
2021-05-14Tweak the two copies of gpt_chk_mbr() to return the index of the MBRKenneth R Westerback
0xEE (DOSPTYP_EFI) partition, or -1 no usable such partition is found. Adopt a consistent idiom to capture the index for future use. Clean up the gpt_chk_mbr() logic to make it clearer what constraints are being applied when looking for the DOSTYP_EFI partition. No intentional functional change.
2021-05-10Replace some magic numbers with #define's. Rename GPT_get_gpt() toKenneth R Westerback
GPT_read() to match MBR_read(). No intentional functional change.
2021-05-07Replace random mix of u_int* and uint* types with consistent uint* types.Kenneth R Westerback
2021-05-02Try harder to ensure there are no GPT revenants afterKenneth R Westerback
choosing MBR partitioning.
2018-04-26Prefer <fcntl.h> over <sys/fcntl.h> in userlandPhilip Guenther
While here, delete some extra #includes and apply style(9) sort rules. ok deraadt@ krw@ mpi@
2016-12-27The "disk too large" and "only LBA values saved" messages are moreKenneth R Westerback
often confusing than useful these days. Stop emitting them. Prompted by bugs@ report of the 8TB disk travails of Jiri. ok deraadt@ tom@
2016-06-25Move pledge after opendev and DIOCGPDINFO. Fixes e.g. fdisk /dev/tty.Theo Buehler
This diff by deraadt was overlooked far too many times, mostly by me. It's the original fix of the pledge disklabel breakage found by espie. diff by deraadt; ok semarie, tb.
2016-03-28Remove unused variablesRicardo Mestre
OK krw@
2015-12-12In olden times (i + u + e) was considered a clever way to 'or'Kenneth R Westerback
together three boolean values. In today's englightened world we know about '||'. Pointed out by naddy@
2015-12-12Open disk READONLY if none of i, e or u are specified.Kenneth R Westerback
Suggestion, original diff and ok naddy@
2015-12-11Add '-v' flag that forces the display of both GPT's and the MBR.Kenneth R Westerback
Useful for seeing exactly what is currently on the disk. Suggested by a request from kettenis@. Man page & usage ok jmc@