Another patch from Denis Vlasenko:

Make hdparm smaller:
* Make bb_ioctl return the status
* Replace ioctl with bb_ioctl in a few places
* Add bb_ioctl_alt, use where appropriate (four places)
* unsigned char args1[4+512] = {WIN_IDENTIFY,0,0,1,};
  ate 0.5k of rodata, fix that
This commit is contained in:
Rob Landley 2006-04-29 16:03:40 +00:00
parent e5b281f89e
commit 5f8b5ecda2

View File

@ -465,12 +465,23 @@ static const char * const secu_str[] = {
static const char bb_msg_shared_mem[] = "could not %s sharedmem buf"; static const char bb_msg_shared_mem[] = "could not %s sharedmem buf";
static const char bb_msg_op_not_supp[] = " operation not supported on %s disks"; static const char bb_msg_op_not_supp[] = " operation not supported on %s disks";
static void bb_ioctl(int fd, int request, void *argp, const char *string) static int bb_ioctl(int fd, int request, void *argp, const char *string)
{ {
if (ioctl (fd, request, argp) != 0) int e = ioctl(fd, request, argp);
if (e && string)
bb_perror_msg(" %s", string); bb_perror_msg(" %s", string);
return e;
} }
static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
{
if (!ioctl(fd, cmd, args))
return 0;
args[0] = alt;
return bb_ioctl(fd, cmd, args, string);
}
static void if_printf(unsigned long i, char *fmt, ... ) static void if_printf(unsigned long i, char *fmt, ... )
{ {
va_list ap; va_list ap;
@ -1454,7 +1465,7 @@ static void flush_buffer_cache (int fd)
#ifdef HDIO_DRIVE_CMD #ifdef HDIO_DRIVE_CMD
sleep(1); sleep(1);
if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
bb_perror_msg("HDIO_DRIVE_CMD"); bb_perror_msg("HDIO_DRIVE_CMD");
#endif #endif
} }
@ -2116,13 +2127,13 @@ static void process_dev (char *devname)
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
if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) if (!wcache)
bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
#endif /* DO_FLUSHCACHE */ #endif /* DO_FLUSHCACHE */
bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
#ifdef DO_FLUSHCACHE #ifdef DO_FLUSHCACHE
if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) if (!wcache)
bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
#endif /* DO_FLUSHCACHE */ #endif /* DO_FLUSHCACHE */
} }
if (set_standbynow) if (set_standbynow)
@ -2133,13 +2144,10 @@ static void process_dev (char *devname)
#ifndef WIN_STANDBYNOW2 #ifndef WIN_STANDBYNOW2
#define WIN_STANDBYNOW2 0x94 #define WIN_STANDBYNOW2 0x94
#endif #endif
static unsigned char args1[4] = {WIN_STANDBYNOW1,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) args[0] = WIN_STANDBYNOW1;
&& ioctl(fd, HDIO_DRIVE_CMD, &args2)) bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
bb_perror_msg("HDIO_DRIVE_CMD(standby)");
} }
if (set_sleepnow) if (set_sleepnow)
{ {
@ -2149,13 +2157,10 @@ static void process_dev (char *devname)
#ifndef WIN_SLEEPNOW2 #ifndef WIN_SLEEPNOW2
#define WIN_SLEEPNOW2 0x99 #define WIN_SLEEPNOW2 0x99
#endif #endif
static unsigned char args1[4] = {WIN_SLEEPNOW1,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) args[0] = WIN_SLEEPNOW1;
&& ioctl(fd, HDIO_DRIVE_CMD, &args2)) bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
bb_perror_msg("HDIO_DRIVE_CMD(sleep)");
} }
if (set_seagate) if (set_seagate)
{ {
@ -2207,9 +2212,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_xt(); no_scsi_no_xt();
if(ioctl(fd, HDIO_GET_32BIT, &parm)) if(!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
bb_perror_msg("HDIO_GET_32BIT");
else
{ {
printf(" IO_support =%3ld (", parm); printf(" IO_support =%3ld (", parm);
switch (parm) switch (parm)
@ -2245,9 +2248,7 @@ static void process_dev (char *devname)
#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
if ((verbose && !is_scsi_hd) || get_dma) { if ((verbose && !is_scsi_hd) || get_dma) {
no_scsi(); no_scsi();
if(ioctl(fd, HDIO_GET_DMA, &parm)) if(!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
bb_perror_msg("HDIO_GET_DMA");
else
{ {
printf(" using_dma = %2ld", parm); printf(" using_dma = %2ld", parm);
if (parm == 8) if (parm == 8)
@ -2294,16 +2295,16 @@ static void process_dev (char *devname)
static struct hd_big_geometry bg; static struct hd_big_geometry bg;
#endif #endif
if (ioctl(fd, BLKGETSIZE, &parm)) if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
bb_perror_msg("BLKGETSIZE"); {
#ifdef HDIO_GETGEO_BIG #ifdef HDIO_GETGEO_BIG
else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) if (!bb_ioctl(fd, HDIO_GETGEO_BIG, &bg, "HDIO_GETGEO_BIG"))
printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start);
else
#endif #endif
else if (ioctl(fd, HDIO_GETGEO, &g)) if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
bb_perror_msg("HDIO_GETGEO"); printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
else }
printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
} }
#ifdef HDIO_DRIVE_CMD #ifdef HDIO_DRIVE_CMD
if (get_powermode) if (get_powermode)
@ -2315,11 +2316,10 @@ static void process_dev (char *devname)
#define WIN_CHECKPOWERMODE2 0x98 #define WIN_CHECKPOWERMODE2 0x98
#endif #endif
const char *state; const char *state;
no_scsi(); no_scsi();
args[0] = WIN_CHECKPOWERMODE1; args[0] = WIN_CHECKPOWERMODE1;
if (ioctl(fd, HDIO_DRIVE_CMD, &args) if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
&& (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
&& ioctl(fd, HDIO_DRIVE_CMD, &args))
{ {
if (errno != EIO || args[0] != 0 || args[1] != 0) if (errno != EIO || args[0] != 0 || args[1] != 0)
state = "unknown"; state = "unknown";
@ -2374,23 +2374,19 @@ static void process_dev (char *devname)
if (get_IDentity) if (get_IDentity)
{ {
unsigned char args1[4+512] = {WIN_IDENTIFY,0,0,1,}; unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
unsigned i; unsigned i;
no_scsi_no_xt(); no_scsi_no_xt();
if (ioctl(fd, HDIO_DRIVE_CMD, &args1)) memset(args1, 0, sizeof(args1));
{ args1[0] = WIN_IDENTIFY;
args[0] = WIN_PIDENTIFY; args1[3] = 1;
if (ioctl(fd, HDIO_DRIVE_CMD, &args1)) if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)"))
{ goto identify_abort;
bb_perror_msg("HDIO_DRIVE_CMD(identify)");
goto identify_abort;
}
}
for(i=0; i<(sizeof args1)/2; i+=2) for(i=0; i<(sizeof args1)/2; i+=2)
__le16_to_cpus((uint16_t *)(&args1[i])); __le16_to_cpus((uint16_t *)(&args1[i]));
identify((void *)&args1[4], NULL); identify((void *)&args1[4], NULL);
identify_abort: identify_abort:
/* VOID */; /* VOID */;
@ -2412,9 +2408,7 @@ identify_abort:
if (get_busstate) if (get_busstate)
{ {
no_scsi(); no_scsi();
if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
bb_perror_msg("HDIO_GET_BUSSTATE");
else
{ {
printf(" busstate = %2ld", parm); printf(" busstate = %2ld", parm);
bus_state_value(parm); bus_state_value(parm);