Page MenuHomeFreeBSD

Implement disk_ioctl() to support DIOCGSECTORSIZE and DIOCGMEDIASIZE.

Authored by tsoome on Nov 20 2016, 9:37 PM.
Referenced Files
Unknown Object (File)
Sat, Jul 20, 11:18 AM
Unknown Object (File)
Fri, Jul 19, 1:36 PM
Unknown Object (File)
Fri, Jul 19, 3:30 AM
Unknown Object (File)
Sat, Jul 13, 9:36 PM
Unknown Object (File)
Sat, Jun 29, 2:55 PM
Unknown Object (File)
Thu, Jun 27, 9:46 PM
Unknown Object (File)
Tue, Jun 25, 9:06 AM
Unknown Object (File)
Jun 21 2024, 6:06 PM



Need interface to extract information about disk abstraction,
to read disk or partition size depending on the provided argument
and adjust disk size based on information in partition table.

The disk handle from disk_open() has d_offset field to point to
partition start. So we can use this fact to return either whole disk
size or partition size. For this we only need to record partition size
we get from disk_open() anyhow.

In addition, this will also make it possible to adjust the disk media size
based on information from partition table. The problem with disk size is
about some BIOS systems reporting bogus disk size for 2+TB disks, but
since such disks are using GPT partitioning, and GPT does have information
about disk size (alternate LBA + 1), we can use this fact to record disk
size based on partition table.

This patch does exactly this: implements DIOCGSECTORSIZE and DIOCGMEDIASIZE
ioctl, and DIOCGMEDIASIZE will report either disk media size or partition size.

Adds ptable_getsize() call to read partition size in bytes from ptable pointer.
Updates disk_open() to use ptable_getsize() to update mediasize value.

Implements GPT detection function to update ptable size (used by
ptable_getsize()) according to alternate lba (which is location of backup copy
of GPT header table).

This implementation is used by
and not yet posted code to fix biosdisk.c for large disks.

Diff Detail

rS FreeBSD src repository - subversion
Lint Not Applicable
Tests Not Applicable

Event Timeline

tsoome retitled this revision from to Implement disk_ioctl() to support DIOCGSECTORSIZE and DIOCGMEDIASIZE..
tsoome updated this object.
tsoome edited the test plan for this revision. (Show Details)
tsoome added reviewers: allanjude, imp.

svn update to current state.

271 ↗(On Diff #24643)

Does it make sense to keep this? Do any of the classes use this?

271 ↗(On Diff #24643)

I haven't seen any need. in fact the need is reversed, the specific interfaces "extend" the disk_* api, like bd_open() does its internal thing and then calls disk_open(), bd_ioctl calls up to disk_ioctl() etc.

allanjude edited edge metadata.

Approved for commit

This revision is now accepted and ready to land.Feb 5 2017, 10:38 PM
This revision was automatically updated to reflect the committed changes.