~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/test_sysctl.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.11 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.84 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.154 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.201 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.201 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.77 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 39 static int i_zero;
 40 static int i_one_hundred = 100;
 41 
 42 struct test_sysctl_data {
 43         int int_0001;
 44         int int_0002;
 45         int int_0003[4];
 46 
 47         unsigned int uint_0001;
 48 
 49         char string_0001[65];
 50 };
 51 
 52 static struct test_sysctl_data test_data = {
 53         .int_0001 = 60,
 54         .int_0002 = 1,
 55 
 56         .int_0003[0] = 0,
 57         .int_0003[1] = 1,
 58         .int_0003[2] = 2,
 59         .int_0003[3] = 3,
 60 
 61         .uint_0001 = 314,
 62 
 63         .string_0001 = "(none)",
 64 };
 65 
 66 /* These are all under /proc/sys/debug/test_sysctl/ */
 67 static struct ctl_table test_table[] = {
 68         {
 69                 .procname       = "int_0001",
 70                 .data           = &test_data.int_0001,
 71                 .maxlen         = sizeof(int),
 72                 .mode           = 0644,
 73                 .proc_handler   = proc_dointvec_minmax,
 74                 .extra1         = &i_zero,
 75                 .extra2         = &i_one_hundred,
 76         },
 77         {
 78                 .procname       = "int_0002",
 79                 .data           = &test_data.int_0002,
 80                 .maxlen         = sizeof(int),
 81                 .mode           = 0644,
 82                 .proc_handler   = proc_dointvec,
 83         },
 84         {
 85                 .procname       = "int_0003",
 86                 .data           = &test_data.int_0003,
 87                 .maxlen         = sizeof(test_data.int_0003),
 88                 .mode           = 0644,
 89                 .proc_handler   = proc_dointvec,
 90         },
 91         {
 92                 .procname       = "uint_0001",
 93                 .data           = &test_data.uint_0001,
 94                 .maxlen         = sizeof(unsigned int),
 95                 .mode           = 0644,
 96                 .proc_handler   = proc_douintvec,
 97         },
 98         {
 99                 .procname       = "string_0001",
100                 .data           = &test_data.string_0001,
101                 .maxlen         = sizeof(test_data.string_0001),
102                 .mode           = 0644,
103                 .proc_handler   = proc_dostring,
104         },
105         { }
106 };
107 
108 static struct ctl_table test_sysctl_table[] = {
109         {
110                 .procname       = "test_sysctl",
111                 .maxlen         = 0,
112                 .mode           = 0555,
113                 .child          = test_table,
114         },
115         { }
116 };
117 
118 static struct ctl_table test_sysctl_root_table[] = {
119         {
120                 .procname       = "debug",
121                 .maxlen         = 0,
122                 .mode           = 0555,
123                 .child          = test_sysctl_table,
124         },
125         { }
126 };
127 
128 static struct ctl_table_header *test_sysctl_header;
129 
130 static int __init test_sysctl_init(void)
131 {
132         test_sysctl_header = register_sysctl_table(test_sysctl_root_table);
133         if (!test_sysctl_header)
134                 return -ENOMEM;
135         return 0;
136 }
137 late_initcall(test_sysctl_init);
138 
139 static void __exit test_sysctl_exit(void)
140 {
141         if (test_sysctl_header)
142                 unregister_sysctl_table(test_sysctl_header);
143 }
144 
145 module_exit(test_sysctl_exit);
146 
147 MODULE_AUTHOR("Luis R. Rodriguez <mcgrof@kernel.org>");
148 MODULE_LICENSE("GPL");
149 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp