History log of /freebsd-current/stand/i386/libi386/biosdisk.c
Revision Date Author Comments
# 3e15b01d 22-Feb-2024 Warner Losh <imp@FreeBSD.org>

libsa: Remove redundant sys/cdefs.h

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 8337ab69 30-Nov-2022 Warner Losh <imp@FreeBSD.org>

stand: For all disk drivers, connect dv_parsedev to disk_parsedev

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37339


# d43bcf62 16-Sep-2022 Warner Losh <imp@FreeBSD.org>

stand: Stop support booting 4.x and earlier kernels

FreeBSD 4.x and earlier used the bi_bios_geom to get the geometry of the
device. Starting in 5.x, with the wdc -> ata rewrite, it was used only
in pc98 kernels to report geometry of the drives. It can be safely
removed as booting kernels this old is no longer supported. This saves
176 bytes in the BIOS loader.

Sponsored by: Netflix
Reviewed by: adrian, emaste
Differential Revision: https://reviews.freebsd.org/D36543


# 72291cee 07-Sep-2022 Kyle Evans <kevans@FreeBSD.org>

stand: i386: take into account disk sector size for blk calculation

disk_blocks assumes BIOSDISK_SECSIZE, but the media may not be using
it. In particular, bioscd on Parallels presents a 2K sector size, so
we end up with a short disk_blocks and subsequent validation fails when
trying to read /boot/lua.

PR: 233098
Reviewed by: imp, tsoome
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D36490


# ad759c73 11-Aug-2022 Warner Losh <imp@FreeBSD.org>

stand: Add disk_fmtdev for dv_fmtdev for all the disk devices

All of the archsw fmtdev functions treat DEVT_DISK as a call to
disk_fmtdev. Set all disks' dv_fmtdev to disk_fmtdev so devformat
will return the same thing.

Sponsored by: Netflix
Reviewed by: tsoome (prior version)
Differential Revision: https://reviews.freebsd.org/D35917


# e98f952c 27-Jul-2022 Warner Losh <imp@FreeBSD.org>

stand: Make sure nobody has a NULL pointer for dv_cleanup

dv_cleanup is specified almost everywhere. Use nullsys instead of NULL
to indicate 'do nothing'. Also, be consistent in trailing commas that
were missing before.

Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D35913


# 313724ba 30-May-2021 Colin Percival <cperciva@FreeBSD.org>

loader: Use tslog to instrument some functions

In my initial testing, these are the functions which showed up as
being worth instrumenting. More may be added later.

common/console.c: cons_probe
common/gfx_fb.c: read_list, insert_font, autoload_font
common/interp.c: interact
common/interp_lua.c: interp_init, interp_run
efi/libefi/efipart.c: efipart_readwrite
i386/libi386/biosdisk.c: bd_init, bd_open, bd_edd_io, bd_chs_io, bd_io
libsa/open.c: open
libsa/read.c: read
libsa/twiddle.c: twiddle

Note that profiling interp_run may be of questionable utility as it
may depend on user behaviour (e.g. pressing keys).

Reviewed by: kevans (earlier version)


# b0af1e20 03-Feb-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: bc_add can not use any other probes than ah=0x4b

CD boot is broken for some systems since bioscd and biosdisk merge. The issue is that we can not use anything else than int 13 ah=0x4b to query cd information.

The patch does restore the same probe as was originally used in bioscd.c. Additionally extra buffer padding is used to avoid memory corruption caused by some systems.

PR: 234031
Reported by: ultramage and others
MFC after: 1 day


# 20698d15 09-Jan-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: bioscd probe can get sector size 0

With buggy BIOS, it may happen we get sector size reported 0 for cd, and then
the default 512 is used, which is quite wrong.

PR: 238749


# 7f549997 16-Dec-2019 Warner Losh <imp@FreeBSD.org>

Use symbolic names for int13 calls

For all the INT13 calls, use symbolic names instead of magic numbers. This makes
it easier to understand what the code is doing w/o a trip to google to find what
these numbers mean.


# 82c29d4f 09-May-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: use DPRINTF in biosdisk.c and define safe DPRINTF

r345066 did miss biosdisk.c.

