1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
From foo@baz Tue Apr 9 12:12:43 2002
Date: Tue, 09 Apr 2002 12:14:34 -0700
To: Greg KH <greg@kroah.com>
From: Greg Kroah-Hartman <gregkh@suse.de>
Subject: debugfs example code
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
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 <greg@kroah.com>
+ * 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 <linux/config.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/mount.h>
+#include <linux/pagemap.h>
+#include <linux/init.h>
+#include <linux/namei.h>
+#include <linux/debugfs.h>
+
+
+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");
+
|