栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Linux内核空间(即从自定义系统调用)添加自定义扩展属性

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Linux内核空间(即从自定义系统调用)添加自定义扩展属性

我能得到工作的扩展属性:

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,而我的尝试使我不胜枚举内核构建的次数。希望这对某些人有所帮助,或者如果有人有任何更正,请告诉我。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号