*/
#include "busybox.h"
-#include <string.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
-#include <sys/times.h>
-#include <sys/mount.h>
-#include <sys/mman.h>
-#include <linux/types.h>
#include <linux/hdreg.h>
-#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
-# define __USE_XOPEN
-#endif
-#include <unistd.h>
-
/* device types */
/* ------------ */
#define NO_DEV 0xffff
static void identify(uint16_t *id_supplied) ATTRIBUTE_NORETURN;
static void identify_from_stdin(void) ATTRIBUTE_NORETURN;
-
+#else
+void identify_from_stdin(void);
#endif
static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg)
{
-
- if (get_arg)
- {
+ if (get_arg) {
printf(" setting %s to %ld", s, arg);
on_off(arg);
}
{
if (ioctl(fd, request, &argp) != 0)
bb_perror_msg(" %s", string);
- else
- {
+ else {
printf(" %s\t= %2ld", str, (unsigned long) argp);
on_off((unsigned long) argp);
}
#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
static void print_ascii(uint16_t *p, uint8_t length);
-static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
+static void xprint_ascii(uint16_t *val ,int i, const char *string, int n)
{
- if (val[i])
- {
- printf("\t%-20s",string);
+ if (val[i]) {
+ printf("\t%-20s", string);
print_ascii(&val[i], n);
}
}
#endif
-/* end of busybox specific stuff */
+/* end of busybox specific stuff */
#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
p++;
}
- printf("\n");
+ puts("");
}
// Parse 512 byte disk identification block and print much crap.
chksum &= 0xff;
/* check if we recognise the device type */
- printf("\n");
- if(!(val[GEN_CONFIG] & NOT_ATA))
+ puts("");
+ if (!(val[GEN_CONFIG] & NOT_ATA))
{
dev = ATA_DEV;
printf("ATA device, with ");
}
- else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
+ else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL)
{
dev = ATA_DEV;
like_std = 4;
printf("CompactFlash ATA device, with ");
}
- else if(!(val[GEN_CONFIG] & NOT_ATAPI))
+ else if (!(val[GEN_CONFIG] & NOT_ATAPI))
{
dev = ATAPI_DEV;
eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
}
else
/*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
- bb_error_msg_and_die("Unknown device type");
+ bb_error_msg_and_die("unknown device type");
printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
/* Info from the specific configuration word says whether or not the
(val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
{
like_std = 5;
- if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
+ if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
printf("powers-up in standby; SET FEATURES subcmd spins-up.\n");
- if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
+ if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
printf("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
}
{
if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
{
- if(like_std < 3) like_std = 3;
+ if (like_std < 3) like_std = 3;
std = actual_ver[val[MINOR]];
- if(std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
+ if (std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
}
/* looks like when they up-issue the std, they obsolete one;
like_std = ii;
kk = like_std >4 ? like_std-4: 0;
}
- if(min_std > ii) min_std = ii;
+ if (min_std > ii) min_std = ii;
}
jj <<= 1;
}
- if(like_std < 3) like_std = 3;
+ if (like_std < 3) like_std = 3;
}
/* Figure out what standard the device is using if it hasn't told
* us. If we know the std, check if the device is using any of
* the words from the next level up. It happens.
*/
- if(like_std < std) like_std = std;
+ if (like_std < std) like_std = std;
if (((std == 5) || (!std && (like_std < 6))) &&
((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
else if (like_std > std)
printf("& some of %u\n",like_std);
else
- printf("\n");
+ puts("");
}
else
{
jj = val[CDR_MAJOR] >> 1;
for (ii = 1; ii <15; ii++)
{
- if(jj & 0x0001) printf("-%u ", ii);
+ if (jj & 0x0001) printf("-%u ", ii);
jj >>= 1;
}
}
jj = val[GEN_CONFIG] >> 1;
for (ii = 1; ii < 15; ii++)
{
- if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
+ if (jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
jj >>=1;
}
}
strng = "<=10ms with INTRQ";
else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL)
strng ="50us";
- else
+ else
strng = "Unknown";
printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */
if (bbbig > 1000)
printf("(%"PRIu64" GB)\n", bbbig/1000);
- else
- printf("\n");
+ else
+ puts("");
}
/* hw support of commands (capabilities) */
if (like_std != 1)
{
- printf("IORDY%s(can%s be disabled)\n",
- !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
+ printf("IORDY%s(can%s be disabled)\n",
+ !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
(val[CAPAB_0] & IORDY_OFF) ? "" :"not");
}
else
if ((like_std == 1) && val[BUF_TYPE])
{
printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
- (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
+ (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
(val[BUF_TYPE] > 2) ? " with read caching ability" : "");
}
if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
else
- printf("\n");
+ puts("");
}
printf("\tR/W multiple sector transfer: ");
if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
printf("\tOverlap support:");
if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]);
if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
- printf("\n");
+ puts("");
}
}
err_dma += mode_loop(jj,kk,'u',&have_mode);
}
if (err_dma || !have_mode) printf("(?)");
- printf("\n");
+ puts("");
if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
printf("\t\tInterleaved DMA support\n");
printf("\t\tCycle time:");
if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]);
if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]);
- printf("\n");
+ puts("");
}
}
if (jj & 0x0001) printf("pio%d ",ii);
jj >>=1;
}
- printf("\n");
+ puts("");
}
else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
{
for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
printf("pio%d ",ii);
- printf("\n");
+ puts("");
}
else
printf("unknown\n");
printf("\t\tCycle time:");
if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]);
if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]);
- printf("\n");
+ puts("");
}
}
}
}
/* Removable Media Status Notification feature set */
- if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
+ if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
printf("\t%s supported\n", cmd_feat_str[27]);
printf("\t");
if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
- printf("\n");
+ puts("");
}
}
strng = " determined by the jumper";
else if ((jj & DEV_DET) == CSEL_VAL)
strng = " determined by CSEL";
- else
+ else
strng = "";
- printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n",
+ printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n",
(val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng);
}
else
printf("off");
}
- printf("\n");
+ puts("");
- if(!(id->field_valid&1))
+ if (!(id->field_valid&1))
printf(" (maybe):");
printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
- id->cur_sectors,
- (BB_BIG_ENDIAN) ?
+ id->cur_sectors,
+ (BB_BIG_ENDIAN) ?
(long unsigned int)(id->cur_capacity0 << 16) | id->cur_capacity1 :
(long unsigned int)(id->cur_capacity1 << 16) | id->cur_capacity0,
((id->capability&2) == 0) ? "no" : "yes");
if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&2)
printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
-
+
if ((id->capability&1) && (id->field_valid&2))
printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
}
}
if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&4)
- {
+ {
printf("\n UDMA modes: ");
if (id->dma_ultra & 0x100) printf("*");
if (id->dma_ultra & 0x001) printf("udma0 ");
if (read_big_block (fd, buf)) return;
printf(" Timing cached reads: ");
fflush(stdout);
-
+
/* Now do the timing */
iterations = 0;
getitimer(ITIMER_REAL, &e1);
elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec)
+ ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
} while (--iterations);
-
+
elapsed -= elapsed2;
- print_timing(BUFCACHE_FACTOR * total_MB, elapsed);
+ print_timing(BUFCACHE_FACTOR * total_MB, elapsed);
flush_buffer_cache(fd);
sleep(1);
}
elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec)
+ ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
} while (elapsed < 3.0 && iterations < max_iterations);
-
+
total_MB = iterations * TIMING_BUF_MB;
print_timing(total_MB, elapsed);
}
{
unsigned int t;
-
+ printf(" (");
if (standby == 0)
printf("off");
else if (standby == 252)
}
#endif /* HDIO_DRIVE_CMD */
-static void print_flag(unsigned long flag, char *s, unsigned long value)
+static void print_flag(unsigned long flag, const char *s, unsigned long value)
{
- if(flag)
+ if (flag)
printf(" setting %s to %ld\n", s, value);
}
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
const char *fmt = " %s\t= %2ld";
- fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
+ fd = xopen(devname, O_RDONLY|O_NONBLOCK);
printf("\n%s:\n", devname);
if (set_readahead)
#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
static int fromhex(unsigned char c)
{
- if (c >= 'a' && c <= 'f')
- return 10 + (c - 'a');
- if (c >= '0' && c <= '9')
+ if (isdigit(c))
return (c - '0');
+ if (c >= 'a' && c <= 'f')
+ return (c - ('a' - 10));
bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
}
static void identify_from_stdin(void)
{
uint16_t sbuf[256];
- unsigned char buf[1280], *b = (unsigned char *)buf;
- int i, count = read(0, buf, 1280);
+ unsigned char buf[1280];
+ unsigned char *b = (unsigned char *)buf;
+ int i;
- if (count != 1280)
- bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count);
+ xread(0, buf, 1280);
// Convert the newline-separated hex data into an identify block.
- for (i = 0; i<256; i++)
- {
+ for (i = 0; i<256; i++) {
int j;
- for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++));
+ for (j = 0; j < 4; j++)
+ sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++));
}
// Parse the data.
/* busybox specific stuff */
static void parse_opts(unsigned long *get, unsigned long *set, unsigned long *value, int min, int max)
{
- if (get) {
- *get = 1;
- }
- if (optarg) {
- *set = 1;
- *value = bb_xgetlarg(optarg, 10, min, max);
- }
+ if (get) {
+ *get = 1;
+ }
+ if (optarg) {
+ *set = 1;
+ *value = xatol_range(optarg, min, max);
+ }
}
static void parse_xfermode(int flag, unsigned long *get, unsigned long *set, int *value)
}
/*------- getopt short options --------*/
-static const char hdparm_options[]= "gfu::n::p:r::m::c::k::a::B:tTh"\
+static const char hdparm_options[] = "gfu::n::p:r::m::c::k::a::B:tTh"
USE_FEATURE_HDPARM_GET_IDENTITY("iI")
USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
#ifdef HDIO_DRIVE_CMD
- "S::D::P::X::K::A::L::W::CyYzZ"
+ "S:D:P:X:K:A:L:W:CyYzZ"
#endif
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:")
#ifdef HDIO_GET_QDMA
#ifdef HDIO_SET_QDMA
- "Q:"
+ "Q:"
#else
- "Q"
+ "Q"
#endif
#endif
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET("w")
/*-------------------------------------*/
/* our main() routine: */
+int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;;
int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;
+int hdparm_main(int argc, char **argv);
int hdparm_main(int argc, char **argv)
{
int c;
do_flush |= do_timings |= (c == 't');
do_flush |= do_ctimings |= (c == 'T');
#ifdef HDIO_DRIVE_CMD
- if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX);
+ if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX);
if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX);
if (c == 'P') parse_opts(&get_prefetch, &set_prefetch, &prefetch, 0, INT_MAX);
parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested);
reread_partn |= (c == 'z');
get_seagate = set_seagate |= (c == 'Z');
#endif
- USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX));
+ USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX));
#ifdef HDIO_GET_QDMA
if (c == 'Q') {
#ifdef HDIO_SET_QDMA
parse_opts(&get_dma_q, &set_dma_q, &dma_q, 0, INT_MAX);
#else
- parse_opts(&get_dma_q, NULL, NULL, 0, 0);
+ parse_opts(&get_dma_q, NULL, NULL, 0, 0);
#endif
}
-#endif
+#endif
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r'));
- USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1));
- USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2));
+ USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1));
+ USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2));
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
if (c == 'R') {
- parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);
- hwif_ctrl = bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX);
- hwif_irq = bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX);
+ parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);
+ hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : "");
+ hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : "");
/* Move past the 2 additional arguments */
argv += 2;
argc -= 2;
#endif
}
/* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
- if (!flagcount){
+ if (!flagcount) {
get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1;
USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1);
}