Commit 3a57cc5f authored by Pali Rohár's avatar Pali Rohár Committed by Linus Torvalds

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: default avatarPali Rohár <pali.rohar@gmail.com>
Cc: Sonal Santan <sonal.santan@gmail.com>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0ba4f6e4
...@@ -8,8 +8,8 @@ disk-shock-protection.txt ...@@ -8,8 +8,8 @@ disk-shock-protection.txt
- information on hard disk shock protection. - information on hard disk shock protection.
dslm.c dslm.c
- Simple Disk Sleep Monitor program - Simple Disk Sleep Monitor program
hpfall.c freefall.c
- (HP) laptop accelerometer program for disk protection. - (HP/DELL) laptop accelerometer program for disk protection.
laptop-mode.txt laptop-mode.txt
- how to conserve battery power using laptop-mode. - how to conserve battery power using laptop-mode.
sony-laptop.txt sony-laptop.txt
......
/* Disk protection for HP machines. /* Disk protection for HP/DELL machines.
* *
* Copyright 2008 Eric Piel * Copyright 2008 Eric Piel
* Copyright 2009 Pavel Machek <pavel@ucw.cz> * Copyright 2009 Pavel Machek <pavel@ucw.cz>
* Copyright 2012 Sonal Santan
* Copyright 2014 Pali Rohár <pali.rohar@gmail.com>
* *
* GPLv2. * GPLv2.
*/ */
...@@ -18,24 +20,31 @@ ...@@ -18,24 +20,31 @@
#include <signal.h> #include <signal.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sched.h> #include <sched.h>
#include <syslog.h>
char unload_heads_path[64]; static int noled;
static char unload_heads_path[64];
static char device_path[32];
static const char app_name[] = "FREE FALL";
int set_unload_heads_path(char *device) static int set_unload_heads_path(char *device)
{ {
char devname[64]; char devname[64];
if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0) if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
return -EINVAL; return -EINVAL;
strncpy(devname, device + 5, sizeof(devname)); strncpy(devname, device + 5, sizeof(devname) - 1);
strncpy(device_path, device, sizeof(device_path) - 1);
snprintf(unload_heads_path, sizeof(unload_heads_path) - 1, snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
"/sys/block/%s/device/unload_heads", devname); "/sys/block/%s/device/unload_heads", devname);
return 0; return 0;
} }
int valid_disk(void)
static int valid_disk(void)
{ {
int fd = open(unload_heads_path, O_RDONLY); int fd = open(unload_heads_path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror(unload_heads_path); perror(unload_heads_path);
return 0; return 0;
...@@ -45,43 +54,54 @@ int valid_disk(void) ...@@ -45,43 +54,54 @@ int valid_disk(void)
return 1; return 1;
} }
void write_int(char *path, int i) static void write_int(char *path, int i)
{ {
char buf[1024]; char buf[1024];
int fd = open(path, O_RDWR); int fd = open(path, O_RDWR);
if (fd < 0) { if (fd < 0) {
perror("open"); perror("open");
exit(1); exit(1);
} }
sprintf(buf, "%d", i); sprintf(buf, "%d", i);
if (write(fd, buf, strlen(buf)) != strlen(buf)) { if (write(fd, buf, strlen(buf)) != strlen(buf)) {
perror("write"); perror("write");
exit(1); exit(1);
} }
close(fd); close(fd);
} }
void set_led(int on) static void set_led(int on)
{ {
if (noled)
return;
write_int("/sys/class/leds/hp::hddprotect/brightness", on); write_int("/sys/class/leds/hp::hddprotect/brightness", on);
} }
void protect(int seconds) static void protect(int seconds)
{ {
const char *str = (seconds == 0) ? "Unparked" : "Parked";
write_int(unload_heads_path, seconds*1000); write_int(unload_heads_path, seconds*1000);
syslog(LOG_INFO, "%s %s disk head\n", str, device_path);
} }
int on_ac(void) static int on_ac(void)
{ {
// /sys/class/power_supply/AC0/online /* /sys/class/power_supply/AC0/online */
return 1;
} }
int lid_open(void) static int lid_open(void)
{ {
// /proc/acpi/button/lid/LID/state /* /proc/acpi/button/lid/LID/state */
return 1;
} }
void ignore_me(void) static void ignore_me(int signum)
{ {
protect(0); protect(0);
set_led(0); set_led(0);
...@@ -90,6 +110,7 @@ void ignore_me(void) ...@@ -90,6 +110,7 @@ void ignore_me(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd, ret; int fd, ret;
struct stat st;
struct sched_param param; struct sched_param param;
if (argc == 1) if (argc == 1)
...@@ -111,7 +132,16 @@ int main(int argc, char **argv) ...@@ -111,7 +132,16 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
daemon(0, 0); if (stat("/sys/class/leds/hp::hddprotect/brightness", &st))
noled = 1;
if (daemon(0, 0) != 0) {
perror("daemon");
return EXIT_FAILURE;
}
openlog(app_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
param.sched_priority = sched_get_priority_max(SCHED_FIFO); param.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0, SCHED_FIFO, &param); sched_setscheduler(0, SCHED_FIFO, &param);
mlockall(MCL_CURRENT|MCL_FUTURE); mlockall(MCL_CURRENT|MCL_FUTURE);
...@@ -141,6 +171,7 @@ int main(int argc, char **argv) ...@@ -141,6 +171,7 @@ int main(int argc, char **argv)
alarm(20); alarm(20);
} }
closelog();
close(fd); close(fd);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment