nachos.kernel.filesys
Interface OpenFile

All Known Implementing Classes:
OpenFileReal, OpenFileStub

public interface OpenFile

Interface that provides read/write access to files in a filesystem. There are two implementations. One is a "stub" that directly turns the file operations into the underlying UNIX operations. (cf. comment in FileSystem.java). The other is the "real" implementation, which turns these operations into read and write disk sector requests. In this baseline implementation of the file system, we don't worry about concurrent accesses to the file system by different threads -- this is part of the assignment.


Method Summary
 int close()
          Close the file, releasing any resources held in kernel memory.
 long length()
          Determine the number of bytes in the file (this interface is simpler than the UNIX idiom -- lseek to end of file, tell, lseek back).
 int read(byte[] into, int index, int numBytes)
          Read bytes from the file, starting at the implicit position.
 int readAt(byte[] into, int index, int numBytes, long position)
          Read bytes from the file, bypassing the implicit position.
 void seek(long position)
          Set the position from which to start reading/writing -- UNIX lseek
 int write(byte[] from, int index, int numBytes)
          Write bytes to the file, starting at the implicit position.
 int writeAt(byte[] from, int index, int numBytes, long position)
          Write bytes to the file, bypassing the implicit position.
 

Method Detail

seek

void seek(long position)
Set the position from which to start reading/writing -- UNIX lseek

Parameters:
position - The desired position in the file, in bytes from the start of file.

readAt

int readAt(byte[] into,
           int index,
           int numBytes,
           long position)
Read bytes from the file, bypassing the implicit position.

Parameters:
into - Buffer into which to read data.
index - Starting position in the buffer.
numBytes - Number of bytes desired.
position - Starting position in the file.
Returns:
The number of bytes actually read (0 in case of an error).

writeAt

int writeAt(byte[] from,
            int index,
            int numBytes,
            long position)
Write bytes to the file, bypassing the implicit position.

Parameters:
from - Buffer containing the data to be written.
index - Starting position in the buffer.
numBytes - Number of bytes to write.
position - Starting position in the file.
Returns:
The number of bytes actually written (0 in case of an error).

read

int read(byte[] into,
         int index,
         int numBytes)
Read bytes from the file, starting at the implicit position. The position is incremented by the number of bytes read.

Parameters:
into - Buffer into which to read data.
index - Starting position in the buffer.
numBytes - Number of bytes desired.
Returns:
The number of bytes actually read (0 in case of an error).

write

int write(byte[] from,
          int index,
          int numBytes)
Write bytes to the file, starting at the implicit position. The position is incremented by the number of bytes read.

Parameters:
from - Buffer containing the data to be written.
index - Starting position in the buffer.
numBytes - Number of bytes to write.
Returns:
The number of bytes actually written (0 in case of an error).

length

long length()
Determine the number of bytes in the file (this interface is simpler than the UNIX idiom -- lseek to end of file, tell, lseek back).

Returns:
the length of the file in bytes.

close

int close()
Close the file, releasing any resources held in kernel memory. Subsequent attempts to access the file will fail.

Returns:
0 if an error occurred while closing the file, otherwise nonzero.