为什么没有调用我的回调?
Why is my callback not called?
我正在尝试在C++(使用 g++ 编译器(中实现 fuse hello 示例 (https://lastlog.de/misc/fuse-doc/doc/html/hello_8c.html(。我不得不稍微改变一下才能做到这一点。
#define FUSE_USE_VERSION 30
#include <cstdlib>
#include <iostream>
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
static const char *hello_str = "Hello World!n";
static int hello_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
memset(stbuf, 0, sizeof(struct stat));
if (strcmp(path, "/") == 0)
{
stbuf->st_mode = S_IFDIR | 0777;
stbuf->st_nlink = 2;
}
else if (strcmp(path, "/hello") == 0)
{
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
stbuf->st_size = strlen(hello_str);
}
else
res = -ENOENT;
return res;
};
static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
if (strcmp(path, "/") != 0)
return -ENOENT;
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
filler(buf, "hello", NULL, 0);
return 0;
};
static int hello_open(const char *path, struct fuse_file_info *fi)
{
if (strcmp(path, "/hello") != 0)
return -ENOENT;
if ((fi->flags & 3) != O_RDONLY)
return -EACCES;
return 0;
};
static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
size_t len;
(void) fi;
if(strcmp(path, "/hello") != 0)
return -ENOENT;
len = strlen(hello_str);
if (offset < len) {
if (offset + size > len)
size = len - offset;
memcpy(buf, hello_str + offset, size);
} else
size = 0;
return size;
};
static int hello_opendir(const char *path, struct fuse_file_info *fi)
{
return 0;
};
struct hello_fuse_operations : fuse_operations
{
hello_fuse_operations()
{
this->getattr = hello_getattr;
this->open = hello_open;
this->read = hello_read;
this->opendir = hello_opendir;
this->readdir = hello_readdir;
}
};
static struct hello_fuse_operations hello_oper;
int main(int argc, char** argv)
{
return fuse_main_real(argc, argv, &hello_oper, sizeof(&hello_oper), NULL);
}
我的问题是,fuse 说read
和readdir
没有实现,也没有调用它们,即使它们显然已经实现。
unique: 13, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 16153
unique: 13, error: -38 (Function not implemented), outsize: 16
看起来我似乎在做一些基本错误的事情,但我无法弄清楚是什么。(我对C++也不是很有经验(
如何使示例正常工作?
sizeof(&hello_oper)
看起来像一个错误 - 这是指针的大小,而不是结构的大小。
sizeof(fuse_operations)
可能是你想要的。 在这种情况下,sizeof hello_oper
是一样的,但是如果您稍后将数据成员添加到hello_fuse_operations
那么它将变得错误。
相关文章:
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- 模板化回调参数的逆变,如 C# 中的逆变
- 是否可以影响 C++ 中回调函数的局部变量?
- C++带有回调函数的模板类
- 获取要在C++中动态调用的回调函数的地址
- C++迭代回调中的向量
- OpenGL 调试 错误回调函数的 ID 参数是什么?
- 共享指针和回调注册的结构.由于我之外的原因调用回调时,原始指针值发生了变化
- 带有回调函数的cocos2d-x菜单项错误
- 使用P/Invoke提高对托管和未管理的回调链的例外
- 允许 lambda/回调函数的多个签名作为模板参数
- 读取 Lambda 回调后的访问冲突
- 回调中的占位符_1是如何工作的
- 用于回调注册的 SFINAE
- boost::asio::async_read 不会回调我的处理程序函数
- 成员静态回调函数的外部"C"
- 将参数中带有回调函数的C/C++函数编组为C#
- C++-17变量模板:捕获回调参数的返回类型和参数类型
- 传递给<N>回调函数的模板化迭代器
- 当我尝试caputre〔this〕时,用于回调函数的lambda表达式失败,原因是什么