Reputation: 357
I am writing a custom fuse Mirror File System (in Ubuntu using FUSE-JNA). By mirror I mean, It will read from and write into a directory of local file system.
I implemented getattr, create, and read operation as below. All these work perfectly.
...
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();
}
below create method creates new file in mirrored folder
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;
}
read method reads file from mirrored folder
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;
}
But my write operation is not working.
Below is my Write method, which is incomplete.
public int write(final String path, final ByteBuffer buf, final long bufSize, final long writeOffset,
final FileInfoWrapper wrapper)
{
return (int) bufSize;
}
When I run it in Debugger mode, the path arguments shows Path=/.goutputstream-xxx (where xxx is random alphanumeric each time write method is called)
Please guide me how to correctly implement write operation.
Upvotes: 1
Views: 2774
Reputation: 4882
Just write to the filename you're given. How do I create a file and write to it in Java?
The reason you're seeing path=/.goutputstream-xxx
is because of https://askubuntu.com/a/151124. This isn't a bug in fuse-jna.
Upvotes: 1