小编goo*_*999的帖子

从内核模块创建 sysfs 条目

我想将一个大于 1024 个字符的字符串传递给我的模块(文件系统)。由于内核参数限制为 1024 个字符,有人建议改用 sysfs。

我试图在我的 super.c 类中包含这个示例,以便在 sysfs 中为我的模块创建一个字符串 'filename' 和字符串 'code' 条目。

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",
};
Run Code Online (Sandbox Code Playgroud)

编译我的模块时出现很多错误(第 41 行是 decl_subsys):

fs/myfs/super.c:41:26: error: expected ‘)’ before ‘(’ token
fs/myfs/super.c:50:2: error: unknown …
Run Code Online (Sandbox Code Playgroud)

c linux kernel-module linux-kernel sysfs

3
推荐指数
1
解决办法
3914
查看次数

标签 统计

c ×1

kernel-module ×1

linux ×1

linux-kernel ×1

sysfs ×1