使用FUSE实现写入文件系统中的文件

时间:2011-12-16 16:23:10

标签: java filesystems fuse

我正在使用这个Java绑定实现带有FUSE的简单内存文件系统https://github.com/dtrott/fuse4j我确实阅读并创建了一个文件支持,但无法写入文件。尝试写时总是出错。以下是一些实现:

   public int truncate(String s, long l) throws FuseException {
        System.out.println("truncate: " + s + " l: " +l);
        Node node = lookup(s);
                        if (node == null)
                               return Errno.ENOENT;

        node.setFileSize(node.getFileSize()+l);

        return 0; 
    }

    public int statfs(FuseStatfsSetter fuseStatfsSetter) throws FuseException {
        fuseStatfsSetter.set(512, 1000, 200, 180, 5, 29, 20);
        return 0;
    }

    public int open(String s, int i, FuseOpenSetter fuseOpenSetter) throws FuseException {
        System.out.println("open: " + s);
        Node node = lookup(s);
                if (node == null)
                       return Errno.ENOENT;

        fuseOpenSetter.setFh(node);
        return 0; 
    }

    public int read(String s, Object o, ByteBuffer byteBuffer, long l) throws FuseException {
        System.out.println("read: " + s);
        Node node = lookup(s);
        if (node == null)
               return Errno.EBADF;
        if (node.getContents() != null)
            byteBuffer.put(node.getContents());
        return 0; 
    }

    public int write(String s, Object o, boolean b, ByteBuffer byteBuffer, long l) throws FuseException {
        System.out.println("write: " + s + " byte: " + byteBuffer.array().length + " l: " + l);
        Node node = lookup(s);
        if (node == null)
            return 0;

        node.setContents(byteBuffer.array());
        node.setFileSize(node.getFileSize()+byteBuffer.array().length);
        return byteBuffer.array().length;
    }

statfs使用一些没有特定含义的硬编码值,flushfsyncrelease始终返回0.

0 个答案:

没有答案