【问题标题】:fuse changes chown to?熔断器更改 chown 为?
【发布时间】:2011-11-12 22:14:47
【问题描述】:

我正在尝试修改 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 位。

【问题讨论】:

  • 知道python api for fuse的人可以检查逻辑。

标签: c filesystems fuse


【解决方案1】:

使用未初始化的 var 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 是如何在那里实现的。

【讨论】:

  • 感谢 pmod 指出这一点。这是非常愚蠢的错误。我为此感到羞耻。我错过了 ni_readdir 中的另一行,ni_fullpath(fpath, path); filler(buf, fpath + 1, NULL, 0); 现在代码正在运行并且 dir tmp 已安装。但是ls -lt tmp 显示ls -lt tmp ls: cannot access tmp /home/nikhil/: Operation not permitted total 0 ?????????? ? ? ? ? ? home/nikhil/
  • 这很有趣,我给/ 挂载到tmp。它成功了。但是如果我给/home/nikhil 挂载在tmp 中,它会给出同样的错误operation not permitted
  • 我做了更改。问题依然存在。仅安装了 /。对于其他位置,它显示Operation not permitted.
  • 检查我上面的更新。现在我怀疑 readdir 和真正的建议从 fusexmp 开始。请注意,您不应该在那里使用 ni_fullpath()。
猜你喜欢
  • 1970-01-01
  • 2016-08-21
  • 2015-05-27
  • 1970-01-01
  • 1970-01-01
  • 2010-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多