From: Frans Pop <elendil@planet.nl>
To: linux-kernel@vger.kernel.org
Cc: Jiri Kosina <trivial@kernel.org>,
Christian Thaeter <ct@pipapo.org>, Pavel Machek <pavel@ucw.cz>
Subject: [PATCH 2/2] hpfall: accept disk device to unload as argument
Date: Sat, 25 Jul 2009 21:00:12 +0200 [thread overview]
Message-ID: <200907252100.14175.elendil@planet.nl> (raw)
In-Reply-To: <200907252055.16416.elendil@planet.nl>
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: Pavel Machek <pavel@ucw.cz>
Cc: Christian Thaeter <ct@pipapo.org>
diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c
index a3cfe1a..681ec22 100644
--- a/Documentation/hwmon/hpfall.c
+++ b/Documentation/hwmon/hpfall.c
@@ -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];
@@ -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)
@@ -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;
}
next prev parent reply other threads:[~2009-07-25 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-25 18:55 [PATCH 1/2] hpfall: reduce risk that hpfall can do harm Frans Pop
2009-07-25 19:00 ` Frans Pop [this message]
2009-07-25 20:48 ` [PATCH 2/2] hpfall: accept disk device to unload as argument Pavel Machek
2009-08-08 1:03 ` Jiri Kosina
2009-08-08 1:01 ` [PATCH 1/2] hpfall: reduce risk that hpfall can do harm Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200907252100.14175.elendil@planet.nl \
--to=elendil@planet.nl \
--cc=ct@pipapo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=trivial@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®