diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-07-22 07:30:36 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-07-22 07:30:36 +0000 |
commit | 3443bd72863326cca2ef4ba78965c05abc77cb96 (patch) | |
tree | 009687f5e562149649a40a8c0878c871c72e30bb /miscutils | |
parent | 1ebcff191a57d792dcbcc651974c54510ed03696 (diff) | |
download | busybox-w32-3443bd72863326cca2ef4ba78965c05abc77cb96.tar.gz busybox-w32-3443bd72863326cca2ef4ba78965c05abc77cb96.tar.bz2 busybox-w32-3443bd72863326cca2ef4ba78965c05abc77cb96.zip |
Matteo Croce submitted a hdparm applet.
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/Config.in | 50 | ||||
-rw-r--r-- | miscutils/Makefile.in | 1 | ||||
-rw-r--r-- | miscutils/hdparm.c | 2665 |
3 files changed, 2716 insertions, 0 deletions
diff --git a/miscutils/Config.in b/miscutils/Config.in index f70c12228..86be4d3a8 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -39,6 +39,56 @@ config CONFIG_DUTMP | |||
39 | help | 39 | help |
40 | Please submit a patch to add help text for this item. | 40 | Please submit a patch to add help text for this item. |
41 | 41 | ||
42 | config CONFIG_HDPARM | ||
43 | bool "hdparm" | ||
44 | default n | ||
45 | help | ||
46 | Get/Set hard drive parameters. Primarily intended for ATA | ||
47 | drives. Adds about 13k (or around 30k if you enable the | ||
48 | CONFIG_FEATURE_HDPARM_GET_IDENTITY option).... | ||
49 | |||
50 | config CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
51 | bool " Support obtaining detailed information directly from drives" | ||
52 | default y | ||
53 | depends on CONFIG_HDPARM | ||
54 | help | ||
55 | Enables the -I and -Istdin options to obtain detailed information | ||
56 | directly from drives about their capabilities and supported ATA | ||
57 | feature set. Enabling this option will add about 16k... | ||
58 | |||
59 | config CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF | ||
60 | bool " Register an IDE interface (DANGEROUS)" | ||
61 | default n | ||
62 | depends on CONFIG_HDPARM | ||
63 | help | ||
64 | Enables the 'hdparm -R' option to register an IDE interface. | ||
65 | This is dangerous stuff, so you should probably say N. | ||
66 | |||
67 | config CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | ||
68 | bool " Un-register an IDE interface (DANGEROUS)" | ||
69 | default n | ||
70 | depends on CONFIG_HDPARM | ||
71 | help | ||
72 | Enables the 'hdparm -U' option to un-register an IDE interface. | ||
73 | This is dangerous stuff, so you should probably say N. | ||
74 | |||
75 | config CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET | ||
76 | bool " perform device reset (DANGEROUS)" | ||
77 | default n | ||
78 | depends on CONFIG_HDPARM | ||
79 | help | ||
80 | Enables the 'hdparm -w' option to perform a device reset. | ||
81 | This is dangerous stuff, so you should probably say N. | ||
82 | |||
83 | config CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
84 | bool " tristate device for hotswap (DANGEROUS)" | ||
85 | default n | ||
86 | depends on CONFIG_HDPARM | ||
87 | help | ||
88 | Enables the 'hdparm -x' option to tristate device for hotswap, | ||
89 | and the '-b' option to get/set bus state. This is dangerous | ||
90 | stuff, so you should probably say N. | ||
91 | |||
42 | config CONFIG_MAKEDEVS | 92 | config CONFIG_MAKEDEVS |
43 | bool "makedevs" | 93 | bool "makedevs" |
44 | default n | 94 | default n |
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in index 1fd109e2d..0ef96f0cd 100644 --- a/miscutils/Makefile.in +++ b/miscutils/Makefile.in | |||
@@ -29,6 +29,7 @@ MISCUTILS-$(CONFIG_CROND) += crond.o | |||
29 | MISCUTILS-$(CONFIG_CRONTAB) += crontab.o | 29 | MISCUTILS-$(CONFIG_CRONTAB) += crontab.o |
30 | MISCUTILS-$(CONFIG_DC) += dc.o | 30 | MISCUTILS-$(CONFIG_DC) += dc.o |
31 | MISCUTILS-$(CONFIG_DUTMP) += dutmp.o | 31 | MISCUTILS-$(CONFIG_DUTMP) += dutmp.o |
32 | MISCUTILS-$(CONFIG_HDPARM) += hdparm.o | ||
32 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o | 33 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o |
33 | MISCUTILS-$(CONFIG_MT) += mt.o | 34 | MISCUTILS-$(CONFIG_MT) += mt.o |
34 | MISCUTILS-$(CONFIG_STRINGS) += strings.o | 35 | MISCUTILS-$(CONFIG_STRINGS) += strings.o |
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c new file mode 100644 index 000000000..1e34f4f4e --- /dev/null +++ b/miscutils/hdparm.c | |||
@@ -0,0 +1,2665 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * hdparm implementation for busybox | ||
4 | * | ||
5 | * | ||
6 | * Copyright (C) [2003] by [Matteo Croce] <pinnolo@tin.it> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
21 | * 02111-1307 USA | ||
22 | * | ||
23 | * | ||
24 | * This program is based on the source code of hdparm: see below... | ||
25 | * hdparm.c - Command line interface to get/set hard disk parameters | ||
26 | * - by Mark Lord (C) 1994-2002 -- freely distributable | ||
27 | */ | ||
28 | |||
29 | #include <unistd.h> | ||
30 | #include <string.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <fcntl.h> | ||
33 | #include <errno.h> | ||
34 | #include <ctype.h> | ||
35 | #include <endian.h> | ||
36 | #include <sys/ioctl.h> | ||
37 | #include <sys/shm.h> | ||
38 | #include <sys/sysmacros.h> | ||
39 | #include <sys/time.h> | ||
40 | #include <sys/times.h> | ||
41 | #include <sys/mount.h> | ||
42 | #include "busybox.h" | ||
43 | #include <linux/types.h> | ||
44 | #include <linux/hdreg.h> | ||
45 | #include <linux/major.h> | ||
46 | #include <asm/byteorder.h> | ||
47 | |||
48 | |||
49 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
50 | #define __USE_XOPEN | ||
51 | #endif | ||
52 | |||
53 | /* device types */ | ||
54 | /* ------------ */ | ||
55 | #define NO_DEV 0xffff | ||
56 | #define ATA_DEV 0x0000 | ||
57 | #define ATAPI_DEV 0x0001 | ||
58 | |||
59 | /* word definitions */ | ||
60 | /* ---------------- */ | ||
61 | #define GEN_CONFIG 0 /* general configuration */ | ||
62 | #define LCYLS 1 /* number of logical cylinders */ | ||
63 | #define CONFIG 2 /* specific configuration */ | ||
64 | #define LHEADS 3 /* number of logical heads */ | ||
65 | #define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */ | ||
66 | #define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */ | ||
67 | #define LSECTS 6 /* number of logical sectors/track */ | ||
68 | #define START_SERIAL 10 /* ASCII serial number */ | ||
69 | #define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */ | ||
70 | #define BUF_TYPE 20 /* buffer type (ATA-1) */ | ||
71 | #define BUFFER__SIZE 21 /* buffer size (ATA-1) */ | ||
72 | #define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/ | ||
73 | #define START_FW_REV 23 /* ASCII firmware revision */ | ||
74 | #define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */ | ||
75 | #define START_MODEL 27 /* ASCII model number */ | ||
76 | #define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */ | ||
77 | #define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */ | ||
78 | #define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */ | ||
79 | #define CAPAB_0 49 /* capabilities */ | ||
80 | #define CAPAB_1 50 | ||
81 | #define PIO_MODE 51 /* max PIO mode supported (obsolete)*/ | ||
82 | #define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/ | ||
83 | #define WHATS_VALID 53 /* what fields are valid */ | ||
84 | #define LCYLS_CUR 54 /* current logical cylinders */ | ||
85 | #define LHEADS_CUR 55 /* current logical heads */ | ||
86 | #define LSECTS_CUR 56 /* current logical sectors/track */ | ||
87 | #define CAPACITY_LSB 57 /* current capacity in sectors */ | ||
88 | #define CAPACITY_MSB 58 | ||
89 | #define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */ | ||
90 | #define LBA_SECTS_LSB 60 /* LBA: total number of user */ | ||
91 | #define LBA_SECTS_MSB 61 /* addressable sectors */ | ||
92 | #define SINGLE_DMA 62 /* singleword DMA modes */ | ||
93 | #define MULTI_DMA 63 /* multiword DMA modes */ | ||
94 | #define ADV_PIO_MODES 64 /* advanced PIO modes supported */ | ||
95 | /* multiword DMA xfer cycle time: */ | ||
96 | #define DMA_TIME_MIN 65 /* - minimum */ | ||
97 | #define DMA_TIME_NORM 66 /* - manufacturer's recommended */ | ||
98 | /* minimum PIO xfer cycle time: */ | ||
99 | #define PIO_NO_FLOW 67 /* - without flow control */ | ||
100 | #define PIO_FLOW 68 /* - with IORDY flow control */ | ||
101 | #define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */ | ||
102 | #define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */ | ||
103 | #define CDR_MAJOR 73 /* CD ROM: major version number */ | ||
104 | #define CDR_MINOR 74 /* CD ROM: minor version number */ | ||
105 | #define QUEUE_DEPTH 75 /* queue depth */ | ||
106 | #define MAJOR 80 /* major version number */ | ||
107 | #define MINOR 81 /* minor version number */ | ||
108 | #define CMDS_SUPP_0 82 /* command/feature set(s) supported */ | ||
109 | #define CMDS_SUPP_1 83 | ||
110 | #define CMDS_SUPP_2 84 | ||
111 | #define CMDS_EN_0 85 /* command/feature set(s) enabled */ | ||
112 | #define CMDS_EN_1 86 | ||
113 | #define CMDS_EN_2 87 | ||
114 | #define ULTRA_DMA 88 /* ultra DMA modes */ | ||
115 | /* time to complete security erase */ | ||
116 | #define ERASE_TIME 89 /* - ordinary */ | ||
117 | #define ENH_ERASE_TIME 90 /* - enhanced */ | ||
118 | #define ADV_PWR 91 /* current advanced power management level | ||
119 | in low byte, 0x40 in high byte. */ | ||
120 | #define PSWD_CODE 92 /* master password revision code */ | ||
121 | #define HWRST_RSLT 93 /* hardware reset result */ | ||
122 | #define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */ | ||
123 | #define LBA_LSB 100 /* LBA: maximum. Currently only 48 */ | ||
124 | #define LBA_MID 101 /* bits are used, but addr 103 */ | ||
125 | #define LBA_48_MSB 102 /* has been reserved for LBA in */ | ||
126 | #define LBA_64_MSB 103 /* the future. */ | ||
127 | #define RM_STAT 127 /* removable media status notification feature set support */ | ||
128 | #define SECU_STATUS 128 /* security status */ | ||
129 | #define CFA_PWR_MODE 160 /* CFA power mode 1 */ | ||
130 | #define START_MEDIA 176 /* media serial number */ | ||
131 | #define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/ | ||
132 | #define START_MANUF 196 /* media manufacturer I.D. */ | ||
133 | #define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */ | ||
134 | #define INTEGRITY 255 /* integrity word */ | ||
135 | |||
136 | /* bit definitions within the words */ | ||
137 | /* -------------------------------- */ | ||
138 | |||
139 | /* many words are considered valid if bit 15 is 0 and bit 14 is 1 */ | ||
140 | #define VALID 0xc000 | ||
141 | #define VALID_VAL 0x4000 | ||
142 | /* many words are considered invalid if they are either all-0 or all-1 */ | ||
143 | #define NOVAL_0 0x0000 | ||
144 | #define NOVAL_1 0xffff | ||
145 | |||
146 | /* word 0: gen_config */ | ||
147 | #define NOT_ATA 0x8000 | ||
148 | #define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */ | ||
149 | #define MEDIA_REMOVABLE 0x0080 | ||
150 | #define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */ | ||
151 | #define INCOMPLETE 0x0004 | ||
152 | #define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */ | ||
153 | #define DRQ_RESPONSE_TIME 0x0060 | ||
154 | #define DRQ_3MS_VAL 0x0000 | ||
155 | #define DRQ_INTR_VAL 0x0020 | ||
156 | #define DRQ_50US_VAL 0x0040 | ||
157 | #define PKT_SIZE_SUPPORTED 0x0003 | ||
158 | #define PKT_SIZE_12_VAL 0x0000 | ||
159 | #define PKT_SIZE_16_VAL 0x0001 | ||
160 | #define EQPT_TYPE 0x1f00 | ||
161 | #define SHIFT_EQPT 8 | ||
162 | |||
163 | #define CDROM 0x0005 | ||
164 | |||
165 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
166 | static const char *pkt_str[] = { | ||
167 | "Direct-access device", /* word 0, bits 12-8 = 00 */ | ||
168 | "Sequential-access device", /* word 0, bits 12-8 = 01 */ | ||
169 | "Printer", /* word 0, bits 12-8 = 02 */ | ||
170 | "Processor", /* word 0, bits 12-8 = 03 */ | ||
171 | "Write-once device", /* word 0, bits 12-8 = 04 */ | ||
172 | "CD-ROM", /* word 0, bits 12-8 = 05 */ | ||
173 | "Scanner", /* word 0, bits 12-8 = 06 */ | ||
174 | "Optical memory", /* word 0, bits 12-8 = 07 */ | ||
175 | "Medium changer", /* word 0, bits 12-8 = 08 */ | ||
176 | "Communications device", /* word 0, bits 12-8 = 09 */ | ||
177 | "ACS-IT8 device", /* word 0, bits 12-8 = 0a */ | ||
178 | "ACS-IT8 device", /* word 0, bits 12-8 = 0b */ | ||
179 | "Array controller", /* word 0, bits 12-8 = 0c */ | ||
180 | "Enclosure services", /* word 0, bits 12-8 = 0d */ | ||
181 | "Reduced block command device", /* word 0, bits 12-8 = 0e */ | ||
182 | "Optical card reader/writer", /* word 0, bits 12-8 = 0f */ | ||
183 | "", /* word 0, bits 12-8 = 10 */ | ||
184 | "", /* word 0, bits 12-8 = 11 */ | ||
185 | "", /* word 0, bits 12-8 = 12 */ | ||
186 | "", /* word 0, bits 12-8 = 13 */ | ||
187 | "", /* word 0, bits 12-8 = 14 */ | ||
188 | "", /* word 0, bits 12-8 = 15 */ | ||
189 | "", /* word 0, bits 12-8 = 16 */ | ||
190 | "", /* word 0, bits 12-8 = 17 */ | ||
191 | "", /* word 0, bits 12-8 = 18 */ | ||
192 | "", /* word 0, bits 12-8 = 19 */ | ||
193 | "", /* word 0, bits 12-8 = 1a */ | ||
194 | "", /* word 0, bits 12-8 = 1b */ | ||
195 | "", /* word 0, bits 12-8 = 1c */ | ||
196 | "", /* word 0, bits 12-8 = 1d */ | ||
197 | "", /* word 0, bits 12-8 = 1e */ | ||
198 | "Unknown", /* word 0, bits 12-8 = 1f */ | ||
199 | }; | ||
200 | static const char *ata1_cfg_str[] = { /* word 0 in ATA-1 mode */ | ||
201 | "reserved", /* bit 0 */ | ||
202 | "hard sectored", /* bit 1 */ | ||
203 | "soft sectored", /* bit 2 */ | ||
204 | "not MFM encoded ", /* bit 3 */ | ||
205 | "head switch time > 15us", /* bit 4 */ | ||
206 | "spindle motor control option", /* bit 5 */ | ||
207 | "fixed drive", /* bit 6 */ | ||
208 | "removable drive", /* bit 7 */ | ||
209 | "disk xfer rate <= 5Mbs", /* bit 8 */ | ||
210 | "disk xfer rate > 5Mbs, <= 10Mbs", /* bit 9 */ | ||
211 | "disk xfer rate > 5Mbs", /* bit 10 */ | ||
212 | "rotational speed tol.", /* bit 11 */ | ||
213 | "data strobe offset option", /* bit 12 */ | ||
214 | "track offset option", /* bit 13 */ | ||
215 | "format speed tolerance gap reqd", /* bit 14 */ | ||
216 | "ATAPI" /* bit 14 */ | ||
217 | }; | ||
218 | #endif | ||
219 | |||
220 | /* word 1: number of logical cylinders */ | ||
221 | #define LCYLS_MAX 0x3fff /* maximum allowable value */ | ||
222 | |||
223 | /* word 2: specific configureation | ||
224 | * (a) require SET FEATURES to spin-up | ||
225 | * (b) require spin-up to fully reply to IDENTIFY DEVICE | ||
226 | */ | ||
227 | #define STBY_NID_VAL 0x37c8 /* (a) and (b) */ | ||
228 | #define STBY_ID_VAL 0x738c /* (a) and not (b) */ | ||
229 | #define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */ | ||
230 | #define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */ | ||
231 | |||
232 | /* words 47 & 59: sector_xfer_max & sector_xfer_cur */ | ||
233 | #define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/ | ||
234 | #define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */ | ||
235 | |||
236 | /* word 49: capabilities 0 */ | ||
237 | #define STD_STBY 0x2000 /* 1=standard values supported (ATA); | ||
238 | 0=vendor specific values */ | ||
239 | #define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */ | ||
240 | #define IORDY_OFF 0x0400 /* 1=may be disabled */ | ||
241 | #define LBA_SUP 0x0200 /* 1=Logical Block Address support */ | ||
242 | #define DMA_SUP 0x0100 /* 1=Direct Memory Access support */ | ||
243 | #define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */ | ||
244 | #define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */ | ||
245 | #define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */ | ||
246 | #define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */ | ||
247 | |||
248 | /* word 50: capabilities 1 */ | ||
249 | #define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */ | ||
250 | |||
251 | /* words 51 & 52: PIO & DMA cycle times */ | ||
252 | #define MODE 0xff00 /* the mode is in the MSBs */ | ||
253 | |||
254 | /* word 53: whats_valid */ | ||
255 | #define OK_W88 0x0004 /* the ultra_dma info is valid */ | ||
256 | #define OK_W64_70 0x0002 /* see above for word descriptions */ | ||
257 | #define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */ | ||
258 | |||
259 | /*word 63,88: dma_mode, ultra_dma_mode*/ | ||
260 | #define MODE_MAX 7 /* bit definitions force udma <=7 (when | ||
261 | * udma >=8 comes out it'll have to be | ||
262 | * defined in a new dma_mode word!) */ | ||
263 | |||
264 | /* word 64: PIO transfer modes */ | ||
265 | #define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */ | ||
266 | #define PIO_MODE_MAX 8 /* but all 8 bits are defined */ | ||
267 | |||
268 | /* word 75: queue_depth */ | ||
269 | #define DEPTH_BITS 0x001f /* bits used for queue depth */ | ||
270 | |||
271 | /* words 80-81: version numbers */ | ||
272 | /* NOVAL_0 or NOVAL_1 means device does not report version */ | ||
273 | |||
274 | /* word 81: minor version number */ | ||
275 | #define MINOR_MAX 0x1C | ||
276 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
277 | static const char *minor_str[] = { /* word 81 value: */ | ||
278 | "device does not report version", /* 0x0000 */ | ||
279 | "ATA-1 X3T9.2 781D prior to revision 4", /* 0x0001 */ | ||
280 | "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */ | ||
281 | "ATA-1 X3T9.2 781D revision 4", /* 0x0003 */ | ||
282 | "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */ | ||
283 | "ATA-2 X3T10 948D prior to revision 2k", /* 0x0005 */ | ||
284 | "ATA-3 X3T10 2008D revision 1", /* 0x0006 */ | ||
285 | "ATA-2 X3T10 948D revision 2k", /* 0x0007 */ | ||
286 | "ATA-3 X3T10 2008D revision 0", /* 0x0008 */ | ||
287 | "ATA-2 X3T10 948D revision 3", /* 0x0009 */ | ||
288 | "ATA-3 published, ANSI X3.298-199x", /* 0x000a */ | ||
289 | "ATA-3 X3T10 2008D revision 6", /* 0x000b */ | ||
290 | "ATA-3 X3T13 2008D revision 7 and 7a", /* 0x000c */ | ||
291 | "ATA/ATAPI-4 X3T13 1153D revision 6", /* 0x000d */ | ||
292 | "ATA/ATAPI-4 T13 1153D revision 13", /* 0x000e */ | ||
293 | "ATA/ATAPI-4 X3T13 1153D revision 7", /* 0x000f */ | ||
294 | "ATA/ATAPI-4 T13 1153D revision 18", /* 0x0010 */ | ||
295 | "ATA/ATAPI-4 T13 1153D revision 15", /* 0x0011 */ | ||
296 | "ATA/ATAPI-4 published, ANSI NCITS 317-1998", /* 0x0012 */ | ||
297 | "ATA/ATAPI-5 T13 1321D revision 3", | ||
298 | "ATA/ATAPI-4 T13 1153D revision 14", /* 0x0014 */ | ||
299 | "ATA/ATAPI-5 T13 1321D revision 1", /* 0x0015 */ | ||
300 | "ATA/ATAPI-5 published, ANSI NCITS 340-2000", /* 0x0016 */ | ||
301 | "ATA/ATAPI-4 T13 1153D revision 17", /* 0x0017 */ | ||
302 | "ATA/ATAPI-6 T13 1410D revision 0", /* 0x0018 */ | ||
303 | "ATA/ATAPI-6 T13 1410D revision 3a", /* 0x0019 */ | ||
304 | "Reserved", /* 0x001a */ | ||
305 | "ATA/ATAPI-6 T13 1410D revision 2", /* 0x001b */ | ||
306 | "ATA/ATAPI-6 T13 1410D revision 1", /* 0x001c */ | ||
307 | "reserved" /* 0x001d */ | ||
308 | "reserved" /* 0x001e */ | ||
309 | "reserved" /* 0x001f-0xfffe*/ | ||
310 | }; | ||
311 | #endif | ||
312 | static const char actual_ver[] = { | ||
313 | /* word 81 value: */ | ||
314 | 0, /* 0x0000 WARNING: */ | ||
315 | 1, /* 0x0001 WARNING: */ | ||
316 | 1, /* 0x0002 WARNING: */ | ||
317 | 1, /* 0x0003 WARNING: */ | ||
318 | 2, /* 0x0004 WARNING: This array */ | ||
319 | 2, /* 0x0005 WARNING: corresponds */ | ||
320 | 3, /* 0x0006 WARNING: *exactly* */ | ||
321 | 2, /* 0x0007 WARNING: to the ATA/ */ | ||
322 | 3, /* 0x0008 WARNING: ATAPI version */ | ||
323 | 2, /* 0x0009 WARNING: listed in */ | ||
324 | 3, /* 0x000a WARNING: the */ | ||
325 | 3, /* 0x000b WARNING: minor_str */ | ||
326 | 3, /* 0x000c WARNING: array */ | ||
327 | 4, /* 0x000d WARNING: above. */ | ||
328 | 4, /* 0x000e WARNING: */ | ||
329 | 4, /* 0x000f WARNING: if you change */ | ||
330 | 4, /* 0x0010 WARNING: that one, */ | ||
331 | 4, /* 0x0011 WARNING: change this one */ | ||
332 | 4, /* 0x0012 WARNING: too!!! */ | ||
333 | 5, /* 0x0013 WARNING: */ | ||
334 | 4, /* 0x0014 WARNING: */ | ||
335 | 5, /* 0x0015 WARNING: */ | ||
336 | 5, /* 0x0016 WARNING: */ | ||
337 | 4, /* 0x0017 WARNING: */ | ||
338 | 6, /* 0x0018 WARNING: */ | ||
339 | 6, /* 0x0019 WARNING: */ | ||
340 | 0, /* 0x001a WARNING: */ | ||
341 | 6, /* 0x001b WARNING: */ | ||
342 | 6, /* 0x001c WARNING: */ | ||
343 | 0 /* 0x001d-0xfffe */ | ||
344 | }; | ||
345 | |||
346 | /* words 82-84: cmds/feats supported */ | ||
347 | #define CMDS_W82 0x77ff /* word 82: defined command locations*/ | ||
348 | #define CMDS_W83 0x3fff /* word 83: defined command locations*/ | ||
349 | #define CMDS_W84 0x002f /* word 83: defined command locations*/ | ||
350 | #define SUPPORT_48_BIT 0x0400 | ||
351 | #define NUM_CMD_FEAT_STR 48 | ||
352 | |||
353 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
354 | static const char *cmd_feat_str[] = { | ||
355 | "", /* word 82 bit 15: obsolete */ | ||
356 | "NOP cmd", /* word 82 bit 14 */ | ||
357 | "READ BUFFER cmd", /* word 82 bit 13 */ | ||
358 | "WRITE BUFFER cmd", /* word 82 bit 12 */ | ||
359 | "", /* word 82 bit 11: obsolete */ | ||
360 | "Host Protected Area feature set", /* word 82 bit 10 */ | ||
361 | "DEVICE RESET cmd", /* word 82 bit 9 */ | ||
362 | "SERVICE interrupt", /* word 82 bit 8 */ | ||
363 | "Release interrupt", /* word 82 bit 7 */ | ||
364 | "Look-ahead", /* word 82 bit 6 */ | ||
365 | "Write cache", /* word 82 bit 5 */ | ||
366 | "PACKET command feature set", /* word 82 bit 4 */ | ||
367 | "Power Management feature set", /* word 82 bit 3 */ | ||
368 | "Removable Media feature set", /* word 82 bit 2 */ | ||
369 | "Security Mode feature set", /* word 82 bit 1 */ | ||
370 | "SMART feature set", /* word 82 bit 0 */ | ||
371 | /* --------------*/ | ||
372 | "", /* word 83 bit 15: !valid bit */ | ||
373 | "", /* word 83 bit 14: valid bit */ | ||
374 | "FLUSH CACHE EXT command", /* word 83 bit 13 */ | ||
375 | "Mandatory FLUSH CACHE command ", /* word 83 bit 12 */ | ||
376 | "Device Configuration Overlay feature set ", | ||
377 | "48-bit Address feature set ", /* word 83 bit 10 */ | ||
378 | "", | ||
379 | "SET MAX security extension", /* word 83 bit 8 */ | ||
380 | "Address Offset Reserved Area Boot", /* word 83 bit 7 */ | ||
381 | "SET FEATURES subcommand required to spinup after power up", | ||
382 | "Power-Up In Standby feature set", /* word 83 bit 5 */ | ||
383 | "Removable Media Status Notification feature set", | ||
384 | "Advanced Power Management feature set",/* word 83 bit 3 */ | ||
385 | "CFA feature set", /* word 83 bit 2 */ | ||
386 | "READ/WRITE DMA QUEUED", /* word 83 bit 1 */ | ||
387 | "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */ | ||
388 | /* --------------*/ | ||
389 | "", /* word 84 bit 15: !valid bit */ | ||
390 | "", /* word 84 bit 14: valid bit */ | ||
391 | "", /* word 84 bit 13: reserved */ | ||
392 | "", /* word 84 bit 12: reserved */ | ||
393 | "", /* word 84 bit 11: reserved */ | ||
394 | "", /* word 84 bit 10: reserved */ | ||
395 | "", /* word 84 bit 9: reserved */ | ||
396 | "", /* word 84 bit 8: reserved */ | ||
397 | "", /* word 84 bit 7: reserved */ | ||
398 | "", /* word 84 bit 6: reserved */ | ||
399 | "General Purpose Logging feature set", /* word 84 bit 5 */ | ||
400 | "", /* word 84 bit 4: reserved */ | ||
401 | "Media Card Pass Through Command feature set ", | ||
402 | "Media serial number ", /* word 84 bit 2 */ | ||
403 | "SMART self-test ", /* word 84 bit 1 */ | ||
404 | "SMART error logging " /* word 84 bit 0 */ | ||
405 | }; | ||
406 | #endif | ||
407 | |||
408 | |||
409 | /* words 85-87: cmds/feats enabled */ | ||
410 | /* use cmd_feat_str[] to display what commands and features have | ||
411 | * been enabled with words 85-87 | ||
412 | */ | ||
413 | |||
414 | /* words 89, 90, SECU ERASE TIME */ | ||
415 | #define ERASE_BITS 0x00ff | ||
416 | |||
417 | /* word 92: master password revision */ | ||
418 | /* NOVAL_0 or NOVAL_1 means no support for master password revision */ | ||
419 | |||
420 | /* word 93: hw reset result */ | ||
421 | #define CBLID 0x2000 /* CBLID status */ | ||
422 | #define RST0 0x0001 /* 1=reset to device #0 */ | ||
423 | #define DEV_DET 0x0006 /* how device num determined */ | ||
424 | #define JUMPER_VAL 0x0002 /* device num determined by jumper */ | ||
425 | #define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */ | ||
426 | |||
427 | /* word 127: removable media status notification feature set support */ | ||
428 | #define RM_STAT_BITS 0x0003 | ||
429 | #define RM_STAT_SUP 0x0001 | ||
430 | |||
431 | /* word 128: security */ | ||
432 | #define SECU_ENABLED 0x0002 | ||
433 | #define SECU_LEVEL 0x0010 | ||
434 | #define NUM_SECU_STR 6 | ||
435 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
436 | static const char *secu_str[] = { | ||
437 | "supported", /* word 128, bit 0 */ | ||
438 | "enabled", /* word 128, bit 1 */ | ||
439 | "locked", /* word 128, bit 2 */ | ||
440 | "frozen", /* word 128, bit 3 */ | ||
441 | "expired: security count", /* word 128, bit 4 */ | ||
442 | "supported: enhanced erase" /* word 128, bit 5 */ | ||
443 | }; | ||
444 | #endif | ||
445 | |||
446 | /* word 160: CFA power mode */ | ||
447 | #define VALID_W160 0x8000 /* 1=word valid */ | ||
448 | #define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/ | ||
449 | #define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */ | ||
450 | #define MAX_AMPS 0x0fff /* value = max current in ma */ | ||
451 | |||
452 | /* word 255: integrity */ | ||
453 | #define SIG 0x00ff /* signature location */ | ||
454 | #define SIG_VAL 0x00A5 /* signature value */ | ||
455 | |||
456 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
457 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) { | ||
458 | uint16_t ii; | ||
459 | uint8_t err_dma = 0; | ||
460 | for(ii = 0; ii <= MODE_MAX; ii++) { | ||
461 | if(mode_sel & 0x0001) { | ||
462 | printf("*%cdma%u ",cc,ii); | ||
463 | if(*have_mode) err_dma = 1; | ||
464 | *have_mode = 1; | ||
465 | } else if(mode_sup & 0x0001) { | ||
466 | printf("%cdma%u ",cc,ii); | ||
467 | } | ||
468 | mode_sup >>=1; mode_sel >>=1; | ||
469 | } | ||
470 | return err_dma; | ||
471 | } | ||
472 | static void print_ascii(uint16_t *p, uint8_t length) { | ||
473 | uint8_t ii; | ||
474 | char cl; | ||
475 | |||
476 | /* find first non-space & print it */ | ||
477 | for(ii = 0; ii< length; ii++) { | ||
478 | if(((char) 0x00ff&((*p)>>8)) != ' ') break; | ||
479 | if((cl = (char) 0x00ff&(*p)) != ' ') { | ||
480 | if(cl != '\0') printf("%c",cl); | ||
481 | p++; ii++; | ||
482 | break; | ||
483 | } | ||
484 | p++; | ||
485 | } | ||
486 | /* print the rest */ | ||
487 | for(; ii< length; ii++) { | ||
488 | if(!(*p)) break; /* some older devices have NULLs */ | ||
489 | printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff); | ||
490 | p++; | ||
491 | } | ||
492 | printf("\n"); | ||
493 | } | ||
494 | |||
495 | /* identify() is the only extern function used across two source files. The | ||
496 | others, though, were declared in hdparm.c with global scope; since other | ||
497 | functions in that file have static (file) scope, I assume the difference is | ||
498 | intentional. */ | ||
499 | static void identify (uint16_t *id_supplied, const char *devname) | ||
500 | { | ||
501 | |||
502 | char *id_file = NULL, fmt[]="/proc/ide/%s/identify"; | ||
503 | FILE *fl; | ||
504 | uint16_t val[256], ii, jj, kk; | ||
505 | uint16_t like_std = 1, std = 0, min_std = 0xffff; | ||
506 | uint16_t dev = NO_DEV, eqpt = NO_DEV; | ||
507 | uint8_t have_mode = 0, err_dma = 0; | ||
508 | uint8_t chksum = 0; | ||
509 | uint32_t ll, mm, nn, oo; | ||
510 | __u64 bbbig; /* (:) */ | ||
511 | |||
512 | if (id_supplied) { | ||
513 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
514 | swab(id_supplied, val, sizeof(val)); | ||
515 | #else | ||
516 | memcpy(val, id_supplied, sizeof(val)); | ||
517 | #endif | ||
518 | } else { | ||
519 | id_file = xcalloc(1, strlen(devname)+1+strlen(fmt)); | ||
520 | sprintf(id_file, fmt, devname); | ||
521 | |||
522 | /* open the file, read in all the info and close it */ | ||
523 | if (id_file == NULL) { | ||
524 | fl = stdin; | ||
525 | } else if(NULL == (fl = fopen(id_file, "r"))) | ||
526 | bb_perror_msg_and_die(id_file); | ||
527 | /* calculate checksum over all bytes */ | ||
528 | for(ii = GEN_CONFIG; ii<=INTEGRITY; ii++) { | ||
529 | unsigned int scratch; | ||
530 | if(1 != fscanf(fl,"%04x",&scratch)) break; | ||
531 | val[ii] = (uint16_t)scratch; | ||
532 | chksum += val[ii] + (val[ii] >> 8); | ||
533 | } | ||
534 | fclose(fl); | ||
535 | if(ii < (INTEGRITY+1)) | ||
536 | bb_error_msg_and_die("Input file wrong format or length"); | ||
537 | } | ||
538 | chksum &= 0xff; | ||
539 | |||
540 | /* check if we recognise the device type */ | ||
541 | printf("\n"); | ||
542 | if(!(val[GEN_CONFIG] & NOT_ATA)) { | ||
543 | dev = ATA_DEV; | ||
544 | printf("ATA device, with "); | ||
545 | } else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL) { | ||
546 | dev = ATA_DEV; | ||
547 | like_std = 4; | ||
548 | printf("CompactFlash ATA device, with "); | ||
549 | } else if(!(val[GEN_CONFIG] & NOT_ATAPI)) { | ||
550 | dev = ATAPI_DEV; | ||
551 | eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT; | ||
552 | printf("ATAPI %s, with ", pkt_str[eqpt]); | ||
553 | like_std = 3; | ||
554 | } else { | ||
555 | bb_error_msg_and_die("Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"); | ||
556 | } | ||
557 | if(!(val[GEN_CONFIG] & MEDIA_REMOVABLE)) | ||
558 | printf("non-"); | ||
559 | printf("removable media\n"); | ||
560 | |||
561 | |||
562 | /* Info from the specific configuration word says whether or not the | ||
563 | * ID command completed correctly. It is only defined, however in | ||
564 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior | ||
565 | * standards. Since the values allowed for this word are extremely | ||
566 | * specific, it should be safe to check it now, even though we don't | ||
567 | * know yet what standard this device is using. | ||
568 | */ | ||
569 | if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) || | ||
570 | (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) ) { | ||
571 | like_std = 5; | ||
572 | if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)) | ||
573 | printf("powers-up in standby; SET FEATURES subcmd spins-up.\n"); | ||
574 | if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && | ||
575 | (val[GEN_CONFIG] & INCOMPLETE)) | ||
576 | printf("\n\tWARNING: ID response incomplete.\n\tWARNING: Following data may be incorrect.\n\n"); | ||
577 | } | ||
578 | |||
579 | /* output the model and serial numbers and the fw revision */ | ||
580 | if(val[START_MODEL]) { | ||
581 | printf("\t%-20s","Model Number:"); | ||
582 | print_ascii(&val[START_MODEL], LENGTH_MODEL); | ||
583 | } | ||
584 | if(val[START_SERIAL]) { | ||
585 | printf("\t%-20s","Serial Number:"); | ||
586 | print_ascii( &val[START_SERIAL], LENGTH_SERIAL); | ||
587 | } | ||
588 | if(val[START_FW_REV]) { | ||
589 | printf("\t%-20s","Firmware Revision:"); | ||
590 | print_ascii(&val[START_FW_REV], LENGTH_FW_REV); | ||
591 | } | ||
592 | if(val[START_MEDIA]) { | ||
593 | printf("\t%-20s","Media Serial Num:"); | ||
594 | print_ascii(&val[START_MEDIA], LENGTH_MEDIA); | ||
595 | } | ||
596 | if(val[START_MANUF]) { | ||
597 | printf("\t%-20s","Media Manufacturer:"); | ||
598 | print_ascii(&val[START_MANUF], LENGTH_MANUF); | ||
599 | } | ||
600 | |||
601 | /* major & minor standards version number (Note: these words were not | ||
602 | * defined until ATA-3 & the CDROM std uses different words.) */ | ||
603 | printf("Standards:"); | ||
604 | if(eqpt != CDROM) { | ||
605 | if(val[MINOR] && (val[MINOR] <= MINOR_MAX)){ | ||
606 | if(like_std < 3) like_std = 3; | ||
607 | std = actual_ver[val[MINOR]]; | ||
608 | if(std) { | ||
609 | printf("\n\tUsed: "); | ||
610 | printf("%s ",minor_str[val[MINOR]]); | ||
611 | } | ||
612 | } | ||
613 | /* looks like when they up-issue the std, they obsolete one; | ||
614 | * thus, only the newest 4 issues need be supported. (That's | ||
615 | * what "kk" and "min_std" are all about.) */ | ||
616 | if(val[MAJOR] && (val[MAJOR] !=NOVAL_1)) { | ||
617 | printf("\n\tSupported: "); | ||
618 | jj = val[MAJOR] << 1; | ||
619 | kk = like_std >4 ? like_std-4: 0; | ||
620 | for(ii = 14; (ii >0)&&(ii>kk); ii--) { | ||
621 | if(jj & 0x8000) { | ||
622 | printf("%u ", ii); | ||
623 | if(like_std < ii) { | ||
624 | like_std = ii; | ||
625 | kk = like_std >4 ? like_std-4: 0; | ||
626 | } | ||
627 | if(min_std > ii) min_std = ii; | ||
628 | } | ||
629 | jj <<= 1; | ||
630 | } | ||
631 | if(like_std < 3) like_std = 3; | ||
632 | } | ||
633 | /* Figure out what standard the device is using if it hasn't told | ||
634 | * us. If we know the std, check if the device is using any of | ||
635 | * the words from the next level up. It happens. | ||
636 | */ | ||
637 | if(like_std < std) like_std = std; | ||
638 | if(((std == 5) || (!std && (like_std < 6))) && | ||
639 | ( (((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | ||
640 | ((val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) || | ||
641 | (((val[CMDS_SUPP_2] & VALID) == VALID_VAL) && | ||
642 | (val[CMDS_SUPP_2] & CMDS_W84) ) ) ) { | ||
643 | like_std = 6; | ||
644 | } else if(((std == 4) || (!std && (like_std < 5))) && | ||
645 | ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) || | ||
646 | ((val[HWRST_RSLT] & VALID) == VALID_VAL) || | ||
647 | (((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | ||
648 | ((val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) ) { | ||
649 | like_std = 5; | ||
650 | } else if(((std == 3) || (!std && (like_std < 4))) && | ||
651 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | ||
652 | (((val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) || | ||
653 | ((val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) || | ||
654 | ((val[CAPAB_1] & VALID) == VALID_VAL) || | ||
655 | ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) || | ||
656 | ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) ) { | ||
657 | like_std = 4; | ||
658 | } else if(((std == 2) || (!std && (like_std < 3))) && | ||
659 | ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) ) { | ||
660 | like_std = 3; | ||
661 | } else if(((std == 1) || (!std && (like_std < 2))) && | ||
662 | ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) || | ||
663 | (val[WHATS_VALID] & OK_W64_70)) ) { | ||
664 | like_std = 2; | ||
665 | } | ||
666 | if(!std) { | ||
667 | printf("\n\tLikely used: %u\n",like_std); | ||
668 | } else if(like_std > std) { | ||
669 | printf("& some of %u\n",like_std); | ||
670 | } else printf("\n"); | ||
671 | } else { | ||
672 | /* TBD: do CDROM stuff more thoroughly. For now... */ | ||
673 | kk = 0; | ||
674 | if(val[CDR_MINOR] == 9) { | ||
675 | kk = 1; | ||
676 | printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5"); | ||
677 | } | ||
678 | if(val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) { | ||
679 | kk = 1; | ||
680 | printf("\n\tSupported: CD-ROM ATAPI"); | ||
681 | jj = val[CDR_MAJOR] >> 1; | ||
682 | for(ii = 1; ii <15; ii++) { | ||
683 | if(jj & 0x0001) { | ||
684 | printf("-%u ", ii); | ||
685 | } | ||
686 | jj >>= 1; | ||
687 | } | ||
688 | } | ||
689 | if(!kk) printf("\n\tLikely used CD-ROM ATAPI-1\n"); | ||
690 | else printf("\n"); | ||
691 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ | ||
692 | like_std = 2; | ||
693 | } | ||
694 | |||
695 | if(min_std == 0xffff) min_std = like_std > 4 ? like_std - 3 : 1; | ||
696 | |||
697 | printf("Configuration:\n"); | ||
698 | /* more info from the general configuration word */ | ||
699 | if((eqpt != CDROM) && (like_std == 1)) { | ||
700 | jj = val[GEN_CONFIG] >> 1; | ||
701 | for(ii = 1; ii < 15; ii++) { | ||
702 | if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]); | ||
703 | jj >>=1; | ||
704 | } | ||
705 | } | ||
706 | if(dev == ATAPI_DEV) { | ||
707 | printf("\tDRQ response: "); /* Data Request (DRQ) */ | ||
708 | switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME) { | ||
709 | case DRQ_3MS_VAL : printf("3ms.\n"); break; | ||
710 | case DRQ_INTR_VAL : printf("<=10ms with INTRQ\n"); break; | ||
711 | case DRQ_50US_VAL : printf("50us.\n"); break; | ||
712 | default : printf("unknown.\n"); break; | ||
713 | } | ||
714 | printf("\tPacket size: "); | ||
715 | switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) { | ||
716 | case PKT_SIZE_12_VAL : printf("12 bytes\n"); break; | ||
717 | case PKT_SIZE_16_VAL : printf("16 bytes\n"); break; | ||
718 | default : printf("Unknown\n"); break; | ||
719 | } | ||
720 | } else { | ||
721 | /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ | ||
722 | ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; | ||
723 | mm = 0; bbbig = 0; | ||
724 | if ( (ll > 0x00FBFC10) && (!val[LCYLS])) { | ||
725 | printf("\tCHS addressing not supported\n"); | ||
726 | } else { | ||
727 | jj = val[WHATS_VALID] & OK_W54_58; | ||
728 | printf("\tLogical\t\tmax\tcurrent\n"); | ||
729 | printf("\tcylinders\t%u\t%u\n",val[LCYLS],jj?val[LCYLS_CUR]:0); | ||
730 | printf("\theads\t\t%u\t%u\n",val[LHEADS],jj?val[LHEADS_CUR]:0); | ||
731 | printf("\tsectors/track\t%u\t%u\n",val[LSECTS],jj?val[LSECTS_CUR]:0); | ||
732 | printf("\t--\n"); | ||
733 | if((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) { | ||
734 | printf("\tbytes/track: %u",val[TRACK_BYTES]); | ||
735 | printf("\tbytes/sector: %u\n",val[SECT_BYTES]); | ||
736 | } | ||
737 | if(jj) { | ||
738 | mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; | ||
739 | if(like_std < 3) { /* check Endian of capacity bytes */ | ||
740 | nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR]; | ||
741 | oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB]; | ||
742 | if(abs(mm - nn) > abs(oo - nn)) | ||
743 | mm = oo; | ||
744 | } | ||
745 | printf("\tCHS current addressable sectors:%11u\n",mm); | ||
746 | } | ||
747 | } | ||
748 | /* LBA addressing */ | ||
749 | printf("\tLBA user addressable sectors:%11u\n",ll); | ||
750 | if( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | ||
751 | (val[CMDS_SUPP_1] & SUPPORT_48_BIT) ) { | ||
752 | bbbig = (__u64)val[LBA_64_MSB] << 48 | | ||
753 | (__u64)val[LBA_48_MSB] << 32 | | ||
754 | (__u64)val[LBA_MID] << 16 | | ||
755 | val[LBA_LSB] ; | ||
756 | printf("\tLBA48 user addressable sectors:%11llu\n",bbbig); | ||
757 | } | ||
758 | if (!bbbig) bbbig = (__u64)(ll>mm ? ll : mm); /* # 512 byte blocks */ | ||
759 | printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11); | ||
760 | bbbig = (bbbig<<9)/1000000; | ||
761 | printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig); | ||
762 | if(bbbig > 1000) printf("(%llu GB)\n",bbbig/1000); | ||
763 | else printf("\n"); | ||
764 | |||
765 | } | ||
766 | |||
767 | /* hw support of commands (capabilities) */ | ||
768 | printf("Capabilities:\n"); | ||
769 | printf("\t"); | ||
770 | if(dev == ATAPI_DEV) { | ||
771 | if(eqpt != CDROM) { | ||
772 | if(val[CAPAB_0] & CMD_Q_SUP) printf("Cmd queuing, "); | ||
773 | } | ||
774 | if(val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); | ||
775 | } | ||
776 | if(val[CAPAB_0] & LBA_SUP) printf("LBA, "); | ||
777 | if(like_std != 1) { | ||
778 | printf("IORDY"); | ||
779 | if(!(val[CAPAB_0] & IORDY_SUP)) printf("(may be)"); | ||
780 | if(val[CAPAB_0] & IORDY_OFF) printf("(can"); | ||
781 | else printf("(cannot"); | ||
782 | printf(" be disabled)"); | ||
783 | } else printf("no IORDY"); | ||
784 | printf("\n"); | ||
785 | if((like_std == 1) && val[BUF_TYPE]) { | ||
786 | kk = val[BUF_TYPE]; | ||
787 | printf("\tBuffer type: %04x: ",kk); | ||
788 | if (kk < 2) printf("single port, single-sector"); | ||
789 | else printf("dual port, multi-sector"); | ||
790 | if (kk > 2) printf(" with read caching ability"); | ||
791 | printf("\n"); | ||
792 | } | ||
793 | jj = 0; | ||
794 | if((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { | ||
795 | printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2); | ||
796 | jj = 1; | ||
797 | } | ||
798 | if((min_std < 4) && (val[RW_LONG])) { | ||
799 | printf("\tbytes avail on r/w long: %u",val[RW_LONG]); | ||
800 | jj = 1; | ||
801 | } | ||
802 | if((eqpt != CDROM) && (like_std > 3)) { | ||
803 | printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1); | ||
804 | jj = 1; | ||
805 | } | ||
806 | if(jj) printf("\n"); | ||
807 | if(dev == ATA_DEV) { | ||
808 | if(like_std == 1) { | ||
809 | printf("\tCan"); | ||
810 | if(!val[DWORD_IO]) printf("not"); | ||
811 | printf(" perform double-word IO\n"); | ||
812 | } else { | ||
813 | printf("\tStandby timer values: spec'd by "); | ||
814 | if(val[CAPAB_0] & STD_STBY) printf("Standard"); | ||
815 | else printf("Vendor"); | ||
816 | if((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) { | ||
817 | if(val[CAPAB_1] & MIN_STANDBY_TIMER) printf(", with "); | ||
818 | else printf(", no "); | ||
819 | printf("device specific minimum\n"); | ||
820 | } else printf("\n"); | ||
821 | } | ||
822 | printf("\tR/W multiple sector transfer: "); | ||
823 | if((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) { | ||
824 | printf("not supported\n"); | ||
825 | } else { | ||
826 | printf("Max = %u\t",val[SECTOR_XFER_MAX] & SECTOR_XFER); | ||
827 | printf("Current = "); | ||
828 | if(val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID) | ||
829 | printf("%u\n",val[SECTOR_XFER_CUR] & SECTOR_XFER); | ||
830 | else printf("?\n"); | ||
831 | } | ||
832 | if((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) { | ||
833 | /* We print out elsewhere whether the APM feature is enabled or | ||
834 | not. If it's not enabled, let's not repeat the info; just print | ||
835 | nothing here. */ | ||
836 | printf("\tAdvanced power management level: "); | ||
837 | if ( (val[ADV_PWR] & 0xFF00) == 0x4000 ) { | ||
838 | uint8_t apm_level = val[ADV_PWR] & 0x00FF; | ||
839 | |||
840 | printf("%u (0x%x)\n", apm_level, apm_level); | ||
841 | } else { | ||
842 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); | ||
843 | } | ||
844 | } | ||
845 | if(like_std > 5) { | ||
846 | if(val[ACOUSTIC]) { | ||
847 | printf("\tRecommended acoustic management value: %u, current value: %u\n", (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); | ||
848 | } | ||
849 | } | ||
850 | } else { /* ATAPI */ | ||
851 | if(eqpt != CDROM) { | ||
852 | if(val[CAPAB_0] & SWRST_REQ) printf("\tATA sw reset required\n"); | ||
853 | } | ||
854 | if(val[PKT_REL] || val[SVC_NBSY]) { | ||
855 | printf("\tOverlap support:"); | ||
856 | if(val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]); | ||
857 | if(val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]); | ||
858 | printf("\n"); | ||
859 | } | ||
860 | } | ||
861 | |||
862 | /* DMA stuff. Check that only one DMA mode is selected. */ | ||
863 | printf("\tDMA: "); | ||
864 | if(!(val[CAPAB_0] & DMA_SUP)) { | ||
865 | printf("not supported\n"); | ||
866 | } else { | ||
867 | if(val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]) | ||
868 | printf(" sdma%u\n",(val[DMA_MODE] & MODE) >> 8); | ||
869 | if(val[SINGLE_DMA]) { | ||
870 | jj = val[SINGLE_DMA]; kk = val[SINGLE_DMA] >> 8; | ||
871 | err_dma += mode_loop(jj,kk,'s',&have_mode); | ||
872 | } | ||
873 | if(val[MULTI_DMA]) { | ||
874 | jj = val[MULTI_DMA]; kk = val[MULTI_DMA] >> 8; | ||
875 | err_dma += mode_loop(jj,kk,'m',&have_mode); | ||
876 | } | ||
877 | if((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) { | ||
878 | jj = val[ULTRA_DMA]; kk = val[ULTRA_DMA] >> 8; | ||
879 | err_dma += mode_loop(jj,kk,'u',&have_mode); | ||
880 | } | ||
881 | if(err_dma || !have_mode) printf("(?)"); | ||
882 | printf("\n"); | ||
883 | |||
884 | if((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) | ||
885 | printf("\t Interleaved DMA support\n"); | ||
886 | |||
887 | if((val[WHATS_VALID] & OK_W64_70) && | ||
888 | (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])) { | ||
889 | printf("\t Cycle time:"); | ||
890 | if(val[DMA_TIME_MIN]) | ||
891 | printf(" min=%uns",val[DMA_TIME_MIN]); | ||
892 | if(val[DMA_TIME_NORM]) | ||
893 | printf(" recommended=%uns",val[DMA_TIME_NORM]); | ||
894 | printf("\n"); | ||
895 | } | ||
896 | } | ||
897 | |||
898 | /* Programmed IO stuff */ | ||
899 | printf("\tPIO: "); | ||
900 | /* If a drive supports mode n (e.g. 3), it also supports all modes less | ||
901 | * than n (e.g. 3, 2, 1 and 0). Print all the modes. */ | ||
902 | if((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) { | ||
903 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; | ||
904 | for(ii = 0; ii <= PIO_MODE_MAX ; ii++) { | ||
905 | if(jj & 0x0001) | ||
906 | printf("pio%d ",ii); | ||
907 | jj >>=1; | ||
908 | } | ||
909 | printf("\n"); | ||
910 | } else if(((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) ) { | ||
911 | for(ii = 0; ii <= val[PIO_MODE]>>8; ii++) { | ||
912 | printf("pio%d ",ii); | ||
913 | } | ||
914 | printf("\n"); | ||
915 | } else printf("unknown\n"); | ||
916 | if(val[WHATS_VALID] & OK_W64_70) { | ||
917 | if(val[PIO_NO_FLOW] || val[PIO_FLOW]) { | ||
918 | printf("\t Cycle time:"); | ||
919 | if(val[PIO_NO_FLOW]) | ||
920 | printf(" no flow control=%uns", val[PIO_NO_FLOW]); | ||
921 | if(val[PIO_FLOW]) | ||
922 | printf(" IORDY flow control=%uns", val[PIO_FLOW]); | ||
923 | printf("\n"); | ||
924 | } | ||
925 | } | ||
926 | |||
927 | if((val[CMDS_SUPP_1] & VALID) == VALID_VAL){ | ||
928 | printf("Commands/features:\n\tEnabled\tSupported:\n"); | ||
929 | jj = val[CMDS_SUPP_0]; | ||
930 | kk = val[CMDS_EN_0]; | ||
931 | for(ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { | ||
932 | if((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) { | ||
933 | if(kk & 0x8000) printf("\t *"); | ||
934 | else printf("\t"); | ||
935 | printf("\t%s\n",cmd_feat_str[ii]); | ||
936 | } | ||
937 | jj <<=1; kk<<=1; | ||
938 | if(ii%16 == 15) { | ||
939 | jj = val[CMDS_SUPP_0+1+(ii/16)]; | ||
940 | kk = val[CMDS_EN_0+1+(ii/16)]; | ||
941 | } | ||
942 | if(ii == 31) { | ||
943 | if((val[CMDS_SUPP_2] & VALID) != VALID_VAL) ii +=16; | ||
944 | } | ||
945 | } | ||
946 | } | ||
947 | if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) | ||
948 | printf("\tRemovable Media Status Notification feature set supported\n"); | ||
949 | |||
950 | |||
951 | /* security */ | ||
952 | if((eqpt != CDROM) && (like_std > 3) && | ||
953 | (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])) { | ||
954 | printf("Security: \n"); | ||
955 | if(val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)) | ||
956 | printf("\tMaster password revision code = %u\n",val[PSWD_CODE]); | ||
957 | jj = val[SECU_STATUS]; | ||
958 | if(jj) { | ||
959 | for(ii = 0; ii < NUM_SECU_STR; ii++) { | ||
960 | if(!(jj & 0x0001)) printf("\tnot\t"); | ||
961 | else printf("\t\t"); | ||
962 | printf("%s\n",secu_str[ii]); | ||
963 | jj >>=1; | ||
964 | } | ||
965 | if(val[SECU_STATUS] & SECU_ENABLED) { | ||
966 | printf("\tSecurity level "); | ||
967 | if(val[SECU_STATUS] & SECU_LEVEL) printf("maximum\n"); | ||
968 | else printf("high\n"); | ||
969 | } | ||
970 | } | ||
971 | jj = val[ERASE_TIME] & ERASE_BITS; | ||
972 | kk = val[ENH_ERASE_TIME] & ERASE_BITS; | ||
973 | if(jj || kk) { | ||
974 | printf("\t"); | ||
975 | if(jj) printf("%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1); | ||
976 | if(kk) printf("%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1); | ||
977 | printf("\n"); | ||
978 | } | ||
979 | } | ||
980 | |||
981 | /* reset result */ | ||
982 | if((val[HWRST_RSLT] & VALID) == VALID_VAL) { | ||
983 | printf("HW reset results:\n"); | ||
984 | if(val[HWRST_RSLT] & CBLID) printf("\tCBLID- above Vih\n"); | ||
985 | else printf("\tCBLID- below Vih\n"); | ||
986 | if(val[HWRST_RSLT] & RST0) { | ||
987 | printf("\tDevice num = 0"); | ||
988 | jj = val[HWRST_RSLT]; | ||
989 | } else { | ||
990 | printf("\tDevice num = 1"); | ||
991 | jj = val[HWRST_RSLT] >> 8; | ||
992 | } | ||
993 | if((jj & DEV_DET) == JUMPER_VAL) | ||
994 | printf(" determined by the jumper"); | ||
995 | else if((jj & DEV_DET) == CSEL_VAL) | ||
996 | printf(" determined by CSEL"); | ||
997 | printf("\n"); | ||
998 | } | ||
999 | |||
1000 | /* more stuff from std 5 */ | ||
1001 | if((like_std > 4) && (eqpt != CDROM)) { | ||
1002 | if(val[CFA_PWR_MODE] & VALID_W160) { | ||
1003 | printf("CFA power mode 1:\n\t"); | ||
1004 | if(val[CFA_PWR_MODE] & PWR_MODE_OFF) printf("dis"); | ||
1005 | else printf("en"); | ||
1006 | printf("abled"); | ||
1007 | if(val[CFA_PWR_MODE] & PWR_MODE_REQ) | ||
1008 | printf(" and required by some commands"); | ||
1009 | printf("\n"); | ||
1010 | if(val[CFA_PWR_MODE] & MAX_AMPS) | ||
1011 | printf("\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS); | ||
1012 | } | ||
1013 | if((val[INTEGRITY] & SIG) == SIG_VAL) { | ||
1014 | printf("Checksum: "); | ||
1015 | if(chksum) printf("in"); | ||
1016 | printf("correct\n"); | ||
1017 | } | ||
1018 | } | ||
1019 | |||
1020 | exit(0); | ||
1021 | } | ||
1022 | #endif | ||
1023 | |||
1024 | #define VERSION "v5.4" | ||
1025 | |||
1026 | #undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ | ||
1027 | #define TIMING_BUF_MB 2 | ||
1028 | #define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024) | ||
1029 | #define BUFCACHE_FACTOR 2 | ||
1030 | |||
1031 | static int verbose = 0, get_identity = 0, get_geom = 0, noisy = 1, quiet = 0; | ||
1032 | static int flagcount = 0, do_flush = 0, is_scsi_hd = 0, is_xt_hd = 0; | ||
1033 | static int do_ctimings, do_timings = 0; | ||
1034 | |||
1035 | static unsigned long set_readahead= 0, get_readahead= 0, readahead= 0; | ||
1036 | static unsigned long set_readonly = 0, get_readonly = 0, readonly = 0; | ||
1037 | static unsigned long set_unmask = 0, get_unmask = 0, unmask = 0; | ||
1038 | static unsigned long set_mult = 0, get_mult = 0, mult = 0; | ||
1039 | static unsigned long set_dma = 0, get_dma = 0, dma = 0; | ||
1040 | static unsigned long set_dma_q = 0, get_dma_q = 0, dma_q = 0; | ||
1041 | static unsigned long set_nowerr = 0, get_nowerr = 0, nowerr = 0; | ||
1042 | static unsigned long set_keep = 0, get_keep = 0, keep = 0; | ||
1043 | static unsigned long set_io32bit = 0, get_io32bit = 0, io32bit = 0; | ||
1044 | static unsigned long set_piomode = 0, noisy_piomode= 0; | ||
1045 | static int piomode = 0; | ||
1046 | #ifdef HDIO_DRIVE_CMD | ||
1047 | static unsigned long set_dkeep = 0, get_dkeep = 0, dkeep = 0; | ||
1048 | static unsigned long set_standby = 0, get_standby = 0, standby_requested= 0; | ||
1049 | static unsigned long set_xfermode = 0, get_xfermode = 0; | ||
1050 | static int xfermode_requested= 0; | ||
1051 | static unsigned long set_lookahead= 0, get_lookahead= 0, lookahead= 0; | ||
1052 | static unsigned long set_prefetch = 0, get_prefetch = 0, prefetch = 0; | ||
1053 | static unsigned long set_defects = 0, get_defects = 0, defects = 0; | ||
1054 | static unsigned long set_wcache = 0, get_wcache = 0, wcache = 0; | ||
1055 | static unsigned long set_doorlock = 0, get_doorlock = 0, doorlock = 0; | ||
1056 | static unsigned long set_seagate = 0, get_seagate = 0; | ||
1057 | static unsigned long set_standbynow = 0, get_standbynow = 0; | ||
1058 | static unsigned long set_sleepnow = 0, get_sleepnow = 0; | ||
1059 | static unsigned long get_powermode = 0; | ||
1060 | static unsigned long set_apmmode = 0, get_apmmode= 0, apmmode = 0; | ||
1061 | #endif | ||
1062 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
1063 | static int get_IDentity = 0; | ||
1064 | #endif | ||
1065 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | ||
1066 | static int unregister_hwif = 0; | ||
1067 | static int hwif = 0; | ||
1068 | #endif | ||
1069 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF | ||
1070 | static int scan_hwif = 0; | ||
1071 | static int hwif_data = 0; | ||
1072 | static int hwif_ctrl = 0; | ||
1073 | static int hwif_irq = 0; | ||
1074 | #endif | ||
1075 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
1076 | static int set_busstate = 0, get_busstate = 0, busstate = 0; | ||
1077 | #endif | ||
1078 | static int reread_partn = 0; | ||
1079 | |||
1080 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET | ||
1081 | static int perform_reset = 0; | ||
1082 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ | ||
1083 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
1084 | static int perform_tristate = 0, tristate = 0; | ||
1085 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ | ||
1086 | |||
1087 | // Historically, if there was no HDIO_OBSOLETE_IDENTITY, then | ||
1088 | // then the HDIO_GET_IDENTITY only returned 142 bytes. | ||
1089 | // Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes, | ||
1090 | // and HDIO_GET_IDENTITY returns 512 bytes. But the latest | ||
1091 | // 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY | ||
1092 | // (which they should, but they should just return -EINVAL). | ||
1093 | // | ||
1094 | // So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes. | ||
1095 | // On a really old system, it will not, and we will be confused. | ||
1096 | // Too bad, really. | ||
1097 | |||
1098 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
1099 | static const char *cfg_str[] = | ||
1100 | { "", " HardSect", " SoftSect", " NotMFM", | ||
1101 | " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable", | ||
1102 | " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%", | ||
1103 | " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic" | ||
1104 | }; | ||
1105 | |||
1106 | static const char *BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"}; | ||
1107 | |||
1108 | #define YN(b) (((b)==0)?"no":"yes") | ||
1109 | |||
1110 | static void dmpstr (const char *prefix, unsigned int i, const char *s[], unsigned int maxi) | ||
1111 | { | ||
1112 | if (i > maxi) | ||
1113 | printf("%s%u", prefix, i); | ||
1114 | else | ||
1115 | printf("%s%s", prefix, s[i]); | ||
1116 | } | ||
1117 | |||
1118 | static void dump_identity (const struct hd_driveid *id) | ||
1119 | { | ||
1120 | int i; | ||
1121 | char pmodes[64] = {0,}, dmodes[128]={0,}, umodes[128]={0,}; | ||
1122 | const unsigned short int *id_regs= (const void*) id; | ||
1123 | unsigned long capacity; | ||
1124 | |||
1125 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s", | ||
1126 | id->model, id->fw_rev, id->serial_no); | ||
1127 | printf("\n Config={"); | ||
1128 | for (i=0; i<=15; i++) { | ||
1129 | if (id->config & (1<<i)) | ||
1130 | printf("%s", cfg_str[i]); | ||
1131 | } | ||
1132 | printf(" }\n"); | ||
1133 | printf(" RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n", | ||
1134 | id->cyls, id->heads, id->sectors, | ||
1135 | id->track_bytes, id->sector_bytes, id->ecc_bytes); | ||
1136 | dmpstr(" BuffType=",id->buf_type,BuffType,3); | ||
1137 | printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect); | ||
1138 | if (id->max_multsect) { | ||
1139 | printf(", MultSect="); | ||
1140 | if (!(id->multsect_valid&1)) | ||
1141 | printf("?%u?", id->multsect); | ||
1142 | else if (id->multsect) | ||
1143 | printf("%u", id->multsect); | ||
1144 | else | ||
1145 | printf("off"); | ||
1146 | } | ||
1147 | putchar('\n'); | ||
1148 | if (id->tPIO <= 5) { | ||
1149 | strcat(pmodes, "pio0 "); | ||
1150 | if (id->tPIO >= 1) strcat(pmodes, "pio1 "); | ||
1151 | if (id->tPIO >= 2) strcat(pmodes, "pio2 "); | ||
1152 | } | ||
1153 | if (!(id->field_valid&1)) | ||
1154 | printf(" (maybe):"); | ||
1155 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
1156 | capacity = (id->cur_capacity0 << 16) | id->cur_capacity1; | ||
1157 | #else | ||
1158 | capacity = (id->cur_capacity1 << 16) | id->cur_capacity0; | ||
1159 | #endif | ||
1160 | printf(" CurCHS=%u/%u/%u, CurSects=%lu", id->cur_cyls, id->cur_heads, id->cur_sectors, capacity); | ||
1161 | printf(", LBA=%s", YN(id->capability&2)); | ||
1162 | if (id->capability&2) | ||
1163 | printf(", LBAsects=%u", id->lba_capacity); | ||
1164 | |||
1165 | if (id->capability&1) { | ||
1166 | if (id->dma_1word | id->dma_mword) { | ||
1167 | if (id->dma_1word & 0x100) strcat(dmodes,"*"); | ||
1168 | if (id->dma_1word & 1) strcat(dmodes,"sdma0 "); | ||
1169 | if (id->dma_1word & 0x200) strcat(dmodes,"*"); | ||
1170 | if (id->dma_1word & 2) strcat(dmodes,"sdma1 "); | ||
1171 | if (id->dma_1word & 0x400) strcat(dmodes,"*"); | ||
1172 | if (id->dma_1word & 4) strcat(dmodes,"sdma2 "); | ||
1173 | if (id->dma_1word & 0xf800) strcat(dmodes,"*"); | ||
1174 | if (id->dma_1word & 0xf8) strcat(dmodes,"sdma? "); | ||
1175 | if (id->dma_mword & 0x100) strcat(dmodes,"*"); | ||
1176 | if (id->dma_mword & 1) strcat(dmodes,"mdma0 "); | ||
1177 | if (id->dma_mword & 0x200) strcat(dmodes,"*"); | ||
1178 | if (id->dma_mword & 2) strcat(dmodes,"mdma1 "); | ||
1179 | if (id->dma_mword & 0x400) strcat(dmodes,"*"); | ||
1180 | if (id->dma_mword & 4) strcat(dmodes,"mdma2 "); | ||
1181 | if (id->dma_mword & 0xf800) strcat(dmodes,"*"); | ||
1182 | if (id->dma_mword & 0xf8) strcat(dmodes,"mdma? "); | ||
1183 | } | ||
1184 | } | ||
1185 | printf("\n IORDY="); | ||
1186 | if (id->capability&8) | ||
1187 | printf((id->capability&4) ? "on/off" : "yes"); | ||
1188 | else | ||
1189 | printf("no"); | ||
1190 | if ((id->capability&8) || (id->field_valid&2)) { | ||
1191 | if (id->field_valid&2) { | ||
1192 | printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); | ||
1193 | if (id->eide_pio_modes & 1) strcat(pmodes, "pio3 "); | ||
1194 | if (id->eide_pio_modes & 2) strcat(pmodes, "pio4 "); | ||
1195 | if (id->eide_pio_modes &~3) strcat(pmodes, "pio? "); | ||
1196 | } | ||
1197 | if (id->field_valid&4) { | ||
1198 | if (id->dma_ultra & 0x100) strcat(umodes,"*"); | ||
1199 | if (id->dma_ultra & 0x001) strcat(umodes,"udma0 "); | ||
1200 | if (id->dma_ultra & 0x200) strcat(umodes,"*"); | ||
1201 | if (id->dma_ultra & 0x002) strcat(umodes,"udma1 "); | ||
1202 | if (id->dma_ultra & 0x400) strcat(umodes,"*"); | ||
1203 | if (id->dma_ultra & 0x004) strcat(umodes,"udma2 "); | ||
1204 | #ifdef __NEW_HD_DRIVE_ID | ||
1205 | if (id->hw_config & 0x2000) { | ||
1206 | #else /* !__NEW_HD_DRIVE_ID */ | ||
1207 | if (id->word93 & 0x2000) { | ||
1208 | #endif /* __NEW_HD_DRIVE_ID */ | ||
1209 | if (id->dma_ultra & 0x0800) strcat(umodes,"*"); | ||
1210 | if (id->dma_ultra & 0x0008) strcat(umodes,"udma3 "); | ||
1211 | if (id->dma_ultra & 0x1000) strcat(umodes,"*"); | ||
1212 | if (id->dma_ultra & 0x0010) strcat(umodes,"udma4 "); | ||
1213 | if (id->dma_ultra & 0x2000) strcat(umodes,"*"); | ||
1214 | if (id->dma_ultra & 0x0020) strcat(umodes,"udma5 "); | ||
1215 | if (id->dma_ultra & 0x4000) strcat(umodes,"*"); | ||
1216 | if (id->dma_ultra & 0x0040) strcat(umodes,"udma6 "); | ||
1217 | if (id->dma_ultra & 0x8000) strcat(umodes,"*"); | ||
1218 | if (id->dma_ultra & 0x0080) strcat(umodes,"udma7 "); | ||
1219 | } | ||
1220 | } | ||
1221 | } | ||
1222 | if ((id->capability&1) && (id->field_valid&2)) | ||
1223 | printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); | ||
1224 | printf("\n PIO modes: %s", pmodes); | ||
1225 | if (*dmodes) | ||
1226 | printf("\n DMA modes: %s", dmodes); | ||
1227 | if (*umodes) | ||
1228 | printf("\n UDMA modes: %s", umodes); | ||
1229 | |||
1230 | printf("\n AdvancedPM=%s",YN(id_regs[83]&8)); | ||
1231 | if (id_regs[83] & 8) { | ||
1232 | if (!(id_regs[86]&8)) | ||
1233 | printf(": disabled (255)"); | ||
1234 | else if ((id_regs[91]&0xFF00)!=0x4000) | ||
1235 | printf(": unknown setting"); | ||
1236 | else | ||
1237 | printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF); | ||
1238 | } | ||
1239 | if (id_regs[82]&0x20) | ||
1240 | printf(" WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled"); | ||
1241 | #ifdef __NEW_HD_DRIVE_ID | ||
1242 | if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31)) { | ||
1243 | printf("\n Drive conforms to: "); | ||
1244 | if (id->minor_rev_num <= 31) | ||
1245 | printf("%s: ", minor_str[id->minor_rev_num]); | ||
1246 | else | ||
1247 | printf("unknown: "); | ||
1248 | if (id->major_rev_num < 31) { | ||
1249 | for (i=0; i <= 15; i++) { | ||
1250 | if (id->major_rev_num & (1<<i)) | ||
1251 | printf(" %u", i); | ||
1252 | } | ||
1253 | } | ||
1254 | } | ||
1255 | #endif /* __NEW_HD_DRIVE_ID */ | ||
1256 | printf("\n"); | ||
1257 | printf("\n * signifies the current active mode\n"); | ||
1258 | printf("\n"); | ||
1259 | } | ||
1260 | #endif | ||
1261 | |||
1262 | static void flush_buffer_cache (int fd) | ||
1263 | { | ||
1264 | fsync (fd); /* flush buffers */ | ||
1265 | if (ioctl(fd, BLKFLSBUF, NULL)) /* do it again, big time */ | ||
1266 | bb_perror_msg("BLKFLSBUF failed"); | ||
1267 | #ifdef HDIO_DRIVE_CMD | ||
1268 | if (is_scsi_hd || is_xt_hd) { | ||
1269 | sleep(1); | ||
1270 | } else { | ||
1271 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ | ||
1272 | bb_perror_msg("HDIO_DRIVE_CMD(null) (wait for flush complete) failed"); | ||
1273 | } | ||
1274 | #endif | ||
1275 | } | ||
1276 | |||
1277 | static int seek_to_zero (int fd) | ||
1278 | { | ||
1279 | if (lseek(fd, (off_t) 0, SEEK_SET)) { | ||
1280 | bb_perror_msg("lseek() failed"); | ||
1281 | return 1; | ||
1282 | } | ||
1283 | return 0; | ||
1284 | } | ||
1285 | |||
1286 | static int read_big_block (int fd, char *buf) | ||
1287 | { | ||
1288 | int i, rc; | ||
1289 | if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) { | ||
1290 | if (rc) { | ||
1291 | if (rc == -1) | ||
1292 | bb_perror_msg("read() failed"); | ||
1293 | else | ||
1294 | bb_error_msg("read(%u) returned %u bytes", TIMING_BUF_BYTES, rc); | ||
1295 | } else { | ||
1296 | fputs ("read() hit EOF - device too small\n", stderr); | ||
1297 | } | ||
1298 | return 1; | ||
1299 | } | ||
1300 | /* access all sectors of buf to ensure the read fully completed */ | ||
1301 | for (i = 0; i < TIMING_BUF_BYTES; i += 512) | ||
1302 | buf[i] &= 1; | ||
1303 | return 0; | ||
1304 | } | ||
1305 | |||
1306 | static void time_cache (int fd) | ||
1307 | { | ||
1308 | char *buf; | ||
1309 | struct itimerval e1, e2; | ||
1310 | int shmid; | ||
1311 | double elapsed, elapsed2; | ||
1312 | unsigned int iterations, total_MB; | ||
1313 | |||
1314 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) { | ||
1315 | bb_perror_msg ("could not allocate sharedmem buf"); | ||
1316 | return; | ||
1317 | } | ||
1318 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) { | ||
1319 | bb_perror_msg ("could not lock sharedmem buf"); | ||
1320 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1321 | return; | ||
1322 | } | ||
1323 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) { | ||
1324 | bb_perror_msg ("could not attach sharedmem buf"); | ||
1325 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1326 | return; | ||
1327 | } | ||
1328 | if (shmctl(shmid, IPC_RMID, NULL) == -1) | ||
1329 | bb_perror_msg ("shmctl(,IPC_RMID,) failed"); | ||
1330 | |||
1331 | /* Clear out the device request queues & give them time to complete */ | ||
1332 | sync(); | ||
1333 | sleep(3); | ||
1334 | |||
1335 | /* | ||
1336 | * getitimer() is used rather than gettimeofday() because | ||
1337 | * it is much more consistent (on my machine, at least). | ||
1338 | */ | ||
1339 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); | ||
1340 | if (seek_to_zero (fd)) return; | ||
1341 | if (read_big_block (fd, buf)) return; | ||
1342 | printf(" Timing buffer-cache reads: "); | ||
1343 | fflush(stdout); | ||
1344 | |||
1345 | /* Clear out the device request queues & give them time to complete */ | ||
1346 | sync(); | ||
1347 | sleep(1); | ||
1348 | |||
1349 | /* Now do the timing */ | ||
1350 | iterations = 0; | ||
1351 | getitimer(ITIMER_REAL, &e1); | ||
1352 | do { | ||
1353 | ++iterations; | ||
1354 | if (seek_to_zero (fd) || read_big_block (fd, buf)) | ||
1355 | goto quit; | ||
1356 | getitimer(ITIMER_REAL, &e2); | ||
1357 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) | ||
1358 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | ||
1359 | } while (elapsed < 2.0); | ||
1360 | total_MB = iterations * TIMING_BUF_MB; | ||
1361 | |||
1362 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) | ||
1363 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | ||
1364 | |||
1365 | /* Now remove the lseek() and getitimer() overheads from the elapsed time */ | ||
1366 | getitimer(ITIMER_REAL, &e1); | ||
1367 | do { | ||
1368 | if (seek_to_zero (fd)) | ||
1369 | goto quit; | ||
1370 | getitimer(ITIMER_REAL, &e2); | ||
1371 | elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec) | ||
1372 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | ||
1373 | } while (--iterations); | ||
1374 | |||
1375 | elapsed -= elapsed2; | ||
1376 | |||
1377 | if ((BUFCACHE_FACTOR * total_MB) >= elapsed) /* more than 1MB/s */ | ||
1378 | printf("%3u MB in %5.2f seconds = %6.2f MB/sec\n", | ||
1379 | (BUFCACHE_FACTOR * total_MB), elapsed, | ||
1380 | (BUFCACHE_FACTOR * total_MB) / elapsed); | ||
1381 | else | ||
1382 | printf("%3u MB in %5.2f seconds = %6.2f kB/sec\n", | ||
1383 | (BUFCACHE_FACTOR * total_MB), elapsed, | ||
1384 | (BUFCACHE_FACTOR * total_MB) / elapsed * 1024); | ||
1385 | |||
1386 | flush_buffer_cache(fd); | ||
1387 | sleep(1); | ||
1388 | quit: | ||
1389 | if (-1 == shmdt(buf)) | ||
1390 | bb_perror_msg ("could not detach sharedmem buf"); | ||
1391 | } | ||
1392 | |||
1393 | static void time_device (int fd) | ||
1394 | { | ||
1395 | char *buf; | ||
1396 | double elapsed; | ||
1397 | struct itimerval e1, e2; | ||
1398 | int shmid; | ||
1399 | unsigned int max_iterations = 1024, total_MB, iterations; | ||
1400 | static long parm; | ||
1401 | |||
1402 | // | ||
1403 | // get device size | ||
1404 | // | ||
1405 | if (do_ctimings || do_timings) { | ||
1406 | if (ioctl(fd, BLKGETSIZE, &parm)) | ||
1407 | bb_perror_msg(" BLKGETSIZE failed"); | ||
1408 | else | ||
1409 | max_iterations = parm / (2 * 1024) / TIMING_BUF_MB; | ||
1410 | } | ||
1411 | |||
1412 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) { | ||
1413 | bb_perror_msg ("could not allocate sharedmem buf"); | ||
1414 | return; | ||
1415 | } | ||
1416 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) { | ||
1417 | bb_perror_msg ("could not lock sharedmem buf"); | ||
1418 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1419 | return; | ||
1420 | } | ||
1421 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) { | ||
1422 | bb_perror_msg ("could not attach sharedmem buf"); | ||
1423 | (void) shmctl(shmid, IPC_RMID, NULL); | ||
1424 | return; | ||
1425 | } | ||
1426 | if (shmctl(shmid, IPC_RMID, NULL) == -1) | ||
1427 | bb_perror_msg ("shmctl(,IPC_RMID,) failed"); | ||
1428 | |||
1429 | /* Clear out the device request queues & give them time to complete */ | ||
1430 | sync(); | ||
1431 | sleep(3); | ||
1432 | |||
1433 | printf(" Timing buffered disk reads: "); | ||
1434 | fflush(stdout); | ||
1435 | |||
1436 | /* | ||
1437 | * getitimer() is used rather than gettimeofday() because | ||
1438 | * it is much more consistent (on my machine, at least). | ||
1439 | */ | ||
1440 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); | ||
1441 | |||
1442 | /* Now do the timings for real */ | ||
1443 | iterations = 0; | ||
1444 | getitimer(ITIMER_REAL, &e1); | ||
1445 | do { | ||
1446 | ++iterations; | ||
1447 | if (read_big_block (fd, buf)) | ||
1448 | goto quit; | ||
1449 | getitimer(ITIMER_REAL, &e2); | ||
1450 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) | ||
1451 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); | ||
1452 | } while (elapsed < 3.0 && iterations < max_iterations); | ||
1453 | |||
1454 | total_MB = iterations * TIMING_BUF_MB; | ||
1455 | if ((total_MB / elapsed) > 1.0) /* more than 1MB/s */ | ||
1456 | printf("%3u MB in %5.2f seconds = %6.2f MB/sec\n", | ||
1457 | total_MB, elapsed, total_MB / elapsed); | ||
1458 | else | ||
1459 | printf("%3u MB in %5.2f seconds = %6.2f kB/sec\n", | ||
1460 | total_MB, elapsed, total_MB / elapsed * 1024); | ||
1461 | quit: | ||
1462 | if (-1 == shmdt(buf)) | ||
1463 | bb_perror_msg ("could not detach sharedmem buf"); | ||
1464 | } | ||
1465 | |||
1466 | static void no_scsi (void) | ||
1467 | { | ||
1468 | if (is_scsi_hd) { | ||
1469 | bb_error_msg_and_die(" operation not supported on SCSI disks\n"); | ||
1470 | } | ||
1471 | } | ||
1472 | |||
1473 | static void no_xt (void) | ||
1474 | { | ||
1475 | if (is_xt_hd) { | ||
1476 | bb_error_msg_and_die (" operation not supported on XT disks\n"); | ||
1477 | } | ||
1478 | } | ||
1479 | |||
1480 | static void on_off (unsigned int value) | ||
1481 | { | ||
1482 | printf(value ? " (on)\n" : " (off)\n"); | ||
1483 | } | ||
1484 | |||
1485 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
1486 | static void bus_state_value (unsigned int value) | ||
1487 | { | ||
1488 | const char *string; | ||
1489 | |||
1490 | switch (value) { | ||
1491 | case BUSSTATE_ON: | ||
1492 | string = " (on)\n"; | ||
1493 | break; | ||
1494 | case BUSSTATE_OFF: | ||
1495 | string = " (off)\n"; | ||
1496 | break; | ||
1497 | case BUSSTATE_TRISTATE: | ||
1498 | string = " (tristate)\n"; | ||
1499 | break; | ||
1500 | default: | ||
1501 | string = " (unknown: %d)\n"; | ||
1502 | break; | ||
1503 | } | ||
1504 | printf(string, value); | ||
1505 | } | ||
1506 | #endif | ||
1507 | |||
1508 | #ifdef HDIO_DRIVE_CMD | ||
1509 | static void interpret_standby (unsigned int standby) | ||
1510 | { | ||
1511 | printf(" ("); | ||
1512 | switch(standby) { | ||
1513 | case 0: printf("off"); | ||
1514 | break; | ||
1515 | case 252: printf("21 minutes"); | ||
1516 | break; | ||
1517 | case 253: printf("vendor-specific"); | ||
1518 | break; | ||
1519 | case 254: printf("?reserved"); | ||
1520 | break; | ||
1521 | case 255: printf("21 minutes + 15 seconds"); | ||
1522 | break; | ||
1523 | default: | ||
1524 | if (standby <= 240) { | ||
1525 | unsigned int secs = standby * 5; | ||
1526 | unsigned int mins = secs / 60; | ||
1527 | secs %= 60; | ||
1528 | if (mins) printf("%u minutes", mins); | ||
1529 | if (mins && secs) printf(" + "); | ||
1530 | if (secs) printf("%u seconds", secs); | ||
1531 | } else if (standby <= 251) { | ||
1532 | unsigned int mins = (standby - 240) * 30; | ||
1533 | unsigned int hrs = mins / 60; | ||
1534 | mins %= 60; | ||
1535 | if (hrs) printf("%u hours", hrs); | ||
1536 | if (hrs && mins) printf(" + "); | ||
1537 | if (mins) printf("%u minutes", mins); | ||
1538 | } else | ||
1539 | printf("illegal value"); | ||
1540 | break; | ||
1541 | } | ||
1542 | printf(")\n"); | ||
1543 | } | ||
1544 | |||
1545 | struct xfermode_entry { | ||
1546 | int val; | ||
1547 | const char *name; | ||
1548 | }; | ||
1549 | |||
1550 | static const struct xfermode_entry xfermode_table[] = { | ||
1551 | { 8, "pio0" }, | ||
1552 | { 9, "pio1" }, | ||
1553 | { 10, "pio2" }, | ||
1554 | { 11, "pio3" }, | ||
1555 | { 12, "pio4" }, | ||
1556 | { 13, "pio5" }, | ||
1557 | { 14, "pio6" }, | ||
1558 | { 15, "pio7" }, | ||
1559 | { 16, "sdma0" }, | ||
1560 | { 17, "sdma1" }, | ||
1561 | { 18, "sdma2" }, | ||
1562 | { 19, "sdma3" }, | ||
1563 | { 20, "sdma4" }, | ||
1564 | { 21, "sdma5" }, | ||
1565 | { 22, "sdma6" }, | ||
1566 | { 23, "sdma7" }, | ||
1567 | { 32, "mdma0" }, | ||
1568 | { 33, "mdma1" }, | ||
1569 | { 34, "mdma2" }, | ||
1570 | { 35, "mdma3" }, | ||
1571 | { 36, "mdma4" }, | ||
1572 | { 37, "mdma5" }, | ||
1573 | { 38, "mdma6" }, | ||
1574 | { 39, "mdma7" }, | ||
1575 | { 64, "udma0" }, | ||
1576 | { 65, "udma1" }, | ||
1577 | { 66, "udma2" }, | ||
1578 | { 67, "udma3" }, | ||
1579 | { 68, "udma4" }, | ||
1580 | { 69, "udma5" }, | ||
1581 | { 70, "udma6" }, | ||
1582 | { 71, "udma7" }, | ||
1583 | { 0, NULL } | ||
1584 | }; | ||
1585 | |||
1586 | static int translate_xfermode(char * name) | ||
1587 | { | ||
1588 | const struct xfermode_entry *tmp; | ||
1589 | char *endptr; | ||
1590 | int val = -1; | ||
1591 | |||
1592 | |||
1593 | for (tmp = xfermode_table; tmp->name != NULL; ++tmp) { | ||
1594 | if (!strcmp(name, tmp->name)) | ||
1595 | return tmp->val; | ||
1596 | } | ||
1597 | |||
1598 | val = strtol(name, &endptr, 10); | ||
1599 | if (*endptr == '\0') | ||
1600 | return val; | ||
1601 | |||
1602 | return -1; | ||
1603 | } | ||
1604 | |||
1605 | static void interpret_xfermode (unsigned int xfermode) | ||
1606 | { | ||
1607 | printf(" ("); | ||
1608 | switch(xfermode) { | ||
1609 | case 0: printf("default PIO mode"); | ||
1610 | break; | ||
1611 | case 1: printf("default PIO mode, disable IORDY"); | ||
1612 | break; | ||
1613 | case 8: | ||
1614 | case 9: | ||
1615 | case 10: | ||
1616 | case 11: | ||
1617 | case 12: | ||
1618 | case 13: | ||
1619 | case 14: | ||
1620 | case 15: printf("PIO flow control mode%u", xfermode-8); | ||
1621 | break; | ||
1622 | case 16: | ||
1623 | case 17: | ||
1624 | case 18: | ||
1625 | case 19: | ||
1626 | case 20: | ||
1627 | case 21: | ||
1628 | case 22: | ||
1629 | case 23: printf("singleword DMA mode%u", xfermode-16); | ||
1630 | break; | ||
1631 | case 32: | ||
1632 | case 33: | ||
1633 | case 34: | ||
1634 | case 35: | ||
1635 | case 36: | ||
1636 | case 37: | ||
1637 | case 38: | ||
1638 | case 39: printf("multiword DMA mode%u", xfermode-32); | ||
1639 | break; | ||
1640 | case 64: | ||
1641 | case 65: | ||
1642 | case 66: | ||
1643 | case 67: | ||
1644 | case 68: | ||
1645 | case 69: | ||
1646 | case 70: | ||
1647 | case 71: printf("UltraDMA mode%u", xfermode-64); | ||
1648 | break; | ||
1649 | default: | ||
1650 | printf("unknown, probably not valid"); | ||
1651 | break; | ||
1652 | } | ||
1653 | printf(")\n"); | ||
1654 | } | ||
1655 | #endif /* HDIO_DRIVE_CMD */ | ||
1656 | |||
1657 | #ifndef VXVM_MAJOR | ||
1658 | #define VXVM_MAJOR 199 | ||
1659 | #endif | ||
1660 | |||
1661 | #ifndef CCISS_MAJOR | ||
1662 | #define CCISS_MAJOR 104 | ||
1663 | #endif | ||
1664 | |||
1665 | static void process_dev (char *devname) | ||
1666 | { | ||
1667 | int fd; | ||
1668 | static long parm, multcount; | ||
1669 | struct stat stat_buf; | ||
1670 | #ifndef HDIO_DRIVE_CMD | ||
1671 | int force_operation = 0; | ||
1672 | #endif | ||
1673 | if (stat(devname,&stat_buf)) | ||
1674 | bb_perror_msg_and_die(devname); | ||
1675 | |||
1676 | switch(major(stat_buf.st_rdev)) { | ||
1677 | #ifdef SCSI_DISK0_MAJOR | ||
1678 | case (SCSI_DISK0_MAJOR): | ||
1679 | case (SCSI_DISK1_MAJOR): | ||
1680 | case (SCSI_DISK2_MAJOR): | ||
1681 | case (SCSI_DISK3_MAJOR): | ||
1682 | case (SCSI_DISK4_MAJOR): | ||
1683 | case (SCSI_DISK5_MAJOR): | ||
1684 | case (SCSI_DISK6_MAJOR): | ||
1685 | case (SCSI_DISK7_MAJOR): | ||
1686 | #else | ||
1687 | case (SCSI_DISK_MAJOR): | ||
1688 | #endif | ||
1689 | #ifdef MD_MAJOR | ||
1690 | case (MD_MAJOR): | ||
1691 | #endif | ||
1692 | case (VXVM_MAJOR): | ||
1693 | #ifdef LVM_BLK_MAJOR | ||
1694 | case (LVM_BLK_MAJOR): | ||
1695 | #endif | ||
1696 | case (CCISS_MAJOR): | ||
1697 | is_scsi_hd = 1; | ||
1698 | break; | ||
1699 | #ifdef XT_DISK_MAJOR | ||
1700 | case (XT_DISK_MAJOR): | ||
1701 | is_xt_hd = 1; | ||
1702 | break; | ||
1703 | #endif | ||
1704 | case IDE0_MAJOR: | ||
1705 | case IDE1_MAJOR: | ||
1706 | #ifdef IDE2_MAJOR | ||
1707 | case IDE2_MAJOR: | ||
1708 | #endif | ||
1709 | #ifdef IDE3_MAJOR | ||
1710 | case IDE3_MAJOR: | ||
1711 | #endif | ||
1712 | #ifdef IDE4_MAJOR | ||
1713 | case IDE4_MAJOR: | ||
1714 | #endif | ||
1715 | #ifdef IDE5_MAJOR | ||
1716 | case IDE5_MAJOR: | ||
1717 | #endif | ||
1718 | #ifdef IDE6_MAJOR | ||
1719 | case IDE6_MAJOR: | ||
1720 | #endif | ||
1721 | #ifdef IDE7_MAJOR | ||
1722 | case IDE7_MAJOR: | ||
1723 | #endif | ||
1724 | #ifdef IDE8_MAJOR | ||
1725 | case IDE8_MAJOR: | ||
1726 | #endif | ||
1727 | #ifdef IDE9_MAJOR | ||
1728 | case IDE9_MAJOR: | ||
1729 | #endif | ||
1730 | break; /* do nothing */ | ||
1731 | default: | ||
1732 | bb_error_msg_and_die("%s not supported by hdparm",devname); | ||
1733 | } | ||
1734 | |||
1735 | fd = open (devname, O_RDONLY|O_NONBLOCK); | ||
1736 | if (fd < 0) | ||
1737 | bb_perror_msg_and_die(devname); | ||
1738 | if (!quiet) | ||
1739 | printf("\n%s:\n", devname); | ||
1740 | |||
1741 | if (set_readahead) { | ||
1742 | if (get_readahead) | ||
1743 | printf(" setting fs readahead to %ld\n", readahead); | ||
1744 | if (ioctl(fd, BLKRASET, readahead)) | ||
1745 | bb_perror_msg(" BLKRASET failed"); | ||
1746 | } | ||
1747 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | ||
1748 | if (unregister_hwif) { | ||
1749 | no_scsi(); | ||
1750 | printf(" attempting to unregister hwif#%u\n", hwif); | ||
1751 | if (ioctl(fd, HDIO_UNREGISTER_HWIF, hwif)) | ||
1752 | bb_perror_msg(" HDIO_UNREGISTER_HWIF failed"); | ||
1753 | } | ||
1754 | #endif | ||
1755 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF | ||
1756 | if (scan_hwif) { | ||
1757 | int args[3]; | ||
1758 | no_scsi(); | ||
1759 | printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq); | ||
1760 | args[0] = hwif_data; | ||
1761 | args[1] = hwif_ctrl; | ||
1762 | args[2] = hwif_irq; | ||
1763 | if (ioctl(fd, HDIO_SCAN_HWIF, args)) | ||
1764 | bb_perror_msg(" HDIO_SCAN_HWIF failed"); | ||
1765 | } | ||
1766 | #endif | ||
1767 | if (set_piomode) { | ||
1768 | no_scsi(); | ||
1769 | no_xt(); | ||
1770 | if (noisy_piomode) { | ||
1771 | if (piomode == 255) | ||
1772 | printf(" attempting to auto-tune PIO mode\n"); | ||
1773 | else if (piomode < 100) | ||
1774 | printf(" attempting to set PIO mode to %d\n", piomode); | ||
1775 | else if (piomode < 200) | ||
1776 | printf(" attempting to set MDMA mode to %d\n", (piomode-100)); | ||
1777 | else | ||
1778 | printf(" attempting to set UDMA mode to %d\n", (piomode-200)); | ||
1779 | } | ||
1780 | if (ioctl(fd, HDIO_SET_PIO_MODE, piomode)) | ||
1781 | bb_perror_msg(" HDIO_SET_PIO_MODE failed"); | ||
1782 | } | ||
1783 | if (set_io32bit) { | ||
1784 | no_scsi(); | ||
1785 | no_xt(); | ||
1786 | if (get_io32bit) | ||
1787 | printf(" setting 32-bit IO_support flag to %ld\n", io32bit); | ||
1788 | if (ioctl(fd, HDIO_SET_32BIT, io32bit)) | ||
1789 | bb_perror_msg(" HDIO_SET_32BIT failed"); | ||
1790 | } | ||
1791 | if (set_mult) { | ||
1792 | no_scsi(); | ||
1793 | no_xt(); | ||
1794 | if (get_mult) | ||
1795 | printf(" setting multcount to %ld\n", mult); | ||
1796 | if (ioctl(fd, HDIO_SET_MULTCOUNT, mult)) | ||
1797 | bb_perror_msg(" HDIO_SET_MULTCOUNT failed"); | ||
1798 | #ifndef HDIO_DRIVE_CMD | ||
1799 | else force_operation = 1; | ||
1800 | #endif | ||
1801 | } | ||
1802 | if (set_readonly) { | ||
1803 | if (get_readonly) { | ||
1804 | printf(" setting readonly to %ld", readonly); | ||
1805 | on_off(readonly); | ||
1806 | } | ||
1807 | if (ioctl(fd, BLKROSET, &readonly)) | ||
1808 | bb_perror_msg(" BLKROSET failed"); | ||
1809 | } | ||
1810 | if (set_unmask) { | ||
1811 | no_scsi(); | ||
1812 | no_xt(); | ||
1813 | if (get_unmask) { | ||
1814 | printf(" setting unmaskirq to %ld", unmask); | ||
1815 | on_off(unmask); | ||
1816 | } | ||
1817 | if (ioctl(fd, HDIO_SET_UNMASKINTR, unmask)) | ||
1818 | bb_perror_msg(" HDIO_SET_UNMASKINTR failed"); | ||
1819 | } | ||
1820 | if (set_dma) { | ||
1821 | no_scsi(); | ||
1822 | if (get_dma) { | ||
1823 | printf(" setting using_dma to %ld", dma); | ||
1824 | on_off(dma); | ||
1825 | } | ||
1826 | if (ioctl(fd, HDIO_SET_DMA, dma)) | ||
1827 | bb_perror_msg(" HDIO_SET_DMA failed"); | ||
1828 | } | ||
1829 | if (set_dma_q) { | ||
1830 | no_scsi(); | ||
1831 | if (get_dma_q) { | ||
1832 | printf(" setting DMA queue_depth to %ld", dma_q); | ||
1833 | on_off(dma_q); | ||
1834 | } | ||
1835 | if (ioctl(fd, HDIO_SET_QDMA, dma_q)) | ||
1836 | bb_perror_msg(" HDIO_SET_QDMA failed"); | ||
1837 | } | ||
1838 | if (set_nowerr) { | ||
1839 | no_scsi(); | ||
1840 | no_xt(); | ||
1841 | if (get_nowerr) { | ||
1842 | printf(" setting nowerr to %ld", nowerr); | ||
1843 | on_off(nowerr); | ||
1844 | } | ||
1845 | if (ioctl(fd, HDIO_SET_NOWERR, nowerr)) | ||
1846 | bb_perror_msg(" HDIO_SET_NOWERR failed"); | ||
1847 | } | ||
1848 | if (set_keep) { | ||
1849 | no_scsi(); | ||
1850 | no_xt(); | ||
1851 | if (get_keep) { | ||
1852 | printf(" setting keep_settings to %ld", keep); | ||
1853 | on_off(keep); | ||
1854 | } | ||
1855 | if (ioctl(fd, HDIO_SET_KEEPSETTINGS, keep)) | ||
1856 | bb_perror_msg(" HDIO_SET_KEEPSETTINGS failed"); | ||
1857 | } | ||
1858 | #ifdef HDIO_DRIVE_CMD | ||
1859 | if (set_doorlock) { | ||
1860 | unsigned char args[4] = {0,0,0,0}; | ||
1861 | no_scsi(); | ||
1862 | no_xt(); | ||
1863 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; | ||
1864 | if (get_doorlock) { | ||
1865 | printf(" setting drive doorlock to %ld", doorlock); | ||
1866 | on_off(doorlock); | ||
1867 | } | ||
1868 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1869 | bb_perror_msg(" HDIO_DRIVE_CMD(doorlock) failed"); | ||
1870 | } | ||
1871 | if (set_dkeep) { | ||
1872 | /* lock/unlock the drive's "feature" settings */ | ||
1873 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | ||
1874 | no_scsi(); | ||
1875 | no_xt(); | ||
1876 | if (get_dkeep) { | ||
1877 | printf(" setting drive keep features to %ld", dkeep); | ||
1878 | on_off(dkeep); | ||
1879 | } | ||
1880 | args[2] = dkeep ? 0x66 : 0xcc; | ||
1881 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1882 | bb_perror_msg(" HDIO_DRIVE_CMD(keepsettings) failed"); | ||
1883 | } | ||
1884 | if (set_defects) { | ||
1885 | unsigned char args[4] = {WIN_SETFEATURES,0,0x04,0}; | ||
1886 | no_scsi(); | ||
1887 | args[2] = defects ? 0x04 : 0x84; | ||
1888 | if (get_defects) | ||
1889 | printf(" setting drive defect-mgmt to %ld\n", defects); | ||
1890 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1891 | bb_perror_msg(" HDIO_DRIVE_CMD(defectmgmt) failed"); | ||
1892 | } | ||
1893 | if (set_prefetch) { | ||
1894 | unsigned char args[4] = {WIN_SETFEATURES,0,0xab,0}; | ||
1895 | no_scsi(); | ||
1896 | no_xt(); | ||
1897 | args[1] = prefetch; | ||
1898 | if (get_prefetch) | ||
1899 | printf(" setting drive prefetch to %ld\n", prefetch); | ||
1900 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1901 | bb_perror_msg(" HDIO_DRIVE_CMD(setprefetch) failed"); | ||
1902 | } | ||
1903 | if (set_xfermode) { | ||
1904 | unsigned char args[4] = {WIN_SETFEATURES,0,3,0}; | ||
1905 | no_scsi(); | ||
1906 | no_xt(); | ||
1907 | args[1] = xfermode_requested; | ||
1908 | if (get_xfermode) { | ||
1909 | printf(" setting xfermode to %d", xfermode_requested); | ||
1910 | interpret_xfermode(xfermode_requested); | ||
1911 | } | ||
1912 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1913 | bb_perror_msg(" HDIO_DRIVE_CMD(setxfermode) failed"); | ||
1914 | } | ||
1915 | if (set_lookahead) { | ||
1916 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | ||
1917 | no_scsi(); | ||
1918 | no_xt(); | ||
1919 | args[2] = lookahead ? 0xaa : 0x55; | ||
1920 | if (get_lookahead) { | ||
1921 | printf(" setting drive read-lookahead to %ld", lookahead); | ||
1922 | on_off(lookahead); | ||
1923 | } | ||
1924 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1925 | bb_perror_msg(" HDIO_DRIVE_CMD(setreadahead) failed"); | ||
1926 | } | ||
1927 | if (set_apmmode) { | ||
1928 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | ||
1929 | no_scsi(); | ||
1930 | if (apmmode<1) apmmode=1; | ||
1931 | if (apmmode>255) apmmode=255; | ||
1932 | if (get_apmmode) | ||
1933 | printf(" setting Advanced Power Management level to"); | ||
1934 | if (apmmode==255) { | ||
1935 | /* disable Advanced Power Management */ | ||
1936 | args[2] = 0x85; /* feature register */ | ||
1937 | if (get_apmmode) printf(" disabled\n"); | ||
1938 | } else { | ||
1939 | /* set Advanced Power Management mode */ | ||
1940 | args[2] = 0x05; /* feature register */ | ||
1941 | args[1] = apmmode; /* sector count register */ | ||
1942 | if (get_apmmode) printf(" 0x%02lX (%ld)\n",apmmode,apmmode); | ||
1943 | } | ||
1944 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1945 | bb_perror_msg(" HDIO_DRIVE_CMD failed"); | ||
1946 | } | ||
1947 | if (set_wcache) { | ||
1948 | #ifdef DO_FLUSHCACHE | ||
1949 | #ifndef WIN_FLUSHCACHE | ||
1950 | #define WIN_FLUSHCACHE 0xe7 | ||
1951 | #endif | ||
1952 | unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; | ||
1953 | #endif /* DO_FLUSHCACHE */ | ||
1954 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | ||
1955 | no_scsi(); | ||
1956 | no_xt(); | ||
1957 | args[2] = wcache ? 0x02 : 0x82; | ||
1958 | if (get_wcache) { | ||
1959 | printf(" setting drive write-caching to %ld", wcache); | ||
1960 | on_off(wcache); | ||
1961 | } | ||
1962 | #ifdef DO_FLUSHCACHE | ||
1963 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) | ||
1964 | bb_perror_msg (" HDIO_DRIVE_CMD(flushcache) failed"); | ||
1965 | #endif /* DO_FLUSHCACHE */ | ||
1966 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
1967 | bb_perror_msg(" HDIO_DRIVE_CMD(setcache) failed"); | ||
1968 | #ifdef DO_FLUSHCACHE | ||
1969 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) | ||
1970 | bb_perror_msg (" HDIO_DRIVE_CMD(flushcache) failed"); | ||
1971 | #endif /* DO_FLUSHCACHE */ | ||
1972 | } | ||
1973 | if (set_standbynow) { | ||
1974 | #ifndef WIN_STANDBYNOW1 | ||
1975 | #define WIN_STANDBYNOW1 0xE0 | ||
1976 | #endif | ||
1977 | #ifndef WIN_STANDBYNOW2 | ||
1978 | #define WIN_STANDBYNOW2 0x94 | ||
1979 | #endif | ||
1980 | unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0}; | ||
1981 | unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0}; | ||
1982 | no_scsi(); | ||
1983 | if (get_standbynow) | ||
1984 | printf(" issuing standby command\n"); | ||
1985 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) | ||
1986 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) | ||
1987 | bb_perror_msg(" HDIO_DRIVE_CMD(standby) failed"); | ||
1988 | } | ||
1989 | if (set_sleepnow) { | ||
1990 | #ifndef WIN_SLEEPNOW1 | ||
1991 | #define WIN_SLEEPNOW1 0xE6 | ||
1992 | #endif | ||
1993 | #ifndef WIN_SLEEPNOW2 | ||
1994 | #define WIN_SLEEPNOW2 0x99 | ||
1995 | #endif | ||
1996 | unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0}; | ||
1997 | unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0}; | ||
1998 | no_scsi(); | ||
1999 | if (get_sleepnow) | ||
2000 | printf(" issuing sleep command\n"); | ||
2001 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) | ||
2002 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) | ||
2003 | bb_perror_msg(" HDIO_DRIVE_CMD(sleep) failed"); | ||
2004 | } | ||
2005 | if (set_seagate) { | ||
2006 | unsigned char args[4] = {0xfb,0,0,0}; | ||
2007 | no_scsi(); | ||
2008 | no_xt(); | ||
2009 | if (get_seagate) | ||
2010 | printf(" disabling Seagate auto powersaving mode\n"); | ||
2011 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
2012 | bb_perror_msg(" HDIO_DRIVE_CMD(seagatepwrsave) failed"); | ||
2013 | } | ||
2014 | if (set_standby) { | ||
2015 | unsigned char args[4] = {WIN_SETIDLE1,standby_requested,0,0}; | ||
2016 | no_scsi(); | ||
2017 | no_xt(); | ||
2018 | if (get_standby) { | ||
2019 | printf(" setting standby to %lu", standby_requested); | ||
2020 | interpret_standby(standby_requested); | ||
2021 | } | ||
2022 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) | ||
2023 | bb_perror_msg(" HDIO_DRIVE_CMD(setidle1) failed"); | ||
2024 | } | ||
2025 | #else /* HDIO_DRIVE_CMD */ | ||
2026 | if (force_operation) { | ||
2027 | char buf[512]; | ||
2028 | flush_buffer_cache(fd); | ||
2029 | if (-1 == read(fd, buf, sizeof(buf))) | ||
2030 | bb_perror_msg(" access failed"); | ||
2031 | } | ||
2032 | #endif /* HDIO_DRIVE_CMD */ | ||
2033 | |||
2034 | if (!flagcount) | ||
2035 | verbose = 1; | ||
2036 | |||
2037 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_mult || get_identity) { | ||
2038 | no_scsi(); | ||
2039 | multcount = -1; | ||
2040 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { | ||
2041 | if ((verbose && !is_xt_hd) || get_mult) | ||
2042 | bb_perror_msg(" HDIO_GET_MULTCOUNT failed"); | ||
2043 | } else if (verbose | get_mult) { | ||
2044 | printf(" multcount = %2ld", multcount); | ||
2045 | on_off(multcount); | ||
2046 | } | ||
2047 | } | ||
2048 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit) { | ||
2049 | no_scsi(); | ||
2050 | no_xt(); | ||
2051 | if (ioctl(fd, HDIO_GET_32BIT, &parm)) | ||
2052 | bb_perror_msg(" HDIO_GET_32BIT failed"); | ||
2053 | else { | ||
2054 | printf(" IO_support =%3ld (", parm); | ||
2055 | switch (parm) { | ||
2056 | case 0: printf("default "); | ||
2057 | case 2: printf("16-bit)\n"); | ||
2058 | break; | ||
2059 | case 1: printf("32-bit)\n"); | ||
2060 | break; | ||
2061 | case 3: printf("32-bit w/sync)\n"); | ||
2062 | break; | ||
2063 | case 8: printf("Request-Queue-Bypass)\n"); | ||
2064 | break; | ||
2065 | default:printf("\?\?\?)\n"); | ||
2066 | } | ||
2067 | } | ||
2068 | } | ||
2069 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask) { | ||
2070 | no_scsi(); | ||
2071 | no_xt(); | ||
2072 | if (ioctl(fd, HDIO_GET_UNMASKINTR, &parm)) | ||
2073 | bb_perror_msg(" HDIO_GET_UNMASKINTR failed"); | ||
2074 | else { | ||
2075 | printf(" unmaskirq = %2ld", parm); | ||
2076 | on_off(parm); | ||
2077 | } | ||
2078 | } | ||
2079 | |||
2080 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GET_DMA | ||
2081 | if ((verbose && !is_scsi_hd) || get_dma) { | ||
2082 | no_scsi(); | ||
2083 | if (ioctl(fd, HDIO_GET_DMA, &parm)) | ||
2084 | bb_perror_msg(" HDIO_GET_DMA failed"); | ||
2085 | else { | ||
2086 | printf(" using_dma = %2ld", parm); | ||
2087 | if (parm == 8) | ||
2088 | printf(" (DMA-Assisted-PIO)\n"); | ||
2089 | else | ||
2090 | on_off(parm); | ||
2091 | } | ||
2092 | } | ||
2093 | #endif | ||
2094 | if (get_dma_q) { | ||
2095 | no_scsi(); | ||
2096 | if(ioctl(fd, HDIO_GET_QDMA, &parm)) { | ||
2097 | bb_perror_msg(" HDIO_GET_QDMA failed"); | ||
2098 | } else { | ||
2099 | printf(" queue_depth = %2ld", parm); | ||
2100 | on_off(parm); | ||
2101 | } | ||
2102 | } | ||
2103 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep) { | ||
2104 | no_scsi(); | ||
2105 | no_xt(); | ||
2106 | if (ioctl(fd, HDIO_GET_KEEPSETTINGS, &parm)) | ||
2107 | bb_perror_msg(" HDIO_GET_KEEPSETTINGS failed"); | ||
2108 | else { | ||
2109 | printf(" keepsettings = %2ld", parm); | ||
2110 | on_off(parm); | ||
2111 | } | ||
2112 | } | ||
2113 | |||
2114 | if (get_nowerr) { | ||
2115 | no_scsi(); | ||
2116 | no_xt(); | ||
2117 | if (ioctl(fd, HDIO_GET_NOWERR, &parm)) | ||
2118 | bb_perror_msg(" HDIO_GET_NOWERR failed"); | ||
2119 | else { | ||
2120 | printf(" nowerr = %2ld", parm); | ||
2121 | on_off(parm); | ||
2122 | } | ||
2123 | } | ||
2124 | if (verbose || get_readonly) { | ||
2125 | if (ioctl(fd, BLKROGET, &parm)) | ||
2126 | bb_perror_msg(" BLKROGET failed"); | ||
2127 | else { | ||
2128 | printf(" readonly = %2ld", parm); | ||
2129 | on_off(parm); | ||
2130 | } | ||
2131 | } | ||
2132 | if ((verbose && !is_scsi_hd) || get_readahead) { | ||
2133 | if (ioctl(fd, BLKRAGET, &parm)) | ||
2134 | bb_perror_msg(" BLKRAGET failed"); | ||
2135 | else { | ||
2136 | printf(" readahead = %2ld", parm); | ||
2137 | on_off(parm); | ||
2138 | } | ||
2139 | } | ||
2140 | if (verbose || get_geom) { | ||
2141 | static const char msg[] = " geometry = %u/%u/%u, sectors = %ld, start = %ld\n"; | ||
2142 | static struct hd_geometry g; | ||
2143 | #ifdef HDIO_GETGEO_BIG | ||
2144 | static struct hd_big_geometry bg; | ||
2145 | #endif | ||
2146 | |||
2147 | if (ioctl(fd, BLKGETSIZE, &parm)) | ||
2148 | bb_perror_msg(" BLKGETSIZE failed"); | ||
2149 | #ifdef HDIO_GETGEO_BIG | ||
2150 | else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) | ||
2151 | printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); | ||
2152 | #endif | ||
2153 | else if (ioctl(fd, HDIO_GETGEO, &g)) | ||
2154 | bb_perror_msg(" HDIO_GETGEO failed"); | ||
2155 | else printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start); | ||
2156 | } | ||
2157 | #ifdef HDIO_DRIVE_CMD | ||
2158 | if (get_powermode) { | ||
2159 | #ifndef WIN_CHECKPOWERMODE1 | ||
2160 | #define WIN_CHECKPOWERMODE1 0xE5 | ||
2161 | #endif | ||
2162 | #ifndef WIN_CHECKPOWERMODE2 | ||
2163 | #define WIN_CHECKPOWERMODE2 0x98 | ||
2164 | #endif | ||
2165 | unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0}; | ||
2166 | const char *state; | ||
2167 | no_scsi(); | ||
2168 | if (ioctl(fd, HDIO_DRIVE_CMD, &args) | ||
2169 | && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */ | ||
2170 | && ioctl(fd, HDIO_DRIVE_CMD, &args)) { | ||
2171 | if (errno != EIO || args[0] != 0 || args[1] != 0) | ||
2172 | state = "unknown"; | ||
2173 | else | ||
2174 | state = "sleeping"; | ||
2175 | } else { | ||
2176 | state = (args[2] == 255) ? "active/idle" : "standby"; | ||
2177 | } | ||
2178 | printf(" drive state is: %s\n", state); | ||
2179 | } | ||
2180 | #endif | ||
2181 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET | ||
2182 | if (perform_reset) { | ||
2183 | no_scsi(); | ||
2184 | no_xt(); | ||
2185 | if (ioctl(fd, HDIO_DRIVE_RESET, NULL)) | ||
2186 | bb_perror_msg(" HDIO_DRIVE_RESET failed"); | ||
2187 | } | ||
2188 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ | ||
2189 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
2190 | if (perform_tristate) { | ||
2191 | unsigned char args[4] = {0,tristate,0,0}; | ||
2192 | no_scsi(); | ||
2193 | no_xt(); | ||
2194 | if (ioctl(fd, HDIO_TRISTATE_HWIF, &args)) | ||
2195 | bb_perror_msg(" HDIO_TRISTATE_HWIF failed"); | ||
2196 | } | ||
2197 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ | ||
2198 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
2199 | if (get_identity) { | ||
2200 | static struct hd_driveid id; | ||
2201 | |||
2202 | no_scsi(); | ||
2203 | no_xt(); | ||
2204 | |||
2205 | if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) { | ||
2206 | if (multcount != -1) { | ||
2207 | id.multsect = multcount; | ||
2208 | id.multsect_valid |= 1; | ||
2209 | } else | ||
2210 | id.multsect_valid &= ~1; | ||
2211 | dump_identity(&id); | ||
2212 | } else if (errno == -ENOMSG) | ||
2213 | printf(" no identification info available\n"); | ||
2214 | else | ||
2215 | bb_perror_msg(" HDIO_GET_IDENTITY failed"); | ||
2216 | } | ||
2217 | if (get_IDentity) { | ||
2218 | unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,}; | ||
2219 | unsigned i; | ||
2220 | no_scsi(); | ||
2221 | no_xt(); | ||
2222 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { | ||
2223 | args[0] = WIN_PIDENTIFY; | ||
2224 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { | ||
2225 | bb_perror_msg(" HDIO_DRIVE_CMD(identify) failed"); | ||
2226 | goto identify_abort; | ||
2227 | } | ||
2228 | } | ||
2229 | for(i=0; i<(sizeof args)/2; i+=2) { | ||
2230 | __le16_to_cpus((uint16_t *)(&args[i])); | ||
2231 | } | ||
2232 | identify((void *)&args[4], NULL); | ||
2233 | identify_abort: ; | ||
2234 | } | ||
2235 | #endif | ||
2236 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
2237 | if (set_busstate) { | ||
2238 | no_scsi(); | ||
2239 | if (get_busstate) { | ||
2240 | printf(" setting bus state to %d", busstate); | ||
2241 | bus_state_value(busstate); | ||
2242 | } | ||
2243 | if (ioctl(fd, HDIO_SET_BUSSTATE, busstate)) | ||
2244 | bb_perror_msg(" HDIO_SET_BUSSTATE failed"); | ||
2245 | } | ||
2246 | #endif | ||
2247 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
2248 | if (get_busstate) { | ||
2249 | no_scsi(); | ||
2250 | if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) | ||
2251 | bb_perror_msg(" HDIO_GET_BUSSTATE failed"); | ||
2252 | else { | ||
2253 | printf(" busstate = %2ld", parm); | ||
2254 | bus_state_value(parm); | ||
2255 | } | ||
2256 | } | ||
2257 | #endif | ||
2258 | if (reread_partn) { | ||
2259 | if (ioctl(fd, BLKRRPART, NULL)) { | ||
2260 | bb_perror_msg(" BLKRRPART failed"); | ||
2261 | } | ||
2262 | } | ||
2263 | |||
2264 | if (do_ctimings) | ||
2265 | time_cache (fd); | ||
2266 | if (do_timings) | ||
2267 | time_device (fd); | ||
2268 | if (do_flush) | ||
2269 | flush_buffer_cache (fd); | ||
2270 | close (fd); | ||
2271 | } | ||
2272 | |||
2273 | #define GET_NUMBER(flag,num) num = 0; \ | ||
2274 | if (!*p && argc && isdigit(**argv)) \ | ||
2275 | p = *argv++, --argc; \ | ||
2276 | while (isdigit(*p)) { \ | ||
2277 | flag = 1; \ | ||
2278 | num = (num * 10) + (*p++ - '0'); \ | ||
2279 | } | ||
2280 | |||
2281 | #define GET_STRING(flag, num) tmpstr = name; \ | ||
2282 | tmpstr[0] = '\0'; \ | ||
2283 | if (!*p && argc && isalnum(**argv)) \ | ||
2284 | p = *argv++, --argc; \ | ||
2285 | while (isalnum(*p) && (tmpstr - name) < 31) { \ | ||
2286 | tmpstr[0] = *p++; \ | ||
2287 | tmpstr[1] = '\0'; \ | ||
2288 | ++tmpstr; \ | ||
2289 | } \ | ||
2290 | num = translate_xfermode(name); \ | ||
2291 | if (num == -1) \ | ||
2292 | flag = 0; \ | ||
2293 | else \ | ||
2294 | flag = 1; | ||
2295 | |||
2296 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
2297 | static int fromhex (unsigned char c) | ||
2298 | { | ||
2299 | if (c >= 'a' && c <= 'f') | ||
2300 | return 10 + (c - 'a'); | ||
2301 | if (c >= '0' && c <= '9') | ||
2302 | return (c - '0'); | ||
2303 | bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c); | ||
2304 | } | ||
2305 | |||
2306 | static int identify_from_stdin (void) | ||
2307 | { | ||
2308 | unsigned short sbuf[800]; | ||
2309 | unsigned char buf[1600], *b = (unsigned char *)buf; | ||
2310 | int i, count = read(0, buf, 1280); | ||
2311 | |||
2312 | if (count != 1280) | ||
2313 | bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count); | ||
2314 | for (i = 0; count >= 4; ++i) { | ||
2315 | sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]); | ||
2316 | __le16_to_cpus((uint16_t *)(&sbuf[i])); | ||
2317 | b += 5; | ||
2318 | count -= 5; | ||
2319 | } | ||
2320 | identify(sbuf, NULL); | ||
2321 | return 0; | ||
2322 | } | ||
2323 | #endif | ||
2324 | |||
2325 | /* our main() routine: */ | ||
2326 | int hdparm_main(int argc, char **argv) | ||
2327 | { | ||
2328 | char c, *p; | ||
2329 | char *tmpstr; | ||
2330 | char name[32]; | ||
2331 | int neg; | ||
2332 | |||
2333 | ++argv; | ||
2334 | if (!--argc) | ||
2335 | bb_show_usage(); | ||
2336 | while (argc--) { | ||
2337 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
2338 | if (!strcmp("-Istdin", *argv)) { | ||
2339 | exit(identify_from_stdin()); | ||
2340 | } | ||
2341 | #endif | ||
2342 | p = *argv++; | ||
2343 | if (*p == '-') { | ||
2344 | if (!*++p) | ||
2345 | bb_show_usage(); | ||
2346 | while ((c = *p++)) { | ||
2347 | ++flagcount; | ||
2348 | switch (c) { | ||
2349 | case 'V': | ||
2350 | bb_error_msg_and_die("%s", VERSION); | ||
2351 | case 'v': | ||
2352 | verbose = 1; | ||
2353 | break; | ||
2354 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY | ||
2355 | case 'I': | ||
2356 | get_IDentity = 1; | ||
2357 | break; | ||
2358 | case 'i': | ||
2359 | get_identity = 1; | ||
2360 | break; | ||
2361 | #endif | ||
2362 | case 'g': | ||
2363 | get_geom = 1; | ||
2364 | break; | ||
2365 | case 'f': | ||
2366 | do_flush = 1; | ||
2367 | break; | ||
2368 | case 'q': | ||
2369 | quiet = 1; | ||
2370 | noisy = 0; | ||
2371 | break; | ||
2372 | case 'u': | ||
2373 | get_unmask = noisy; | ||
2374 | noisy = 1; | ||
2375 | if (!*p && argc && isdigit(**argv)) | ||
2376 | p = *argv++, --argc; | ||
2377 | if (*p == '0' || *p == '1') { | ||
2378 | set_unmask = 1; | ||
2379 | unmask = *p++ - '0'; | ||
2380 | } | ||
2381 | break; | ||
2382 | case 'd': | ||
2383 | get_dma = noisy; | ||
2384 | noisy = 1; | ||
2385 | if (!*p && argc && isdigit(**argv)) | ||
2386 | p = *argv++, --argc; | ||
2387 | if (*p >= '0' && *p <= '9') { | ||
2388 | set_dma = 1; | ||
2389 | dma = *p++ - '0'; | ||
2390 | } | ||
2391 | break; | ||
2392 | case 'n': | ||
2393 | get_nowerr = noisy; | ||
2394 | noisy = 1; | ||
2395 | if (!*p && argc && isdigit(**argv)) | ||
2396 | p = *argv++, --argc; | ||
2397 | if (*p == '0' || *p == '1') { | ||
2398 | set_nowerr = 1; | ||
2399 | nowerr = *p++ - '0'; | ||
2400 | } | ||
2401 | break; | ||
2402 | case 'p': | ||
2403 | noisy_piomode = noisy; | ||
2404 | noisy = 1; | ||
2405 | GET_STRING(set_piomode,piomode); | ||
2406 | break; | ||
2407 | case 'r': | ||
2408 | get_readonly = noisy; | ||
2409 | noisy = 1; | ||
2410 | if (!*p && argc && isdigit(**argv)) | ||
2411 | p = *argv++, --argc; | ||
2412 | if (*p == '0' || *p == '1') { | ||
2413 | set_readonly = 1; | ||
2414 | readonly = *p++ - '0'; | ||
2415 | } | ||
2416 | break; | ||
2417 | case 'm': | ||
2418 | get_mult = noisy; | ||
2419 | noisy = 1; | ||
2420 | GET_NUMBER(set_mult,mult); | ||
2421 | break; | ||
2422 | case 'c': | ||
2423 | get_io32bit = noisy; | ||
2424 | noisy = 1; | ||
2425 | GET_NUMBER(set_io32bit,io32bit); | ||
2426 | break; | ||
2427 | #ifdef HDIO_DRIVE_CMD | ||
2428 | case 'S': | ||
2429 | get_standby = noisy; | ||
2430 | noisy = 1; | ||
2431 | GET_NUMBER(set_standby,standby_requested); | ||
2432 | if (!set_standby) | ||
2433 | bb_error_msg("-S: missing value"); | ||
2434 | break; | ||
2435 | |||
2436 | case 'D': | ||
2437 | get_defects = noisy; | ||
2438 | noisy = 1; | ||
2439 | GET_NUMBER(set_defects,defects); | ||
2440 | if (!set_defects) | ||
2441 | bb_error_msg("-D: missing value"); | ||
2442 | break; | ||
2443 | case 'P': | ||
2444 | get_prefetch = noisy; | ||
2445 | noisy = 1; | ||
2446 | GET_NUMBER(set_prefetch,prefetch); | ||
2447 | if (!set_prefetch) | ||
2448 | bb_error_msg("-P: missing value"); | ||
2449 | break; | ||
2450 | |||
2451 | case 'X': | ||
2452 | get_xfermode = noisy; | ||
2453 | noisy = 1; | ||
2454 | GET_STRING(set_xfermode,xfermode_requested); | ||
2455 | if (!set_xfermode) | ||
2456 | bb_error_msg("-X: missing value"); | ||
2457 | break; | ||
2458 | |||
2459 | case 'K': | ||
2460 | get_dkeep = noisy; | ||
2461 | noisy = 1; | ||
2462 | if (!*p && argc && isdigit(**argv)) | ||
2463 | p = *argv++, --argc; | ||
2464 | if (*p == '0' || *p == '1') { | ||
2465 | set_dkeep = 1; | ||
2466 | dkeep = *p++ - '0'; | ||
2467 | } else | ||
2468 | bb_error_msg("-K: missing value (0/1)"); | ||
2469 | break; | ||
2470 | |||
2471 | case 'A': | ||
2472 | get_lookahead = noisy; | ||
2473 | noisy = 1; | ||
2474 | if (!*p && argc && isdigit(**argv)) | ||
2475 | p = *argv++, --argc; | ||
2476 | if (*p == '0' || *p == '1') { | ||
2477 | set_lookahead = 1; | ||
2478 | lookahead = *p++ - '0'; | ||
2479 | } else | ||
2480 | bb_error_msg("-A: missing value (0/1)"); | ||
2481 | break; | ||
2482 | |||
2483 | case 'L': | ||
2484 | get_doorlock = noisy; | ||
2485 | noisy = 1; | ||
2486 | if (!*p && argc && isdigit(**argv)) | ||
2487 | p = *argv++, --argc; | ||
2488 | if (*p == '0' || *p == '1') { | ||
2489 | set_doorlock = 1; | ||
2490 | doorlock = *p++ - '0'; | ||
2491 | } else | ||
2492 | bb_error_msg("-L: missing value (0/1)"); | ||
2493 | break; | ||
2494 | |||
2495 | case 'W': | ||
2496 | get_wcache = noisy; | ||
2497 | noisy = 1; | ||
2498 | if (!*p && argc && isdigit(**argv)) | ||
2499 | p = *argv++, --argc; | ||
2500 | if (*p == '0' || *p == '1') { | ||
2501 | set_wcache = 1; | ||
2502 | wcache = *p++ - '0'; | ||
2503 | } else | ||
2504 | bb_error_msg("-W: missing value (0/1)"); | ||
2505 | break; | ||
2506 | |||
2507 | case 'C': | ||
2508 | get_powermode = noisy; | ||
2509 | noisy = 1; | ||
2510 | break; | ||
2511 | |||
2512 | case 'y': | ||
2513 | get_standbynow = noisy; | ||
2514 | noisy = 1; | ||
2515 | set_standbynow = 1; | ||
2516 | break; | ||
2517 | |||
2518 | case 'Y': | ||
2519 | get_sleepnow = noisy; | ||
2520 | noisy = 1; | ||
2521 | set_sleepnow = 1; | ||
2522 | break; | ||
2523 | |||
2524 | case 'z': | ||
2525 | reread_partn = 1; | ||
2526 | break; | ||
2527 | |||
2528 | case 'Z': | ||
2529 | get_seagate = noisy; | ||
2530 | noisy = 1; | ||
2531 | set_seagate = 1; | ||
2532 | break; | ||
2533 | #endif /* HDIO_DRIVE_CMD */ | ||
2534 | case 'k': | ||
2535 | get_keep = noisy; | ||
2536 | noisy = 1; | ||
2537 | if (!*p && argc && isdigit(**argv)) | ||
2538 | p = *argv++, --argc; | ||
2539 | if (*p == '0' || *p == '1') { | ||
2540 | set_keep = 1; | ||
2541 | keep = *p++ - '0'; | ||
2542 | } | ||
2543 | break; | ||
2544 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF | ||
2545 | case 'U': | ||
2546 | if (!*p && argc && isdigit(**argv)) | ||
2547 | p = *argv++, --argc; | ||
2548 | |||
2549 | if(! p) { | ||
2550 | bb_error_msg_and_die("expected hwif_nr"); | ||
2551 | } | ||
2552 | |||
2553 | sscanf(p++, "%i", &hwif); | ||
2554 | |||
2555 | unregister_hwif = 1; | ||
2556 | break; | ||
2557 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */ | ||
2558 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF | ||
2559 | case 'R': | ||
2560 | if (!*p && argc && isdigit(**argv)) | ||
2561 | p = *argv++, --argc; | ||
2562 | |||
2563 | if(! p) { | ||
2564 | bb_error_msg_and_die("expected hwif_data"); | ||
2565 | } | ||
2566 | |||
2567 | sscanf(p++, "%i", &hwif_data); | ||
2568 | |||
2569 | if (argc && isdigit(**argv)) | ||
2570 | p = *argv++, --argc; | ||
2571 | else { | ||
2572 | bb_error_msg_and_die("expected hwif_ctrl"); | ||
2573 | } | ||
2574 | |||
2575 | sscanf(p, "%i", &hwif_ctrl); | ||
2576 | |||
2577 | if (argc && isdigit(**argv)) | ||
2578 | p = *argv++, --argc; | ||
2579 | else { | ||
2580 | bb_error_msg_and_die("expected hwif_irq"); | ||
2581 | } | ||
2582 | |||
2583 | sscanf(p, "%i", &hwif_irq); | ||
2584 | |||
2585 | *p = '\0'; | ||
2586 | |||
2587 | scan_hwif = 1; | ||
2588 | break; | ||
2589 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */ | ||
2590 | case 'Q': | ||
2591 | get_dma_q = noisy; | ||
2592 | noisy = 1; | ||
2593 | neg = 0; | ||
2594 | GET_NUMBER(set_dma_q, dma_q); | ||
2595 | if (neg) | ||
2596 | dma_q = -dma_q; | ||
2597 | break; | ||
2598 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET | ||
2599 | case 'w': | ||
2600 | perform_reset = 1; | ||
2601 | break; | ||
2602 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ | ||
2603 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
2604 | case 'x': | ||
2605 | if (!*p && argc && isdigit(**argv)) | ||
2606 | p = *argv++, --argc; | ||
2607 | if (*p == '0' || *p == '1') { | ||
2608 | perform_tristate = 1; | ||
2609 | tristate = *p++ - '0'; | ||
2610 | } else | ||
2611 | bb_error_msg("-x: missing value (0/1)"); | ||
2612 | break; | ||
2613 | |||
2614 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ | ||
2615 | case 'a': | ||
2616 | get_readahead = noisy; | ||
2617 | noisy = 1; | ||
2618 | GET_NUMBER(set_readahead,readahead); | ||
2619 | break; | ||
2620 | case 'B': | ||
2621 | get_apmmode = noisy; | ||
2622 | noisy = 1; | ||
2623 | GET_NUMBER(set_apmmode,apmmode); | ||
2624 | if (!set_apmmode) | ||
2625 | printf("-B: missing value (1-255)"); | ||
2626 | break; | ||
2627 | case 't': | ||
2628 | do_timings = 1; | ||
2629 | do_flush = 1; | ||
2630 | break; | ||
2631 | case 'T': | ||
2632 | do_ctimings = 1; | ||
2633 | do_flush = 1; | ||
2634 | break; | ||
2635 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF | ||
2636 | case 'b': | ||
2637 | get_busstate = noisy; | ||
2638 | noisy = 1; | ||
2639 | if (!*p && argc && isdigit(**argv)) | ||
2640 | p = *argv++, --argc; | ||
2641 | switch (*p) { | ||
2642 | case '0': | ||
2643 | case '1': | ||
2644 | case '2': | ||
2645 | set_busstate = 1; | ||
2646 | busstate = *p++ - '0'; | ||
2647 | break; | ||
2648 | default: | ||
2649 | break; | ||
2650 | } | ||
2651 | break; | ||
2652 | #endif | ||
2653 | case 'h': | ||
2654 | default: | ||
2655 | bb_show_usage(); | ||
2656 | } | ||
2657 | } | ||
2658 | if (!argc) | ||
2659 | bb_show_usage(); | ||
2660 | } else { | ||
2661 | process_dev (p); | ||
2662 | } | ||
2663 | } | ||
2664 | return 0 ; | ||
2665 | } | ||