Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/miscutils/hdparm.c

    r902 r1770  
    1313 */
    1414
    15 #include "busybox.h"
    16 #include <string.h>
    17 #include <fcntl.h>
    18 #include <errno.h>
    19 #include <ctype.h>
    20 #include <sys/ioctl.h>
    21 #include <sys/sysmacros.h>
    22 #include <sys/times.h>
    23 #include <sys/mman.h>
    24 #include <linux/types.h>
     15#include "libbb.h"
    2516#include <linux/hdreg.h>
    26 
    27 #if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
    28 # define __USE_XOPEN
    29 #endif
    30 #include <unistd.h>
    3117
    3218/* device types */
     
    5440#define START_MODEL     27  /* ASCII model number */
    5541#define LENGTH_MODEL        20  /* 20 words (40 bytes or characters) */
    56 #define SECTOR_XFER_MAX         47  /* r/w multiple: max sectors xfered */
     42#define SECTOR_XFER_MAX     47  /* r/w multiple: max sectors xfered */
    5743#define DWORD_IO        48  /* can do double-word IO (ATA-1 only) */
    5844#define CAPAB_0         49  /* capabilities */
     
    6349#define LCYLS_CUR       54  /* current logical cylinders */
    6450#define LHEADS_CUR      55  /* current logical heads */
    65 #define LSECTS_CUR          56  /* current logical sectors/track */
     51#define LSECTS_CUR      56  /* current logical sectors/track */
    6652#define CAPACITY_LSB        57  /* current capacity in sectors */
    6753#define CAPACITY_MSB        58
     
    142128#define CDROM 0x0005
    143129
    144 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    145 static const char * const pkt_str[] = {
     130#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     131static const char *const pkt_str[] = {
    146132    "Direct-access device",         /* word 0, bits 12-8 = 00 */
    147133    "Sequential-access device",     /* word 0, bits 12-8 = 01 */
     
    178164};
    179165
    180 static const char * const ata1_cfg_str[] = {            /* word 0 in ATA-1 mode */
     166static const char *const ata1_cfg_str[] = {         /* word 0 in ATA-1 mode */
    181167    "Reserved",             /* bit 0 */
    182168    "hard sectored",            /* bit 1 */
     
    215201
    216202/* word 49: capabilities 0 */
    217 #define STD_STBY        0x2000  /* 1=standard values supported (ATA);
    218                        0=vendor specific values */
     203#define STD_STBY        0x2000  /* 1=standard values supported (ATA); 0=vendor specific values */
    219204#define IORDY_SUP       0x0800  /* 1=support; 0=may be supported */
    220205#define IORDY_OFF       0x0400  /* 1=may be disabled */
     
    254239/* word 81: minor version number */
    255240#define MINOR_MAX       0x22
    256 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    257 static const char *minor_str[MINOR_MAX+2] = {           /* word 81 value: */
    258     "Unspecified",                  /* 0x0000   */
    259     "ATA-1 X3T9.2 781D prior to rev.4", /* 0x0001   */
    260     "ATA-1 published, ANSI X3.221-1994",        /* 0x0002   */
    261     "ATA-1 X3T9.2 781D rev.4",          /* 0x0003   */
    262     "ATA-2 published, ANSI X3.279-1996",        /* 0x0004   */
    263     "ATA-2 X3T10 948D prior to rev.2k", /* 0x0005   */
    264     "ATA-3 X3T10 2008D rev.1",          /* 0x0006   */
    265     "ATA-2 X3T10 948D rev.2k",          /* 0x0007   */
    266     "ATA-3 X3T10 2008D rev.0",          /* 0x0008   */
    267     "ATA-2 X3T10 948D rev.3",           /* 0x0009   */
    268     "ATA-3 published, ANSI X3.298-199x",        /* 0x000a   */
    269     "ATA-3 X3T10 2008D rev.6",          /* 0x000b   */
    270     "ATA-3 X3T13 2008D rev.7 and 7a",       /* 0x000c   */
    271     "ATA/ATAPI-4 X3T13 1153D rev.6",        /* 0x000d   */
    272     "ATA/ATAPI-4 T13 1153D rev.13",     /* 0x000e   */
    273     "ATA/ATAPI-4 X3T13 1153D rev.7",        /* 0x000f   */
    274     "ATA/ATAPI-4 T13 1153D rev.18",     /* 0x0010   */
    275     "ATA/ATAPI-4 T13 1153D rev.15",     /* 0x0011   */
    276     "ATA/ATAPI-4 published, ANSI INCITS 317-1998",  /* 0x0012   */
    277     "ATA/ATAPI-5 T13 1321D rev.3",
    278     "ATA/ATAPI-4 T13 1153D rev.14",     /* 0x0014   */
    279     "ATA/ATAPI-5 T13 1321D rev.1",      /* 0x0015   */
    280     "ATA/ATAPI-5 published, ANSI INCITS 340-2000",  /* 0x0016   */
    281     "ATA/ATAPI-4 T13 1153D rev.17",     /* 0x0017   */
    282     "ATA/ATAPI-6 T13 1410D rev.0",      /* 0x0018   */
    283     "ATA/ATAPI-6 T13 1410D rev.3a",     /* 0x0019   */
    284     "ATA/ATAPI-7 T13 1532D rev.1",      /* 0x001a   */
    285     "ATA/ATAPI-6 T13 1410D rev.2",      /* 0x001b   */
    286     "ATA/ATAPI-6 T13 1410D rev.1",      /* 0x001c   */
    287     "ATA/ATAPI-7 published, ANSI INCITS 397-2005",  /* 0x001d   */
    288     "ATA/ATAPI-7 T13 1532D rev.0",      /* 0x001e   */
    289     "Reserved"                  /* 0x001f   */
    290     "Reserved"                  /* 0x0020   */
    291     "ATA/ATAPI-7 T13 1532D rev.4a",     /* 0x0021   */
    292     "ATA/ATAPI-6 published, ANSI INCITS 361-2002",  /* 0x0022   */
    293     "Reserved"                  /* 0x0023-0xfffe*/
     241#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     242static const char *const minor_str[MINOR_MAX + 2] = {
     243    /* word 81 value: */
     244    "Unspecified",                                  /* 0x0000 */
     245    "ATA-1 X3T9.2 781D prior to rev.4",             /* 0x0001 */
     246    "ATA-1 published, ANSI X3.221-1994",            /* 0x0002 */
     247    "ATA-1 X3T9.2 781D rev.4",                      /* 0x0003 */
     248    "ATA-2 published, ANSI X3.279-1996",            /* 0x0004 */
     249    "ATA-2 X3T10 948D prior to rev.2k",             /* 0x0005 */
     250    "ATA-3 X3T10 2008D rev.1",                      /* 0x0006 */
     251    "ATA-2 X3T10 948D rev.2k",                      /* 0x0007 */
     252    "ATA-3 X3T10 2008D rev.0",                      /* 0x0008 */
     253    "ATA-2 X3T10 948D rev.3",                       /* 0x0009 */
     254    "ATA-3 published, ANSI X3.298-199x",            /* 0x000a */
     255    "ATA-3 X3T10 2008D rev.6",                      /* 0x000b */
     256    "ATA-3 X3T13 2008D rev.7 and 7a",               /* 0x000c */
     257    "ATA/ATAPI-4 X3T13 1153D rev.6",                /* 0x000d */
     258    "ATA/ATAPI-4 T13 1153D rev.13",                 /* 0x000e */
     259    "ATA/ATAPI-4 X3T13 1153D rev.7",                /* 0x000f */
     260    "ATA/ATAPI-4 T13 1153D rev.18",                 /* 0x0010 */
     261    "ATA/ATAPI-4 T13 1153D rev.15",                 /* 0x0011 */
     262    "ATA/ATAPI-4 published, ANSI INCITS 317-1998",  /* 0x0012 */
     263    "ATA/ATAPI-5 T13 1321D rev.3",                  /* 0x0013 */
     264    "ATA/ATAPI-4 T13 1153D rev.14",                 /* 0x0014 */
     265    "ATA/ATAPI-5 T13 1321D rev.1",                  /* 0x0015 */
     266    "ATA/ATAPI-5 published, ANSI INCITS 340-2000",  /* 0x0016 */
     267    "ATA/ATAPI-4 T13 1153D rev.17",                 /* 0x0017 */
     268    "ATA/ATAPI-6 T13 1410D rev.0",                  /* 0x0018 */
     269    "ATA/ATAPI-6 T13 1410D rev.3a",                 /* 0x0019 */
     270    "ATA/ATAPI-7 T13 1532D rev.1",                  /* 0x001a */
     271    "ATA/ATAPI-6 T13 1410D rev.2",                  /* 0x001b */
     272    "ATA/ATAPI-6 T13 1410D rev.1",                  /* 0x001c */
     273    "ATA/ATAPI-7 published, ANSI INCITS 397-2005",  /* 0x001d */
     274    "ATA/ATAPI-7 T13 1532D rev.0",                  /* 0x001e */
     275    "Reserved"                                      /* 0x001f */
     276    "Reserved"                                      /* 0x0020 */
     277    "ATA/ATAPI-7 T13 1532D rev.4a",                 /* 0x0021 */
     278    "ATA/ATAPI-6 published, ANSI INCITS 361-2002",  /* 0x0022 */
     279    "Reserved"                                      /* 0x0023-0xfffe */
    294280};
    295281#endif
    296 static const char actual_ver[MINOR_MAX+2] = {
    297             /* word 81 value: */
    298     0,      /* 0x0000   WARNING:    */
    299     1,      /* 0x0001   WARNING:    */
    300     1,      /* 0x0002   WARNING:    */
    301     1,      /* 0x0003   WARNING:    */
    302     2,      /* 0x0004   WARNING:   This array       */
    303     2,      /* 0x0005   WARNING:   corresponds      */
    304     3,      /* 0x0006   WARNING:   *exactly*        */
    305     2,      /* 0x0007   WARNING:   to the ATA/      */
    306     3,      /* 0x0008   WARNING:   ATAPI version    */
    307     2,      /* 0x0009   WARNING:   listed in        */
    308     3,      /* 0x000a   WARNING:   the          */
    309     3,      /* 0x000b   WARNING:   minor_str        */
    310     3,      /* 0x000c   WARNING:   array        */
    311     4,      /* 0x000d   WARNING:   above.       */
    312     4,      /* 0x000e   WARNING:            */
    313     4,      /* 0x000f   WARNING:   if you change    */
    314     4,      /* 0x0010   WARNING:   that one,        */
    315     4,      /* 0x0011   WARNING:   change this one  */
    316     4,      /* 0x0012   WARNING:   too!!!       */
    317     5,      /* 0x0013   WARNING:    */
    318     4,      /* 0x0014   WARNING:    */
    319     5,      /* 0x0015   WARNING:    */
    320     5,      /* 0x0016   WARNING:    */
    321     4,      /* 0x0017   WARNING:    */
    322     6,      /* 0x0018   WARNING:    */
    323     6,      /* 0x0019   WARNING:    */
    324     7,      /* 0x001a   WARNING:    */
    325     6,      /* 0x001b   WARNING:    */
    326     6,      /* 0x001c   WARNING:    */
    327     7,      /* 0x001d   WARNING:    */
    328     7,      /* 0x001e   WARNING:    */
    329     0,      /* 0x001f   WARNING:    */
    330     0,      /* 0x0020   WARNING:    */
    331     7,      /* 0x0021   WARNING:    */
    332     6,      /* 0x0022   WARNING:    */
    333     0       /* 0x0023-0xfffe        */
     282static const char actual_ver[MINOR_MAX + 2] ALIGN1 = {
     283       /* word 81 value: */
     284    0, /* 0x0000 WARNING: actual_ver[] array */
     285    1, /* 0x0001 WARNING: corresponds        */
     286    1, /* 0x0002 WARNING: *exactly*          */
     287    1, /* 0x0003 WARNING: to the ATA/        */
     288    2, /* 0x0004 WARNING: ATAPI version      */
     289    2, /* 0x0005 WARNING: listed in          */
     290    3, /* 0x0006 WARNING: the                */
     291    2, /* 0x0007 WARNING: minor_str          */
     292    3, /* 0x0008 WARNING: array              */
     293    2, /* 0x0009 WARNING: above.             */
     294    3, /* 0x000a WARNING:                    */
     295    3, /* 0x000b WARNING: If you change      */
     296    3, /* 0x000c WARNING: that one,          */
     297    4, /* 0x000d WARNING: change this one    */
     298    4, /* 0x000e WARNING: too!!!             */
     299    4, /* 0x000f */
     300    4, /* 0x0010 */
     301    4, /* 0x0011 */
     302    4, /* 0x0012 */
     303    5, /* 0x0013 */
     304    4, /* 0x0014 */
     305    5, /* 0x0015 */
     306    5, /* 0x0016 */
     307    4, /* 0x0017 */
     308    6, /* 0x0018 */
     309    6, /* 0x0019 */
     310    7, /* 0x001a */
     311    6, /* 0x001b */
     312    6, /* 0x001c */
     313    7, /* 0x001d */
     314    7, /* 0x001e */
     315    0, /* 0x001f */
     316    0, /* 0x0020 */
     317    7, /* 0x0021 */
     318    6, /* 0x0022 */
     319    0  /* 0x0023-0xfffe */
    334320};
    335321
     
    341327#define NUM_CMD_FEAT_STR    48
    342328
    343 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    344 static const char * const cmd_feat_str[] = {
     329#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     330static const char *const cmd_feat_str[] = {
    345331    "",                 /* word 82 bit 15: obsolete  */
    346332    "NOP cmd",              /* word 82 bit 14 */
     
    359345    "Security Mode feature set",        /* word 82 bit  1 */
    360346    "SMART feature set",            /* word 82 bit  0 */
    361                         /* --------------*/
     347                        /* -------------- */
    362348    "",                 /* word 83 bit 15: !valid bit */
    363349    "",                 /* word 83 bit 14:  valid bit */
    364     "FLUSH CACHE EXT cmd",      /* word 83 bit 13 */
    365     "Mandatory FLUSH CACHE cmd ",   /* word 83 bit 12 */
     350    "FLUSH CACHE EXT cmd",          /* word 83 bit 13 */
     351    "Mandatory FLUSH CACHE cmd ",       /* word 83 bit 12 */
    366352    "Device Configuration Overlay feature set ",
    367353    "48-bit Address feature set ",      /* word 83 bit 10 */
     
    372358    "Power-Up In Standby feature set",  /* word 83 bit  5 */
    373359    "Removable Media Status Notification feature set",
    374     "Adv. Power Management feature set",/* word 83 bit  3 */
     360    "Adv. Power Management feature set",    /* word 83 bit  3 */
    375361    "CFA feature set",          /* word 83 bit  2 */
    376362    "READ/WRITE DMA QUEUED",        /* word 83 bit  1 */
    377363    "DOWNLOAD MICROCODE cmd",       /* word 83 bit  0 */
    378                         /* --------------*/
     364                        /* -------------- */
    379365    "",                 /* word 84 bit 15: !valid bit */
    380366    "",                 /* word 84 bit 14:  valid bit */
     
    408394
    409395/* words 89, 90, SECU ERASE TIME */
    410 #define ERASE_BITS      0x00ff
     396#define ERASE_BITS      0x00ff
    411397
    412398/* word 92: master password revision */
     
    414400
    415401/* word 93: hw reset result */
    416 #define CBLID           0x2000  /* CBLID status */
    417 #define RST0            0x0001  /* 1=reset to device #0 */
    418 #define DEV_DET         0x0006  /* how device num determined */
    419 #define JUMPER_VAL      0x0002  /* device num determined by jumper */
    420 #define CSEL_VAL        0x0004  /* device num determined by CSEL_VAL */
     402#define CBLID           0x2000  /* CBLID status */
     403#define RST0            0x0001  /* 1=reset to device #0 */
     404#define DEV_DET         0x0006  /* how device num determined */
     405#define JUMPER_VAL      0x0002  /* device num determined by jumper */
     406#define CSEL_VAL        0x0004  /* device num determined by CSEL_VAL */
    421407
    422408/* word 127: removable media status notification feature set support */
    423 #define RM_STAT_BITS        0x0003
    424 #define RM_STAT_SUP     0x0001
     409#define RM_STAT_BITS    0x0003
     410#define RM_STAT_SUP     0x0001
    425411
    426412/* word 128: security */
    427 #define SECU_ENABLED    0x0002
    428 #define SECU_LEVEL      0x0010
    429 #define NUM_SECU_STR    6
    430 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    431 static const char * const secu_str[] = {
     413#define SECU_ENABLED    0x0002
     414#define SECU_LEVEL      0x0010
     415#define NUM_SECU_STR    6
     416#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     417static const char *const secu_str[] = {
    432418    "supported",            /* word 128, bit 0 */
    433419    "enabled",          /* word 128, bit 1 */
     
    440426
    441427/* word 160: CFA power mode */
    442 #define VALID_W160      0x8000  /* 1=word valid */
    443 #define PWR_MODE_REQ        0x2000  /* 1=CFA power mode req'd by some cmds*/
    444 #define PWR_MODE_OFF        0x1000  /* 1=CFA power moded disabled */
    445 #define MAX_AMPS        0x0fff  /* value = max current in ma */
     428#define VALID_W160              0x8000  /* 1=word valid */
     429#define PWR_MODE_REQ            0x2000  /* 1=CFA power mode req'd by some cmds*/
     430#define PWR_MODE_OFF            0x1000  /* 1=CFA power moded disabled */
     431#define MAX_AMPS                0x0fff  /* value = max current in ma */
    446432
    447433/* word 255: integrity */
    448 #define SIG         0x00ff  /* signature location */
    449 #define SIG_VAL         0x00A5  /* signature value */
    450 
    451 #define TIMING_MB       64
    452 #define TIMING_BUF_MB       1
    453 #define TIMING_BUF_BYTES    (TIMING_BUF_MB * 1024 * 1024)
    454 #define TIMING_BUF_COUNT    (timing_MB / TIMING_BUF_MB)
    455 #define BUFCACHE_FACTOR     2
    456 
    457 #undef DO_FLUSHCACHE        /* under construction: force cache flush on -W0 */
     434#define SIG                     0x00ff  /* signature location */
     435#define SIG_VAL                 0x00a5  /* signature value */
     436
     437#define TIMING_MB               64
     438#define TIMING_BUF_MB           1
     439#define TIMING_BUF_BYTES        (TIMING_BUF_MB * 1024 * 1024)
     440#define BUFCACHE_FACTOR         2
     441
     442#undef DO_FLUSHCACHE            /* under construction: force cache flush on -W0 */
    458443
    459444/* Busybox messages and functions */
    460 static int bb_ioctl(int fd, int request, void *argp, const char *string)
    461 {
    462     int e = ioctl(fd, request, argp);
    463     if (e && string)
    464         bb_perror_msg(" %s", string);
    465     return e;
    466 }
    467 
    468 static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
     445#if ENABLE_IOCTL_HEX2STR_ERROR
     446static int ioctl_alt_func(int fd, int cmd, unsigned char *args, int alt, const char *string)
    469447{
    470448    if (!ioctl(fd, cmd, args))
    471449        return 0;
    472450    args[0] = alt;
    473     return bb_ioctl(fd, cmd, args, string);
    474 }
    475 
    476 static void on_off(unsigned int value);
    477 
    478 static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg)
    479 {
    480 
    481     if (get_arg)
    482     {
     451    return bb_ioctl_or_warn(fd, cmd, args, string);
     452}
     453#define ioctl_alt_or_warn(fd,cmd,args,alt) ioctl_alt_func(fd,cmd,args,alt,#cmd)
     454#else
     455static int ioctl_alt_func(int fd, int cmd, unsigned char *args, int alt)
     456{
     457    if (!ioctl(fd, cmd, args))
     458        return 0;
     459    args[0] = alt;
     460    return bb_ioctl_or_warn(fd, cmd, args);
     461}
     462#define ioctl_alt_or_warn(fd,cmd,args,alt) ioctl_alt_func(fd,cmd,args,alt)
     463#endif
     464
     465static void on_off(int value)
     466{
     467    puts(value ? " (on)" : " (off)");
     468}
     469
     470static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
     471{
     472    if (get_arg) {
    483473        printf(" setting %s to %ld", s, arg);
    484474        on_off(arg);
     
    486476}
    487477
    488 static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
    489                              const char * str)
    490 {
    491     if (ioctl(fd, request, &argp) != 0)
    492         bb_perror_msg(" %s", string);
    493     else
    494     {
    495         printf(" %s\t= %2ld", str, (unsigned long) argp);
    496         on_off((unsigned long) argp);
    497     }
    498 }
    499 
    500 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
     478static void print_value_on_off(const char *str, unsigned long argp)
     479{
     480    printf(" %s\t= %2ld", str, argp);
     481    on_off(argp != 0);
     482}
     483
     484#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
    501485static void print_ascii(uint16_t *p, uint8_t length);
    502486
    503 static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
    504 {
    505     if (val[i])
    506     {
    507         printf("\t%-20s",string);
     487static void xprint_ascii(uint16_t *val, int i, const char *string, int n)
     488{
     489    if (val[i]) {
     490        printf("\t%-20s", string);
    508491        print_ascii(&val[i], n);
    509492    }
    510493}
    511494#endif
    512 /* end of  busybox specific stuff */
    513 
    514 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
     495/* end of busybox specific stuff */
     496
     497#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
    515498static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
    516499{
     
    518501    uint8_t err_dma = 0;
    519502
    520     for (ii = 0; ii <= MODE_MAX; ii++)
    521     {
    522         if (mode_sel & 0x0001)
    523         {
    524             printf("*%cdma%u ",cc,ii);
     503    for (ii = 0; ii <= MODE_MAX; ii++) {
     504        if (mode_sel & 0x0001) {
     505            printf("*%cdma%u ", cc, ii);
    525506            if (*have_mode)
    526507                err_dma = 1;
    527508            *have_mode = 1;
    528         }
    529         else if (mode_sup & 0x0001)
    530             printf("%cdma%u ",cc,ii);
    531 
    532         mode_sup >>=1;
    533         mode_sel >>=1;
     509        } else if (mode_sup & 0x0001)
     510            printf("%cdma%u ", cc, ii);
     511
     512        mode_sup >>= 1;
     513        mode_sel >>= 1;
    534514    }
    535515    return err_dma;
    536516}
    537517
    538 static void print_ascii(uint16_t *p, uint8_t length) {
     518static void print_ascii(uint16_t *p, uint8_t length)
     519{
    539520    uint8_t ii;
    540521    char cl;
    541522
    542523    /* find first non-space & print it */
    543     for (ii = 0; ii< length; ii++)
    544     {
    545         if (((char) 0x00ff&((*p)>>8)) != ' ')
     524    for (ii = 0; ii < length; ii++) {
     525        if ((char)((*p)>>8) != ' ')
    546526            break;
    547         if ((cl = (char) 0x00ff&(*p)) != ' ')
    548         {
    549             if (cl != '\0') printf("%c",cl);
     527        cl = (char)(*p);
     528        if (cl != ' ') {
     529            if (cl != '\0')
     530                printf("%c", cl);
    550531            p++;
    551532            ii++;
     
    555536    }
    556537    /* print the rest */
    557     for (; ii< length; ii++)
    558     {
     538    for (; ii< length; ii++) {
    559539        if (!(*p))
    560540            break; /* some older devices have NULLs */
    561         printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
     541        printf("%c%c", (char)((*p)>>8), (char)(*p));
    562542        p++;
    563543    }
    564     printf("\n");
     544    puts("");
    565545}
    566546
     
    584564        swab(id_supplied, buf, sizeof(buf));
    585565        val = buf;
    586     } else val = id_supplied;
     566    } else
     567        val = id_supplied;
    587568
    588569    chksum &= 0xff;
    589570
    590571    /* check if we recognise the device type */
    591     printf("\n");
    592     if(!(val[GEN_CONFIG] & NOT_ATA))
    593     {
     572    puts("");
     573    if (!(val[GEN_CONFIG] & NOT_ATA)) {
    594574        dev = ATA_DEV;
    595575        printf("ATA device, with ");
    596     }
    597     else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
    598     {
     576    } else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL) {
    599577        dev = ATA_DEV;
    600578        like_std = 4;
    601579        printf("CompactFlash ATA device, with ");
    602     }
    603     else if(!(val[GEN_CONFIG] & NOT_ATAPI))
    604     {
     580    } else if (!(val[GEN_CONFIG] & NOT_ATAPI)) {
    605581        dev = ATAPI_DEV;
    606582        eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
    607583        printf("ATAPI %s, with ", pkt_str[eqpt]);
    608584        like_std = 3;
    609     }
    610     else
     585    } else
    611586        /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
    612         bb_error_msg_and_die("Unknown device type");
     587        bb_error_msg_and_die("unknown device type");
    613588
    614589    printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
     
    620595     * know yet what standard this device is using.
    621596     */
    622     if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) ||
    623        (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
    624     {
     597    if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)
     598     || (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL)
     599    ) {
    625600        like_std = 5;
    626         if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
     601        if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
    627602            printf("powers-up in standby; SET FEATURES subcmd spins-up.\n");
    628         if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
     603        if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
    629604            printf("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
    630605    }
     
    640615     * defined until ATA-3 & the CDROM std uses different words.) */
    641616    printf("Standards:");
    642     if (eqpt != CDROM)
    643     {
    644         if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
    645         {
    646             if(like_std < 3) like_std = 3;
     617    if (eqpt != CDROM) {
     618        if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) {
     619            if (like_std < 3) like_std = 3;
    647620            std = actual_ver[val[MINOR]];
    648             if(std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
     621            if (std) printf("\n\tUsed: %s ", minor_str[val[MINOR]]);
    649622
    650623        }
     
    652625         * thus, only the newest 4 issues need be supported. (That's
    653626         * what "kk" and "min_std" are all about.) */
    654         if (val[MAJOR] && (val[MAJOR] !=NOVAL_1))
    655         {
     627        if (val[MAJOR] && (val[MAJOR] != NOVAL_1)) {
    656628            printf("\n\tSupported: ");
    657629            jj = val[MAJOR] << 1;
    658630            kk = like_std >4 ? like_std-4: 0;
    659             for (ii = 14; (ii >0)&&(ii>kk); ii--)
    660             {
    661                 if (jj & 0x8000)
    662                 {
     631            for (ii = 14; (ii >0)&&(ii>kk); ii--) {
     632                if (jj & 0x8000) {
    663633                    printf("%u ", ii);
    664                     if (like_std < ii)
    665                     {
     634                    if (like_std < ii) {
    666635                        like_std = ii;
    667636                        kk = like_std >4 ? like_std-4: 0;
    668637                    }
    669                     if(min_std > ii) min_std = ii;
     638                    if (min_std > ii) min_std = ii;
    670639                }
    671640                jj <<= 1;
    672641            }
    673             if(like_std < 3) like_std = 3;
     642            if (like_std < 3) like_std = 3;
    674643        }
    675644        /* Figure out what standard the device is using if it hasn't told
     
    677646         * the words from the next level up.  It happens.
    678647         */
    679         if(like_std < std) like_std = std;
     648        if (like_std < std) like_std = std;
    680649
    681650        if (((std == 5) || (!std && (like_std < 6))) &&
     
    683652            ((  val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
    684653            ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
    685             (   val[CMDS_SUPP_2] & CMDS_W84) ) ) )
    686         {
     654            (   val[CMDS_SUPP_2] & CMDS_W84) ) )
     655        ) {
    687656            like_std = 6;
    688         }
    689         else if (((std == 4) || (!std && (like_std < 5))) &&
     657        } else if (((std == 4) || (!std && (like_std < 5))) &&
    690658            ((((val[INTEGRITY]  & SIG) == SIG_VAL) && !chksum) ||
    691659            ((  val[HWRST_RSLT] & VALID) == VALID_VAL) ||
     
    694662        {
    695663            like_std = 5;
    696         }
    697         else if (((std == 3) || (!std && (like_std < 4))) &&
     664        } else if (((std == 3) || (!std && (like_std < 4))) &&
    698665                ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
    699666                ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
     
    701668                ((  val[CAPAB_1] & VALID) == VALID_VAL) ||
    702669                ((  val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
    703                 ((  val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) )
    704         {
     670                ((  val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) )
     671        ) {
    705672            like_std = 4;
    706         }
    707         else if (((std == 2) || (!std && (like_std < 3))) &&
    708                ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) )
    709         {
     673        } else if (((std == 2) || (!std && (like_std < 3)))
     674         && ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
     675        ) {
    710676            like_std = 3;
    711         }
    712         else if (((std == 1) || (!std && (like_std < 2))) &&
     677        } else if (((std == 1) || (!std && (like_std < 2))) &&
    713678                ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
    714679                (val[WHATS_VALID] & OK_W64_70)) )
     
    716681            like_std = 2;
    717682        }
     683
    718684        if (!std)
    719             printf("\n\tLikely used: %u\n",like_std);
     685            printf("\n\tLikely used: %u\n", like_std);
    720686        else if (like_std > std)
    721             printf("& some of %u\n",like_std);
     687            printf("& some of %u\n", like_std);
    722688        else
    723             printf("\n");
    724     }
    725     else
    726     {
     689            puts("");
     690    } else {
    727691        /* TBD: do CDROM stuff more thoroughly.  For now... */
    728692        kk = 0;
    729         if (val[CDR_MINOR] == 9)
    730         {
     693        if (val[CDR_MINOR] == 9) {
    731694            kk = 1;
    732695            printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
    733696        }
    734         if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1))
    735         {
     697        if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) {
    736698            kk = 1;
    737699            printf("\n\tSupported: CD-ROM ATAPI");
    738700            jj = val[CDR_MAJOR] >> 1;
    739             for (ii = 1; ii <15; ii++)
    740             {
    741                 if(jj & 0x0001) printf("-%u ", ii);
     701            for (ii = 1; ii < 15; ii++) {
     702                if (jj & 0x0001) printf("-%u ", ii);
    742703                jj >>= 1;
    743704            }
    744705        }
    745         printf("%s\n", (!kk) ? "\n\tLikely used CD-ROM ATAPI-1" : "" );
     706        printf("%s\n", kk ? "" : "\n\tLikely used CD-ROM ATAPI-1");
    746707        /* the cdrom stuff is more like ATA-2 than anything else, so: */
    747708        like_std = 2;
     
    753714    printf("Configuration:\n");
    754715    /* more info from the general configuration word */
    755     if ((eqpt != CDROM) && (like_std == 1))
    756     {
     716    if ((eqpt != CDROM) && (like_std == 1)) {
    757717        jj = val[GEN_CONFIG] >> 1;
    758         for (ii = 1; ii < 15; ii++)
    759         {
    760             if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
     718        for (ii = 1; ii < 15; ii++) {
     719            if (jj & 0x0001)
     720                printf("\t%s\n", ata1_cfg_str[ii]);
    761721            jj >>=1;
    762722        }
    763723    }
    764     if (dev == ATAPI_DEV)
    765     {
     724    if (dev == ATAPI_DEV) {
    766725        if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) ==  DRQ_3MS_VAL)
    767726            strng = "3ms";
     
    770729        else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) ==  DRQ_50US_VAL)
    771730            strng ="50us";
    772         else 
     731        else
    773732            strng = "Unknown";
    774733        printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */
     
    781740            strng = "Unknown";
    782741        puts(strng);
    783     }
    784     else
    785     {
     742    } else {
    786743        /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
    787744        ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
    788745        mm = 0; bbbig = 0;
    789         if ( (ll > 0x00FBFC10) && (!val[LCYLS]))
     746        if ((ll > 0x00FBFC10) && (!val[LCYLS]))
    790747            printf("\tCHS addressing not supported\n");
    791         else
    792         {
     748        else {
    793749            jj = val[WHATS_VALID] & OK_W54_58;
    794750            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",
     
    796752
    797753            if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES]))
    798                 printf("\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]);
    799 
    800             if (jj)
    801             {
     754                printf("\tbytes/track: %u\tbytes/sector: %u\n", val[TRACK_BYTES], val[SECT_BYTES]);
     755
     756            if (jj) {
    802757                mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
    803                 if (like_std < 3)
    804                 {
    805                      /* check Endian of capacity bytes */
     758                if (like_std < 3) {
     759                    /* check Endian of capacity bytes */
    806760                    nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
    807761                    oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
     
    809763                        mm = oo;
    810764                }
    811                 printf("\tCHS current addressable sectors:%11u\n",mm);
     765                printf("\tCHS current addressable sectors:%11u\n", mm);
    812766            }
    813767        }
    814768        /* LBA addressing */
    815         printf("\tLBA    user addressable sectors:%11u\n",ll);
    816         if ( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
    817              (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
    818         {
    819             bbbig = (uint64_t)val[LBA_64_MSB]   << 48 |
    820                     (uint64_t)val[LBA_48_MSB]   << 32 |
    821                     (uint64_t)val[LBA_MID]  << 16 |
    822                     val[LBA_LSB] ;
    823             printf("\tLBA48  user addressable sectors:%11"PRIu64"\n",bbbig);
     769        printf("\tLBA    user addressable sectors:%11u\n", ll);
     770        if (((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
     771         && (val[CMDS_SUPP_1] & SUPPORT_48_BIT)
     772        ) {
     773            bbbig = (uint64_t)val[LBA_64_MSB] << 48 |
     774                    (uint64_t)val[LBA_48_MSB] << 32 |
     775                    (uint64_t)val[LBA_MID] << 16 |
     776                    val[LBA_LSB];
     777            printf("\tLBA48  user addressable sectors:%11"PRIu64"\n", bbbig);
    824778        }
    825779
    826780        if (!bbbig)
    827781            bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
    828         printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n",bbbig>>11);
    829         bbbig = (bbbig<<9)/1000000;
    830         printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ",bbbig);
     782        printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n", bbbig>>11);
     783        bbbig = (bbbig << 9) / 1000000;
     784        printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ", bbbig);
    831785
    832786        if (bbbig > 1000)
    833787            printf("(%"PRIu64" GB)\n", bbbig/1000);
    834         else 
    835             printf("\n");
     788        else
     789            puts("");
    836790    }
    837791
     
    839793    printf("Capabilities:\n\t");
    840794
    841     if (dev == ATAPI_DEV)
    842     {
     795    if (dev == ATAPI_DEV) {
    843796        if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, ");
    844797        if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, ");
     
    846799    if (val[CAPAB_0] & LBA_SUP) printf("LBA, ");
    847800
    848     if (like_std != 1)
    849     {
    850         printf("IORDY%s(can%s be disabled)\n",
    851                 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
     801    if (like_std != 1) {
     802        printf("IORDY%s(can%s be disabled)\n",
     803                !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
    852804                (val[CAPAB_0] & IORDY_OFF) ? "" :"not");
    853     }
    854     else
     805    } else
    855806        printf("no IORDY\n");
    856807
    857     if ((like_std == 1) && val[BUF_TYPE])
    858     {
     808    if ((like_std == 1) && val[BUF_TYPE]) {
    859809        printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
    860                 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", 
     810                (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
    861811                (val[BUF_TYPE] > 2) ? " with read caching ability" : "");
    862812    }
    863813
    864     if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1)))
    865     {
    866         printf("\tBuffer size: %.1fkB\n",(float)val[BUFFER__SIZE]/2);
    867     }
    868     if ((min_std < 4) && (val[RW_LONG]))
    869     {
    870         printf("\tbytes avail on r/w long: %u\n",val[RW_LONG]);
    871     }
    872     if ((eqpt != CDROM) && (like_std > 3))
    873     {
    874         printf("\tQueue depth: %u\n",(val[QUEUE_DEPTH] & DEPTH_BITS)+1);
    875     }
    876 
    877     if (dev == ATA_DEV)
    878     {
     814    if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) {
     815        printf("\tBuffer size: %.1fkB\n", (float)val[BUFFER__SIZE]/2);
     816    }
     817    if ((min_std < 4) && (val[RW_LONG])) {
     818        printf("\tbytes avail on r/w long: %u\n", val[RW_LONG]);
     819    }
     820    if ((eqpt != CDROM) && (like_std > 3)) {
     821        printf("\tQueue depth: %u\n", (val[QUEUE_DEPTH] & DEPTH_BITS) + 1);
     822    }
     823
     824    if (dev == ATA_DEV) {
    879825        if (like_std == 1)
    880             printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":"");
    881         else
    882         {
     826            printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : "");
     827        else {
    883828            printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor");
    884829            if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
    885                 printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
     830                printf(", %s device specific minimum\n", (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no");
    886831            else
    887               printf("\n");
     832                puts("");
    888833        }
    889834        printf("\tR/W multiple sector transfer: ");
    890835        if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
    891836            printf("not supported\n");
    892         else
    893         {
    894             printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER);
     837        else {
     838            printf("Max = %u\tCurrent = ", val[SECTOR_XFER_MAX] & SECTOR_XFER);
    895839            if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID)
    896840                printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER);
     
    898842                printf("?\n");
    899843        }
    900         if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008))
    901         {
     844        if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) {
    902845            /* We print out elsewhere whether the APM feature is enabled or
    903846               not.  If it's not enabled, let's not repeat the info; just print
    904847               nothing here. */
    905848            printf("\tAdvancedPM level: ");
    906             if ( (val[ADV_PWR] & 0xFF00) == 0x4000 )
    907             {
     849            if ((val[ADV_PWR] & 0xFF00) == 0x4000) {
    908850                uint8_t apm_level = val[ADV_PWR] & 0x00FF;
    909851                printf("%u (0x%x)\n", apm_level, apm_level);
     
    914856        if (like_std > 5 && val[ACOUSTIC]) {
    915857            printf("\tRecommended acoustic management value: %u, current value: %u\n",
    916                                     (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
    917         }
    918     }
    919     else
    920     {
     858                    (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
     859        }
     860    } else {
    921861         /* ATAPI */
    922862        if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ))
    923863            printf("\tATA sw reset required\n");
    924864
    925         if (val[PKT_REL] || val[SVC_NBSY])
    926         {
     865        if (val[PKT_REL] || val[SVC_NBSY]) {
    927866            printf("\tOverlap support:");
    928             if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]);
    929             if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
    930             printf("\n");
     867            if (val[PKT_REL]) printf(" %uus to release bus.", val[PKT_REL]);
     868            if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.", val[SVC_NBSY]);
     869            puts("");
    931870        }
    932871    }
     
    936875    if (!(val[CAPAB_0] & DMA_SUP))
    937876        printf("not supported\n");
    938     else
    939     {
     877    else {
    940878        if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA])
    941             printf(" sdma%u\n",(val[DMA_MODE] & MODE) >> 8);
    942         if (val[SINGLE_DMA])
    943         {
     879            printf(" sdma%u\n", (val[DMA_MODE] & MODE) >> 8);
     880        if (val[SINGLE_DMA]) {
    944881            jj = val[SINGLE_DMA];
    945882            kk = val[SINGLE_DMA] >> 8;
    946             err_dma += mode_loop(jj,kk,'s',&have_mode);
    947         }
    948         if (val[MULTI_DMA])
    949         {
     883            err_dma += mode_loop(jj, kk, 's', &have_mode);
     884        }
     885        if (val[MULTI_DMA]) {
    950886            jj = val[MULTI_DMA];
    951887            kk = val[MULTI_DMA] >> 8;
    952             err_dma += mode_loop(jj,kk,'m',&have_mode);
    953         }
    954         if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA])
    955         {
     888            err_dma += mode_loop(jj, kk, 'm', &have_mode);
     889        }
     890        if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) {
    956891            jj = val[ULTRA_DMA];
    957892            kk = val[ULTRA_DMA] >> 8;
    958             err_dma += mode_loop(jj,kk,'u',&have_mode);
     893            err_dma += mode_loop(jj, kk, 'u', &have_mode);
    959894        }
    960895        if (err_dma || !have_mode) printf("(?)");
    961         printf("\n");
     896        puts("");
    962897
    963898        if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
    964899            printf("\t\tInterleaved DMA support\n");
    965900
    966         if ((val[WHATS_VALID] & OK_W64_70) &&
    967            (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]))
    968         {
     901        if ((val[WHATS_VALID] & OK_W64_70)
     902         && (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])
     903        ) {
    969904            printf("\t\tCycle time:");
    970             if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]);
    971             if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]);
    972             printf("\n");
     905            if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]);
     906            if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]);
     907            puts("");
    973908        }
    974909    }
     
    978913    /* If a drive supports mode n (e.g. 3), it also supports all modes less
    979914     * than n (e.g. 3, 2, 1 and 0).  Print all the modes. */
    980     if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP))
    981     {
     915    if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) {
    982916        jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
    983         for (ii = 0; ii <= PIO_MODE_MAX ; ii++)
    984         {
    985             if (jj & 0x0001) printf("pio%d ",ii);
     917        for (ii = 0; ii <= PIO_MODE_MAX; ii++) {
     918            if (jj & 0x0001) printf("pio%d ", ii);
    986919            jj >>=1;
    987920        }
    988         printf("\n");
    989     }
    990     else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
    991     {
     921        puts("");
     922    } else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) {
    992923        for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
    993             printf("pio%d ",ii);
    994         printf("\n");
    995     }
    996     else
     924            printf("pio%d ", ii);
     925        puts("");
     926    } else
    997927        printf("unknown\n");
    998928
    999     if (val[WHATS_VALID] & OK_W64_70)
    1000     {
    1001         if (val[PIO_NO_FLOW] || val[PIO_FLOW])
    1002         {
     929    if (val[WHATS_VALID] & OK_W64_70) {
     930        if (val[PIO_NO_FLOW] || val[PIO_FLOW]) {
    1003931            printf("\t\tCycle time:");
    1004932            if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]);
    1005933            if (val[PIO_FLOW]) printf("  IORDY flow control=%uns", val[PIO_FLOW]);
    1006             printf("\n");
    1007         }
    1008     }
    1009 
    1010     if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
    1011     {
     934            puts("");
     935        }
     936    }
     937
     938    if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) {
    1012939        printf("Commands/features:\n\tEnabled\tSupported:\n");
    1013940        jj = val[CMDS_SUPP_0];
    1014941        kk = val[CMDS_EN_0];
    1015         for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++)
    1016         {
    1017             if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0'))
    1018             {
     942        for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) {
     943            if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) {
    1019944                printf("\t%s\t%s\n", (kk & 0x8000) ? "   *" : "", cmd_feat_str[ii]);
    1020945            }
    1021             jj <<=1; kk<<=1;
    1022             if (ii%16 == 15)
    1023             {
     946            jj <<= 1;
     947            kk <<= 1;
     948            if (ii % 16 == 15) {
    1024949                jj = val[CMDS_SUPP_0+1+(ii/16)];
    1025950                kk = val[CMDS_EN_0+1+(ii/16)];
    1026951            }
    1027             if (ii == 31)
    1028             {
     952            if (ii == 31) {
    1029953                if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
    1030954                    ii +=16;
     
    1033957    }
    1034958    /* Removable Media Status Notification feature set */
    1035     if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
     959    if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
    1036960        printf("\t%s supported\n", cmd_feat_str[27]);
    1037961
    1038 
    1039962    /* security */
    1040     if ((eqpt != CDROM) && (like_std > 3) &&
    1041        (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]))
    1042     {
     963    if ((eqpt != CDROM) && (like_std > 3)
     964     && (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])
     965    ) {
    1043966        printf("Security:\n");
    1044967        if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1))
    1045             printf("\tMaster password revision code = %u\n",val[PSWD_CODE]);
     968            printf("\tMaster password revision code = %u\n", val[PSWD_CODE]);
    1046969        jj = val[SECU_STATUS];
    1047         if (jj)
    1048         {
    1049             for (ii = 0; ii < NUM_SECU_STR; ii++)
    1050             {
     970        if (jj) {
     971            for (ii = 0; ii < NUM_SECU_STR; ii++) {
    1051972                printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "",  secu_str[ii]);
    1052973                jj >>=1;
    1053974            }
    1054             if (val[SECU_STATUS] & SECU_ENABLED)
    1055             {
     975            if (val[SECU_STATUS] & SECU_ENABLED) {
    1056976                printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high");
    1057977            }
     
    1059979        jj =  val[ERASE_TIME]     & ERASE_BITS;
    1060980        kk =  val[ENH_ERASE_TIME] & ERASE_BITS;
    1061         if (jj || kk)
    1062         {
     981        if (jj || kk) {
    1063982            printf("\t");
    1064983            if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
    1065984            if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
    1066             printf("\n");
     985            puts("");
    1067986        }
    1068987    }
     
    1070989    /* reset result */
    1071990    jj = val[HWRST_RSLT];
    1072     if ((jj & VALID) == VALID_VAL)
    1073     {
     991    if ((jj & VALID) == VALID_VAL) {
    1074992        if (!(oo = (jj & RST0)))
    1075993            jj >>= 8;
     
    1078996        else if ((jj & DEV_DET) == CSEL_VAL)
    1079997            strng = " determined by CSEL";
    1080         else 
     998        else
    1081999            strng = "";
    1082         printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", 
     1000        printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n",
    10831001                (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng);
    10841002    }
    10851003
    10861004    /* more stuff from std 5 */
    1087     if ((like_std > 4) && (eqpt != CDROM))
    1088     {
    1089         if (val[CFA_PWR_MODE] & VALID_W160)
    1090         {
     1005    if ((like_std > 4) && (eqpt != CDROM)) {
     1006        if (val[CFA_PWR_MODE] & VALID_W160) {
    10911007            printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled",
    1092                                         (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
    1093 
    1094             if (val[CFA_PWR_MODE] & MAX_AMPS) printf("\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS);
    1095         }
    1096         if ((val[INTEGRITY] & SIG) == SIG_VAL)
    1097         {
     1008                    (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
     1009
     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) {
    10981014            printf("Checksum: %scorrect\n", chksum ? "in" : "");
    10991015        }
     
    11041020#endif
    11051021
    1106 static int get_identity, get_geom;
    1107 static int do_flush;
    1108 static int do_ctimings, do_timings;
    1109 static unsigned long set_readahead, get_readahead, Xreadahead;
    1110 static unsigned long set_readonly, get_readonly, readonly;
    1111 static unsigned long set_unmask, get_unmask, unmask;
    1112 static unsigned long set_mult, get_mult, mult;
    1113 #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
    1114 static unsigned long set_dma, get_dma, dma;
    1115 #endif
    1116 static unsigned long set_dma_q, get_dma_q, dma_q;
    1117 static unsigned long set_nowerr, get_nowerr, nowerr;
    1118 static unsigned long set_keep, get_keep, keep;
    1119 static unsigned long set_io32bit, get_io32bit, io32bit;
    1120 static unsigned long set_piomode, noisy_piomode;
     1022static smallint get_identity, get_geom;
     1023static smallint do_flush;
     1024static smallint do_ctimings, do_timings;
     1025static smallint reread_partn;
     1026
     1027static smallint set_piomode, noisy_piomode;
     1028static smallint set_readahead, get_readahead;
     1029static smallint set_readonly, get_readonly;
     1030static smallint set_unmask, get_unmask;
     1031static smallint set_mult, get_mult;
     1032static smallint set_dma_q, get_dma_q;
     1033static smallint set_nowerr, get_nowerr;
     1034static smallint set_keep, get_keep;
     1035static smallint set_io32bit, get_io32bit;
    11211036static int piomode;
     1037static unsigned long Xreadahead;
     1038static unsigned long readonly;
     1039static unsigned long unmask;
     1040static unsigned long mult;
     1041static unsigned long dma_q;
     1042static unsigned long nowerr;
     1043static unsigned long keep;
     1044static unsigned long io32bit;
     1045#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
     1046static unsigned long dma;
     1047static smallint set_dma, get_dma;
     1048#endif
    11221049#ifdef HDIO_DRIVE_CMD
    1123 static unsigned long set_dkeep, get_dkeep, dkeep;
    1124 static unsigned long set_standby, get_standby, standby_requested;
    1125 static unsigned long set_xfermode, get_xfermode;
     1050static smallint set_xfermode, get_xfermode;
     1051static smallint set_dkeep, get_dkeep;
     1052static smallint set_standby, get_standby;
     1053static smallint set_lookahead, get_lookahead;
     1054static smallint set_prefetch, get_prefetch;
     1055static smallint set_defects, get_defects;
     1056static smallint set_wcache, get_wcache;
     1057static smallint set_doorlock, get_doorlock;
     1058static smallint set_seagate, get_seagate;
     1059static smallint set_standbynow, get_standbynow;
     1060static smallint set_sleepnow, get_sleepnow;
     1061static smallint get_powermode;
     1062static smallint set_apmmode, get_apmmode;
    11261063static int xfermode_requested;
    1127 static unsigned long set_lookahead, get_lookahead, lookahead;
    1128 static unsigned long set_prefetch, get_prefetch, prefetch;
    1129 static unsigned long set_defects, get_defects, defects;
    1130 static unsigned long set_wcache, get_wcache, wcache;
    1131 static unsigned long set_doorlock, get_doorlock, doorlock;
    1132 static unsigned long set_seagate, get_seagate;
    1133 static unsigned long set_standbynow, get_standbynow;
    1134 static unsigned long set_sleepnow, get_sleepnow;
    1135 static unsigned long get_powermode;
    1136 static unsigned long set_apmmode, get_apmmode, apmmode;
    1137 #endif
    1138 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    1139 static int get_IDentity;
    1140 #endif
    1141 #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
    1142 static unsigned long    unregister_hwif;
    1143 static unsigned long    hwif;
    1144 #endif
    1145 #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
    1146 static unsigned long scan_hwif;
     1064static unsigned long dkeep;
     1065static unsigned long standby_requested;
     1066static unsigned long lookahead;
     1067static unsigned long prefetch;
     1068static unsigned long defects;
     1069static unsigned long wcache;
     1070static unsigned long doorlock;
     1071static unsigned long apmmode;
     1072#endif
     1073USE_FEATURE_HDPARM_GET_IDENTITY(        static smallint get_IDentity;)
     1074USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(  static smallint set_busstate, get_busstate;)
     1075USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(    static smallint perform_reset;)
     1076USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(  static smallint perform_tristate;)
     1077USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(static smallint unregister_hwif;)
     1078USE_FEATURE_HDPARM_HDIO_SCAN_HWIF(      static smallint scan_hwif;)
     1079USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(  static unsigned long busstate;)
     1080USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(  static unsigned long tristate;)
     1081USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(static unsigned long hwif;)
     1082#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
    11471083static unsigned long hwif_data;
    11481084static unsigned long hwif_ctrl;
    11491085static unsigned long hwif_irq;
    11501086#endif
    1151 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
    1152 static unsigned long    set_busstate, get_busstate, busstate;
    1153 #endif
    1154 static int  reread_partn;
    1155 
    1156 #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
    1157 static int  perform_reset;
    1158 #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
    1159 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
    1160 static unsigned long    perform_tristate,   tristate;
    1161 #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
    11621087
    11631088// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
     
    11721097// Too bad, really.
    11731098
    1174 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    1175 static const char * const cfg_str[] =
    1176 {   "",      "HardSect",   "SoftSect",   "NotMFM",
     1099#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     1100static const char *const cfg_str[] = {
     1101    "",      "HardSect",   "SoftSect",   "NotMFM",
    11771102    "HdSw>15uSec", "SpinMotCtl", "Fixed",     "Removeable",
    11781103    "DTR<=5Mbs",   "DTR>5Mbs",   "DTR>10Mbs", "RotSpdTol>.5%",
     
    11801105};
    11811106
    1182 static const char * const BuffType[] = {"Unknown", "1Sect", "DualPort", "DualPortCache"};
     1107static const char *const BuffType[] = {
     1108    "Unknown", "1Sect", "DualPort", "DualPortCache"
     1109};
    11831110
    11841111static void dump_identity(const struct hd_driveid *id)
    11851112{
    11861113    int i;
    1187     const unsigned short int *id_regs= (const void*) id;
     1114    const unsigned short int *id_regs = (const void*) id;
    11881115
    11891116    printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
    11901117                id->model, id->fw_rev, id->serial_no);
    1191     for (i=0; i<=15; i++) {
     1118    for (i = 0; i <= 15; i++) {
    11921119        if (id->config & (1<<i))
    11931120            printf(" %s", cfg_str[i]);
    11941121    }
    1195     printf( " }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
     1122    printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
    11961123            " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u",
    11971124                id->cyls, id->heads, id->sectors, id->track_bytes,
     
    11991126                id->buf_type, BuffType[(id->buf_type > 3) ? 0 :  id->buf_type],
    12001127                id->buf_size/2, id->max_multsect);
    1201     if (id->max_multsect)
    1202     {
     1128    if (id->max_multsect) {
    12031129        printf(", MultSect=");
    1204         if (!(id->multsect_valid&1))
     1130        if (!(id->multsect_valid & 1))
    12051131            printf("?%u?", id->multsect);
    12061132        else if (id->multsect)
     
    12091135            printf("off");
    12101136    }
    1211     printf("\n");
    1212 
    1213     if(!(id->field_valid&1))
     1137    puts("");
     1138
     1139    if (!(id->field_valid & 1))
    12141140        printf(" (maybe):");
    12151141
    1216     printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
    1217                                                     id->cur_sectors,
    1218                                                     (BB_BIG_ENDIAN) ?
    1219                                                     (long unsigned int)(id->cur_capacity0 << 16) | id->cur_capacity1 :
    1220                                                     (long unsigned int)(id->cur_capacity1 << 16) | id->cur_capacity0,
    1221                                                     ((id->capability&2) == 0) ? "no" : "yes");
    1222 
    1223     if (id->capability&2)
     1142    printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s", id->cur_cyls, id->cur_heads,
     1143        id->cur_sectors,
     1144        (BB_BIG_ENDIAN) ?
     1145            (unsigned long)(id->cur_capacity0 << 16) | id->cur_capacity1 :
     1146            (unsigned long)(id->cur_capacity1 << 16) | id->cur_capacity0,
     1147            ((id->capability&2) == 0) ? "no" : "yes");
     1148
     1149    if (id->capability & 2)
    12241150        printf(", LBAsects=%u", id->lba_capacity);
    12251151
    1226     printf("\n IORDY=%s", (id->capability&8) ? (id->capability&4) ?  "on/off" : "yes" : "no");
    1227 
    1228     if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&2)
     1152    printf("\n IORDY=%s", (id->capability & 8) ? (id->capability & 4) ?  "on/off" : "yes" : "no");
     1153
     1154    if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2))
    12291155        printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
    1230    
    1231     if ((id->capability&1) && (id->field_valid&2))
     1156
     1157    if ((id->capability & 1) && (id->field_valid & 2))
    12321158        printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
    12331159
    12341160    printf("\n PIO modes:  ");
    1235     if (id->tPIO <= 5)
    1236     {
     1161    if (id->tPIO <= 5) {
    12371162        printf("pio0 ");
    12381163        if (id->tPIO >= 1) printf("pio1 ");
    12391164        if (id->tPIO >= 2) printf("pio2 ");
    12401165    }
    1241     if (id->field_valid&2)
    1242     {
     1166    if (id->field_valid & 2) {
    12431167        if (id->eide_pio_modes & 1) printf("pio3 ");
    12441168        if (id->eide_pio_modes & 2) printf("pio4 ");
    12451169        if (id->eide_pio_modes &~3) printf("pio? ");
    12461170    }
    1247     if (id->capability&1)
    1248     {
    1249         if (id->dma_1word | id->dma_mword)
    1250         {
     1171    if (id->capability & 1) {
     1172        if (id->dma_1word | id->dma_mword) {
    12511173            printf("\n DMA modes:  ");
    12521174            if (id->dma_1word & 0x100) printf("*");
     
    12681190        }
    12691191    }
    1270     if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&4)
    1271     {   
     1192    if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) {
    12721193        printf("\n UDMA modes: ");
    12731194        if (id->dma_ultra & 0x100) printf("*");
     
    12781199        if (id->dma_ultra & 0x004) printf("udma2 ");
    12791200#ifdef __NEW_HD_DRIVE_ID
    1280         if (id->hw_config & 0x2000)
    1281         {
     1201        if (id->hw_config & 0x2000) {
    12821202#else /* !__NEW_HD_DRIVE_ID */
    1283         if (id->word93 & 0x2000)
    1284         {
     1203        if (id->word93 & 0x2000) {
    12851204#endif /* __NEW_HD_DRIVE_ID */
    12861205            if (id->dma_ultra & 0x0800) printf("*");
     
    12961215        }
    12971216    }
    1298     printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes");
    1299     if (id_regs[83] & 8)
    1300     {
    1301         if (!(id_regs[86]&8))
     1217    printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes");
     1218    if (id_regs[83] & 8) {
     1219        if (!(id_regs[86] & 8))
    13021220            printf(": disabled (255)");
    1303         else if ((id_regs[91]&0xFF00)!=0x4000)
     1221        else if ((id_regs[91] & 0xFF00) != 0x4000)
    13041222            printf(": unknown setting");
    13051223        else
    1306             printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF);
    1307     }
    1308     if (id_regs[82]&0x20)
    1309         printf(" WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled");
     1224            printf(": mode=0x%02X (%u)", id_regs[91] & 0xFF, id_regs[91] & 0xFF);
     1225    }
     1226    if (id_regs[82] & 0x20)
     1227        printf(" WriteCache=%s", (id_regs[85] & 0x20) ? "enabled" : "disabled");
    13101228#ifdef __NEW_HD_DRIVE_ID
    1311     if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31))
    1312     {
     1229    if ((id->minor_rev_num && id->minor_rev_num <= 31)
     1230     || (id->major_rev_num && id->minor_rev_num <= 31)
     1231    ) {
    13131232        printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? minor_str[id->minor_rev_num] : "Unknown");
    13141233        if (id->major_rev_num != 0x0000 &&  /* NOVAL_0 */
    13151234            id->major_rev_num != 0xFFFF) {  /* NOVAL_1 */
    1316             for (i=0; i <= 15; i++) {
     1235            for (i = 0; i <= 15; i++) {
    13171236                if (id->major_rev_num & (1<<i))
    13181237                        printf(" ATA/ATAPI-%u", i);
     
    13281247{
    13291248    fsync(fd);              /* flush buffers */
    1330     bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */
     1249    ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
    13311250#ifdef HDIO_DRIVE_CMD
    13321251    sleep(1);
    1333     if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
    1334         bb_perror_msg("HDIO_DRIVE_CMD");
     1252    if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) {   /* await completion */
     1253        if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
     1254            bb_perror_msg("HDIO_DRIVE_CMD");
     1255        else
     1256            bb_perror_msg("ioctl %#x failed", HDIO_DRIVE_CMD);
     1257    }
    13351258#endif
    13361259}
     
    13471270    int i;
    13481271
    1349     if ((i = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) {
     1272    i = read(fd, buf, TIMING_BUF_BYTES);
     1273    if (i != TIMING_BUF_BYTES) {
    13501274        bb_error_msg("read(%d bytes) failed (rc=%d)", TIMING_BUF_BYTES, i);
    13511275        return 1;
     
    13571281}
    13581282
    1359 static void print_timing(int t, double e)
    1360 {
    1361     if (t >= e)  /* more than 1MB/s */
    1362         printf("%2d MB in %5.2f seconds =%6.2f %cB/sec\n", t, e, t / e, 'M');
    1363     else
    1364         printf("%2d MB in %5.2f seconds =%6.2f %cB/sec\n", t, e, t / e * 1024, 'k');
    1365 }
    1366 
    1367 static int do_blkgetsize (int fd, unsigned long long *blksize64)
    1368 {
    1369     int     rc;
    1370     unsigned int    blksize32 = 0;
     1283static int do_blkgetsize(int fd, unsigned long long *blksize64)
     1284{
     1285    int rc;
     1286    unsigned blksize32 = 0;
    13711287
    13721288    if (0 == ioctl(fd, BLKGETSIZE64, blksize64)) {  // returns bytes
     
    13741290        return 0;
    13751291    }
    1376     rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors
    1377     if (rc)
    1378         bb_perror_msg("BLKGETSIZE");
     1292    rc = ioctl_or_warn(fd, BLKGETSIZE, &blksize32); // returns sectors
    13791293    *blksize64 = blksize32;
    13801294    return rc;
    13811295}
    13821296
     1297static void print_timing(unsigned t, double e)
     1298{
     1299    if (t >= e)  /* more than 1MB/s */
     1300        printf("%4d MB in %.2f seconds = %.2f %cB/sec\n", t, e, t / e, 'M');
     1301    else
     1302        printf("%4d MB in %.2f seconds = %.2f %cB/sec\n", t, e, t / e * 1024, 'k');
     1303}
     1304
    13831305static void do_time(int flag, int fd)
    1384 /*
    1385     flag = 0 time_cache
    1386     flag = 1 time_device
    1387 */
    1388 {
    1389     struct itimerval e1, e2;
    1390     double elapsed, elapsed2;
    1391     unsigned int max_iterations = 1024, total_MB, iterations;
     1306/* flag = 0 time_cache, 1 time_device */
     1307{
     1308    static const struct itimerval thousand = {{1000, 0}, {1000, 0}};
     1309
     1310    struct itimerval itv;
     1311    unsigned elapsed, elapsed2;
     1312    unsigned max_iterations, total_MB, iterations;
    13921313    unsigned long long blksize;
    13931314    RESERVE_CONFIG_BUFFER(buf, TIMING_BUF_BYTES);
     
    13981319    }
    13991320
     1321    max_iterations = 1024;
    14001322    if (0 == do_blkgetsize(fd, &blksize)) {
    14011323        max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB;
     
    14041326    /* Clear out the device request queues & give them time to complete */
    14051327    sync();
    1406     sleep(3);
    1407 
    1408     setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
    1409 
    1410     if (flag  == 0) /* Time cache */
    1411     {
    1412         if (seek_to_zero (fd)) return;
    1413         if (read_big_block (fd, buf)) return;
    1414         printf(" Timing cached reads:   ");
    1415         fflush(stdout);
    1416    
    1417         /* Now do the timing */
    1418         iterations = 0;
    1419         getitimer(ITIMER_REAL, &e1);
     1328    sleep(2);
     1329    if (flag == 0) { /* Time cache */
     1330        if (seek_to_zero(fd))
     1331            goto quit;
     1332        if (read_big_block(fd, buf))
     1333            goto quit;
     1334        printf(" Timing buffer-cache reads:  ");
     1335    } else { /* Time device */
     1336        printf(" Timing buffered disk reads: ");
     1337    }
     1338    fflush(stdout);
     1339    iterations = 0;
     1340    /*
     1341     * getitimer() is used rather than gettimeofday() because
     1342     * it is much more consistent (on my machine, at least).
     1343     */
     1344    setitimer(ITIMER_REAL, &thousand, NULL);
     1345    /* Now do the timing */
     1346    do {
     1347        ++iterations;
     1348        if ((flag == 0) && seek_to_zero(fd))
     1349            goto quit;
     1350        if (read_big_block(fd, buf))
     1351            goto quit;
     1352        getitimer(ITIMER_REAL, &itv);
     1353        elapsed = (1000 - itv.it_value.tv_sec) * 1000000
     1354                - itv.it_value.tv_usec;
     1355    } while (elapsed < 3000000 && iterations < max_iterations);
     1356    total_MB = iterations * TIMING_BUF_MB;
     1357    if (flag == 0) {
     1358        /* Now remove the lseek() and getitimer() overheads from the elapsed time */
     1359        setitimer(ITIMER_REAL, &thousand, NULL);
    14201360        do {
    1421             ++iterations;
    1422             if (seek_to_zero (fd) || read_big_block (fd, buf))
     1361            if (seek_to_zero(fd))
    14231362                goto quit;
    1424             getitimer(ITIMER_REAL, &e2);
    1425             elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec)
    1426             + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
    1427         } while (elapsed < 2.0);
    1428         total_MB = iterations * TIMING_BUF_MB;
    1429 
    1430         /* Now remove the lseek() and getitimer() overheads from the elapsed time */
    1431         getitimer(ITIMER_REAL, &e1);
    1432         do {
    1433             if (seek_to_zero (fd))
    1434                 goto quit;
    1435             getitimer(ITIMER_REAL, &e2);
    1436             elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec)
    1437             + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
     1363            getitimer(ITIMER_REAL, &itv);
     1364            elapsed2 = (1000 - itv.it_value.tv_sec) * 1000000
     1365                    - itv.it_value.tv_usec;
    14381366        } while (--iterations);
    1439    
    14401367        elapsed -= elapsed2;
    1441         print_timing(BUFCACHE_FACTOR * total_MB, elapsed); 
     1368        total_MB *= BUFCACHE_FACTOR;
    14421369        flush_buffer_cache(fd);
    1443         sleep(1);
    1444     }
    1445     else /* Time device */
    1446     {
    1447         printf(" Timing buffered disk reads:  ");
    1448         fflush(stdout);
    1449         /*
    1450         * getitimer() is used rather than gettimeofday() because
    1451         * it is much more consistent (on my machine, at least).
    1452         */
    1453         /* Now do the timings for real */
    1454         iterations = 0;
    1455         getitimer(ITIMER_REAL, &e1);
    1456         do {
    1457             ++iterations;
    1458             if (read_big_block (fd, buf))
    1459                 goto quit;
    1460             getitimer(ITIMER_REAL, &e2);
    1461             elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec)
    1462             + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
    1463         } while (elapsed < 3.0 && iterations < max_iterations);
    1464    
    1465         total_MB = iterations * TIMING_BUF_MB;
    1466         print_timing(total_MB, elapsed);
    1467     }
    1468 quit:
     1370    }
     1371    print_timing(total_MB, elapsed / 1000000.0);
     1372 quit:
    14691373    munlock(buf, TIMING_BUF_BYTES);
    1470 quit2:
     1374 quit2:
    14711375    RELEASE_CONFIG_BUFFER(buf);
    14721376}
    14731377
    1474 static void on_off (unsigned int value)
    1475 {
    1476     printf(value ? " (on)\n" : " (off)\n");
    1477 }
    1478 
    1479 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
    1480 static void bus_state_value(unsigned int value)
     1378#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
     1379static void bus_state_value(unsigned value)
    14811380{
    14821381    if (value == BUSSTATE_ON)
     
    14921391
    14931392#ifdef HDIO_DRIVE_CMD
    1494 static void interpret_standby(unsigned int standby)
    1495 {
    1496     unsigned int t;
     1393static void interpret_standby(unsigned standby)
     1394{
     1395    unsigned t;
    14971396
    14981397    printf(" (");
     
    15071406    else if (standby == 255)
    15081407        printf("21 minutes + 15 seconds");
    1509     else {
    1510         if (standby <= 240) {
    1511             t = standby * 5;
    1512             printf("%u minutes + %u seconds", t / 60, t % 60);
    1513         } else if (standby <= 251) {
    1514             t = (standby - 240) * 30;
    1515             printf("%u hours + %u minutes", t / 60, t % 60);
    1516         } else
    1517             printf("illegal value");
    1518     }
     1408    else if (standby <= 240) {
     1409        t = standby * 5;
     1410        printf("%u minutes + %u seconds", t / 60, t % 60);
     1411    } else if (standby <= 251) {
     1412        t = (standby - 240) * 30;
     1413        printf("%u hours + %u minutes", t / 60, t % 60);
     1414    } else
     1415        printf("illegal value");
    15191416    printf(")\n");
    15201417}
    15211418
    1522 struct xfermode_entry {
    1523     int val;
    1524     const char *name;
     1419static const uint8_t xfermode_val[] ALIGN1 = {
     1420     8,      9,     10,     11,     12,     13,     14,     15,
     1421    16,     17,     18,     19,     20,     21,     22,     23,
     1422    32,     33,     34,     35,     36,     37,     38,     39,
     1423    64,     65,     66,     67,     68,     69,     70,     71
    15251424};
    1526 
    1527 static const struct xfermode_entry xfermode_table[] = {
    1528     { 8,    "pio0" },
    1529     { 9,    "pio1" },
    1530     { 10,   "pio2" },
    1531     { 11,   "pio3" },
    1532     { 12,   "pio4" },
    1533     { 13,   "pio5" },
    1534     { 14,   "pio6" },
    1535     { 15,   "pio7" },
    1536     { 16,   "sdma0" },
    1537     { 17,   "sdma1" },
    1538     { 18,   "sdma2" },
    1539     { 19,   "sdma3" },
    1540     { 20,   "sdma4" },
    1541     { 21,   "sdma5" },
    1542     { 22,   "sdma6" },
    1543     { 23,   "sdma7" },
    1544     { 32,   "mdma0" },
    1545     { 33,   "mdma1" },
    1546     { 34,   "mdma2" },
    1547     { 35,   "mdma3" },
    1548     { 36,   "mdma4" },
    1549     { 37,   "mdma5" },
    1550     { 38,   "mdma6" },
    1551     { 39,   "mdma7" },
    1552     { 64,   "udma0" },
    1553     { 65,   "udma1" },
    1554     { 66,   "udma2" },
    1555     { 67,   "udma3" },
    1556     { 68,   "udma4" },
    1557     { 69,   "udma5" },
    1558     { 70,   "udma6" },
    1559     { 71,   "udma7" },
    1560     { 0, NULL }
     1425/* NB: we save size by _not_ storing terninating NUL! */
     1426static const char xfermode_name[][5] ALIGN1 = {
     1427    "pio0", "pio1", "pio2", "pio3", "pio4", "pio5", "pio6", "pio7",
     1428    "sdma0","sdma1","sdma2","sdma3","sdma4","sdma5","sdma6","sdma7",
     1429    "mdma0","mdma1","mdma2","mdma3","mdma4","mdma5","mdma6","mdma7",
     1430    "udma0","udma1","udma2","udma3","udma4","udma5","udma6","udma7"
    15611431};
    15621432
    1563 static int translate_xfermode(char * name)
    1564 {
    1565     const struct xfermode_entry *tmp;
    1566     char *endptr;
    1567     int val = -1;
    1568 
    1569 
    1570     for (tmp = xfermode_table; tmp->name != NULL; ++tmp)
    1571     {
    1572         if (!strcmp(name, tmp->name))
    1573             return tmp->val;
    1574     }
    1575 
    1576     val = strtol(name, &endptr, 10);
    1577     if (*endptr == '\0')
     1433static int translate_xfermode(const char *name)
     1434{
     1435    int val, i;
     1436
     1437    for (i = 0; i < ARRAY_SIZE(xfermode_val); i++) {
     1438        if (!strncmp(name, xfermode_name[i], 5))
     1439            if (strlen(name) <= 5)
     1440                return xfermode_val[i];
     1441    }
     1442    /* Negative numbers are invalid and are caught later */
     1443    val = bb_strtoi(name, NULL, 10);
     1444    if (!errno)
    15781445        return val;
    1579 
    15801446    return -1;
    15811447}
    15821448
    1583 static void interpret_xfermode(unsigned int xfermode)
     1449static void interpret_xfermode(unsigned xfermode)
    15841450{
    15851451    printf(" (");
     
    15891455        printf("default PIO mode, disable IORDY");
    15901456    else if (xfermode >= 8 && xfermode <= 15)
    1591         printf("PIO flow control mode%u", xfermode-8);
     1457        printf("PIO flow control mode%u", xfermode - 8);
    15921458    else if (xfermode >= 16 && xfermode <= 23)
    1593         printf("singleword DMA mode%u", xfermode-16);
     1459        printf("singleword DMA mode%u", xfermode - 16);
    15941460    else if (xfermode >= 32 && xfermode <= 39)
    1595         printf("multiword DMA mode%u", xfermode-32);
     1461        printf("multiword DMA mode%u", xfermode - 32);
    15961462    else if (xfermode >= 64 && xfermode <= 71)
    1597         printf("UltraDMA mode%u", xfermode-64);
     1463        printf("UltraDMA mode%u", xfermode - 64);
    15981464    else
    15991465        printf("Unknown");
     
    16021468#endif /* HDIO_DRIVE_CMD */
    16031469
    1604 static void print_flag(unsigned long flag, char *s, unsigned long value)
    1605 {
    1606     if(flag)
     1470static void print_flag(int flag, const char *s, unsigned long value)
     1471{
     1472    if (flag)
    16071473        printf(" setting %s to %ld\n", s, value);
    16081474}
     
    16111477{
    16121478    int fd;
    1613     static long parm, multcount;
     1479    long parm, multcount;
    16141480#ifndef HDIO_DRIVE_CMD
    16151481    int force_operation = 0;
     
    16171483    /* Please restore args[n] to these values after each ioctl
    16181484       except for args[2] */
    1619     unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
     1485    unsigned char args[4] = { WIN_SETFEATURES, 0, 0, 0 };
    16201486    const char *fmt = " %s\t= %2ld";
    16211487
    1622     fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
     1488    fd = xopen(devname, O_RDONLY|O_NONBLOCK);
    16231489    printf("\n%s:\n", devname);
    16241490
    1625     if (set_readahead)
    1626     {
    1627         print_flag(get_readahead,"fs readahead", Xreadahead);
    1628         bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET");
    1629     }
    1630 #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
    1631     if (unregister_hwif)
    1632     {
     1491    if (set_readahead) {
     1492        print_flag(get_readahead, "fs readahead", Xreadahead);
     1493        ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead);
     1494    }
     1495#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
     1496    if (unregister_hwif) {
    16331497        printf(" attempting to unregister hwif#%lu\n", hwif);
    1634         bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
    1635     }
    1636 #endif
    1637 #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
    1638     if (scan_hwif)
    1639     {
     1498        ioctl_or_warn(fd, HDIO_UNREGISTER_HWIF, (int *)(unsigned long)hwif);
     1499    }
     1500#endif
     1501#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
     1502    if (scan_hwif) {
    16401503        printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq);
    16411504        args[0] = hwif_data;
    16421505        args[1] = hwif_ctrl;
    16431506        args[2] = hwif_irq;
    1644         bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF");
     1507        ioctl_or_warn(fd, HDIO_SCAN_HWIF, args);
    16451508        args[0] = WIN_SETFEATURES;
    16461509        args[1] = 0;
    16471510    }
    16481511#endif
    1649     if (set_piomode)
    1650     {
    1651         if (noisy_piomode)
    1652         {
     1512    if (set_piomode) {
     1513        if (noisy_piomode) {
    16531514            printf(" attempting to ");
    16541515            if (piomode == 255)
     
    16611522                printf("set UDMA mode to %d\n", (piomode-200));
    16621523        }
    1663         bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE");
    1664     }
    1665     if (set_io32bit)
    1666     {
    1667         print_flag(get_io32bit,"32-bit IO_support flag", io32bit);
    1668         bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
    1669     }
    1670     if (set_mult)
    1671     {
     1524        ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode);
     1525    }
     1526    if (set_io32bit) {
     1527        print_flag(get_io32bit, "32-bit IO_support flag", io32bit);
     1528        ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit);
     1529    }
     1530    if (set_mult) {
    16721531        print_flag(get_mult, "multcount", mult);
    16731532#ifdef HDIO_DRIVE_CMD
    1674         bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT");
     1533        ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult);
    16751534#else
    1676         force_operation |= (!bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT"));
    1677 #endif
    1678     }
    1679     if (set_readonly)
    1680     {
    1681         print_flag_on_off(get_readonly,"readonly", readonly);
    1682         bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET");
    1683     }
    1684     if (set_unmask)
    1685     {
    1686         print_flag_on_off(get_unmask,"unmaskirq", unmask);
    1687         bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
    1688     }
    1689 #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
    1690     if (set_dma)
    1691     {
     1535        force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult));
     1536#endif
     1537    }
     1538    if (set_readonly) {
     1539        print_flag_on_off(get_readonly, "readonly", readonly);
     1540        ioctl_or_warn(fd, BLKROSET, &readonly);
     1541    }
     1542    if (set_unmask) {
     1543        print_flag_on_off(get_unmask, "unmaskirq", unmask);
     1544        ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask);
     1545    }
     1546#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
     1547    if (set_dma) {
    16921548        print_flag_on_off(get_dma, "using_dma", dma);
    1693         bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
    1694     }
    1695 #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
    1696     if (set_dma_q)
    1697     {
    1698         print_flag_on_off(get_dma_q,"DMA queue_depth", dma_q);
    1699         bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
    1700     }
    1701     if (set_nowerr)
    1702     {
    1703         print_flag_on_off(get_nowerr,"nowerr", nowerr);
    1704         bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
    1705     }
    1706     if (set_keep)
    1707     {
    1708         print_flag_on_off(get_keep,"keep_settings", keep);
    1709         bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
     1549        ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma);
     1550    }
     1551#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */
     1552    if (set_dma_q) {
     1553        print_flag_on_off(get_dma_q, "DMA queue_depth", dma_q);
     1554        ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q);
     1555    }
     1556    if (set_nowerr) {
     1557        print_flag_on_off(get_nowerr, "nowerr", nowerr);
     1558        ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr);
     1559    }
     1560    if (set_keep) {
     1561        print_flag_on_off(get_keep, "keep_settings", keep);
     1562        ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep);
    17101563    }
    17111564#ifdef HDIO_DRIVE_CMD
    1712     if (set_doorlock)
    1713     {
     1565    if (set_doorlock) {
    17141566        args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
    17151567        args[2] = 0;
    1716         print_flag_on_off(get_doorlock,"drive doorlock", doorlock);
    1717         bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
     1568        print_flag_on_off(get_doorlock, "drive doorlock", doorlock);
     1569        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    17181570        args[0] = WIN_SETFEATURES;
    17191571    }
    1720     if (set_dkeep)
    1721     {
     1572    if (set_dkeep) {
    17221573        /* lock/unlock the drive's "feature" settings */
    1723         print_flag_on_off(get_dkeep,"drive keep features", dkeep);
     1574        print_flag_on_off(get_dkeep, "drive keep features", dkeep);
    17241575        args[2] = dkeep ? 0x66 : 0xcc;
    1725         bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
    1726     }
    1727     if (set_defects)
    1728     {
     1576        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
     1577    }
     1578    if (set_defects) {
    17291579        args[2] = defects ? 0x04 : 0x84;
    1730         print_flag(get_defects,"drive defect-mgmt", defects);
    1731         bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
    1732     }
    1733     if (set_prefetch)
    1734     {
     1580        print_flag(get_defects, "drive defect-mgmt", defects);
     1581        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
     1582    }
     1583    if (set_prefetch) {
    17351584        args[1] = prefetch;
    17361585        args[2] = 0xab;
    1737         print_flag(get_prefetch,"drive prefetch", prefetch);
    1738         bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
     1586        print_flag(get_prefetch, "drive prefetch", prefetch);
     1587        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    17391588        args[1] = 0;
    17401589    }
    1741     if (set_xfermode)
    1742     {
     1590    if (set_xfermode) {
    17431591        args[1] = xfermode_requested;
    17441592        args[2] = 3;
    1745         if (get_xfermode)
    1746         {
    1747             print_flag(1,"xfermode", xfermode_requested);
     1593        if (get_xfermode) {
     1594            print_flag(1, "xfermode", xfermode_requested);
    17481595            interpret_xfermode(xfermode_requested);
    17491596        }
    1750         bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)");
     1597        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    17511598        args[1] = 0;
    17521599    }
    1753     if (set_lookahead)
    1754     {
     1600    if (set_lookahead) {
    17551601        args[2] = lookahead ? 0xaa : 0x55;
    1756         print_flag_on_off(get_lookahead,"drive read-lookahead", lookahead);
    1757         bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
    1758     }
    1759     if (set_apmmode)
    1760     {
     1602        print_flag_on_off(get_lookahead, "drive read-lookahead", lookahead);
     1603        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
     1604    }
     1605    if (set_apmmode) {
    17611606        args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */
    17621607        args[1] = apmmode; /* sector count register 1-255 */
    17631608        if (get_apmmode)
    17641609            printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode);
    1765         bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD");
     1610        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    17661611        args[1] = 0;
    17671612    }
    1768     if (set_wcache)
    1769     {
     1613    if (set_wcache) {
    17701614#ifdef DO_FLUSHCACHE
    17711615#ifndef WIN_FLUSHCACHE
    17721616#define WIN_FLUSHCACHE 0xe7
    17731617#endif
    1774         static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
     1618        static unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
    17751619#endif /* DO_FLUSHCACHE */
    17761620        args[2] = wcache ? 0x02 : 0x82;
    1777         print_flag_on_off(get_wcache,"drive write-caching", wcache);
     1621        print_flag_on_off(get_wcache, "drive write-caching", wcache);
    17781622#ifdef DO_FLUSHCACHE
    17791623        if (!wcache)
    1780             bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
     1624            ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
    17811625#endif /* DO_FLUSHCACHE */
    1782         bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
     1626        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    17831627#ifdef DO_FLUSHCACHE
    17841628        if (!wcache)
    1785             bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
     1629            ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
    17861630#endif /* DO_FLUSHCACHE */
    17871631    }
     
    17911635    args[2] = 0;
    17921636
    1793     if (set_standbynow)
    1794     {
     1637    if (set_standbynow) {
    17951638#ifndef WIN_STANDBYNOW1
    17961639#define WIN_STANDBYNOW1 0xE0
     
    18011644        if (get_standbynow) printf(" issuing standby command\n");
    18021645        args[0] = WIN_STANDBYNOW1;
    1803         bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
    1804     }
    1805     if (set_sleepnow)
    1806     {
     1646        ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2);
     1647    }
     1648    if (set_sleepnow) {
    18071649#ifndef WIN_SLEEPNOW1
    18081650#define WIN_SLEEPNOW1 0xE6
     
    18131655        if (get_sleepnow) printf(" issuing sleep command\n");
    18141656        args[0] = WIN_SLEEPNOW1;
    1815         bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
    1816     }
    1817     if (set_seagate)
    1818     {
     1657        ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2);
     1658    }
     1659    if (set_seagate) {
    18191660        args[0] = 0xfb;
    18201661        if (get_seagate) printf(" disabling Seagate auto powersaving mode\n");
    1821         bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
    1822     }
    1823     if (set_standby)
    1824     {
     1662        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
     1663    }
     1664    if (set_standby) {
    18251665        args[0] = WIN_SETIDLE1;
    18261666        args[1] = standby_requested;
    1827         if (get_standby)
    1828         {
    1829             print_flag(1,"standby", standby_requested);
     1667        if (get_standby) {
     1668            print_flag(1, "standby", standby_requested);
    18301669            interpret_standby(standby_requested);
    18311670        }
    1832         bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)");
     1671        ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
    18331672        args[1] = 0;
    18341673    }
    18351674#else   /* HDIO_DRIVE_CMD */
    1836     if (force_operation)
    1837     {
     1675    if (force_operation) {
    18381676        char buf[512];
    18391677        flush_buffer_cache(fd);
     
    18431681#endif  /* HDIO_DRIVE_CMD */
    18441682
    1845     if (get_mult || get_identity)
    1846     {
     1683    if (get_mult || get_identity) {
    18471684        multcount = -1;
    1848         if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
    1849         {
    1850             if (get_mult)
     1685        if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) {
     1686            if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn. */
    18511687                bb_perror_msg("HDIO_GET_MULTCOUNT");
    1852         }
    1853         else if (get_mult)
    1854         {
     1688            else
     1689                bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT);
     1690        } else if (get_mult) {
    18551691            printf(fmt, "multcount", multcount);
    1856             on_off(multcount);
    1857         }
    1858     }
    1859     if (get_io32bit)
    1860     {
    1861         if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
    1862         {
     1692            on_off(multcount != 0);
     1693        }
     1694    }
     1695    if (get_io32bit) {
     1696        if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) {
    18631697            printf(" IO_support\t=%3ld (", parm);
    18641698            if (parm == 0)
     
    18761710        }
    18771711    }
    1878     if (get_unmask)
    1879     {
    1880         bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
    1881                         "HDIO_GET_UNMASKINTR","unmaskirq");
    1882     }
    1883 
    1884 
    1885 #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
     1712    if (get_unmask) {
     1713        if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, (unsigned long *)parm))
     1714            print_value_on_off("unmaskirq", parm);
     1715    }
     1716
     1717
     1718#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
    18861719    if (get_dma) {
    1887         if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
    1888         {
     1720        if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) {
    18891721            printf(fmt, "using_dma", parm);
    18901722            if (parm == 8)
    18911723                printf(" (DMA-Assisted-PIO)\n");
    18921724            else
    1893                 on_off(parm);
    1894         }
    1895     }
    1896 #endif
    1897     if (get_dma_q)
    1898     {
    1899         bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
    1900                           "HDIO_GET_QDMA","queue_depth");
    1901     }
    1902     if (get_keep)
    1903     {
    1904         bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
    1905                             "HDIO_GET_KEEPSETTINGS","keepsettings");
    1906     }
    1907 
    1908     if (get_nowerr)
    1909     {
    1910         bb_ioctl_on_off  (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
    1911                             "HDIO_GET_NOWERR","nowerr");
    1912     }
    1913     if (get_readonly)
    1914     {
    1915         bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
    1916                           "BLKROGET","readonly");
    1917     }
    1918     if (get_readahead)
    1919     {
    1920         bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
    1921                             "BLKRAGET","readahead");
    1922     }
    1923     if (get_geom)
    1924     {
    1925         if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
    1926         {
     1725                on_off(parm != 0);
     1726        }
     1727    }
     1728#endif
     1729    if (get_dma_q) {
     1730        if(!ioctl_or_warn(fd, HDIO_GET_QDMA, (unsigned long *)parm))
     1731            print_value_on_off("queue_depth", parm);
     1732    }
     1733    if (get_keep) {
     1734        if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, (unsigned long *)parm))
     1735            print_value_on_off("keepsettings", parm);
     1736    }
     1737
     1738    if (get_nowerr) {
     1739        if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, (unsigned long *)parm))
     1740            print_value_on_off("nowerr", parm);
     1741    }
     1742    if (get_readonly) {
     1743        if(!ioctl_or_warn(fd, BLKROGET, (unsigned long *)parm))
     1744            print_value_on_off("readonly", parm);
     1745    }
     1746    if (get_readahead) {
     1747        if(!ioctl_or_warn(fd, BLKRAGET, (unsigned long *)parm))
     1748            print_value_on_off("readahead", parm);
     1749    }
     1750    if (get_geom) {
     1751        if (!ioctl_or_warn(fd, BLKGETSIZE, &parm)) {
    19271752            struct hd_geometry g;
    19281753
    1929             if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
     1754            if (!ioctl_or_warn(fd, HDIO_GETGEO, &g))
    19301755                printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
    19311756                        g.cylinders, g.heads, g.sectors, parm, g.start);
     
    19331758    }
    19341759#ifdef HDIO_DRIVE_CMD
    1935     if (get_powermode)
    1936     {
     1760    if (get_powermode) {
    19371761#ifndef WIN_CHECKPOWERMODE1
    19381762#define WIN_CHECKPOWERMODE1 0xE5
     
    19441768
    19451769        args[0] = WIN_CHECKPOWERMODE1;
    1946         if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
    1947         {
     1770        if (ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2)) {
    19481771            if (errno != EIO || args[0] != 0 || args[1] != 0)
    1949                 state = "Unknown";
     1772                state = "unknown";
    19501773            else
    19511774                state = "sleeping";
    1952         }
    1953         else
     1775        } else
    19541776            state = (args[2] == 255) ? "active/idle" : "standby";
    19551777        args[1] = args[2] = 0;
     
    19581780    }
    19591781#endif
    1960 #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
    1961     if (perform_reset)
    1962     {
    1963         bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
    1964     }
    1965 #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
    1966 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
    1967     if (perform_tristate)
    1968     {
     1782#if ENABLE_FEATURE_HDPARM_HDIO_DRIVE_RESET
     1783    if (perform_reset) {
     1784        ioctl_or_warn(fd, HDIO_DRIVE_RESET, NULL);
     1785    }
     1786#endif /* FEATURE_HDPARM_HDIO_DRIVE_RESET */
     1787#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
     1788    if (perform_tristate) {
    19691789        args[0] = 0;
    19701790        args[1] = tristate;
    1971         bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
    1972     }
    1973 #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
    1974 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
    1975     if (get_identity)
    1976     {
    1977         static struct hd_driveid id;
    1978 
    1979         if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
    1980         {
    1981             if (multcount != -1)
    1982             {
     1791        ioctl_or_warn(fd, HDIO_TRISTATE_HWIF, &args);
     1792    }
     1793#endif /* FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
     1794#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
     1795    if (get_identity) {
     1796        struct hd_driveid id;
     1797
     1798        if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) {
     1799            if (multcount != -1) {
    19831800                id.multsect = multcount;
    19841801                id.multsect_valid |= 1;
    1985             }
    1986             else
     1802            } else
    19871803                id.multsect_valid &= ~1;
    19881804            dump_identity(&id);
    1989         }
    1990         else if (errno == -ENOMSG)
     1805        } else if (errno == -ENOMSG)
    19911806            printf(" no identification info available\n");
     1807        else if (ENABLE_IOCTL_HEX2STR_ERROR)  /* To be coherent with ioctl_or_warn */
     1808            bb_perror_msg("HDIO_GET_IDENTITY");
    19921809        else
    1993             bb_perror_msg("HDIO_GET_IDENTITY");
    1994     }
    1995 
    1996     if (get_IDentity)
    1997     {
     1810            bb_perror_msg("ioctl %#x failed", HDIO_GET_IDENTITY);
     1811    }
     1812
     1813    if (get_IDentity) {
    19981814        unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
    19991815
     
    20011817        args1[0] = WIN_IDENTIFY;
    20021818        args1[3] = 1;
    2003         if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)"))
     1819        if (!ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY))
    20041820            identify((void *)(args1 + 4));
    20051821    }
    20061822#endif
    2007 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
    2008     if (set_busstate)
    2009     {
    2010         if (get_busstate)
    2011         {
     1823#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
     1824    if (set_busstate) {
     1825        if (get_busstate) {
    20121826            print_flag(1, "bus state", busstate);
    20131827            bus_state_value(busstate);
    20141828        }
    2015         bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE");
    2016     }
    2017     if (get_busstate)
    2018     {
    2019         if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
    2020         {
     1829        ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate);
     1830    }
     1831    if (get_busstate) {
     1832        if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) {
    20211833            printf(fmt, "bus state", parm);
    20221834            bus_state_value(parm);
     
    20251837#endif
    20261838    if (reread_partn)
    2027         bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART");
    2028 
     1839        ioctl_or_warn(fd, BLKRRPART, NULL);
    20291840
    20301841    if (do_ctimings)
    2031         do_time(0,fd);      /*time cache */
     1842        do_time(0, fd); /* time cache */
    20321843    if (do_timings)
    2033         do_time(1,fd);      /*time device */
     1844        do_time(1, fd); /* time device */
    20341845    if (do_flush)
    20351846        flush_buffer_cache(fd);
     
    20371848}
    20381849
    2039 #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
     1850#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
    20401851static int fromhex(unsigned char c)
    20411852{
     1853    if (isdigit(c))
     1854        return (c - '0');
    20421855    if (c >= 'a' && c <= 'f')
    2043         return 10 + (c - 'a');
    2044     if (c >= '0' && c <= '9')
    2045         return (c - '0');
     1856        return (c - ('a' - 10));
    20461857    bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
    20471858}
     
    20501861{
    20511862    uint16_t sbuf[256];
    2052     unsigned char  buf[1280], *b = (unsigned char *)buf;
    2053     int i, count = read(0, buf, 1280);
    2054 
    2055     if (count != 1280)
    2056         bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count);
     1863    unsigned char buf[1280];
     1864    unsigned char *b = (unsigned char *)buf;
     1865    int i;
     1866
     1867    xread(0, buf, 1280);
    20571868
    20581869    // Convert the newline-separated hex data into an identify block.
    20591870
    2060     for (i = 0; i<256; i++)
    2061     {
     1871    for (i = 0; i < 256; i++) {
    20621872        int j;
    2063         for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++));
     1873        for (j = 0; j < 4; j++)
     1874            sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++));
    20641875    }
    20651876
     
    20711882
    20721883/* busybox specific stuff */
    2073 static void parse_opts(unsigned long *get, unsigned long *set, unsigned long *value, int min, int max)
    2074 {
    2075         if (get) {
    2076             *get = 1;
    2077         }
    2078         if (optarg) {
    2079             *set = 1;
    2080             *value = bb_xgetlarg(optarg, 10, min, max);
    2081         }
    2082 }
    2083 
    2084 static void parse_xfermode(int flag, unsigned long *get, unsigned long *set, int *value)
     1884static void parse_opts(smallint *get, smallint *set, unsigned long *value, int min, int max)
     1885{
     1886    if (get) {
     1887        *get = 1;
     1888    }
     1889    if (optarg) {
     1890        *set = 1;
     1891        *value = xatol_range(optarg, min, max);
     1892    }
     1893}
     1894
     1895static void parse_xfermode(int flag, smallint *get, smallint *set, int *value)
    20851896{
    20861897    if (flag) {
    20871898        *get = 1;
    20881899        if (optarg) {
    2089             *set = ((*value = translate_xfermode(optarg)) > -1);
     1900            *value = translate_xfermode(optarg);
     1901            *set = (*value > -1);
    20901902        }
    20911903    }
     
    20931905
    20941906/*------- getopt short options --------*/
    2095 static const char hdparm_options[]= "gfu::n::p:r::m::c::k::a::B:tTh"\
     1907static const char hdparm_options[] ALIGN1 =
     1908    "gfu::n::p:r::m::c::k::a::B:tTh"
    20961909    USE_FEATURE_HDPARM_GET_IDENTITY("iI")
    20971910    USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
    20981911#ifdef HDIO_DRIVE_CMD
    2099                                     "S:D:P:X:K:A:L:W:CyYzZ"
     1912    "S:D:P:X:K:A:L:W:CyYzZ"
    21001913#endif
    21011914    USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:")
    21021915#ifdef HDIO_GET_QDMA
    21031916#ifdef HDIO_SET_QDMA
    2104                                     "Q:"
     1917    "Q:"
    21051918#else
    2106                                     "Q"
     1919    "Q"
    21071920#endif
    21081921#endif
     
    21131926
    21141927/* our main() routine: */
    2115 int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;
     1928int hdparm_main(int argc, char **argv);
    21161929int hdparm_main(int argc, char **argv)
    21171930{
     
    21291942        USE_FEATURE_HDPARM_HDIO_GETSET_DMA(if (c == 'd') parse_opts(&get_dma, &set_dma, &dma, 0, 9));
    21301943        if (c == 'n') parse_opts(&get_nowerr, &set_nowerr, &nowerr, 0, 1);
    2131         parse_xfermode((c == 'p'),&noisy_piomode, &set_piomode, &piomode);
     1944        parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode);
    21321945        if (c == 'r') parse_opts(&get_readonly, &set_readonly, &readonly, 0, 1);
    21331946        if (c == 'm') parse_opts(&get_mult, &set_mult, &mult, 0, INT_MAX /*32*/);
     
    21391952        do_flush |= do_ctimings |= (c == 'T');
    21401953#ifdef HDIO_DRIVE_CMD
    2141         if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX);   
     1954        if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX);
    21421955        if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX);
    21431956        if (c == 'P') parse_opts(&get_prefetch, &set_prefetch, &prefetch, 0, INT_MAX);
     
    21531966        get_seagate = set_seagate |= (c == 'Z');
    21541967#endif
    2155         USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX));   
     1968        USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX));
    21561969#ifdef HDIO_GET_QDMA
    21571970        if (c == 'Q') {
     
    21591972            parse_opts(&get_dma_q, &set_dma_q, &dma_q, 0, INT_MAX);
    21601973#else
    2161             parse_opts(&get_dma_q, NULL, NULL, 0, 0);   
    2162 #endif
    2163         }
    2164 #endif     
     1974            parse_opts(&get_dma_q, NULL, NULL, 0, 0);
     1975#endif
     1976        }
     1977#endif
    21651978        USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r'));
    2166         USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1)); 
    2167         USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2)); 
     1979        USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1));
     1980        USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2));
    21681981#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
    21691982        if (c == 'R') {
    2170             parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);   
    2171             hwif_ctrl =  bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX);
    2172             hwif_irq  =  bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX);
     1983            parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);
     1984            hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : "");
     1985            hwif_irq  = xatoi_u((argv[optind+1]) ? argv[optind+1] : "");
    21731986            /* Move past the 2 additional arguments */
    21741987            argv += 2;
     
    21781991    }
    21791992    /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
    2180     if (!flagcount){
     1993    if (!flagcount) {
    21811994        get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1;
    21821995        USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1);
    21831996    }
    2184     argc -= optind;
    21851997    argv += optind;
    21861998
    2187     if (argc < 1) {
     1999    if (!*argv) {
    21882000        if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO))
    21892001            identify_from_stdin(); /* EXIT */
     
    21912003    }
    21922004
    2193     while (argc--) {
    2194         process_dev(*argv);
    2195         argv++;
    2196     }
    2197     exit(EXIT_SUCCESS);
    2198 }
     2005    do {
     2006        process_dev(*argv++);
     2007    } while (*argv);
     2008
     2009    return EXIT_SUCCESS;
     2010}
Note: See TracChangeset for help on using the changeset viewer.