c - Create sysfs entry from kernel module -


i want pass string > 1024 chars module (filesystem). kernel parameters limited 1024 chars, someone recommended use sysfs instead.

i tried include this example in super.c class create string 'filename' & string 'code' entry in sysfs module.

static decl_subsys(myfs, null, null);  struct myfs_attr {     struct attribute attr;     char *value; };  static struct myfs_attr fname = {     .attr.name="filename",     .attr.owner = this_module,     .attr.mode = 0644,     .value = "/my/test/path", };  static struct myfs_attr code = {     .attr.name="code",     .attr.owner = this_module,     .attr.mode = 0644,     .value = "0101", }; 

when compiling module lot of errors (line 41 decl_subsys):

fs/myfs/super.c:41:26: error: expected ‘)’ before ‘(’ token fs/myfs/super.c:50:2: error: unknown field ‘owner’ specified in initializer fs/myfs/super.c:50:2: warning: initialization incompatible pointer type [enabled default] fs/myfs/super.c:50:2: warning: (near initialization ‘fname.attr.name’) [enabled default] ... fs/myfs/super.c: @ top level: fs/myfs/super.c:83:15: error: variable ‘myfsops’ has initializer incomplete type fs/myfs/super.c:84:2: error: unknown field ‘show’ specified in initializer fs/myfs/super.c:84:2: warning: excess elements in struct initializer [enabled default] fs/myfs/super.c:84:2: warning: (near initialization ‘myfsops’) [enabled default] fs/myfs/super.c:85:2: error: unknown field ‘store’ specified in initializer fs/myfs/super.c:85:2: warning: excess elements in struct initializer [enabled default] fs/myfs/super.c:85:2: warning: (near initialization ‘myfsops’) [enabled default] fs/myfs/super.c:89:2: error: unknown field ‘myfs_ops’ specified in initializer fs/myfs/super.c:89:2: warning: initialization incompatible pointer type [enabled default] fs/myfs/super.c:89:2: warning: (near initialization ‘myfstype.release’) [enabled default] fs/myfs/super.c: in function ‘init_myfs_fs’: fs/myfs/super.c:1554:2: error: implicit declaration of function ‘kobj_set_kset_s’ [-werror=implicit-function-declaration] fs/myfs/super.c:1554:19: error: ‘myfs_subsys’ undeclared (first use in function) fs/myfs/super.c:1554:19: note: each undeclared identifier reported once each function appears in fs/myfs/super.c:1554:32: error: ‘fs_subsys’ undeclared (first use in function) fs/myfs/super.c:1557:2: error: implicit declaration of function ‘subsystem_register’ [-werror=implicit-function-declaration] fs/myfs/super.c: in function ‘exit_myfs_fs’: fs/myfs/super.c:1579:2: error: implicit declaration of function ‘subsystem_unregister’ [-werror=implicit-function-declaration] fs/myfs/super.c:1579:24: error: ‘myfs_subsys’ undeclared (first use in function) 
  1. is tutorial outdated 3.5 kernel or missing else?
  2. how create 2 char string entries module in sysfs?

here source code transmitting data "param_buf" string. requested, without read method. store.

#include <linux/init.h> #include <linux/module.h> #include <linux/slab.h> #include <asm/string.h>  static struct kobject *register_kobj; static char *param_buf;  // function many symbol data enter static ssize_t __used store_value(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count){      printk(kern_alert "you entered %s\n", buf);     strncpy(param_buf, buf, page_size - 1);     return count; }  // register function attribute static struct kobj_attribute store_val_attribute = __attr( put_parameters, 0220, null, store_value);  // put attribute attribute group static struct attribute *register_attrs[] = {     &store_val_attribute.attr,     null,   /* null terminate list*/ }; static struct attribute_group  reg_attr_group = {     .attrs = register_attrs };  static int hello_init(void){     param_buf = kzalloc(page_size, gfp_kernel);     // create sysfs object ( /sys/kernel/test_1025_sym directory )     register_kobj = kobject_create_and_add("test_1025_sym", kernel_kobj);     if (!register_kobj)     return -enomem;      //create attributes (files)     if(sysfs_create_group(register_kobj, &reg_attr_group)){         kobject_put(register_kobj);         return -enomem;     }      return 0; }  static void hello_exit(void){     printk(kern_alert "last value %s\n", param_buf);     kfree(param_buf);     kobject_put(register_kobj); }  module_license("dual bsd/gpl"); module_init(hello_init); module_exit(hello_exit); 

you can test in such way:

cat /etc/fstab > /sys/kernel/test_1025_sym/put_parameters 

for 2 string entries: copy store_value function, register 1 more store_val_attribute , put attributes list.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -