DISK(9)
πΎ DISK(9) β kernel disk storage API πΎ
okay bestie, gather round, because this is the disk(9) manual page from the Kernel Developer's Manual, and it's literally the whole vibe of "hey kernel driver, tell everyone about your disk". no cap.
β¨ 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 π
so the disk storage API is the lil' matchmaker that lets kernel device drivers for disk-like storage devices advertise themselves to the rest of the kernel, including GEOM(4) and devfs(5). it's giving "introducing my device to the group chat". β¨
every disk device gets described by a struct disk structure, which holds a whole bunch of parameters for the disk device, function pointers for the various methods that might get performed on the device, plus some private data storage for the device driver. and on top of that, some fields are reserved for GEOM to manage access to the device and its statistics. π
GEOM owns struct disk, periodt. drivers have to allocate storage for it with disk_alloc(), fill in the fields, and call disk_create() when the device is ready to service requests. disk_add_alias() adds an alias for the disk and must be called before disk_create(), but you can call it multiple times, no problem. for each alias you add, a device node gets created with make_dev_alias(9) β same way primary device nodes get created with make_dev(9) for d_name and d_unit. π
be careful bestie: make sure that only one driver creates aliases for any given name. we don't do duplicate drama here. π
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. plus, it prevents a re-taste on last close for writing if an error condition has been set in the provider. and after you call disk_destroy(), the device driver is not allowed to access the contents of struct disk anymore. like, at all. it's over, babe. π
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 π
these fields identify the disk device described by the structure instance. you must fill them in prior to submitting the structure to disk_create(), and they may not be subsequently changed. so get it right the first time, queen. π
u_int d_flagsβ optional flags telling 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 it must not conflict with devices serviced by other device drivers. iykyk. π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 π
these 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. slay, no gatekeeping. β¨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. this one is not optional bestie, it's the main character. π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. stay in your lane, respectfully. πdumper_t * d_dumpβ optional: if configured with dumpon(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. π this is the "we're so back" function.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 π
these fields identify the size and granularity of the disk device. they must stay stable from return of the drivers 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. they must stay stable from return of the drivers 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. π iconic honestly.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 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. it's your little pocket, bestie. π
void * d_drv1β private data pointer. typically used to store a pointer to the drivers softc structure for this disk device.
β SEE ALSO β
GEOM(4), devfs(5), MAKE_DEV(9)
π AUTHORS π
this manual page was written by Robert Watson. π thank you for your service, king.
π BUGS π
disk aliases are not a general purpose aliasing mechanism, but are intended only to ease the transition from one name to another. they can be used to ensure that nvd0 and nda0 are the same thing. they cannot be used to implement the diskX concept from macOS. soz, that's just not what this is. π
and that's the whole page, bestie!! this one came from the Debian flavour of the manual, dated August 3, 2017, and it's filed under DISK(9). go forth and advertise your disks responsibly. π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2003 Robert N. M. Watson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms