问题
I'm implementing simple in-memory file system with FUSE using this Java binding https://github.com/dtrott/fuse4j I did reading and creating a file support, but can't get writing to a file working. I always get an error with an attempt to write. Here are some implementations:
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
uses some hardcoded values without a specific meaning, flush
, fsync
and release
always return 0.
来源:https://stackoverflow.com/questions/8537066/implementing-writing-to-a-file-in-filesystem-using-fuse