Fuse文件系统查找/Trash、/autorun.inf和/.xdg卷信息文件
Fuse file system looks for /.Trash, /autorun.inf and /.xdg-volume-info files
我正在尝试用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调用变得可预测。
相关文章:
- 如何检查 log2 'inbuilt c++ function'是否返回 '-inf'?
- 是否可以将"inf"分配给变量,例如 c++ 中的常规数值
- 在泰勒展开中获取 inf 对于 e^x,但仅适用于小误差边界
- XDG-Shell:如何更改窗口大小
- 获取从函数返回'-inf'
- 计算百分比 C++ 时产生的 inf%
- Fuse文件系统查找/Trash、/autorun.inf和/.xdg卷信息文件
- 为什么当我尝试计算平均绝对偏差时,我的程序返回 inf
- c++ std 的 inf 的行为是否与常识无穷大完全一样
- 什么是 gdb 中的 inf
- INF输出计算线斜率
- 继续获得 1.#INF 作为我的输出
- 从字符串中读取溢出双倍作为'inf'的安全方法
- 在c++中将-inf和inf值过滤为0
- 提升单元测试:BOOST_CHECK_CLOSE回报 1.#INF%
- #inf c++ visual studio
- 如何在没有[DefaultInstall]部分的情况下从.NET桌面应用程序安装INF驱动程序
- 指数生成器c++,有时返回inf
- 为什么“inf”表示浮点数溢出
- 默认情况下,xdg 开放在每个 Linux 发行版中都可用