小编ams*_*152的帖子

在内核模式下在 ext4 中设置自定义扩展属性

我正在尝试在 linux 内核的 ext4 文件系统中实现自定义扩展属性。我添加了两个新的系统调用来设置和获取文件的 Security_Tag(我的新属性)。在这些系统调用的实现中,我使用了setxattr、getxattr和access函数。

这是我实现系统调用的源代码:

#include <linux/kernel.h>
#include <linux/unistd.h>
#include <linux/syscalls.h>
#include <linux/types.h>
#include <linux/xattr.h>

// Sets the Security_Tag attribute for the given file to the  specified
// integer value.
asmlinkage int sys_set_security_tag(const char *filename, int new_tag)
{
        // Check if the current user has write access to this file
        int permissions = access(filename, W_OK);
        if(permissions < 0){
                printk("ERROR: Permission Denied");
                return -1;
        }

        // Set the value of the Security_Tag attribute …
Run Code Online (Sandbox Code Playgroud)

c linux linux-kernel

5
推荐指数
0
解决办法
257
查看次数

标签 统计

c ×1

linux ×1

linux-kernel ×1