^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Hard disk shock protection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Author: Elias Oltmanns <eo@nebensachen.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Last modified: 2008-10-03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) .. 0. Contents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 1. Intro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 2. The interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 3. References
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 4. CREDITS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 1. Intro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) Issuing this command should cause the drive to switch to idle mode and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unload disk heads. This feature is being used in modern laptops in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) conjunction with accelerometers and appropriate software to implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) a shock protection facility. The idea is to stop all I/O operations on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) the internal hard drive and park its heads on the ramp when critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) situations are anticipated. The desire to have such a feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) available on GNU/Linux systems has been the original motivation to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) implement a generic disk head parking interface in the Linux kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Please note, however, that other components have to be set up on your
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) system in order to get disk shock protection working (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) section 3. References below for pointers to more information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) that).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 2. The interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) For each ATA device, the kernel exports the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) `block/*/device/unload_heads` in sysfs (here assumed to be mounted under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /sys). Access to `/sys/block/*/device/unload_heads` is denied with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) -EOPNOTSUPP if the device does not support the unload feature.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Otherwise, writing an integer value to this file will take the heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) of the respective drive off the platter and block all I/O operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) for the specified number of milliseconds. When the timeout expires and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) no further disk head park request has been issued in the meantime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) normal operation will be resumed. The maximal value accepted for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) timeout is 30000 milliseconds. Exceeding this limit will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) -EOVERFLOW, but heads will be parked anyway and the timeout will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) set to 30 seconds. However, you can always change a timeout to any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) value between 0 and 30000 by issuing a subsequent head park request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) before the timeout of the previous one has expired. In particular, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) total timeout can exceed 30 seconds and, more importantly, you can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) cancel a previously set timeout and resume normal operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) immediately by specifying a timeout of 0. Values below -2 are rejected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) with -EINVAL (see below for the special meaning of -1 and -2). If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) timeout specified for a recent head park request has not yet expired,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) reading from `/sys/block/*/device/unload_heads` will report the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) of milliseconds remaining until normal operation will be resumed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) otherwise, reading the unload_heads attribute will return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) For example, do the following in order to park the heads of drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /dev/sda and stop all I/O operations for five seconds::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) # echo 5000 > /sys/block/sda/device/unload_heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) A simple::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) # cat /sys/block/sda/device/unload_heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) will show you how many milliseconds are left before normal operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) will be resumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) A word of caution: The fact that the interface operates on a basis of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) milliseconds may raise expectations that cannot be satisfied in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) reality. In fact, the ATA specs clearly state that the time for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unload operation to complete is vendor specific. The hint in ATA-7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) that this will typically be within 500 milliseconds apparently has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) been dropped in ATA-8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) There is a technical detail of this implementation that may cause some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) confusion and should be discussed here. When a head park request has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) been issued to a device successfully, all I/O operations on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) controller port this device is attached to will be deferred. That is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) to say, any other device that may be connected to the same port will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) be affected too. The only exception is that a subsequent head unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) request to that other device will be executed immediately. Further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) operations on that port will be deferred until the timeout specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) for either device on the port has expired. As far as PATA (old style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) IDE) configurations are concerned, there can only be two devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) attached to any single port. In SATA world we have port multipliers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) which means that a user-issued head parking request to one device may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) actually result in stopping I/O to a whole bunch of devices. However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) since this feature is supposed to be used on laptops and does not seem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) to be very useful in any other environment, there will be mostly one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) device per port. Even if the CD/DVD writer happens to be connected to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) the same port as the hard drive, it generally *should* recover just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) fine from the occasional buffer under-run incurred by a head park
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) request to the HD. Actually, when you are using an ide driver rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) than its libata counterpart (i.e. your disk is called /dev/hda
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) instead of /dev/sda), then parking the heads of one drive (drive X)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) will generally not affect the mode of operation of another drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) (drive Y) on the same port as described above. It is only when a port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) reset is required to recover from an exception on drive Y that further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) I/O operations on that drive (and the reset itself) will be delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) until drive X is no longer in the parked state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) Finally, there are some hard drives that only comply with an earlier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) version of the ATA standard than ATA-7, but do support the unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) feature nonetheless. Unfortunately, there is no safe way Linux can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) detect these devices, so you won't be able to write to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unload_heads attribute. If you know that your device really does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) support the unload feature (for instance, because the vendor of your
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) laptop or the hard drive itself told you so), then you can tell the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) kernel to enable the usage of this feature for that drive by writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) the special value -1 to the unload_heads attribute::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) # echo -1 > /sys/block/sda/device/unload_heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) will enable the feature for /dev/sda, and giving -2 instead of -1 will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) disable it again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 3. References
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) -------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) There are several laptops from different vendors featuring shock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) protection capabilities. As manufacturers have refused to support open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) source development of the required software components so far, Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) support for shock protection varies considerably between different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) hardware implementations. Ideally, this section should contain a list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) of pointers at different projects aiming at an implementation of shock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) protection on different systems. Unfortunately, I only know of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) single project which, although still considered experimental, is fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) for use. Please feel free to add projects that have been the victims
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) of my ignorance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) - https://www.thinkwiki.org/wiki/HDAPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) See this page for information about Linux support of the hard disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) active protection system as implemented in IBM/Lenovo Thinkpads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 4. CREDITS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) This implementation of disk head parking has been inspired by a patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) originally published by Jon Escombe <lists@dresco.co.uk>. My efforts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) to develop an implementation of this feature that is fit to be merged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) into mainline have been aided by various kernel developers, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) particular by Tejun Heo and Bartlomiej Zolnierkiewicz.