簡體   English   中英

fuse:創建線程時出錯:資源暫時不可用

[英]fuse: error creating thread: Resource temporarily unavailable

在為最簡單的fuse文件系統編寫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修飾符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM