1.\" 2.\" Copyright (c) 2003 Robert N. M. Watson 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice(s), this list of conditions and the following disclaimer as 10.\" the first lines of this file unmodified other than the possible 11.\" addition of one or more copyright notices. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice(s), this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 17.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 20.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26.\" DAMAGE. 27.\" 28.\" $FreeBSD$ 29.\" 30.Dd October 30, 2012 31.Dt DISK 9 32.Os 33.Sh NAME 34.Nm disk 35.Nd kernel disk storage API 36.Sh SYNOPSIS 37.In geom/geom_disk.h 38.Ft struct disk * 39.Fn disk_alloc void 40.Ft void 41.Fn disk_create "struct disk *disk" "int version" 42.Ft void 43.Fn disk_gone "struct disk *disk" 44.Ft void 45.Fn disk_destroy "struct disk *disk" 46.Ft int 47.Fn disk_resize "struct disk *disk" "int flags" 48.Sh DESCRIPTION 49The disk storage API permits kernel device drivers providing access to 50disk-like storage devices to advertise the device to other kernel 51components, including 52.Xr GEOM 4 53and 54.Xr devfs 5 . 55.Pp 56Each disk device is described by a 57.Vt "struct disk" 58structure, which contains a variety of parameters for the disk device, 59function pointers for various methods that may be performed on the device, 60as well as private data storage for the device driver. 61In addition, some fields are reserved for use by GEOM in managing access 62to the device and its statistics. 63.Pp 64GEOM has the ownership of 65.Vt "struct disk" , 66and drivers must allocate storage for it with the 67.Fn disk_alloc 68function, 69fill in the fields and call 70.Fn disk_create 71when the device is ready to service requests. 72.Fn disk_resize 73can be called by the driver after modifying 74.Va d_mediasize 75to notify GEOM about the disk capacity change. 76The 77.Fa flags 78field should be set to either M_WAITOK, or M_NOWAIT. 79.Fn disk_gone 80orphans all of the providers associated with the drive, setting an error 81condition of ENXIO in each one. 82In addition, it prevents a re-taste on last close for writing if an error 83condition has been set in the provider. 84After calling 85.Fn disk_destroy , 86the device driver is not allowed to access the contents of 87.Vt "struct disk" 88anymore. 89.Pp 90The 91.Fn disk_create 92function 93takes a second parameter, 94.Fa version , 95which must always be passed 96.Dv DISK_VERSION . 97If GEOM detects that the driver is compiled against an unsupported version, 98it will ignore the device and print a warning on the console. 99.Ss Descriptive Fields 100The following fields identify the disk device described by the structure 101instance, and must be filled in prior to submitting the structure to 102.Fn disk_create 103and may not be subsequently changed: 104.Bl -tag -width indent 105.It Vt u_int Va d_flags 106Optional flags indicating to the storage framework what optional features 107or descriptions the storage device driver supports. 108Currently supported flags are 109.Dv DISKFLAG_NEEDSGIANT 110(maintained by device driver), 111.Dv DISKFLAG_OPEN 112(maintained by storage framework), 113.Dv DISKFLAG_CANDELETE 114(maintained by device driver), 115and 116.Dv DISKFLAG_CANFLUSHCACHE 117(maintained by device driver). 118.It Vt "const char *" Va d_name 119Holds the name of the storage device class, e.g., 120.Dq Li ahd . 121This value typically uniquely identifies a particular driver device, 122and must not conflict with devices serviced by other device drivers. 123.It Vt u_int Va d_unit 124Holds the instance of the storage device class, e.g., 125.Dq Li 4 . 126This namespace is managed by the device driver, and assignment of unit 127numbers might be a property of probe order, or in some cases topology. 128Together, the 129.Va d_name 130and 131.Va d_unit 132values will uniquely identify a disk storage device. 133.El 134.Ss Disk Device Methods 135The following fields identify various disk device methods, if implemented: 136.Bl -tag -width indent 137.It Vt "disk_open_t *" Va d_open 138Optional: invoked when the disk device is opened. 139If no method is provided, open will always succeed. 140.It Vt "disk_close_t *" Va d_close 141Optional: invoked when the disk device is closed. 142Although an error code may be returned, the call should always terminate 143any state setup by the corresponding open method call. 144.It Vt "disk_strategy_t *" Va d_strategy 145Mandatory: invoked when a new 146.Vt "struct bio" 147is to be initiated on the disk device. 148.It Vt "disk_ioctl_t *" Va d_ioctl 149Optional: invoked when an I/O control operation is initiated on the disk device. 150Please note that for security reasons these operations should not 151be able to affect other devices than the one on which they are performed. 152.It Vt "dumper_t *" Va d_dump 153Optional: if configured with 154.Xr dumpon 8 , 155this function is invoked from a very restricted system state after a 156kernel panic to record a copy of the system RAM to the disk. 157.It Vt "disk_getattr_t *" Va d_getattr 158Optional: if this method is provided, it gives the disk driver the 159opportunity to override the default GEOM response to BIO_GETATTR requests. 160This function should return -1 if the attribute is not handled, 0 if the 161attribute is handled, or an errno to be passed to g_io_deliver(). 162.It Vt "disk_gone_t *" Va d_gone 163Optional: if this method is provided, it will be called after disk_gone() 164is called, once GEOM has finished its cleanup process. 165Once this callback is called, it is safe for the disk driver to free all of 166its resources, as it will not be receiving further calls from GEOM. 167.El 168.Ss Mandatory Media Properties 169The following fields identify the size and granularity of the disk device. 170These fields must stay stable from return of the drivers open method until 171the close method is called, but it is perfectly legal to modify them in 172the open method before returning. 173.Bl -tag -width indent 174.It Vt u_int Va d_sectorsize 175The sector size of the disk device in bytes. 176.It Vt off_t Va d_mediasize 177The size of the disk device in bytes. 178.It Vt u_int Va d_maxsize 179The maximum supported size in bytes of an I/O request. 180Requests larger than this size will be chopped up by GEOM. 181.El 182.Ss Optional Media Properties 183These optional fields can provide extra information about the disk 184device. 185Do not initialize these fields if the field/concept does not apply. 186These fields must stay stable from return of the drivers open method until 187the close method is called, but it is perfectly legal to modify them in 188the open method before returning. 189.Bl -tag -width indent 190.It Vt u_int Va d_fwsectors , Vt u_int Va d_fwheads 191The number of sectors and heads advertised on the disk device by the 192firmware or BIOS. 193These values are almost universally bogus, but on some architectures 194necessary for the correct calculation of disk partitioning. 195.It Vt u_int Va d_stripeoffset , Vt u_int Va d_stripesize 196These two fields can be used to describe the width and location of 197natural performance boundaries for most disk technologies. 198Please see 199.Pa src/sys/geom/notes 200for details. 201.It Vt char Va d_ident[DISK_IDENT_SIZE] 202This field can and should be used to store disk's serial number if the 203d_getattr method described above isn't implemented, or if it does not 204support the GEOM::ident attribute. 205.It Vt char Va d_descr[DISK_IDENT_SIZE] 206This field can be used to store the disk vendor and product description. 207.It Vt uint16_t Va d_hba_vendor 208This field can be used to store the PCI vendor ID for the HBA connected to 209the disk. 210.It Vt uint16_t Va d_hba_device 211This field can be used to store the PCI device ID for the HBA connected to 212the disk. 213.It Vt uint16_t Va d_hba_subvendor 214This field can be used to store the PCI subvendor ID for the HBA connected to 215the disk. 216.It Vt uint16_t Va d_hba_subdevice 217This field can be used to store the PCI subdevice ID for the HBA connected to 218the disk. 219.El 220.Ss Driver Private Data 221This field may be used by the device driver to store a pointer to 222private data to implement the disk service. 223.Bl -tag -width indent 224.It Vt "void *" Va d_drv1 225Private data pointer. 226Typically used to store a pointer to the drivers 227.Vt softc 228structure for this disk device. 229.El 230.Sh SEE ALSO 231.Xr GEOM 4 , 232.Xr devfs 5 233.Sh AUTHORS 234This manual page was written by 235.An Robert Watson . 236