--- ../hdparm-3.9.orig/hdparm.c Sun Feb 11 23:08:08 2001 +++ hdparm.c Sun Feb 11 23:52:06 2001 @@ -78,10 +78,11 @@ static unsigned long set_doorlock = 0, get_doorlock = 0, doorlock = 0; static unsigned long set_seagate = 0, get_seagate = 0; static unsigned long set_standbynow = 0, get_standbynow = 0; static unsigned long set_sleepnow = 0, get_sleepnow = 0; static unsigned long get_powermode = 0; +static unsigned long set_apmmode = 0, get_apmmode= 0, apmmode = 0; #endif #ifdef CDROM_SELECT_SPEED static unsigned long set_cdromspeed = 0, cdromspeed = 0; #endif /* CDROM_SELECT_SPEED */ #ifdef HDIO_SET_32BIT @@ -119,10 +120,11 @@ static void dump_identity (struct hd_driveid *id) { int i; char pmodes[64] = {0,}, dmodes[128]={0,}; + unsigned short int *id_regs=(void*)id; printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s", id->model, id->fw_rev, id->serial_no); printf("\n Config={"); for (i=0; i<=15; i++) { @@ -223,10 +225,21 @@ } if ((id->capability&1) && (id->field_valid&2)) printf(", tDMA={min:%d,rec:%d}", id->eide_dma_min, id->eide_dma_time); printf("\n PIO modes: %s", pmodes); printf("\n DMA modes: %s\n", dmodes); + + printf("\nAdvancedPowerManagement=%s",YN(id_regs[83]&8)); + if (id_regs[83]&8) { + if (!(id_regs[86]&8)) + printf(": disabled (255)"); + else if ((id_regs[91]&0xFF00)!=0x4000) + printf(": unknown setting"); + else + printf(": mode=0x%02X (%d)",id_regs[91]&0xFF,id_regs[91]&0xFF); + } + printf("\n"); } void flush_buffer_cache (int fd) { fsync (fd); /* flush buffers */ @@ -791,10 +804,30 @@ on_off(lookahead); } if (ioctl(fd, HDIO_DRIVE_CMD, &args)) perror(" HDIO_DRIVE_CMD(setreadahead) failed"); } + if (set_apmmode) { + unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; + no_scsi(); + if (apmmode<1) apmmode=1; + if (apmmode>255) apmmode=255; + if (get_apmmode) + printf(" setting Advanced Power Management level to"); + if (apmmode==255) { + /* disable Advanced Power Management */ + args[2] = 0x85; /* feature register */ + if (get_apmmode) printf(" disabled\n"); + } else { + /* set Advanced Power Management mode */ + args[2] = 0x05; /* feature register */ + args[1] = apmmode; /* sector count register */ + if (get_apmmode) printf(" 0x%02lX (%ld)\n",apmmode,apmmode); + } + if (ioctl(fd, HDIO_DRIVE_CMD, &args)) + perror(" HDIO_DRIVE_CMD failed"); + } #ifdef CDROM_SELECT_SPEED if (set_cdromspeed) { printf ("setting cdrom speed to %ld\n", cdromspeed); if (ioctl (fd, CDROM_SELECT_SPEED, cdromspeed)) perror(" CDROM_SELECT_SPEED failed"); @@ -1071,10 +1104,11 @@ fprintf(stderr,"Options:\n" " -a get/set fs readahead\n" #ifdef HDIO_DRIVE_CMD " -A set drive read-lookahead flag (0/1)\n" #endif + " -b get Advanced Power Management setting (1-255)\n" #ifdef HDIO_SET_32BIT " -c get/set IDE 32-bit IO setting\n" #endif #ifdef HDIO_DRIVE_CMD " -C check IDE power mode status\n" @@ -1434,10 +1468,16 @@ #endif /* HDIO_SCAN_HWIF */ case 'a': get_readahead = noisy; noisy = 1; GET_NUMBER(set_readahead,readahead); + break; + case 'b': + noisy = 1; + GET_NUMBER(set_apmmode,apmmode); + if (!set_apmmode) + printf("-b: missing value (1-255)\n"); break; case 't': do_timings = 1; do_flush = 1; break;