Thursday, January 8, 2009

Fuse-J : Java bindings for FUSE (Filesystem in Userspace)

Fuse :

Provides framework for creating a virtual file system.As given in the site the important thing to remember is it runs only on Linux kernels 2.4.X and 2.6.X. For more details you can look at the fuse site

http://fuse.sourceforge.net/

Fuse-J :

Fuse-J Java bindings for FUSE (Filesystem in Userspace) is a Java API that uses JNI bindings to FUSE library and enables writing Linux filesystems in Java language.For more details you can look at the Fuse-J site

http://sourceforge.net/projects/fuse-j

Recently we needed to develop a virtual file system using fuse and fuse-j.Fuse has pretty good documentation.Fuse-J has pretty good examples, but what is missing is the good documentation of their API and usage guidelines.I would like to take a stab at describing them in this blog.I would like to start with the most important classes and methods, then gradually move to the documentation for their full API.

The most imporatant class that the framework gives is

fuse.FuseMount

The class provides the logic to mount any directory you want with fuse for intercepting OS level calls for the mounted directory.The below method can be used to mount a directory with fuse framework.

public static void mount(String[] args, Filesystem3 filesystem, Log log)

The first entry in the String array should be the directory you want to mount with fuse framework. The filesystem instance is the implementation class for Filesystem3 which contains the call back methods.

The main interface in the Fuse-J framework that needs to be implemented by the user is

fuse.Filesystem3

The most important methods that need to be implemented in the above interface are below

public int getattr(String path, FuseGetattrSetter getattrSetter)

This is the first method called by the fuse framework when the OS tries to access any file or folder in the mounted directory. You could provide the properties of the file or folder in FuseGetattrSetter class.

public int getdir(String path, FuseDirFiller dirFiller)

This method is called to get the contents of a folder in the mounted directory.You can set the contents in the FuseDirFiller class.

public int read(String path, Object fh, ByteBuffer buf, long offset)

This method is invoked when the user tries to read a file in the mounted directory.

public int write(String path, Object fh, boolean isWritepage, ByteBuffer buf, long offset)
This method is invoked when the user tries to write a file into a mounted directory.

I hope this information will be helpful in coming upto speed in applications using Fuse-J. Planning to update this in the coming days with more information.

No comments:

Post a Comment