org.catacombae.jfuse.test
Class TestFS

java.lang.Object
  extended by org.catacombae.jfuse.FUSE26FileSystemAdapter
      extended by org.catacombae.jfuse.FUSEFileSystemAdapter
          extended by org.catacombae.jfuse.MacFUSE20FileSystemAdapter
              extended by org.catacombae.jfuse.MacFUSEFileSystemAdapter
                  extended by org.catacombae.jfuse.test.TestFS
All Implemented Interfaces:
FUSE26FileSystem, FUSE26Operations, FUSEErrorValues, FUSEFileSystem, MacFUSE20FileSystem, MacFUSE20Operations, FileModeFlags, FileStatusFlags, SystemConstants

public class TestFS
extends MacFUSEFileSystemAdapter

In-memory file system for testing jFUSE.
This file system will be used for testing jFUSE. All or most of the FUSEOperations will be implemented in this file system eventually. (Current status is work-in-progress.)

Author:
Erik Larsson

Field Summary
 
Fields inherited from interface org.catacombae.jfuse.types.system.FileStatusFlags
O_ACCMODE, O_APPEND, O_ASYNC, O_CREAT, O_DIRECTORY, O_EVTONLY, O_EXCL, O_EXLOCK, O_NOCTTY, O_NOFOLLOW, O_NONBLOCK, O_RDONLY, O_RDWR, O_SHLOCK, O_SYMLINK, O_SYNC, O_TRUNC, O_WRONLY
 
Fields inherited from interface org.catacombae.jfuse.types.system.FileModeFlags
S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR
 
Fields inherited from interface org.catacombae.jfuse.FUSEErrorValues
E2BIG, EACCES, EADDRINUSE, EADDRNOTAVAIL, EAFNOSUPPORT, EAGAIN, EALREADY, EBADF, EBADMSG, EBUSY, ECANCELED, ECHILD, ECONNABORTED, ECONNREFUSED, ECONNRESET, EDEADLK, EDESTADDRREQ, EDOM, EDQUOT, EEXIST, EFAULT, EFBIG, EHOSTDOWN, EHOSTUNREACH, EIDRM, EILSEQ, EINPROGRESS, EINTR, EINVAL, EIO, EISCONN, EISDIR, ELOOP, EMFILE, EMLINK, EMSGSIZE, EMULTIHOP, ENAMETOOLONG, ENETDOWN, ENETRESET, ENETUNREACH, ENFILE, ENOBUFS, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOLINK, ENOMEM, ENOMSG, ENOPROTOOPT, ENOSPC, ENOSYS, ENOTBLK, ENOTCONN, ENOTDIR, ENOTEMPTY, ENOTSOCK, ENOTSUP, ENOTTY, ENXIO, EOPNOTSUPP, EOVERFLOW, EPERM, EPFNOSUPPORT, EPIPE, EPROTO, EPROTONOSUPPORT, EPROTOTYPE, ERANGE, EREMOTE, EROFS, ESHUTDOWN, ESOCKTNOSUPPORT, ESPIPE, ESRCH, ESTALE, ETIMEDOUT, ETOOMANYREFS, ETXTBSY, EUSERS, EWOULDBLOCK, EXDEV
 
Constructor Summary
TestFS()
           
 
Method Summary
 int chflags(ByteBuffer path, int flags)
          Change file flags.
 int chmod(ByteBuffer path, short newMode)
           Change the permission bits of a file.
 int create(ByteBuffer path, short mode, FUSEFileInfo fi)
           Create and open a file.
 void destroy(Object o)
           Clean up filesystem.
 int getattr(ByteBuffer path, Stat stbuf)
           Get file attributes.
 int getxtimes(ByteBuffer path, Timespec bkuptime, Timespec crtime)
          Get the Mac OS X extended time values "backup time" and "create time".
 Object init(FUSEConnInfo conn)
           Initialize filesystem.
