From Dennis Vlasenko, Make hdparm smaller:

* Use combined no_scsi_no_xt()
 * Have common unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
This commit is contained in:
Rob Landley 2006-04-29 15:49:18 +00:00
parent 2e2d752d49
commit e5b281f89e

View File

@ -1652,6 +1652,12 @@ static void no_xt (void)
bb_error_msg_and_die(bb_msg_op_not_supp,"XT"); bb_error_msg_and_die(bb_msg_op_not_supp,"XT");
} }
static void no_scsi_no_xt (void)
{
no_scsi();
no_xt();
}
static void on_off (unsigned int value) static void on_off (unsigned int value)
{ {
printf(value ? " (on)\n" : " (off)\n"); printf(value ? " (on)\n" : " (off)\n");
@ -1864,6 +1870,8 @@ static void process_dev (char *devname)
#ifndef HDIO_DRIVE_CMD #ifndef HDIO_DRIVE_CMD
int force_operation = 0; int force_operation = 0;
#endif #endif
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
xstat(devname,&stat_buf); xstat(devname,&stat_buf);
switch(major(stat_buf.st_rdev)) switch(major(stat_buf.st_rdev))
@ -1945,7 +1953,6 @@ static void process_dev (char *devname)
#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
if (scan_hwif) if (scan_hwif)
{ {
int args[3];
no_scsi(); no_scsi();
printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq); printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq);
args[0] = hwif_data; args[0] = hwif_data;
@ -1956,8 +1963,7 @@ static void process_dev (char *devname)
#endif #endif
if (set_piomode) if (set_piomode)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if (noisy_piomode) if (noisy_piomode)
{ {
@ -1975,15 +1981,13 @@ static void process_dev (char *devname)
} }
if (set_io32bit) if (set_io32bit)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit); if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit);
bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
} }
if (set_mult) if (set_mult)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf(get_mult, " setting multcount to %ld\n", mult); if_printf(get_mult, " setting multcount to %ld\n", mult);
if(ioctl(fd, HDIO_SET_MULTCOUNT, mult)) if(ioctl(fd, HDIO_SET_MULTCOUNT, mult))
bb_perror_msg("HDIO_SET_MULTCOUNT"); bb_perror_msg("HDIO_SET_MULTCOUNT");
@ -1999,8 +2003,7 @@ static void process_dev (char *devname)
} }
if (set_unmask) if (set_unmask)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask); if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask);
bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
} }
@ -2020,25 +2023,20 @@ static void process_dev (char *devname)
} }
if (set_nowerr) if (set_nowerr)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr); if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr);
bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR"); bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
} }
if (set_keep) if (set_keep)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf_on_off(get_keep," setting keep_settings to %ld", keep); if_printf_on_off(get_keep," setting keep_settings to %ld", keep);
bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS"); bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
} }
#ifdef HDIO_DRIVE_CMD #ifdef HDIO_DRIVE_CMD
if (set_doorlock) if (set_doorlock)
{ {
unsigned char args[4] = {0,0,0,0}; no_scsi_no_xt();
no_scsi();
no_xt();
args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock); if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock);
bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
@ -2046,17 +2044,13 @@ static void process_dev (char *devname)
if (set_dkeep) if (set_dkeep)
{ {
/* lock/unlock the drive's "feature" settings */ /* lock/unlock the drive's "feature" settings */
unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; no_scsi_no_xt();
no_scsi();
no_xt();
if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep); if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep);
args[2] = dkeep ? 0x66 : 0xcc; args[2] = dkeep ? 0x66 : 0xcc;
bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
} }
if (set_defects) if (set_defects)
{ {
unsigned char args[4] = {WIN_SETFEATURES,0,0x04,0};
no_scsi(); no_scsi();
args[2] = defects ? 0x04 : 0x84; args[2] = defects ? 0x04 : 0x84;
if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects); if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects);
@ -2064,21 +2058,17 @@ static void process_dev (char *devname)
} }
if (set_prefetch) if (set_prefetch)
{ {
unsigned char args[4] = {WIN_SETFEATURES,0,0xab,0}; no_scsi_no_xt();
no_scsi();
no_xt();
args[1] = prefetch; args[1] = prefetch;
args[2] = 0xab;
if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch); if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch);
bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
} }
if (set_xfermode) if (set_xfermode)
{ {
unsigned char args[4] = {WIN_SETFEATURES,0,3,0}; no_scsi_no_xt();
no_scsi();
no_xt();
args[1] = xfermode_requested; args[1] = xfermode_requested;
args[2] = 3;
if (get_xfermode) if (get_xfermode)
{ {
printf(" setting xfermode to %d", xfermode_requested); printf(" setting xfermode to %d", xfermode_requested);
@ -2088,17 +2078,13 @@ static void process_dev (char *devname)
} }
if (set_lookahead) if (set_lookahead)
{ {
unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; no_scsi_no_xt();
no_scsi();
no_xt();
args[2] = lookahead ? 0xaa : 0x55; args[2] = lookahead ? 0xaa : 0x55;
if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead); if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead);
bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
} }
if (set_apmmode) if (set_apmmode)
{ {
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
no_scsi(); no_scsi();
apmmode=check_if_min_and_set_val(apmmode,1); apmmode=check_if_min_and_set_val(apmmode,1);
apmmode=check_if_maj_and_set_val(apmmode,255); apmmode=check_if_maj_and_set_val(apmmode,255);
@ -2124,11 +2110,9 @@ static void process_dev (char *devname)
#ifndef WIN_FLUSHCACHE #ifndef WIN_FLUSHCACHE
#define WIN_FLUSHCACHE 0xe7 #define WIN_FLUSHCACHE 0xe7
#endif #endif
unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
#endif /* DO_FLUSHCACHE */ #endif /* DO_FLUSHCACHE */
unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; no_scsi_no_xt();
no_scsi();
no_xt();
args[2] = wcache ? 0x02 : 0x82; args[2] = wcache ? 0x02 : 0x82;
if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
#ifdef DO_FLUSHCACHE #ifdef DO_FLUSHCACHE
@ -2149,8 +2133,8 @@ static void process_dev (char *devname)
#ifndef WIN_STANDBYNOW2 #ifndef WIN_STANDBYNOW2
#define WIN_STANDBYNOW2 0x94 #define WIN_STANDBYNOW2 0x94
#endif #endif
unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0}; static unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0};
unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0}; static unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0};
no_scsi(); no_scsi();
if_printf(get_standbynow," issuing standby command\n"); if_printf(get_standbynow," issuing standby command\n");
if (ioctl(fd, HDIO_DRIVE_CMD, &args1) if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
@ -2165,8 +2149,8 @@ static void process_dev (char *devname)
#ifndef WIN_SLEEPNOW2 #ifndef WIN_SLEEPNOW2
#define WIN_SLEEPNOW2 0x99 #define WIN_SLEEPNOW2 0x99
#endif #endif
unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0}; static unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0};
unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0}; static unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0};
no_scsi(); no_scsi();
if_printf(get_sleepnow," issuing sleep command\n"); if_printf(get_sleepnow," issuing sleep command\n");
if (ioctl(fd, HDIO_DRIVE_CMD, &args1) if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
@ -2175,17 +2159,16 @@ static void process_dev (char *devname)
} }
if (set_seagate) if (set_seagate)
{ {
unsigned char args[4] = {0xfb,0,0,0}; args[0] = 0xfb;
no_scsi(); no_scsi_no_xt();
no_xt();
if_printf(get_seagate," disabling Seagate auto powersaving mode\n"); if_printf(get_seagate," disabling Seagate auto powersaving mode\n");
bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
} }
if (set_standby) if (set_standby)
{ {
unsigned char args[4] = {WIN_SETIDLE1,standby_requested,0,0}; args[0] = WIN_SETIDLE1;
no_scsi(); args[1] = standby_requested;
no_xt(); no_scsi_no_xt();
if (get_standby) if (get_standby)
{ {
printf(" setting standby to %lu", standby_requested); printf(" setting standby to %lu", standby_requested);
@ -2223,8 +2206,7 @@ static void process_dev (char *devname)
} }
if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit) if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
if(ioctl(fd, HDIO_GET_32BIT, &parm)) if(ioctl(fd, HDIO_GET_32BIT, &parm))
bb_perror_msg("HDIO_GET_32BIT"); bb_perror_msg("HDIO_GET_32BIT");
else else
@ -2254,8 +2236,7 @@ static void process_dev (char *devname)
} }
if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask) if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm, bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
"HDIO_GET_UNMASKINTR"," unmaskirq = %2ld"); "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld");
} }
@ -2284,16 +2265,14 @@ static void process_dev (char *devname)
} }
if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep) if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm, bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
"HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld"); "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld");
} }
if (get_nowerr) if (get_nowerr)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm, bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
" HDIO_GET_NOWERR"," nowerr = %2ld"); " HDIO_GET_NOWERR"," nowerr = %2ld");
} }
@ -2335,9 +2314,9 @@ static void process_dev (char *devname)
#ifndef WIN_CHECKPOWERMODE2 #ifndef WIN_CHECKPOWERMODE2
#define WIN_CHECKPOWERMODE2 0x98 #define WIN_CHECKPOWERMODE2 0x98
#endif #endif
unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0};
const char *state; const char *state;
no_scsi(); no_scsi();
args[0] = WIN_CHECKPOWERMODE1;
if (ioctl(fd, HDIO_DRIVE_CMD, &args) if (ioctl(fd, HDIO_DRIVE_CMD, &args)
&& (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */ && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
&& ioctl(fd, HDIO_DRIVE_CMD, &args)) && ioctl(fd, HDIO_DRIVE_CMD, &args))
@ -2356,17 +2335,16 @@ static void process_dev (char *devname)
#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
if (perform_reset) if (perform_reset)
{ {
no_scsi(); no_scsi_no_xt();
no_xt();
bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET"); bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
} }
#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
if (perform_tristate) if (perform_tristate)
{ {
unsigned char args[4] = {0,tristate,0,0}; args[0] = 0;
no_scsi(); args[1] = tristate;
no_xt(); no_scsi_no_xt();
bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF"); bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
} }
#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
@ -2375,8 +2353,7 @@ static void process_dev (char *devname)
{ {
static struct hd_driveid id; static struct hd_driveid id;
no_scsi(); no_scsi_no_xt();
no_xt();
if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
{ {
@ -2397,25 +2374,24 @@ static void process_dev (char *devname)
if (get_IDentity) if (get_IDentity)
{ {
unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,}; unsigned char args1[4+512] = {WIN_IDENTIFY,0,0,1,};
unsigned i; unsigned i;
no_scsi(); no_scsi_no_xt();
no_xt();
if (ioctl(fd, HDIO_DRIVE_CMD, &args)) if (ioctl(fd, HDIO_DRIVE_CMD, &args1))
{ {
args[0] = WIN_PIDENTIFY; args[0] = WIN_PIDENTIFY;
if (ioctl(fd, HDIO_DRIVE_CMD, &args)) if (ioctl(fd, HDIO_DRIVE_CMD, &args1))
{ {
bb_perror_msg("HDIO_DRIVE_CMD(identify)"); bb_perror_msg("HDIO_DRIVE_CMD(identify)");
goto identify_abort; goto identify_abort;
} }
} }
for(i=0; i<(sizeof args)/2; i+=2) for(i=0; i<(sizeof args1)/2; i+=2)
__le16_to_cpus((uint16_t *)(&args[i])); __le16_to_cpus((uint16_t *)(&args1[i]));
identify((void *)&args[4], NULL); identify((void *)&args1[4], NULL);
identify_abort: identify_abort:
/* VOID */; /* VOID */;
} }