DISK(9) | Kernel Developer's Manual | DISK(9) |
disk
— kernel disk
storage API
#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);
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) 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) 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.
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.
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:
DISKFLAG_OPEN
(maintained by storage
framework), DISKFLAG_CANDELETE
(maintained by
device driver), and DISKFLAG_CANFLUSHCACHE
(maintained by device driver).ahd
”. This value typically uniquely
identifies a particular driver device, and must not conflict with devices
serviced by other device drivers.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.The following fields identify various disk device methods, if implemented:
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.
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.
This field may be used by the device driver to store a pointer to private data to implement the disk service.
This manual page was written by Robert Watson.
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.
August 3, 2017 | Debian |