Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/subr_disk_mbr.c
RevisionDateAuthorComments
 1.59  08-Feb-2025  mlelstv Handle reading larger sectors (including 2k CD-ROM blocks).
Fall back to scan for ISO9660 sessions when MMC code fails.

disklabel now reports ISO/UDF partitions again for cd(4).
 1.58  03-Apr-2023  gutteridge Fix typos: s/trough/through/
 1.57  17-May-2021  mrg branches: 1.57.12;
move bi-endian disklabel support from the kernel and libsa into libkern.

- dkcksum() and dkcksum_sized() move from subr_disk.c and from
libsa into libkern/dkcksum.c (which is missing _sized() version),
using the version from usr.sbin/disklabel.

- swap_disklabel() moves from subr_disk_mbr.c into libkern, now called
disklabel_swap(). (the sh3 version should be updated to use this.)

- DISKLABEL_EI becomes a first-class option with opt_disklabel.h.

- add libkern.h to libsa/disklabel.c.

this enables future work for bi-endian libsa/ufs.c (relevant for ffsv1,
ffsv2, lfsv1, and lfsv2), as well as making it possible for ports not
using subr_disk_mbr.c to include bi-endian disklabel support (which,
afaict, includes any disk on mbr-supporting platforms that do not have
an mbr as well as disklabel.)

builds successsfully on: alpha, i386, amd64, sun2, sun3, evbarm64,
evbarm64-eb, sparc, and sparc64. tested in anita on i386 and sparc,
testing in hardware on evbarm64*.
 1.56  07-Nov-2019  kamil branches: 1.56.12; 1.56.14;
Revert subr_disk_mbr.c r.1.54

Requested by <christos> as there can be a better way to fix the original
problem with alignment.
 1.55  07-Nov-2019  kamil Decorate check_label_magic() with __noubsan

Requested by <christos>
 1.54  07-Nov-2019  kamil Revert src/sys/kern/subr_disk_mbr.c r.1.52

Addressed in a better way in r. 1.53.
 1.53  07-Nov-2019  kamil Ensure in validate_label() that struct disklabel pointer is 8-byte aligned

The label is searched each 4 bytes and can be detected in an unaligned
location. Before any operations on it, copy it to promptly aligned local
copy on the stack.

This is a missing part of the following change:

revision 1.108
date: 2011-01-18 20:52:24 +0100; author: matt; state: Exp; lines: +2 -1;
Make struct disklabel 8 byte aligned. This increases its size by 4 bytes
on IPL32 platforms so add code in sys_ioctl (and netbsd32_ioctl) to deal
with the older/smaller diskabel size. This change makes disklabel the
same for both IPL32 and LP64 platforms

OK by <martin>
 1.52  06-Nov-2019  kamil Avoid unaligned pointer arithmetic in check_label_magic()

Replace the logic of calculating the address with with base + offset.

Reported by GCC8.

Reported-by: syzbot+56769dece0ec3e35731e@syzkaller.appspotmail.com
 1.51  17-May-2019  christos Factor out the magic checking code for the label, and make it not depend
on alignment.
 1.50  03-Apr-2019  christos centralize setdisklabel(9)
 1.49  21-Jan-2018  christos branches: 1.49.4;
CID-1427768: Off by one
 1.48  07-Jan-2018  christos use a fixed-size type, this code also exists in
sys/dev/dkwedge/dkwedge_bsdlabel.c
 1.47  19-Feb-2017  rin PR kern/51208
Add DISKLABEL_EI (``Endian-Independent'' disklabel) kernel option to machines
that support Master Boot Record (MBR)
 1.46  26-Jun-2013  matt branches: 1.46.10; 1.46.14; 1.46.18;
If the MBR is a protective MBR, don't bother looking at it.
 1.45  03-Oct-2012  mlelstv No longer determine availability of ISO and UDF partitions, we default
to allow access to both. Only use a found ISO header to access the
correct session.
 1.44  13-Jul-2012  christos branches: 1.44.2;
revert previous; the problem was off by one in the bios device comparison
in x86_autoconf.c
 1.43  03-Jul-2012  christos Don't kill the iso partition at 'a' when we have a udf raw partition.
Makes cd0a mountable again. Should be pulled up to 6 (after people
verify that it works in the broken cases)
http://mail-index.netbsd.org/current-users/2012/06/14/msg020415.html
 1.42  30-Jun-2011  wiz branches: 1.42.2; 1.42.8;
