next up previous contents
Next: File System Physical Representation Up: Nachos Filesystem Previous: FileSystem Object

OpenFile Object

  The OpenFile object manages the details of accessing the contents of a specific file. Opening a file for access returns a pointer to an OpenFile object that can be used in subsequent read and write operations. Each OpenFile object has an associated read/write mark that keeps track of where the previous read or write operation ended. Supported operations include:

OpenFile(int sector)
opens the file sector. Argument sector is the sector number containing the FileHeader for the file. A FileHeader (discussed in detail below) is similar to a Unix inode in that the low-level file system routines know nothing about file names; files are uniquely identified by there FileHeader number. OpenFile returns a pointer to an OpenFile object that is subsequently used to invoke any of remaining operations.
int ReadAt(char *into, int numBytes, int position)
copies numBytes of data into the buffer into. Argument position specifies at what offset within the file reading is to start. ReadAt returns the number of bytes successfully read.
int Read(char *into, int numBytes)
simply invokes ReadAt, passing it the current read/write mark. Read is used to read the file sequentially from start to finish, letting keeping track of which part of the file has already been read, and at what offset the next read operation is to continue. Read returns the number of bytes successfully read.

int WriteAt(char *from, int numBytes, int position)
copies numBytes of data from the buffer from to the open file, starting position bytes from the start of the file. WriteAt returns the number of bytes actually written.

int Write(char *from, int numBytes)
is used to write a file sequentially. The first Write begins at the start of the file, with subsequent writes beginning where the previous operation ended. Write returns the number of bytes actually written.
int Length()
returns the actual size of the file.


next up previous contents
Next: File System Physical Representation Up: Nachos Filesystem Previous: FileSystem Object

Thomas Narten
Mon Feb 3 15:00:27 EST 1997