Also define DPRINTF as ((void)0) for case we do not want debug printouts.

MFC after: 1 week


# 14243f8d 24-Mar-2019 Ian Lepore <ian@FreeBSD.org>

Distinguish between "no partition" and "choose best partition" with a constant.

The values of the d_slice and d_partition fields of a disk_devdesc have a
few values with special meanings in the disk_open() routine. Through various
evolutions of the loader code over time, a d_partition value of -1 has
meant both "use the first ufs partition found in the bsd label" and "don't
open a bsd partition at all, open the raw slice."

This defines a new special value of -2 to mean open the raw slice, and it
gives symbolic names to all the special values used in d_slice and
d_partition, and adjusts all existing uses of those fields to use the new
constants.

The phab review for this timed out without being accepted, but I'm still
citing it below because there is useful commentary there.

Differential Revision: https://reviews.freebsd.org/D19262


# a9f7119b 05-Jan-2019 Toomas Soome <tsoome@FreeBSD.org>

With buggy int13 ah=15, we can mis-identify the floppy devices.

We have no option than trust INT13 ah=08 return code during the init phase.

PR: 234460
Reported by: Oleh Hushchenkov
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D18723


# 75772fa2 30-Dec-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: create bio_alloc and bio_free for bios bounce buffer

We do have 16KB buffer space defined in pxe.c, move it to bio.c and implement
bio_alloc()/bio_free() interface to make it possible to use this space for
other BIOS calls (notably, from biosdisk.c).

MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D17131


# cdff1036 30-Nov-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: create separate lists for fd, cd and hd, merge bioscd with biosdisk

Create unified block IO implementation in BIOS version, like it is done in UEFI
side. Implement fd, disk and cd device lists, this will split floppy devices
from disks and will allow us to have consistent, predictable device naming
(modulo BIOS issues).

Differential Revision: https://reviews.freebsd.org/D17888


# 55d5c949 29-Nov-2018 Maxim Sobolev <sobomax@FreeBSD.org>

The libstand's panic() appends its own '\n' to the message, so that users of the API
don't need to supply one.

MFC after: 2 weeks


# 53e3fbee 07-Nov-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: always set media size from partition.

The disk access is validated by using partition table definitions, therefore
we have no need for if statements, just set the disk size.

Of course the partition table itself may be incorrect/inconsistent, but if
so, we are in trouble anyhow.

Differential Revision: https://reviews.freebsd.org/D17822


# 0d0ffe4f 02-Nov-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: biosdisk should check if the media is present

The bd_print/bd_open/bd_strategy need to make sure the device does have
media, before getting into performing IO operations. Some systems can
hung if the device without a media is accessed.

Reported by: yuripv


# 09312399 31-Oct-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: issue edd probe before legacy ah=08 and detect no media

while probing for drives, use int13 extended info before standard one and
provide workaround for case we are not getting needed information in case
of floppy drive.

In case of INT13 errors, there are (at least) 3 error codes appearing in case
of missin media - 20h, 31h and 80h. Flag the no media and do not print an
error.

Differential Revision: https://reviews.freebsd.org/D17667


# 8b7db465 23-Oct-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: biosdisk interface should be able to cope with 4k sectors

The 4kn support in current bios specific biosdisk.c is broken, as the code
is only implementing the support for the 512B sector size.

This work is building the support for custom size sectors, we still do assume
the requested data to be multiple of 512B blocks and we only do address the
biosdisk.c interface here.

For reference, see also:
https://www.illumos.org/issues/8303
https://www.illumos.org/rb/r/547

As the GELI is moved above biosdisk "layer", the GELI should just work

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D11174


# e7da951e 16-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

libi386: bd_io_workaround() is to be called for reads only

bd_io() can perform either reads or writes, we only need bd_io_workaround()
for reads.


# 8000f383 16-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

libi386: small style updates in biosdisk

Use break instead of return in for loop, as done earlier. Insert and remove
some blank lines. No functional changes intended.


# 799bbc25 15-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

libi386: use BD_RD and BR_WR constants

Use BD_RD and BD_WR instead of 0 and 1.

Reported by: ian


# 462d81dd 15-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

libi386: remove bd_read() and bd_write() wrappers

