diff options
Diffstat (limited to 'Documentation/laptops')
-rw-r--r-- | Documentation/laptops/00-INDEX | 4 | ||||
-rw-r--r-- | Documentation/laptops/freefall.c (renamed from Documentation/laptops/hpfall.c) | 59 |
2 files changed, 47 insertions, 16 deletions
diff --git a/Documentation/laptops/00-INDEX b/Documentation/laptops/00-INDEX index d13b9a9a9e00..d399ae1fc724 100644 --- a/Documentation/laptops/00-INDEX +++ b/Documentation/laptops/00-INDEX | |||
@@ -8,8 +8,8 @@ disk-shock-protection.txt | |||
8 | - information on hard disk shock protection. | 8 | - information on hard disk shock protection. |
9 | dslm.c | 9 | dslm.c |
10 | - Simple Disk Sleep Monitor program | 10 | - Simple Disk Sleep Monitor program |
11 | hpfall.c | 11 | freefall.c |
12 | - (HP) laptop accelerometer program for disk protection. | 12 | - (HP/DELL) laptop accelerometer program for disk protection. |
13 | laptop-mode.txt | 13 | laptop-mode.txt |
14 | - how to conserve battery power using laptop-mode. | 14 | - how to conserve battery power using laptop-mode. |
15 | sony-laptop.txt | 15 | sony-laptop.txt |
diff --git a/Documentation/laptops/hpfall.c b/Documentation/laptops/freefall.c index b85dbbac0499..aab2ff09e868 100644 --- a/Documentation/laptops/hpfall.c +++ b/Documentation/laptops/freefall.c | |||
@@ -1,7 +1,9 @@ | |||
1 | /* Disk protection for HP machines. | 1 | /* Disk protection for HP/DELL machines. |
2 | * | 2 | * |
3 | * Copyright 2008 Eric Piel | 3 | * Copyright 2008 Eric Piel |
4 | * Copyright 2009 Pavel Machek <pavel@ucw.cz> | 4 | * Copyright 2009 Pavel Machek <pavel@ucw.cz> |
5 | * Copyright 2012 Sonal Santan | ||
6 | * Copyright 2014 Pali Rohár <pali.rohar@gmail.com> | ||
5 | * | 7 | * |
6 | * GPLv2. | 8 | * GPLv2. |
7 | */ | 9 | */ |
@@ -18,24 +20,31 @@ | |||
18 | #include <signal.h> | 20 | #include <signal.h> |
19 | #include <sys/mman.h> | 21 | #include <sys/mman.h> |
20 | #include <sched.h> | 22 | #include <sched.h> |
23 | #include <syslog.h> | ||
21 | 24 | ||
22 | char unload_heads_path[64]; | 25 | static int noled; |
26 | static char unload_heads_path[64]; | ||
27 | static char device_path[32]; | ||
28 | static const char app_name[] = "FREE FALL"; | ||
23 | 29 | ||
24 | int set_unload_heads_path(char *device) | 30 | static int set_unload_heads_path(char *device) |
25 | { | 31 | { |
26 | char devname[64]; | 32 | char devname[64]; |
27 | 33 | ||
28 | if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0) | 34 | if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0) |
29 | return -EINVAL; | 35 | return -EINVAL; |
30 | strncpy(devname, device + 5, sizeof(devname)); | 36 | strncpy(devname, device + 5, sizeof(devname) - 1); |
37 | strncpy(device_path, device, sizeof(device_path) - 1); | ||
31 | 38 | ||
32 | snprintf(unload_heads_path, sizeof(unload_heads_path) - 1, | 39 | snprintf(unload_heads_path, sizeof(unload_heads_path) - 1, |
33 | "/sys/block/%s/device/unload_heads", devname); | 40 | "/sys/block/%s/device/unload_heads", devname); |
34 | return 0; | 41 | return 0; |
35 | } | 42 | } |
36 | int valid_disk(void) | 43 | |
44 | static int valid_disk(void) | ||
37 | { | 45 | { |
38 | int fd = open(unload_heads_path, O_RDONLY); | 46 | int fd = open(unload_heads_path, O_RDONLY); |
47 | |||
39 | if (fd < 0) { | 48 | if (fd < 0) { |
40 | perror(unload_heads_path); | 49 | perror(unload_heads_path); |
41 | return 0; | 50 | return 0; |
@@ -45,43 +54,54 @@ int valid_disk(void) | |||
45 | return 1; | 54 | return 1; |
46 | } | 55 | } |
47 | 56 | ||
48 | void write_int(char *path, int i) | 57 | static void write_int(char *path, int i) |
49 | { | 58 | { |
50 | char buf[1024]; | 59 | char buf[1024]; |
51 | int fd = open(path, O_RDWR); | 60 | int fd = open(path, O_RDWR); |
61 | |||
52 | if (fd < 0) { | 62 | if (fd < 0) { |
53 | perror("open"); | 63 | perror("open"); |
54 | exit(1); | 64 | exit(1); |
55 | } | 65 | } |
66 | |||
56 | sprintf(buf, "%d", i); | 67 | sprintf(buf, "%d", i); |
68 | |||
57 | if (write(fd, buf, strlen(buf)) != strlen(buf)) { | 69 | if (write(fd, buf, strlen(buf)) != strlen(buf)) { |
58 | perror("write"); | 70 | perror("write"); |
59 | exit(1); | 71 | exit(1); |
60 | } | 72 | } |
73 | |||
61 | close(fd); | 74 | close(fd); |
62 | } | 75 | } |
63 | 76 | ||
64 | void set_led(int on) | 77 | static void set_led(int on) |
65 | { | 78 | { |
79 | if (noled) | ||
80 | return; | ||
66 | write_int("/sys/class/leds/hp::hddprotect/brightness", on); | 81 | write_int("/sys/class/leds/hp::hddprotect/brightness", on); |
67 | } | 82 | } |
68 | 83 | ||
69 | void protect(int seconds) | 84 | static void protect(int seconds) |
70 | { | 85 | { |
86 | const char *str = (seconds == 0) ? "Unparked" : "Parked"; | ||
87 | |||
71 | write_int(unload_heads_path, seconds*1000); | 88 | write_int(unload_heads_path, seconds*1000); |
89 | syslog(LOG_INFO, "%s %s disk head\n", str, device_path); | ||
72 | } | 90 | } |
73 | 91 | ||
74 | int on_ac(void) | 92 | static int on_ac(void) |
75 | { | 93 | { |
76 | // /sys/class/power_supply/AC0/online | 94 | /* /sys/class/power_supply/AC0/online */ |
95 | return 1; | ||
77 | } | 96 | } |
78 | 97 | ||
79 | int lid_open(void) | 98 | static int lid_open(void) |
80 | { | 99 | { |
81 | // /proc/acpi/button/lid/LID/state | 100 | /* /proc/acpi/button/lid/LID/state */ |
101 | return 1; | ||
82 | } | 102 | } |
83 | 103 | ||
84 | void ignore_me(void) | 104 | static void ignore_me(int signum) |
85 | { | 105 | { |
86 | protect(0); | 106 | protect(0); |
87 | set_led(0); | 107 | set_led(0); |
@@ -90,6 +110,7 @@ void ignore_me(void) | |||
90 | int main(int argc, char **argv) | 110 | int main(int argc, char **argv) |
91 | { | 111 | { |
92 | int fd, ret; | 112 | int fd, ret; |
113 | struct stat st; | ||
93 | struct sched_param param; | 114 | struct sched_param param; |
94 | 115 | ||
95 | if (argc == 1) | 116 | if (argc == 1) |
@@ -111,7 +132,16 @@ int main(int argc, char **argv) | |||
111 | return EXIT_FAILURE; | 132 | return EXIT_FAILURE; |
112 | } | 133 | } |
113 | 134 | ||
114 | daemon(0, 0); | 135 | if (stat("/sys/class/leds/hp::hddprotect/brightness", &st)) |
136 | noled = 1; | ||
137 | |||
138 | if (daemon(0, 0) != 0) { | ||
139 | perror("daemon"); | ||
140 | return EXIT_FAILURE; | ||
141 | } | ||
142 | |||
143 | openlog(app_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); | ||
144 | |||
115 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); | 145 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); |
116 | sched_setscheduler(0, SCHED_FIFO, ¶m); | 146 | sched_setscheduler(0, SCHED_FIFO, ¶m); |
117 | mlockall(MCL_CURRENT|MCL_FUTURE); | 147 | mlockall(MCL_CURRENT|MCL_FUTURE); |
@@ -141,6 +171,7 @@ int main(int argc, char **argv) | |||
141 | alarm(20); | 171 | alarm(20); |
142 | } | 172 | } |
143 | 173 | ||
174 | closelog(); | ||
144 | close(fd); | 175 | close(fd); |
145 | return EXIT_SUCCESS; | 176 | return EXIT_SUCCESS; |
146 | } | 177 | } |