смена предохранителя - PullRequest
       20

смена предохранителя

1 голос
/ 11 ноября 2011

я пытаюсь изменить fuse пример для монтирования любого каталога. Я хочу смонтировать / home / nikhil в ТМП. я пробежал как $ ./ni /home/nikhil tmp

Он монтирует папку tmp, но не может получить к ней доступ.

$ls -ltr tmp 

ls: cannot access tmp: Operation not permitted

$ ls -ltr

ls: cannot access delete: Operation not permitted total 11716 d????????? ? ? ? ? ? delete

Мой код

#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>

#define MAX 100
char *rootpath;

static void ni_fullpath(char fpath[MAX], const char *path){
    strcpy(fpath, rootpath);
    strncat(fpath, path, MAX);
}

static int ni_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
char fpath[MAX];
memset(stbuf, 0, sizeof(struct stat));
    ni_fullpath(fpath, path);
res = lstat(fpath, stbuf);
return res;
}

static int ni_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
         off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
// i didnt understand this
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
    ni_fullpath(fpath, path);
filler(buf, fpath + 1, NULL, 0);

return 0;
}

static int ni_open(const char *path, struct fuse_file_info *fi)
{
int fd;
char fpath[MAX];
ni_fullpath(fpath, path);
if ((fi->flags & 3) != O_RDONLY)
    return -EACCES;

fd = open(fpath, fi->flags);
return fd;
}

static int ni_read(const char *path, char *buf, size_t size, off_t offset,
          struct fuse_file_info *fi)
{
return pread(fi->fh, buf, size, offset);

}

static struct fuse_operations ni_oper = {
.getattr    = ni_getattr,
.readdir    = ni_readdir,
.open       = ni_open,
.read       = ni_read,    
};


void ni_usage(){
fprintf(stderr, "usage ni rootDir mountPoint");
abort();
}

int main(int argc, char *argv[])
{
printf("%s %s \n", argv[1], argv[2]);
rootpath = realpath(argv[1], NULL);

argv[1] = argv[2];
argc--;
return fuse_main(argc, argv, &ni_oper, NULL);
}   

Кто-нибудь может помочь, что я делаю неправильно? Я использую Ubuntu 1104 64 бит.

1 Ответ

1 голос
/ 11 ноября 2011

Как насчет использования неинициализированной переменной fpath вместо path ?

static int ni_getattr(const char *path, struct stat *stbuf)
{
   int res = 0;
   char fpath[MAX];
   memset(stbuf, 0, sizeof(struct stat));

   res = lstat(fpath, stbuf);
   return res;
} 

Возможно, вы пропустили ni_fullpath (fpath, path);

И, насколько я понимаю, 0 должен быть возвращен в открытом обратном вызове в случае успеха, поэтому он должен выглядеть следующим образом:

   ....
   fd = open(fpath, fi->flags);
   if (fd < 0)
       return -errno;
   fi->fh = fd;
   return 0;
}

Операция списка должна использовать обратный вызов readdir, а в вашем случае этоимеет очень ограниченное применение.Было бы лучше начать код на основе fusexmp .Проверьте, как там реализован readdir.

...