opendir() function in FUSE

0

I'm writing a program using FUSE library and the thing is that I don't know what I've done wrong with my codes.

Here is some informations came out when I run my program with '-d' option.

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

and this is a part of my codes which I think it allegedly makes the problem related to the logs.

#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;

If you guys have any idea about this issue, please state anything that might help.

c
filesystems
fuse
asked on Stack Overflow Nov 17, 2015 by user3551261 • edited Jul 9, 2020 by genpfault

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0