【发布时间】:2017-06-15 22:45:21
【问题描述】:
我想记录指定目录的每个系统调用,我找到了这个存储库https://github.com/rflament/loggedfs
它创建了一个带有 fuse 的虚拟文件系统,并将所有内容都记录在其中,就像我想要的那样。
我试图将它移植到 mac 上,但它使用了一个在 osx 上不起作用的“技巧”。 lstat 卡住 10 秒并崩溃。
我想知道为什么?
这是我的代码的主要部分:
// g++ -Wall main.cpp `pkg-config fuse --cflags --libs` -o hello
#define FUSE_USE_VERSION 26
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
static char *path;
static int savefd;
static int getattr(const char *path, struct stat *stbuf)
{
int res;
char rPath[1024];
strcpy(rPath, "."); strcat(rPath, path);
res = lstat(rPath, stbuf); // Mac stuck here
return (res == -1 ? -errno : 0);
}
static void* loggedFS_init(struct fuse_conn_info* info)
{
fchdir(savefd); close(savefd); return NULL;
}
int main(int argc, char *argv[])
{
struct fuse_operations oper;
bzero(&oper, sizeof(fuse_operations));
oper.init = loggedFS_init;
oper.getattr = getattr;
path = strdup(argv[argc - 1]);
printf("chdir to %s\n", path);
chdir(path);
savefd = open(".", 0);
return fuse_main(argc, argv, &oper, NULL);
}
【问题讨论】:
-
rPath 是否包含安装驱动器的路径?不确定我是否理解你的问题,但你不应该通过 fuse 回调在驱动器中执行任何文件操作 - 这会导致死锁
标签: c++ linux macos fuse osxfuse