After writing getattr and readdir functions for simplest fuse filesystem, i get fuse: error creating thread: Resource temporarily unavailable. . I would like to know where in my code i made mistake
I already search for this, but couldnt find anything that satisfies me. It seems to me that it exceeded thread limit, but i dont know how to fix it. I compiled it with
$ 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]
Here is the source code of program
#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);
}
And here is the output i'm getting
[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/
the problem is in the function: e_getattr()
It should be written as:
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;
}
Notice the added modifier static
Notice the removal of the third function parameter
Notice the modification to the return (on error) to -ENONET
Also the list of included header files is missing the statement;
#include <stdlib.h> // exposes function: `realpath()`
the function: e_getattr()
also needs the `static modifier
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.