From: Thadeu Lima de Souza Cascardo Date: Sat, 5 Dec 2009 14:26:00 +0000 (-0200) Subject: Implement procfs demonstration. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fkernel%2Fsamples%2F03.proc%2F.git;a=commitdiff_plain;h=f00589a76b75592dfcfdec48a279bdd1122ad0d0;hp=b437b7b6ba61ac9e881180f167162cb34d2095ae Implement procfs demonstration. --- diff --git a/hello_procfs.c b/hello_procfs.c index 1390972..a78eff8 100644 --- a/hello_procfs.c +++ b/hello_procfs.c @@ -19,17 +19,65 @@ #include #include +#include MODULE_AUTHOR("Thadeu Lima de Souza Cascardo "); MODULE_LICENSE("GPL"); +static int hello_show(struct seq_file *file, void *data) +{ + seq_puts(file, "Hello, world!\n"); + return 0; +} + +#if 0 +static void * hello_start(struct seq_file *file, loff_t *pos) +{ + return NULL; +} + +static void hello_stop(struct seq_file *file, void *data) +{ +} + +static void * hello_next(struct seq_file *file, void *data, loff_t *pos) +{ + return NULL; +} + +static const struct seq_operations hello_seqops = +{ + .start = hello_start, + .stop = hello_stop, + .next = hello_next, + .show = hello_show, +}; +#endif + +static int hello_procfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, hello_show, NULL); +} + +static const struct file_operations hello_procfs_fops = +{ + .open = hello_procfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + static int hello_procfs_init(void) { + struct proc_dir_entry *entry; + entry = create_proc_entry("gnu", 0666, NULL); + entry->proc_fops = &hello_procfs_fops; return 0; } static void hello_procfs_exit(void) { + remove_proc_entry("gnu", NULL); } module_init(hello_procfs_init);