嘿,我正在尝试使用sysfs一点点,从用户空间获取一些数据到我的内核模块.这是代码:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/elf.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#define PRINT(x) printk(KERN_INFO x "\n")
#define ERROR(fmt,arg...) printk(KERN_ALERT "Error - " fmt,##arg)
ssize_t mystore (struct kobject *obj,
struct attribute *attr, const char *buff, size_t count)
{
/* doing a little bit */
return count;
}
ssize_t myshow (struct kobject *obj, struct attribute *attr, char *buff)
{
return 0;
}
char file_name[] = "myfile";
static struct attribute myattribute = {
.name = file_name,
.mode …Run Code Online (Sandbox Code Playgroud)