1.\" 2.\" Copyright (c) 1994 Wilko Bulte 3.\" Copyright (c) 2001 Joerg Wunsch 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. The name of the author may not be used to endorse or promote products 15.\" derived from this software without specific prior written permission 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27.\" 28.Dd November 16, 2025 29.Dt FDC 4 30.Os 31.Sh NAME 32.Nm fdc 33.Nd "PC architecture floppy disk controller driver" 34.Sh SYNOPSIS 35.Cd device fdc 36.Pp 37In 38.Pa /boot/device.hints : 39.Cd hint.fdc.0.at="isa" 40.Cd hint.fdc.0.port="0x3F0" 41.Cd hint.fdc.0.irq="6" 42.Cd hint.fdc.0.drq="2" 43.Cd hint.fdc.0.flags="0x0" 44.Cd hint.fd.0.at="fdc0" 45.Cd hint.fd.0.drive="0" 46.Cd hint.fd.0.flags="0x0" 47.Cd hint.fd.1.at="fdc0" 48.Cd hint.fd.1.drive="1" 49.Cd hint.fd.1.flags="0x0" 50.Sh DEPRECATION NOTICE 51The 52.Nm 53driver is deprecated and may not be present in 54.Fx 16.0 55and later. 56.Sh DESCRIPTION 57.Ss Device Usage 58This driver provides access to floppy disk drives. 59Floppy disks using 60either FM (single-density) or MFM (double or high-density) recording 61can be handled. 62.Pp 63Floppy disk controllers can connect up to four drives each. 64The 65.Nm 66driver can currently handle up to two drives per controller (or four 67drives on ACPI). 68Upon 69driver initialization, an attempt is made to find out the type of the 70floppy controller in use. 71The known controller types are either the 72original NE765 or i8272 chips, or alternatively 73.Em enhanced 74controllers that are compatible with the NE72065 or i82077 chips. 75These enhanced controllers (among other enhancements) implement a FIFO 76for floppy data transfers that will automatically be enabled once an 77enhanced chip has been detected. 78This FIFO activation can be disabled 79using the per-controller flags value of 80.Ar 0x1 . 81.Pp 82By default, this driver creates a single device node 83.Pa /dev/fd Ns Ar N 84for each attached drive with number 85.Ar N . 86For historical reasons, device nodes that use a trailing UFS-style 87partition letter (ranging from 88.Sq a 89through 90.Sq h ) 91can also be accessed, which will be implemented as symbolic links to 92the main device node. 93.Pp 94Accessing the main device node will attempt to autodetect the density 95of the available medium for multi-density devices. 96Thus it is 97possible to use either a 720 KB medium or a 1440 KB medium in a 98high-density 3.5 inch standard floppy drive. 99Normally, this 100autodetection will only happen once at the first call to 101.Xr open 2 102for the device after inserting the medium. 103This assumes the drive 104offers proper changeline support so media changes can be detected by 105the driver. 106To indicate a drive that does not have the changeline support, 107this can be overridden using the per-drive device flags value of 108.Ar 0x10 109(causing each call to 110.Xr open 2 111to perform the autodetection). 112.Pp 113When trying to use a floppy device with special-density media, other 114device nodes can be created, of the form 115.Pa /dev/fd Ns Ar N . Ns Ar MMMM , 116where 117.Ar N 118is the drive number, and 119.Ar MMMM 120is a number between one and four digits describing the device density. 121Up to 15 additional subdevices per drive can be created that way. 122The 123administrator is free to decide on a policy how to assign these 124numbers. 125The two common policies are to either implement subdevices 126numbered 1 through 15, or to use a number that describes the medium 127density in kilobytes. 128Initially, each of those devices will be 129configured to the maximal density that is possible for the drive type 130(like 1200 KB for 5.25 inch HD drives or 1440 KB for 3.5 inch HD 131drives). 132The desired density to be used on that subdevice needs to be 133configured using 134.Xr fdcontrol 8 . 135.Pp 136Drive types are configured using the lower four bits of the per-drive 137device flags. 138The following values can be specified: 139.Bl -tag -width 2n -offset indent 140.It Ar 1 1415.25 inch double-density device with 40 cylinders (360 KB native 142capacity) 143.It Ar 2 1445.25 inch high-density device with 80 cylinders (1200 KB native 145capacity) 146.It Ar 3 1473.5 inch double-density device with 80 cylinders (720 KB native 148capacity) 149.It Ar 4 1503.5 inch high-density device with 80 cylinders (1440 KB native 151capacity) 152.It Ar 5 1533.5 inch extra-density device with 80 cylinders (2880 KB native 154capacity, usage currently restricted to at most 1440 KB media) 155.It Ar 6 156Same as type 5, available for compatibility with some BIOSes 157.El 158.Pp 159On IA32 architectures, the drive type can be specified as 0 for the 160drives. 161In that case, the CMOS configuration memory will be 162consulted to obtain the value for that drive. 163The ACPI probe automatically determines these values via the _FDE and 164_FDI methods, but this can be overridden by specifying a drive type hint. 165.Pp 166Normally, each configured drive will be probed at initialization 167time, using a short seek sequence. 168This is intended to find out about 169drives that have been configured but are actually missing or 170otherwise not responding. 171(The ACPI probe method does not perform this seek.) 172In some environments (like laptops with 173detachable drives), it might be desirable to bypass this drive probe, 174and pretend a drive to be there so the driver autoconfiguration will 175work even if the drive is currently not present. 176For that purpose, a 177per-drive device flags value of 178.Ar 0x20 179needs to be specified. 180.Ss Programming Interface 181In addition to the normal read and write functionality, the 182.Nm 183driver offers a number of configurable options using 184.Xr ioctl 2 . 185In order to access any of this functionality, programmers need to 186include the header file 187.In sys/fdcio.h 188into their programs. 189The call to 190.Xr open 2 191can be performed in two possible ways. 192When opening the device 193without the 194.Dv O_NONBLOCK 195flag set, the device is opened in a normal way, which would cause the 196main device nodes to perform automatic media density selection, and which 197will yield a file descriptor that is fully available for any I/O operation 198or any of the following 199.Xr ioctl 2 200commands. 201.Pp 202When opening the device with 203.Dv O_NONBLOCK 204set, automatic media density selection will be bypassed, and the device 205remains in a half-opened state. 206No actual I/O operations are possible, but 207many of the 208.Xr ioctl 2 209commands described below can be performed. 210This mode is intended for 211access to the device without the requirement to have an accessible 212media present, like for status inquiries to the drive, or in order to 213format a medium. 214.Dv O_NONBLOCK 215needs to be cleared before I/O operations are possible on the descriptor, 216which requires a prior specification of the density using the 217.Dv FD_STYPE 218command (see below). 219Operations that are not allowed on the half-opened 220descriptor will cause an error value of 221.Er EAGAIN . 222.Pp 223The following 224.Xr ioctl 2 225commands are currently available: 226.Bl -tag -width ".Dv FD_READID" 227.It Dv FD_FORM 228Used to format a floppy disk medium. 229Third argument is a pointer to a 230.Vt "struct fd_formb" 231specifying which track to format, and which parameters to fill into 232the ID fields of the floppy disk medium. 233.It Dv FD_GTYPE 234Returns the current density definition record for the selected device. 235Third argument is a pointer to 236.Vt "struct fd_type" . 237.It Dv FD_STYPE 238Adjusts the density definition of the selected device. 239Third argument 240is a pointer to 241.Vt "struct fd_type" . 242For the fixed-density subdevices (1 through 15 per drive), this 243operation is restricted to a process with superuser privileges. 244For 245the auto-selecting subdevice 0, the operation is temporarily allowed 246to any process, but this setting will be lost again upon the next 247autoselection. 248This can be used when formatting a new medium (which 249will require to open the device using 250.Dv O_NONBLOCK , 251and thus to later adjust the density using 252.Dv FD_STYPE ) . 253.It Dv FD_GOPTS 254Obtain the current drive options. 255Third argument is a pointer to 256.Vt int , 257containing a bitwise union of the following possible flag values: 258.Bl -tag -width ".Dv FDOPT_NOERRLOG" 259.It Dv FDOPT_NORETRY 260Do not automatically retry operations upon failure. 261.It Dv FDOPT_NOERRLOG 262Do not cause 263.Dq "hard error" 264kernel logs for failed I/O operations. 265.It Dv FDOPT_NOERROR 266Do not indicate I/O errors when returning from 267.Xr read 2 268or 269.Xr write 2 270system calls. 271The caller is assumed to use 272.Dv FD_GSTAT 273calls in order to inquire about the success of each operation. 274This 275is intended to allow even erroneous data from bad blocks to be 276retrieved using normal I/O operations. 277.It Dv FDOPT_AUTOSEL 278Device performs automatic density selection. 279Unlike the above flags, 280this one is read-only. 281.El 282.It Dv FD_SOPTS 283Set device options, see above for their meaning. 284Third argument is a 285pointer to 286.Vt int . 287Drive options will always be cleared when closing the descriptor. 288.It Dv FD_CLRERR 289Clear the internal low-level error counter. 290Normally, controller-level 291I/O errors are only logged up to 292.Dv FDC_ERRMAX 293errors (currently defined to 100). 294This command resets the counter. 295Requires superuser privileges. 296.It Dv FD_READID 297Read one sector ID field from the floppy disk medium. 298Third argument is 299a pointer to 300.Vt "struct fdc_readid" , 301where the read data will be returned. 302Can be used to analyze a floppy 303disk medium. 304.It Dv FD_GSTAT 305Return the recent floppy disk controller status, if available. 306Third 307argument is a pointer to 308.Vt "struct fdc_status" , 309where the status registers (ST0, ST1, ST2, C, H, R, and N) are being 310returned. 311.Er EINVAL 312will be caused if no recent status is available. 313.It Dv FD_GDTYPE 314Returns the floppy disk drive type. 315Third argument is a pointer to 316.Vt "enum fd_drivetype" . 317This type is the same as being used in the per-drive configuration 318flags, or in the CMOS configuration data or ACPI namespace on IA32 systems. 319.El 320.Sh SYSCTL VARIABLES 321.Bl -tag -width "debug.fdc.debugflags" 322.It Dv debug.fdc.debugflags 323Selectively enable debugging by setting one or more flags. 324.Bl -tag -width "0x40" 325.It Dv 0x01 326Dump device registers on reset. 327.It Dv 0x02 328When an IO operation completes, print the number of retries 329when that number is greater than zero. 330.It Dv 0x04 331Print when the number of retries exceeds 332.Dv debug.fdc.retries 333.Pq Dv EIO . 334Print when the option 335.Dv FDOPT_NOERROR 336is set and an error would have returned from a write operation. 337.It Dv 0x08 338Print detailed IO command information. 339.It Dv 0x10 340Print status registers. 341.It Dv 0x20 342Print detailed status registers when interrupts complete. 343Print the source code line number close to the source of a 344non-zero return from a thread worker operation. 345.It Dv 0x40 346Print when the disk appears to be lost. 347Print cylinder, head, sector, and sector shift information 348after a request to read an ID field. 349Notify whether a disk probe resulted in finding a disk. 350When detecting the density of media present, indicate whether 351the autosensing was successful, and if so, the size of the 352medium in kilobytes. 353Print detailed type information when setting the drive type. 354.It Dv 0x80 355Print when an unknown IOCTL is used. 356.El 357.It Dv debug.fdc.fifo 358For enhanced controllers, allows a non-default FIFO 359threshold setting. 360The default is 8 bytes. 361.It Dv debug.fdc.retries 362Maximum number of retries to attempt. 363The default is 10. 364.It Dv debug.fdc.spec1 365Specification byte one (step-rate + head unload). 366The default step rate is 6 ms. 367The default head unload time is 240 ms. 368.It Dv debug.fdc.spec2 369Specification byte two (head load time + no-dma). 370The default head load time is 16 ms, and no-dma is 0 371.Pq disabled . 372.It Dv debug.fdc.settle 373Head settling time in 374.Sy settle 375/ hz seconds. The default value is set during device attach. 376.El 377.Sh FILES 378.Bl -tag -width ".Pa /dev/fd*" -compact 379.It Pa /dev/fd* 380floppy disk device nodes 381.El 382.Sh SEE ALSO 383.Xr fdread 1 , 384.Xr fdwrite 1 , 385.Xr ioctl 2 , 386.Xr open 2 , 387.Xr read 2 , 388.Xr write 2 , 389.Xr fdcontrol 8 , 390.Xr fdformat 8 391.Sh AUTHORS 392.An -nosplit 393This man page was initially written by 394.An Wilko Bulte , 395and later vastly rewritten by 396.An J\(:org Wunsch . 397