dependant -> dependent
 1.41  11-May-2010  pooka This not working on ews4800mips has nothing to do with rump, so:
_RUMPKERNEL -> _MACHINE != ews4800mips
 1.40  04-May-2010  tsutsui Don't #error on invalid LABELSECTOR or LABELOFFSET on __RUMPKERNEL build.

As mentioned in src/sys/rump/dev/lib/libdisk/Makefile,
rump(4) builds don't check if each ${MACHINE} actually supports
MBR in MD readdisklabel(9) ops while it pulls MD <machine/disklabel.h>.

Workarounds so long broken build of ews4800mips.
 1.39  23-Dec-2009  mbalmer branches: 1.39.2; 1.39.4;
Fix typo, no code change.
 1.38  27-Nov-2009  pooka Make this work on some m68k ports which like putting the disklabel
in the third sector (or have copypasted disklabel.h from a port
which likes doing that ;).
 1.37  23-Nov-2009  pooka If cpu_disklabel includes struct dkbad, define __HAVE_DISKLABEL_DKBAD.
This allows use of subr_disk_mbr on all archs. Default to it for
the rump disk component. No functional change for regular kernels.
(The other option would've been to include dkbad in disklabels
everywhere, but arguably this approach has less possible side-effects,
especially given that wedges and related magic will take over the
world any second now).
 1.36  03-Jun-2009  pooka opt for _KERNEL_OPT
 1.35  28-Jan-2009  reinoud branches: 1.35.2;
Don't claim its an ISO partitioning scheme too early in the label. An MBR
might me there instead.
 1.34  08-Jan-2009  reinoud Fix the mess i made with the iso partitioning reading due to the fact that
