summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.c
AgeCommit message (Collapse)Author
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@
2015-12-01Make '-i' set 'reinited' flag so that the initial Xwrite() will zapKenneth R Westerback
any undesirable GPT hanging around. i.e. same as 'reinit' from the fdisk(8) command line. Noticed now that install media relies on '-i' rather than issuing 'reinit' in a script.
2015-11-24pledge "stdio rpath wpath disklabel proc exec" throughout, afterTheo de Raadt
krw's refactorings which hoisted disk-opening to the top. tested by krw
2015-11-19Oops. Missed a file.Kenneth R Westerback
Reduce overburden of unnecessary #include's. Note that param.h is included only for DEV_BSIZE. Use INT64_MAX instead of LLONG_MAX so stdint.h is enough. General tidying up of #include sections. ok GCC
2015-11-18Parse the original on-disk MBR into a local variable. Use theKenneth R Westerback
partition table in this variable when doing an 'u'pdate of the MBR. Remove now superfluous MBR_pcopy() and its re-read of the on-disk MBR.
2015-11-18g_flag does not need to be a global. Move it inside main().Kenneth R Westerback
2015-11-18Rejig the MBR file reading logic soKenneth R Westerback
1) If mbr_file is NULL use built-in mbr for -i, -u and 'reinit'. 2) If mbr_file cannot be opened issue a warning and use built-in mbr for -i, -u, and 'reinit'. 3) If mbr_file can't be read, bail out of fdisk. 4) Use the mbr read from mbr_file for -i, -u, and 'reinit'. Remove inappropriate GPT dancing. This restores pre-GPT-editing mbr_file handling and makes the logic clearer at the expense of a tiny bit of duplication.
2015-11-18Read MBR immediately, and only read the GPT if the MBR is aKenneth R Westerback
protective MBR.
2015-11-15Move zapping of invalid GPT data into GPT_get_gpt() rather thanKenneth R Westerback
returning a value to tell callers to zap it. Use consistant idiom to check for the presence of a GPT (check gh.gh_sig). When zapping GPT, always zap both the header and partition table just for paranoia's sake.
2015-11-14Since -l is ignored if -c/-h/-s are specified, make that combinationKenneth R Westerback
invalid and mention the constraint in usage(). Modify the appropriate field(s) of the global 'disk' as -l/-c/-h/-s are encountered. As a result use the disklabel information to populate the global 'disk' only when it has not already been populated. Move test for 'disk' validity into DISK_open().
2015-11-14Consolidate usage() checking for -c/-h/-s with other checks. TweakKenneth R Westerback
usage() verbiage a bit so it's clear all of '-c -h -s' are required if any are used.
2015-11-14pledge("stdio", NULL) for code path that just prints the MBR or GPT. i.e.Kenneth R Westerback
when none of -i, -e or -u are specified. Prodded by deraadt@
2015-11-14If none of -i, -u or -e are specified exit immediately after theKenneth R Westerback
MBR or GPT is printed. Do not attempt to read the MBR template file, construct an initial mbr, etc.
2015-11-13No need to supplement usage() with extra messages about -b needing -i, orKenneth R Westerback
-g needing -i. The usage() text is quite clear. usage() doesn't return so eliminate unneeded 'else'.
2015-11-13No need to zero a global variable before use.Kenneth R Westerback
2015-11-13Make usage() output fit on a 'normal' 80-character line. Tweak someKenneth R Westerback
verbiage in the usage() output.
2015-11-13Move from opening/closing disk for every i/o to opening the disk onceKenneth R Westerback
and saving the fd in the global 'disk' structure. Stop passing around fd's and just use the global. Makes pledge() feasible. Prompted by and ok deraadt@
2015-11-11Display full disk size when editing GPT, not the truncated MBR size. DisplayKenneth R Westerback
'disk too large' message only when no GPT is found. Problems found, fix tested and ok naddy@.
2015-10-26Add GPT editing. Based on GSOC 2014 work by Markus Muller.Kenneth R Westerback
2015-10-05Enhance '-g' to create a default GPT label in addition to the protectiveKenneth R Westerback
MBR. If '-b' is specified an EFI System partition of the requested size is created. All remaining space is put into an OpenBSD partition. Minimal enhancement necessary for upcoming UEFI install support. Committed first to flush out any unexpected impacts on 'normal' MBR operation and install media. ok deraadt@
2015-09-06correct a mistake in my previous commit;Jason McIntyre
2015-09-04shuffle -b into place; while there, do some general tidy upJason McIntyre
of SYNOPSIS and usage();
2015-09-04Add a -b option, to be used together with -i, that tells fdisk to add aMark Kettenis
special boot partition on architectures that need it. For now those architectures are amd64 and i386, where this option will create an EFI system partition to store our new UEFI bootloader. ok deraadt@, krw@
2015-07-09Nuke unused variable.Kenneth R Westerback
2015-07-08Do not attempt to read a disk sector worth of data from the fileKenneth R Westerback
containing the MBR template. Most especially don't get upset when the 512-byte file does not contain a full 4096 byte disk sector. Allows 4096-byte disks to be fdisk'ed once more. Problem reported and fix tested by Gerald Hanuer via bugs@. ok deraadt@
2015-03-19Nuke now unused variable.Kenneth R Westerback
2015-03-18Stop passing around little used 'struct mbr tt' parameter. JustKenneth R Westerback
make the initial mbr that tt pointed at a global that can be directly accessed in the couple of places it is needed. Fewer parameters, less confusion, no functional change.
2015-03-17Stop passing around little used and superfluous 'offset' parameter.Kenneth R Westerback
Just use the offset recorded/parsed in the struct mbr being used. Can still traverse/edit extended MBRs so offset really wasn't needed. Fewer parameters, less confusion, no functional change.
2015-03-16Stop passing around a pointer to the stack variable 'disk' in main().Kenneth R Westerback
There is only one disk being worked on, so just make it a global. Fewer parameters, less confusion, no functional change.
2015-03-16Document that -i/-u are mutually exclusive and clean up the relatedKenneth R Westerback
code a bit. ok deraadt@ igor@ (with suggested tweak that is coming)
2015-03-14Whitespace & KNF tweaks. Change functions whose return values areKenneth R Westerback
not checked to void. Use continue inside a do loop instead of a goto to the top. Move a #define/#undef more local to use. Eliminate some lint. General cleanup of things noticed preparing the big churn. No intentional functional change.
2015-03-14Switch all the license blocks to the standard OpenBSD/ISC license.Kenneth R Westerback
With the permission of Toby. ok deraadt@
2015-02-09Rename 'm_flag' to 'e_flag' since it's '-e' that sets it. RenameKenneth R Westerback
'User_modify' to 'USER_edit' for the same reason.
2015-01-03Add support for creating a protective MBR for GPT.Joel Sing
Part of a diff by Markus Mueller, which was derived from Bitrig during Google Summer of Code, with further tweaks by me. ok krw@ miod@
2014-03-20Add back various #includes of err.h, unistd.h, ctype.h, ioctl.h toKenneth R Westerback
eliminate multiple 'implicit' declarations introduced by the previous over-zealous #include cleanup. Thanks to to tedu@ for pointing out how -Wall reveals all.
2014-03-17Nuke pointless blank lines, defines, comments and casts. EliminateKenneth R Westerback
#include in *.h files in favour of listing them as required in the *.c files. Fix error message to correctly state that 64 is the minimum value for -l. Use errx() where errno is not relevant. Use 'continue' rather than a label to go back to start of a loop. No intentional functional change.
2014-03-17Un-revert, being careful to not break snap building. Add paranoia checkKenneth R Westerback
for any missing geometry.
2014-03-14Revert last -- broke building snaps.Kenneth R Westerback
2014-03-13Merge 'struct DISK_metrics' and 'struct disk' into one, since we don'tKenneth R Westerback
need to record two sets of metric/geometry data. Use 'geometry' instead of 'metrics' in names and comments. Eliminate DISK_getmetrics(). While here, make 64 the minimal valid value for '-l' instead of 1. This avoids the possibility of having 0 cylinders. No intentional functional change. Feedback & tweak from chris@
2014-03-09Instead of passing around 'char buf[DEV_BSIZE]' buffers, pass aroundKenneth R Westerback
'struct dos_mbr' variables, since that is what the buffers were used for. Removes need to know about DEV_BSIZE and thus include param.h from all files but one so move the param.h #include to that file (mbr.c). Nuke a bunch of local MBR #defines in favour of the disklabel.h ones. Remove a bunch of unneeded #includes, replace the odd malloc/bzero with calloc, replace equally odd bcopy's with memcpy, remove a stray duplicate MBR parsing in MBR_pcopy(). No intentional functional change.
2014-03-07Relieve the code of an overburden of unnecessary typedefKenneth R Westerback
abstraction. Call a 'struct' a 'struct' and not a pony. No functional change. idea ok deraadt@
2014-03-06tweak previous;Jason McIntyre
2014-03-02-l disksize code, to force LBA mode. code by chris, after I suggestedTheo de Raadt
wrapping rows of echo's via fdisk was silly. ok kettenis krw
2013-03-21more substantial include cleanupTheo de Raadt
2011-12-25printf("msg")/return 1 -> err(1, "msg"), which will also show relevantKenneth R Westerback
errno string. Since we are err()'ing out, don't worry about closing MBR fd first.