Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Documenation/laptops: rename and update hpfall.c

Dell kernel driver dell-smo8800 provides same freefall interface as hp_accel so
program hpfall.c works also on Dell laptops. So rename it to freefall.c.

Dell driver does not provide hp::hddprotect led so make sure that freefall.c
works also if hp::hddprotect does not exist in sysfs.

Additionally write info to syslog.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Cc: Sonal Santan <sonal.santan@gmail.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Pali Rohár and committed by
Linus Torvalds
3a57cc5f 0ba4f6e4

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