summaryrefslogtreecommitdiff
path: root/sbin/fdisk/cmd.c
AgeCommit message (Collapse)Author
2017-11-13Constrain MBR partition offsets to 0 .. disk.size - 1.Kenneth R Westerback
Issue reported by Alexi Malinin via bugs@. Thanks!
2016-09-03'reinit' should check the MBR on disk, as the man page says.Kenneth R Westerback
Makes 'reinit' respect current state of disk when deciding between MBR and GPT initialization. Problem noted by halex@
2016-08-02capitalize a question like all the othersJoshua Stein
ok krw
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-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-11-26When prompting for a GPT partition type, use the partition's current type asTim van der Molen
default; OK krw@
2015-11-25Try harder to prevent 0-length partitions from being defined.Kenneth R Westerback
Suggested by & ok tim@
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-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-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-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-26Add GPT editing. Based on GSOC 2014 work by Markus Muller.Kenneth R Westerback
2015-04-02Don't printf("offset: ...) before every call to MBR_print(). Do itKenneth R Westerback
once inside MBR_print().
2015-03-26Adapt ask_string() from disklabel's getstring(). It will be usedKenneth R Westerback
to obtain GPT partition names. Tweak ask_pid() to take low/high bounds so it can handle 1-ff (MBR) or 1000-ffff (GPT) partition pids as required. A pid of '0' is still special and disables the partition. No visible or intentional functional change.
2015-03-26Expand internal representation of partition starting LBA and sizeKenneth R Westerback
to 64 bits, adjusting printf()'s, etc. as required. Preparing for GPT partitions. Add 't' size unit. No other intentional functional change.
2015-03-19When zapping the GPT at the end of the disk, don't use disk.sizeKenneth R Westerback
to get the location. disk.size is a 32 bit value for MBR use. Use DL_GETDSIZE(&dl) to get the real location even on 'big' disks.
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-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-10If 'write' is issued after a 'reinit' command, and the MBR to beKenneth R Westerback
written does not contain an EFI partition, zap any GPT signature found on the 2nd (LBA 1) and last sectors on the disk. The install script uses this sequence. This is a temporary workaround until more GPT support is imported post-5.7. Should fix at least some machines who insist on using the GPT even after we have overritten the 'protective' MBR. ok deraadt@ tedu@ beck@ millert@
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.
2014-03-31Use return value constants to make effects clearer than the useKenneth R Westerback
of an intermediate variable. No intended functional change.
2014-03-31Whitespace rectification.Kenneth R Westerback
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-13Remove some lint -- ARGSUSED.Kenneth R Westerback
Inspired by guenther@.
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-10No need to pass the name of the command to the function that isKenneth R Westerback
implementing that command, a pointer to the command arguments is the only thing needed. No need to have a pointer to the command table in every command, since there is only one table. No need for shiney new stack space for every command name and arguments parsed, since we don't recurse we can just use static memory. No intentional functional change.
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@
2013-03-21more substantial include cleanupTheo de Raadt
2013-03-21I don't feel great about adding an include for <sys/param.h>, but I feelTheo de Raadt
great for removing an include of <machine/param.h> This needs further cleanup if someone has time.
2012-07-11Simplify guts and calling of getuint(). Eliminate a useless 'help'Kenneth R Westerback
capablity by using help text as regular prompt for 'size' and 'offset'. Try to detect and handle more overflow/underflow conditions in getuint() and ensure returned value is always within requested bounds. Handle zero-length partitions by treating them as UNUSED. tested & ok halex@
2012-07-09We always want to do unit conversions. So flags parameter of getuint()Kenneth R Westerback
is now superflous. With rounding gone the offset parameter is similarly superfluous. Simply getuint() accordingly.
2012-07-09I want some of what kjell was smoking 10 years ago when he addedKenneth R Westerback
units handling by copying getuint() from disklabel. MBR partition id and disklabel partition type are different beasts. So deciding to round off a MBR partition with id FS_BSDFFS meant rounding off NTFS partitions. And FS_SWAP partitions meant DOS FAT 12. So just nuke rounding off for now to simplify getuint(). ok beck@
2012-07-09Make 'swap' command work like fdisk(8) says -- you must supply two validKenneth R Westerback
partition numbers.
2012-07-09Use strtonum() instead of strtol() inside ask_num(). Many overflowsKenneth R Westerback
are thus avoided. Since bounds are now reliable don't check the returned value for being in-bounds. Since default value is forced inside bounds, don't bother being tricky and passing a default that is outside the bounds being specified. ok beck@
2012-07-08set_pid() does not need prompt string, low or high parameters. TheseKenneth R Westerback
are all constants. Independantly suggested by guenther@.
2012-07-08Split out an ask_pid() function rather than over-parameterizing theKenneth R Westerback
ask_num() function. Remove now unneeded 'flags' and 'help' parameters from both. Display out of range values in hex in ask_pid(), since we are seeking hex input. ok guenther@
2012-07-08Call Xsetpid() to edit the partition type from Xedit() rather thanKenneth R Westerback
duplicating the code. Allows simplification of the EDIT() #define in Xedit() since we always ASK_DEC and use a NULL help parameter when invoking ask_num().
2012-07-08Nuke useless EDIT() #define in Xsetpid.Kenneth R Westerback
A #define to simplify a function calling snippet does not simply or help when it is used only once.
2012-07-08Replace tricker atoi() and hand rolled parsing with strsep() andKenneth R Westerback
strtonum(). Make related error messages consistant. ok haesbaert@