---
name: "disk"
section: "9freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/disk/9freebsd"
---

# disk(9freebsd)

kernel disk storage API

## 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

The disk storage API permits kernel device drivers providing access to disk-like storage devices to advertise the device to other kernel components, including [GEOM(4)](/GEOM/4.md) and devfs(5).

Each disk device is described by a *struct disk* structure, which contains a variety of parameters for the disk device, function pointers for various methods that may be performed on the device, as well as private data storage for the device driver. In addition, some fields are reserved for use by GEOM in managing access to the device and its statistics.

GEOM has the ownership of *struct disk*, and 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. **disk\_add\_alias**() adds an alias for the disk and must be called before **disk\_create**(), but may be called multiple times. For each alias added, a device node will be created with [make\_dev\_alias(9)](/make_dev_alias/9.md) in the same way primary device nodes are created with [make\_dev(9)](/make_dev/9.md) 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.

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, and 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 are DISKFLAG\_OPEN (maintained by storage framework), DISKFLAG\_CANDELETE (maintained by device driver), and DISKFLAG\_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, the *d\_name* and *d\_unit* values 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 new *struct bio* is 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 with [dumpon(8)](/dumpon/8.md), 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 to BIO\_GETATTR requests. This function should return -1 if the attribute is not handled, 0 if the attribute is handled, or an errno to be passed to g\_io\_deliver().

- *disk\_gone\_t \** *d\_gone*

  Optional: if this method is provided, it will be called after disk\_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 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. These fields 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.

- *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 see *src/sys/geom/notes* for details.

- *char* *d\_ident\[DISK\_IDENT\_SIZE\]*

  This field can and should be used to store disk's serial number if the d\_getattr method described above isn't implemented, or if it does not support the GEOM::ident attribute.

- *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 drivers *softc* structure for this disk device.

## SEE ALSO

[GEOM(4)](/GEOM/4.md), devfs(5), MAKE\_DEV(9)

## AUTHORS

This manual page was written by Robert Watson.

## 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.
