aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/hwmon
diff options
context:
space:
mode:
authorFrans Pop <elendil@planet.nl>2009-07-25 15:00:12 -0400
committerJiri Kosina <jkosina@suse.cz>2009-09-21 09:14:57 -0400
commitbe3990b7efbe8784fe063fb6871a772c0703891a (patch)
treeb11207c6eb29a3c9bc381ed16a42c83f8b2713d2 /Documentation/hwmon
parent2bace8b95108746f6123d312f47f5bda4eb17a26 (diff)
trivial: doc: hpfall: accept disk device to unload as argument
Allows users who use an IDE driver for their disk to use hpfall without having to modify the source. By default /dev/sda is used. Suggested by Christian Thaeter in http://lkml.org/lkml/2009/3/25/505. While we're add it, improve error message if opening /dev/freefall fails. Signed-off-by: Frans Pop <elendil@planet.nl> Cc: Christian Thaeter <ct@pipapo.org> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'Documentation/hwmon')
-rw-r--r--Documentation/hwmon/hpfall.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c
index a3cfe1a5f964..681ec22b9d0e 100644
--- a/Documentation/hwmon/hpfall.c
+++ b/Documentation/hwmon/hpfall.c
@@ -19,6 +19,32 @@
19#include <sys/mman.h> 19#include <sys/mman.h>
20#include <sched.h> 20#include <sched.h>
21 21
22char unload_heads_path[64];
23
24int set_unload_heads_path(char *device)
25{
26 char devname[64];
27
28 if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
29 return -EINVAL;
30 strncpy(devname, device + 5, sizeof(devname));
31
32 snprintf(unload_heads_path, sizeof(unload_heads_path),
33 "/sys/block/%s/device/unload_heads", devname);
34 return 0;
35}
36int valid_disk(void)
37{
38 int fd = open(unload_heads_path, O_RDONLY);
39 if (fd < 0) {
40 perror(unload_heads_path);
41 return 0;
42 }
43
44 close(fd);
45 return 1;
46}
47
22void write_int(char *path, int i) 48void write_int(char *path, int i)
23{ 49{
24 char buf[1024]; 50 char buf[1024];
@@ -42,7 +68,7 @@ void set_led(int on)
42 68
43void protect(int seconds) 69void protect(int seconds)
44{ 70{
45 write_int("/sys/block/sda/device/unload_heads", seconds*1000); 71 write_int(unload_heads_path, seconds*1000);
46} 72}
47 73
48int on_ac(void) 74int on_ac(void)
@@ -61,14 +87,27 @@ void ignore_me(void)
61 set_led(0); 87 set_led(0);
62} 88}
63 89
64int main(int argc, char *argv[]) 90int main(int argc, char **argv)
65{ 91{
66 int fd, ret; 92 int fd, ret;
67 struct sched_param param; 93 struct sched_param param;
68 94
95 if (argc == 1)
96 ret = set_unload_heads_path("/dev/sda");
97 else if (argc == 2)
98 ret = set_unload_heads_path(argv[1]);
99 else
100 ret = -EINVAL;
101
102 if (ret || !valid_disk()) {
103 fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n",
104 argv[0]);
105 exit(1);
106 }
107
69 fd = open("/dev/freefall", O_RDONLY); 108 fd = open("/dev/freefall", O_RDONLY);
70 if (fd < 0) { 109 if (fd < 0) {
71 perror("open"); 110 perror("/dev/freefall");
72 return EXIT_FAILURE; 111 return EXIT_FAILURE;
73 } 112 }
74 113