2 * proc sysctl test driver
4 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or at your option any
9 * later version; or, when distributed separately from the Linux kernel or
10 * when incorporated into other software packages, subject to the following
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of copyleft-next (version 0.3.1 or later) as published
15 * at http://copyleft-next.org/.
19 * This module provides an interface to the the proc sysctl interfaces. This
20 * driver requires CONFIG_PROC_SYSCTL. It will not normally be loaded by the
21 * system unless explicitly requested by name. You can also build this driver
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/init.h>
28 #include <linux/list.h>
29 #include <linux/module.h>
30 #include <linux/printk.h>
32 #include <linux/miscdevice.h>
33 #include <linux/slab.h>
34 #include <linux/uaccess.h>
35 #include <linux/async.h>
36 #include <linux/delay.h>
37 #include <linux/vmalloc.h>
40 static int i_one_hundred
= 100;
42 struct test_sysctl_data
{
47 unsigned int uint_0001
;
51 #define SYSCTL_TEST_BITMAP_SIZE 65536
52 unsigned long *bitmap_0001
;
55 static struct test_sysctl_data test_data
= {
66 .string_0001
= "(none)",
69 /* These are all under /proc/sys/debug/test_sysctl/ */
70 static struct ctl_table test_table
[] = {
72 .procname
= "int_0001",
73 .data
= &test_data
.int_0001
,
74 .maxlen
= sizeof(int),
76 .proc_handler
= proc_dointvec_minmax
,
78 .extra2
= &i_one_hundred
,
81 .procname
= "int_0002",
82 .data
= &test_data
.int_0002
,
83 .maxlen
= sizeof(int),
85 .proc_handler
= proc_dointvec
,
88 .procname
= "int_0003",
89 .data
= &test_data
.int_0003
,
90 .maxlen
= sizeof(test_data
.int_0003
),
92 .proc_handler
= proc_dointvec
,
95 .procname
= "uint_0001",
96 .data
= &test_data
.uint_0001
,
97 .maxlen
= sizeof(unsigned int),
99 .proc_handler
= proc_douintvec
,
102 .procname
= "string_0001",
103 .data
= &test_data
.string_0001
,
104 .maxlen
= sizeof(test_data
.string_0001
),
106 .proc_handler
= proc_dostring
,
109 .procname
= "bitmap_0001",
110 .data
= &test_data
.bitmap_0001
,
111 .maxlen
= SYSCTL_TEST_BITMAP_SIZE
,
113 .proc_handler
= proc_do_large_bitmap
,
118 static struct ctl_table test_sysctl_table
[] = {
120 .procname
= "test_sysctl",
128 static struct ctl_table test_sysctl_root_table
[] = {
133 .child
= test_sysctl_table
,
138 static struct ctl_table_header
*test_sysctl_header
;
140 static int __init
test_sysctl_init(void)
142 test_data
.bitmap_0001
= kzalloc(SYSCTL_TEST_BITMAP_SIZE
/8, GFP_KERNEL
);
143 if (!test_data
.bitmap_0001
)
145 test_sysctl_header
= register_sysctl_table(test_sysctl_root_table
);
146 if (!test_sysctl_header
) {
147 kfree(test_data
.bitmap_0001
);
152 late_initcall(test_sysctl_init
);
154 static void __exit
test_sysctl_exit(void)
156 kfree(test_data
.bitmap_0001
);
157 if (test_sysctl_header
)
158 unregister_sysctl_table(test_sysctl_header
);
161 module_exit(test_sysctl_exit
);
163 MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>");
164 MODULE_LICENSE("GPL");