Home | History | Annotate | Download | only in fdisk
History log of /src/sbin/fdisk/fdisk.c
RevisionDateAuthorComments
 1.163  24-Feb-2025  andvar s/sightly/slightly/ and s/sligtly/slightly/ in documentation and comment.
 1.162  03-Jan-2025  rillig fdisk: remove unreachable options 'T' and 't', fix lint warnings
 1.161  02-Apr-2022  mlelstv Avoid crashes with invalid or tiny sector sizes.
 1.160  03-Nov-2021  nia fdisk(8): Convert realloc(x * y) to reallocarr. Eliminate temp variables.
 1.159  24-May-2020  wiz Add -g to usage.
 1.158  24-May-2020  jmcneill Add -g flag to preserve GPT headers when updating MBR.
 1.157  07-Oct-2019  christos print the name of the disk causing the error.
 1.156  14-Nov-2018  mlelstv In validate_bootsel, the code assumed that arr[j][i] can be accessed
with something like arr[0][j*ARRAYWIDTH+i]. gcc no longer allows such
hacks and discards the code silently because of undefined behaviour.
 1.155  27-Aug-2018  sevan Add missing -z flag to usage()
 1.154  02-Oct-2017  joerg branches: 1.154.2; 1.154.4;
Really don't include ioctl code for tools build.
 1.153  22-Nov-2015  christos branches: 1.153.8;
explain how to clear an entry (without reading the source)
 1.152  16-Jun-2015  christos a few more \n's in errors
 1.151  16-Jun-2015  christos fix error messages containing \n
 1.150  04-Apr-2014  christos remove debugging.
 1.149  03-Apr-2014  christos instead of using ugly -1's make args optional
 1.148  01-Apr-2014  christos default to something reasonable (like the interactive mode does) instead
of 0 when -1 is specified for the start or size.
 1.147  30-Mar-2014  christos Allow -1 values in the -s <sysid>/<start>/<size> indicate use the previous
values. For example:
fdisk -f -i /dev/rsd0d # initialize mbr and create an msdos partition.
fdisk -f -u -0 -a -s 169/-1/-1 /dev/rsd0d # converts the msdos partition
to a netbsd one, and makes it active.
 1.146  10-Mar-2014  jakllsch Always print the MBR drive serial number, even if it's 0.
 1.145  14-Apr-2013  jakllsch Improve support for logical sector sizes greater than 512.
 1.144  13-Feb-2013  christos Don't produce spurious errors when creating labels on files.
 1.143  09-Feb-2013  christos CID/979997: missing va_end()
 1.142  05-Jun-2012  tsutsui branches: 1.142.2;
Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8)
rather than unknown build host's /usr/mdec directory.

XXX: no option to leave MBR bootcode empty on x86 targets
 1.141  05-May-2012  tsutsui Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.

Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
 1.140  06-Apr-2012  christos support sector sizes > 512.
 1.139  15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.138  02-Dec-2011  christos branches: 1.138.2;
Also ignore out of space conditions for -I so we can create overlapping
partitions on a full disk. Document and add it to the options.
 1.137  02-Dec-2011  enami Add missing -F flag and -I flag in usage. Sort the order to match
manpage.
 1.136  02-Dec-2011  christos put the error check in the conditional where it belongs.
 1.135  01-Dec-2011  christos Add a flag to support writing overlapping partitions and explain why.
 1.134  28-Aug-2011  gson branches: 1.134.2;
fix the sparc build
 1.133  27-Aug-2011  christos one static is enough, otherwise you risk zapping yourself.
 1.132  27-Aug-2011  joerg staticfy. __dead.
 1.131  08-May-2011  pgoyette Fix parsing of -A option so that the [/ptn_0_offset] part is optional, as
described in the man page.
 1.130  23-Dec-2009  dsl Put #endif in correct place - fixes PR/42500
Update usage() for -A, and rename one of the variables for clarity.
 1.129  22-Dec-2009  dsl Add support for partition being aligned on non-cylinder boundaries.
