com.dalsemi.fs
Interface FileSystemDriver


public interface FileSystemDriver

This interface will be used to implement external file systems. Anyone wishing to extend TINI's file system must first implement this interface. The class can then be passed to the com.dalsemi.fs.DSFile.mount() method for creation.

Nearly every method in this interface takes either a file name or a file descriptor. File names will be Strings that do not include the name of the mount point itself. For example, if you have a mount point named "mnt", and on the mounted file system there is a directory called test, on TINI you would access a file in that directory by using the String "/mnt/test/myfile". The name would then be passed to the driver as "test/myfile". When accessing mount point itself ("/mnt"), it will be represented by an empty string (""). Methods that use a file descriptor will use the file descriptor returned by the openReadingFD, openWritingFD, and openRandomFD methods. What is contained in the file descriptor is up to developer.

Many methods also use a uid parameter. This is the uid of the person trying to perform the operation. IDs that have the high bit set can be assumed to have administrator privileges.


Method Summary
 int available(byte[] fd)
          The number of bytes that can be read without blocking.
 boolean canExec(java.lang.String fileName, byte uid)
          Determines if the given file is executable.
 boolean canRead(java.lang.String fileName, byte uid)
          Determines if the given file is readable.
 boolean canWrite(java.lang.String fileName, byte uid)
          Determines if the given file is writable.
 void close(byte[] fd)
          Closes the file descriptor's stream and releases any system resources used.
 boolean delete(java.lang.String fileName, byte uid)
          Removes the specified file from the mounted file system.
 boolean exists(java.lang.String fileName)
          Determines if the given file exists on the mounted file system.
 byte[] getContents(java.lang.String fileName, byte uid)
          Gets the complete contents of a file on the mounted file system.
 long getLength(byte[] fd)
          Gets the length of the file represented by the file descriptor.
 long getOffset(byte[] fd)
          Gets the current offset into the file.
 int getOtherPermissions(java.lang.String fileName)
          Gets the other (non-owner) permissions for the given file.
 int getUser(java.lang.String fileName)
          Gets the owner of a file.
 int getUserPermissions(java.lang.String fileName)
          Gets the user/owner permissions for the given file.
 void init(java.lang.String[] args)
          This method will be called the first time a mounted file system accessed.
 boolean isDirectory(java.lang.String fileName)
          Determines if the given name represents a directory.
 boolean isFile(java.lang.String fileName)
          Determines if the given name represents a file and not a directory.
 long lastModified(java.lang.String fileName)
          Indicates the time the file was last modified.
 long length(java.lang.String fileName)
          Gets the length of the file.
 java.lang.String[] list(java.lang.String fileName, byte uid)
          Retrieves a listing of the files in the directory specified.
 boolean mkdir(java.lang.String fileName, byte uid)
          Creates a directory on the mounted file system.
 byte[] openRandomFD(java.lang.String fileName, byte uid)
          Opens the given file for random access.
 byte[] openReadingFD(java.lang.String fileName, byte uid)
          Opens the given file for reading.
 byte[] openWritingFD(java.lang.String fileName, boolean append, byte uid)
          Opens the given file for writing.
 int readBytes(byte[] fd, byte[] data, int start, int length)
          Reads from the file represented by the file descriptor.
 boolean rename(java.lang.String srcname, java.lang.String destname, byte uid)
          Changes the name of a file.
 void seek(byte[] fd, long n)
          Moves the file pointer to a given location, measured in bytes from the beginning of the file.
 void setOtherPermissions(java.lang.String fileName, int perms, byte uid)
          Changes the other (non-owner) permissions for the given file.
 void setUser(java.lang.String fileName, byte newUID, byte uid)
          Sets the owner of the given file.
 void setUserPermissions(java.lang.String fileName, int perms, byte uid)
          Changes the user/owner permissions for the given file.
 long skipBytes(byte[] fd, long n)
          Skips the next n bytes of data from the stream.
 void touch(java.lang.String fileName, byte uid)
          Updates the last modified time on the given file to the current time.
 void unmount()
          Allows the driver a chance to clean up and release any resources used when a mount point is removed.
 void writeBytes(byte[] fd, byte[] data, int start, int length)
          Writes the given data to the file represented by the file descriptor.
 

