Filesystems Fuse&实现写操作

Filesystems Fuse&实现写操作,filesystems,fuse,Filesystems,Fuse,我正在编写一个自定义的fuse镜像文件系统(在Ubuntu中使用fuse-JNA)。通过镜像,我的意思是,它将读取和写入本地文件系统的目录 我实现了getattr、create和read操作,如下所示。所有这些都非常有效 ... private final String mirroredFolder = "./target/mirrored"; ... ... public int getattr(final String path, final StatWrapper stat) {

我正在编写一个自定义的fuse镜像文件系统(在Ubuntu中使用fuse-JNA)。通过镜像,我的意思是,它将读取和写入本地文件系统的目录

我实现了getattr、create和read操作,如下所示。所有这些都非常有效

...
private final String mirroredFolder = "./target/mirrored";
...
...

    public int getattr(final String path, final StatWrapper stat)
{   

    File f = new File(mirroredFolder+path);         

    //if current path is of file
    if (f.isFile())
    {
        stat.setMode(NodeType.FILE,true,true,true,true,true,true,true,true,true);
        stat.size(f.length());
        stat.atime(f.lastModified()/ 1000L);
        stat.mtime(0);
        stat.nlink(1);
        stat.uid(0);
        stat.gid(0);
        stat.blocks((int) ((f.length() + 511L) / 512L));
        return 0;
    }


    //if current file is of Directory
    else if(f.isDirectory())
    {
        stat.setMode(NodeType.DIRECTORY);
        return 0;
    }





    return -ErrorCodes.ENOENT();
}
下面的创建方法在镜像文件夹中创建新文件

    public int create(final String path, final ModeWrapper mode, final FileInfoWrapper info)
{
    File f = new File(mirroredFolder+path);
    try {
        f.createNewFile();
        mode.setMode(NodeType.FILE, true, true, true);
    } catch (IOException e) {
        e.printStackTrace();
    }


    return 0;
}
    public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info)
{

    String contentOfFile=null;
    try {
        contentOfFile= readFile(mirroredFolder+path);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    final String s = contentOfFile.substring((int) offset,
            (int) Math.max(offset, Math.min(contentOfFile.length() - offset, offset + size)));
    buffer.put(s.getBytes());
    return s.getBytes().length;

}
读取方法从镜像文件夹读取文件

    public int create(final String path, final ModeWrapper mode, final FileInfoWrapper info)
{
    File f = new File(mirroredFolder+path);
    try {
        f.createNewFile();
        mode.setMode(NodeType.FILE, true, true, true);
    } catch (IOException e) {
        e.printStackTrace();
    }


    return 0;
}
    public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info)
{

    String contentOfFile=null;
    try {
        contentOfFile= readFile(mirroredFolder+path);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    final String s = contentOfFile.substring((int) offset,
            (int) Math.max(offset, Math.min(contentOfFile.length() - offset, offset + size)));
    buffer.put(s.getBytes());
    return s.getBytes().length;

}
但我的写入操作不起作用

下面是我的写作方法,它是不完整的

public int write(final String path, final ByteBuffer buf, final long bufSize, final long writeOffset,
        final FileInfoWrapper wrapper)
{

    return (int) bufSize;
}
当我在调试器模式下运行它时,path参数显示path=/.goutputstream xxx(其中xxx是每次调用write方法时的随机字母数字)


请指导我如何正确执行写入操作。

只需按照给定的文件名写入即可


您看到
path=/.goutputstream xxx
的原因是。这不是fuse jna中的错误。

如果我在path参数中得到
/.goutputstream xxx
,那么我如何知道要写入哪个文件。例如,如果我编辑并保存abc.txt文件。write()方法中的path参数显示的是
/.goutputstream xxx
,而不是当前编辑的文件。我知道它的ubuntu bug。我把它从12版升级到了ubuntu 14版,但仍然存在同样的问题。我现在应该尝试哪个操作系统/或任何其他解决方案。您得到的是
/.goutputstream xxx
,因为lightdm错误试图写入这些文件,而与文本编辑器写入
/abc.txt
无关。如果您得到
/.goutputstream xxx
,则写入
/.goutputstream xxx
。当文本编辑器保存时,您将获得
/abc.txt
。函数被调用多次(每个块一次,为每个文件写入)。谢谢。我完成了这个项目,并在这里公开了它