static void main(String[] args)
           
 int mkdir(ByteBuffer path, short mode)
           Create a directory.
 int open(ByteBuffer path, FUSEFileInfo fi)
           File open operation.
 int read(ByteBuffer path, ByteBuffer buf, long offset, FUSEFileInfo fi)
           Read data from an open file.
 int readdir(ByteBuffer path, FUSEFillDir filler, long offset, FUSEFileInfo fi)
           Read directory.
 int readlink(ByteBuffer path, ByteBuffer buffer)
           Read the target of a symbolic link.
 int rename(ByteBuffer oldPath, ByteBuffer newPath)
           Rename a file.
 int rmdir(ByteBuffer path)
           Remove a directory.
 int setbkuptime(ByteBuffer path, Timespec tv)
          Set the Mac OS X extended time value "backup time".
 int setcrtime(ByteBuffer path, Timespec tv)
          Set the Mac OS X extended time value "create time".
 int symlink(ByteBuffer source, ByteBuffer dest)
           Create a symbolic link.
 int truncate(ByteBuffer path, long newSize)
           Change the size of a file.
 int unlink(ByteBuffer path)
           Remove a file.
 int utimens(ByteBuffer path, Timespec accessTime, Timespec modificationTime)
           Change the access and modification times of a file with nanosecond resolution.
 int write(ByteBuffer path, ByteBuffer buf, long offset, FUSEFileInfo fi)
           Write data to an open file.
 
Methods inherited from class org.catacombae.jfuse.MacFUSE20FileSystemAdapter
exchange, fsetattr_x, getMacFUSECapabilities, setattr_x
 
Methods inherited from class org.catacombae.jfuse.FUSE26FileSystemAdapter
access, bmap, chown, fgetattr, flush, fsync, fsyncdir, ftruncate, getdir, getFUSECapabilities, getxattr_BSD, getxattr, link, listxattr, lock, mknod, opendir, release, releasedir, removexattr, setxattr_BSD, setxattr, statfs, utime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestFS

public TestFS()
Method Detail

init

public Object init(FUSEConnInfo conn)
Description copied from interface: FUSE26Operations
 Initialize filesystem.

 The return value will passed in the private_data field of
 fuse_context to all file operations and as a parameter to the
 destroy() method.

 Introduced in version 2.3
 Changed in version 2.6
 

Specified by:
init in interface FUSE26Operations
Overrides:
init in class FUSE26FileSystemAdapter
Parameters:
conn - (struct fuse_conn_info*)
Returns:
(optional) a return value that will be passed in the private_data field of fuse_context to all file operations and as a parameter to the destroy() method.

destroy

public void destroy(Object o)
Description copied from interface: FUSE26Operations
 Clean up filesystem.

 Called on filesystem exit.

 Introduced in version 2.3
 

Specified by:
destroy in interface FUSE26Operations
Overrides:
destroy in class FUSE26FileSystemAdapter

getattr

public int getattr(ByteBuffer path,
                   Stat stbuf)
Description copied from interface: FUSE26Operations
 Get file attributes.

 Similar to stat().  The 'st_dev' and 'st_blksize' fields are
 ignored.  The 'st_ino' field is ignored except if the 'use_ino'
 mount option is given.
 

Specified by:
getattr in interface FUSE26Operations
Overrides:
getattr in class FUSE26FileSystemAdapter
Parameters:
path - (const char*)
stbuf - (struct stat*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

chmod

public int chmod(ByteBuffer path,
                 short newMode)
Description copied from interface: FUSE26Operations
 Change the permission bits of a file.
 

Specified by:
chmod in interface FUSE26Operations
Overrides:
chmod in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
newMode - (mode_t)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

readdir

public int readdir(ByteBuffer path,
                   FUSEFillDir filler,
                   long offset,
                   FUSEFileInfo fi)
Description copied from interface: FUSE26Operations
 Read directory.

 This supersedes the old getdir() interface.  New applications
 should use this.

 The filesystem may choose between two modes of operation:

 1) The readdir implementation ignores the offset parameter, and
 passes zero to the filler function's offset.  The filler
 function will not return '1' (unless an error happens), so the
 whole directory is read in a single readdir operation.  This
 works just like the old getdir() method.

 2) The readdir implementation keeps track of the offsets of the
 directory entries.  It uses the offset parameter and always
 passes non-zero offset to the filler function.  When the buffer
 is full (or an error happens) the filler function will return
 '1'.

 Introduced in version 2.3
 

