diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-02-20 09:07:22 -0500 |
---|---|---|
committer | Alexey Dobriyan <adobriyan@gmail.com> | 2009-03-30 17:14:58 -0400 |
commit | a9caa3de249a6c43bc9c6aec87881f09276677e3 (patch) | |
tree | 900831b12af9b3cd4743d4ae5ed5a457f8125edb /fs/proc/uptime.c | |
parent | 99b76233803beab302123d243eea9e41149804f3 (diff) |
Revert "proc: revert /proc/uptime to ->read_proc hook"
This reverts commit 6c87df37dcb9c6c33923707fa5191e0a65874d60.
proc files implemented through seq_file do pread(2) now.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Diffstat (limited to 'fs/proc/uptime.c')
-rw-r--r-- | fs/proc/uptime.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c index df26aa88fa47..0c10a0b3f146 100644 --- a/fs/proc/uptime.c +++ b/fs/proc/uptime.c | |||
@@ -1,45 +1,43 @@ | |||
1 | #include <linux/fs.h> | ||
1 | #include <linux/init.h> | 2 | #include <linux/init.h> |
2 | #include <linux/proc_fs.h> | 3 | #include <linux/proc_fs.h> |
3 | #include <linux/sched.h> | 4 | #include <linux/sched.h> |
5 | #include <linux/seq_file.h> | ||
4 | #include <linux/time.h> | 6 | #include <linux/time.h> |
5 | #include <asm/cputime.h> | 7 | #include <asm/cputime.h> |
6 | 8 | ||
7 | static int proc_calc_metrics(char *page, char **start, off_t off, | 9 | static int uptime_proc_show(struct seq_file *m, void *v) |
8 | int count, int *eof, int len) | ||
9 | { | ||
10 | if (len <= off + count) | ||
11 | *eof = 1; | ||
12 | *start = page + off; | ||
13 | len -= off; | ||
14 | if (len > count) | ||
15 | len = count; | ||
16 | if (len < 0) | ||
17 | len = 0; | ||
18 | return len; | ||
19 | } | ||
20 | |||
21 | static int uptime_read_proc(char *page, char **start, off_t off, int count, | ||
22 | int *eof, void *data) | ||
23 | { | 10 | { |
24 | struct timespec uptime; | 11 | struct timespec uptime; |
25 | struct timespec idle; | 12 | struct timespec idle; |
26 | int len; | ||
27 | cputime_t idletime = cputime_add(init_task.utime, init_task.stime); | 13 | cputime_t idletime = cputime_add(init_task.utime, init_task.stime); |
28 | 14 | ||
29 | do_posix_clock_monotonic_gettime(&uptime); | 15 | do_posix_clock_monotonic_gettime(&uptime); |
30 | monotonic_to_bootbased(&uptime); | 16 | monotonic_to_bootbased(&uptime); |
31 | cputime_to_timespec(idletime, &idle); | 17 | cputime_to_timespec(idletime, &idle); |
32 | len = sprintf(page, "%lu.%02lu %lu.%02lu\n", | 18 | seq_printf(m, "%lu.%02lu %lu.%02lu\n", |
33 | (unsigned long) uptime.tv_sec, | 19 | (unsigned long) uptime.tv_sec, |
34 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), | 20 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), |
35 | (unsigned long) idle.tv_sec, | 21 | (unsigned long) idle.tv_sec, |
36 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); | 22 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); |
37 | return proc_calc_metrics(page, start, off, count, eof, len); | 23 | return 0; |
38 | } | 24 | } |
39 | 25 | ||
26 | static int uptime_proc_open(struct inode *inode, struct file *file) | ||
27 | { | ||
28 | return single_open(file, uptime_proc_show, NULL); | ||
29 | } | ||
30 | |||
31 | static const struct file_operations uptime_proc_fops = { | ||
32 | .open = uptime_proc_open, | ||
33 | .read = seq_read, | ||
34 | .llseek = seq_lseek, | ||
35 | .release = single_release, | ||
36 | }; | ||
37 | |||
40 | static int __init proc_uptime_init(void) | 38 | static int __init proc_uptime_init(void) |
41 | { | 39 | { |
42 | create_proc_read_entry("uptime", 0, NULL, uptime_read_proc, NULL); | 40 | proc_create("uptime", 0, NULL, &uptime_proc_fops); |
43 | return 0; | 41 | return 0; |
44 | } | 42 | } |
45 | module_init(proc_uptime_init); | 43 | module_init(proc_uptime_init); |