1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-08 06:48:28 +00:00

Add option to enable/disable write cache and display its current

status. Bump PORTREVISION.
This commit is contained in:
Maxim Sobolev 2011-06-24 23:51:39 +00:00
parent c7d6649784
commit 2b40c4b267
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=276245
5 changed files with 178 additions and 4 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= ataidle
PORTVERSION= 2.5.1
PORTREVISION= 1
CATEGORIES= sysutils
MASTER_SITES= http://www.cran.org.uk/bruce/software/

View File

@ -0,0 +1,39 @@
$FreeBSD$
--- main.c
+++ main.c
@@ -52,7 +52,7 @@
long opt_val;
int ch;
struct ata_ident ident;
- const char * const optstr = "hA:S:sI:iP:o";
+ const char * const optstr = "hA:S:sI:iP:owW";
/* need more than just the executable name */
if( argc == 1 )
@@ -151,6 +151,24 @@
}
break;
+ /* Write Cache Disable */
+ case 'w':
+ if (!(ident.cmd_supp1 & ATA_WC_SUPPORTED)) {
+ warnx("the device does not support write cache");
+ break;
+ }
+ rc = ata_setwc(ata, 0);
+ break;
+
+ /* Write Cache Enable */
+ case 'W':
+ if (!(ident.cmd_supp1 & ATA_WC_SUPPORTED)) {
+ warnx("the device does not support write cache");
+ break;
+ }
+ rc = ata_setwc(ata, 1);
+ break;
+
case 'h':
default:
usage();

View File

@ -0,0 +1,32 @@
$FreeBSD$
--- mi/atagen.h
+++ mi/atagen.h
@@ -62,6 +62,9 @@
#define ATA_SMART_SUPPORTED 0x0001
#define ATA_SMART_ENABLED 0x0001
+#define ATA_WC_SUPPORTED 0x0020
+#define ATA_WC_ENABLED 0x0020
+
#define ATA__SETFEATURES 0xEF
#define ATA__IDENTIFY 0xEC
#define ATA__ATAPI_IDENTIFY 0xA1
@@ -76,6 +79,8 @@
#define ATA_AUTOACOUSTIC_DISABLE 0xC2
#define ATA_APM_ENABLE 0x05
#define ATA_APM_DISABLE 0x85
+#define ATA_WC_ENABLE 0x02
+#define ATA_WC_DISABLE 0x82
#define ATA_AUTOACOUSTIC_MAXPERF 0xFE
#define ATA_AUTOACOUSTIC_MINPERF 0x80
#define ATA_APM_MINPOWER_NO_STANDBY 0x80
@@ -156,6 +161,7 @@
ATA* ata_open(const char *device);
void ata_close(ATA *ata);
int ata_setidletimer(ATA *ata, uint32_t idle_mins);
+int ata_setwc(ATA *ata, int enable);
int ata_sleep(ATA *ata);
int ata_setstandbytimer(ATA *ata, uint32_t standby_mins);
int ata_setacoustic(ATA *ata, uint32_t acoustic_val);

View File

