tac0S
Template Affectional Command Operating System
Public Member Functions | List of all members
OpenFile Class Reference

Public Member Functions

 OpenFile (int sector)
 OpenFileTable::OpenFileTable Open a Nachos file for reading and writing. Bring the file header into memory while the file is open. More...
 
 ~OpenFile ()
 OpenFileTable::~OpenFileTable Close a Nachos file, de-allocating any in-memory data structures.
 
void Seek (int position, unsigned int tid=0)
 OpenFileTable::Seek Change the current location within the open file – the point at which the next Read or Write will start from. More...
 
int Read (char *into, int numBytes, unsigned int tid=0)
 OpenFileTable::Read/Write Read/write a portion of a file, starting from seekPosition. More...
 
int Write (const char *from, int numBytes, unsigned int tid=0)
 OpenFileTable::Write into a file. More...
 
int ReadAt (char *into, int numBytes, int position)
 OpenFileTable::ReadAt/WriteAt Read/write a portion of a file, starting at "position". Return the number of bytes actually written or read, but has no side effects (except that Write modifies the file, of course). More...
 
int WriteAt (const char *from, int numBytes, int position)
 
int Length ()
 OpenFileTable::Length. More...
 
int get_sector ()
 
void add_seek (unsigned int tid)
 OpenFileTable::add_seek add a seek to a openfile Allow multi threads to access to the same openfile with separated pointer. More...
 
bool remove_seek (unsigned int tid)
 OpenFileTable::remove_seek remove a seek to a openfile Allow multi threads to access to the same openfile with separated pointer. More...
 
bool isOpenByOthers ()
 
bool isdir ()
 

Constructor & Destructor Documentation

OpenFile::OpenFile ( int  sector)

OpenFileTable::OpenFileTable Open a Nachos file for reading and writing. Bring the file header into memory while the file is open.

Parameters
sector– the location on disk of the file header for this file

Member Function Documentation

void OpenFile::add_seek ( unsigned int  tid)

OpenFileTable::add_seek add a seek to a openfile Allow multi threads to access to the same openfile with separated pointer.

Parameters
tidthe thread tid
int OpenFile::Length ( )

OpenFileTable::Length.

Returns
Return the number of bytes in the file.
int OpenFile::Read ( char *  into,
int  numBytes,
unsigned int  tid = 0 
)

OpenFileTable::Read/Write Read/write a portion of a file, starting from seekPosition.

Returns
Return the number of bytes actually written or read, and as a side effect, increment the current position within the file.

Implemented using the more primitive ReadAt/WriteAt.

Parameters
into– the buffer to contain the data to be read from disk
from– the buffer containing the data to be written to disk
numBytes– the number of bytes to transfer
int OpenFile::ReadAt ( char *  into,
int  numBytes,
int  position 
)

OpenFileTable::ReadAt/WriteAt Read/write a portion of a file, starting at "position". Return the number of bytes actually written or read, but has no side effects (except that Write modifies the file, of course).

There is no guarantee the request starts or ends on an even disk sector boundary; however the disk only knows how to read/write a whole disk sector at a time. Thus:

For ReadAt: We read in all of the full or partial sectors that are part of the request, but we only copy the part we are interested in. For WriteAt: We must first read in any sectors that will be partially written, so that we don't overwrite the unmodified portion. We then copy in the data that will be modified, and write back all the full or partial sectors that are part of the request.

Parameters
into– the buffer to contain the data to be read from disk
from– the buffer containing the data to be written to disk
numBytes– the number of bytes to transfer
position– the offset within the file of the first byte to be read/written
bool OpenFile::remove_seek ( unsigned int  tid)

OpenFileTable::remove_seek remove a seek to a openfile Allow multi threads to access to the same openfile with separated pointer.

Parameters
tidthe thread tid
void OpenFile::Seek ( int  position,
unsigned int  tid = 0 
)

OpenFileTable::Seek Change the current location within the open file – the point at which the next Read or Write will start from.

Parameters
position– the location within the file for the next Read/Write
int OpenFile::Write ( const char *  into,
int  numBytes,
unsigned int  tid = 0 
)

OpenFileTable::Write into a file.

Parameters
into
numBytes
tid
Returns

The documentation for this class was generated from the following files: