uk.me.parabola.imgfmt.sys
Class ImgFS

java.lang.Object
  extended by uk.me.parabola.imgfmt.sys.ImgFS
All Implemented Interfaces:
java.io.Closeable, FileSystem

public class ImgFS
extends java.lang.Object
implements FileSystem

The img file is really a filesystem containing several files. It is made up of a header, a directory area and a data area which occur in the filesystem in that order.

Author:
steve

Method Summary
 void close()
          Close the filesystem.
 ImgChannel create(java.lang.String name)
          Create a new file, it must not already exist.
static FileSystem createFs(java.lang.String filename, FileSystemParam params)
          Create an IMG file from its external filesystem name and optionally some parameters.
 FileSystemParam fsparam()
          Get the filesystem / archive parameters.
 void fsparam(FileSystemParam param)
          Reconfigure the filesystem with the given parameters.
 java.util.List<DirectoryEntry> list()
          List all the files in the directory.
 DirectoryEntry lookup(java.lang.String name)
          Lookup the file and return a directory entry for it.
 ImgChannel open(java.lang.String name, java.lang.String mode)
          Open a file.
static FileSystem openFs(java.lang.String name)
          Open an existing IMG file system.
 void sync()
          Sync with the underlying file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createFs

public static FileSystem createFs(java.lang.String filename,
                                  FileSystemParam params)
                           throws FileNotWritableException
Create an IMG file from its external filesystem name and optionally some parameters.

Parameters:
filename - The name of the file to be created.
params - File system parameters. Can not be null.
Throws:
FileNotWritableException - If the file can not be written to.

openFs

public static FileSystem openFs(java.lang.String name)
                         throws java.io.FileNotFoundException
Open an existing IMG file system.

Parameters:
name - The file name to open.
Returns:
A File system that can be used lookup the internal files.
Throws:
java.io.FileNotFoundException - When the file doesn't exist or can't be read.

create

public ImgChannel create(java.lang.String name)
                  throws FileExistsException
Create a new file, it must not already exist.

Specified by:
create in interface FileSystem
Parameters:
name - The file name.
Returns:
A directory entry for the new file.
Throws:
FileExistsException - If the file already exists.

open

public ImgChannel open(java.lang.String name,
                       java.lang.String mode)
                throws java.io.FileNotFoundException
Open a file. The returned file object can be used to read and write the underlying file.

Specified by:
open in interface FileSystem
Parameters:
name - The file name to open.
mode - Either "r" for read access, "w" for write access or "rw" for both read and write.
Returns:
A file descriptor.
Throws:
java.io.FileNotFoundException - When the file does not exist.

lookup

public DirectoryEntry lookup(java.lang.String name)
                      throws java.io.FileNotFoundException
Lookup the file and return a directory entry for it.

Specified by:
lookup in interface FileSystem
Parameters:
name - The filename to look up.
Returns:
A directory entry.
Throws:
java.io.FileNotFoundException - If an error occurs looking for the file, including it not existing.

list

public java.util.List<DirectoryEntry> list()
List all the files in the directory.

Specified by:
list in interface FileSystem
Returns:
A List of directory entries.

fsparam

public FileSystemParam fsparam()
Description copied from interface: FileSystem
Get the filesystem / archive parameters. Things that are stored in the header.

Specified by:
fsparam in interface FileSystem
Returns:
The filesystem parameters.

fsparam

public void fsparam(FileSystemParam param)
Description copied from interface: FileSystem
Reconfigure the filesystem with the given parameters. Only some parameters can be changed and the may only be changeable at certain points in the construction of a file system for example.

Specified by:
fsparam in interface FileSystem
Parameters:
param - The new parameters.

sync

public void sync()
          throws java.io.IOException
Sync with the underlying file. All unwritten data is written out to the underlying file.

Specified by:
sync in interface FileSystem
Throws:
java.io.IOException - If an error occurs during the write.

close

public void close()
Close the filesystem. Any saved data is flushed out. It is better to explicitly sync the data out first, to be sure that it has worked.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface FileSystem