1 /* Disk protection for HP machines.
3 * Copyright 2008 Eric Piel
4 * Copyright 2009 Pavel Machek <pavel@suse.cz>
14 #include <sys/types.h>
20 void write_int(char *path
, int i
)
23 int fd
= open(path
, O_RDWR
);
28 sprintf(buf
, "%d", i
);
29 if (write(fd
, buf
, strlen(buf
)) != strlen(buf
)) {
38 write_int("/sys/class/leds/hp::hddprotect/brightness", on
);
41 void protect(int seconds
)
43 write_int("/sys/block/sda/device/unload_heads", seconds
*1000);
48 // /sys/class/power_supply/AC0/online
53 // /proc/acpi/button/lid/LID/state
63 int main(int argc
, char* argv
[])
67 fd
= open("/dev/freefall", O_RDONLY
);
73 signal(SIGALRM
, ignore_me
);
78 ret
= read(fd
, &count
, sizeof(count
));
80 if ((ret
== -1) && (errno
== EINTR
)) {
81 /* Alarm expired, time to unpark the heads */
85 if (ret
!= sizeof(count
)) {
92 if (1 || on_ac() || lid_open()) {