Search code examples
symlinkfuse

fuse - Setting target of Symbolic link - Java


I want to make symbolic link in FUSE (Fuse-jna, Java binding of fuse). I implemented readdir() and getattr() correctly but I do not correctly know that how to implement the readlink().

Here is my getattr() method

public int getattr(final String path, final StatWrapper stat)
{
 ...
    stat.setMode(NodeType.SYMBOLIC_LINK);
    return 0;
}

I want to set target of my symbolic link as /Documents/Untitled Document

I tried below, but it is not working.

    public int readlink(final String path, final ByteBuffer buffer, final long size)
{

    CharBuffer cbuf = buffer.asCharBuffer();
    cbuf.put("/Documents/Untitled Document");
    cbuf.flip();

    return 0;
}

Please guide me how to correctly set the target of symbolic link


Solution

  • Sorry,

    I have fixed my problem as below.

        public int readlink(final String path, final ByteBuffer buffer, final long size)
    {
    
        String s = "../Documents/Untitled Document";
        byte[] b = s.getBytes(Charset.forName("UTF-8"));
        buffer.put(b);
    
        return 0;
    }
    

    thanks any way