summaryrefslogtreecommitdiff
path: root/sbin/fdisk
AgeCommit message (Collapse)Author
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-30Dump strdup()/free() dance and just use a local buffer to translate helpKenneth R Westerback
messages to GPT. Unchecked strdup() result noted by mestre@. ok mestre@ tim@
2016-03-28The GPT versions of help strings that don't contain'MBR' wereKenneth R Westerback
leaking. Refactor logic a bit to avoid leak and make logic clearer. Noticed by (and initial diff from) mestre@ and his friend clang.
2016-03-28Remove unused variablesRicardo Mestre
OK krw@
2016-03-09Accept only character special devices rather than generating a coreKenneth R Westerback
dump on the attempt to get a disklabel from a regular file. Regular files have not been acceptable as the 'disk' for some time, and pledging changed the consequences from a somewhat obscure error message to an abort(). Issue discovered by espie@. ok natano@
2016-02-23A disk name of /dev/wd0c doesn't work. Correct verbiage and example.Kenneth R Westerback
Discovered by rpe@. Tweaked by schwarze@. ok rpe@ schwarze@ jmc@ deraadt@
2016-01-09Revamp the display of GPT information, hiding less importantKenneth R Westerback
information under the '-v' flag. This brings the GPT display more into line with the MBR display and simplifies and hardens the parsing of the partition info in the install scripts. Original problem with install scripts parsing hand edited GPT information reported by Valere Monseur via bugs@. Man page fixes and tweaks from jmc@. Install script changes tested & ok rpe@.
2015-12-30Revert r1.59's over-enthusiatic MBR zero'ing in MBR_init(). It wasKenneth R Westerback
killing the macppc MSDOS partition created by '-i'. Should fix the macppc install problems reported by Brian Conway on bugs@. Date of breakage found by rpe@.
2015-12-27Use 'standard' gpt_chk_mbr() to check for protective MBR.Kenneth R Westerback
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-11there are no boot_ pages for armish or landisk that i can see,Jason McIntyre
so remove their references; while here undo a predefined string (as mandoc_char(7) calls them);
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-01Fix inexplicable use of 'disk' instead of 'disk.name' when trying toKenneth R Westerback
print the disk's name in an error message.
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-26When prompting for a GPT partition type, use the partition's current type asTim van der Molen
default; OK krw@
2015-11-26When prompting for an LBA, show the min and max values in the prompt; OK krw@Tim van der Molen
2015-11-25Try harder to prevent 0-length partitions from being defined.Kenneth R Westerback
Suggested by & ok tim@
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-21Bring GPT partition editing into line with MBR partition editingKenneth R Westerback
by presenting the existing offset and size as the defaults. Enhance getuint64() to take a minimum value as ask_num() does. Use this to ensure that GPT partitions are constrained to the valid area of the disk. Leave MBR partition constraints alone for the moment. Original problem(s) noted by tim@
2015-11-21Nuke long standing annoyance of EDIT() macros and switch both Xedit()Kenneth R Westerback
and Xgedit() to a new mechanism. Keep a copy of the old partition and compare final edited version to that to decide if it is dirty. Fixes a number of (but not all!) nits in editing partitions. Original problem(s) noted by, suggestions from, much testing and ok tim@
2015-11-19When an existing partition is modified in LBA mode, ensure that the partitionTim van der Molen
table is marked dirty so that it gets written when "quit" is issued. This commit contains the MBR part of the fix only. The GPT code needs a few adjustments before the GPT part can be fixed properly. OK 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-19Reduce overburden of unnecessary #include's. Note that param.h isKenneth R Westerback
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-18Change #include <memory.h> to #include <string.h>Kenneth R Westerback
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-18USER_edit() (a.k.a. -e) edits the on-disk information. So zap GPTKenneth R Westerback
and re-read it from disk if appropriate. i.e. when the re-read MBR is a protective MBR.
2015-11-18Read MBR immediately, and only read the GPT if the MBR is aKenneth R Westerback
protective MBR.
2015-11-17note that -chs and -l are mutually exclusive;Jason McIntyre
from jan stary
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-12'reinit mbr' must zero existing MBR and GPT partition informationKenneth R Westerback
before constructing default MBR. Change last bzero() to memset().
2015-11-12Refresh the in-kernel copy of the disklabel from the disk *after* writingKenneth R Westerback
the new GPT.
2015-11-12Simplify string_from_line(). No functional change.Tim van der Molen
OK krw@
2015-11-12Avoid problems with pathological input during edit operations. i.e. neverKenneth R Westerback
attempt to use data past the end of the input. Since the return value of ask_cmd() is never checked, make it void instead of int. Problems found, original diff from and ok tim@.
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-11-10Use UINT32_MAX for the size of the EFI System partition on disks larger thanKenneth R Westerback
UINT32_MAX sectors. i.e. don't use the truncated value aligned to cylinder size that we use for 'real' MBR partitions. Makes GPT on large disks work. Problem found & fix tested by naddy@.
2015-11-03Don't allow the user to enter GPT partition names too large to fitKenneth R Westerback
in the GPT partition structure. And don't run off the end of the name buffer by confusing sizeof() with the number of elements in an array. Use the new GPTPARTNAMESIZE #define instead. While here, zap the old partition name before setting the new one, lest a short new name leave bits of an old long name in place. Originally spotted by jsg@ and his friend cppcheck. ok jsg@ for slightly different version.
2015-10-26tweak previous;Jason McIntyre
2015-10-26Add GPT editing. Based on GSOC 2014 work by Markus Muller.Kenneth R Westerback
2015-10-26Flesh out GPT info and tweak other verbiage to be less MBR specific.Kenneth R Westerback