Method Detail

init

public void init(java.lang.String[] args)
          throws java.lang.Exception
This method will be called the first time a mounted file system accessed.
Parameters:
args - Any arguments needed to initialize the file system.
Throws:
java.lang.Exception -  

exists

public boolean exists(java.lang.String fileName)
Determines if the given file exists on the mounted file system. This method should match the behavior of java.io.File.exists().
Parameters:
fileName - The file.
Returns:
true if the file exists.

canWrite

public boolean canWrite(java.lang.String fileName,
                        byte uid)
Determines if the given file is writable. If the file does not exists, the driver should determine if it can be created and return accordingly. This method should match the behavior of java.io.File.canWrite().
Parameters:
fileName - The file.
uid - The user that is trying to access the file.
Returns:
true if the file can be written by this user.

canRead

public boolean canRead(java.lang.String fileName,
                       byte uid)
Determines if the given file is readable. This method should match the behavior of java.io.File.canRead().
Parameters:
fileName - The file.
uid - The user that is trying to access the file.
Returns:
true if the file can be read by this user.

canExec

public boolean canExec(java.lang.String fileName,
                       byte uid)
Determines if the given file is executable. This method should match the behavior of com.dalsemi.fs.DSFile.canExec().
Parameters:
fileName - The file.
uid - The user that is trying to access the file.
Returns:
true if the file can be executed by this user.

isFile

public boolean isFile(java.lang.String fileName)
Determines if the given name represents a file and not a directory. This method should match the behavior of java.io.File.isFile().
Parameters:
fileName - The file.
Returns:
true if fileName represents a file.

isDirectory

public boolean isDirectory(java.lang.String fileName)
Determines if the given name represents a directory. This method should match the behavior of java.io.File.isDirectory().
Parameters:
fileName - The file.
Returns:
true if fileName represents a directory.

lastModified

public long lastModified(java.lang.String fileName)
Indicates the time the file was last modified. This method should match the behavior of java.io.File.lastModified().
Parameters:
fileName - The file.
Returns:
the modification time of the file.

length

public long length(java.lang.String fileName)
Gets the length of the file. This method should match the behavior of java.io.File.length().
Parameters:
fileName - The file.
Returns:
the length of the file.

mkdir

public boolean mkdir(java.lang.String fileName,
                     byte uid)
Creates a directory on the mounted file system. This method should match the behavior of java.io.File.mkdir().
Parameters:
fileName - The name of the directory to create.
uid - The user that is trying to create the directory.
Returns:
true if the directory was created.

rename

public boolean rename(java.lang.String srcname,
                      java.lang.String destname,
                      byte uid)
Changes the name of a file. This method should match the behavior of java.io.File.renameTo(File dest).
Parameters:
srcname - The name of the file to be changed.
destname - The new name for the file.
uid - The user that is trying to rename the file.
Returns:
true if the file was renamed.

list

public java.lang.String[] list(java.lang.String fileName,
                               byte uid)
Retrieves a listing of the files in the directory specified. This method should match the behavior of java.io.File.list().
Parameters:
fileName - The directory to get a listing from.
uid - The user trying to retreive the list.
Returns:
the list of files, or null if fileName doesn't represent a directory.

delete

public boolean delete(java.lang.String fileName,
                      byte uid)
Removes the specified file from the mounted file system. This method should match the behavior of java.io.File.delete().
Parameters:
fileName - The File to delete.
uid - The user trying to delete the file.
Returns:
true if the file was removed.

touch

public void touch(java.lang.String fileName,
                  byte uid)
           throws java.io.IOException
