forked from topjohnwu/ndk-busybox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdparm.c
2200 lines (2055 loc) · 73.9 KB
/
hdparm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi: set sw=4 ts=4: */
/*
* hdparm implementation for busybox
*
* Copyright (C) [2003] by [Matteo Croce] <[email protected]>
* Hacked by Tito <[email protected]> for size optimization.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
* This program is based on the source code of hdparm: see below...
* hdparm.c - Command line interface to get/set hard disk parameters
* - by Mark Lord (C) 1994-2002 -- freely distributable
*/
//config:config HDPARM
//config: bool "hdparm (25 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Get/Set hard drive parameters. Primarily intended for ATA
//config: drives.
//config:
//config:config FEATURE_HDPARM_GET_IDENTITY
//config: bool "Support obtaining detailed information directly from drives"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the -I and -i options to obtain detailed information
//config: directly from drives about their capabilities and supported ATA
//config: feature set. If no device name is specified, hdparm will read
//config: identify data from stdin. Enabling this option will add about 16k...
//config:
//config:config FEATURE_HDPARM_HDIO_SCAN_HWIF
//config: bool "Register an IDE interface (DANGEROUS)"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the 'hdparm -R' option to register an IDE interface.
//config: This is dangerous stuff, so you should probably say N.
//config:
//config:config FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
//config: bool "Un-register an IDE interface (DANGEROUS)"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the 'hdparm -U' option to un-register an IDE interface.
//config: This is dangerous stuff, so you should probably say N.
//config:
//config:config FEATURE_HDPARM_HDIO_DRIVE_RESET
//config: bool "Perform device reset (DANGEROUS)"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the 'hdparm -w' option to perform a device reset.
//config: This is dangerous stuff, so you should probably say N.
//config:
//config:config FEATURE_HDPARM_HDIO_TRISTATE_HWIF
//config: bool "Tristate device for hotswap (DANGEROUS)"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the 'hdparm -x' option to tristate device for hotswap,
//config: and the '-b' option to get/set bus state. This is dangerous
//config: stuff, so you should probably say N.
//config:
//config:config FEATURE_HDPARM_HDIO_GETSET_DMA
//config: bool "Get/set using_dma flag"
//config: default y
//config: depends on HDPARM
//config: help
//config: Enable the 'hdparm -d' option to get/set using_dma flag.
//applet:IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_HDPARM) += hdparm.o
//usage:#define hdparm_trivial_usage
//usage: "[OPTIONS] [DEVICE]"
//usage:#define hdparm_full_usage "\n\n"
//usage: " -a Get/set fs readahead"
//usage: "\n -A Set drive read-lookahead flag (0/1)"
//usage: "\n -b Get/set bus state (0 == off, 1 == on, 2 == tristate)"
//usage: "\n -B Set Advanced Power Management setting (1-255)"
//usage: "\n -c Get/set IDE 32-bit IO setting"
//usage: "\n -C Check IDE power mode status"
//usage: IF_FEATURE_HDPARM_HDIO_GETSET_DMA(
//usage: "\n -d Get/set using_dma flag")
//usage: "\n -D Enable/disable drive defect-mgmt"
//usage: "\n -f Flush buffer cache for device on exit"
//usage: "\n -g Display drive geometry"
//usage: "\n -h Display terse usage information"
//usage: IF_FEATURE_HDPARM_GET_IDENTITY(
//usage: "\n -i Display drive identification")
//usage: IF_FEATURE_HDPARM_GET_IDENTITY(
//usage: "\n -I Detailed/current information directly from drive")
//usage: "\n -k Get/set keep_settings_over_reset flag (0/1)"
//usage: "\n -K Set drive keep_features_over_reset flag (0/1)"
//usage: "\n -L Set drive doorlock (0/1) (removable harddisks only)"
//usage: "\n -m Get/set multiple sector count"
//usage: "\n -n Get/set ignore-write-errors flag (0/1)"
//usage: "\n -p Set PIO mode on IDE interface chipset (0,1,2,3,4,...)"
//usage: "\n -P Set drive prefetch count"
/* //usage: "\n -q Change next setting quietly" - not supported ib bbox */
//usage: "\n -Q Get/set DMA tagged-queuing depth (if supported)"
//usage: "\n -r Get/set readonly flag (DANGEROUS to set)"
//usage: IF_FEATURE_HDPARM_HDIO_SCAN_HWIF(
//usage: "\n -R Register an IDE interface (DANGEROUS)")
//usage: "\n -S Set standby (spindown) timeout"
//usage: "\n -t Perform device read timings"
//usage: "\n -T Perform cache read timings"
//usage: "\n -u Get/set unmaskirq flag (0/1)"
//usage: IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(
//usage: "\n -U Unregister an IDE interface (DANGEROUS)")
//usage: "\n -v Defaults; same as -mcudkrag for IDE drives"
//usage: "\n -V Display program version and exit immediately"
//usage: IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(
//usage: "\n -w Perform device reset (DANGEROUS)")
//usage: "\n -W Set drive write-caching flag (0/1) (DANGEROUS)"
//usage: IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(
//usage: "\n -x Tristate device for hotswap (0/1) (DANGEROUS)")
//usage: "\n -X Set IDE xfer mode (DANGEROUS)"
//usage: "\n -y Put IDE drive in standby mode"
//usage: "\n -Y Put IDE drive to sleep"
//usage: "\n -Z Disable Seagate auto-powersaving mode"
//usage: "\n -z Reread partition table"
#include "libbb.h"
#include "common_bufsiz.h"
/* must be _after_ libbb.h: */
#include <linux/hdreg.h>
#include <sys/mount.h>
#if !defined(BLKGETSIZE64)
# define BLKGETSIZE64 _IOR(0x12,114,size_t)
#endif
/* device types */
/* ------------ */
#define NO_DEV 0xffff
#define ATA_DEV 0x0000
#define ATAPI_DEV 0x0001
/* word definitions */
/* ---------------- */
#define GEN_CONFIG 0 /* general configuration */
#define LCYLS 1 /* number of logical cylinders */
#define CONFIG 2 /* specific configuration */
#define LHEADS 3 /* number of logical heads */
#define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */
#define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */
#define LSECTS 6 /* number of logical sectors/track */
#define START_SERIAL 10 /* ASCII serial number */
#define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */
#define BUF_TYPE 20 /* buffer type (ATA-1) */
#define BUFFER__SIZE 21 /* buffer size (ATA-1) */
#define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/
#define START_FW_REV 23 /* ASCII firmware revision */
#define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */
#define START_MODEL 27 /* ASCII model number */
#define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */
#define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */
#define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */
#define CAPAB_0 49 /* capabilities */
#define CAPAB_1 50
#define PIO_MODE 51 /* max PIO mode supported (obsolete)*/
#define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/
#define WHATS_VALID 53 /* what fields are valid */
#define LCYLS_CUR 54 /* current logical cylinders */
#define LHEADS_CUR 55 /* current logical heads */
#define LSECTS_CUR 56 /* current logical sectors/track */
#define CAPACITY_LSB 57 /* current capacity in sectors */
#define CAPACITY_MSB 58
#define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */
#define LBA_SECTS_LSB 60 /* LBA: total number of user */
#define LBA_SECTS_MSB 61 /* addressable sectors */
#define SINGLE_DMA 62 /* singleword DMA modes */
#define MULTI_DMA 63 /* multiword DMA modes */
#define ADV_PIO_MODES 64 /* advanced PIO modes supported */
/* multiword DMA xfer cycle time: */
#define DMA_TIME_MIN 65 /* - minimum */
#define DMA_TIME_NORM 66 /* - manufacturer's recommended */
/* minimum PIO xfer cycle time: */
#define PIO_NO_FLOW 67 /* - without flow control */
#define PIO_FLOW 68 /* - with IORDY flow control */
#define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */
#define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */
#define CDR_MAJOR 73 /* CD ROM: major version number */
#define CDR_MINOR 74 /* CD ROM: minor version number */
#define QUEUE_DEPTH 75 /* queue depth */
#define MAJOR 80 /* major version number */
#define MINOR 81 /* minor version number */
#define CMDS_SUPP_0 82 /* command/feature set(s) supported */
#define CMDS_SUPP_1 83
#define CMDS_SUPP_2 84
#define CMDS_EN_0 85 /* command/feature set(s) enabled */
#define CMDS_EN_1 86
#define CMDS_EN_2 87
#define ULTRA_DMA 88 /* ultra DMA modes */
/* time to complete security erase */
#define ERASE_TIME 89 /* - ordinary */
#define ENH_ERASE_TIME 90 /* - enhanced */
#define ADV_PWR 91 /* current advanced power management level
in low byte, 0x40 in high byte. */
#define PSWD_CODE 92 /* master password revision code */
#define HWRST_RSLT 93 /* hardware reset result */
#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */
#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */
#define LBA_MID 101 /* bits are used, but addr 103 */
#define LBA_48_MSB 102 /* has been reserved for LBA in */
#define LBA_64_MSB 103 /* the future. */
#define RM_STAT 127 /* removable media status notification feature set support */
#define SECU_STATUS 128 /* security status */
#define CFA_PWR_MODE 160 /* CFA power mode 1 */
#define START_MEDIA 176 /* media serial number */
#define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/
#define START_MANUF 196 /* media manufacturer I.D. */
#define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */
#define INTEGRITY 255 /* integrity word */
/* bit definitions within the words */
/* -------------------------------- */
/* many words are considered valid if bit 15 is 0 and bit 14 is 1 */
#define VALID 0xc000
#define VALID_VAL 0x4000
/* many words are considered invalid if they are either all-0 or all-1 */
#define NOVAL_0 0x0000
#define NOVAL_1 0xffff
/* word 0: gen_config */
#define NOT_ATA 0x8000
#define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */
#define MEDIA_REMOVABLE 0x0080
#define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */
#define INCOMPLETE 0x0004
#define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */
#define DRQ_RESPONSE_TIME 0x0060
#define DRQ_3MS_VAL 0x0000
#define DRQ_INTR_VAL 0x0020
#define DRQ_50US_VAL 0x0040
#define PKT_SIZE_SUPPORTED 0x0003
#define PKT_SIZE_12_VAL 0x0000
#define PKT_SIZE_16_VAL 0x0001
#define EQPT_TYPE 0x1f00
#define SHIFT_EQPT 8
#define CDROM 0x0005
/* word 1: number of logical cylinders */
#define LCYLS_MAX 0x3fff /* maximum allowable value */
/* word 2: specific configuration
* (a) require SET FEATURES to spin-up
* (b) require spin-up to fully reply to IDENTIFY DEVICE
*/
#define STBY_NID_VAL 0x37c8 /* (a) and (b) */
#define STBY_ID_VAL 0x738c /* (a) and not (b) */
#define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */
#define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */
/* words 47 & 59: sector_xfer_max & sector_xfer_cur */
#define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/
#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
/* word 49: capabilities 0 */
#define STD_STBY 0x2000 /* 1=standard values supported (ATA); 0=vendor specific values */
#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
#define IORDY_OFF 0x0400 /* 1=may be disabled */
#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
#define DMA_SUP 0x0100 /* 1=Direct Memory Access support */
#define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */
#define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */
#define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */
#define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */
/* word 50: capabilities 1 */
#define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */
/* words 51 & 52: PIO & DMA cycle times */
#define MODE 0xff00 /* the mode is in the MSBs */
/* word 53: whats_valid */
#define OK_W88 0x0004 /* the ultra_dma info is valid */
#define OK_W64_70 0x0002 /* see above for word descriptions */
#define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */
/*word 63,88: dma_mode, ultra_dma_mode*/
#define MODE_MAX 7 /* bit definitions force udma <=7 (when
* udma >=8 comes out it'll have to be
* defined in a new dma_mode word!) */
/* word 64: PIO transfer modes */
#define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */
#define PIO_MODE_MAX 8 /* but all 8 bits are defined */
/* word 75: queue_depth */
#define DEPTH_BITS 0x001f /* bits used for queue depth */
/* words 80-81: version numbers */
/* NOVAL_0 or NOVAL_1 means device does not report version */
/* word 81: minor version number */
#define MINOR_MAX 0x22
/* words 82-84: cmds/feats supported */
#define CMDS_W82 0x77ff /* word 82: defined command locations*/
#define CMDS_W83 0x3fff /* word 83: defined command locations*/
#define CMDS_W84 0x002f /* word 83: defined command locations*/
#define SUPPORT_48_BIT 0x0400
#define NUM_CMD_FEAT_STR 48
/* words 85-87: cmds/feats enabled */
/* use cmd_feat_str[] to display what commands and features have
* been enabled with words 85-87
*/
/* words 89, 90, SECU ERASE TIME */
#define ERASE_BITS 0x00ff
/* word 92: master password revision */
/* NOVAL_0 or NOVAL_1 means no support for master password revision */
/* word 93: hw reset result */
#define CBLID 0x2000 /* CBLID status */
#define RST0 0x0001 /* 1=reset to device #0 */
#define DEV_DET 0x0006 /* how device num determined */
#define JUMPER_VAL 0x0002 /* device num determined by jumper */
#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
/* word 127: removable media status notification feature set support */
#define RM_STAT_BITS 0x0003
#define RM_STAT_SUP 0x0001
/* word 128: security */
#define SECU_ENABLED 0x0002
#define SECU_LEVEL 0x0010
#define NUM_SECU_STR 6
/* word 160: CFA power mode */
#define VALID_W160 0x8000 /* 1=word valid */
#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
#define MAX_AMPS 0x0fff /* value = max current in ma */
/* word 255: integrity */
#define SIG 0x00ff /* signature location */
#define SIG_VAL 0x00a5 /* signature value */
#define TIMING_BUF_MB 1
#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
#define IS_GET 1
#define IS_SET 2
enum { fd = 3 };
struct globals {
smallint get_identity, get_geom;
smallint do_flush;
smallint do_ctimings, do_timings;
smallint reread_partn;
smallint set_piomode, noisy_piomode;
smallint getset_readahead;
smallint getset_readonly;
smallint getset_unmask;
smallint getset_mult;
#ifdef HDIO_GET_QDMA
smallint getset_dma_q;
#endif
smallint getset_nowerr;
smallint getset_keep;
smallint getset_io32bit;
int piomode;
unsigned long Xreadahead;
unsigned long readonly;
unsigned long unmask;
unsigned long mult;
#ifdef HDIO_SET_QDMA
unsigned long dma_q;
#endif
unsigned long nowerr;
unsigned long keep;
unsigned long io32bit;
#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
unsigned long dma;
smallint getset_dma;
#endif
#ifdef HDIO_DRIVE_CMD
smallint set_xfermode, get_xfermode;
smallint getset_dkeep;
smallint getset_standby;
smallint getset_lookahead;
smallint getset_prefetch;
smallint getset_defects;
smallint getset_wcache;
smallint getset_doorlock;
smallint set_seagate;
smallint set_standbynow;
smallint set_sleepnow;
smallint get_powermode;
smallint getset_apmmode;
int xfermode_requested;
unsigned long dkeep;
unsigned long standby_requested; /* 0..255 */
unsigned long lookahead;
unsigned long prefetch;
unsigned long defects;
unsigned long wcache;
unsigned long doorlock;
unsigned long apmmode;
#endif
IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;)
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint getset_busstate;)
IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;)
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;)
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;)
IF_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;)
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;)
IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;)
IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;)
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
unsigned long hwif_data;
unsigned long hwif_ctrl;
unsigned long hwif_irq;
#endif
#ifdef DO_FLUSHCACHE
unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
#endif
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define get_identity (G.get_identity )
#define get_geom (G.get_geom )
#define do_flush (G.do_flush )
#define do_ctimings (G.do_ctimings )
#define do_timings (G.do_timings )
#define reread_partn (G.reread_partn )
#define set_piomode (G.set_piomode )
#define noisy_piomode (G.noisy_piomode )
#define getset_readahead (G.getset_readahead )
#define getset_readonly (G.getset_readonly )
#define getset_unmask (G.getset_unmask )
#define getset_mult (G.getset_mult )
#define getset_dma_q (G.getset_dma_q )
#define getset_nowerr (G.getset_nowerr )
#define getset_keep (G.getset_keep )
#define getset_io32bit (G.getset_io32bit )
#define piomode (G.piomode )
#define Xreadahead (G.Xreadahead )
#define readonly (G.readonly )
#define unmask (G.unmask )
#define mult (G.mult )
#define dma_q (G.dma_q )
#define nowerr (G.nowerr )
#define keep (G.keep )
#define io32bit (G.io32bit )
#define dma (G.dma )
#define getset_dma (G.getset_dma )
#define set_xfermode (G.set_xfermode )
#define get_xfermode (G.get_xfermode )
#define getset_dkeep (G.getset_dkeep )
#define getset_standby (G.getset_standby )
#define getset_lookahead (G.getset_lookahead )
#define getset_prefetch (G.getset_prefetch )
#define getset_defects (G.getset_defects )
#define getset_wcache (G.getset_wcache )
#define getset_doorlock (G.getset_doorlock )
#define set_seagate (G.set_seagate )
#define set_standbynow (G.set_standbynow )
#define set_sleepnow (G.set_sleepnow )
#define get_powermode (G.get_powermode )
#define getset_apmmode (G.getset_apmmode )
#define xfermode_requested (G.xfermode_requested )
#define dkeep (G.dkeep )
#define standby_requested (G.standby_requested )
#define lookahead (G.lookahead )
#define prefetch (G.prefetch )
#define defects (G.defects )
#define wcache (G.wcache )
#define doorlock (G.doorlock )
#define apmmode (G.apmmode )
#define get_IDentity (G.get_IDentity )
#define getset_busstate (G.getset_busstate )
#define perform_reset (G.perform_reset )
#define perform_tristate (G.perform_tristate )
#define unregister_hwif (G.unregister_hwif )
#define scan_hwif (G.scan_hwif )
#define busstate (G.busstate )
#define tristate (G.tristate )
#define hwif (G.hwif )
#define hwif_data (G.hwif_data )
#define hwif_ctrl (G.hwif_ctrl )
#define hwif_irq (G.hwif_irq )
#define INIT_G() do { \
setup_common_bufsiz(); \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
/* Busybox messages and functions */
#if ENABLE_IOCTL_HEX2STR_ERROR
static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt, const char *string)
{
if (!ioctl(fd, cmd, args))
return 0;
args[0] = alt;
return bb_ioctl_or_warn(fd, cmd, args, string);
}
#define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt,#cmd)
#else
static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt)
{
if (!ioctl(fd, cmd, args))
return 0;
args[0] = alt;
return bb_ioctl_or_warn(fd, cmd, args);
}
#define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt)
#endif
static void on_off(int value)
{
puts(value ? " (on)" : " (off)");
}
static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
{
if (get_arg) {
printf(" setting %s to %lu", s, arg);
on_off(arg);
}
}
static void print_value_on_off(const char *str, unsigned long argp)
{
printf(" %s\t= %2lu", str, argp);
on_off(argp != 0);
}
#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
static void print_ascii(const char *p, int length)
{
#if BB_BIG_ENDIAN
#define LE_ONLY(x)
enum { ofs = 0 };
#else
#define LE_ONLY(x) x
/* every 16bit word is big-endian (i.e. inverted) */
/* accessing bytes in 1,0, 3,2, 5,4... sequence */
int ofs = 1;
#endif
length *= 2;
/* find first non-space & print it */
while (length && p[ofs] != ' ') {
p++;
LE_ONLY(ofs = -ofs;)
length--;
}
while (length && p[ofs]) {
bb_putchar(p[ofs]);
p++;
LE_ONLY(ofs = -ofs;)
length--;
}
bb_putchar('\n');
#undef LE_ONLY
}
static void xprint_ascii(uint16_t *val, int i, const char *string, int n)
{
if (val[i]) {
printf("\t%-20s", string);
print_ascii((void*)&val[i], n);
}
}
static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
{
uint16_t ii;
uint8_t err_dma = 0;
for (ii = 0; ii <= MODE_MAX; ii++) {
if (mode_sel & 0x0001) {
printf("*%cdma%u ", cc, ii);
if (*have_mode)
err_dma = 1;
*have_mode = 1;
} else if (mode_sup & 0x0001)
printf("%cdma%u ", cc, ii);
mode_sup >>= 1;
mode_sel >>= 1;
}
return err_dma;
}
static const char pkt_str[] ALIGN1 =
"Direct-access device" "\0" /* word 0, bits 12-8 = 00 */
"Sequential-access device" "\0" /* word 0, bits 12-8 = 01 */
"Printer" "\0" /* word 0, bits 12-8 = 02 */
"Processor" "\0" /* word 0, bits 12-8 = 03 */
"Write-once device" "\0" /* word 0, bits 12-8 = 04 */
"CD-ROM" "\0" /* word 0, bits 12-8 = 05 */
"Scanner" "\0" /* word 0, bits 12-8 = 06 */
"Optical memory" "\0" /* word 0, bits 12-8 = 07 */
"Medium changer" "\0" /* word 0, bits 12-8 = 08 */
"Communications device" "\0" /* word 0, bits 12-8 = 09 */
"ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0a */
"ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0b */
"Array controller" "\0" /* word 0, bits 12-8 = 0c */
"Enclosure services" "\0" /* word 0, bits 12-8 = 0d */
"Reduced block command device" "\0" /* word 0, bits 12-8 = 0e */
"Optical card reader/writer" "\0" /* word 0, bits 12-8 = 0f */
;
static const char ata1_cfg_str[] ALIGN1 = /* word 0 in ATA-1 mode */
"reserved" "\0" /* bit 0 */
"hard sectored" "\0" /* bit 1 */
"soft sectored" "\0" /* bit 2 */
"not MFM encoded " "\0" /* bit 3 */
"head switch time > 15us" "\0" /* bit 4 */
"spindle motor control option" "\0" /* bit 5 */
"fixed drive" "\0" /* bit 6 */
"removable drive" "\0" /* bit 7 */
"disk xfer rate <= 5Mbs" "\0" /* bit 8 */
"disk xfer rate > 5Mbs, <= 10Mbs" "\0" /* bit 9 */
"disk xfer rate > 5Mbs" "\0" /* bit 10 */
"rotational speed tol." "\0" /* bit 11 */
"data strobe offset option" "\0" /* bit 12 */
"track offset option" "\0" /* bit 13 */
"format speed tolerance gap reqd" "\0" /* bit 14 */
"ATAPI" /* bit 14 */
;
static const char minor_str[] ALIGN1 =
/* word 81 value: */
"Unspecified" "\0" /* 0x0000 */
"ATA-1 X3T9.2 781D prior to rev.4" "\0" /* 0x0001 */
"ATA-1 published, ANSI X3.221-1994" "\0" /* 0x0002 */
"ATA-1 X3T9.2 781D rev.4" "\0" /* 0x0003 */
"ATA-2 published, ANSI X3.279-1996" "\0" /* 0x0004 */
"ATA-2 X3T10 948D prior to rev.2k" "\0" /* 0x0005 */
"ATA-3 X3T10 2008D rev.1" "\0" /* 0x0006 */
"ATA-2 X3T10 948D rev.2k" "\0" /* 0x0007 */
"ATA-3 X3T10 2008D rev.0" "\0" /* 0x0008 */
"ATA-2 X3T10 948D rev.3" "\0" /* 0x0009 */
"ATA-3 published, ANSI X3.298-199x" "\0" /* 0x000a */
"ATA-3 X3T10 2008D rev.6" "\0" /* 0x000b */
"ATA-3 X3T13 2008D rev.7 and 7a" "\0" /* 0x000c */
"ATA/ATAPI-4 X3T13 1153D rev.6" "\0" /* 0x000d */
"ATA/ATAPI-4 T13 1153D rev.13" "\0" /* 0x000e */
"ATA/ATAPI-4 X3T13 1153D rev.7" "\0" /* 0x000f */
"ATA/ATAPI-4 T13 1153D rev.18" "\0" /* 0x0010 */
"ATA/ATAPI-4 T13 1153D rev.15" "\0" /* 0x0011 */
"ATA/ATAPI-4 published, ANSI INCITS 317-1998" "\0" /* 0x0012 */
"ATA/ATAPI-5 T13 1321D rev.3" "\0" /* 0x0013 */
"ATA/ATAPI-4 T13 1153D rev.14" "\0" /* 0x0014 */
"ATA/ATAPI-5 T13 1321D rev.1" "\0" /* 0x0015 */
"ATA/ATAPI-5 published, ANSI INCITS 340-2000" "\0" /* 0x0016 */
"ATA/ATAPI-4 T13 1153D rev.17" "\0" /* 0x0017 */
"ATA/ATAPI-6 T13 1410D rev.0" "\0" /* 0x0018 */
"ATA/ATAPI-6 T13 1410D rev.3a" "\0" /* 0x0019 */
"ATA/ATAPI-7 T13 1532D rev.1" "\0" /* 0x001a */
"ATA/ATAPI-6 T13 1410D rev.2" "\0" /* 0x001b */
"ATA/ATAPI-6 T13 1410D rev.1" "\0" /* 0x001c */
"ATA/ATAPI-7 published, ANSI INCITS 397-2005" "\0" /* 0x001d */
"ATA/ATAPI-7 T13 1532D rev.0" "\0" /* 0x001e */
"reserved" "\0" /* 0x001f */
"reserved" "\0" /* 0x0020 */
"ATA/ATAPI-7 T13 1532D rev.4a" "\0" /* 0x0021 */
"ATA/ATAPI-6 published, ANSI INCITS 361-2002" "\0" /* 0x0022 */
"reserved" /* 0x0023-0xfffe */
;
static const char actual_ver[MINOR_MAX + 2] ALIGN1 = {
/* word 81 value: */
0, /* 0x0000 WARNING: actual_ver[] array */
1, /* 0x0001 WARNING: corresponds */
1, /* 0x0002 WARNING: *exactly* */
1, /* 0x0003 WARNING: to the ATA/ */
2, /* 0x0004 WARNING: ATAPI version */
2, /* 0x0005 WARNING: listed in */
3, /* 0x0006 WARNING: the */
2, /* 0x0007 WARNING: minor_str */
3, /* 0x0008 WARNING: array */
2, /* 0x0009 WARNING: above. */
3, /* 0x000a WARNING: */
3, /* 0x000b WARNING: If you change */
3, /* 0x000c WARNING: that one, */
4, /* 0x000d WARNING: change this one */
4, /* 0x000e WARNING: too!!! */
4, /* 0x000f */
4, /* 0x0010 */
4, /* 0x0011 */
4, /* 0x0012 */
5, /* 0x0013 */
4, /* 0x0014 */
5, /* 0x0015 */
5, /* 0x0016 */
4, /* 0x0017 */
6, /* 0x0018 */
6, /* 0x0019 */
7, /* 0x001a */
6, /* 0x001b */
6, /* 0x001c */
7, /* 0x001d */
7, /* 0x001e */
0, /* 0x001f */
0, /* 0x0020 */
7, /* 0x0021 */
6, /* 0x0022 */
0 /* 0x0023-0xfffe */
};
static const char cmd_feat_str[] ALIGN1 =
"" "\0" /* word 82 bit 15: obsolete */
"NOP cmd" "\0" /* word 82 bit 14 */
"READ BUFFER cmd" "\0" /* word 82 bit 13 */
"WRITE BUFFER cmd" "\0" /* word 82 bit 12 */
"" "\0" /* word 82 bit 11: obsolete */
"Host Protected Area feature set" "\0" /* word 82 bit 10 */
"DEVICE RESET cmd" "\0" /* word 82 bit 9 */
"SERVICE interrupt" "\0" /* word 82 bit 8 */
"Release interrupt" "\0" /* word 82 bit 7 */
"Look-ahead" "\0" /* word 82 bit 6 */
"Write cache" "\0" /* word 82 bit 5 */
"PACKET command feature set" "\0" /* word 82 bit 4 */
"Power Management feature set" "\0" /* word 82 bit 3 */
"Removable Media feature set" "\0" /* word 82 bit 2 */
"Security Mode feature set" "\0" /* word 82 bit 1 */
"SMART feature set" "\0" /* word 82 bit 0 */
/* -------------- */
"" "\0" /* word 83 bit 15: !valid bit */
"" "\0" /* word 83 bit 14: valid bit */
"FLUSH CACHE EXT cmd" "\0" /* word 83 bit 13 */
"Mandatory FLUSH CACHE cmd " "\0" /* word 83 bit 12 */
"Device Configuration Overlay feature set " "\0"
"48-bit Address feature set " "\0" /* word 83 bit 10 */
"" "\0"
"SET MAX security extension" "\0" /* word 83 bit 8 */
"Address Offset Reserved Area Boot" "\0" /* word 83 bit 7 */
"SET FEATURES subcommand required to spinup after power up" "\0"
"Power-Up In Standby feature set" "\0" /* word 83 bit 5 */
"Removable Media Status Notification feature set" "\0"
"Adv. Power Management feature set" "\0" /* word 83 bit 3 */
"CFA feature set" "\0" /* word 83 bit 2 */
"READ/WRITE DMA QUEUED" "\0" /* word 83 bit 1 */
"DOWNLOAD MICROCODE cmd" "\0" /* word 83 bit 0 */
/* -------------- */
"" "\0" /* word 84 bit 15: !valid bit */
"" "\0" /* word 84 bit 14: valid bit */
"" "\0" /* word 84 bit 13: reserved */
"" "\0" /* word 84 bit 12: reserved */
"" "\0" /* word 84 bit 11: reserved */
"" "\0" /* word 84 bit 10: reserved */
"" "\0" /* word 84 bit 9: reserved */
"" "\0" /* word 84 bit 8: reserved */
"" "\0" /* word 84 bit 7: reserved */
"" "\0" /* word 84 bit 6: reserved */
"General Purpose Logging feature set" "\0" /* word 84 bit 5 */
"" "\0" /* word 84 bit 4: reserved */
"Media Card Pass Through Command feature set " "\0"
"Media serial number " "\0" /* word 84 bit 2 */
"SMART self-test " "\0" /* word 84 bit 1 */
"SMART error logging " /* word 84 bit 0 */
;
static const char secu_str[] ALIGN1 =
"supported" "\0" /* word 128, bit 0 */
"enabled" "\0" /* word 128, bit 1 */
"locked" "\0" /* word 128, bit 2 */
"frozen" "\0" /* word 128, bit 3 */
"expired: security count" "\0" /* word 128, bit 4 */
"supported: enhanced erase" /* word 128, bit 5 */
;
// Parse 512 byte disk identification block and print much crap.
static void identify(uint16_t *val) NORETURN;
static void identify(uint16_t *val)
{
uint16_t ii, jj, kk;
uint16_t like_std = 1, std = 0, min_std = 0xffff;
uint16_t dev = NO_DEV, eqpt = NO_DEV;
uint8_t have_mode = 0, err_dma = 0;
uint8_t chksum = 0;
uint32_t ll, mm, nn, oo;
uint64_t bbbig; /* (:) */
const char *strng;
#if BB_BIG_ENDIAN
uint16_t buf[256];
// Adjust for endianness
swab(val, buf, sizeof(buf));
val = buf;
#endif
/* check if we recognize the device type */
bb_putchar('\n');
if (!(val[GEN_CONFIG] & NOT_ATA)) {
dev = ATA_DEV;
printf("ATA device, with ");
} else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL) {
dev = ATA_DEV;
like_std = 4;
printf("CompactFlash ATA device, with ");
} else if (!(val[GEN_CONFIG] & NOT_ATAPI)) {
dev = ATAPI_DEV;
eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
printf("ATAPI %s, with ", eqpt <= 0xf ? nth_string(pkt_str, eqpt) : "unknown");
like_std = 3;
} else
/* "Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n" */
bb_error_msg_and_die("unknown device type");
printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
/* Info from the specific configuration word says whether or not the
* ID command completed correctly. It is only defined, however in
* ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
* standards. Since the values allowed for this word are extremely
* specific, it should be safe to check it now, even though we don't
* know yet what standard this device is using.
*/
if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)
|| (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL)
) {
like_std = 5;
if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
puts("powers-up in standby; SET FEATURES subcmd spins-up.");
if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
puts("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n");
}
/* output the model and serial numbers and the fw revision */
xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
/* major & minor standards version number (Note: these words were not
* defined until ATA-3 & the CDROM std uses different words.) */
printf("Standards:");
if (eqpt != CDROM) {
if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) {
if (like_std < 3) like_std = 3;
std = actual_ver[val[MINOR]];
if (std)
printf("\n\tUsed: %s ", nth_string(minor_str, val[MINOR]));
}
/* looks like when they up-issue the std, they obsolete one;
* thus, only the newest 4 issues need be supported. (That's
* what "kk" and "min_std" are all about.) */
if (val[MAJOR] && (val[MAJOR] != NOVAL_1)) {
printf("\n\tSupported: ");
jj = val[MAJOR] << 1;
kk = like_std >4 ? like_std-4: 0;
for (ii = 14; (ii >0)&&(ii>kk); ii--) {
if (jj & 0x8000) {
printf("%u ", ii);
if (like_std < ii) {
like_std = ii;
kk = like_std >4 ? like_std-4: 0;
}
if (min_std > ii) min_std = ii;
}
jj <<= 1;
}
if (like_std < 3) like_std = 3;
}
/* Figure out what standard the device is using if it hasn't told
* us. If we know the std, check if the device is using any of
* the words from the next level up. It happens.
*/
if (like_std < std) like_std = std;
if (((std == 5) || (!std && (like_std < 6))) &&
((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
(( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
( val[CMDS_SUPP_2] & CMDS_W84) ) )
) {
like_std = 6;
} else if (((std == 4) || (!std && (like_std < 5))) &&
((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
(( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
(( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
{
like_std = 5;
} else if (((std == 3) || (!std && (like_std < 4))) &&
((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
(( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
(( val[CAPAB_1] & VALID) == VALID_VAL) ||
(( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
(( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) )
) {
like_std = 4;
} else if (((std == 2) || (!std && (like_std < 3)))
&& ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
) {
like_std = 3;
} else if (((std == 1) || (!std && (like_std < 2))) &&
((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
(val[WHATS_VALID] & OK_W64_70)) )
{
like_std = 2;
}
if (!std)
printf("\n\tLikely used: %u\n", like_std);
else if (like_std > std)
printf("& some of %u\n", like_std);
else
bb_putchar('\n');
} else {
/* TBD: do CDROM stuff more thoroughly. For now... */
kk = 0;
if (val[CDR_MINOR] == 9) {
kk = 1;
printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
}
if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) {
kk = 1;
printf("\n\tSupported: CD-ROM ATAPI");
jj = val[CDR_MAJOR] >> 1;
for (ii = 1; ii < 15; ii++) {
if (jj & 0x0001) printf("-%u ", ii);
jj >>= 1;
}
}
puts(kk ? "" : "\n\tLikely used CD-ROM ATAPI-1");
/* the cdrom stuff is more like ATA-2 than anything else, so: */
like_std = 2;
}
if (min_std == 0xffff)
min_std = like_std > 4 ? like_std - 3 : 1;
puts("Configuration:");
/* more info from the general configuration word */
if ((eqpt != CDROM) && (like_std == 1)) {
jj = val[GEN_CONFIG] >> 1;
for (ii = 1; ii < 15; ii++) {
if (jj & 0x0001)
printf("\t%s\n", nth_string(ata1_cfg_str, ii));
jj >>=1;
}
}
if (dev == ATAPI_DEV) {
if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL)
strng = "3ms";
else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL)
strng = "<=10ms with INTRQ";
else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL)
strng ="50us";
else
strng = "unknown";
printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */
if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL)
strng = "12 bytes";
else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL)
strng = "16 bytes";
else
strng = "unknown";
puts(strng);
} else {
/* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
mm = 0;
bbbig = 0;
if ((ll > 0x00FBFC10) && (!val[LCYLS]))
puts("\tCHS addressing not supported");
else {
jj = val[WHATS_VALID] & OK_W54_58;
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",
val[LCYLS],
jj ? val[LCYLS_CUR] : 0,
val[LHEADS],
jj ? val[LHEADS_CUR] : 0,
val[LSECTS],
jj ? val[LSECTS_CUR] : 0);
if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES]))
printf("\tbytes/track: %u\tbytes/sector: %u\n",
val[TRACK_BYTES], val[SECT_BYTES]);
if (jj) {
mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
if (like_std < 3) {
/* check Endian of capacity bytes */
nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
if (abs(mm - nn) > abs(oo - nn))
mm = oo;