3

モジュール (ファイルシステム) に 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",
};

モジュールをコンパイルすると、多くのエラーが発生します (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 from incompatible pointer type [enabled by default]
fs/myfs/super.c:50:2: warning: (near initialization for ‘fname.attr.name’) [enabled by default]
...
fs/myfs/super.c: At top level:
fs/myfs/super.c:83:15: error: variable ‘myfsops’ has initializer but 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 by default]
fs/myfs/super.c:84:2: warning: (near initialization for ‘myfsops’) [enabled by 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 by default]
fs/myfs/super.c:85:2: warning: (near initialization for ‘myfsops’) [enabled by default]
fs/myfs/super.c:89:2: error: unknown field ‘myfs_ops’ specified in initializer
fs/myfs/super.c:89:2: warning: initialization from incompatible pointer type [enabled by default]
fs/myfs/super.c:89:2: warning: (near initialization for ‘myfstype.release’) [enabled by 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 this function)
fs/myfs/super.c:1554:19: note: each undeclared identifier is reported only once for each function it appears in
fs/myfs/super.c:1554:32: error: ‘fs_subsys’ undeclared (first use in this 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 this function)
  1. このチュートリアルは私の 3.5 カーネルでは古くなっているのでしょうか、それとも他に何か不足しているのでしょうか?
  2. sysfs でモジュールの 2 つの文字列エントリを作成するにはどうすればよいですか?
4

1 に答える 1