gpt4 book ai didi

permissions - 无法在 sysfs 中将属性权限设置为 0666

转载 作者:行者123 更新时间:2023-12-03 09:12:32 28 4
gpt4 key购买 nike

我正在使用sysfs,我需要在sysfs下创建一个文件,该文件应该对所有用户可读可写,为此我将'__ATTR'中的权限设置为 0666 。但是该模块无法编译,当我将权限更改为0660时,它就可以正确编译。

我收到的0666权限错误消息如下

`/home/rishabh/kernel_modules/Task09/task9.c: At top level:
include/linux/bug.h:33:45: error: negative width in bit-field ‘<anonymous>’
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
^
include/linux/kernel.h:859: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/rishabh/kernel_modules/Task09/task9.c:65:2: note: in expansion of macro ‘__ATTR’
__ATTR(id, 0666, id_show, id_store);
^
include/linux/bug.h:33:45: warning: initialization from incompatible pointer type [enabled by default]
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
^
include/linux/kernel.h:859: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/rishabh/kernel_modules/Task09/task9.c:65:2: note: in expansion of macro ‘__ATTR’
__ATTR(id, 0666, id_show, id_store);
^
include/linux/bug.h:33:45: warning: (near initialization for ‘id_attribute.show’) [enabled by default]
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
^
include/linux/kernel.h:859: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/rishabh/kernel_modules/Task09/task9.c:65:2: note: in expansion of macro ‘__ATTR’
__ATTR(id, 0666, id_show, id_store);
^
`

我还尝试使用 __ATTR_RW(_name) 宏,但它仅向 root 授予读写权限,而所有其他人都保留读取权限。

最佳答案

如果您遵循错误消息,则第二个是

kernel.h:859:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
BUILD_BUG_ON_ZERO((perms) & 2)

如果你查看kernel.h,你会看到注释

#define VERIFY_OCTAL_PERMISSIONS(perms)                      
...
/* OTHER_WRITABLE? Generally considered a bad idea. */ \
BUILD_BUG_ON_ZERO((perms) & 2) + \
...

因此您可以看到,您被告知让 sysfs 文件对所有人都可写是一个坏主意。如果你真的想这样做,你必须绕过这个宏检查。例如,在调用 __ATTR() 之前添加宏的重新定义:

/* warning! need write-all permission so overriding check */ 
#undef VERIFY_OCTAL_PERMISSIONS
#define VERIFY_OCTAL_PERMISSIONS(perms) (perms)

关于permissions - 无法在 sysfs 中将属性权限设置为 0666,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40776170/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com