11 |
* hdparm.c - Command line interface to get/set hard disk parameters |
* hdparm.c - Command line interface to get/set hard disk parameters |
12 |
* - by Mark Lord (C) 1994-2002 -- freely distributable |
* - by Mark Lord (C) 1994-2002 -- freely distributable |
13 |
*/ |
*/ |
|
|
|
14 |
#include "libbb.h" |
#include "libbb.h" |
15 |
|
/* must be _after_ libbb.h: */ |
16 |
#include <linux/hdreg.h> |
#include <linux/hdreg.h> |
17 |
|
#include <sys/mount.h> |
18 |
|
#if !defined(BLKGETSIZE64) |
19 |
|
# define BLKGETSIZE64 _IOR(0x12,114,size_t) |
20 |
|
#endif |
21 |
|
|
22 |
/* device types */ |
/* device types */ |
23 |
/* ------------ */ |
/* ------------ */ |
63 |
#define ADV_PIO_MODES 64 /* advanced PIO modes supported */ |
#define ADV_PIO_MODES 64 /* advanced PIO modes supported */ |
64 |
/* multiword DMA xfer cycle time: */ |
/* multiword DMA xfer cycle time: */ |
65 |
#define DMA_TIME_MIN 65 /* - minimum */ |
#define DMA_TIME_MIN 65 /* - minimum */ |
66 |
#define DMA_TIME_NORM 66 /* - manufacturer's recommended */ |
#define DMA_TIME_NORM 66 /* - manufacturer's recommended */ |
67 |
/* minimum PIO xfer cycle time: */ |
/* minimum PIO xfer cycle time: */ |
68 |
#define PIO_NO_FLOW 67 /* - without flow control */ |
#define PIO_NO_FLOW 67 /* - without flow control */ |
69 |
#define PIO_FLOW 68 /* - with IORDY flow control */ |
#define PIO_FLOW 68 /* - with IORDY flow control */ |
86 |
#define ENH_ERASE_TIME 90 /* - enhanced */ |
#define ENH_ERASE_TIME 90 /* - enhanced */ |
87 |
#define ADV_PWR 91 /* current advanced power management level |
#define ADV_PWR 91 /* current advanced power management level |
88 |
in low byte, 0x40 in high byte. */ |
in low byte, 0x40 in high byte. */ |
89 |
#define PSWD_CODE 92 /* master password revision code */ |
#define PSWD_CODE 92 /* master password revision code */ |
90 |
#define HWRST_RSLT 93 /* hardware reset result */ |
#define HWRST_RSLT 93 /* hardware reset result */ |
91 |
#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */ |
#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */ |
92 |
#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */ |
#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */ |
236 |
#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ |
#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ |
237 |
|
|
238 |
|
|
239 |
|
#define IS_GET 1 |
240 |
|
#define IS_SET 2 |
241 |
|
|
242 |
|
|
243 |
enum { fd = 3 }; |
enum { fd = 3 }; |
244 |
|
|
245 |
|
|
249 |
smallint do_ctimings, do_timings; |
smallint do_ctimings, do_timings; |
250 |
smallint reread_partn; |
smallint reread_partn; |
251 |
smallint set_piomode, noisy_piomode; |
smallint set_piomode, noisy_piomode; |
252 |
smallint set_readahead, get_readahead; |
smallint getset_readahead; |
253 |
smallint set_readonly, get_readonly; |
smallint getset_readonly; |
254 |
smallint set_unmask, get_unmask; |
smallint getset_unmask; |
255 |
smallint set_mult, get_mult; |
smallint getset_mult; |
256 |
#ifdef HDIO_GET_QDMA |
#ifdef HDIO_GET_QDMA |
257 |
smallint get_dma_q; |
smallint getset_dma_q; |
|
#ifdef HDIO_SET_QDMA |
|
|
smallint set_dma_q; |
|
|
#endif |
|
258 |
#endif |
#endif |
259 |
smallint set_nowerr, get_nowerr; |
smallint getset_nowerr; |
260 |
smallint set_keep, get_keep; |
smallint getset_keep; |
261 |
smallint set_io32bit, get_io32bit; |
smallint getset_io32bit; |
262 |
int piomode; |
int piomode; |
263 |
unsigned long Xreadahead; |
unsigned long Xreadahead; |
264 |
unsigned long readonly; |
unsigned long readonly; |
272 |
unsigned long io32bit; |
unsigned long io32bit; |
273 |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
274 |
unsigned long dma; |
unsigned long dma; |
275 |
smallint set_dma, get_dma; |
smallint getset_dma; |
276 |
#endif |
#endif |
277 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
278 |
smallint set_xfermode, get_xfermode; |
smallint set_xfermode, get_xfermode; |
279 |
smallint set_dkeep, get_dkeep; |
smallint getset_dkeep; |
280 |
smallint set_standby, get_standby; |
smallint getset_standby; |
281 |
smallint set_lookahead, get_lookahead; |
smallint getset_lookahead; |
282 |
smallint set_prefetch, get_prefetch; |
smallint getset_prefetch; |
283 |
smallint set_defects, get_defects; |
smallint getset_defects; |
284 |
smallint set_wcache, get_wcache; |
smallint getset_wcache; |
285 |
smallint set_doorlock, get_doorlock; |
smallint getset_doorlock; |
286 |
smallint set_seagate, get_seagate; |
smallint set_seagate; |
287 |
smallint set_standbynow, get_standbynow; |
smallint set_standbynow; |
288 |
smallint set_sleepnow, get_sleepnow; |
smallint set_sleepnow; |
289 |
smallint get_powermode; |
smallint get_powermode; |
290 |
smallint set_apmmode, get_apmmode; |
smallint getset_apmmode; |
291 |
int xfermode_requested; |
int xfermode_requested; |
292 |
unsigned long dkeep; |
unsigned long dkeep; |
293 |
unsigned long standby_requested; /* 0..255 */ |
unsigned long standby_requested; /* 0..255 */ |
298 |
unsigned long doorlock; |
unsigned long doorlock; |
299 |
unsigned long apmmode; |
unsigned long apmmode; |
300 |
#endif |
#endif |
301 |
USE_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;) |
IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;) |
302 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint set_busstate, get_busstate;) |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint getset_busstate;) |
303 |
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;) |
IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;) |
304 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;) |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;) |
305 |
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;) |
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;) |
306 |
USE_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;) |
IF_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;) |
307 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;) |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;) |
308 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;) |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;) |
309 |
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;) |
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;) |
310 |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
311 |
unsigned long hwif_data; |
unsigned long hwif_data; |
312 |
unsigned long hwif_ctrl; |
unsigned long hwif_ctrl; |
328 |
#define reread_partn (G.reread_partn ) |
#define reread_partn (G.reread_partn ) |
329 |
#define set_piomode (G.set_piomode ) |
#define set_piomode (G.set_piomode ) |
330 |
#define noisy_piomode (G.noisy_piomode ) |
#define noisy_piomode (G.noisy_piomode ) |
331 |
#define set_readahead (G.set_readahead ) |
#define getset_readahead (G.getset_readahead ) |
332 |
#define get_readahead (G.get_readahead ) |
#define getset_readonly (G.getset_readonly ) |
333 |
#define set_readonly (G.set_readonly ) |
#define getset_unmask (G.getset_unmask ) |
334 |
#define get_readonly (G.get_readonly ) |
#define getset_mult (G.getset_mult ) |
335 |
#define set_unmask (G.set_unmask ) |
#define getset_dma_q (G.getset_dma_q ) |
336 |
#define get_unmask (G.get_unmask ) |
#define getset_nowerr (G.getset_nowerr ) |
337 |
#define set_mult (G.set_mult ) |
#define getset_keep (G.getset_keep ) |
338 |
#define get_mult (G.get_mult ) |
#define getset_io32bit (G.getset_io32bit ) |
|
#define set_dma_q (G.set_dma_q ) |
|
|
#define get_dma_q (G.get_dma_q ) |
|
|
#define set_nowerr (G.set_nowerr ) |
|
|
#define get_nowerr (G.get_nowerr ) |
|
|
#define set_keep (G.set_keep ) |
|
|
#define get_keep (G.get_keep ) |
|
|
#define set_io32bit (G.set_io32bit ) |
|
|
#define get_io32bit (G.get_io32bit ) |
|
339 |
#define piomode (G.piomode ) |
#define piomode (G.piomode ) |
340 |
#define Xreadahead (G.Xreadahead ) |
#define Xreadahead (G.Xreadahead ) |
341 |
#define readonly (G.readonly ) |
#define readonly (G.readonly ) |
346 |
#define keep (G.keep ) |
#define keep (G.keep ) |
347 |
#define io32bit (G.io32bit ) |
#define io32bit (G.io32bit ) |
348 |
#define dma (G.dma ) |
#define dma (G.dma ) |
349 |
#define set_dma (G.set_dma ) |
#define getset_dma (G.getset_dma ) |
|
#define get_dma (G.get_dma ) |
|
350 |
#define set_xfermode (G.set_xfermode ) |
#define set_xfermode (G.set_xfermode ) |
351 |
#define get_xfermode (G.get_xfermode ) |
#define get_xfermode (G.get_xfermode ) |
352 |
#define set_dkeep (G.set_dkeep ) |
#define getset_dkeep (G.getset_dkeep ) |
353 |
#define get_dkeep (G.get_dkeep ) |
#define getset_standby (G.getset_standby ) |
354 |
#define set_standby (G.set_standby ) |
#define getset_lookahead (G.getset_lookahead ) |
355 |
#define get_standby (G.get_standby ) |
#define getset_prefetch (G.getset_prefetch ) |
356 |
#define set_lookahead (G.set_lookahead ) |
#define getset_defects (G.getset_defects ) |
357 |
#define get_lookahead (G.get_lookahead ) |
#define getset_wcache (G.getset_wcache ) |
358 |
#define set_prefetch (G.set_prefetch ) |
#define getset_doorlock (G.getset_doorlock ) |
|
#define get_prefetch (G.get_prefetch ) |
|
|
#define set_defects (G.set_defects ) |
|
|
#define get_defects (G.get_defects ) |
|
|
#define set_wcache (G.set_wcache ) |
|
|
#define get_wcache (G.get_wcache ) |
|
|
#define set_doorlock (G.set_doorlock ) |
|
|
#define get_doorlock (G.get_doorlock ) |
|
359 |
#define set_seagate (G.set_seagate ) |
#define set_seagate (G.set_seagate ) |
|
#define get_seagate (G.get_seagate ) |
|
360 |
#define set_standbynow (G.set_standbynow ) |
#define set_standbynow (G.set_standbynow ) |
|
#define get_standbynow (G.get_standbynow ) |
|
361 |
#define set_sleepnow (G.set_sleepnow ) |
#define set_sleepnow (G.set_sleepnow ) |
|
#define get_sleepnow (G.get_sleepnow ) |
|
362 |
#define get_powermode (G.get_powermode ) |
#define get_powermode (G.get_powermode ) |
363 |
#define set_apmmode (G.set_apmmode ) |
#define getset_apmmode (G.getset_apmmode ) |
|
#define get_apmmode (G.get_apmmode ) |
|
364 |
#define xfermode_requested (G.xfermode_requested ) |
#define xfermode_requested (G.xfermode_requested ) |
365 |
#define dkeep (G.dkeep ) |
#define dkeep (G.dkeep ) |
366 |
#define standby_requested (G.standby_requested ) |
#define standby_requested (G.standby_requested ) |
371 |
#define doorlock (G.doorlock ) |
#define doorlock (G.doorlock ) |
372 |
#define apmmode (G.apmmode ) |
#define apmmode (G.apmmode ) |
373 |
#define get_IDentity (G.get_IDentity ) |
#define get_IDentity (G.get_IDentity ) |
374 |
#define set_busstate (G.set_busstate ) |
#define getset_busstate (G.getset_busstate ) |
|
#define get_busstate (G.get_busstate ) |
|
375 |
#define perform_reset (G.perform_reset ) |
#define perform_reset (G.perform_reset ) |
376 |
#define perform_tristate (G.perform_tristate ) |
#define perform_tristate (G.perform_tristate ) |
377 |
#define unregister_hwif (G.unregister_hwif ) |
#define unregister_hwif (G.unregister_hwif ) |
680 |
swab(val, buf, sizeof(buf)); |
swab(val, buf, sizeof(buf)); |
681 |
val = buf; |
val = buf; |
682 |
#endif |
#endif |
683 |
/* check if we recognise the device type */ |
/* check if we recognize the device type */ |
684 |
bb_putchar('\n'); |
bb_putchar('\n'); |
685 |
if (!(val[GEN_CONFIG] & NOT_ATA)) { |
if (!(val[GEN_CONFIG] & NOT_ATA)) { |
686 |
dev = ATA_DEV; |
dev = ATA_DEV; |
854 |
} else { |
} else { |
855 |
/* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ |
/* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ |
856 |
ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; |
ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; |
857 |
mm = 0; bbbig = 0; |
mm = 0; |
858 |
|
bbbig = 0; |
859 |
if ((ll > 0x00FBFC10) && (!val[LCYLS])) |
if ((ll > 0x00FBFC10) && (!val[LCYLS])) |
860 |
printf("\tCHS addressing not supported\n"); |
printf("\tCHS addressing not supported\n"); |
861 |
else { |
else { |
862 |
jj = val[WHATS_VALID] & OK_W54_58; |
jj = val[WHATS_VALID] & OK_W54_58; |
863 |
printf("\tLogical\t\tmax\tcurrent\n\tcylinders\t%u\t%u\n\theads\t\t%u\t%u\n\tsectors/track\t%u\t%u\n\t--\n", |
printf("\tLogical\t\tmax\tcurrent\n" |
864 |
val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); |
"\tcylinders\t%u\t%u\n" |
865 |
|
"\theads\t\t%u\t%u\n" |
866 |
|
"\tsectors/track\t%u\t%u\n" |
867 |
|
"\t--\n", |
868 |
|
val[LCYLS], |
869 |
|
jj ? val[LCYLS_CUR] : 0, |
870 |
|
val[LHEADS], |
871 |
|
jj ? val[LHEADS_CUR] : 0, |
872 |
|
val[LSECTS], |
873 |
|
jj ? val[LSECTS_CUR] : 0); |
874 |
|
|
875 |
if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) |
if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) |
876 |
printf("\tbytes/track: %u\tbytes/sector: %u\n", val[TRACK_BYTES], val[SECT_BYTES]); |
printf("\tbytes/track: %u\tbytes/sector: %u\n", |
877 |
|
val[TRACK_BYTES], val[SECT_BYTES]); |
878 |
|
|
879 |
if (jj) { |
if (jj) { |
880 |
mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; |
mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; |
916 |
printf("Capabilities:\n\t"); |
printf("Capabilities:\n\t"); |
917 |
|
|
918 |
if (dev == ATAPI_DEV) { |
if (dev == ATAPI_DEV) { |
919 |
if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, "); |
if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) |
920 |
if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); |
printf("Cmd queuing, "); |
921 |
|
if (val[CAPAB_0] & OVLP_SUP) |
922 |
|
printf("Cmd overlap, "); |
923 |
} |
} |
924 |
if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); |
if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); |
925 |
|
|
926 |
if (like_std != 1) { |
if (like_std != 1) { |
927 |
printf("IORDY%s(can%s be disabled)\n", |
printf("IORDY%s(can%s be disabled)\n", |
928 |
!(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", |
!(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", |
929 |
(val[CAPAB_0] & IORDY_OFF) ? "" :"not"); |
(val[CAPAB_0] & IORDY_OFF) ? "" :"not"); |
930 |
} else |
} else |
931 |
printf("no IORDY\n"); |
printf("no IORDY\n"); |
932 |
|
|
933 |
if ((like_std == 1) && val[BUF_TYPE]) { |
if ((like_std == 1) && val[BUF_TYPE]) { |
934 |
printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], |
printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], |
935 |
(val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", |
(val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", |
936 |
(val[BUF_TYPE] > 2) ? " with read caching ability" : ""); |
(val[BUF_TYPE] > 2) ? " with read caching ability" : ""); |
937 |
} |
} |
938 |
|
|
939 |
if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { |
if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { |
950 |
if (like_std == 1) |
if (like_std == 1) |
951 |
printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : ""); |
printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : ""); |
952 |
else { |
else { |
953 |
printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor"); |
printf("\tStandby timer values: spec'd by %s", |
954 |
|
(val[CAPAB_0] & STD_STBY) ? "standard" : "vendor"); |
955 |
if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
956 |
printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); |
printf(", %s device specific minimum\n", |
957 |
|
(val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); |
958 |
else |
else |
959 |
bb_putchar('\n'); |
bb_putchar('\n'); |
960 |
} |
} |
982 |
} |
} |
983 |
if (like_std > 5 && val[ACOUSTIC]) { |
if (like_std > 5 && val[ACOUSTIC]) { |
984 |
printf("\tRecommended acoustic management value: %u, current value: %u\n", |
printf("\tRecommended acoustic management value: %u, current value: %u\n", |
985 |
(val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); |
(val[ACOUSTIC] >> 8) & 0x00ff, |
986 |
|
val[ACOUSTIC] & 0x00ff); |
987 |
} |
} |
988 |
} else { |
} else { |
989 |
/* ATAPI */ |
/* ATAPI */ |
992 |
|
|
993 |
if (val[PKT_REL] || val[SVC_NBSY]) { |
if (val[PKT_REL] || val[SVC_NBSY]) { |
994 |
printf("\tOverlap support:"); |
printf("\tOverlap support:"); |
995 |
if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]); |
if (val[PKT_REL]) |
996 |
if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]); |
printf(" %uus to release bus.", val[PKT_REL]); |
997 |
|
if (val[SVC_NBSY]) |
998 |
|
printf(" %uus to clear BSY after SERVICE cmd.", |
999 |
|
val[SVC_NBSY]); |
1000 |
bb_putchar('\n'); |
bb_putchar('\n'); |
1001 |
} |
} |
1002 |
} |
} |
1060 |
if (val[WHATS_VALID] & OK_W64_70) { |
if (val[WHATS_VALID] & OK_W64_70) { |
1061 |
if (val[PIO_NO_FLOW] || val[PIO_FLOW]) { |
if (val[PIO_NO_FLOW] || val[PIO_FLOW]) { |
1062 |
printf("\t\tCycle time:"); |
printf("\t\tCycle time:"); |
1063 |
if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
if (val[PIO_NO_FLOW]) |
1064 |
if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
1065 |
|
if (val[PIO_FLOW]) |
1066 |
|
printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
1067 |
bb_putchar('\n'); |
bb_putchar('\n'); |
1068 |
} |
} |
1069 |
} |
} |
1070 |
|
|
1071 |
if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) { |
if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) { |
1072 |
printf("Commands/features:\n\tEnabled\tSupported:\n"); |
printf("Commands/features:\n" |
1073 |
|
"\tEnabled\tSupported:\n"); |
1074 |
jj = val[CMDS_SUPP_0]; |
jj = val[CMDS_SUPP_0]; |
1075 |
kk = val[CMDS_EN_0]; |
kk = val[CMDS_EN_0]; |
1076 |
for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { |
for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { |
1104 |
jj = val[SECU_STATUS]; |
jj = val[SECU_STATUS]; |
1105 |
if (jj) { |
if (jj) { |
1106 |
for (ii = 0; ii < NUM_SECU_STR; ii++) { |
for (ii = 0; ii < NUM_SECU_STR; ii++) { |
1107 |
printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", nth_string(secu_str, ii)); |
printf("\t%s\t%s\n", |
1108 |
|
(!(jj & 0x0001)) ? "not" : "", |
1109 |
|
nth_string(secu_str, ii)); |
1110 |
jj >>=1; |
jj >>=1; |
1111 |
} |
} |
1112 |
if (val[SECU_STATUS] & SECU_ENABLED) { |
if (val[SECU_STATUS] & SECU_ENABLED) { |
1113 |
printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); |
printf("\tSecurity level %s\n", |
1114 |
|
(val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); |
1115 |
} |
} |
1116 |
} |
} |
1117 |
jj = val[ERASE_TIME] & ERASE_BITS; |
jj = val[ERASE_TIME] & ERASE_BITS; |
1136 |
strng = " determined by CSEL"; |
strng = " determined by CSEL"; |
1137 |
else |
else |
1138 |
strng = ""; |
strng = ""; |
1139 |
printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", |
printf("HW reset results:\n" |
1140 |
(val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng); |
"\tCBLID- %s Vih\n" |
1141 |
|
"\tDevice num = %i%s\n", |
1142 |
|
(val[HWRST_RSLT] & CBLID) ? "above" : "below", |
1143 |
|
!(oo), strng); |
1144 |
} |
} |
1145 |
|
|
1146 |
/* more stuff from std 5 */ |
/* more stuff from std 5 */ |
1147 |
if ((like_std > 4) && (eqpt != CDROM)) { |
if ((like_std > 4) && (eqpt != CDROM)) { |
1148 |
if (val[CFA_PWR_MODE] & VALID_W160) { |
if (val[CFA_PWR_MODE] & VALID_W160) { |
1149 |
printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", |
printf("CFA power mode 1:\n" |
1150 |
(val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); |
"\t%s%s\n", |
1151 |
|
(val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", |
1152 |
|
(val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); |
1153 |
if (val[CFA_PWR_MODE] & MAX_AMPS) |
if (val[CFA_PWR_MODE] & MAX_AMPS) |
1154 |
printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS); |
printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS); |
1155 |
} |
} |
1185 |
"unknown""\0" "1Sect""\0" "DualPort""\0" "DualPortCache" |
"unknown""\0" "1Sect""\0" "DualPort""\0" "DualPortCache" |
1186 |
; |
; |
1187 |
|
|
1188 |
static void dump_identity(const struct hd_driveid *id) |
static NOINLINE void dump_identity(const struct hd_driveid *id) |
1189 |
{ |
{ |
1190 |
int i; |
int i; |
1191 |
const unsigned short *id_regs = (const void*) id; |
const unsigned short *id_regs = (const void*) id; |
1197 |
printf(" %s", nth_string(cfg_str, i)); |
printf(" %s", nth_string(cfg_str, i)); |
1198 |
} |
} |
1199 |
printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" |
printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" |
1200 |
" BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", |
" BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", |
1201 |
id->cyls, id->heads, id->sectors, id->track_bytes, |
id->cyls, id->heads, id->sectors, id->track_bytes, |
1202 |
id->sector_bytes, id->ecc_bytes, |
id->sector_bytes, id->ecc_bytes, |
1203 |
id->buf_type, nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type), |
id->buf_type, |
1204 |
id->buf_size/2, id->max_multsect); |
nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type), |
1205 |
|
id->buf_size/2, id->max_multsect); |
1206 |
if (id->max_multsect) { |
if (id->max_multsect) { |
1207 |
printf(", MultSect="); |
printf(", MultSect="); |
1208 |
if (!(id->multsect_valid & 1)) |
if (!(id->multsect_valid & 1)) |
1227 |
if (id->capability & 2) |
if (id->capability & 2) |
1228 |
printf(", LBAsects=%u", id->lba_capacity); |
printf(", LBAsects=%u", id->lba_capacity); |
1229 |
|
|
1230 |
printf("\n IORDY=%s", (id->capability & 8) ? (id->capability & 4) ? "on/off" : "yes" : "no"); |
printf("\n IORDY=%s", |
1231 |
|
(id->capability & 8) |
1232 |
|
? ((id->capability & 4) ? "on/off" : "yes") |
1233 |
|
: "no"); |
1234 |
|
|
1235 |
if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2)) |
if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2)) |
1236 |
printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); |
printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); |
1259 |
"*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0", |
"*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0", |
1260 |
id->dma_1word, NULL); |
id->dma_1word, NULL); |
1261 |
print_flags_separated(dma_wmode_masks, |
print_flags_separated(dma_wmode_masks, |
1262 |
"*\0""mdma0\0""*\0""mdma1\0""*\0""mdma2\0""*\0""mdma?\0", |
"*\0""mdma0 \0""*\0""mdma1 \0""*\0""mdma2 \0""*\0""mdma? \0", |
1263 |
id->dma_mword, NULL); |
id->dma_mword, NULL); |
1264 |
} |
} |
1265 |
} |
} |
1302 |
if ((id->minor_rev_num && id->minor_rev_num <= 31) |
if ((id->minor_rev_num && id->minor_rev_num <= 31) |
1303 |
|| (id->major_rev_num && id->minor_rev_num <= 31) |
|| (id->major_rev_num && id->minor_rev_num <= 31) |
1304 |
) { |
) { |
1305 |
printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown"); |
printf("\n Drive conforms to: %s: ", |
1306 |
if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ |
(id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown"); |
1307 |
id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ |
if (id->major_rev_num != 0x0000 /* NOVAL_0 */ |
1308 |
|
&& id->major_rev_num != 0xFFFF /* NOVAL_1 */ |
1309 |
|
) { |
1310 |
for (i = 0; i <= 15; i++) { |
for (i = 0; i <= 15; i++) { |
1311 |
if (id->major_rev_num & (1<<i)) |
if (id->major_rev_num & (1<<i)) |
1312 |
printf(" ATA/ATAPI-%u", i); |
printf(" ATA/ATAPI-%u", i); |
1313 |
} |
} |
1314 |
} |
} |
1315 |
} |
} |
1406 |
} else { /* Time device */ |
} else { /* Time device */ |
1407 |
printf("Timing buffered disk reads:"); |
printf("Timing buffered disk reads:"); |
1408 |
} |
} |
1409 |
fflush(stdout); |
fflush_all(); |
1410 |
|
|
1411 |
/* Now do the timing */ |
/* Now do the timing */ |
1412 |
iterations = 0; |
iterations = 0; |
1469 |
printf("off"); |
printf("off"); |
1470 |
} else if (standby <= 240 || standby == 252 || standby == 255) { |
} else if (standby <= 240 || standby == 252 || standby == 255) { |
1471 |
/* standby is in 5 sec units */ |
/* standby is in 5 sec units */ |
1472 |
printf("%u minutes %u seconds", standby / 12, (standby*5) % 60); |
unsigned t = standby * 5; |
1473 |
|
printf("%u minutes %u seconds", t / 60, t % 60); |
1474 |
} else if (standby <= 251) { |
} else if (standby <= 251) { |
1475 |
unsigned t = (standby - 240); /* t is in 30 min units */; |
unsigned t = (standby - 240); /* t is in 30 min units */; |
1476 |
printf("%u.%c hours", t / 2, (t & 1) ? '0' : '5'); |
printf("%u.%c hours", t / 2, (t & 1) ? '5' : '0'); |
1477 |
} |
} |
1478 |
if (standby == 253) |
if (standby == 253) |
1479 |
printf("vendor-specific"); |
printf("vendor-specific"); |
1552 |
unsigned char args[4] = { WIN_SETFEATURES, 0, 0, 0 }; |
unsigned char args[4] = { WIN_SETFEATURES, 0, 0, 0 }; |
1553 |
const char *fmt = " %s\t= %2ld"; |
const char *fmt = " %s\t= %2ld"; |
1554 |
|
|
1555 |
/*fd = xopen(devname, O_RDONLY | O_NONBLOCK);*/ |
/*fd = xopen_nonblocking(devname);*/ |
1556 |
xmove_fd(xopen(devname, O_RDONLY | O_NONBLOCK), fd); |
xmove_fd(xopen_nonblocking(devname), fd); |
1557 |
printf("\n%s:\n", devname); |
printf("\n%s:\n", devname); |
1558 |
|
|
1559 |
if (set_readahead) { |
if (getset_readahead == IS_SET) { |
1560 |
print_flag(get_readahead, "fs readahead", Xreadahead); |
print_flag(getset_readahead, "fs readahead", Xreadahead); |
1561 |
ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead); |
ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead); |
1562 |
} |
} |
1563 |
#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
1567 |
} |
} |
1568 |
#endif |
#endif |
1569 |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
1570 |
if (scan_hwif) { |
if (scan_hwif == IS_SET) { |
1571 |
printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq); |
printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq); |
1572 |
args[0] = hwif_data; |
args[0] = hwif_data; |
1573 |
args[1] = hwif_ctrl; |
args[1] = hwif_ctrl; |
1591 |
} |
} |
1592 |
ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode); |
ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode); |
1593 |
} |
} |
1594 |
if (set_io32bit) { |
if (getset_io32bit == IS_SET) { |
1595 |
print_flag(get_io32bit, "32-bit IO_support flag", io32bit); |
print_flag(getset_io32bit, "32-bit IO_support flag", io32bit); |
1596 |
ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit); |
ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit); |
1597 |
} |
} |
1598 |
if (set_mult) { |
if (getset_mult == IS_SET) { |
1599 |
print_flag(get_mult, "multcount", mult); |
print_flag(getset_mult, "multcount", mult); |
1600 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
1601 |
ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult); |
ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult); |
1602 |
#else |
#else |
1603 |
force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult)); |
force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult)); |
1604 |
#endif |
#endif |
1605 |
} |
} |
1606 |
if (set_readonly) { |
if (getset_readonly == IS_SET) { |
1607 |
print_flag_on_off(get_readonly, "readonly", readonly); |
print_flag_on_off(getset_readonly, "readonly", readonly); |
1608 |
ioctl_or_warn(fd, BLKROSET, &readonly); |
ioctl_or_warn(fd, BLKROSET, &readonly); |
1609 |
} |
} |
1610 |
if (set_unmask) { |
if (getset_unmask == IS_SET) { |
1611 |
print_flag_on_off(get_unmask, "unmaskirq", unmask); |
print_flag_on_off(getset_unmask, "unmaskirq", unmask); |
1612 |
ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask); |
ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask); |
1613 |
} |
} |
1614 |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
1615 |
if (set_dma) { |
if (getset_dma == IS_SET) { |
1616 |
print_flag_on_off(get_dma, "using_dma", dma); |
print_flag_on_off(getset_dma, "using_dma", dma); |
1617 |
ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma); |
ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma); |
1618 |
} |
} |
1619 |
#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */ |
#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */ |
1620 |
#ifdef HDIO_SET_QDMA |
#ifdef HDIO_SET_QDMA |
1621 |
if (set_dma_q) { |
if (getset_dma_q == IS_SET) { |
1622 |
print_flag_on_off(get_dma_q, "DMA queue_depth", dma_q); |
print_flag_on_off(getset_dma_q, "DMA queue_depth", dma_q); |
1623 |
ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q); |
ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q); |
1624 |
} |
} |
1625 |
#endif |
#endif |
1626 |
if (set_nowerr) { |
if (getset_nowerr == IS_SET) { |
1627 |
print_flag_on_off(get_nowerr, "nowerr", nowerr); |
print_flag_on_off(getset_nowerr, "nowerr", nowerr); |
1628 |
ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr); |
ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr); |
1629 |
} |
} |
1630 |
if (set_keep) { |
if (getset_keep == IS_SET) { |
1631 |
print_flag_on_off(get_keep, "keep_settings", keep); |
print_flag_on_off(getset_keep, "keep_settings", keep); |
1632 |
ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep); |
ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep); |
1633 |
} |
} |
1634 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
1635 |
if (set_doorlock) { |
if (getset_doorlock == IS_SET) { |
1636 |
args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
1637 |
args[2] = 0; |
args[2] = 0; |
1638 |
print_flag_on_off(get_doorlock, "drive doorlock", doorlock); |
print_flag_on_off(getset_doorlock, "drive doorlock", doorlock); |
1639 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1640 |
args[0] = WIN_SETFEATURES; |
args[0] = WIN_SETFEATURES; |
1641 |
} |
} |
1642 |
if (set_dkeep) { |
if (getset_dkeep == IS_SET) { |
1643 |
/* lock/unlock the drive's "feature" settings */ |
/* lock/unlock the drive's "feature" settings */ |
1644 |
print_flag_on_off(get_dkeep, "drive keep features", dkeep); |
print_flag_on_off(getset_dkeep, "drive keep features", dkeep); |
1645 |
args[2] = dkeep ? 0x66 : 0xcc; |
args[2] = dkeep ? 0x66 : 0xcc; |
1646 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1647 |
} |
} |
1648 |
if (set_defects) { |
if (getset_defects == IS_SET) { |
1649 |
args[2] = defects ? 0x04 : 0x84; |
args[2] = defects ? 0x04 : 0x84; |
1650 |
print_flag(get_defects, "drive defect-mgmt", defects); |
print_flag(getset_defects, "drive defect-mgmt", defects); |
1651 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1652 |
} |
} |
1653 |
if (set_prefetch) { |
if (getset_prefetch == IS_SET) { |
1654 |
args[1] = prefetch; |
args[1] = prefetch; |
1655 |
args[2] = 0xab; |
args[2] = 0xab; |
1656 |
print_flag(get_prefetch, "drive prefetch", prefetch); |
print_flag(getset_prefetch, "drive prefetch", prefetch); |
1657 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1658 |
args[1] = 0; |
args[1] = 0; |
1659 |
} |
} |
1660 |
if (set_xfermode) { |
if (set_xfermode) { |
1661 |
args[1] = xfermode_requested; |
args[1] = xfermode_requested; |
1662 |
args[2] = 3; |
args[2] = 3; |
1663 |
if (get_xfermode) { |
print_flag(1, "xfermode", xfermode_requested); |
1664 |
print_flag(1, "xfermode", xfermode_requested); |
interpret_xfermode(xfermode_requested); |
|
interpret_xfermode(xfermode_requested); |
|
|
} |
|
1665 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1666 |
args[1] = 0; |
args[1] = 0; |
1667 |
} |
} |
1668 |
if (set_lookahead) { |
if (getset_lookahead == IS_SET) { |
1669 |
args[2] = lookahead ? 0xaa : 0x55; |
args[2] = lookahead ? 0xaa : 0x55; |
1670 |
print_flag_on_off(get_lookahead, "drive read-lookahead", lookahead); |
print_flag_on_off(getset_lookahead, "drive read-lookahead", lookahead); |
1671 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1672 |
} |
} |
1673 |
if (set_apmmode) { |
if (getset_apmmode == IS_SET) { |
1674 |
args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ |
/* feature register */ |
1675 |
|
args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; |
1676 |
args[1] = apmmode; /* sector count register 1-255 */ |
args[1] = apmmode; /* sector count register 1-255 */ |
1677 |
if (get_apmmode) |
printf(" setting APM level to %s 0x%02lX (%ld)\n", |
1678 |
printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); |
(apmmode == 255) ? "disabled" : "", |
1679 |
|
apmmode, apmmode); |
1680 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1681 |
args[1] = 0; |
args[1] = 0; |
1682 |
} |
} |
1683 |
if (set_wcache) { |
if (getset_wcache == IS_SET) { |
1684 |
#ifdef DO_FLUSHCACHE |
#ifdef DO_FLUSHCACHE |
1685 |
#ifndef WIN_FLUSHCACHE |
#ifndef WIN_FLUSHCACHE |
1686 |
#define WIN_FLUSHCACHE 0xe7 |
#define WIN_FLUSHCACHE 0xe7 |
1687 |
#endif |
#endif |
1688 |
#endif /* DO_FLUSHCACHE */ |
#endif /* DO_FLUSHCACHE */ |
1689 |
args[2] = wcache ? 0x02 : 0x82; |
args[2] = wcache ? 0x02 : 0x82; |
1690 |
print_flag_on_off(get_wcache, "drive write-caching", wcache); |
print_flag_on_off(getset_wcache, "drive write-caching", wcache); |
1691 |
#ifdef DO_FLUSHCACHE |
#ifdef DO_FLUSHCACHE |
1692 |
if (!wcache) |
if (!wcache) |
1693 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache); |
1710 |
#ifndef WIN_STANDBYNOW2 |
#ifndef WIN_STANDBYNOW2 |
1711 |
#define WIN_STANDBYNOW2 0x94 |
#define WIN_STANDBYNOW2 0x94 |
1712 |
#endif |
#endif |
1713 |
if (get_standbynow) printf(" issuing standby command\n"); |
printf(" issuing standby command\n"); |
1714 |
args[0] = WIN_STANDBYNOW1; |
args[0] = WIN_STANDBYNOW1; |
1715 |
ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2); |
ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2); |
1716 |
} |
} |
1721 |
#ifndef WIN_SLEEPNOW2 |
#ifndef WIN_SLEEPNOW2 |
1722 |
#define WIN_SLEEPNOW2 0x99 |
#define WIN_SLEEPNOW2 0x99 |
1723 |
#endif |
#endif |
1724 |
if (get_sleepnow) printf(" issuing sleep command\n"); |
printf(" issuing sleep command\n"); |
1725 |
args[0] = WIN_SLEEPNOW1; |
args[0] = WIN_SLEEPNOW1; |
1726 |
ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2); |
ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2); |
1727 |
} |
} |
1728 |
if (set_seagate) { |
if (set_seagate) { |
1729 |
args[0] = 0xfb; |
args[0] = 0xfb; |
1730 |
if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); |
printf(" disabling Seagate auto powersaving mode\n"); |
1731 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1732 |
} |
} |
1733 |
if (set_standby) { |
if (getset_standby == IS_SET) { |
1734 |
args[0] = WIN_SETIDLE1; |
args[0] = WIN_SETIDLE1; |
1735 |
args[1] = standby_requested; |
args[1] = standby_requested; |
1736 |
if (get_standby) { |
print_flag(1, "standby", standby_requested); |
1737 |
print_flag(1, "standby", standby_requested); |
interpret_standby(standby_requested); |
|
interpret_standby(standby_requested); |
|
|
} |
|
1738 |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
1739 |
args[1] = 0; |
args[1] = 0; |
1740 |
} |
} |
1743 |
char buf[512]; |
char buf[512]; |
1744 |
flush_buffer_cache(); |
flush_buffer_cache(); |
1745 |
if (-1 == read(fd, buf, sizeof(buf))) |
if (-1 == read(fd, buf, sizeof(buf))) |
1746 |
bb_perror_msg("read(%d bytes) failed (rc=-1)", sizeof(buf)); |
bb_perror_msg("read of 512 bytes failed"); |
1747 |
} |
} |
1748 |
#endif /* HDIO_DRIVE_CMD */ |
#endif /* HDIO_DRIVE_CMD */ |
1749 |
|
if (getset_mult || get_identity) { |
|
if (get_mult || get_identity) { |
|
1750 |
multcount = -1; |
multcount = -1; |
1751 |
if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { |
if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { |
1752 |
if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn. */ |
/* To be coherent with ioctl_or_warn. */ |
1753 |
|
if (getset_mult && ENABLE_IOCTL_HEX2STR_ERROR) |
1754 |
bb_perror_msg("HDIO_GET_MULTCOUNT"); |
bb_perror_msg("HDIO_GET_MULTCOUNT"); |
1755 |
else |
else |
1756 |
bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT); |
bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT); |
1757 |
} else if (get_mult) { |
} else if (getset_mult) { |
1758 |
printf(fmt, "multcount", multcount); |
printf(fmt, "multcount", multcount); |
1759 |
on_off(multcount != 0); |
on_off(multcount != 0); |
1760 |
} |
} |
1761 |
} |
} |
1762 |
if (get_io32bit) { |
if (getset_io32bit) { |
1763 |
if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) { |
if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) { |
1764 |
printf(" IO_support\t=%3ld (", parm); |
printf(" IO_support\t=%3ld (", parm); |
1765 |
if (parm == 0) |
if (parm == 0) |
1776 |
printf("\?\?\?)\n"); |
printf("\?\?\?)\n"); |
1777 |
} |
} |
1778 |
} |
} |
1779 |
if (get_unmask) { |
if (getset_unmask) { |
1780 |
if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm)) |
if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm)) |
1781 |
print_value_on_off("unmaskirq", parm); |
print_value_on_off("unmaskirq", parm); |
1782 |
} |
} |
|
|
|
|
|
|
1783 |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
1784 |
if (get_dma) { |
if (getset_dma) { |
1785 |
if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) { |
if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) { |
1786 |
printf(fmt, "using_dma", parm); |
printf(fmt, "using_dma", parm); |
1787 |
if (parm == 8) |
if (parm == 8) |
1792 |
} |
} |
1793 |
#endif |
#endif |
1794 |
#ifdef HDIO_GET_QDMA |
#ifdef HDIO_GET_QDMA |
1795 |
if (get_dma_q) { |
if (getset_dma_q) { |
1796 |
if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm)) |
if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm)) |
1797 |
print_value_on_off("queue_depth", parm); |
print_value_on_off("queue_depth", parm); |
1798 |
} |
} |
1799 |
#endif |
#endif |
1800 |
if (get_keep) { |
if (getset_keep) { |
1801 |
if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm)) |
if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm)) |
1802 |
print_value_on_off("keepsettings", parm); |
print_value_on_off("keepsettings", parm); |
1803 |
} |
} |
1804 |
|
if (getset_nowerr) { |
|
if (get_nowerr) { |
|
1805 |
if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm)) |
if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm)) |
1806 |
print_value_on_off("nowerr", parm); |
print_value_on_off("nowerr", parm); |
1807 |
} |
} |
1808 |
if (get_readonly) { |
if (getset_readonly) { |
1809 |
if (!ioctl_or_warn(fd, BLKROGET, &parm)) |
if (!ioctl_or_warn(fd, BLKROGET, &parm)) |
1810 |
print_value_on_off("readonly", parm); |
print_value_on_off("readonly", parm); |
1811 |
} |
} |
1812 |
if (get_readahead) { |
if (getset_readahead) { |
1813 |
if (!ioctl_or_warn(fd, BLKRAGET, &parm)) |
if (!ioctl_or_warn(fd, BLKRAGET, &parm)) |
1814 |
print_value_on_off("readahead", parm); |
print_value_on_off("readahead", parm); |
1815 |
} |
} |
1819 |
|
|
1820 |
if (!ioctl_or_warn(fd, HDIO_GETGEO, &g)) |
if (!ioctl_or_warn(fd, HDIO_GETGEO, &g)) |
1821 |
printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", |
printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", |
1822 |
g.cylinders, g.heads, g.sectors, parm, g.start); |
g.cylinders, g.heads, g.sectors, parm, g.start); |
1823 |
} |
} |
1824 |
} |
} |
1825 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
1887 |
} |
} |
1888 |
#endif |
#endif |
1889 |
#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
1890 |
if (set_busstate) { |
if (getset_busstate == IS_SET) { |
1891 |
if (get_busstate) { |
print_flag(1, "bus state", busstate); |
1892 |
print_flag(1, "bus state", busstate); |
bus_state_value(busstate); |
|
bus_state_value(busstate); |
|
|
} |
|
1893 |
ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate); |
ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate); |
1894 |
} |
} |
1895 |
if (get_busstate) { |
if (getset_busstate) { |
1896 |
if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) { |
if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) { |
1897 |
printf(fmt, "bus state", parm); |
printf(fmt, "bus state", parm); |
1898 |
bus_state_value(parm); |
bus_state_value(parm); |
1948 |
#endif |
#endif |
1949 |
|
|
1950 |
/* busybox specific stuff */ |
/* busybox specific stuff */ |
1951 |
static void parse_opts(smallint *get, smallint *set, unsigned long *value, int min, int max) |
static int parse_opts(unsigned long *value, int min, int max) |
1952 |
{ |
{ |
|
if (get) { |
|
|
*get = 1; |
|
|
} |
|
1953 |
if (optarg) { |
if (optarg) { |
|
*set = 1; |
|
1954 |
*value = xatol_range(optarg, min, max); |
*value = xatol_range(optarg, min, max); |
1955 |
|
return IS_SET; |
1956 |
} |
} |
1957 |
|
return IS_GET; |
1958 |
|
} |
1959 |
|
static int parse_opts_0_max(unsigned long *value, int max) |
1960 |
|
{ |
1961 |
|
return parse_opts(value, 0, max); |
1962 |
|
} |
1963 |
|
static int parse_opts_0_1(unsigned long *value) |
1964 |
|
{ |
1965 |
|
return parse_opts(value, 0, 1); |
1966 |
|
} |
1967 |
|
static int parse_opts_0_INTMAX(unsigned long *value) |
1968 |
|
{ |
1969 |
|
return parse_opts(value, 0, INT_MAX); |
1970 |
} |
} |
1971 |
|
|
1972 |
static void parse_xfermode(int flag, smallint *get, smallint *set, int *value) |
static void parse_xfermode(int flag, smallint *get, smallint *set, int *value) |
1973 |
{ |
{ |
1974 |
if (flag) { |
if (flag) { |
1975 |
*get = 1; |
*get = IS_GET; |
1976 |
if (optarg) { |
if (optarg) { |
1977 |
*value = translate_xfermode(optarg); |
*value = translate_xfermode(optarg); |
1978 |
*set = (*value > -1); |
*set = (*value > -1); |
1983 |
/*------- getopt short options --------*/ |
/*------- getopt short options --------*/ |
1984 |
static const char hdparm_options[] ALIGN1 = |
static const char hdparm_options[] ALIGN1 = |
1985 |
"gfu::n::p:r::m::c::k::a::B:tT" |
"gfu::n::p:r::m::c::k::a::B:tT" |
1986 |
USE_FEATURE_HDPARM_GET_IDENTITY("iI") |
IF_FEATURE_HDPARM_GET_IDENTITY("iI") |
1987 |
USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") |
IF_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") |
1988 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
1989 |
"S:D:P:X:K:A:L:W:CyYzZ" |
"S:D:P:X:K:A:L:W:CyYzZ" |
1990 |
#endif |
#endif |
1991 |
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:") |
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:") |
1992 |
#ifdef HDIO_GET_QDMA |
#ifdef HDIO_GET_QDMA |
1993 |
#ifdef HDIO_SET_QDMA |
#ifdef HDIO_SET_QDMA |
1994 |
"Q:" |
"Q:" |
1996 |
"Q" |
"Q" |
1997 |
#endif |
#endif |
1998 |
#endif |
#endif |
1999 |
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET("w") |
IF_FEATURE_HDPARM_HDIO_DRIVE_RESET("w") |
2000 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:") |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:") |
2001 |
USE_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:"); |
IF_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:"); |
2002 |
/*-------------------------------------*/ |
/*-------------------------------------*/ |
2003 |
|
|
2004 |
/* our main() routine: */ |
/* our main() routine: */ |
2010 |
|
|
2011 |
while ((c = getopt(argc, argv, hdparm_options)) >= 0) { |
while ((c = getopt(argc, argv, hdparm_options)) >= 0) { |
2012 |
flagcount++; |
flagcount++; |
2013 |
USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); |
IF_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); |
2014 |
USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); |
IF_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); |
2015 |
get_geom |= (c == 'g'); |
get_geom |= (c == 'g'); |
2016 |
do_flush |= (c == 'f'); |
do_flush |= (c == 'f'); |
2017 |
if (c == 'u') parse_opts(&get_unmask, &set_unmask, &unmask, 0, 1); |
if (c == 'u') getset_unmask = parse_opts_0_1(&unmask); |
2018 |
USE_FEATURE_HDPARM_HDIO_GETSET_DMA(if (c == 'd') parse_opts(&get_dma, &set_dma, &dma, 0, 9)); |
IF_FEATURE_HDPARM_HDIO_GETSET_DMA( |
2019 |
if (c == 'n') parse_opts(&get_nowerr, &set_nowerr, &nowerr, 0, 1); |
if (c == 'd') getset_dma = parse_opts_0_max(&dma, 9); |
2020 |
|
) |
2021 |
|
if (c == 'n') getset_nowerr = parse_opts_0_1(&nowerr); |
2022 |
parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode); |
parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode); |
2023 |
if (c == 'r') parse_opts(&get_readonly, &set_readonly, &readonly, 0, 1); |
if (c == 'r') getset_readonly = parse_opts_0_1(&readonly); |
2024 |
if (c == 'm') parse_opts(&get_mult, &set_mult, &mult, 0, INT_MAX /*32*/); |
if (c == 'm') getset_mult = parse_opts_0_INTMAX(&mult /*32*/); |
2025 |
if (c == 'c') parse_opts(&get_io32bit, &set_io32bit, &io32bit, 0, INT_MAX /*8*/); |
if (c == 'c') getset_io32bit = parse_opts_0_INTMAX(&io32bit /*8*/); |
2026 |
if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1); |
if (c == 'k') getset_keep = parse_opts_0_1(&keep); |
2027 |
if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX); |
if (c == 'a') getset_readahead = parse_opts_0_INTMAX(&Xreadahead); |
2028 |
if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255); |
if (c == 'B') getset_apmmode = parse_opts(&apmmode, 1, 255); |
2029 |
do_flush |= do_timings |= (c == 't'); |
do_flush |= do_timings |= (c == 't'); |
2030 |
do_flush |= do_ctimings |= (c == 'T'); |
do_flush |= do_ctimings |= (c == 'T'); |
2031 |
#ifdef HDIO_DRIVE_CMD |
#ifdef HDIO_DRIVE_CMD |
2032 |
if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, 255); |
if (c == 'S') getset_standby = parse_opts_0_max(&standby_requested, 255); |
2033 |
if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX); |
if (c == 'D') getset_defects = parse_opts_0_INTMAX(&defects); |
2034 |
if (c == 'P') parse_opts(&get_prefetch, &set_prefetch, &prefetch, 0, INT_MAX); |
if (c == 'P') getset_prefetch = parse_opts_0_INTMAX(&prefetch); |
2035 |
parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested); |
parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested); |
2036 |
if (c == 'K') parse_opts(&get_dkeep, &set_dkeep, &prefetch, 0, 1); |
if (c == 'K') getset_dkeep = parse_opts_0_1(&prefetch); |
2037 |
if (c == 'A') parse_opts(&get_lookahead, &set_lookahead, &lookahead, 0, 1); |
if (c == 'A') getset_lookahead = parse_opts_0_1(&lookahead); |
2038 |
if (c == 'L') parse_opts(&get_doorlock, &set_doorlock, &doorlock, 0, 1); |
if (c == 'L') getset_doorlock = parse_opts_0_1(&doorlock); |
2039 |
if (c == 'W') parse_opts(&get_wcache, &set_wcache, &wcache, 0, 1); |
if (c == 'W') getset_wcache = parse_opts_0_1(&wcache); |
2040 |
get_powermode |= (c == 'C'); |
get_powermode |= (c == 'C'); |
2041 |
get_standbynow = set_standbynow |= (c == 'y'); |
set_standbynow |= (c == 'y'); |
2042 |
get_sleepnow = set_sleepnow |= (c == 'Y'); |
set_sleepnow |= (c == 'Y'); |
2043 |
reread_partn |= (c == 'z'); |
reread_partn |= (c == 'z'); |
2044 |
get_seagate = set_seagate |= (c == 'Z'); |
set_seagate |= (c == 'Z'); |
2045 |
#endif |
#endif |
2046 |
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX)); |
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') unregister_hwif = parse_opts_0_INTMAX(&hwif)); |
2047 |
#ifdef HDIO_GET_QDMA |
#ifdef HDIO_GET_QDMA |
2048 |
if (c == 'Q') { |
if (c == 'Q') { |
2049 |
#ifdef HDIO_SET_QDMA |
getset_dma_q = parse_opts_0_INTMAX(&dma_q); |
|
parse_opts(&get_dma_q, &set_dma_q, &dma_q, 0, INT_MAX); |
|
|
#else |
|
|
parse_opts(&get_dma_q, NULL, NULL, 0, 0); |
|
|
#endif |
|
2050 |
} |
} |
2051 |
#endif |
#endif |
2052 |
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r')); |
IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r')); |
2053 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1)); |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') perform_tristate = parse_opts_0_1(&tristate)); |
2054 |
USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2)); |
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') getset_busstate = parse_opts_0_max(&busstate, 2)); |
2055 |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
2056 |
if (c == 'R') { |
if (c == 'R') { |
2057 |
parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX); |
scan_hwif = parse_opts_0_INTMAX(&hwif_data); |
2058 |
hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : ""); |
hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : ""); |
2059 |
hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : ""); |
hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : ""); |
2060 |
/* Move past the 2 additional arguments */ |
/* Move past the 2 additional arguments */ |
2065 |
} |
} |
2066 |
/* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */ |
/* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */ |
2067 |
if (!flagcount) { |
if (!flagcount) { |
2068 |
get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1; |
getset_mult = getset_io32bit = getset_unmask = getset_keep = getset_readonly = getset_readahead = get_geom = IS_GET; |
2069 |
USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1); |
IF_FEATURE_HDPARM_HDIO_GETSET_DMA(getset_dma = IS_GET); |
2070 |
} |
} |
2071 |
argv += optind; |
argv += optind; |
2072 |
|
|