DISK(9)
πΎ DISK(9) β kernel disk storage API πΎ
from the Kernel Developer's Manual β okay bestie, let's get into it π
πΈ NAME πΈ
disk β kernel disk storage API
β¨ SYNOPSIS β¨
#include <geom/geom_disk.h>
struct disk *
disk_alloc(void);
void
disk_create(struct disk *disk, int version);
void
disk_gone(struct disk *disk);
void
disk_destroy(struct disk *disk);
int
disk_resize(struct disk *disk, int flags);
void
disk_add_alias(struct disk *disk, const char *alias);
π«Ά DESCRIPTION π«Ά
Okay so the disk storage API is literally the way kernel device drivers that provide access to disk-like storage devices advertise those devices to other kernel components β including GEOM(4) and devfs(4). iconic.
Each disk device is described by a struct disk structure. That structure has a bunch of parameters for the disk device, function pointers for various methods that may be performed on the device, and private data storage for the device driver. Some fields are also reserved for use by GEOM in managing access to the device and its statistics. no cap.
GEOM owns struct disk, so drivers must allocate storage for it with the disk_alloc() function, fill in the fields, and call disk_create() when the device is ready to service requests. fr fr.
disk_add_alias() adds an alias for the disk and must be called before disk_create(), but it may be called multiple times. For each alias added, a device node will be created with make_dev_alias(9) in the same way primary device nodes are created with make_dev(9) for d_name and d_unit. Care should be taken to ensure that only one driver creates aliases for any given name. π
disk_resize() can be called by the driver after modifying d_mediasize to notify GEOM about the disk capacity change. The flags field should be set to either M_WAITOK or M_NOWAIT.
disk_gone() orphans all of the providers associated with the drive, setting an error condition of ENXIO in each one. In addition, it prevents a re-taste on last close for writing if an error condition has been set in the provider. After calling disk_destroy(), the device driver is not allowed to access the contents of struct disk anymore. periodt.
The disk_create() function takes a second parameter, version, which must always be passed DISK_VERSION. If GEOM detects that the driver is compiled against an unsupported version, it will ignore the device and print a warning on the console. β οΈ
πͺͺ Descriptive Fields πͺͺ
The following fields identify the disk device described by the structure instance. They must be filled in prior to submitting the structure to disk_create() and may not be subsequently changed.
u_int d_flagsβ Optional flags indicating to the storage framework what optional features or descriptions the storage device driver supports. Currently supported flags areDISKFLAG_OPEN(maintained by storage framework),DISKFLAG_CANDELETE(maintained by device driver), andDISKFLAG_CANFLUSHCACHE(maintained by device driver).const char * d_nameβ Holds the name of the storage device class, e.g.,ahd. This value typically uniquely identifies a particular driver device, and must not conflict with devices serviced by other device drivers.u_int d_unitβ Holds the instance of the storage device class, e.g.,4. This namespace is managed by the device driver, and assignment of unit numbers might be a property of probe order, or in some cases topology. Together, thed_nameandd_unitvalues will uniquely identify a disk storage device. β¨
π§ Disk Device Methods π§
The following fields identify various disk device methods, if implemented:
disk_open_t * d_openβ Optional: invoked when the disk device is opened. If no method is provided, open will always succeed.disk_close_t * d_closeβ Optional: invoked when the disk device is closed. Although an error code may be returned, the call should always terminate any state setup by the corresponding open method call.disk_strategy_t * d_strategyβ Mandatory: invoked when a newstruct biois to be initiated on the disk device.disk_ioctl_t * d_ioctlβ Optional: invoked when an I/O control operation is initiated on the disk device. Please note that for security reasons these operations should not be able to affect other devices than the one on which they are performed. πdumper_t * d_dumpβ Optional: if configured withdumpon(8), this function is invoked from a very restricted system state after a kernel panic to record a copy of the system RAM to the disk.disk_getattr_t * d_getattrβ Optional: if this method is provided, it gives the disk driver the opportunity to override the default GEOM response toBIO_GETATTRrequests. This function should return-1if the attribute is not handled,0if the attribute is handled, or anerrnoto be passed tog_io_deliver().disk_gone_t * d_goneβ Optional: if this method is provided, it will be called afterdisk_gone()is called, once GEOM has finished its cleanup process. Once this callback is called, it is safe for the disk driver to free all of its resources, as it will not be receiving further calls from GEOM. π¦
π§± Mandatory Media Properties π§±
The following fields identify the size and granularity of the disk device. These fields must stay stable from return of the driver's open method until the close method is called, but it is perfectly legal to modify them in the open method before returning.
u_int d_sectorsizeβ The sector size of the disk device in bytes.off_t d_mediasizeβ The size of the disk device in bytes.u_int d_maxsizeβ The maximum supported size in bytes of an I/O request. Requests larger than this size will be chopped up by GEOM. π₯
π Optional Media Properties π
These optional fields can provide extra information about the disk device. Do not initialize these fields if the field/concept does not apply. These fields must stay stable from return of the driver's open method until the close method is called, but it is perfectly legal to modify them in the open method before returning.
u_int d_fwsectors,u_int d_fwheadsβ The number of sectors and heads advertised on the disk device by the firmware or BIOS. These values are almost universally bogus, but on some architectures necessary for the correct calculation of disk partitioning.u_int d_stripeoffset,u_int d_stripesizeβ These two fields can be used to describe the width and location of natural performance boundaries for most disk technologies. Please seesrc/sys/geom/notesfor details.char d_ident[DISK_IDENT_SIZE]β This field can and should be used to store the disk's serial number if thed_getattrmethod described above isn't implemented, or if it does not support theGEOM::identattribute.char d_descr[DISK_IDENT_SIZE]β This field can be used to store the disk vendor and product description.uint16_t d_hba_vendorβ This field can be used to store the PCI vendor ID for the HBA connected to the disk.uint16_t d_hba_deviceβ This field can be used to store the PCI device ID for the HBA connected to the disk.uint16_t d_hba_subvendorβ This field can be used to store the PCI subvendor ID for the HBA connected to the disk.uint16_t d_hba_subdeviceβ This field can be used to store the PCI subdevice ID for the HBA connected to the disk. π
π Driver Private Data π
This field may be used by the device driver to store a pointer to private data to implement the disk service.
void * d_drv1β Private data pointer. Typically used to store a pointer to the driver's softc structure for this disk device.
π SEE ALSO π
π HISTORY π
The kernel disk storage API first appeared in FreeBSD 4.9.
π AUTHORS π
This manual page was written by Robert Watson.
π BUGS π
π¨ bestie, listen: disk aliases are not a general purpose aliasing mechanism. They are intended only to ease the transition from one name to another. They can be used to ensure thatnvd0andnda0are the same thing. They cannot be used to implement thediskXconcept from macOS. π
π that's the whole page β sourced from Debian, dated April 30, 2020, and it's the DISK(9) manual. mwah! π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 Robert N. M. Watson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms