From 102a0743326a03cd1a1202ceda21e175b7d3575c Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Tue, 20 Feb 2024 01:20:52 +0000 Subject: [PATCH] add new system file --- kernel/lib/test_sysctl.c | 37 +++++++++++++++++++++++++++++++++---- 1 files changed, 33 insertions(+), 4 deletions(-) diff --git a/kernel/lib/test_sysctl.c b/kernel/lib/test_sysctl.c index 3dd801c..3750323 100644 --- a/kernel/lib/test_sysctl.c +++ b/kernel/lib/test_sysctl.c @@ -16,7 +16,7 @@ */ /* - * This module provides an interface to the the proc sysctl interfaces. This + * This module provides an interface to the proc sysctl interfaces. This * driver requires CONFIG_PROC_SYSCTL. It will not normally be loaded by the * system unless explicitly requested by name. You can also build this driver * into your kernel. @@ -44,9 +44,14 @@ int int_0002; int int_0003[4]; + int boot_int; + unsigned int uint_0001; char string_0001[65]; + +#define SYSCTL_TEST_BITMAP_SIZE 65536 + unsigned long *bitmap_0001; }; static struct test_sysctl_data test_data = { @@ -57,6 +62,8 @@ .int_0003[1] = 1, .int_0003[2] = 2, .int_0003[3] = 3, + + .boot_int = 0, .uint_0001 = 314, @@ -89,6 +96,15 @@ .proc_handler = proc_dointvec, }, { + .procname = "boot_int", + .data = &test_data.boot_int, + .maxlen = sizeof(test_data.boot_int), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { .procname = "uint_0001", .data = &test_data.uint_0001, .maxlen = sizeof(unsigned int), @@ -101,6 +117,13 @@ .maxlen = sizeof(test_data.string_0001), .mode = 0644, .proc_handler = proc_dostring, + }, + { + .procname = "bitmap_0001", + .data = &test_data.bitmap_0001, + .maxlen = SYSCTL_TEST_BITMAP_SIZE, + .mode = 0644, + .proc_handler = proc_do_large_bitmap, }, { } }; @@ -129,15 +152,21 @@ static int __init test_sysctl_init(void) { - test_sysctl_header = register_sysctl_table(test_sysctl_root_table); - if (!test_sysctl_header) + test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL); + if (!test_data.bitmap_0001) return -ENOMEM; + test_sysctl_header = register_sysctl_table(test_sysctl_root_table); + if (!test_sysctl_header) { + kfree(test_data.bitmap_0001); + return -ENOMEM; + } return 0; } -late_initcall(test_sysctl_init); +module_init(test_sysctl_init); static void __exit test_sysctl_exit(void) { + kfree(test_data.bitmap_0001); if (test_sysctl_header) unregister_sysctl_table(test_sysctl_header); } -- Gitblit v1.6.2