]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - lib/test_sysctl.c
test_sysctl: add simple proc_douintvec() case
[mirror_ubuntu-artful-kernel.git] / lib / test_sysctl.c
CommitLineData
9308f2f9
LR
1/*
2 * proc sysctl test driver
3 *
4 * Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
5 *
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
11 * license:
12 *
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/.
16 */
17
18/*
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
22 * into your kernel.
23 */
24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
27#include <linux/init.h>
28#include <linux/list.h>
29#include <linux/module.h>
30#include <linux/printk.h>
31#include <linux/fs.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>
38
39static int i_zero;
40static int i_one_hundred = 100;
41
42struct test_sysctl_data {
43 int int_0001;
eb965eda
LR
44 int int_0002;
45
2920fad3
LR
46 unsigned int uint_0001;
47
9308f2f9
LR
48 char string_0001[65];
49};
50
51static struct test_sysctl_data test_data = {
52 .int_0001 = 60,
eb965eda
LR
53 .int_0002 = 1,
54
2920fad3
LR
55 .uint_0001 = 314,
56
9308f2f9
LR
57 .string_0001 = "(none)",
58};
59
60/* These are all under /proc/sys/debug/test_sysctl/ */
61static struct ctl_table test_table[] = {
62 {
63 .procname = "int_0001",
64 .data = &test_data.int_0001,
65 .maxlen = sizeof(int),
66 .mode = 0644,
67 .proc_handler = proc_dointvec_minmax,
68 .extra1 = &i_zero,
69 .extra2 = &i_one_hundred,
70 },
eb965eda
LR
71 {
72 .procname = "int_0002",
73 .data = &test_data.int_0002,
74 .maxlen = sizeof(int),
75 .mode = 0644,
76 .proc_handler = proc_dointvec,
77 },
2920fad3
LR
78 {
79 .procname = "uint_0001",
80 .data = &test_data.uint_0001,
81 .maxlen = sizeof(unsigned int),
82 .mode = 0644,
83 .proc_handler = proc_douintvec,
84 },
9308f2f9
LR
85 {
86 .procname = "string_0001",
87 .data = &test_data.string_0001,
88 .maxlen = sizeof(test_data.string_0001),
89 .mode = 0644,
90 .proc_handler = proc_dostring,
91 },
92 { }
93};
94
95static struct ctl_table test_sysctl_table[] = {
96 {
97 .procname = "test_sysctl",
98 .maxlen = 0,
99 .mode = 0555,
100 .child = test_table,
101 },
102 { }
103};
104
105static struct ctl_table test_sysctl_root_table[] = {
106 {
107 .procname = "debug",
108 .maxlen = 0,
109 .mode = 0555,
110 .child = test_sysctl_table,
111 },
112 { }
113};
114
115static struct ctl_table_header *test_sysctl_header;
116
117static int __init test_sysctl_init(void)
118{
119 test_sysctl_header = register_sysctl_table(test_sysctl_root_table);
120 if (!test_sysctl_header)
121 return -ENOMEM;
122 return 0;
123}
124late_initcall(test_sysctl_init);
125
126static void __exit test_sysctl_exit(void)
127{
128 if (test_sysctl_header)
129 unregister_sysctl_table(test_sysctl_header);
130}
131
132module_exit(test_sysctl_exit);
133
134MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>");
135MODULE_LICENSE("GPL");