#include #include #include static struct dentry *d_debugfs; static struct dentry *data_file; #define TST_DFS "dfs" static int yy = 21; static int n = 42; char data[PAGE_SIZE]; int data_size = 0; struct debugfs_blob_wrapper w_data; static ssize_t m_read(struct file *f, char *buffer, size_t len, loff_t *offset) { pr_info("m_read\n"); return simple_read_from_buffer(buffer, len, offset, data, data_size); } static ssize_t m_write(struct file *f, const char *buffer, size_t len, loff_t *offset) { ssize_t ret; pr_info("m_write\n"); ret = simple_write_to_buffer(data, PAGE_SIZE, offset, buffer, len); if (ret < 0) return ret; data_size = ret; pr_info("m_write: data size=%d\n", data_size); return len; } const struct file_operations fops = { .write = m_write, .read = m_read, }; int notify_param(const char *val, const struct kernel_param *kp) { int r = param_set_int(val, kp); if (r == 0) { pr_info("call back ...\n"); pr_info("n val: n=%d\n", n); return 0; } return -1; } int view_param(char *val, const struct kernel_param *kp) { int r = param_get_int(val, kp); yy++; pr_info("view (%d/%s)\n", r, val); return r; } const struct kernel_param_ops my_param_ops = { .set = ¬ify_param, .get = &view_param, // .get = ¶m_get_int; }; module_param_cb(name_n, &my_param_ops, &n, 0660); MODULE_PARM_DESC(n, "un entier"); int init_module(void) { pr_info("kparm debugs BEGIN\n"); pr_crit("n=%d\n", n); d_debugfs = debugfs_create_dir(TST_DFS, NULL); if (d_debugfs == NULL) { return -ENOENT; } debugfs_create_u32("n", 0660, d_debugfs, &yy); data_file = debugfs_create_file("f0", 0660, d_debugfs, NULL, &fops); w_data.data = "TEST"; w_data.size = strlen(w_data.data); debugfs_create_blob("TST_B", 0660, d_debugfs, &w_data); return 0; } void cleanup_module(void) { pr_crit("n=%d\n", n); debugfs_remove_recursive(d_debugfs); pr_info("kparm debugfs END\n"); } MODULE_LICENSE("GPL");