我正在尝试实现一个FUSE文件系统,包括设置/获取扩展文件属性的能力。在本例中,我感兴趣的属性是创建一个布尔条件,将文件标记为加密的。假设我有一个名为test.txt的文件。在终端窗口中,我可以轻松地完成以下操作:
setfattr -n user.encrypted -v 1 test.txt getfattr -n user.encrypted test.txt
得到输出:
档案: test.txt user.encrypted="1“
因此,我知道我的系统被正确地设置为使用扩展属性。
但是,我只能从FUSE内部编程地设置和获取这些属性。例如,我有以下功能:
/* File open operation */
int bb_open(const char *path, struct fuse_file_info *fi)
{
int retstat = 0;
int fd;
int isEncrypted;
char user[] = "user";
char encAttr[] = "encrypted";
fd = open(path, fi->flags);
if (fd < 0)
retstat = bb_error("bb_open open");
log_msg("\nAbout to get encryption attribute\n");
/* get the encryption attribute */
isEncrypted = fgetxattr(fd, user, encAttr, 1);
log_msg("\nisEncrypted: %d\n", isEncrypted);
return retstat;
}当我运行这个属性时,即使在从命令行设置这个属性之后,fgetxattr也总是失败(即它返回的值为-1)。我的日志文件中的输出是:
isEncrypted = -1
显然,我调用这个函数是错误的,但是我不知道如何纠正这个错误。有人能帮忙吗?谢谢。
发布于 2013-04-28 13:54:31
您需要在FUSE文件系统中实现以下功能:
https://stackoverflow.com/questions/16045921
复制相似问题