我正在使用这个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
使用一些没有特定含义的硬编码值,flush
,fsync
和release
始终返回0.