Info can be specified with -A parameter.
Default is based on how the first partition is defined.
For empty disks larger than 128GB (arbitrary figure) use 1MB alignment.
 1.128  22-Dec-2009  dsl Editing partitions larger than 1TB works better if 'decimal' returns
64 bit integer values!
 1.127  20-Dec-2009  dsl Add a large comment about disk geometries.
Rename (with #defines) the variables use for aligning partitions to
separate them from the bios geometry.
All in advance of allowing other partition alignments (eg 2048 sectors).
 1.126  17-Dec-2009  pooka Use implicit -F for regular files, much like disklabel(8).
 1.125  04-Nov-2009  dsl Allow MB, GB and CYL (not just M, G and C) and lower case.
Don't output a splurious 'd' before "cyl".
Fixes PR/37414.
Patch in PR is wrong!
 1.124  31-Oct-2009  dsl Make absence of /usr/mdec/mbr only a warning.
Fixes PR/26510
 1.123  05-Aug-2009  dsl Change arguments to decimal() to be int64_t.
They need to be able to hold disk sector numbers > 2^31 and also -1.
Should fix PR/34807
 1.122  02-Jun-2009  christos make this compile one non mbr machines (move #define to the general section)
 1.121  01-Jun-2009  christos Delete GPT partitions if we overwrite with MBR to avoid confusion with disks
that have both MBR and a secondary left over GPT partition signature. From
Mike M. Volokhov
 1.120  20-Apr-2009  drochner also fix a comment wrt use of the csysid/cstart/csize vars
 1.119  20-Apr-2009  sborrill When using -s flag, read start and size as unsigned to allow for larger
disks. (Thanks to drochner@ for catching it).
 1.118  06-Apr-2009  lukem fix sign-compare issues
 1.117  18-Jan-2009  apb branches: 1.117.2;
Remove local definitions of PRIxxxx macros in favour of the
centralised definitions from tools/compat/compat_defs.h, which
are included via nbtool_config.h.
 1.116  09-Mar-2008  tnn branches: 1.116.6;
mbr_dsn is unsigned, print it as such.
 1.115  25-Jan-2008  dsl branches: 1.115.2; 1.115.4;
Add support for mbr code with ascii keycodes
 1.114  20-Jan-2008  tsutsui - add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"

Should close PR bin/37656.
 1.113  23-Dec-2007  apb Track zero is not strictly reserved for the BIOS, that's just a
convention, so don't make it an error in check_overlap(). Sector 0 is
reserved for the MBR, so make that an error in check_overlap().
 1.112  23-Dec-2007  apb Report the first active partition.
 1.111  23-Dec-2007  apb If the partition is unused, then attempting to decode the PBR would
actually decode the MBR from sector 0 of the disk. Don't do it if
v_flag < 3.
 1.110  29-Nov-2007  dsl branches: 1.110.2;
Make this compile without -Wno-pointer-sign
(Needs updated bootblock.h)
 1.109  29-Nov-2007  dsl Change -F to not use opendisk().
Don't change default to the boot volume until after we've found we aren't
doing -F.
For tool-fdisk enforce -F and use #defines to make code that can no
longer possibly execute compile.
 1.108  18-Nov-2007  apb Remove unwanted ">" from a printed message.
 1.107  28-Oct-2007  tsutsui Don't print Drive serial number if -S (setting shell variables) is specified.
 1.106  04-Sep-2007  tls This program is a host tool, so when we use newfangled C features like
PRIxyz we have to ensure it still builds on hosts with Old compilers.
Noticed while building a cross-toolchain on FreeBSD 4.
 1.105  05-Jul-2007  dsl branches: 1.105.4;
Preserve the mbr 'driver serial number' when copying in the netbsd
mbr code. Should leave windows vista bootable.
Print the dsn from the mbr, not each pbr.
 1.104  26-Apr-2007  christos PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.103  10-Mar-2007  apb Try to check whether each partition is bootable. If not,
always print an error message. If bootable and -v flag was
specified, print a success message. If -v flag was specified
more than once, also try to decode more information from
the PBR.

Input from dsl and bad.
 1.102  25-Nov-2006  dsl branches: 1.102.2;
Report the last sector number of a partition, instead of that of the first
of the next - with appropriate discarding of the head/sector values
if the partition is cylinder aligned.
Fixes PR 26921
 1.101  02-Jun-2006  christos PR/33633: Yoshito Komatsu: /sbin/fdisk does not work
Downgrade error getting heads to a warning.
 1.100  21-May-2006  christos PR/33522: Peter Bex: Sanity checks to avoid zerodivide.
 1.99  18-Mar-2006  dsl Appease Coverty CID 7449. Avoid close(-1) in error path.
 1.98  17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.97  14-Feb-2006  dyoung So that we can build a full-featured fdisk cross-tool with -DBOOTSEL,
condition the definition of DEFAULT_BOOTxxx variables and SCAN_xxx
on defined(BOOTSEL), instead of defined(__i386__) || defined(__x86_64__).

While I'm here, only build get_diskname in the same conditions as
get_geometry is built, since only the latter calls the former.
 1.96  29-Jan-2006  dsl Byteswap the constant MBR_{BS_}MAGIC throughout, should genetate better code.
Except that non all architectures have that optimisation :-(
 1.95  07-Oct-2005  uwe PRI* macros should not contain percent sign.
While here, conditionalise use of "lld" for PRId64 on HAVE_LONG_LONG.
 1.94  07-Oct-2005  dogcow Fix cross-compilation on FreeBSD 4.x (and other OSes) where PRId64 isn't
defined.
 1.93  27-Aug-2005  uwe When building as host tool don't include "../../include/util.h".

opendisk() declared in that file is not used in this case anyway, and
<util.h> pulls in unwatned includes (e.g. <utmpx.h> doesn't exist on
FreeBSD 4.*).
 1.92  27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.91  12-Jun-2005  dyoung Turn fdisk(8) into a host tool. Still todo: commit the host-tool
build infrastructure to src/tools/fdisk/.
 1.90  12-Jun-2005  dyoung For portability, use standard types: s/uint/unsigned int/,
s/ulong/unsigned long/, s/u_int8_t/uint8_t/.
 1.89  07-Apr-2005  dsl Allow partition sizes to be input in GB
 1.88  20-Jan-2005  xtraeme branches: 1.88.2;
Remove main() prototype; WARNS=2
 1.87  18-Nov-2004  wiz Fix typo in error message, reported by Nicolas Joly in PR 28347.
 1.86  15-Nov-2004  christos Use the 1st element's size as the argument to bsearch.
 1.85  12-Nov-2004  christos Use ptype table from <sys/bootblock.h>
 1.84  10-Nov-2004  christos Add 0xBF for Solaris. From Larry Lee <lclee at west.sun.com>
 1.83  28-Oct-2004  dsl Add (unsigned char) to isdigit() calls
 1.82  12-Sep-2004  dsl Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.81  30-Jul-2004  dbj check sysctl error return on both calls.
this prevents sysctl from coredumping if the second call fails while the
first succeeds. This isn't supposed to happen, but there is another bug
in the i386 kernel implementation of sysctl machdep.diskinfo that excites this
 1.80  19-May-2004  dyoung Insert missing space so fdisk prints "primary partition table
invalid, no magic in sector 0", not "primarypartition ...".
 1.79  10-May-2004  dsl Use the disk size from the device driver, not the bios when checking
whether partitions are valid.
Stops problems with broken BIOS, fixes PR bin/25491
 1.78  08-May-2004  dsl Don't output the 'Installed bootfile doesn't support required options'
message when we are updating the mbr code because the user did fdisk -i ...
 1.77  24-Mar-2004  lukem branches: 1.77.2;
Only examine mbr_bootsel* #ifdef BOOTSEL.
Noted on current-users@ by Markus Hennecke.
 1.76  22-Mar-2004  lukem Move mbr_bootsel from offset 404 to offset 400 in struct mbr_sector to
leave 4 bytes for the Windows NT Drive Serial Number (DSN) at 440-443
(as mbr_sector.mbr_dsn).

Ensure that all the MBR & PBR code reserves space for mbr_sector.mbr_dsn.

Leave the bootsel magic number at 444-445 as mbr_sector.mbr_bootsel_magic
(instead of mbr_sector.mbr_bootsel.mbrbs_magic), but use 0xb5e1 (MBR_BS_MAGIC)
instead of 0xaa55 (MBR_MAGIC) to indicate that this change has occurred.

Rework MBR_BS_NEWMBR to mean "mbr_bootsel has moved to 400".

Modify fdisk(8) to automatically relocate the mbr_bootsel from 404 to 400
if mbr_bootsel_magic is the old value (0xaa55), and unset MBR_BS_NEWMBR
to flag that new mbr_bootsel code must be used if updating the MBR.


These changes fixes a problem where Windows 2000 or Windows XP would corrupt
the last 3 bytes + NUL of MBR partition 3's bootsel name if the bootsel name
was 5 characters long, replacing bytes 6-9 with the DSN.
Also, by explicitly reserving the space for the DSN we prevent problems in the
future if non bootsel MBR or PBR code had other information at bytes 440-443.
 1.75  19-Mar-2004  dyoung Add flag -F, options -t disktab and -T disktype to fdisk. Flag -F
indicates that the target of the fdisk operation is a file, not a
disk. With -t and -T, the user tells fdisk the geometry for the
file If the default geometry that fdisk will "fake up" for a file
are not satisfactory, the user may tell the geometry to fdisk using
-t disktab -T disktype.
 1.74  05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.73  21-Nov-2003  lukem Add "DISK" to -S output.
 1.72  11-Oct-2003  lukem unconditionally #define DEFAULT_BOOTDIR. should fix non-x86 builds
 1.71  08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.70  19-Sep-2003  itojun realloc pedant
 1.69  29-Aug-2003  dsl Define and use PRIdaddr for printing disk block numbers.
Should fix bin/22638 for compilation on amd64.
 1.68  10-Aug-2003  dsl Put cylinder number 1023 into the mbr for sectors beyond the CHS limit
(rather than encoding the highest CHS addressable sector).
 1.67  14-Jul-2003  dsl Fix code that detects bios geometry from mbr table.
 1.66  07-Jul-2003  dsl Only look at each pair of CHS values once when trying to guess geometry.
 1.65  17-May-2003  itojun asprintf is easier
 1.64  14-May-2003  dsl delete a diagnostic printf that was accidentally left in
 1.63  01-May-2003  bjh21 Remove some unused variabled from get_params_to_use() in the !i386 && !amd64
case.
 1.62  30-Apr-2003  dsl Rototilled fdisk that supports:
- editing of the extended partition list
- user friendly default start/size for new partitions
- partition start/size input in sectors, cylinders or MB
- bootsel menu names configured with paritition bounds
- partition update loop asks used which partition to change
(instead of asking about each partition in turn).
- detection (and erroring) of overlapped partitions.
- automatic installation of correct mbr_xxx code (after prompting user)
 1.61  30-Apr-2003  dsl Move some definitions from fdisk.c to disklabel_mbr.h so they don't have
to be duplicated elsewhere (eg in mbr.S).
Modify fdisk.c so that it builds with the new disklabel.h
 1.60  01-Apr-2003  fvdl Fix range check for the default boot option case.
 1.59  10-Jan-2003  jmmv Print missing newline in two bootselector-related messages. Approved by wiz.
 1.58  30-Nov-2002  fvdl Enable bootselector code for x86_64.
XXX the ifdef-ed parts should be split off into a seperate file.
 1.57  24-Nov-2002  fvdl Avoid format warning for off_t printf.
 1.56  08-Oct-2002  jdarrow Make the -l flage more useful, by actually printing the systype number
alongside the sysid string (instead of just the array index of the
struct part_type they are found in).

Now fdisk -l shows the familiar 169 for NetBSD, 165 for FreeBSD or
386BSD or old NetBSD, and other possibly-familiar (131 for Linux native,
015 for Ext. Partition - LBA) values in with their correct numbers.
 1.55  27-Sep-2002  dbj add partition type 0xaf for Apple HFS.
 1.54  08-Aug-2002  soren Clean up printf->err conversions.
 1.53  05-Jun-2002  yamt exit on EOF from stdin.
 1.52  03-Apr-2002  thorpej branches: 1.52.2;
Build fdisk(8) on netwinder.
 1.51  26-Mar-2002  christos nicer printing.
 1.50  26-Mar-2002  christos PR/16073: Jachym _Freza_ Holecek: Add the ability to list known partition types.
While I am here, KNF a bit.
 1.49  04-Mar-2002  dbj add "Apple UFS" and "Apple Boot" partition ids used by Darwin
 1.48  07-Nov-2001  lukem if sysctl kern.root_device is availalbe, use that the default device
(rather than /dev/rwd0d). display the disk device used when printing
the partition table.
 1.47  01-Nov-2001  lukem opendisk(3) checks the device type for us
 1.46  16-Apr-2001  lukem add fix by Minoura Makoto to correctly support recursive extended partitions.
the offset of an extended sub-partition is the offset of the top-level
extended partition, not the partition before it (this is annoying, and
makes `clean' recursive mbr descent difficult). fixes PRs 11829 and 12677.
 1.45  24-Dec-2000  lukem use MBR_IS_EXTENDED() instead of local test (which was missing a test case)
 1.44  19-Dec-2000  lukem * Recursively print out extended partition entries. An extended partition is
effectively an MBR with it's own partition table which contains another
4 `slots', each of which can be another extended partition...
This involved reworking some of the internal functions.
* Use off_t appropriately (so we can manipulate sectors past 4GB).
* Tweak to compile with WARNS=2
 1.43  19-Dec-2000  lukem convert to ANSI KNF
 1.42  06-Jul-2000  thorpej When fetching the disk's hardware geometry, first attempt the
DIOCGDEFLABEL ioctl, then fall back onto the DIOCGDINFO ioctl
if that fails. This ensures that we will get the actual hardware
geometry info rather than any bogus info that might have been
previously written to the disk's label area.
 1.41  14-Jun-2000  wiz branches: 1.41.2;
Fix QNX partition IDs, confirmed by looking at FreeBSD's fdisk.
Note: 77 == 0x4d
 1.40  27-May-2000  fvdl Truncate the CHS values correctly in case a partition boundary exceeds
their range.
 1.39  31-Jan-2000  soda branches: 1.39.2;
Build fdisk also on arc
 1.38  06-Sep-1999  soren Update usage().
Prevent buffer overflows when configuring boot selector.
Cycle through partitions when entering boot names.
Use '<UNUSED>' consistently.

Reviewed by: fvdl
 1.37  04-Jun-1999  thorpej Make sure the boot selector actually gets updated if you only change
the timeout and/or the default menu choice.
 1.36  02-May-1999  fvdl Make check if we need int13 extensions for the bootselector more correct.
 1.35  28-Apr-1999  fvdl Only use int13 extensions if the sectors can not be read through the
older CHS interface. This works around stupid BIOSs who report that
int13 extensions are present and functional, but fail when you actually
use them. Like Adaptec SCSI BIOSs.

For the bootselector, there was no space to get the CHS info from
the BIOS. Instead, use a flag that can be set by fdisk. fdisk will
set it if one of the partitions on the disk is out of CHS reach
for this disk/BIOS, so that the bootselector will use int13 extensions.
This isn't so bad, because it needs to be configured via fdisk anyway.

Change the mbr manualpage to reflect some shorter error messages.
 1.34  17-Apr-1999  fvdl Make the bootselector configurable by fdisk. Add a -B flag to this
effect (i386 only of course). Also change one branch in the
bootselector code to an explicit 16 bit one, and check both
the boot menu and partition tables to see if the partition
requested by the user should be booted. This check just in case,
should the bootselector menu and partition table get out of sync
somehow. (mmm, bytesqueezing)
 1.33  09-Feb-1999  perry branches: 1.33.2;
add BeOS entry, from URA Hiroshi, PR 6974
 1.32  27-Jan-1999  thorpej Use <sys/disklabel_mbr.h>.
 1.31  08-Nov-1998  jonathan Set otherwise-unused global variable `disksectors' to disklabel.d_secperunit.
Change fdisk -S to emit disksectors as DLSIZE (for benefit of sysinst.)
 1.30  15-Oct-1998  ws Separate master bootcode from fdisk.
 1.29  02-Oct-1998  ws Completely zero out a partition table entry,
if type, start and size are given as zero.
 1.28  28-Sep-1998  ws Automagically initialize boot code and partition table if not yet valid.
Don't touch the partition table on -i, if previously valid.
 1.27  10-Aug-1998  rvb Dont report more than 1023 cylinders for DOS/BIOS because
the code below will truncate to a 10 bit field. This
can cause major problems later for DOS.
 1.26  25-Feb-1998  drochner Use the new NetBSD partition ID for first time setup of an MBR.
 1.25  19-Feb-1998  drochner Add new NetBSD partition ID.
Update information about partition types - add missing types, insert
"reserved" for IDs which are marked as "officially reserved" in other
lists.
Sources of information:
-"How it Works -- Partition Tables" by Hale Landis <hlandis@ibm.net>
-Ralph Brown's interrupt list
 1.24  07-Feb-1998  ghudson When estimating the number of cylinders in the BIOS geometry, use the
total number of sectors as reported by disklabel.d_secperunit rather
than multiplying out the disklabel geometry, which is less accurate.
 1.23  02-Feb-1998  mikel Don't print "DOS partition initialized" if -S set; from Nathan
Williams in PR bin/4893.
 1.22  22-Dec-1997  enami Add missing cast. This is a minimum fix to avoid overflow which causes
core dumps with some disk geometry.
 1.21  30-Sep-1997  phil branches: 1.21.2;
Backout the prototype of opendisk().
 1.20  30-Sep-1997  phil Prototype opendisk().
 1.19  25-Sep-1997  lukem switch to using opendisk(3) from libutil
 1.18  14-Sep-1997  lukem * support ``short'' names of disks (e.g, ``sd0'') instead of requiring
the full name (e.g, ``/dev/rsd0d'') a la disklabel(8) (where the code
was effectively lifted from ;-)
* prefix hexadecimal numbers in output with '0x'
 1.17  11-Sep-1997  phil Don't print some things if -f flag given.
 1.16  05-Sep-1997  phil -- add -b flag for setting fdisk's idea of BIOS geometry from command line
-- cleanup so WARNS=1 works
-- man page updated to reality.
 1.15  11-Aug-1997  phil Upgrade for non-interactive use. Interactive use is nearly unchanged.
-i no longer implies -u, -i now does not use the entire first track
because some BIOSes refuse to boot from a partition in the first track.
-s renamed to -S, new -s for non-interactive setting of a partition's
id, offset and size. Updated documentation to match.
 1.14  29-Jul-1997  phil Add code for a -s flag where the output is a series of VAL=xyz lines
so /bin/sh can "eval `fdisk -s`" and get variables defined with the
fdisk information.
 1.13  24-Jun-1997  perry Add a whole lot of MBR partition types, derived from a couple of sources
including Linux.
Is there a master list of this somewhere?
 1.12  29-Mar-1997  thorpej Make this work on big-endian systems, such as the PowerPC. From
Wolfgang Solfrank <ws@tools.de>
 1.11  04-Oct-1995  ghudson Add code to look at the existing partition entries to deduce the
translated geometry of the disk. This code will only change the
disk geometry if it can find a geometry which is consistent with
all partition entries, so it's very conservative about choosing
a new disk geometry. Under some circumstances, it will choose a
number of cylinders which is a little lower than it needs to be,
but this code is enough so that you can create new partitions
with the correct physical addresses.

The right solution to this problem is to have the boot loader
communicate the BIOS geometry of each disk to the kernel, in a
manner similar to the symbol table, and then provide a kernel
interface to get at that information. I'm unfortunately not
really qualified to make such a change, and I want something
that works better than the status quo.
 1.10  18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9  13-Jan-1995  mycroft Recognize Linux file systems correctly.
 1.8  05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7  20-Oct-1994  mycroft Allow `partitioning' of a regaular file.
 1.6  23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.5  23-Sep-1994  mycroft Clean up a bit more.
 1.4  23-Sep-1994  mycroft Clean this up a bit.
 1.3  06-Dec-1993  cgd 386bsd -> NetBSD
 1.2  02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1  09-Apr-1993  cgd added a 386bsd fdisk program, by julian elischer. (patch 111)
 1.21.2.4  16-Nov-1998  cgd pull up rev 1.25 from trunk (jonathan)
 1.21.2.3  24-Feb-1998  mellon Pull up 1.24 (ghudson)
 1.21.2.2  07-Feb-1998  mellon Pull up 1.23 (mycroft)
 1.21.2.1  22-Dec-1997  perry pullup from trunk to fix coredump (enami)
 1.33.2.4  01-Jun-2000  he Pull up revision 1.40 (requested by fvdl):
Fix a booting problem when int13 extensions are used (> 8GB),
and CHS values in MBRs were written from sysinst or fdisk that
some BIOSes (Adaptec SCSI BIOS 2.20 in particular) didn't like.
 1.33.2.3  22-Jun-1999  perry pullup 1.36->1.37 (thorpej): update boot selector only if it needs updating
 1.33.2.2  02-May-1999  perry pullup 1.34->1.36 (fvdl)
 1.33.2.1  18-Apr-1999  fvdl Pull up bootselector mods, as approved by releng.
 1.39.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.41.2.1  14-Feb-2002  he Pull up revision 1.42 (requested by itojun):
When fetching the disk's hardware geometry, first attempt the
DIOCGDEFLABEL ioctl, then fall back to the DIOCGDINFO ioctl.
This ensures that we will get the actual hardware geometry info
rather than any bogus info which might have been previously
written to the disk's label area.
 1.52.2.3  02-Jun-2003  tron Pull up revision 1.56 (requested by jdarrow in ticket #1206):
Make the -l flage more useful, by actually printing the systype number
alongside the sysid string (instead of just the array index of the
struct part_type they are found in).
Now fdisk -l shows the familiar 169 for NetBSD, 165 for FreeBSD or
386BSD or old NetBSD, and other possibly-familiar (131 for Linux native,
015 for Ext. Partition - LBA) values in with their correct numbers.
 1.52.2.2  02-Jun-2003  tron Pull up revision 1.55 (requested by jdarrow in ticket #1205):
add partition type 0xaf for Apple HFS.
 1.52.2.1  11-Jan-2003  jmc Pull up revisions 1.58-1.59 (requested by jmmv in ticket #1065)
Print missing newline in two bootselector-related messages.
 1.77.2.2  01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.77.2.1  16-Aug-2004  jmc branches: 1.77.2.1.2; 1.77.2.1.4;
Pullup rev 1.81 (requested by dbj in ticket #767)

Add support to pxeboot for reading the bios disk geometry
as well as fixing several related bugs that occur when the bios
geometry is not read by the boot loader.
 1.77.2.1.4.1  01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.77.2.1.2.1  01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.88.2.2  30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2018):
sbin/fdisk/fdisk.c: revision 1.104
PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.88.2.1  22-Feb-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1897):
sbin/fdisk/fdisk.c: revisions 1.100, 1.101, 1.114
PR/33522: Peter Bex: Sanity checks to avoid zerodivide.
PR/33633: Yoshito Komatsu: /sbin/fdisk does not work
Downgrade error getting heads to a warning.
- add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"
Should close PR bin/37656.
 1.102.2.5  03-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1053):
sbin/fdisk/fdisk.c: revision 1.107
Don't print Drive serial number if -S (setting shell variables) is specified.
 1.102.2.4  03-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1052):
sbin/fdisk/fdisk.c: revision 1.114
- add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"
Should close PR bin/37656.
 1.102.2.3  24-Aug-2007  liamjfoy Pull up following revision(s) (requested by dsl in ticket #832):
sbin/fdisk/fdisk.c: revision 1.105
Preserve the mbr 'driver serial number' when copying in the netbsd
mbr code. Should leave windows vista bootable.
Print the dsn from the mbr, not each pbr.
 1.102.2.2  28-Apr-2007  bouyer branches: 1.102.2.2.2;
Pull up following revision(s) (requested by christos in ticket #593):
sbin/fdisk/fdisk.c: revision 1.104
PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.102.2.1  22-Mar-2007  jdc Pull up revision 1.103 (requested by apb in ticket #513).

Try to check whether each partition is bootable. If not,
always print an error message. If bootable and -v flag was
specified, print a success message. If -v flag was specified
more than once, also try to decode more information from
the PBR.

Input from dsl and bad.
 1.102.2.2.2.2  03-Jun-2008  skrll Sync with netbsd-4.
 1.102.2.2.2.1  03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.105.4.3  23-Mar-2008  matt sync with HEAD
 1.105.4.2  09-Jan-2008  matt sync with HEAD
 1.105.4.1  06-Nov-2007  matt sync with HEAD
 1.110.2.3  18-Feb-2008  mjf Sync with HEAD.
 1.110.2.2  27-Dec-2007  mjf Sync with HEAD.
 1.110.2.1  29-Nov-2007  mjf file fdisk.c was added on branch mjf-devfs on 2007-12-27 00:46:56 +0000
 1.115.4.1  03-Apr-2008  mjf Sync with HEAD.
 1.115.2.1  24-Mar-2008  keiichi sync with head.
 1.116.6.3  09-Jan-2010  snj Pull up following revision(s) (requested by dsl in ticket #1207):
sbin/fdisk/fdisk.c: revision 1.128
Editing partitions larger than 1TB works better if 'decimal' returns
64 bit integer values!
 1.116.6.2  24-Dec-2009  snj Pull up following revision(s) (requested by dsl in ticket #1201):
sbin/fdisk/fdisk.c: revision 1.123
Change arguments to decimal() to be int64_t.
They need to be able to hold disk sector numbers > 2^31 and also -1.
Should fix PR/34807
 1.116.6.1  20-Apr-2009  snj branches: 1.116.6.1.4;
Pull up following revision(s) (requested by sborrill in ticket #712):
sbin/fdisk/fdisk.c: revision 1.119
When using -s flag, read start and size as unsigned to allow for larger
disks. (Thanks to drochner@ for catching it).
 1.116.6.1.4.1  21-Apr-2010  matt sync to netbsd-5
 1.117.2.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.134.2.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.134.2.3  30-Oct-2012  yamt sync with head
 1.134.2.2  23-May-2012  yamt sync with head.
 1.134.2.1  17-Apr-2012  yamt sync with head
 1.138.2.1  12-Jun-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #315):
sbin/fdisk/fdisk.c: revision 1.141
sbin/fdisk/fdisk.c: revision 1.142
tools/fdisk/Makefile: revision 1.5
tools/fdisk/Makefile: revision 1.7
sbin/fdisk/Makefile: revision 1.42
Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.
Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8)
rather than unknown build host's /usr/mdec directory.
XXX: no option to leave MBR bootcode empty on x86 targets
 1.142.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.142.2.2  23-Jun-2013  tls resync from head
 1.142.2.1  25-Feb-2013  tls resync with head
 1.153.8.1  28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #993):

sbin/fdisk/fdisk.c: revision 1.155

Add missing -z flag to usage()
 1.154.4.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.154.4.1  10-Jun-2019  christos Sync with HEAD
 1.154.2.2  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.154.2.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)

RSS XML Feed