FUSE

时间:2015-11-17 07:00:26

标签: c filesystems fuse

目前,我正在使用FUSE库编写一个程序,问题是我不知道我的代码出了什么问题。所以我留下这个问题是为了尽快解决问题。

当我使用'-d'选项运行程序时,会出现一些信息。

FUSE library version: 2.9.4
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.23
flags=0x0003f7fb
max_readahead=0x00020000
   INIT: 7.19
   flags=0x00000010
   max_readahead=0x00020000
   max_write=0x00020000
   max_background=0
   congestion_threshold=0
   unique: 1, success, outsize: 40
unique: 2, opcode: OPENDIR (27), nodeid: 1, insize: 48, pid: 1608
   unique: 2, success, outsize: 32
unique: 3, opcode: LOOKUP (1), nodeid: 1, insize: 52, pid: 4989
unique: 4, opcode: ACCESS (34), nodeid: 1, insize: 48, pid: 1672
   unique: 4, error: -38 (Function not implemented), outsize: 16
LOOKUP /autorun.inf
getattr /autorun.inf
Killed

这是我的代码的一部分,我认为它据称使问题与日志有关。

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <limits.h>
#include <signal.h>
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>

static char *fullpath = "/proc";

static int pfs_getattr (const char  *path, struct stat *stbuf)
{
    /* not yet implemented */
    bool found = false;

    int size = -1;
    int filedes;

    pid_t pid;

    char *ptr;
    char buf[2048];
    char fileName[2048];
    char *cur;
    char *sizeinfo;

    long clocks_per_second = sysconf(_SC_CLK_TCK);

    long long boot_time_since_epoch = 0;
    long long process_start_time_since_boot;

    time_t process_start_time_since_epoch;

    struct stat statbuf;
    struct dirent *dirp;
    DIR *dp;

    memset(stbuf, 0, sizeof(struct stat));

    if(strcmp(path, "/") == 0){
        stbuf->st_mode = S_IFDIR | 0755;
        stbuf->st_nlink= 2;
    }
    else{
        if(lstat(fullpath, &statbuf) < 0){
            return -errno;
        }
        if(S_ISDIR(statbuf.st_mode) == 0){
            return -errno;
        }

        if((dp = opendir(fullpath)) == NULL){
            return -errno;
        }

        while((dirp = readdir(dp)) != NULL){
            memset(buf, 0, 2048);
            memset(fileName, 0, 2048);
            strcat(buf, fullpath);

            if(strcmp(dirp->d_name, ".") == 0
                    || strcmp(dirp->d_name, "..") == 0){
                continue;
            }

            if((pid = (pid_t)atoi(dirp->d_name)) == (pid_t)0)
                continue;

            strcat(buf, dirp->d_name);

            if(lstat(buf, &statbuf) < 0){
                continue;
            }

            if(S_ISDIR(statbuf.st_mode) == 0){
                continue;
            }

            strcat(buf, "/cmdline");

            if((filedes = open(buf, O_RDONLY)) < 0)
                continue;

            memset(buf, 0, 2048);
            if(read(filedes, buf, 2048) <= 0)
                continue;

如果您对此问题有任何疑问,请说明可能有用的任何内容。感谢。

0 个答案:

没有答案