Class FileSystem

java.lang.Object
   |
   +----FileSystem

public class FileSystem
extends Object
A simulated file system.

Author:
Ray Ontko

Variable Index

 o NOT_A_BLOCK
 o ROOT_INDEX_NODE_NUMBER

Constructor Index

 o FileSystem(String, String)
Construct a FileSystem and open a FileSystem file.

Method Index

 o allocateBlock()
Allocate a data block from the list of free blocks.
 o allocateIndexNode()
Allocate an index node for the file system.
 o close()
Close the backing file for this FileSystem, if any.
 o freeBlock(int)
Mark a data block as being free in the free list.
 o getBlockSize()
Get the blockSize for this FileSystem.
 o getDataBlockOffset()
 o getFreeListBlockOffset()
 o getInodeBlockOffset()
 o getRootIndexNode()
Get the rootIndexNode for this FileSystem.
 o open()
Open a backing file for this FileSystem and read the superblock.
 o read(byte[], int)
Read bytes into a buffer from the specified absolute block number of the file system.
 o readIndexNode(IndexNode, short)
Reads an index node at the index node location specified.
 o write(byte[], int)
Write bytes from a buffer to the specified absolute block number of the file system.
 o writeIndexNode(IndexNode, short)
Writes an index node at the index node location specified.

Variables

 o ROOT_INDEX_NODE_NUMBER
 public static short ROOT_INDEX_NODE_NUMBER
 o NOT_A_BLOCK
 public static int NOT_A_BLOCK

Constructors

 o FileSystem
 public FileSystem(String newFilename,
                   String newMode) throws IOException
Construct a FileSystem and open a FileSystem file.

Parameters:
newFilename - the name of the FileSystem file to open
newMode - the mode ("r" or "rw") to use when opening the file
Throws: IOException
if any IOExceptions are thrown during the open.

Methods

 o getBlockSize
 public short getBlockSize()
Get the blockSize for this FileSystem.

Returns:
the block size in bytes
 o getFreeListBlockOffset
 public int getFreeListBlockOffset()
 o getInodeBlockOffset
 public int getInodeBlockOffset()
 o getDataBlockOffset
 public int getDataBlockOffset()
 o getRootIndexNode
 public IndexNode getRootIndexNode()
Get the rootIndexNode for this FileSystem.

Returns:
the root index node
 o open
 public void open() throws IOException
Open a backing file for this FileSystem and read the superblock.

Throws: IOException
if the open or read causes IOException to be thrown
 o close
 public void close() throws IOException
Close the backing file for this FileSystem, if any.

Throws: IOException
if the closing the backing file causes any IOException to be thrown
 o read
 public void read(byte bytes[],
                  int blockNumber) throws IOException
Read bytes into a buffer from the specified absolute block number of the file system.

Parameters:
bytes - the byte buffer into which the block should be read
blockNumber - the absolute block number which should be read
Throws: IOException
if there are any exceptions during the read from the underlying "file system" file.
 o write
 public void write(byte bytes[],
                   int blockNumber) throws IOException
Write bytes from a buffer to the specified absolute block number of the file system.

Parameters:
bytes - the byte buffer from which the block should be written
blockNumber - the absolute block number which should be written
Throws: IOException
if there are any exceptions during the write to the underlying "file system" file.
 o freeBlock
 public void freeBlock(int dataBlockNumber) throws IOException
Mark a data block as being free in the free list.

Parameters:
dataBlockNumber - the data block which is to be marked free
Throws: IOException
if any exception occurs during an operation on the underlying "file system" file.
 o allocateBlock
 public int allocateBlock() throws IOException
Allocate a data block from the list of free blocks.

Returns:
the data block number which was allocated; -1 if no blocks are available
Throws: IOException
if any exception occurs during an operation on the underlying "file system" file.
 o allocateIndexNode
 public short allocateIndexNode() throws IOException
Allocate an index node for the file system.

Returns:
the inode number for the next available index node; -1 if there are no index nodes available.
Throws: IOException
if there is an exception during an operation on the underlying "file system" file.
 o readIndexNode
 public void readIndexNode(IndexNode indexNode,
                           short indexNodeNumber) throws IOException
Reads an index node at the index node location specified.

Parameters:
indexNode - the index node
indexNodeNumber - the location
 o writeIndexNode
 public void writeIndexNode(IndexNode indexNode,
                            short indexNodeNumber) throws IOException
Writes an index node at the index node location specified.

Parameters:
indexNode - the index node
indexNodeNumber - the location