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

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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@ disk-shock-protection.txt
	- information on hard disk shock protection.
dslm.c
	- Simple Disk Sleep Monitor program
hpfall.c
	- (HP) laptop accelerometer program for disk protection.
freefall.c
	- (HP/DELL) laptop accelerometer program for disk protection.
laptop-mode.txt
	- how to conserve battery power using laptop-mode.
sony-laptop.txt
+45 −14
Original line number Diff line number Diff line
/* Disk protection for HP machines.
/* Disk protection for HP/DELL machines.
 *
 * Copyright 2008 Eric Piel
 * Copyright 2009 Pavel Machek <pavel@ucw.cz>
 * Copyright 2012 Sonal Santan
 * Copyright 2014 Pali Rohár <pali.rohar@gmail.com>
 *
 * GPLv2.
 */
@@ -18,24 +20,31 @@
#include <signal.h>
#include <sys/mman.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];

	if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
		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,
				"/sys/block/%s/device/unload_heads", devname);
	return 0;
}
int valid_disk(void)

static int valid_disk(void)
{
	int fd = open(unload_heads_path, O_RDONLY);

	if (fd < 0) {
		perror(unload_heads_path);
		return 0;
@@ -45,43 +54,54 @@ int valid_disk(void)
	return 1;
}

void write_int(char *path, int i)
static void write_int(char *path, int i)
{
	char buf[1024];
	int fd = open(path, O_RDWR);

	if (fd < 0) {
		perror("open");
		exit(1);
	}

	sprintf(buf, "%d", i);

	if (write(fd, buf, strlen(buf)) != strlen(buf)) {
		perror("write");
		exit(1);
	}

	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);
}

void protect(int seconds)
static void protect(int seconds)
{
	const char *str = (seconds == 0) ? "Unparked" : "Parked";

	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);
	set_led(0);
@@ -90,6 +110,7 @@ void ignore_me(void)
int main(int argc, char **argv)
{
	int fd, ret;
	struct stat st;
	struct sched_param param;

	if (argc == 1)
@@ -111,7 +132,16 @@ int main(int argc, char **argv)
		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);
	sched_setscheduler(0, SCHED_FIFO, &param);
	mlockall(MCL_CURRENT|MCL_FUTURE);
@@ -141,6 +171,7 @@ int main(int argc, char **argv)
			alarm(20);
	}

	closelog();
	close(fd);
	return EXIT_SUCCESS;
}