gpt4 book ai didi

c - fuse :创建线程时出错:资源暂时不可用

转载 作者:行者123 更新时间:2023-11-30 16:20:23 25 4
gpt4 key购买 nike

在为最简单的熔丝文件系统编写getattrreaddir函数后,我得到fuse:创建线程时出错:资源暂时不可用。 。我想知道我的代码中哪里出错了

我已经在搜索这个,但找不到任何令我满意的东西。在我看来,它超出了线程限制,但我不知道如何修复它。我用它编译了

$ gcc passthrough.c -o passthrough `pkg-config fuse --cflags --libs`
passthrough.c:65:2: warning: initialization from incompatible pointer type [enabled by default]
.getattr = e_getattr,
^
passthrough.c:65:2: warning: (near initialization for 'oper.getattr') [enabled by default]

这是程序的源代码

#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <limits.h>

char rootdir[100];

void get_fullpath(char fpath[PATH_MAX], const char *path){
strcpy(fpath,rootdir);
strncat(fpath,path,PATH_MAX);
printf("[fullpath] file: %s\n",fpath);
}

int e_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi){
(void)fi;
int res;

char fpath[PATH_MAX];
get_fullpath(fpath,path);

printf("[getattr] file: %s\n",fpath);

res = lstat(fpath,stbuf);
if (res == -1)
return -errno;
return 0;
}

int e_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){
DIR *dp;
struct dirent *de;

(void)offset;
(void)fi;

char fpath[PATH_MAX];
get_fullpath(fpath,path);
printf("[readdir] file: %s\n",fpath);

dp = opendir(fpath);
if (dp == NULL)
return -errno;

while ((de = readdir(dp)) != NULL){
struct stat st;
memset(&st,0,sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
if (filler(buf,de->d_name,&st,0))
break;
}
closedir(dp);
return 0;
}

struct fuse_operations oper = {
.getattr = e_getattr,
.readdir = e_readdir,
};

int main(int argc, char * argv[]){
umask(0);
realpath(argv[2],rootdir);
printf("Real path is %s\n",rootdir);
return fuse_main(argc,argv,&oper,NULL);
}

这是我得到的输出

[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
...
...
...
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
fuse: error creating thread: Resource temporarily unavailable
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/

最佳答案

问题出在函数:e_getattr() 应该写成:

static int e_getattr(const char *path, struct stat *stbuf )
{
int res;

char fpath[PATH_MAX];
get_fullpath(fpath,path);

printf("[getattr] file: %s\n",fpath);

res = lstat(fpath,stbuf);
if (res == -1)
return -ENONET;
return 0;
}

注意添加的修饰符static

注意第三个函数参数的删除

注意对 -ENONET 返回(出错时)的修改

此外,包含的头文件列表也缺少该语句;

#include <stdlib.h> // exposes function: `realpath()`

函数:e_getattr()也需要`static修饰符

关于c - fuse :创建线程时出错:资源暂时不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55324837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com