我想记录的指定目录的每一个系统调用我发现这个仓库https://github.com/rflament/loggedfsloggedfs在Mac与osxfuse卡住
,它创建一个保险丝一个虚拟文件系统,并在其记录的一切,就像我想要的。
我试图在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是否包含装载驱动器的路径? 不知道我是否理解你的问题,但你不应该从驱动器的保险丝回调中做任何文件操作 - 它会导致死锁 – DoN1cK