FreeNOS
Data Structures | Public Types | Public Member Functions | Static Public Attributes | Private Attributes
FileDescriptor Class Reference

Abstracts files which are opened by a user process. More...

#include <FileDescriptor.h>

Inheritance diagram for FileDescriptor:
StrictSingleton< FileDescriptor >

Data Structures

struct  Entry
 Describes a single file opened by a user process. More...
 

Public Types

enum  Result { Success, InvalidArgument, OutOfFiles }
 Result code. More...
 

Public Member Functions

 FileDescriptor ()
 Constructor. More...
 
EntrygetArray (Size &count)
 Get entry table. More...
 
void setArray (Entry *array, const Size count)
 Assign entry table. More...
 
Result openEntry (const u32 inode, const ProcessID filesystem, Size &index)
 Add new file descriptor entry. More...
 
EntrygetEntry (const Size index)
 Retrieve a file descriptor Entry. More...
 
Result closeEntry (const Size index)
 Remove file descriptor entry. More...
 

Static Public Attributes

static const Size MaximumFiles = 1024
 Default maximum number of files which can be opened. More...
 

Private Attributes

Entrym_array
 Pointer to array of entries. More...
 
Size m_count
 Number of entries in the array. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from StrictSingleton< FileDescriptor >
static FileDescriptorinstance ()
 Retrieve the instance. More...
 

Detailed Description

Abstracts files which are opened by a user process.

Definition at line 36 of file FileDescriptor.h.

Member Enumeration Documentation

◆ Result

Result code.

Enumerator
Success 
InvalidArgument 
OutOfFiles 

Definition at line 57 of file FileDescriptor.h.

Constructor & Destructor Documentation

◆ FileDescriptor()

FileDescriptor::FileDescriptor ( )

Constructor.

Definition at line 20 of file FileDescriptor.cpp.

Member Function Documentation

◆ closeEntry()

FileDescriptor::Result FileDescriptor::closeEntry ( const Size  index)

Remove file descriptor entry.

Parameters
indexIndex in the array of entries
Returns
Result code

Definition at line 68 of file FileDescriptor.cpp.

References InvalidArgument, m_array, m_count, FileDescriptor::Entry::open, and Success.

Referenced by FileSystemClient::closeFile().

◆ getArray()

FileDescriptor::Entry * FileDescriptor::getArray ( Size count)

Get entry table.

Parameters
countMaximum number of entries
Returns
Entry table pointer

Definition at line 25 of file FileDescriptor.cpp.

References m_array, and m_count.

Referenced by setupMappings().

◆ getEntry()

FileDescriptor::Entry * FileDescriptor::getEntry ( const Size  index)

Retrieve a file descriptor Entry.

Parameters
indexIndex in the array of entries
Returns
Pointer to the Entry on success or ZERO on failure

Definition at line 58 of file FileDescriptor.cpp.

References m_array, m_count, and ZERO.

Referenced by lseek(), FileStorage::read(), FileSystemClient::readFile(), NetworkClient::waitSocket(), FileStorage::write(), FileSystemClient::writeFile(), and NetworkClient::writeSocketInfo().

◆ openEntry()

FileDescriptor::Result FileDescriptor::openEntry ( const u32  inode,
const ProcessID  filesystem,
Size index 
)

Add new file descriptor entry.

Parameters
inodeInode number of the file to add
filesystemProcess identifier of the filesystem
indexOn output contains the index number for the entry
Returns
Result code

Definition at line 38 of file FileDescriptor.cpp.

References FileDescriptor::Entry::inode, m_array, m_count, open(), FileDescriptor::Entry::open, OutOfFiles, FileDescriptor::Entry::pid, FileDescriptor::Entry::position, and Success.

Referenced by FileSystemClient::openFile().

◆ setArray()

void FileDescriptor::setArray ( Entry array,
const Size  count 
)

Assign entry table.

Parameters
arrayPointer to array with file descriptor entries
countNumber of Entry structures in the array

Definition at line 31 of file FileDescriptor.cpp.

References m_array, and m_count.

Referenced by setupMappings().

Field Documentation

◆ m_array

Entry* FileDescriptor::m_array
private

Pointer to array of entries.

Definition at line 123 of file FileDescriptor.h.

Referenced by closeEntry(), getArray(), getEntry(), openEntry(), and setArray().

◆ m_count

Size FileDescriptor::m_count
private

Number of entries in the array.

Definition at line 126 of file FileDescriptor.h.

Referenced by closeEntry(), getArray(), getEntry(), openEntry(), and setArray().

◆ MaximumFiles

const Size FileDescriptor::MaximumFiles = 1024
static

Default maximum number of files which can be opened.

Definition at line 41 of file FileDescriptor.h.


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