disk_read_sector() wants DEV_BLKSIZE blkno's BUT sectorsize unit lengths
specified... how `logical'.

Real fixup pending on discussion on tech-kern/source-changes.
 1.33  03-Jan-2009  reinoud Fix ISO partitioning readin. ISO dictates its descriptors are minimal 2048
bytes long independent of the device block size.
 1.32  30-Dec-2008  reinoud Add ISO partition detection enabling auto-detection of iso9660 and UDF
partitions on optical media like CD/DVD/BD but also on all other media if
there is no NetBSD disklabel or MBR label.

Also fix cd's readdisklabel arguments so the ioctl's arrive at the right
device (!) and update its default label to make more sense.
 1.31  02-Jan-2008  ad branches: 1.31.6; 1.31.10; 1.31.18;
Merge vmlocking2 to head.
 1.30  08-Oct-2007  ad branches: 1.30.4; 1.30.6; 1.30.10;
Merge brelse() changes from the vmlocking branch.
 1.29  29-Jul-2007  ad branches: 1.29.4; 1.29.6; 1.29.8; 1.29.10;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.28  24-Jun-2007  dyoung branches: 1.28.2;
Extract common code from i386, xen, and sparc64, creating
config_handle_wedges() and read_disk_sectors(). On x86, handle_wedges()
is a thin wrapper for config_handle_wedges(). Share opendisk()
across architectures.

Add kernel code in support of specifying a root partition by wedge
name. E.g., root specifications "wedge:wd0a", "wedge:David's Root
Volume" are possible. (Patches for config(1) coming soon.)

In support of moving disks between architectures (esp. i386 <->
evbmips), I've written a routine convertdisklabel() that ensures
that the raw partition is at RAW_DISK by following these steps:

0 If we have read a disklabel that has a RAW_PART with
p_offset == 0 and p_size != 0, then use that raw partition.

1 If we have read a disklabel that has both partitions 'c'
and 'd', and RAW_PART has p_offset != 0 or p_size == 0,
but the other partition is suitable for a raw partition
(p_offset == 0, p_size != 0), then swap the two partitions
and use the new raw partition.

2 If the architecture's raw partition is 'd', and if there
is no partition 'd', but there is a partition 'c' that
is suitable for a raw partition, then copy partition 'c'
to partition 'd'.

3 Determine the drive's last sector, using either the
d_secperunit the drive reported, or by guessing (0x1fffffff).
If we cannot read the drive's last sector, then fail.

4 If we have read a disklabel that has no partition slot
RAW_PART, then create a partition RAW_PART. Make it span
the whole drive.

5 If there are fewer than MAXPARTITIONS partitions,
then "slide" the unsuitable raw partition RAW_PART, and
subsequent partitions, into partition slots RAW_PART+1
and subsequent slots. Create a raw partition at RAW_PART.
Make it span the whole drive.

The convertdisklabel() procedure can probably stand to be simplified,
but it ought to deal with all but an extraordinarily broken disklabel,
now.

i386: compiled and tested, sparc64: compiled, evbmips: compiled.
 1.27  14-Jun-2007  dyoung #include sys/bootblocks.h for its MBR #definitions.
 1.26  04-Mar-2007  christos branches: 1.26.2; 1.26.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.25  22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.24  21-Feb-2007  thorpej Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.23  09-Feb-2007  ad branches: 1.23.2;
Merge newlock2 to head.
 1.22  25-Nov-2006  scw Replace the myriad copies of bounds_check_with_label() with a single MI
version.

Add disk_blocksize(9) so that disk drivers can record the physical
block size of a disk if it is different to DEV_BSIZE. Right now this
simply initialises dk_blkshift and dk_byteshift according to the
supplied block size. This information is used in the MI version of
bounds_check_with_label().
 1.21  01-Nov-2006  yamt remove some __unused from function parameters.
 1.20  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.19  23-Sep-2006  jmcneill PR# 33260: [dM] kernel divide-by-zero for some broken disks
 1.18  11-Jun-2006  christos branches: 1.18.6; 1.18.8;
Always make partitions contiguous even if the mbr has gaps. From someone
who wants to remain anonymous.
 1.17  28-Jan-2006  dsl branches: 1.17.2; 1.17.6; 1.17.12;
Improve disk portability between systems.
- Always look for labels in the first two sectors
- Update all existing labels, but only write new labels to netbsd mbr
partitions, and the first/second sector of disks that don't have an mbr.
Moving disks between systems still sucks bigtime!
- raw patition is either c or d, if d then c is reserved
- max partitions might be 8 or 16, nothing in the label gives the maximum
- endianness
 1.16  27-Dec-2005  jmmv branches: 1.16.2;
Improve a comment in the patch I sent (handle DM6 DDO partition) based
on hubertf@'s comments. Hmm... I didn't even notice this was already
committed.
 1.15  26-Dec-2005  christos don't hard-code 63.
 1.14  26-Dec-2005  christos Julio M. Merino Vidal: Patch to recognize and automatically skip the Ontrack
Disk Manager drivers.
 1.13  18-Dec-2005  dsl KNF - remove the K&R function definitions
 1.12  18-Dec-2005  dsl Only update partition 2 when RAW_PART is 3.
 1.11  14-Dec-2005  dsl Revert previous change.
It breaks the code that generates a default label (with partition 'a'
covering the entire volume - which is what everything expects) for disks that
don't have a NetBSD label nor an MBR, but do have a single filesytem covering
the entire volume.
 1.10  14-Dec-2005  cube Remove bogus XXX comment: a.msg doesn't point to stack data.
 1.9  14-Dec-2005  cube Fix typo in previous commit.
 1.8  14-Dec-2005  reinoud Fix disklabel recognition code for mbr based systems like i386. It would
return NULL even though no disklabel was found making callers assume that a
valid disklabel WAS found but instead were presented by the dummy disklabel
that is created.

If the rval is SCAN_CONTINUE it now returns a standard error that no
disklabel was found instead of the NULL.
 1.7  11-Dec-2005  christos merge ktrace-lwp.
 1.6  26-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5  08-Feb-2005  fvdl Change the 'sz' variable in bounds_check_* to int64_t to avoid overflows
when a very large blocknumber is passed in.
 1.4  08-Oct-2003  lukem branches: 1.4.4; 1.4.10; 1.4.12;
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.3  19-Aug-2003  dsl When writing the disklabel:
- Write label to all netbsd (type 169) mbr partitions (even if they don't
already have a label).
- Update any label found in sector LABELSECTOR and sector 0.
Latter change makes DIOCWDINFO (etc) work on raidframe (fixing bin/22529).
 1.2  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1  07-Jul-2003  dsl MI code to read disklabels from mbr disks.
 1.4.12.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.12.1  12-Feb-2005  yamt sync with head.
 1.4.10.1  29-Apr-2005  kent sync with -current
 1.4.4.6  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.4.5  09-Feb-2005  skrll Sync with HEAD.
 1.4.4.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.4.3  18-Sep-2004  skrll Sync with HEAD.
 1.4.4.2  03-Aug-2004  skrll Sync with HEAD
 1.4.4.1  08-Oct-2003  skrll file subr_disk_mbr.c was added on branch ktrace-lwp on 2004-08-03 10:52:55 +0000
 1.6.4.6  21-Jan-2008  yamt sync with head
 1.6.4.5  27-Oct-2007  yamt sync with head.
 1.6.4.4  03-Sep-2007  yamt sync with head.
 1.6.4.3  26-Feb-2007  yamt sync with head.
 1.6.4.2  30-Dec-2006  yamt sync with head.
 1.6.4.1  21-Jun-2006  yamt sync with head.
 1.16.2.1  01-Feb-2006  yamt sync with head.
 1.17.12.1  19-Jun-2006  chap Sync with head.
 1.17.6.1  26-Jun-2006  yamt sync with head.
 1.17.2.1  09-Sep-2006  rpaulo sync with head
 1.18.8.2  10-Dec-2006  yamt sync with head.
 1.18.8.1  22-Oct-2006  yamt sync with head
 1.18.6.1  12-Jan-2007  ad Sync with head.
 1.23.2.2  12-Mar-2007  rmind Sync with HEAD.
 1.23.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.26.4.1  11-Jul-2007  mjf Sync with head.
 1.26.2.4  24-Aug-2007  ad Sync with buffer cache locking changes. See buf.h/vfs_bio.c for details.
Some minor portions are incomplete and needs to be verified as a whole.
 1.26.2.3  19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.26.2.2  15-Jul-2007  ad Sync with head.
 1.26.2.1  13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.28.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.29.10.2  29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.29.10.1  29-Jul-2007  ad file subr_disk_mbr.c was added on branch matt-mips64 on 2007-07-29 12:15:46 +0000
 1.29.8.1  14-Oct-2007  yamt sync with head.
 1.29.6.2  09-Jan-2008  matt sync with HEAD
 1.29.6.1  06-Nov-2007  matt sync with HEAD
 1.29.4.1  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.30.10.1  02-Jan-2008  bouyer Sync with HEAD
 1.30.6.1  04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.30.4.1  18-Feb-2008  mjf Sync with HEAD.
 1.31.18.2  03-Mar-2009  skrll Sync with HEAD.
 1.31.18.1  19-Jan-2009  skrll Sync with HEAD.
 1.31.10.4  11-Aug-2010  yamt sync with head.
 1.31.10.3  11-Mar-2010  yamt sync with head
 1.31.10.2  20-Jun-2009  yamt sync with head
 1.31.10.1  04-May-2009  yamt sync with head.
 1.31.6.1  17-Jan-2009  mjf Sync with HEAD.
 1.35.2.1  23-Jul-2009  jym Sync with HEAD.
 1.39.4.1  30-May-2010  rmind sync with head
 1.39.2.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.42.8.2  29-Jul-2013  msaitoh Pull up following revision(s) (requested by matt in ticket #910):
sys/kern/subr_disk_mbr.c: revision 1.46
If the MBR is a protective MBR, don't bother looking at it.
 1.42.8.1  12-Aug-2012  martin Pull up following revision(s) (requested by tsutsui in ticket #482):
sys/kern/subr_disk_mbr.c: revision 1.43
Apply workaround for installcd mountroot failure on some i386 machines
 1.42.2.2  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.42.2.1  30-Oct-2012  yamt sync with head
 1.44.2.3  03-Dec-2017  jdolecek update from HEAD
 1.44.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.44.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.46.18.1  21-Apr-2017  bouyer Sync with HEAD
 1.46.14.1  20-Mar-2017  pgoyette Sync with HEAD
 1.46.10.1  28-Aug-2017  skrll Sync with HEAD
 1.49.4.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.49.4.1  10-Jun-2019  christos Sync with HEAD
 1.56.14.1  31-May-2021  cjep sync with head
 1.56.12.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.57.12.1  22-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1052):

sys/kern/subr_disk_mbr.c: revision 1.59
sys/arch/evbppc/include/wii.h: revision 1.10
sys/arch/evbppc/wii/machdep.c: revision 1.9
sys/arch/evbppc/conf/files.wii: revision 1.5
sys/arch/evbppc/wii/dev/di.c: revision 1.1
sys/arch/evbppc/conf/WII: revision 1.8

Handle reading larger sectors (including 2k CD-ROM blocks).

Fall back to scan for ISO9660 sessions when MMC code fails.
disklabel now reports ISO/UDF partitions again for cd(4).

wii: Add more register definitions.

wii: Add support for Wii DVD drive.
This adds a virtual SCSI HBA driver that is able to read DVD video discs
inserted in the Wii.

wii: Early init for DVD support

RSS XML Feed