Those wroappers are nice, but do not really add much value.


# 4273aef5 15-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

libi386: remove BD_SUPPORT_FRAGS

BD_SUPPORT_FRAGS is preprocessor knob to allow partial reads in bioscd/biosdisk
level. However, we already have support for partial reads in bcache, and there
is no need to have duplication via preprocessor controls.

Note that bioscd/biosdisk interface is assumed to perform IO in 512B blocks,
so the only translation we have to do is 512 <-> native block size.

Differential Revision: https://reviews.freebsd.org/D16600


# 8750586c 05-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: bd_open() should cleanup from disk_open() error

Since bd_open() does early increment for reference counter and bcache
allocation, it also should undo those in case of the error.

Also remove unused variables rdev, g_err.


# d1e22b8f 05-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: 337353 did miss to rename 2 write instances

2 write instances got somehow missed.


# 7bb45e61 05-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: cstyle cleanup for biosdisk.c

Also switch u_int to uint32_t. Also replace "write" by "dowrite".
No functional changes intended.


# d11ef379 04-Aug-2018 Toomas Soome <tsoome@FreeBSD.org>

loader: biosdisk.c has leftover geli header.

A small cleanup, remove unneeded #include.


# 3848ff5c 04-Aug-2018 Xin LI <delphij@FreeBSD.org>

In r337271, we limited the sector number to the lower of calculated
number and CHS based number. However, on some systems, BIOS would
report 0 in CHS fields, making the system to think there is 0 sectors.

Add a check before comparing the calculated total with bd_sectors.

Reviewed by: tsoome, cy
Differential Revision: https://reviews.freebsd.org/D16577


# ca237cc5 03-Aug-2018 Cy Schubert <cy@FreeBSD.org>

Some drives report a geometry that is inconsisetent with the total
number of sectors reported through the BIOS. Cylinders * heads *
sectors may not necessarily be equal to the total number of sectors
reported through int13h function 48h.

An example of this is when a Mediasonic HD3-U2B PATA to USB enclosure
with a 80 GB disk is attached. Loader hangs at line 506 of
stand/i386/libi386/biosdisk.c while attempting to read sectors beyond
the end of the disk, sector 156906855. I discovered that the Mediasonic
enclosure was reporting the disk with 9767 cylinders, 255 heads, 63
sectors/track. That's 156906855 sectors. However camcontrol and
Windows 10 both report report the disk having 156301488 sectors, not
the calculated value. At line 280 biosdisk.c sets the sectors to the
higher of either bd->bd_sectors or the total calculated at line 276
(156906855) instead of the lower and correct value of 156301488 reported
by int 13h 48h.

This was tested on all three of my Mediasonic HD3-U2B PATA to USB
enclosures.

Instead of using the higher of bd_sectors (returned by int13h) or the
calculated value, this patch uses the lower and safer of the values.

Reviewed by: tsoome@
Differential Revision: https://reviews.freebsd.org/D16577


# c1418270 13-Jul-2018 Ian Lepore <ian@FreeBSD.org>

Extend loader(8) geli support to all architectures and all disk-like devices.

This moves the bulk of the geli support from lib386/biosdisk.c into a new
geli/gelidev.c which implements a devsw-type device whose dv_strategy()
function handles geli decryption. Support for all arches comes from moving
the taste-and-attach code to the devopen() function in libsa.

After opening any DEVT_DISK device, devopen() calls the new function
geli_probe_and_attach(), which will "attach" the geli code to the open_file
struct by creating a geli_devdesc instance to replace the disk_devdesc
instance in the open_file. That routes all IO for the device through the
geli code.

A new public geli_add_key() function is added, to allow arch/vendor-specific
code to add keys obtained from custom hardware or other sources.

With these changes, geli support will be compiled into all variations of
loader(8) on all arches because the default is WITH_LOADER_GELI.

Relnotes: yes
Sponsored by: Microchip Technology Inc
Differential Revision: https://reviews.freebsd.org/D15743


# 71f0c895 16-Jun-2018 Allan Jude <allanjude@FreeBSD.org>

Avoid reading past the end of the disk in zfsboot.c and biosdisk.c