Specified by:
readdir in interface FUSE26Operations
Overrides:
readdir in class FUSE26FileSystemAdapter
Parameters:
path - (const char*)
filler - (fuse_fill_dir_t)
offset - (off_t)
fi - (struct fuse_file_info*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

readlink

public int readlink(ByteBuffer path,
                    ByteBuffer buffer)
Description copied from interface: FUSE26Operations
 Read the target of a symbolic link.

 The buffer should be filled with a null terminated string.  The
 buffer size argument includes the space for the terminating
 null character.  If the linkname is too long to fit in the
 buffer, it should be truncated.  The return value should be 0
 for success.
 
In jFUSE the buffer size argument has already been parsed when this method gets the buffer. The byte array passed to readlink has a size equal to the size of the native buffer.

Specified by:
readlink in interface FUSE26Operations
Overrides:
readlink in class FUSE26FileSystemAdapter
Parameters:
path - (const char*)
buffer - (char*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

symlink

public int symlink(ByteBuffer source,
                   ByteBuffer dest)
Description copied from interface: FUSE26Operations
 Create a symbolic link.
 

Specified by:
symlink in interface FUSE26Operations
Overrides:
symlink in class FUSE26FileSystemAdapter
Parameters:
source - (const char*)
dest - (const char*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

open

public int open(ByteBuffer path,
                FUSEFileInfo fi)
Description copied from interface: FUSE26Operations
 File open operation.

 No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
 will be passed to open().  Open should check if the operation
 is permitted for the given flags.  Optionally open may also
 return an arbitrary filehandle in the fuse_file_info structure,
 which will be passed to all file operations.

 Changed in version 2.2
 

Specified by:
open in interface FUSE26Operations
Overrides:
open in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
fi - (struct fuse_file_info*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

create

public int create(ByteBuffer path,
                  short mode,
                  FUSEFileInfo fi)
Description copied from interface: FUSE26Operations
 Create and open a file.

 If the file does not exist, first create it with the specified
 mode, and then open it.

 If this method is not implemented or under Linux kernel
 versions earlier than 2.6.15, the mknod() and open() methods
 will be called instead.

 Introduced in version 2.5
 

Specified by:
create in interface FUSE26Operations
Overrides:
create in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) path to the newly created file.
mode - (mode_t) the mode flags for the created file.
fi - (struct fuse_file_info*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

unlink

public int unlink(ByteBuffer path)
Description copied from interface: FUSE26Operations
 Remove a file.
 

Specified by:
unlink in interface FUSE26Operations
Overrides:
unlink in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
Returns:
0 if successful, an inverted error value from FUSEErrorValues otherwise.

truncate

public int truncate(ByteBuffer path,
                    long newSize)
Description copied from interface: FUSE26Operations
 Change the size of a file.
 

Specified by:
truncate in interface FUSE26Operations
Overrides:
truncate in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
newSize - (off_t)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

utimens

public int utimens(ByteBuffer path,
                   Timespec accessTime,
                   Timespec modificationTime)
Description copied from interface: FUSE26Operations
 Change the access and modification times of a file with
 nanosecond resolution.

 Introduced in version 2.6
 

Specified by:
utimens in interface FUSE26Operations
Overrides:
utimens in class FUSE26FileSystemAdapter
Parameters:
path - (const char*)
accessTime - (const struct timespec)
modificationTime - (const struct timespec)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

mkdir

public int mkdir(ByteBuffer path,
                 short mode)
Description copied from interface: FUSE26Operations
 Create a directory.
 

Specified by:
mkdir in interface FUSE26Operations
Overrides:
mkdir in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
mode - (mode_t)
Returns:
0 if successful, an inverted error value from FUSEErrorValues otherwise.

rmdir

public int rmdir(ByteBuffer path)
Description copied from interface: FUSE26Operations
 Remove a directory.
 

Specified by:
rmdir in interface FUSE26Operations
Overrides:
rmdir in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
Returns:
0 if successful, an inverted error value from FUSEErrorValues otherwise.

rename

public int rename(ByteBuffer oldPath,
                  ByteBuffer newPath)
Description copied from interface: FUSE26Operations
 Rename a file.
 

Specified by:
rename in interface FUSE26Operations
Overrides:
rename in class FUSE26FileSystemAdapter
Parameters:
oldPath - (const char*)
newPath - (const char*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

read

public int read(ByteBuffer path,
                ByteBuffer buf,
                long offset,
                FUSEFileInfo fi)
Description copied from interface: FUSE26Operations
 Read data from an open file.

 Read should return exactly the number of bytes requested except
 on EOF or error, otherwise the rest of the data will be
 substituted with zeroes.  An exception to this is when the
 'direct_io' mount option is specified, in which case the return
 value of the read system call will reflect the return value of
 this operation.

 Changed in version 2.2
 

Specified by:
read in interface FUSE26Operations
Overrides:
read in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) a path to the file to read from.
buf - (char*) the destination buffer.
offset - (off_t) offset in file to start reading.
fi - (struct fuse_file_info*) file info.
Returns:
the number of bytes read (a positive number) if the operation completed successfully, or a negated value from FUSEErrorValues if an error occurred.
Typical error return values for read:

write

public int write(ByteBuffer path,
                 ByteBuffer buf,
                 long offset,
                 FUSEFileInfo fi)
Description copied from interface: FUSE26Operations
 Write data to an open file.

 Write should return exactly the number of bytes requested
 except on error.  An exception to this is when the 'direct_io'
 mount option is specified (see read operation).

 Changed in version 2.2
 

Specified by:
write in interface FUSE26Operations
Overrides:
write in class FUSE26FileSystemAdapter
Parameters:
path - (const char*) the path to the file system node on which the operation is to be applied.
buf - (const char*) the data to write.
offset - (off_t) offset in file where data should be written.
fi - (struct fuse_file_info*)
Returns:
0 if successful or an inverted error value from FUSEErrorValues otherwise.

getxtimes

public int getxtimes(ByteBuffer path,
                     Timespec bkuptime,
                     Timespec crtime)
Description copied from interface: MacFUSE20Operations
Get the Mac OS X extended time values "backup time" and "create time".

Specified by:
getxtimes in interface MacFUSE20Operations
Overrides:
getxtimes in class MacFUSE20FileSystemAdapter
Parameters:
path - (const char*)
bkuptime - (struct timespec*)
crtime - (struct timespec*)
Returns:
0 if successful or a negated error value from FUSEErrorValues otherwise.

setbkuptime

public int setbkuptime(ByteBuffer path,
                       Timespec tv)
Description copied from interface: MacFUSE20Operations
Set the Mac OS X extended time value "backup time".

Specified by:
setbkuptime in interface MacFUSE20Operations
Overrides:
setbkuptime in class MacFUSE20FileSystemAdapter
Parameters:
path - (const char*)
tv - (const struct timespec*)
Returns:
0 if successful or a negated error value from FUSEErrorValues otherwise.

setcrtime

public int setcrtime(ByteBuffer path,
                     Timespec tv)
Description copied from interface: MacFUSE20Operations
Set the Mac OS X extended time value "create time".

Specified by:
setcrtime in interface MacFUSE20Operations
Overrides:
setcrtime in class MacFUSE20FileSystemAdapter
Parameters:
path - (const char*)
tv - (const struct timespec*)
Returns:
0 if successful and a negated error value from FUSEErrorValues otherwise.

chflags

public int chflags(ByteBuffer path,
                   int flags)
Description copied from interface: MacFUSE20Operations
Change file flags. See chflags(2) for more info.

Specified by:
chflags in interface MacFUSE20Operations
Overrides:
chflags in class MacFUSE20FileSystemAdapter
Parameters:
path - (const char*)
flags - (uint32_t)
Returns:
0 if successful and a negated error value from FUSEErrorValues otherwise.

main

public static void main(String[] args)