我正在尝试在 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)