mi/util.c
// command the device to spindown after idle_mins of no disk activity
command the device to spindown after idle_mins of no disk activity
command the device to spindown after idle_mins of no disk activity
int32_t 
ata_setidle(struct ATA *ata, uint32_t chan, uint32_t dev, uint32_t idle_mins)
{
	uint16_t timer_val = 0;
	int32_t rc = 0;
	rc = ata_getidleval( idle_mins, &timer_val );	
	if(timer_val == ATA_IDLEVAL_IMMEDIATE)
		ata_setataparams(ata, 0, 0);
	else
		ata_setataparams(ata, timer_val, 0);
	if(!rc) {
		if(timer_val == ATA_IDLEVAL_IMMEDIATE)
			rc = ata_cmd(ata, chan, dev, ATA_IDLE_IMMEDIATE, 0);
		else
			rc = ata_cmd(ata, chan, dev, ATA_IDLE, 0);
	}
	if(rc) { 
		if(rc == -2)
 			printf("error setting idle timeout\n");
		else
			perror("error setting idle timeout");
	} else {
		if(timer_val == ATA_IDLEVAL_IMMEDIATE)
				printf("set chan %d, dev %d to idle immediately\n",
					chan, dev);
		else if(timer_val == 0)
			printf("turned off idle timer on chan %d, dev %d\n",
					chan, dev);
		else
			printf("set chan %d, dev %d to idle after %d minutes\n", 
					chan, dev, idle_mins);
	}
	return rc;
}
int32_t ata_setidle ( struct ATA * ata , uint32_t chan , uint32_t dev , uint32_t idle_mins ) { uint16_t timer_val = 0 ; int32_t rc = 0 ; rc = ata_getidleval ( idle_mins , & timer_val ) ; if ( timer_val == ATA_IDLEVAL_IMMEDIATE ) ata_setataparams ( ata , 0 , 0 ) ; else ata_setataparams ( ata , timer_val , 0 ) ; if ( ! rc ) { if ( timer_val == ATA_IDLEVAL_IMMEDIATE ) rc = ata_cmd ( ata , chan , dev , ATA_IDLE_IMMEDIATE , 0 ) ; else rc = ata_cmd ( ata , chan , dev , ATA_IDLE , 0 ) ; } if ( rc ) { if ( rc == -2 ) printf ( " \n " ) ; else perror ( " " ) ; } else { if ( timer_val == ATA_IDLEVAL_IMMEDIATE ) printf ( " \n " , chan , dev ) ; else if ( timer_val == 0 ) printf ( " \n " , chan , dev ) ; else printf ( " \n " , chan , dev , idle_mins ) ; } return rc ; }
command the device to spindown after idle_mins of no disk activity
command the device to spindown after idle_mins of no disk activity
// send the IDLE command to the drive