具体的实现可以参考linux内核的scsi硬盘里class类的实现,这里只是简单的使用实例
#include
#include
#include
MODULE_LICENSE("GPL");
static ssize_t example_show(struct class_device *cdev,char *buf)
{
printk("==>%s\n",__FUNCTION__);
return snprintf(buf,40,"%s\n","version 1.0");
}
static ssize_t example_store(struct device *cdev,char *buf)
{
return 1;
}
static void example_release(struct class_device *cdev)
{
}
static struct class_device_attribute example_attr[] = {
__ATTR(version,S_IRUGO|S_IWUSR,example_show,example_store),
__ATTR_NULL,
};
static struct class example_class = {
.name = "example",
.owner = THIS_MODULE,
.release = example_release,
.class_dev_attrs = example_attr,
};
static int __init class_init(void)
{
int err;
err = class_register(&example_class);
class_create_file(&example_class,&example_attr[0]);
return err;
}
static void __exit class_exit(void)
{
class_remove_file(&example_class,&example_attr[0]);
class_unregister(&example_class);
}
module_init(class_init);
module_exit(class_exit);
阅读(1718) | 评论(0) | 转发(0) |