我能得到工作的扩展属性:
vfs_setxattr(struct dentry *, const char *, const void *, size_t,int);主要的问题是
const void *需要一个
char *传递。该代码看起来像这样:
char * buf = "test ";int size = 5; //number of bytes needed for attributeint flag = 0; //0 allows for replacement or creation of attributeint err; //gets error pre negative error and positive successerr = vfs_setxattr(path_struct.dentry, "user.custom_attrib", buf, size, flag);
我也能够开始
vfs_getxattr(struct dentry *, const char *, const void *,size_t);工作。缓冲区,
void *又是我卡住的地方。我必须分配一个缓冲区来保存正在传递的扩展属性。所以我的代码看起来像这样:
char buf[1024];int size_buf = 1024;int err;err = vfs_getxattr(path_struct.dentry, "user.custom_attrib",buf, size_buf);
因此,buf将保留来自dentry的指定文件中的值。错误代码对于找出正在发生的事情非常有帮助。使用命令行工具也是如此。
要安装命令行工具:
sudo apt-get install attr
要从命令行手动设置属性:
setfattr -n user.custom_attrib -v "test_if working" test.txt
要从命令行手动获取属性:
getfattr -n user.custom_attrib test.txt
我无法弄清楚您是否可以将诸如int的不同类型传递给扩展的atrributes,而我的尝试使我不胜枚举内核构建的次数。希望这对某些人有所帮助,或者如果有人有任何更正,请告诉我。



