Class FileSystem
java.lang.Object
|
+----FileSystem
- public class FileSystem
- extends Object
A simulated file system.
- Author:
- Ray Ontko
-
NOT_A_BLOCK
-
-
ROOT_INDEX_NODE_NUMBER
-
-
FileSystem(String, String)
- Construct a FileSystem and open a FileSystem file.
-
allocateBlock()
- Allocate a data block from the list of free blocks.
-
allocateIndexNode()
- Allocate an index node for the file system.
-
close()
- Close the backing file for this FileSystem, if any.
-
freeBlock(int)
- Mark a data block as being free in the free list.
-
getBlockSize()
- Get the blockSize for this FileSystem.
-
getDataBlockOffset()
-
-
getFreeListBlockOffset()
-
-
getInodeBlockOffset()
-
-
getRootIndexNode()
- Get the rootIndexNode for this FileSystem.
-
open()
- Open a backing file for this FileSystem and read the superblock.
-
read(byte[], int)
- Read bytes into a buffer from the specified absolute block number
of the file system.
-
readIndexNode(IndexNode, short)
- Reads an index node at the index node location specified.
-
write(byte[], int)
- Write bytes from a buffer to the specified absolute block number
of the file system.
-
writeIndexNode(IndexNode, short)
- Writes an index node at the index node location specified.
ROOT_INDEX_NODE_NUMBER
public static short ROOT_INDEX_NODE_NUMBER
NOT_A_BLOCK
public static int NOT_A_BLOCK
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.
getBlockSize
public short getBlockSize()
- Get the blockSize for this FileSystem.
- Returns:
- the block size in bytes
getFreeListBlockOffset
public int getFreeListBlockOffset()
getInodeBlockOffset
public int getInodeBlockOffset()
getDataBlockOffset
public int getDataBlockOffset()
getRootIndexNode
public IndexNode getRootIndexNode()
- Get the rootIndexNode for this FileSystem.
- Returns:
- the root index node
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
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
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.
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.
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.
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.
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.
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
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