2017-01-20 22 views
0

"属性"構造体を使ってsysfsエントリを作成したいと思います。これを行う方法は、次のように__ATTRマクロを使用することです。__ATTRマクロはLinuxカーネルでどのように使用されますか?

static ssize_t functionCalledOnRead(struct kobject *, struct attribute *, char *); 
static ssize_t functionCalledOnRead(struct kobject *, struct attribute *, char *); 

static struct attribute genericSysfsAttribute = __ATTR(attr_name, S_IRUGO | S_IRUSR, functionCalledOnRead, functionCalledOnWrite); 

ただし、これは機能しません。

/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: warning: braces around scalar initializer 
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: warning: (near initialization for 'genericSysfsAttribute.name') 
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: error: field name not in record or union initializer 
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: error: (near initialization for 'genericSysfsAttribute.name') 
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: error: field name not in record or union initializer 
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:15: error: (near initialization for 'genericSysfsAttribute.name') 
In file included from include/linux/thread_info.h:11:0, 
       from include/asm-generic/preempt.h:4, 
       from arch/arm/include/generated/asm/preempt.h:1, 
       from include/linux/preempt.h:59, 
       from include/linux/spinlock.h:50, 
       from include/linux/seqlock.h:35, 
       from include/linux/time.h:5, 
       from include/linux/stat.h:18, 
       from include/linux/module.h:10, 
       from /home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:2: 
include/linux/bug.h:34:45: warning: excess elements in scalar initializer 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: warning: (near initialization for 'genericSysfsAttribute.name') 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: error: unknown field 'show' specified in initializer 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: warning: initialization makes integer from pointer without a cast 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: warning: (near initialization for 'genericSysfsAttribute.mode') 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: error: initializer element is not computable at load time 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: error: (near initialization for 'genericSysfsAttribute.mode') 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: error: unknown field 'store' specified in initializer 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: warning: excess elements in struct initializer 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
include/linux/bug.h:34:45: warning: (near initialization for 'genericSysfsAttribute') 
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 
              ^
include/linux/kernel.h:842:3: note: in expansion of macro 'BUILD_BUG_ON_ZERO' 
    BUILD_BUG_ON_ZERO((perms) & 2) +  \ 
^
include/linux/sysfs.h:102:12: note: in expansion of macro 'VERIFY_OCTAL_PERMISSIONS' 
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 
      ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:49: note: in expansion of macro '__ATTR' 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
               ^
/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.c:32:25: warning: 'genericSysfsAttribute' defined but not used [-Wunused-variable] 
static struct attribute genericSysfsAttribute = __ATTR(attr_name,S_IRUGO | S_IRUSR,functionCalledOnRead,functionCalledOnWrite); 
         ^
scripts/Makefile.build:297: recipe for target '/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.o' failed 
make[2]: *** [/home/osboxes/Documents/kernel_modules/sysfsmodule/sysfsmodule.o] Error 1 
Makefile:1425: recipe for target '_module_/home/osboxes/Documents/kernel_modules/sysfsmodule' failed 
make[1]: *** [_module_/home/osboxes/Documents/kernel_modules/sysfsmodule] Error 2 
make[1]: Leaving directory '/home/osboxes/Documents/linux-mykonos' 
Makefile:7: recipe for target 'cross' failed 
make: *** [cross] Error 2 

私が書いたコードではなく、含まれているコードについて話しているので、これらのエラーのほとんどが何を言っているのか分かりません。しかし、最初の引数は単なる名前であり、2番目の引数は単なる数値であるため、それらに何か問題があるとは思わないので、その2つの関数の名前をどのように与えるかとは働いていない。このような関数をどのように渡しますか?

答えて

0

マクロ__ATTRは直接使用するためではなく、kobjectのための型を定義し、struct attribute「由来」の属性構造を作成サブシステム開発者が使用のために。

はまた、平野struct attributea little senceがあります

裸の属性は 属性の値を読み書きする手段を全く含まれていません。サブシステムには、特定のオブジェクトタイプ の属性を追加および削除するための独自の属性 構造体およびラッパー関数を定義することをお勧めします。

関連する問題