@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ usr-src-sys-dev-ata-ata-disk.c.patch @@@ ATA_IDLE_CMD 発行 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ *** ata-disk.c.org 2010-06-14 11:09:06.000000000 +0900 --- ata-disk.c 2011-01-07 17:03:15.000000000 +0900 *************** *** 399,404 **** --- 399,410 ---- ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_DIS_WCACHE, 0, 0); } + #if 1 + device_printf(dev, "try to set IDLE after 10 minutes\n"); + if(ata_controlcmd(dev, ATA_IDLE_CMD, 0, 0, 120)) + device_printf(dev, "fail to set IDLE timer\n"); + #endif /* 1 */ + /* use multiple sectors/interrupt if device supports it */ if (ad_version(atadev->param.version_major)) { int secsperint = max(1, min(atadev->param.sectors_intr & 0xff, 16)); @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ usr-src-sys-dev-ata-ata-all.h.patch @@@ タイムアウト伸長 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ *** ata-all.h.org 2010-06-14 11:09:06.000000000 +0900 --- ata-all.h 2011-01-08 08:06:14.000000000 +0900 *************** *** 348,354 **** #define ATA_MAX_28BIT_LBA 268435455UL #ifndef ATA_REQUEST_TIMEOUT ! #define ATA_REQUEST_TIMEOUT 10 #endif /* structure used for composite atomic operations */ --- 348,354 ---- #define ATA_MAX_28BIT_LBA 268435455UL #ifndef ATA_REQUEST_TIMEOUT ! #define ATA_REQUEST_TIMEOUT 29 #endif /* structure used for composite atomic operations */ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ etc-fstab @@@ noatime 追加 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # Device Mountpoint FStype Options Dump Pass# /dev/ad6s1b none swap sw 0 0 /dev/ad6s1a / ufs rw,noatime 1 1 /dev/ad6s1d /usr ufs rw,noatime 2 2 /dev/ad6s2 /home ufs rw,noatime 3 3 /dev/ad4s2 /hbackup ufs rw,noatime,noauto 3 3 /dev/acd0 /cdrom cd9660 ro,noauto 0 0 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ etc-crontab @@@ ジョブを 00分近傍に集中 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ # /etc/crontab - root's crontab for FreeBSD # # $FreeBSD: src/etc/crontab,v 1.33.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ # SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin # #minute hour mday month wday who command # #*/5 * * * * root /usr/libexec/atrun 59 * * * * root /usr/libexec/atrun # # Save some entropy so that /dev/random can re-seed on boot. #*/11 * * * * operator /usr/libexec/save-entropy 1 * * * * operator /usr/libexec/save-entropy # # Rotate log files every hour, if necessary. 0 * * * * root newsyslog # # Perform daily/weekly/monthly maintenance. 1 3 * * * root periodic daily 4 4 * * 6 root periodic weekly 8 5 1 * * root periodic monthly # # Adjust the time zone if the CMOS clock keeps local time, as opposed to # UTC time. See adjkerntz(8) for details. #1,31 0-5 * * * root adjkerntz -a 1 0-5 * * * root adjkerntz -a # # my local jobs # #minute hour mday month wday who command 3 3 * * * root /root/Rsync @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ etc-syslog.conf-patch @@@ 不要なログの抑制(のつもり) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ *** syslog.conf.org 2010-07-19 11:24:59.000000000 +0900 --- syslog.conf 2011-01-09 09:10:33.000000000 +0900 *************** *** 6,17 **** # may want to use only tabs as field separators here. # Consult the syslog.conf(5) manpage. *.err;kern.warning;auth.notice;mail.crit /dev/console ! *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages security.* /var/log/security auth.info;authpriv.info /var/log/auth.log mail.info /var/log/maillog lpr.info /var/log/lpd-errs ftp.info /var/log/xferlog cron.* /var/log/cron *.=debug /var/log/debug.log *.emerg * --- 6,19 ---- # may want to use only tabs as field separators here. # Consult the syslog.conf(5) manpage. *.err;kern.warning;auth.notice;mail.crit /dev/console ! #*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages ! *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err;ntp.none /var/log/messages security.* /var/log/security auth.info;authpriv.info /var/log/auth.log mail.info /var/log/maillog lpr.info /var/log/lpd-errs ftp.info /var/log/xferlog + ntp.info /var/log/ntp.log cron.* /var/log/cron *.=debug /var/log/debug.log *.emerg * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ usr-src-sbin-atacontrol-atacontrol.c.patch @@@ ATA_IDLE_CMD、温度測定ほか (いんちき) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ *** atacontrol.c.org 2011-01-07 18:05:40.000000000 +0900 --- atacontrol.c 2011-01-07 18:55:28.000000000 +0900 *************** *** 39,44 **** --- 39,268 ---- #include #include + #define TIMEOUT 10 /* [sec] */ + + int ata_smart_read(int fd); + int ata_set_max(int fd); + int ata_set_idle_timer(int fd, int time); + int ata_check_power_mode(int fd); + + int + ata_smart_read(int fd) + { + struct ata_ioc_request req; + unsigned char buff[512]; + // int i, j; + int j; + + /* + * get SMART data + */ + bzero(&req, sizeof(req)); + req.u.ata.command = ATA_SMART_CMD; + req.u.ata.feature = 0xd0; /* ATA_SF_SMART_READ_DATA */ + req.u.ata.lba = 0xc24f<<8; /* magic number */ + req.data = buff; + req.count = 512; + req.flags = ATA_CMD_READ; + req.timeout = TIMEOUT; + + if (ioctl(fd, IOCATAREQUEST, &req) < 0) { + printf("fail ioctl()\n"); + return errno; + } + + // printf("Seagate_ST340823A/3.05: "); + // j = 98; + // printf(" Temp: %3d", buff[j+5]); + // printf(" [%04x:", j); + // for(i=0; i<12; i++) + // printf(" %02x", buff[j+i]); + // printf("]"); + // printf("\n"); + + + //printf("Maxtor_6V250F0/VA111900:"); + printf("ST32000542AS/CC34:"); + j = 158; + printf(" Temp: %3d", buff[j+5]); + // printf(" [%04x:", j); + // for(i=0; i<12; i++) + // printf(" %02x", buff[j+i]); + // printf("]"); + printf("\n"); + + return 0; + } + + int + ata_set_max(int fd) + { + /* + * do NOT use ATA_READ_NATIVE_MAX_ADDRESS48 and ATA_SET_MAX_ADDRESS48 ! + * + * shall use ATA_READ_NATIVE_MAX_ADDRESS and ATA_SET_MAX_ADDRESS and + * make the kernel to switch to 48bit mode by making conditions below ! + * + * (request->u.ata.lba >= ATA_MAX_28BIT_LBA (268435455UL)) || + * (request->u.ata.count > 256) + */ + #define VALUE_VOLATILE 0 + + struct ata_params params; + struct ata_ioc_request req; + u_int64_t native_max; + + /* + * get identify device data at first + */ + if (ioctl(fd, IOCATAGPARM, ¶ms) < 0) + return errno; + + /* + * get native max lba + */ + bzero(&req, sizeof(req)); + req.u.ata.command = ATA_READ_NATIVE_MAX_ADDRESS; + req.flags = ATA_CMD_CONTROL; + req.timeout = TIMEOUT; + if(params.support.command2 & ATA_SUPPORT_ADDRESS48) + req.u.ata.count |= 0x1000; /* force to use 48bit command */ + + if (ioctl(fd, IOCATAREQUEST, &req) < 0) { + printf("fail ioctl()\n"); + return errno; + } + native_max = req.u.ata.lba; + printf("native max lba: %llu/0x%llx\n", native_max, native_max); + + /* + * set max lba to native value + */ + bzero(&req, sizeof(req)); + req.u.ata.command = ATA_SET_MAX_ADDRESS; + #if VALUE_VOLATILE + req.u.ata.count = 1; /* Value Volatile */ + #else /* VALUE_VOLATILE */ + req.u.ata.count = 0; /* Value NOT Volatile */ + #endif /* VALUE_VOLATILE */ + req.u.ata.lba = native_max; + req.flags = ATA_CMD_CONTROL; + req.timeout = TIMEOUT; + if(params.support.command2 & ATA_SUPPORT_ADDRESS48) + req.u.ata.count |= 0x1000; /* force to use 48bit command */ + + if (ioctl(fd, IOCATAREQUEST, &req) < 0) { + printf("fail ioctl()\n"); + return errno; + } + + return 0; + } + + int + ata_set_idle_timer(int fd, int time) + { + struct ata_ioc_request req; + int sc; + + /* + * given unit is [min], convert it to [sec] + */ + time *= 60; + + /* + * convert time to Sector Count register value + * + * SecReg | Corresponding timeout period + * -------+---------------------------------- + * 0 | Timeout disabled + * - - - + - - - - - - - - - - - - - - - - + * 1 | 5sec + * 2 | 10sec + * .. | .. + * 239 | 1195sec + * 240 | 1200sec (20min) + * - - - + - - - - - - - - - - - - - - - - + * 241 | 1800sec (30min, 0.5hour) + * 242 | 3600sec (60min, 1.0hour) + * .. | .. + * 250 | 18000sec (300min, 5.0hour) + * 251 | 19800sec (330min, 5.5hour) + * ------+--------------------------------- + * 252 | 21min + * 253 | Period between 8 hours and 12 hours + * 254 | (reserved) + * 255 | 21min 15seconds + * -------+---------------------------------- + */ + if(time <= 0) { + sc = 0; /* Timeout disabled */ + } else if(time <= 1200) { + sc = (time + 4) / 5; /* 5sec step until 20min */ + } else if(time <= 19800) { + sc = (time + (30*60-1)) / (30*60) + 240; + /* 30min step until 5.5hour */ + } else { + sc = 0xfd; /* Period between 8hours and 12hours */ + } + + bzero(&req, sizeof(req)); + req.u.ata.command = ATA_IDLE_CMD; /* 8 */ + req.u.ata.count = sc; /* 16, ==> COUNT */ + req.flags = ATA_CMD_CONTROL; + req.timeout = TIMEOUT; + + if (ioctl(fd, IOCATAREQUEST, &req) < 0) { + printf("fail ioctl()\n"); + return errno; + } + + printf("set idle timer "); + if(sc == 0) { + printf("disabled\n"); + } else if(sc <= 240) { + printf("to %d min\n", (sc * 5) / 60); + } else if(sc <= 251) { + printf("to %d min\n", (sc - 240) * 30); + } else { + printf("to about 8--12 hours\n"); + } + + return 0; + } + + int + ata_check_power_mode(int fd) + { + #define ATA_CHECK_POWER_MODE 0xe5 + struct ata_ioc_request req; + + bzero(&req, sizeof(req)); + req.u.ata.command = ATA_CHECK_POWER_MODE; + req.flags = ATA_CMD_CONTROL; + req.timeout = TIMEOUT; + + if (ioctl(fd, IOCATAREQUEST, &req) < 0) { + printf("fail ioctl()\n"); + return errno; + } + + switch(req.u.ata.count) { + case 0x00: printf("in Standby mode\n"); + break; + case 0x80: printf("in Idle mode\n"); + break; + case 0xff: printf("in Active (or Idle) mode\n"); + break; + default: printf("unknown\n"); + break; + } + + return 0; + } + + + static const char * mode2str(int mode) { *************** *** 125,130 **** --- 349,358 ---- " atacontrol mode device [mode]\n" " atacontrol cap device\n" " atacontrol spindown device [seconds]\n" + " atacontrol max device (set max LBA to native)\n" + " atacontrol idle device minutes (set idle timer)\n" + " atacontrol pow device (check power mode)\n" + " atacontrol temp device (smart read)\n" ); exit(EX_USAGE); } *************** *** 268,273 **** --- 496,508 ---- ATA_ACOUSTIC_CURRENT(parm->acoustic), ATA_ACOUSTIC_VENDOR(parm->acoustic), ATA_ACOUSTIC_VENDOR(parm->acoustic)); + + printf("host protected area %s %s\n", + parm->support.command1 & ATA_SUPPORT_PROTECTED ? "yes" : "no", + parm->enabled.command1 & ATA_SUPPORT_PROTECTED ? "yes" : "no"); + printf(" (security extensions) %s %s\n", + parm->support.command2 & ATA_SUPPORT_MAXSECURITY ? "yes" : "no", + parm->enabled.command2 & ATA_SUPPORT_MAXSECURITY ? "yes" : "no"); } static void *************** *** 410,415 **** --- 645,674 ---- exit(EX_OK); } + + if (!strcmp(argv[1], "max") && argc == 3) { + fd = open_dev(argv[2], O_RDONLY); + ata_set_max(fd); + exit(EX_OK); + } + if (!strcmp(argv[1], "idle") && argc == 4) { + fd = open_dev(argv[2], O_RDONLY); + ata_set_idle_timer(fd, atoi(argv[3])); + exit(EX_OK); + } + if (!strcmp(argv[1], "pow") && argc == 3) { + fd = open_dev(argv[2], O_RDONLY); + ata_check_power_mode(fd); + exit(EX_OK); + } + if (!strcmp(argv[1], "temp") && argc == 3) { + fd = open_dev(argv[2], O_RDONLY); + ata_smart_read(fd); + exit(EX_OK); + } + + + if ((fd = open("/dev/ata", O_RDWR)) < 0) err(1, "control device not found");