Interfaces used by disk devices
The classical UNIX device interface
- implement bdevsw
- methods
- d_open
- d_close
- d_strategy
- d_ioctl
- d_psize
- d_discard
- constants
- d_flag
- methods
- implement cdevsw
- methods
- d_open
- d_close
- d_read
- d_write
- d_ioctl
- d_mmap
- d_discard
- other methods not used by disk drivers
- d_stop
- d_tty
- d_poll
- d_kqfilter
- constants
- d_flag
- methods
Layering is possible, the dk_lookup function is used to get a handle (a vnode) a child device.
- call each other using vnode layer
- methods VOP_IOCTL VOP_STRATEGY
- dk_lookup to find vnode
- vn_close to release vnode
Disk drivers use the kernel disk interface to provide information for iostat and property lists. There are also helper routines to handle partitions and to get a disklabel.
- kernel disk interface
- kern/subr_disk.c
- driver calls disk_init() to register
- instrumentation (iostat)
- DIOCGDISKINFO
- partition support (bounds_check_..)
- disklabel routines
- low-level routines polluting namespace (disk_read_sectors)
- registers a callback to strategy and minphys functions, currently there are only one user, dk(4) calls the minphys function.
- kern/subr_disk.c
Almost all disk drivers have a regular driver structure that is created by the autoconf framework. An exception is the ccd(4) driver that hand-crafts its private data without autoconf.
- autoconf device building
- kern/subr_autoconf.c
- generic for all device drivers, not only disk drivers
- provides common data including a proplib dictionary
- the dictionary is used to register unit data, for example a drive geometry.
- kern/subr_autoconf.c
The disklabel routines are mostly MD, the sun/sparc routines are not in arch/ but in dev/sun/, the i386/amd64 routines (also used by other archs) are in kern/subr_disk_mbr.c
- disklabel routines
- really MD, implement readdisklabel, writedisklabel, setdisklabel
- kern/subr_disk_mbr.c
- more disklabel routines, MBR, ISO9660
- writedisklabel
- sun/disksubr.c
- like subr_disk_mbr.c but different for sun3/sparc/sparc64
- arch/*/*/disksubr.c
- like subr_disk_mbr.c but different
A wedge is a layered device on top of the RAW_PART of a standard disk device. All disk drivers need to implement ioctls to manually attach wedge devices (using dkctl(8)) and need to call dkwedge_discover to implement autodetect
- wedge routines
- dev/dkwedge/*
- implement dk device
- implement scan routines for various labels (MBR,BSD,GPT)
- IOCTLs to attach dk devices
- scan routines called by each disk driver
The attempt to refactor disk drivers by collecting common functionality. Hardly used, the dk_lookup routine doesn't really belong here (it's more a vnode routine).
- dksubr interface
- dk_lookup helper to find vnodes
- dk_intf switch implements common parts of
- open
- close
- strategy
- size
- ioctl
- dump
- dk_getdisklabel, dk_makedisklabel. fallback routines ?.
- used only by cgd, xbd