From foo@baz Tue Apr 9 12:12:43 2002 Date: Tue, 09 Apr 2002 12:14:34 -0700 To: Greg KH From: Greg Kroah-Hartman Subject: debugfs example code Signed-off-by: Greg Kroah-Hartman --- fs/debugfs/debugfs_example.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) --- /dev/null +++ gregkh-2.6/fs/debugfs/debugfs_example.c @@ -0,0 +1,70 @@ +/* + * debugfs_example.c - Tiny example of how to use debugfs + * + * Copyright (C) 2004 Greg Kroah-Hartman + * Copyright (C) 2004 IBM Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * debugfs is for people to use instead of /proc or /sys. + * See Documentation/fs/debugfs.txt for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +static struct dentry *test_dentry; +static struct dentry *test_dir; +static struct dentry *test_u32_dentry; +static u32 value = 42; + + +static ssize_t example_read_file(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char buf[10]; + + sprintf(buf, "foo\n"); + return simple_read_from_buffer(user_buf, count, ppos, buf, sizeof(buf)); +} + + +static int example_open(struct inode *inode, struct file *file) +{ + return 0; +} + +static struct file_operations example_file_operations = { + .read = example_read_file, + .open = example_open, +}; + +static int __init test_init(void) +{ + test_dir = debugfs_create_dir("foo_dir", NULL); + test_dentry = debugfs_create_file("foo", 0444, test_dir, NULL, &example_file_operations); + test_u32_dentry = debugfs_create_u32("foo_u32", 0444, test_dir, &value); + return 0; +} + +static void __exit test_exit(void) +{ + debugfs_remove(test_u32_dentry); + debugfs_remove(test_dentry); + debugfs_remove(test_dir); +} + +module_init(test_init); +module_exit(test_exit); +MODULE_LICENSE("GPL"); +