Updates the last modified time on the given file to the current time. This method should match the behavior of com.dalsemi.fs.DSFile.touch().
Parameters:
fileName - The file to touch.
uid - The user trying to update the file.
Throws:
java.io.IOException -  

setUserPermissions

public void setUserPermissions(java.lang.String fileName,
                               int perms,
                               byte uid)
                        throws java.io.IOException
Changes the user/owner permissions for the given file. This method should match the behavior of com.dalsemi.fs.DSFile.setUserPermissions(int perms).
Parameters:
fileName - The file.
perms - The new permissions.
uid - The user that is trying to change the file.
Throws:
java.io.IOException -  

setOtherPermissions

public void setOtherPermissions(java.lang.String fileName,
                                int perms,
                                byte uid)
                         throws java.io.IOException
Changes the other (non-owner) permissions for the given file. This method should match the behavior of com.dalsemi.fs.DSFile.setOtherPermissions(int perms).
Parameters:
fileName - The file.
perms - The new permissions.
uid - The user that is trying to change the file.
Throws:
java.io.IOException -  

setUser

public void setUser(java.lang.String fileName,
                    byte newUID,
                    byte uid)
             throws java.io.IOException
Sets the owner of the given file. This method should match the behavior of com.dalsemi.fs.DSFile.setUser(byte uid).
Parameters:
fileName - The file.
newUID - The new owner.
uid - The user that is trying to change the file.
Throws:
java.io.IOException -  

getUserPermissions

public int getUserPermissions(java.lang.String fileName)
                       throws java.io.FileNotFoundException
Gets the user/owner permissions for the given file. This method should match the behavior of com.dalsemi.fs.DSFile.getUserPermissions().
Parameters:
fileName - The file.
Returns:
the user permissions.
Throws:
java.io.FileNotFoundException -  

getOtherPermissions

public int getOtherPermissions(java.lang.String fileName)
                        throws java.io.FileNotFoundException
Gets the other (non-owner) permissions for the given file. This method should match the behavior of com.dalsemi.fs.DSFile.getOtherPermissions().
Parameters:
fileName - The file.
Returns:
the other permissions.
Throws:
java.io.FileNotFoundException -  

getUser

public int getUser(java.lang.String fileName)
            throws java.io.FileNotFoundException
Gets the owner of a file. This method should match the behavior of com.dalsemi.fs.DSFile.getUser().
Parameters:
fileName - The file.
Returns:
the file's owner.
Throws:
java.io.FileNotFoundException -  

openWritingFD

public byte[] openWritingFD(java.lang.String fileName,
                            boolean append,
                            byte uid)
                     throws java.io.IOException
Opens the given file for writing. The file descriptor that is returned will be used to identify the file in other driver calls. A file descriptor can be any length and should hold any information the driver needs to identify the associated file and the stream's state. This method should match the behavior of java.io.FileOutputStream(String name, boolean append).
Parameters:
fileName - The name of the file to open.
append - If true and the file exists, the file should be opened and the file pointer set to the end of the file. If false and the file exists, all contents of the file should be erased and the file's length set to 0.
uid - The user trying to open the file.
Returns:
The file descriptor.
Throws:
java.io.IOException -  

openReadingFD

public byte[] openReadingFD(java.lang.String fileName,
                            byte uid)
                     throws java.io.FileNotFoundException
Opens the given file for reading. The file descriptor that is returned will be used to identify the file in other driver calls. A file descriptor can be any length and should hold any information the driver needs to identify the associated file and the stream's state. This method should match the behavior of java.io.FileInputStream(String name).
Parameters:
fileName - The name of the file to open.
uid - The user trying to open the file.
Returns:
The file descriptor.
Throws:
java.io.FileNotFoundException -  

openRandomFD

public byte[] openRandomFD(java.lang.String fileName,
                           byte uid)
                    throws java.io.IOException
