熔丝变化chown到?

时间:2011-11-11 17:45:25

标签: c filesystems fuse

我试图修改fuse example以挂载任何目录。我想在tmp中挂载/ 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 个答案:

答案 0 :(得分:1)

如何使用未初始化的var fpath 而不是路径

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的实现方式。

相关问题