Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164574
b: refs/heads/master
c: be3990b
h: refs/heads/master
v: v3
  • Loading branch information
Frans Pop authored and Jiri Kosina committed Sep 21, 2009
1 parent 59e932c commit 7344b0a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2bace8b95108746f6123d312f47f5bda4eb17a26
refs/heads/master: be3990b7efbe8784fe063fb6871a772c0703891a
45 changes: 42 additions & 3 deletions trunk/Documentation/hwmon/hpfall.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@
#include <sys/mman.h>
#include <sched.h>

char unload_heads_path[64];

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

snprintf(unload_heads_path, sizeof(unload_heads_path),
"/sys/block/%s/device/unload_heads", devname);
return 0;
}
int valid_disk(void)
{
int fd = open(unload_heads_path, O_RDONLY);
if (fd < 0) {
perror(unload_heads_path);
return 0;
}

close(fd);
return 1;
}

void write_int(char *path, int i)
{
char buf[1024];
Expand All @@ -42,7 +68,7 @@ void set_led(int on)

void protect(int seconds)
{
write_int("/sys/block/sda/device/unload_heads", seconds*1000);
write_int(unload_heads_path, seconds*1000);
}

int on_ac(void)
Expand All @@ -61,14 +87,27 @@ void ignore_me(void)
set_led(0);
}

int main(int argc, char *argv[])
int main(int argc, char **argv)
{
int fd, ret;
struct sched_param param;

if (argc == 1)
ret = set_unload_heads_path("/dev/sda");
else if (argc == 2)
ret = set_unload_heads_path(argv[1]);
else
ret = -EINVAL;

if (ret || !valid_disk()) {
fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n",
argv[0]);
exit(1);
}

fd = open("/dev/freefall", O_RDONLY);
if (fd < 0) {
perror("open");
perror("/dev/freefall");
return EXIT_FAILURE;
}

Expand Down

0 comments on commit 7344b0a

Please sign in to comment.