1 /* Disk protection for HP machines.
3 * Copyright 2008 Eric Piel
4 * Copyright 2009 Pavel Machek <pavel@ucw.cz>
14 #include <sys/types.h>
22 char unload_heads_path[64];
24 int set_unload_heads_path(char *device)
28 if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
30 strncpy(devname, device + 5, sizeof(devname));
32 snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
33 "/sys/block/%s/device/unload_heads", devname);
38 int fd = open(unload_heads_path, O_RDONLY);
40 perror(unload_heads_path);
48 void write_int(char *path, int i)
51 int fd = open(path, O_RDWR);
56 sprintf(buf, "%d", i);
57 if (write(fd, buf, strlen(buf)) != strlen(buf)) {
66 write_int("/sys/class/leds/hp::hddprotect/brightness", on);
69 void protect(int seconds)
71 write_int(unload_heads_path, seconds*1000);
76 // /sys/class/power_supply/AC0/online
81 // /proc/acpi/button/lid/LID/state
90 int main(int argc, char **argv)
93 struct sched_param param;
96 ret = set_unload_heads_path("/dev/sda");
98 ret = set_unload_heads_path(argv[1]);
102 if (ret || !valid_disk()) {
103 fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n",
108 fd = open("/dev/freefall", O_RDONLY);
110 perror("/dev/freefall");
115 param.sched_priority = sched_get_priority_max(SCHED_FIFO);
116 sched_setscheduler(0, SCHED_FIFO, ¶m);
117 mlockall(MCL_CURRENT|MCL_FUTURE);
119 signal(SIGALRM, ignore_me);
124 ret = read(fd, &count, sizeof(count));
126 if ((ret == -1) && (errno == EINTR)) {
127 /* Alarm expired, time to unpark the heads */
131 if (ret != sizeof(count)) {
138 if (1 || on_ac() || lid_open())