Advertisement
Guest User

sysctl_module

a guest
Feb 23rd, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/sysctl.h>
  4.  
  5.  
  6. static struct ctl_table_header * test_sysctl_header1;
  7. static struct ctl_table_header * test_sysctl_header2;
  8.  
  9. int value1 = 0;
  10. int value2 = 1;
  11.  
  12. int min = 10;
  13. int max = 20;
  14.  
  15. /*only values between min and max can be written to value1 and value2 respectively. */
  16. static ctl_table test_table1[] = {
  17. {
  18. .ctl_name = CTL_UNNUMBERED,
  19. .procname = "value1",
  20. .data = &value1,
  21. .maxlen = sizeof(int),
  22. .mode = 0644,
  23. .proc_handler = &proc_dointvec_minmax,
  24. .strategy = &sysctl_intvec,
  25. .extra1 = &min,
  26. .extra2 = &max
  27. },
  28. {
  29. .ctl_name = CTL_UNNUMBERED,
  30. .procname = "value2",
  31. .data = &value2,
  32. .maxlen = sizeof(int),
  33. .mode = 0644,
  34. .proc_handler = &proc_dointvec_minmax,
  35. .strategy = &sysctl_intvec,
  36. .extra1 = &min,
  37. .extra2 = &max
  38. },
  39. { .ctl_name = 0 }
  40. };
  41.  
  42. static ctl_table test_table2[] = {
  43. {
  44. .ctl_name = CTL_UNNUMBERED,
  45. .procname = "value1",
  46. .data = &value1,
  47. .maxlen = sizeof(int),
  48. .mode = 0644,
  49. .proc_handler = &proc_dointvec_minmax,
  50. .strategy = &sysctl_intvec,
  51. .extra1 = &min,
  52. .extra2 = &max
  53. },
  54. {
  55. .ctl_name = CTL_UNNUMBERED,
  56. .procname = "value2",
  57. .data = &value2,
  58. .maxlen = sizeof(int),
  59. .mode = 0644,
  60. .proc_handler = &proc_dointvec_minmax,
  61. .strategy = &sysctl_intvec,
  62. .extra1 = &min,
  63. .extra2 = &max
  64. },
  65. { .ctl_name = 0 }
  66. };
  67.  
  68. static ctl_table test_net_table1[] = {
  69. {
  70. .ctl_name = CTL_UNNUMBERED,
  71. .procname = "test1",
  72. .mode = 0555,
  73. .child = test_table1
  74. },
  75. { .ctl_name = 0 }
  76. };
  77.  
  78. static ctl_table test_net_table2[] = {
  79. {
  80. .ctl_name = CTL_UNNUMBERED,
  81. .procname = "test2",
  82. .mode = 0555,
  83. .child = test_table2
  84. },
  85. { .ctl_name = 0 }
  86. };
  87.  
  88. static ctl_table test_root_table1[] = {
  89. {
  90. .ctl_name = CTL_UNNUMBERED,
  91. .procname = "net1",
  92. .mode = 0555,
  93. .child = test_net_table1
  94. },
  95. { .ctl_name = 0 }
  96. };
  97.  
  98. static ctl_table test_root_table2[] = {
  99. {
  100. .ctl_name = CTL_UNNUMBERED,
  101. .procname = "net2",
  102. .mode = 0555,
  103. .child = test_net_table2
  104. },
  105. { .ctl_name = 0 }
  106. };
  107.  
  108.  
  109. static struct ctl_path net1_path[] = {
  110. { .procname = "my_net", .ctl_name = CTL_UNNUMBERED },
  111. { }
  112. };
  113.  
  114.  
  115. static int __init sysctl_module_init(void)
  116. {
  117. test_sysctl_header1 = register_sysctl_paths(net1_path, test_root_table1);
  118. test_sysctl_header2 = register_sysctl_paths(net1_path, test_root_table2);
  119. return 0;
  120. }
  121.  
  122. static void __exit sysctl_module_exit(void)
  123. {
  124. unregister_sysctl_table(test_sysctl_header1);
  125. unregister_sysctl_table(test_sysctl_header2);
  126. }
  127.  
  128. module_init(sysctl_module_init);
  129. module_exit(sysctl_module_exit);
  130. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement