|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.filesys.OpenFileReal
class OpenFileReal
This is a class for managing an open Nachos file. As in UNIX, a file must be open before we can read or write to it. Once we're all done, we can close it (in Nachos, by deleting the OpenFile data structure). Also as in UNIX, for convenience, we keep the file header in memory while the file is open. Supports opening, closing, reading and writing to individual files. The operations supported are similar to the UNIX ones. There are two implementations. This is the "real" implementation, that 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.
Field Summary | |
---|---|
private FileHeader |
hdr
Cached copy of the header for this file. |
private int |
seekPosition
Current position within the file. |
Constructor Summary | |
---|---|
OpenFileReal(int sector)
Open a Nachos file for reading and writing. |
Method Summary | |
---|---|
int |
close()
Close the file, releasing any resources held in kernel memory. |
long |
length()
Determine the number of bytes in the file. |
int |
read(byte[] into,
int index,
int numBytes)
Read a portion of a file, starting from seekPosition. |
int |
readAt(byte[] into,
int index,
int numBytes,
long position)
Read a portion of a file, starting at "position". |
void |
seek(long position)
Change the current location within the open file -- the point at which the next Read or Write will start from. |
int |
write(byte[] from,
int index,
int numBytes)
Write a portion of a file, starting from seekPosition. |
int |
writeAt(byte[] from,
int index,
int numBytes,
long position)
Write a portion of a file, starting at "position". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private FileHeader hdr
private int seekPosition
Constructor Detail |
---|
OpenFileReal(int sector)
sector
- The location on disk of the file header for this file.Method Detail |
---|
public void seek(long position)
seek
in interface OpenFile
position
- -- the location within the file for the next Read/Write.public int read(byte[] into, int index, int numBytes)
read
in interface OpenFile
into
- The buffer to contain the data to be read from disk .index
- Position in the buffer at which to begin placing data.numBytes
- The number of bytes to transfer.
public int write(byte[] from, int index, int numBytes)
write
in interface OpenFile
from
- The buffer containing the data to be written to disk .index
- Position in the buffer at which to begin taking data.numBytes
- The number of bytes to transfer.
public int readAt(byte[] into, int index, int numBytes, long position)
readAt
in interface OpenFile
into
- The buffer to contain the data to be read from disk.index
- Position in the buffer at which to begin placing data.numBytes
- The number of bytes to transfer.position
- The offset within the file of the first byte to be
read/written.
public int writeAt(byte[] from, int index, int numBytes, long position)
writeAt
in interface OpenFile
from
- The buffer containing the data to be written to disk.index
- Position in the buffer at which to begin placing data.numBytes
- The number of bytes to transfer.position
- The offset within the file of the first byte to be
read/written.
public long length()
length
in interface OpenFile
public int close()
close
in interface OpenFile
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |