保险丝:错误创建线程:资源暂时不可用
fuse: error creating thread: Resource temporarily unavailable
在为最简单的 fuse 文件系统编写 getattr 和 readdir 函数后,我得到 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
注意删除了第三个函数参数
注意将 return(错误)修改为 -ENONET
包含的头文件列表也缺少声明;
#include <stdlib.h> // exposes function: `realpath()`
函数:e_getattr()
还需要`static修饰符
在为最简单的 fuse 文件系统编写 getattr 和 readdir 函数后,我得到 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
注意删除了第三个函数参数
注意将 return(错误)修改为 -ENONET
包含的头文件列表也缺少声明;
#include <stdlib.h> // exposes function: `realpath()`
函数:e_getattr()
还需要`static修饰符