On Thu, Dec 11, 2003 at 09:15:50AM -0600, Jack O'Quin wrote: > I've been looking at that, and plan to do it next. A good example is > always helpful. It can help to avoid missing some subtle detail, > especially important for kernel-mode programming.
Here is some of the boilerplate code we used. Also have code to make a proc dir and use it, so instead of /proc/realtime or what not, you could have /proc/realtime/a, /proc/realtime/b, etc. Also have code to do a read/write proc file. These are against linux-2.4. Haven't played with proc on 2.6, yet. #include <linux/proc_fs.h> #ifdef CONFIG_PROC_FS static struct proc_dir_entry *proc_foo; #endif init(...) { ... #ifdef CONFIG_PROC_FS proc_foo = create_proc_read_entry("foo", 0, NULL, foo_read_proc, NULL); if (!proc_foo { printk(KERN_ERR "can't create /proc/foo\n"); } #endif ... } cleanup(...) { ... remove_proc_entry("foo", NULL); ... } #ifdef CONFIG_PROC_FS static int foo_read_proc(char *buf, char **start, off_t pos, int len, int *eof, void *x) { int plen; plen = sprintf(buf, "%s\n", foo); /* trying to read a bad offset? */ if (pos >= plen) { *eof = 1; return 0; } /* did we write everything we wanted to? */ if (len >= (plen-pos)) { *eof = 1; } *start = buf + pos; plen -= pos; return (len > plen) ? plen : len; } #endif