RW.c:
#include linux/module.h
#include linux/init.h
#include linux/kobject.h
#include linux/kernel.h
#include "RW.h"
static struct kobject *devicesSY_kobj;
static struct kobject *kobj;
struct textattribute testattr = {
.attr = {
.name = "test_attr",
.mode = 0777,
},
.str = "test_attr_str",
};
static ssize_t devicesSY_attr_show(struct kobject *kobj, struct attribute *attr,char *buf)
{
struct textattribute * test;
test = container_of(attr, struct textattribute, attr);
printk("test file str = %s\n",test->str);
printk("test file attr name = %s\n",test->attr.name);
}
static ssize_t devicesSY_attr_store(struct kobject *kobj, struct attribute *attr,const char *buf, size_t count)
{
}
static const struct sysfs_ops devicesSY_sysfs_ops = {
.show = devicesSY_attr_show,
.store = devicesSY_attr_store,
};
int devicesSY_register(void)
{
kobj = kobject_create_and_add("test", devicesSY_kobj);
kobj->ktype->sysfs_ops = &devicesSY_sysfs_ops;
sysfs_create_file(kobj,&(testattr.attr));
return 0;
}
static int devicesSY_init(void)
{
devicesSY_kobj = kobject_create_and_add("devicesSY",NULL);
if (!devicesSY_kobj)
return -ENOMEM;
devicesSY_register();
return 0;
}
static void devicesSY_exit(void)
{
kobject_put(devicesSY_kobj);
kobject_put(kobj);
}
MODULE_AUTHOR("devicesSY");
MODULE_LICENSE("GPL");
module_init(devicesSY_init);
module_exit(devicesSY_exit);
RC.h:
#ifndef _RW_H_
#define _RW_H_
#include
struct textattribute{
struct attribute attr;
char * str;
};
#endif
阅读(4245) | 评论(0) | 转发(0) |