@ -0,0 +1,102 @@
$FreeBSD$
--- mi/util.c
+++ mi/util.c
@@ -230,19 +230,19 @@
printf("Model:\t\t\t%s\n", model);
printf("Serial:\t\t\t%s\n", serial);
printf("Firmware Rev:\t\t%s\n", firmware);
- ata_version = ata_getversionstring(buf[80]);
+ ata_version = ata_getversionstring(ident.version_major);
printf("ATA revision:\t\t%s\n", (ident.version_major > 1)?
ata_version : "unknown/pre ATA-2");
- printf("LBA 48:\t\t\t%s\n", (buf[86] & 0x400)? "yes" : "no");
+ printf("LBA 48:\t\t\t%s\n", (ident.cmd_enabled2 & 0x400)? "yes" : "no");
printf("Geometry:\t\t%d cyls, %d heads, %d spt\n",
- buf[1], buf[3], buf[6]);
+ ident.word1, ident.word3, ident.word6);
if (ata_version != NULL)
free(ata_version);
mbsize = 0;
- if (buf[86] & 0x400)
+ if (ident.cmd_enabled2 & 0x400)
{
mbsize = (((uint64_t)ident.max_lba48_address[0] +
((uint64_t)ident.max_lba48_address[1] << 16) +
@@ -254,12 +254,14 @@
mbsize = ((ident.nsect[0] + (ident.nsect[1] << 16))*512)/1048576;
}
- bool smart_supported = buf[82] & ATA_SMART_SUPPORTED;
- bool smart_enabled = buf[85] & ATA_SMART_ENABLED;
- bool apm_supported = buf[83] & ATA_APM_SUPPORTED;
- bool apm_enabled = buf[86] & ATA_APM_ENABLED;
- bool aam_supported = buf[83] & ATA_AAM_SUPPORTED;
- bool aam_enabled = buf[86] & ATA_AAM_ENABLED;
+ bool smart_supported = ident.cmd_supp1 & ATA_SMART_SUPPORTED;
+ bool smart_enabled = ident.cmd_enabled1 & ATA_SMART_ENABLED;
+ bool wc_supported = ident.cmd_supp1 & ATA_WC_SUPPORTED;
+ bool wc_enabled = ident.cmd_enabled1 & ATA_WC_ENABLED;
+ bool apm_supported = ident.cmd_supp2 & ATA_APM_SUPPORTED;
+ bool apm_enabled = ident.cmd_enabled2 & ATA_APM_ENABLED;
+ bool aam_supported = ident.cmd_supp2 & ATA_AAM_SUPPORTED;
+ bool aam_enabled = ident.cmd_enabled2 & ATA_AAM_ENABLED;
printf("Capacity:\t\t%u%s\n", (mbsize < 1024)?
mbsize : mbsize/1024, (mbsize < 1024)? "MB" : "GB");
@@ -269,12 +271,17 @@
if (smart_supported)
printf("SMART Enabled: \t\t%s\n", smart_enabled? "yes" : "no" );
+ printf("Write Cache Supported: \t%s\n", wc_supported? "yes" : "no" );
+
+ if (wc_supported)
+ printf("Write Cache Enabled: \t\t%s\n", wc_enabled? "yes" : "no" );
+
printf("APM Supported: \t\t%s\n", apm_supported? "yes" : "no" );
if (apm_supported) {
printf("APM Enabled: \t\t%s\n", apm_enabled? "yes" : "no" );
if (apm_enabled)
- printf("APM Value: \t\t%d\n", buf[91]);
+ printf("APM Value: \t\t%d\n", ident.apm_value);
}
printf("AAM Supported: \t\t%s\n", aam_supported? "yes" : "no" );
@@ -282,9 +289,9 @@
if (aam_supported) {
printf("AAM Enabled: \t\t%s\n", aam_enabled? "yes" : "no");
if (aam_enabled)
- printf("AAM Value: \t\t%d\n", ((buf[94] & 0x00FF))-127);
+ printf("AAM Value: \t\t%d\n", ((ident.aam_value & 0x00FF))-127);
- printf("Vendor Recommended AAM: %d\n", ((buf[94] & 0xFF00) >> 8)-127);
+ printf("Vendor Recommended AAM: %d\n", ((ident.aam_value & 0xFF00) >> 8)-127);
}
}
@@ -345,6 +352,20 @@
return rc;
}
+int
+ata_setwc(ATA *ata, int enable)
+{
+ int rc, cmd;
+
+ /* allocate and initialize the ata_cmd structure */
+ ata_init(ata);
+ cmd = enable ? ATA_WC_ENABLE : ATA_WC_DISABLE;
+ rc = ata_cmd(ata, ATA__SETFEATURES, cmd, 0);
+ if(rc)
+ perror("Failed to configure Write Cache");
+ return rc;
+}
+
/*
* Sets the acoustic level on modern hard drives. This is used to run it
* at a lower speed/performance level, which in turn reduces noise.

View File

@ -1,7 +1,7 @@
ATAidle is a utility to set the power management features
of ata hard drives. This includes standby timeouts, power (APM)
and acoustic (AAM) level settings, and it can show details about
the installed devices.
ATAidle is a utility to set the power management and performance
features of ATA hard drives. This includes standby timeouts, power
(APM) write cache and acoustic (AAM) level settings, and it can show
details about the installed devices.
Author: Bruce Cran <bruce@cran.org.uk>
WWW: http://www.cran.org.uk/bruce/software/ataidle/