Opens the given file for random access. The file descriptor that is returned will be used to identify the file in other driver calls. A file descriptor can be any length and should hold any information the driver needs to identify the associated file and the stream's state. This method should match the behavior of java.io.RandomAccessFile(String name, String mode).
Parameters:
fileName - The name of the file to open.
uid - The user trying to open the file.
Returns:
The file descriptor.
Throws:
java.io.IOException -  

writeBytes

public void writeBytes(byte[] fd,
                       byte[] data,
                       int start,
                       int length)
                throws java.io.IOException
Writes the given data to the file represented by the file descriptor. This method should match the behavior of java.io.OutputStream.write(byte[] b, int off, int len).
Parameters:
fd - The file descriptor identifying the file to write to.
data - The data to write.
start - The start offset in the data.
length - The number of bytes to write.
Throws:
java.io.IOException -  

readBytes

public int readBytes(byte[] fd,
                     byte[] data,
                     int start,
                     int length)
              throws java.io.IOException
Reads from the file represented by the file descriptor. This method should match the behavior of java.io.InputStream.read(byte[] b, int off, int len).
Parameters:
fd - The file descriptor identifying the file to read from.
data - A buffer to store the data that is read.
start - The start offset in the buffer.
length - The number of bytes to read.
Returns:
the number of bytes read.
Throws:
java.io.IOException -  

seek

public void seek(byte[] fd,
                 long n)
          throws java.io.IOException
Moves the file pointer to a given location, measured in bytes from the beginning of the file. This method should match the behavior of java.io.RandomAccessFile.seek(long pos).
Parameters:
fd - The file descriptor identifying the file.
n - The new position for the file pointer.
Throws:
java.io.IOException -  

skipBytes

public long skipBytes(byte[] fd,
                      long n)
               throws java.io.IOException
Skips the next n bytes of data from the stream. This method should match the behavior of java.io.InputStream.skip(long n) if the file descriptor represents a FileInputStream and should match the behavior of java.io.RandomAccessFile.skipBytes(long n) if the file descriptor represents a RandomAccessFile.
Parameters:
fd - The file descriptor identifying the file.
n - The number of bytes to skip.
Returns:
The actual number of bytes skipped.
Throws:
java.io.IOException -  

getOffset

public long getOffset(byte[] fd)
               throws java.io.IOException
Gets the current offset into the file. This method should match the behavior of java.io.RandomAccessFile.getFilePointer().
Parameters:
fd - The file descriptor identifying the file.
Returns:
the current position of the file pointer.
Throws:
java.io.IOException -  

getLength

public long getLength(byte[] fd)
               throws java.io.IOException
Gets the length of the file represented by the file descriptor. This method should match the behavior of java.io.RandomAccessFile.length().
Parameters:
fd - The file descriptor identifying the file.
Returns:
the length of the file.
Throws:
java.io.IOException -  

available

public int available(byte[] fd)
              throws java.io.IOException
The number of bytes that can be read without blocking. This method should match the behavior of java.io.FileInputStream.available().
Parameters:
fd - The file descriptor identifying the file.
Returns:
the number of bytes available.
Throws:
java.io.IOException -  

close

public void close(byte[] fd)
           throws java.io.IOException
Closes the file descriptor's stream and releases any system resources used. This method should match the behavior of java.io.FileInputStream.close(), java.io.FileOutputStream.close(), or java.io.RandomAccessFile.close() depending on the type of file descriptor passed in.
Parameters:
fd - The file descriptor identifying the file.
Throws:
java.io.IOException -  

unmount

public void unmount()
Allows the driver a chance to clean up and release any resources used when a mount point is removed.

getContents

public byte[] getContents(java.lang.String fileName,
                          byte uid)
                   throws java.io.IOException
Gets the complete contents of a file on the mounted file system. This method will be called when the system attempts to execute a file located on the mounted file system.
Parameters:
fileName - The file to retreive.
uid - The user trying to execute the file.
Returns:
the contents of the file.
Throws:
java.io.IOException -