1 ==============================
2 Summary of `HDIO_` ioctl calls
3 ==============================
5 - Edward A. Falk <efalk@google.com>
9 This document attempts to describe the ioctl(2) calls supported by
10 the HD/IDE layer. These are by-and-large implemented (as of Linux 2.6)
11 in drivers/ide/ide.c and drivers/block/scsi_ioctl.c
13 ioctl values are listed in <linux/hdreg.h>. As of this writing, they
16 ioctls that pass argument pointers to user space:
18 ======================= =======================================
19 HDIO_GETGEO get device geometry
20 HDIO_GET_UNMASKINTR get current unmask setting
21 HDIO_GET_MULTCOUNT get current IDE blockmode setting
22 HDIO_GET_QDMA get use-qdma flag
23 HDIO_SET_XFER set transfer rate via proc
24 HDIO_OBSOLETE_IDENTITY OBSOLETE, DO NOT USE
25 HDIO_GET_KEEPSETTINGS get keep-settings-on-reset flag
26 HDIO_GET_32BIT get current io_32bit setting
27 HDIO_GET_NOWERR get ignore-write-error flag
28 HDIO_GET_DMA get use-dma flag
29 HDIO_GET_NICE get nice flags
30 HDIO_GET_IDENTITY get IDE identification info
31 HDIO_GET_WCACHE get write cache mode on|off
32 HDIO_GET_ACOUSTIC get acoustic value
33 HDIO_GET_ADDRESS get sector addressing mode
34 HDIO_GET_BUSSTATE get the bus state of the hwif
35 HDIO_TRISTATE_HWIF execute a channel tristate
36 HDIO_DRIVE_RESET execute a device reset
37 HDIO_DRIVE_TASKFILE execute raw taskfile
38 HDIO_DRIVE_TASK execute task and special drive command
39 HDIO_DRIVE_CMD execute a special drive command
40 HDIO_DRIVE_CMD_AEB HDIO_DRIVE_TASK
41 ======================= =======================================
43 ioctls that pass non-pointer values:
45 ======================= =======================================
46 HDIO_SET_MULTCOUNT change IDE blockmode
47 HDIO_SET_UNMASKINTR permit other irqs during I/O
48 HDIO_SET_KEEPSETTINGS keep ioctl settings on reset
49 HDIO_SET_32BIT change io_32bit flags
50 HDIO_SET_NOWERR change ignore-write-error flag
51 HDIO_SET_DMA change use-dma flag
52 HDIO_SET_PIO_MODE reconfig interface to new speed
53 HDIO_SCAN_HWIF register and (re)scan interface
54 HDIO_SET_NICE set nice flags
55 HDIO_UNREGISTER_HWIF unregister interface
56 HDIO_SET_WCACHE change write cache enable-disable
57 HDIO_SET_ACOUSTIC change acoustic behavior
58 HDIO_SET_BUSSTATE set the bus state of the hwif
59 HDIO_SET_QDMA change use-qdma flag
60 HDIO_SET_ADDRESS change lba addressing modes
62 HDIO_SET_IDE_SCSI Set scsi emulation mode on/off
63 HDIO_SET_SCSI_IDE not implemented yet
64 ======================= =======================================
67 The information that follows was determined from reading kernel source
68 code. It is likely that some corrections will be made over time.
70 ------------------------------------------------------------------------------
74 Unless otherwise specified, all ioctl calls return 0 on success
75 and -1 with errno set to an appropriate value on error.
77 Unless otherwise specified, all ioctl calls return -1 and set
78 errno to EFAULT on a failed attempt to copy data to or from user
81 Unless otherwise specified, all data structures and constants
82 are defined in <linux/hdreg.h>
84 ------------------------------------------------------------------------------
92 struct hd_geometry geom;
94 ioctl(fd, HDIO_GETGEO, &geom);
103 hd_geometry structure containing:
106 ========= ==================================
107 heads number of heads
108 sectors number of sectors/track
109 cylinders number of cylinders, mod 65536
110 start starting sector of this partition.
111 ========= ==================================
117 if the device is not a disk drive or floppy drive,
118 or if the user passes a null pointer
122 Not particularly useful with modern disk drives, whose geometry
123 is a polite fiction anyway. Modern drives are addressed
124 purely by sector number nowadays (lba addressing), and the
125 drive geometry is an abstraction which is actually subject
126 to change. Currently (as of Nov 2004), the geometry values
127 are the "bios" values -- presumably the values the drive had
128 when Linux first booted.
130 In addition, the cylinders field of the hd_geometry is an
131 unsigned short, meaning that on most architectures, this
132 ioctl will not return a meaningful value on drives with more
135 The start field is unsigned long, meaning that it will not
136 contain a meaningful value for disks over 219 Gb in size.
142 get current unmask setting
149 ioctl(fd, HDIO_GET_UNMASKINTR, &val);
157 The value of the drive's current unmask setting
164 permit other irqs during I/O
171 ioctl(fd, HDIO_SET_UNMASKINTR, val);
174 New value for unmask flag
184 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
185 - EACCES Access denied: requires CAP_SYS_ADMIN
186 - EINVAL value out of range [0 1]
187 - EBUSY Controller busy
193 get current IDE blockmode setting
200 ioctl(fd, HDIO_GET_MULTCOUNT, &val);
208 The value of the current IDE block mode setting. This
209 controls how many sectors the drive will transfer per
222 ioctl(fd, HDIO_SET_MULTCOUNT, val);
225 New value for IDE block mode setting. This controls how many
226 sectors the drive will transfer per interrupt.
234 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
235 - EACCES Access denied: requires CAP_SYS_ADMIN
236 - EINVAL value out of range supported by disk.
237 - EBUSY Controller busy or blockmode already set.
238 - EIO Drive did not accept new block mode.
241 Source code comments read::
243 This is tightly woven into the driver->do_special cannot
244 touch. DON'T do it again until a total personality rewrite
247 If blockmode has already been set, this ioctl will fail with
256 Not implemented, as of 2.6.8.1
261 set transfer rate via proc
264 Not implemented, as of 2.6.8.1
268 HDIO_OBSOLETE_IDENTITY
272 Same as HDIO_GET_IDENTITY (see below), except that it only
273 returns the first 142 bytes of drive identity information.
278 get IDE identification info
283 unsigned char identity[512];
285 ioctl(fd, HDIO_GET_IDENTITY, identity);
293 ATA drive identity information. For full description, see
294 the IDENTIFY DEVICE and IDENTIFY PACKET DEVICE commands in
295 the ATA specification.
298 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
299 - ENOMSG IDENTIFY DEVICE information not available
302 Returns information that was obtained when the drive was
303 probed. Some of this information is subject to change, and
304 this ioctl does not re-probe the drive to update the
307 This information is also available from /proc/ide/hdX/identify
311 HDIO_GET_KEEPSETTINGS
312 get keep-settings-on-reset flag
319 ioctl(fd, HDIO_GET_KEEPSETTINGS, &val);
327 The value of the current "keep settings" flag
332 When set, indicates that kernel should restore settings
337 HDIO_SET_KEEPSETTINGS
338 keep ioctl settings on reset
345 ioctl(fd, HDIO_SET_KEEPSETTINGS, val);
348 New value for keep_settings flag
358 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
359 - EACCES Access denied: requires CAP_SYS_ADMIN
360 - EINVAL value out of range [0 1]
361 - EBUSY Controller busy
366 get current io_32bit setting
373 ioctl(fd, HDIO_GET_32BIT, &val);
381 The value of the current io_32bit setting
386 0=16-bit, 1=32-bit, 2,3 = 32bit+sync
393 get ignore-write-error flag
400 ioctl(fd, HDIO_GET_NOWERR, &val);
408 The value of the current ignore-write-error flag
422 ioctl(fd, HDIO_GET_DMA, &val);
430 The value of the current use-dma flag
444 ioctl(fd, HDIO_GET_NICE, &nice);
452 The drive's "nice" values.
457 Per-drive flags which determine when the system will give more
458 bandwidth to other devices sharing the same IDE bus.
460 See <linux/hdreg.h>, near symbol IDE_NICE_DSC_OVERLAP.
474 ioctl(fd, HDIO_SET_NICE, nice);
477 bitmask of nice flags.
487 - EACCES Access denied: requires CAP_SYS_ADMIN
488 - EPERM Flags other than DSC_OVERLAP and NICE_1 set.
489 - EPERM DSC_OVERLAP specified but not supported by drive
492 This ioctl sets the DSC_OVERLAP and NICE_1 flags from values
493 provided by the user.
495 Nice flags are listed in <linux/hdreg.h>, starting with
496 IDE_NICE_DSC_OVERLAP. These values represent shifts.
503 get write cache mode on|off
510 ioctl(fd, HDIO_GET_WCACHE, &val);
518 The value of the current write cache mode
532 ioctl(fd, HDIO_GET_ACOUSTIC, &val);
540 The value of the current acoustic settings
545 See HDIO_SET_ACOUSTIC
557 ioctl(fd, HDIO_GET_ADDRESS, &val);
565 The value of the current addressing mode:
567 = ===================
570 2 48-bit doing 28-bit
572 = ===================
577 get the bus state of the hwif
584 ioctl(fd, HDIO_SCAN_HWIF, &state);
592 Current power state of the IDE bus. One of BUSSTATE_OFF,
593 BUSSTATE_ON, or BUSSTATE_TRISTATE
596 - EACCES Access denied: requires CAP_SYS_ADMIN
602 set the bus state of the hwif
610 ioctl(fd, HDIO_SCAN_HWIF, state);
613 Desired IDE power state. One of BUSSTATE_OFF, BUSSTATE_ON,
622 - EACCES Access denied: requires CAP_SYS_RAWIO
623 - EOPNOTSUPP Hardware interface does not support bus power control
629 execute a channel tristate
632 Not implemented, as of 2.6.8.1. See HDIO_SET_BUSSTATE
637 execute a device reset
645 ioctl(fd, HDIO_DRIVE_RESET, args);
658 - EACCES Access denied: requires CAP_SYS_ADMIN
659 - ENXIO No such device: phy dead or ctl_addr == 0
660 - EIO I/O error: reset timed out or hardware error
664 - Execute a reset on the device as soon as the current IO
665 operation has completed.
667 - Executes an ATAPI soft reset if applicable, otherwise
668 executes an ATA soft reset on the controller.
677 If you don't have a copy of the ANSI ATA specification
678 handy, you should probably ignore this ioctl.
680 - Execute an ATA disk command directly by writing the "taskfile"
681 registers of the drive. Requires ADMIN and RAWIO access
688 ide_task_request_t req_task;
689 u8 outbuf[OUTPUT_SIZE];
690 u8 inbuf[INPUT_SIZE];
692 memset(&task.req_task, 0, sizeof(task.req_task));
693 task.req_task.out_size = sizeof(task.outbuf);
694 task.req_task.in_size = sizeof(task.inbuf);
696 ioctl(fd, HDIO_DRIVE_TASKFILE, &task);
701 (See below for details on memory area passed to ioctl.)
703 ============ ===================================================
704 io_ports[8] values to be written to taskfile registers
705 hob_ports[8] high-order bytes, for extended commands.
706 out_flags flags indicating which registers are valid
707 in_flags flags indicating which registers should be returned
709 req_cmd command type to be executed
710 out_size size of output buffer
711 outbuf buffer of data to be transmitted to disk
712 inbuf buffer of data to be received from disk (see [1])
713 ============ ===================================================
717 =========== ====================================================
718 io_ports[] values returned in the taskfile registers
719 hob_ports[] high-order bytes, for extended commands.
720 out_flags flags indicating which registers are valid (see [2])
721 in_flags flags indicating which registers should be returned
722 outbuf buffer of data to be transmitted to disk (see [1])
723 inbuf buffer of data to be received from disk
724 =========== ====================================================
727 - EACCES CAP_SYS_ADMIN or CAP_SYS_RAWIO privilege not set.
728 - ENOMSG Device is not a disk drive.
729 - ENOMEM Unable to allocate memory for task
730 - EFAULT req_cmd == TASKFILE_IN_OUT (not implemented as of 2.6.8)
733 req_cmd == TASKFILE_MULTI_OUT and drive
734 multi-count not yet set.
735 - EIO Drive failed the command.
739 [1] READ THE FOLLOWING NOTES *CAREFULLY*. THIS IOCTL IS
740 FULL OF GOTCHAS. Extreme caution should be used with using
741 this ioctl. A mistake can easily corrupt data or hang the
744 [2] Both the input and output buffers are copied from the
745 user and written back to the user, even when not used.
747 [3] If one or more bits are set in out_flags and in_flags is
748 zero, the following values are used for in_flags.all and
749 written back into in_flags on completion.
751 * IDE_TASKFILE_STD_IN_FLAGS | (IDE_HOB_STD_IN_FLAGS << 8)
752 if LBA48 addressing is enabled for the drive
753 * IDE_TASKFILE_STD_IN_FLAGS
756 The association between in_flags.all and each enable
757 bitfield flips depending on endianness; fortunately, TASKFILE
758 only uses inflags.b.data bit and ignores all other bits.
759 The end result is that, on any endian machines, it has no
760 effect other than modifying in_flags on completion.
762 [4] The default value of SELECT is (0xa0|DEV_bit|LBA_bit)
763 except for four drives per port chipsets. For four drives
764 per port chipsets, it's (0xa0|DEV_bit|LBA_bit) for the first
765 pair and (0x80|DEV_bit|LBA_bit) for the second pair.
767 [5] The argument to the ioctl is a pointer to a region of
768 memory containing a ide_task_request_t structure, followed
769 by an optional buffer of data to be transmitted to the
770 drive, followed by an optional buffer to receive data from
773 Command is passed to the disk drive via the ide_task_request_t
774 structure, which contains these fields:
776 ============ ===============================================
777 io_ports[8] values for the taskfile registers
778 hob_ports[8] high-order bytes, for extended commands
779 out_flags flags indicating which entries in the
780 io_ports[] and hob_ports[] arrays
781 contain valid values. Type ide_reg_valid_t.
782 in_flags flags indicating which entries in the
783 io_ports[] and hob_ports[] arrays
784 are expected to contain valid values
787 req_cmd Command type, see below
788 out_size output (user->drive) buffer size, bytes
789 in_size input (drive->user) buffer size, bytes
790 ============ ===============================================
792 When out_flags is zero, the following registers are loaded.
794 ============ ===============================================
795 HOB_FEATURE If the drive supports LBA48
796 HOB_NSECTOR If the drive supports LBA48
797 HOB_SECTOR If the drive supports LBA48
798 HOB_LCYL If the drive supports LBA48
799 HOB_HCYL If the drive supports LBA48
805 SELECT First, masked with 0xE0 if LBA48, 0xEF
806 otherwise; then, or'ed with the default
808 ============ ===============================================
810 If any bit in out_flags is set, the following registers are loaded.
812 ============ ===============================================
813 HOB_DATA If out_flags.b.data is set. HOB_DATA will
814 travel on DD8-DD15 on little endian machines
815 and on DD0-DD7 on big endian machines.
816 DATA If out_flags.b.data is set. DATA will
817 travel on DD0-DD7 on little endian machines
818 and on DD8-DD15 on big endian machines.
819 HOB_NSECTOR If out_flags.b.nsector_hob is set
820 HOB_SECTOR If out_flags.b.sector_hob is set
821 HOB_LCYL If out_flags.b.lcyl_hob is set
822 HOB_HCYL If out_flags.b.hcyl_hob is set
823 FEATURE If out_flags.b.feature is set
824 NSECTOR If out_flags.b.nsector is set
825 SECTOR If out_flags.b.sector is set
826 LCYL If out_flags.b.lcyl is set
827 HCYL If out_flags.b.hcyl is set
828 SELECT Or'ed with the default value of SELECT and
829 loaded regardless of out_flags.b.select.
830 ============ ===============================================
832 Taskfile registers are read back from the drive into
833 {io|hob}_ports[] after the command completes iff one of the
834 following conditions is met; otherwise, the original values
835 will be written back, unchanged.
837 1. The drive fails the command (EIO).
838 2. One or more than one bits are set in out_flags.
839 3. The requested data_phase is TASKFILE_NO_DATA.
841 ============ ===============================================
842 HOB_DATA If in_flags.b.data is set. It will contain
843 DD8-DD15 on little endian machines and
844 DD0-DD7 on big endian machines.
845 DATA If in_flags.b.data is set. It will contain
846 DD0-DD7 on little endian machines and
847 DD8-DD15 on big endian machines.
848 HOB_FEATURE If the drive supports LBA48
849 HOB_NSECTOR If the drive supports LBA48
850 HOB_SECTOR If the drive supports LBA48
851 HOB_LCYL If the drive supports LBA48
852 HOB_HCYL If the drive supports LBA48
857 ============ ===============================================
859 The data_phase field describes the data transfer to be
860 performed. Value is one of:
862 =================== ========================================
869 TASKFILE_IN_DMAQ == IN_DMA (queueing not supported)
871 TASKFILE_OUT_DMAQ == OUT_DMA (queueing not supported)
872 TASKFILE_P_IN unimplemented
873 TASKFILE_P_IN_DMA unimplemented
874 TASKFILE_P_IN_DMAQ unimplemented
875 TASKFILE_P_OUT unimplemented
876 TASKFILE_P_OUT_DMA unimplemented
877 TASKFILE_P_OUT_DMAQ unimplemented
878 =================== ========================================
880 The req_cmd field classifies the command type. It may be
883 ======================== =======================================
884 IDE_DRIVE_TASK_NO_DATA
885 IDE_DRIVE_TASK_SET_XFER unimplemented
887 IDE_DRIVE_TASK_OUT unimplemented
888 IDE_DRIVE_TASK_RAW_WRITE
889 ======================== =======================================
891 [6] Do not access {in|out}_flags->all except for resetting
892 all the bits. Always access individual bit fields. ->all
893 value will flip depending on endianness. For the same
894 reason, do not use IDE_{TASKFILE|HOB}_STD_{OUT|IN}_FLAGS
895 constants defined in hdreg.h.
900 execute a special drive command
903 Note: If you don't have a copy of the ANSI ATA specification
904 handy, you should probably ignore this ioctl.
908 u8 args[4+XFER_SIZE];
911 ioctl(fd, HDIO_DRIVE_CMD, args);
914 Commands other than WIN_SMART:
933 args[] buffer is filled with register values followed by any
936 data returned by the disk.
938 ======== ====================================================
943 args[4+] NSECTOR * 512 bytes of data returned by the command.
944 ======== ====================================================
947 - EACCES Access denied: requires CAP_SYS_RAWIO
948 - ENOMEM Unable to allocate memory for task
949 - EIO Drive reports error
953 [1] For commands other than WIN_SMART, args[1] should equal
954 args[3]. SECTOR, LCYL and HCYL are undefined. For
955 WIN_SMART, 0x4f and 0xc2 are loaded into LCYL and HCYL
956 respectively. In both cases SELECT will contain the default
957 value for the drive. Please refer to HDIO_DRIVE_TASKFILE
958 notes for the default value of SELECT.
960 [2] If NSECTOR value is greater than zero and the drive sets
961 DRQ when interrupting for the command, NSECTOR * 512 bytes
962 are read from the device into the area following NSECTOR.
963 In the above example, the area would be
964 args[4..4+XFER_SIZE]. 16bit PIO is used regardless of
965 HDIO_SET_32BIT setting.
967 [3] If COMMAND == WIN_SETFEATURES && FEATURE == SETFEATURES_XFER
968 && NSECTOR >= XFER_SW_DMA_0 && the drive supports any DMA
969 mode, IDE driver will try to tune the transfer mode of the
975 execute task and special drive command
978 Note: If you don't have a copy of the ANSI ATA specification
979 handy, you should probably ignore this ioctl.
986 ioctl(fd, HDIO_DRIVE_TASK, args);
989 Taskfile register values:
1002 Taskfile register values:
1016 - EACCES Access denied: requires CAP_SYS_RAWIO
1017 - ENOMEM Unable to allocate memory for task
1018 - ENOMSG Device is not a disk drive.
1019 - EIO Drive failed the command.
1023 [1] DEV bit (0x10) of SELECT register is ignored and the
1024 appropriate value for the drive is used. All other bits
1033 Not implemented, as of 2.6.8.1
1038 change io_32bit flags
1045 ioctl(fd, HDIO_SET_32BIT, val);
1048 New value for io_32bit flag
1058 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1059 - EACCES Access denied: requires CAP_SYS_ADMIN
1060 - EINVAL value out of range [0 3]
1061 - EBUSY Controller busy
1067 change ignore-write-error flag
1074 ioctl(fd, HDIO_SET_NOWERR, val);
1077 New value for ignore-write-error flag. Used for ignoring
1088 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1089 - EACCES Access denied: requires CAP_SYS_ADMIN
1090 - EINVAL value out of range [0 1]
1091 - EBUSY Controller busy
1103 ioctl(fd, HDIO_SET_DMA, val);
1106 New value for use-dma flag
1116 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1117 - EACCES Access denied: requires CAP_SYS_ADMIN
1118 - EINVAL value out of range [0 1]
1119 - EBUSY Controller busy
1124 reconfig interface to new speed
1131 ioctl(fd, HDIO_SET_PIO_MODE, val);
1134 New interface speed.
1144 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1145 - EACCES Access denied: requires CAP_SYS_ADMIN
1146 - EINVAL value out of range [0 255]
1147 - EBUSY Controller busy
1152 register and (re)scan interface
1160 ioctl(fd, HDIO_SCAN_HWIF, args);
1164 ======= =========================
1165 args[0] io address to probe
1168 args[1] control address to probe
1170 ======= =========================
1178 - EACCES Access denied: requires CAP_SYS_RAWIO
1182 This ioctl initializes the addresses and irq for a disk
1183 controller, probes for drives, and creates /proc/ide
1184 interfaces as appropriate.
1188 HDIO_UNREGISTER_HWIF
1189 unregister interface
1196 ioctl(fd, HDIO_UNREGISTER_HWIF, index);
1199 index index of hardware interface to unregister
1209 - EACCES Access denied: requires CAP_SYS_RAWIO
1212 This ioctl removes a hardware interface from the kernel.
1214 Currently (2.6.8) this ioctl silently fails if any drive on
1215 the interface is busy.
1220 change write cache enable-disable
1227 ioctl(fd, HDIO_SET_WCACHE, val);
1230 New value for write cache enable
1240 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1241 - EACCES Access denied: requires CAP_SYS_ADMIN
1242 - EINVAL value out of range [0 1]
1243 - EBUSY Controller busy
1248 change acoustic behavior
1255 ioctl(fd, HDIO_SET_ACOUSTIC, val);
1258 New value for drive acoustic settings
1268 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1269 - EACCES Access denied: requires CAP_SYS_ADMIN
1270 - EINVAL value out of range [0 254]
1271 - EBUSY Controller busy
1276 change use-qdma flag
1279 Not implemented, as of 2.6.8.1
1284 change lba addressing modes
1291 ioctl(fd, HDIO_SET_ADDRESS, val);
1294 New value for addressing mode
1296 = ===================
1299 2 48-bit doing 28-bit
1300 = ===================
1308 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1309 - EACCES Access denied: requires CAP_SYS_ADMIN
1310 - EINVAL value out of range [0 2]
1311 - EBUSY Controller busy
1312 - EIO Drive does not support lba48 mode.
1321 ioctl(fd, HDIO_SET_IDE_SCSI, val);
1324 New value for scsi emulation mode (?)
1334 - EINVAL (bdev != bdev->bd_contains) (not sure what this means)
1335 - EACCES Access denied: requires CAP_SYS_ADMIN
1336 - EINVAL value out of range [0 1]
1337 - EBUSY Controller busy
1342 Not implemented, as of 2.6.8.1