/* * dslm.c * Simple Disk Sleep Monitor * by Bartek Kania * Licensed under the GPL
*/ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <time.h> #include <string.h> #include <signal.h> #include <sys/ioctl.h> #include <linux/hdreg.h>
#ifdef DEBUG #define D(x) x #else #define D(x) #endif
int endit = 0;
/* Check if the disk is in powersave-mode * Most of the code is stolen from hdparm.
* 1 = active, 0 = standby/sleep, -1 = unknown */ staticint check_powermode(int fd)
{ unsignedchar args[4] = {WIN_CHECKPOWERMODE1,0,0,0}; int state;
if (ioctl(fd, HDIO_DRIVE_CMD, &args)
&& (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
&& ioctl(fd, HDIO_DRIVE_CMD, &args)) { if (errno != EIO || args[0] != 0 || args[1] != 0) {
state = -1; /* "unknown"; */
} else
state = 0; /* "sleeping"; */
} else {
state = (args[2] == 255) ? 1 : 0;
}
D(printf(" drive state is: %d\n", state));
return state;
}
staticchar *state_name(int i)
{ if (i == -1) return"unknown"; if (i == 0) return"sleeping"; if (i == 1) return"active";
int main(int argc, char **argv)
{ int fd; char *disk = 0; int settle_time = 60;
/* Parse the simple command-line */ if (argc == 2)
disk = argv[1]; elseif (argc == 4) {
settle_time = atoi(argv[2]);
disk = argv[3];
} else
usage();
if (!(fd = open(disk, O_RDONLY|O_NONBLOCK))) {
printf("Can't open %s, because: %s\n", disk, strerror(errno)); exit(-1);
}
if (settle_time) {
printf("Waiting %d seconds for the system to settle down to " "'normal'\n", settle_time);
sleep(settle_time);
} else
puts("Not waiting for system to settle down");
signal(SIGINT, ender);
measure(fd);
close(fd);
return 0;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.