smartmontools SVN Rev 3317
Utility to control and monitor storage systems with "S.M.A.R.T."
ataidentify.cpp
Go to the documentation of this file.
00001 /*
00002  * ataidentify.cpp
00003  *
00004  * Home page of code is: http://smartmontools.sourceforge.net
00005  *
00006  * Copyright (C) 2012-13 Christian Franke <smartmontools-support@lists.sourceforge.net>
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  */
00017 
00018 #include "config.h"
00019 #include "ataidentify.h"
00020 
00021 const char * ataidentify_cpp_cvsid = "$Id: ataidentify.cpp 3851 2013-08-17 20:10:11Z chrfranke $"
00022   ATAIDENTIFY_H_CVSID;
00023 
00024 #include "int64.h"
00025 #include "utility.h"
00026 
00027 
00028 // Table 12 of X3T10/0948D (ATA-2) Revision 4c, March 18, 1996
00029 // Table 9 of X3T13/2008D (ATA-3) Revision 7b, January 27, 1997
00030 // Tables 11 and 13 of T13/1153D (ATA/ATAPI-4) revision 18, August 19, 1998
00031 // Tables 20 and 22 of T13/1321D (ATA/ATAPI-5) Revision 3, February 29, 2000
00032 // Tables 27 and 29 of T13/1410D (ATA/ATAPI-6) Revision 3b, February 26, 2002
00033 // Tables 16 and 18 of T13/1532D (ATA/ATAPI-7) Volume 1 Revision 4b, April 21, 2004
00034 // Tables 29 and 39 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
00035 // Tables 50 and 61 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
00036 // Tables 51 and 56 of T13/2161-D (ACS-3) Revision 4g, February 27, 2013
00037 
00038 const char * const identify_descriptions[] = {
00039   "  0 General configuration",
00040     ". 15 Device identifier: 0 = ATA, 1 = ATAPI",
00041     ". 14:8 ATA: Vendor specific [RET-3]",
00042     ". 14 ATAPI: Must be set to 0",
00043     ". 13 ATAPI: Reserved",
00044     ". 12:8 ATAPI: Command set: 0x05 = CD/DVD",
00045     ". 7 Removable media device",
00046     ". 6 ATA: Not removable controller and/or device [OBS-6]",
00047     ". 5:3 ATA: Vendor specific [RET-3]",
00048     ". 6:5 ATAPI: DRQ after PACKET cmd: 0x0 = 3ms, 0x2 = 50us",
00049     ". 4:3 ATAPI: Reserved",
00050     ". 2 Response incomplete",
00051     ". 1 ATA: Vendor specific [RET-3]",
00052     ". 0 ATA: Reserved",
00053     ". 1:0 ATAPI: Packet size: 0x0 = 12 byte, 0x1 = 16 byte",
00054 
00055   "  1 Cylinders [OBS-6]",
00056   "  2 Specific configuration (0x37c8/738c/8c73/c837)",
00057   "  3 Heads [OBS-6]",
00058   "  4 Vendor specific [RET-3]",
00059   "  5 Vendor specific [RET-3]",
00060   "  6 Sectors per track [OBS-6]",
00061   "  7-8 Reserved for CFA (Sectors per card)",
00062   "  9 Vendor specific [RET-4]",
00063   " 10-19 Serial number (String)",
00064   " 20 Vendor specific [RET-3]",
00065   " 21 Vendor specific [RET-3]",
00066   " 22 Vendor specific bytes on READ/WRITE LONG [OBS-4]",
00067   " 23-26 Firmware revision (String)",
00068   " 27-46 Model number (String)",
00069 
00070   " 47 READ/WRITE MULTIPLE support",
00071     ". 15:8 Must be set to 0x80",
00072     ". 7:0 Maximum sectors per DRQ on READ/WRITE MULTIPLE",
00073 
00074   " 48 Trusted Computing feature set options",
00075     ". 15:14 Must be set to 0x1",
00076     ". 13:1 Reserved for the Trusted Computing Group",
00077     ". 0 Trusted Computing feature set supported",
00078 
00079   " 49 Capabilities",
00080     ". 15:14 ATA: Reserved for IDENTIFY PACKET DEVICE",
00081     ". 15 ATAPI: Interleaved DMA supported [OBS-8]",
00082     ". 14 ATAPI: Command queuing supported [OBS-8]",
00083     ". 13 ATA: Standard standby timer values supported",
00084     ". 13 ATAPI: Overlap operation supported [OBS-8]",
00085     ". 12 ATA: Reserved for IDENTIFY PACKET DEVICE",
00086     ". 12 ATAPI: ATA software reset required [OBS-5]",
00087     ". 11 IORDY supported",
00088     ". 10 IORDY may be disabled",
00089     ". 9 LBA supported",
00090     ". 8 DMA supported",
00091     ". 7:0 Vendor specific [RET-4]",
00092 
00093   " 50 Capabilities",
00094     ". 15:14 Must be set to 0x1",
00095     ". 13:2 Reserved",
00096     ". 1 Reserved [OBS-6]",
00097     ". 0 Vendor specific minimum standby timer value",
00098 
00099   " 51 PIO data transfer mode [OBS-5]",
00100   " 52 Single Word DMA data transfer mode [OBS-3]",
00101 
00102   " 53 Field validity / Free-fall Control",
00103     ". 15:8 Free-fall Control sensitivity",
00104     ". 7:3 Reserved",
00105     ". 2 Word 88 (Ultra DMA modes) is valid",
00106     ". 1 Words 64-70 (PIO modes) are valid",
00107     ". 0 Words 54-58 (CHS) are valid [OBS-6]",
00108 
00109   " 54 Current cylinders [OBS-6]",
00110   " 55 Current heads [OBS-6]",
00111   " 56 Current sectors per track [OBS-6]",
00112   " 57-58 Current capacity in sectors (DWord) [OBS-6]",
00113 
00114   " 59 Sanitize Device - READ/WRITE MULTIPLE support",
00115     ". 15 BLOCK ERASE EXT supported",
00116     ". 14 OVERWRITE EXT supported",
00117     ". 13 CRYPTO SCRAMBLE EXT supported",
00118     ". 12 Sanitize Device feature set supported",
00119     ". 11:9 Reserved",
00120     ". 8 Bits 7:0 are valid",
00121     ". 7:0 Current sectors per DRQ on READ/WRITE MULTIPLE",
00122 
00123   " 60-61 User addressable sectors for 28-bit commands (DWord)",
00124   " 62 Single Word DMA modes [OBS-3]",
00125 
00126   " 63 Multiword DMA modes",
00127     ". 15:11 Reserved",
00128     ". 10 Multiword DMA mode 2 selected",
00129     ". 9 Multiword DMA mode 1 selected",
00130     ". 8 Multiword DMA mode 0 selected",
00131     ". 7:3 Reserved",
00132     ". 2 Multiword DMA mode 2 and below supported",
00133     ". 1 Multiword DMA mode 1 and below supported",
00134     ". 0 Multiword DMA mode 0 supported",
00135 
00136   " 64 PIO modes",
00137     ". 15:2 Reserved",
00138     ". 1 PIO mode 4 supported",
00139     ". 0 PIO mode 3 supported",
00140 
00141   " 65 Minimum Multiword DMA cycle time per word in ns",
00142   " 66 Recommended Multiword DMA cycle time in ns",
00143   " 67 Minimum PIO cycle time without flow control in ns",
00144   " 68 Minimum PIO cycle time with IORDY flow control in ns",
00145 
00146   " 69 Additional support",
00147     ". 15 CFast specification supported",
00148     ". 14 Deterministic data after trim supported",
00149     ". 13 LPS Alignment Error Reporting Control supported",
00150     ". 12 DCO IDENTIFY/SET DMA supported [OBS-ACS-3]",
00151     ". 11 READ BUFFER DMA supported",
00152     ". 10 WRITE BUFFER DMA supported",
00153     ". 9 SET MAX SET PASSWORD/UNLOCK DMA supported [OBS-ACS-3]",
00154     ". 8 DOWNLOAD MICROCODE DMA supported",
00155     ". 7 Reserved for IEEE 1667",
00156     ". 6 Optional ATA device 28-bit commands supported",
00157     ". 5 Trimmed LBA range(s) returning zeroed data supported",
00158     ". 4 Device encrypts all user data",
00159     ". 3 Extended number of user addressable sectors supported",
00160     ". 2 All write cache is non-volatile",
00161     ". 1:0 Reserved",
00162 
00163   " 70 Reserved",
00164   " 71-74 ATA: Reserved for IDENTIFY PACKET DEVICE",
00165   " 71 ATAPI: Time in ns from PACKET to bus release [OBS-8]",
00166   " 72 ATAPI: Time in ns from SERVICE to BSY cleared [OBS-8]",
00167   " 73-74 ATAPI: Reserved",
00168 
00169   " 75 Queue depth",
00170     ". 15:5 Reserved",
00171     ". 4:0 Maximum queue depth - 1",
00172 
00173   " 76 Serial ATA capabilities",
00174     ". 15 READ LOG DMA EXT as equiv to READ LOG EXT supported",
00175     ". 14 Device Auto Partial to Slumber transitions supported",
00176     ". 13 Host Auto Partial to Slumber transitions supported",
00177     ". 12 NCQ priority information supported",
00178     ". 11 Unload while NCQ commands are outstanding supported",
00179     ". 10 Phy Event Counters supported",
00180     ". 9 Receipt of host initiated PM requests supported",
00181     ". 8 NCQ feature set supported",
00182     ". 7:4 Reserved for Serial ATA",
00183     ". 3 SATA Gen3 signaling speed (6.0 Gb/s) supported",
00184     ". 2 SATA Gen2 signaling speed (3.0 Gb/s) supported",
00185     ". 1 SATA Gen1 signaling speed (1.5 Gb/s) supported",
00186     ". 0 Must be set to 0",
00187 
00188   " 77 Serial ATA additional capabilities", // ACS-3
00189     ". 15:7 Reserved for Serial ATA",
00190     ". 6 RECEIVE/SEND FPDMA QUEUED supported",
00191     ". 5 NCQ Queue Management supported",
00192     ". 4 NCQ Streaming supported",
00193     ". 3:1 Current Serial ATA signal speed",
00194     ". 0 Must be set to 0",
00195 
00196   " 78 Serial ATA features supported",
00197     ". 15:8 Reserved for Serial ATA",
00198     ". 7 NCQ Autosense supported", // ACS-3
00199     ". 6 Software Settings Preservation supported",
00200     ". 5 Hardware Feature Control supported", // ACS-3
00201     ". 4 In-order data delivery supported",
00202     ". 3 Device initiated power management supported",
00203     ". 2 DMA Setup auto-activation supported",
00204     ". 1 Non-zero buffer offsets supported",
00205     ". 0 Must be set to 0",
00206 
00207   " 79 Serial ATA features enabled",
00208     ". 15:8 Reserved for Serial ATA",
00209     ". 7 Automatic Partial to Slumber transitions enabled", // ACS-3
00210     ". 6 Software Settings Preservation enabled",
00211     ". 5 Hardware Feature Control enabled", // ACS-3
00212     ". 4 In-order data delivery enabled",
00213     ". 3 Device initiated power management enabled",
00214     ". 2 DMA Setup auto-activation enabled",
00215     ". 1 Non-zero buffer offsets enabled",
00216     ". 0 Must be set to 0",
00217 
00218   " 80 Major version number",
00219     ". 15:11 Reserved",
00220     ". 10 ACS-3 supported",
00221     ". 9 ACS-2 supported",
00222     ". 8 ATA8-ACS supported",
00223     ". 7 ATA/ATAPI-7 supported",
00224     ". 6 ATA/ATAPI-6 supported",
00225     ". 5 ATA/ATAPI-5 supported",
00226     ". 4 ATA/ATAPI-4 supported [OBS-8]",
00227     ". 3 ATA-3 supported [OBS-7]",
00228     ". 2 ATA-2 supported [OBS-6]",
00229     ". 1 ATA-1 supported [OBS-5]",
00230     ". 0 Reserved",
00231 
00232   " 81 Minor version number",
00233 
00234   " 82 Commands and feature sets supported",
00235     ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
00236     ". 14 NOP supported",
00237     ". 13 READ BUFFER supported",
00238     ". 12 WRITE BUFFER supported",
00239     ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
00240     ". 10 HPA feature set supported [OBS-ACS-3]",
00241     ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
00242     ". 8 SERVICE interrupt supported [OBS-ACS-2]",
00243     ". 7 Release interrupt supported [OBS-ACS-2]",
00244     ". 6 Read look-ahead supported",
00245     ". 5 Volatile write cache supported",
00246     ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
00247     ". 3 Power Management feature set supported",
00248     ". 2 Removable Media feature set supported [OBS-8]",
00249     ". 1 Security feature set supported",
00250     ". 0 SMART feature set supported",
00251 
00252   " 83 Commands and feature sets supported",
00253     ". 15:14 Must be set to 0x1",
00254     ". 13 FLUSH CACHE EXT supported",
00255     ". 12 FLUSH CACHE supported",
00256     ". 11 DCO feature set supported [OBS-ACS-3]",
00257     ". 10 48-bit Address feature set supported",
00258     ". 9 AAM feature set supported [OBS-ACS-2]",
00259     ". 8 SET MAX security extension supported [OBS-ACS-3]",
00260     ". 7 Reserved for Address Offset Reserved Area Boot Method",
00261     ". 6 SET FEATURES subcommand required to spin-up",
00262     ". 5 PUIS feature set supported",
00263     ". 4 Removable Media Status Notification supported [OBS-8]",
00264     ". 3 APM feature set supported",
00265     ". 2 CFA feature set supported",
00266     ". 1 TCQ feature set supported [OBS-ACS-2]",
00267     ". 0 DOWNLOAD MICROCODE supported",
00268 
00269   " 84 Commands and feature sets supported",
00270     ". 15:14 Must be set to 0x1",
00271     ". 13 IDLE IMMEDIATE with UNLOAD feature supported",
00272     ". 12:11 Reserved for TLC [OBS-ACS-3]",
00273     ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
00274     ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
00275     ". 8 64-bit World Wide Name supported",
00276     ". 7 WRITE DMA QUEUED FUA EXT supported",
00277     ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
00278     ". 5 GPL feature set supported",
00279     ". 4 Streaming feature set supported [OBS-ACS-3]",
00280     ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
00281     ". 2 Media serial number supported", // ACS-3 r3 or later: Reserved
00282     ". 1 SMART self-test supported",
00283     ". 0 SMART error logging supported",
00284 
00285   " 85 Commands and feature sets supported or enabled",
00286     ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
00287     ". 14 NOP supported",
00288     ". 13 READ BUFFER supported",
00289     ". 12 WRITE BUFFER supported",
00290     ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
00291     ". 10 HPA feature set supported [OBS-ACS-3]",
00292     ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
00293     ". 8 SERVICE interrupt enabled [OBS-ACS-2]",
00294     ". 7 Release interrupt enabled [OBS-ACS-2]",
00295     ". 6 Read look-ahead enabled",
00296     ". 5 Write cache enabled",
00297     ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
00298     ". 3 Power Management feature set supported",
00299     ". 2 Removable Media feature set supported [OBS-8]",
00300     ". 1 Security feature set enabled",
00301     ". 0 SMART feature set enabled",
00302 
00303   " 86 Commands and feature sets supported or enabled",
00304     ". 15 Words 119-120 are valid",
00305     ". 14 Reserved",
00306     ". 13 FLUSH CACHE EXT supported",
00307     ". 12 FLUSH CACHE supported",
00308     ". 11 DCO feature set supported [OBS-ACS-3]",
00309     ". 10 48-bit Address features set supported",
00310     ". 9 AAM feature set enabled [OBS-ACS-2]",
00311     ". 8 SET MAX security extension enabled [OBS-ACS-3]",
00312     ". 7 Reserved for Address Offset Reserved Area Boot Method",
00313     ". 6 SET FEATURES subcommand required to spin-up",
00314     ". 5 PUIS feature set enabled",
00315     ". 4 Removable Media Status Notification enabled [OBS-8]",
00316     ". 3 APM feature set enabled",
00317     ". 2 CFA feature set supported",
00318     ". 1 TCQ feature set supported [OBS-ACS-2]",
00319     ". 0 DOWNLOAD MICROCODE supported",
00320 
00321   " 87 Commands and feature sets supported or enabled",
00322     ". 15:14 Must be set to 0x1",
00323     ". 13 IDLE IMMEDIATE with UNLOAD FEATURE supported",
00324     ". 12:11 Reserved for TLC [OBS-ACS-3]",
00325     ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
00326     ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
00327     ". 8 64-bit World Wide Name supported",
00328     ". 7 WRITE DMA QUEUED FUA EXT supported [OBS-ACS-2]",
00329     ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
00330     ". 5 GPL feature set supported",
00331     ". 4 Valid CONFIGURE STREAM has been executed [OBS-8]",
00332     ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
00333     ". 2 Media serial number is valid",
00334     ". 1 SMART self-test supported",
00335     ". 0 SMART error logging supported",
00336 
00337   " 88 Ultra DMA modes",
00338     ". 15 Reserved",
00339     ". 14 Ultra DMA mode 6 selected",
00340     ". 13 Ultra DMA mode 5 selected",
00341     ". 12 Ultra DMA mode 4 selected",
00342     ". 11 Ultra DMA mode 3 selected",
00343     ". 10 Ultra DMA mode 2 selected",
00344     ". 9 Ultra DMA mode 1 selected",
00345     ". 8 Ultra DMA mode 0 selected",
00346     ". 7 Reserved",
00347     ". 6 Ultra DMA mode 6 and below supported",
00348     ". 5 Ultra DMA mode 5 and below supported",
00349     ". 4 Ultra DMA mode 4 and below supported",
00350     ". 3 Ultra DMA mode 3 and below supported",
00351     ". 2 Ultra DMA mode 2 and below supported",
00352     ". 1 Ultra DMA mode 1 and below supported",
00353     ". 0 Ultra DMA mode 0 supported",
00354 
00355   " 89 SECURITY ERASE UNIT time",
00356   " 90 ENHANCED SECURITY ERASE UNIT time",
00357   " 91 Current APM level",
00358   " 92 Master password revision code",
00359 
00360   " 93 Hardware reset result (PATA)",
00361     ". 15:14 Must be set to 0x1",
00362     ". 13 Device detected CBLID- above(1)/below(0) ViHB",
00363     ". 12 Reserved",
00364     ". 11 Device 1 asserted PDIAG-",
00365     ". 10:9 Device 1 detection method: -, Jumper, CSEL, other",
00366     ". 8 Must be set to 1",
00367     ". 7 Reserved",
00368     ". 6 Device 0 responds when device 1 selected",
00369     ". 5 Device 0 detected the assertion of DASP-",
00370     ". 4 Device 0 detected the assertion of PDIAG-",
00371     ". 3 Device 0 passed diagnostics",
00372     ". 2:1 Device 0 detection method: -, Jumper, CSEL, other",
00373     ". 0 Must be set to 1",
00374 
00375   " 94 AAM level [OBS-ACS-2]",
00376     ". 15:8 Recommended AAM level [OBS-ACS-2]",
00377     ". 7:0 Current AAM level [OBS-ACS-2]",
00378 
00379   " 95 Stream Minimum Request Size",
00380   " 96 Streaming Transfer Time - DMA",
00381   " 97 Streaming Access Latency - DMA and PIO",
00382   " 98-99 Streaming Performance Granularity (DWord)",
00383   "100-103 User addressable sectors for 48-bit commands (QWord)",
00384   "104 Streaming Transfer Time - PIO",
00385   "105 Max blocks of LBA Range Entries per DS MANAGEMENT cmd",
00386 
00387   "106 Physical sector size / logical sector size",
00388     ". 15:14 Must be set to 0x1",
00389     ". 13 Multiple logical sectors per physical sector",
00390     ". 12 Logical Sector longer than 256 words",
00391     ". 11:4 Reserved",
00392     ". 3:0 2^X logical sectors per physical sector",
00393 
00394   "107 Inter-seek delay for ISO 7779 acoustic testing",
00395   "108-111 64-bit World Wide Name",
00396   "112-115 Reserved for a 128-bit World Wide Name",
00397   "116 Reserved for TLC [OBS-ACS-3]",
00398   "117-118 Logical sector size (DWord)",
00399 
00400   "119 Commands and feature sets supported",
00401     ". 15:14 Must be set to 0x1",
00402     ". 13:10 Reserved",
00403     ". 9 DSN feature set supported", // ACS-3
00404     ". 8 Accessible Max Address Config feature set supported", // ACS-3
00405     ". 7 Extended Power Conditions feature set supported",
00406     ". 6 Sense Data Reporting feature set supported",
00407     ". 5 Free-fall Control feature set supported",
00408     ". 4 DOWNLOAD MICROCODE with mode 3 supported",
00409     ". 3 READ/WRITE LOG DMA EXT supported",
00410     ". 2 WRITE UNCORRECTABLE EXT supported",
00411     ". 1 Write-Read-Verify feature set supported",
00412     ". 0 Reserved for DDT [OBS-ACS-3]",
00413 
00414   "120 Commands and feature sets supported or enabled",
00415     ". 15:14 Must be set to 0x1",
00416     ". 13:10 Reserved",
00417     ". 9 DSN feature set enabled", // ACS-3
00418     ". 8 Reserved",
00419     ". 7 Extended Power Conditions feature set enabled",
00420     ". 6 Sense Data Reporting feature set enabled",
00421     ". 5 Free-fall Control feature set enabled",
00422     ". 4 DOWNLOAD MICROCODE with mode 3 supported",
00423     ". 3 READ/WRITE LOG DMA EXT supported",
00424     ". 2 WRITE UNCORRECTABLE EXT supported",
00425     ". 1 Write-Read-Verify feature set enabled",
00426     ". 0 Reserved for DDT [OBS-ACS-3]",
00427 
00428   "121-126 ATA: Reserved",
00429   "121-124 ATAPI: Reserved",
00430   "125 ATAPI: Byte count = 0 behavior",
00431   "126 ATAPI: Byte count = 0 behavior [OBS-6]",
00432 
00433   "127 Removable Media Status Notification [OBS-8]",
00434     ". 15:1 Reserved",
00435     ". 0 Removable Media Status Notification supported",
00436 
00437   "128 Security status",
00438     ". 15:9 Reserved",
00439     ". 8 Master password capability: 0 = High, 1 = Maximum",
00440     ". 7:6 Reserved",
00441     ". 5 Enhanced security erase supported",
00442     ". 4 Security count expired",
00443     ". 3 Security frozen",
00444     ". 2 Security locked",
00445     ". 1 Security enabled",
00446     ". 0 Security supported",
00447 
00448   "129-159 Vendor specific",
00449 
00450   "160 CFA power mode",
00451   // ". 15 Word 160 supported",
00452   // ". 14 Reserved",
00453   // ". 13 CFA power mode 1 is required for some commands",
00454   // ". 12 CFA power mode 1 disabled",
00455   // ". 11:0 Maximum current in mA",
00456   "161-167 Reserved for CFA",
00457 
00458   "168 Form factor",
00459     ". 15:4 Reserved",
00460     ". 3:0 Nominal form factor: -, 5.25, 3.5, 2.5, 1.8, <1.8",
00461 
00462   "169 Data Set Management support",
00463     ". 15:1 Reserved",
00464     ". 0 Trim bit in DATA SET MANAGEMENT command supported",
00465 
00466   "170-173 Additional product identifier (String)",
00467   "174-175 Reserved",
00468   "176-205 Current media serial number (String)",
00469 
00470   "206 SCT Command Transport",
00471     ". 15:12 Vendor Specific",
00472     ". 11:8 Reserved",
00473     ". 7 Reserved for Serial ATA",
00474     ". 6 Reserved",
00475     ". 5 SCT Data Tables supported",
00476     ". 4 SCT Feature Control supported",
00477     ". 3 SCT Error Recovery Control supported",
00478     ". 2 SCT Write Same supported",
00479     ". 1 SCT Read/Write Long supported [OBS-ACS-2]",
00480     ". 0 SCT Command Transport supported",
00481 
00482   "207-208 Reserved for CE-ATA",
00483 
00484   "209 Alignment of logical sectors",
00485     ". 15:14 Must be set to 0x1",
00486     ". 13:0 Logical sector offset",
00487 
00488   "210-211 Write-Read-Verify sector count mode 3 (DWord)",
00489   "212-213 Write-Read-Verify sector count mode 2 (DWord)",
00490 
00491   "214 NV Cache capabilities [OBS-ACS-3]",
00492     ". 15:12 NV Cache feature set version [OBS-ACS-3]",
00493     ". 11:8 NV Cache Power Mode feature set version [OBS-ACS-3]",
00494     ". 7:5 Reserved [OBS-ACS-3]",
00495     ". 4 NV Cache feature set enabled [OBS-ACS-3]",
00496     ". 3:2 Reserved",
00497     ". 1 NV Cache Power Mode feature set enabled [OBS-ACS-3]",
00498     ". 0 NV Cache Power Mode feature set supported [OBS-ACS-3]",
00499 
00500   "215-216 NV Cache size in logical blocks (DWord) [OBS-ACS-3]",
00501   "217 Nominal media rotation rate",
00502   "218 Reserved",
00503 
00504   "219 NV Cache options [OBS-ACS-3]",
00505     ". 15:8 Reserved [OBS-ACS-3]",
00506     ". 7:0 Estimated time to spin up in seconds [OBS-ACS-3]",
00507 
00508   "220 Write-Read-Verify mode",
00509     ". 15:8 Reserved",
00510     ". 7:0 Write-Read-Verify feature set current mode",
00511 
00512   "221 Reserved",
00513 
00514   "222 Transport major version number",
00515     ". 15:12 Transport type: 0x0 = Parallel, 0x1 = Serial",
00516     ". 11:7 Reserved    | Reserved",
00517     ". 6 Reserved    | SATA 3.1",
00518     ". 5 Reserved    | SATA 3.0",
00519     ". 4 Reserved    | SATA 2.6",
00520     ". 3 Reserved    | SATA 2.5",
00521     ". 2 Reserved    | SATA II: Extensions",
00522     ". 1 ATA/ATAPI-7 | SATA 1.0a",
00523     ". 0 ATA8-APT    | ATA8-AST",
00524 
00525   "223 Transport minor version number",
00526   "224-229 Reserved",
00527   "230-233 Extended number of user addressable sectors (QWord)",
00528   "234 Minimum blocks per DOWNLOAD MICROCODE mode 3 command",
00529   "235 Maximum blocks per DOWNLOAD MICROCODE mode 3 command",
00530   "236-254 Reserved",
00531 
00532   "255 Integrity word",
00533     ". 15:8 Checksum",
00534     ". 7:0 Signature"
00535 };
00536 
00537 const int num_identify_descriptions = sizeof(identify_descriptions)/sizeof(identify_descriptions[0]);
00538 
00539 static inline unsigned short get_word(const void * id, int word)
00540 {
00541   const unsigned char * p = ((const unsigned char *)id) + 2 * word;
00542   return p[0] + (p[1] << 8);
00543 }
00544 
00545 void ata_print_identify_data(const void * id, bool all_words, int bit_level)
00546 {
00547   // ATA or ATAPI ?
00548   unsigned short w = get_word(id, 0);
00549   bool is_atapi = ((w & 0x8000) && (w != 0x848a/*CompactFlash Signature*/));
00550 
00551   int prev_word = -1, prev_bit = -1;
00552   pout("Word     %s Value   Description\n", (bit_level >= 0 ? "Bit    " : " "));
00553 
00554   for (int i = 0; i < num_identify_descriptions; i++) {
00555     // Parse table entry
00556     const char * desc = identify_descriptions[i];
00557 
00558     int word = prev_word, word2 = -1;
00559     int bit = -1, bit2 = -1;
00560 
00561     int nc;
00562     unsigned v1, v2;
00563     if (word >= 0 && sscanf(desc, ". %u:%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && 16 > v1 && v1 > v2) {
00564       bit = v1; bit2 = v2;
00565     }
00566     else if (word >= 0 && sscanf(desc, ". %u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 16) {
00567       bit = v1;
00568     }
00569     else if (sscanf(desc, "%u-%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && v1 < v2 && v2 < 256) {
00570       word = v1, word2 = v2;
00571     }
00572     else if (sscanf(desc, "%u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 256) {
00573       word = v1;
00574     }
00575     else {
00576       pout("Error: #%d: Syntax\n", i);
00577       continue;
00578     }
00579     desc += nc;
00580 
00581     // Check for ATA/ATAPI specific entries
00582     if (str_starts_with(desc, "ATA: ")) {
00583       if (is_atapi)
00584         continue;
00585       desc += sizeof("ATA: ")-1;
00586     }
00587     else if (str_starts_with(desc, "ATAPI: ")) {
00588       if (!is_atapi)
00589         continue;
00590     }
00591 
00592     // Check table entry
00593     if (bit < 0) {
00594       if (word != prev_word+1) {
00595         pout("Error: #%d: Missing word %d\n", i, prev_word+1);
00596         return;
00597       }
00598       else if (prev_bit > 0) {
00599         pout("Error: #%d: Missing bit 0 from word %d\n", i, prev_word);
00600         return;
00601       }
00602     }
00603     else if (!((prev_bit < 0 && bit == 15) || bit == prev_bit-1)) {
00604       pout("Error: #%d: Missing bit %d from word %d\n", i, bit+1, word);
00605       return;
00606     }
00607 
00608     w = get_word(id, word);
00609     bool w_is_set = (w != 0x0000 && w != 0xffff);
00610 
00611     if (bit >= 0) {
00612       int b;
00613       if (bit2 >= 0)
00614         b = (w >> bit2) & ~(~0 << (bit-bit2+1));
00615       else
00616         b = (w >> bit) & 1;
00617 
00618       if (   (bit_level >= 0 && b)
00619           || (bit_level >= 1 && w_is_set)
00620           || (bit_level >= 2 && all_words)) {
00621         if (bit2 >= 0) {
00622           // Print bitfield
00623           char valstr[20];
00624           snprintf(valstr, sizeof(valstr), "0x%0*x", (bit - bit2 + 4) >> 2, b);
00625           pout("%4d     %2d:%-2d  %6s   %s\n", word, bit, bit2, valstr, desc);
00626         }
00627         else {
00628           // Print bit
00629           pout("%4d     %2d          %u   %s\n", word, bit, b, desc);
00630         }
00631       }
00632 
00633       prev_bit = (bit2 >= 0 ? bit2 : bit);
00634     }
00635     else {
00636       if (word2 >= 0) {
00637         for (int j = word+1; !w_is_set && j <= word2; j++) {
00638            if (get_word(id, j) != w)
00639              w_is_set = true;
00640         }
00641 
00642         // Print word array
00643         if (all_words || w_is_set) {
00644           pout("%s%4d-%-3d  %s",
00645                (bit_level >= 0 ? "\n" : ""), word, word2,
00646                (bit_level >= 0 ? "-     " : ""));
00647 
00648           if (!w_is_set) {
00649             pout("0x%02x...  %s\n", w & 0xff, desc);
00650           }
00651           else {
00652             bool is_str = !!strstr(desc, "(String)");
00653             pout(".        %s", desc);
00654 
00655             for (int j = word; j <= word2; j += 4) {
00656               if (j + 2*4 < word2 && !nonempty((const unsigned char *)id + 2*j, 2*(word2-j+1))) {
00657                 // Remaining words are null
00658                 pout("\n%4d-%-3d  %s0x0000:0000:0000:00...", j, word2,
00659                      (bit_level >= 0 ? ".     " : ""));
00660                 break;
00661               }
00662               // Print 4 words in a row
00663               pout("\n%4d-%-3d  %s0x", j, (j+3 <= word2 ? j+3 : word2),
00664                    (bit_level >= 0 ? ".     " : ""));
00665               int k;
00666               for (k = 0; k < 4 && j+k <= word2; k++)
00667                 pout("%s%04x",  (k == 0 ? "" : ":"), get_word(id, j+k));
00668 
00669               if (is_str) {
00670                 // Append little endian string
00671                 pout("%*s  \"", 20 - 5 * k, "");
00672                 for (k = 0; k < 4 && j+k <= word2; k++) {
00673                   char c2 = ((const char *)id)[2*(j+k)    ];
00674                   char c1 = ((const char *)id)[2*(j+k) + 1];
00675                   pout("%c%c", (' ' <= c1 && c1 <= '~' ? c1 : '.'),
00676                                (' ' <= c2 && c2 <= '~' ? c2 : '.') );
00677                 }
00678                 pout("\"");
00679               }
00680             }
00681 
00682             // Print decimal value of D/QWords
00683             if (word + 1 == word2 && strstr(desc, "(DWord)"))
00684               pout("  (%u)\n", ((unsigned)get_word(id, word2) << 16) | w);
00685             else if (word + 3 == word2 && strstr(desc, "(QWord)"))
00686               pout("  (%" PRIu64 ")\n", ((uint64_t)get_word(id, word + 3) << 48)
00687                                       | ((uint64_t)get_word(id, word + 2) << 32)
00688                                       | ((unsigned)get_word(id, word + 1) << 16) | (unsigned)w);
00689             else
00690               pout("\n");
00691           }
00692         }
00693       }
00694       else {
00695         // Print word
00696         if (all_words || w_is_set)
00697           pout("%s%4d      %s0x%04x   %s\n",
00698                (bit_level >= 0 ? "\n" : ""), word,
00699                (bit_level >= 0 ? "-     " : ""), w, desc);
00700       }
00701 
00702       prev_word = (word2 >= 0 ? word2 : word);
00703       prev_bit = -1;
00704     }
00705   }
00706 
00707   pout("\n");
00708 }