The GELI boot code rounds reads up to 4k, since the encrypted sectors are
4k, and must be decrypted as a unit. With oddball sized disks (almost
always virtual), this can lead to reading past the end of the disk.

Reviewed by: imp, tsoome
Sponsored by: Klara Systems
Differential Revision: https://reviews.freebsd.org/D15844


# f567034d 16-Jun-2018 Allan Jude <allanjude@FreeBSD.org>

biosdisk.c: fix type in debug printf

Sponsored by: Klara Systems


# 23e7fe13 15-Jun-2018 Allan Jude <allanjude@FreeBSD.org>

biosdisk.c: add missing \n to error message

Sponsored by: Klara Systems


# bdeee1b2 15-Jun-2018 Allan Jude <allanjude@FreeBSD.org>

biosdisk.c remove redundant variable

`rdev` and `disk` serve the same purpose, read the partition table without
the `d_offset` or `d_slice` set, so the read is relative to the start of
the disk. Reuse the already initialized `disk` instead of making another
copy later.

Sponsored by: Klara Systems


# 86981e42 15-Jun-2018 Allan Jude <allanjude@FreeBSD.org>

Correct logic error in biosdisk.c:bd_realstrategy()

The wrong condition is used when evaluating the return of disk_ioctl()
This results in reaching the 'We should not get here' branch in most casts

Reviewed by: imp
Sponsored by: Klara Systems
Differential Revision: https://reviews.freebsd.org/D15839


# 9f6fd839 05-Jun-2018 Ian Lepore <ian@FreeBSD.org>

Remove comments and assertions that are no longer valid after r330809.

r330809 replaced duplication of devdesc struct fields with an embedded copy
of the devdesc struct, to avoid fragility. That means all the scattered
comments indicating that structs must match are no longer valid. Likewise
asserts that attempted to mitigate some of the old fragility.

Reviewed by: imp@


# 3bb88c3c 28-Mar-2018 Kyle Evans <kevans@FreeBSD.org>

stand: Add workaround for HP BIOS issues

hrs@ and kuriyama@ have found that on some HP BIOS, a system will fail to
boot immediately after installation with the claim that it can't work out
which disk they are booting from.

They tracked it down to a buffer overrun, and found that it could be
alleviated by doing a dummy read before-hand.

Submitted by: kuriyama
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D14341


# 56e53cb8 13-Mar-2018 Warner Losh <imp@FreeBSD.org>

Prefer uintXX_t to u_intXX_t

A foolish consistency is the hobgoblin of little minds, adored by
little statesmen and philosophers and divines. With consistency a
great soul has simply nothing to do. -- Ralph Waldo Emerson


# 3ee1f280 13-Mar-2018 Toomas Soome <tsoome@FreeBSD.org>

biosdisk.c should not set d_opendata.

Same as 330807, d_opendata is owned by open_disk and we should not
set it.

M stand/i386/libi386/biosdisk.c


# ad00892f 12-Mar-2018 Warner Losh <imp@FreeBSD.org>

Remove d_type from devdesc. It's not needed as we can fetch it from
d_dev->dv_type when we need it.


# de04d704 12-Mar-2018 Warner Losh <imp@FreeBSD.org>

Use the actual struct devdesc at the start of all *_devdesc structs

The current system is fragile and requires very careful layout of all
*_devdesc structures. It also makes it hard to change the base
devdesc. Take a page from CAM and put the 'header' in all the derived
classes and adjust the code to match.

For OFW, move the iHandle h_handle out of a slot conflicting with
d_opendata. Due to quirks in the alignment rules, this worked.
However changing the code to use d_opendata storage now that it's a
pointer is hard, so just have a separate field for it.

All other cleanups were to make the *_devdesc structures match where
they'd taken some liberties that were none-the-less compatible enough
to work.


# 1227a4f4 01-Dec-2017 Warner Losh <imp@FreeBSD.org>

Fix all warnings related to geli and ZFS support on x86.

Default WARNS to 0 still, since there's still some warnings on other
architectures.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D13301


# ca987d46 14-Nov-2017 Warner Losh <imp@FreeBSD.org>

Move sys/boot to stand. Fix all references to new location

Sponsored by: Netflix