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

Public Member Functions

 FileSystem (bool format)
 FileSystem::FileSystem Initialize the file system. If format = TRUE, the disk has nothing on it, and we need to initialize the disk to contain an empty directory, and a bitmap of free sectors (with almost but not all of the sectors marked as free). More...
 
 ~FileSystem ()
 ~FileSystem() delete all file system
 
bool Create (const char *name, int initialSize, File_type type=f)
 FileSystem::Create Create a file in the Nachos file system (similar to UNIX create). Since we can't increase the size of files dynamically, we have to give Create the initial size of the file. More...
 
bool MkDir (const char *directory_name, unsigned int tid=0)
 FileSystem::MkDir Create a new folder in the Nachos file system. More...
 
bool CdDir (const char *directory_name, unsigned int tid=0)
 FileSystem::CdDir Come in folder given. More...
 
bool RmDir (const char *directory_name, unsigned int tid=0)
 FileSystem::RmDir Remove the folder given. More...
 
path_parse_tCdFromPathName (const char *path_name, unsigned int tid=0, int truncate=0)
 FileSystem::CdFromPathName can jump into the directory with a path. More...
 
OpenFileOpenFromPathName (const char *path_name, unsigned int tid=0)
 FileSystem::OpenFromPathName. More...
 
bool MkdirFromPathName (const char *path_name, unsigned int tid=0)
 FileSystem::MkdirFromPathName. More...
 
bool RmdirFromPathName (const char *path_name, unsigned int tid=0)
 
OpenFileOpen (const char *name, unsigned int tid=0)
 FileSystem::Open Open a file for reading and writing. To open a file: Find the location of the file's header, using the directory Bring the header into memory. More...
 
bool Remove (const char *name, unsigned int tid=0)
 FileSystem::Remove Delete a file from the file system. This requires: Remove it from the directory Delete the space for its header Delete the space for its data blocks Write changes to directory, bitmap back to disk. More...
 
void List ()
 FileSystem::List List all the files in the file system directory.
 
void Print ()
 FileSystem::Print Print everything about the file system: the contents of the bitmap the contents of the directory for each file in the directory, the contents of the file header the data in the file.
 
void registerOpenFileTable (int *table, unsigned int tid)
 Allow a thread to use filesystem by register his tid. More...
 
bool unregisterOpenFileTable (unsigned int tid)
 When thread die need to call this method. More...
 
int UserOpen (const char *name, unsigned int tid)
 allow a user to open a file More...
 
int UserRead (int fileDescriptor, char *into, int numBytes, unsigned int tid)
 allow user to read into file More...
 
int UserWrite (int fileDescriptor, char *from, int numBytes, unsigned int tid)
 Allow user to write into a file. More...
 
void UserSetSeek (int fileDescriptor, int position, unsigned int tid)
 User method that allow user to move the seek into a file. More...
 
int UserCloseFile (int fileDescriptor, int *threadTableFileDescriptor, unsigned int tid)
 

Constructor & Destructor Documentation

FileSystem::FileSystem ( bool  format)

FileSystem::FileSystem Initialize the file system. If format = TRUE, the disk has nothing on it, and we need to initialize the disk to contain an empty directory, and a bitmap of free sectors (with almost but not all of the sectors marked as free).

If format = FALSE, we just have to open the files representing the bitmap and the directory.

Parameters
format– should we initialize the disk?

Member Function Documentation

bool FileSystem::CdDir ( const char *  directory_name,
unsigned int  tid = 0 
)

FileSystem::CdDir Come in folder given.

Returns
Return TRUE if everything goes ok, otherwise, return FALSE.
Parameters
name– name of folder to come in
path_parse_t * FileSystem::CdFromPathName ( const char *  path_name,
unsigned int  tid = 0,
int  truncate = 0 
)

FileSystem::CdFromPathName can jump into the directory with a path.

Parameters
path_namethe path name
Returns
bool FileSystem::Create ( const char *  name,
int  initialSize,
File_type  type = f 
)

FileSystem::Create Create a file in the Nachos file system (similar to UNIX create). Since we can't increase the size of files dynamically, we have to give Create the initial size of the file.

The steps to create a file are: Make sure the file doesn't already exist Allocate a sector for the file header Allocate space on disk for the data blocks for the file Add the name to the directory Store the new file header on disk Flush the changes to the bitmap and the directory back to disk

Returns
Return TRUE if everything goes ok, otherwise, return FALSE.

Create fails if: file is already in directory no free space for file header no free entry for file in directory no free space for data blocks for the file

Note that this implementation assumes there is no concurrent access to the file system!

Parameters
name– name of file to be created
initialSize– size of file to be created
bool FileSystem::MkDir ( const char *  directory_name,
unsigned int  tid = 0 
)

FileSystem::MkDir Create a new folder in the Nachos file system.

Returns
Return TRUE if everything goes ok, otherwise, return FALSE.
Parameters
name– name of folder to be created
bool FileSystem::MkdirFromPathName ( const char *  path_name,
unsigned int  tid = 0 
)

FileSystem::MkdirFromPathName.

Parameters
path_name
tid
Returns
OpenFile * FileSystem::Open ( const char *  name,
unsigned int  tid = 0 
)

FileSystem::Open Open a file for reading and writing. To open a file: Find the location of the file's header, using the directory Bring the header into memory.

Parameters
name– the text name of the file to be opened
Returns
openfile, or NULL if error
OpenFile * FileSystem::OpenFromPathName ( const char *  path_name,
unsigned int  tid = 0 
)

FileSystem::OpenFromPathName.

Parameters
path_name
tid
Returns
openFile pointer of te file opened, null if no success
void FileSystem::registerOpenFileTable ( int *  table,
unsigned int  tid 
)

Allow a thread to use filesystem by register his tid.

Parameters
table
tid
bool FileSystem::Remove ( const char *  name,
unsigned int  tid = 0 
)

FileSystem::Remove Delete a file from the file system. This requires: Remove it from the directory Delete the space for its header Delete the space for its data blocks Write changes to directory, bitmap back to disk.

Returns
Return TRUE if the file was deleted, FALSE if the file wasn't in the file system.
Parameters
name– the text name of the file to be removed
bool FileSystem::RmDir ( const char *  directory_name,
unsigned int  tid = 0 
)

FileSystem::RmDir Remove the folder given.

Returns
Return TRUE if everything goes ok, otherwise, return FALSE.
Parameters
name– name of folder to be removed
bool FileSystem::RmdirFromPathName ( const char *  path_name,
unsigned int  tid = 0 
)
Parameters
path_name
tid
Returns
bool FileSystem::unregisterOpenFileTable ( unsigned int  tid)

When thread die need to call this method.

Parameters
tidthe tid of the thread
Returns
false if an error occur, otherwise true
int FileSystem::UserOpen ( const char *  name,
unsigned int  tid 
)

allow a user to open a file

Methode for User Syscall

Parameters
name
tid
Returns
a file descritptor
int FileSystem::UserRead ( int  fileDescriptor,
char *  into,
int  numBytes,
unsigned int  tid 
)

allow user to read into file

Parameters
fileDescriptor
into
numBytes
tid
Returns
void FileSystem::UserSetSeek ( int  fileDescriptor,
int  position,
unsigned int  tid 
)

User method that allow user to move the seek into a file.

Parameters
fileDescriptor
position
tid
int FileSystem::UserWrite ( int  fileDescriptor,
char *  from,
int  numBytes,
unsigned int  tid 
)

Allow user to write into a file.

Parameters
fileDescriptor
from
numBytes
tid
Returns

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