Fuse文件系统查找/Trash、/autorun.inf和/.xdg卷信息文件

Fuse file system looks for /.Trash, /autorun.inf and /.xdg-volume-info files

本文关键字:xdg inf 信息 文件 autorun 文件系统 查找 Trash Fuse      更新时间:2023-10-16

我正在尝试用fuse库编写一个最低限度的工作示例。所需的文件系统应该只有一个只读文件。问题是,当我初始化fuse文件系统时,它试图获取/.Trash/autorun.inf/.xdg-volume-info的属性。之后,它会反复尝试获取根目录和文件系统所拥有的唯一文件的属性。之后,它尝试获取/autorun.inf的属性,然后冻结。


我使用的是保险丝3.4.1。我已经尝试过从名为hello_fuse.c的库中运行这个示例,但我在那里遇到了同样的问题。我按照本教程编写了这段代码。


Readdir操作(读取目录的内容):


static int do_readdir(const char *path, void *buffer, fuse_fill_dir_t filler,
off_t offset, fuse_file_info *fi, enum fuse_readdir_flags)
{
std::cout << "do_readdir is called on " << path << std::endl;
if (!dir_exists(path))
{
std::cout << "Entry doesn't exist" << std::endl
<< std::endl;
return -ENOENT;
}
filler(buffer, ".", nullptr, 0, FUSE_FILL_DIR_PLUS);
filler(buffer, "..", nullptr, 0, FUSE_FILL_DIR_PLUS);
if (strcmp(path, "/") == 0)
{
filler(buffer, "file_1.txt", nullptr, 0, FUSE_FILL_DIR_PLUS);
}
return 0;
}

读取操作(读取文件的内容)


static int do_read(const char *path, char *buffer, size_t size, off_t offset, fuse_file_info *fi)
{
std::cout << "do_read is called on " << path << std::endl
<< std::endl;
if (!file_exists(path))
{
std::cout << "Entry doesn't exist" << std::endl
<< std::endl;
return -ENOENT;
}
if (strlen(file_1_content) - offset < size)
{
size = strlen(file_1_content) - offset;
}
memcpy(buffer, file_1_content + offset, size);
return size;
}

获取属性操作(提供文件系统条目的属性)


static int do_getattr(const char *path, struct stat *st, fuse_file_info *fi)
{
std::cout << "do_getattr is called on " << path << std::endl
<< std::endl;
bool not_exists = !file_exists(path) && !dir_exists(path);
if (not_exists)
{
std::cout << "Entry doesn't exist" << std::endl
<< std::endl;
return -ENOENT;
}
st->st_uid = getuid();
st->st_gid = getgid();
st->st_atim.tv_sec = time(nullptr);
st->st_mtim.tv_sec = time(nullptr);
if (dir_exists(path))
{
st->st_mode = S_IFDIR | 0777;
st->st_nlink = 2;
}
else
{
st->st_mode = S_IFREG | 0777;
st->st_nlink = 1;
st->st_size = strlen(file_1_content);
}
return 0;
}

其他代码:

static struct fuse_operations operations = {
getattr : do_getattr,
read : do_read,
readdir : do_readdir,
};
int main(int argc, char *argv[])
{
std::cout << "Start mounting" << std::endl
<< std::endl;
return fuse_main(argc, argv, &operations, nullptr);
}

这是程序的输出:

Start mounting
do_getattr is called on /.Trash
Entry doesn't exist
do_getattr is called on /.xdg-volume-info
Entry doesn't exist
do_getattr is called on /
do_readdir is called on /
do_getattr is called on /autorun.inf
Entry doesn't exist
do_getattr is called on /file_1.txt
do_getattr is called on /
do_readdir is called on /
do_getattr is called on /
.........................
do_readdir is called on /
do_getattr is called on /autorun.inf
Entry doesn't exist

在最后一行之后,程序冻结。


预期的结果是文件系统安装在某个目录中,例如,我可以列出该目录的内容,并查看那里唯一的只读文件。

对我来说,oh-my-zsh是罪魁祸首。使用bash使stat调用变得可预测。