FreeNOS
Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes
FileSystemServer Class Reference

Abstract filesystem class. More...

#include <FileSystemServer.h>

Inheritance diagram for FileSystemServer:
ChannelServer< FileSystemServer, FileSystemMessage > DeviceServer LinnFileSystem TmpFileSystem NetworkServer

Public Member Functions

 FileSystemServer (Directory *root, const char *path)
 Constructor function. More...
 
virtual ~FileSystemServer ()
 Destructor function. More...
 
const char * getMountPath () const
 Get mount path. More...
 
u32 getNextInode ()
 Get next unused inode. More...
 
FileSystem::Result mount ()
 Mount the FileSystem. More...
 
FileSystem::Result registerFile (File *file, const char *path)
 Register a new File. More...
 
FileSystem::Result registerDirectory (Directory *dir, const char *path)
 Register a new Directory. More...
 
FileSystem::Result unregisterFile (const char *path)
 Remove a File from the FileSystemServer. More...
 
virtual FilecreateFile (const FileSystem::FileType type)
 Create a new file. More...
 
void pathHandler (FileSystemMessage *msg)
 Process an incoming filesystem request using a path. More...
 
void mountHandler (FileSystemMessage *msg)
 Process a filesystem mount request message. More...
 
void getFileSystemsHandler (FileSystemMessage *msg)
 Read the file system mounts table. More...
 
virtual bool retryRequests ()
 Retry any pending requests. More...
 
- Public Member Functions inherited from ChannelServer< FileSystemServer, FileSystemMessage >
 ChannelServer (FileSystemServer *inst)
 Constructor function. More...
 
virtual ~ChannelServer ()
 Destructor function. More...
 
int run ()
 Enters an infinite loop, serving incoming requests. More...
 
void setTimeout (const uint msec)
 Set a sleep timeout. More...
 

Protected Member Functions

FileSystem::Result processRequest (FileSystemRequest &req)
 Process a FileSystemRequest. More...
 
FileSystem::Result inodeHandler (FileSystemRequest &req)
 Handle a request for a File specified by its inode. More...
 
FileSystem::Result waitFileHandler (FileSystemRequest &req)
 Handle a WaitFile request. More...
 
void sendResponse (FileSystemMessage *msg) const
 Send response for a FileSystemMessage. More...
 
bool redirectRequest (const char *path, FileSystemMessage *msg)
 Try to forward the given FileSystemMessage to a mount file system. More...
 
void setRoot (Directory *newRoot)
 Change the filesystem root directory. More...
 
DirectorygetParentDirectory (const char *path)
 Retrieve parent Directory for a file. More...
 
FileCachelookupFile (const FileSystemPath &path)
 Retrieve a File from storage. More...
 
FileCachefindFileCache (const char *path) const
 Search the cache for an entry. More...
 
FileCachefindFileCache (const String &path) const
 Search the cache for an entry. More...
 
FileCachefindFileCache (const FileSystemPath &path) const
 Search the cache for an entry. More...
 
FileCacheinsertFileCache (File *file, const char *pathFormat)
 Inserts a file into the in-memory filesystem tree. More...
 
void removeFileFromCache (FileCache *cache, File *file)
 Remove a File from the cache. More...
 
void clearFileCache (FileCache *cache=ZERO)
 Cleans up the entire file cache (except opened file caches and root). More...
 
- Protected Member Functions inherited from ChannelServer< FileSystemServer, FileSystemMessage >
void addIPCHandler (const Size slot, IPCHandlerFunction h, const bool sendReply=true)
 Register a new IPC message action handler. More...
 
void addIRQHandler (const Size slot, IRQHandlerFunction h)
 Register a new IRQ message vector handler. More...
 
virtual void timeout ()
 Called when sleep timeout is reached. More...
 
virtual void onProcessTerminated (const ProcessID pid)
 Called whenever another Process is terminated. More...
 
void retryAllRequests ()
 Keep retrying requests until all served. More...
 

Protected Attributes

const ProcessID m_pid
 Process identifier. More...
 
FileCachem_root
 Root entry of the filesystem tree. More...
 
HashTable< u32, File * > m_inodeMap
 Contains a mapping of inode number to file of all cached files. More...
 
const char * m_mountPath
 Mount point path. More...
 
FileSystemMountm_mounts
 Table with mounted file systems (only used by the root file system). More...
 
List< FileSystemRequest * > * m_requests
 Contains ongoing requests. More...
 
- Protected Attributes inherited from ChannelServer< FileSystemServer, FileSystemMessage >
FileSystemServerm_instance
 Server object instance. More...
 
ChannelClientm_client
 Client for sending replies. More...
 
ChannelRegistrym_registry
 Contains registered channels. More...
 
MemoryChannel m_kernelEvent
 Kernel event channel. More...
 
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCountm_ipcHandlers
 IPC handler functions. More...
 
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCountm_irqHandlers
 IRQ handler functions. More...
 
ProcessID m_self
 ProcessID of ourselves. More...
 
Timer::Info m_time
 System timer value. More...
 
Timer::Info m_expiry
 System timer expiration value. More...
 

Static Private Attributes

static const Size MaximumFileSystemMounts = 32
 Maximum number of supported file system mount entries. More...
 
static const Size MaximumWaitSetCount = 32
 Maximum number of WaitSet entries supported. More...
 

Additional Inherited Members

- Public Types inherited from ChannelServer< FileSystemServer, FileSystemMessage >
enum  Result
 Result codes. More...
 
- Protected Types inherited from ChannelServer< FileSystemServer, FileSystemMessage >
typedef void(FileSystemServer ::* IPCHandlerFunction) (FileSystemMessage *)
 Member function pointer inside Base, to handle IPC messages. More...
 
typedef void(FileSystemServer ::* IRQHandlerFunction) (Size)
 Member function pointer inside Base, to handle interrupts. More...
 

Detailed Description

Abstract filesystem class.

Definition at line 44 of file FileSystemServer.h.

Constructor & Destructor Documentation

◆ FileSystemServer()

FileSystemServer::FileSystemServer ( Directory root,
const char *  path 
)

◆ ~FileSystemServer()

FileSystemServer::~FileSystemServer ( )
virtual

Destructor function.

Definition at line 51 of file FileSystemServer.cpp.

References clearFileCache(), m_requests, and m_root.

Member Function Documentation

◆ clearFileCache()

void FileSystemServer::clearFileCache ( FileCache cache = ZERO)
protected

Cleans up the entire file cache (except opened file caches and root).

Parameters
cacheInput FileCache object. ZERO to clean up all from root.

Definition at line 813 of file FileSystemServer.cpp.

References assert, HashTable< K, V >::count(), FileCache::entries, FileCache::file, File::getInode(), HashIterator< K, V >::hasCurrent(), m_inodeMap, m_root, FileCache::name, FileCache::parent, HashTable< K, V >::remove(), removeFileFromCache(), and ZERO.

Referenced by unregisterFile(), and ~FileSystemServer().

◆ createFile()

File * FileSystemServer::createFile ( const FileSystem::FileType  type)
virtual

Create a new file.

Parameters
typeDescribes the type of file to create.
Returns
Pointer to a new File on success or ZERO on failure.

Reimplemented in TmpFileSystem.

Definition at line 110 of file FileSystemServer.cpp.

References ZERO.

Referenced by processRequest().

◆ findFileCache() [1/3]

FileCache * FileSystemServer::findFileCache ( const char *  path) const
protected

Search the cache for an entry.

Parameters
pathFull path of the file to find.
Returns
Pointer to FileCache object on success, NULL on failure.

Definition at line 758 of file FileSystemServer.cpp.

Referenced by findFileCache(), getParentDirectory(), insertFileCache(), processRequest(), and unregisterFile().

◆ findFileCache() [2/3]

FileCache * FileSystemServer::findFileCache ( const FileSystemPath path) const
protected

Search the cache for an entry.

Parameters
pathFull path of the file to find.
Returns
Pointer to FileCache object on success, NULL on failure.

Definition at line 769 of file FileSystemServer.cpp.

References Associative< K, V >::contains(), FileCache::entries, ListIterator< T >::hasCurrent(), FileSystemPath::length(), String::length(), m_root, FileSystemPath::parent(), FileSystemPath::split(), HashTable< K, V >::value(), and ZERO.

◆ findFileCache() [3/3]

FileCache * FileSystemServer::findFileCache ( const String path) const
protected

Search the cache for an entry.

Parameters
pathFull path of the file to find.
Returns
Pointer to FileCache object on success, NULL on failure.

Definition at line 764 of file FileSystemServer.cpp.

References findFileCache().

◆ getFileSystemsHandler()

void FileSystemServer::getFileSystemsHandler ( FileSystemMessage msg)

◆ getMountPath()

const char * FileSystemServer::getMountPath ( ) const

Get mount path.

Returns
Mount path of the filesystem

Definition at line 61 of file FileSystemServer.cpp.

References m_mountPath.

Referenced by UDP::createSocket(), and ICMP::createSocket().

◆ getNextInode()

u32 FileSystemServer::getNextInode ( )

◆ getParentDirectory()

Directory * FileSystemServer::getParentDirectory ( const char *  path)
protected

Retrieve parent Directory for a file.

Parameters
pathPath to the file
Returns
Directory pointer on success or NULL on failure

Definition at line 659 of file FileSystemServer.cpp.

References FileCache::file, findFileCache(), String::length(), m_root, FileSystemPath::parent(), and ZERO.

Referenced by registerDirectory(), and registerFile().

◆ inodeHandler()

FileSystem::Result FileSystemServer::inodeHandler ( FileSystemRequest req)
protected

◆ insertFileCache()

FileCache * FileSystemServer::insertFileCache ( File file,
const char *  pathFormat 
)
protected

Inserts a file into the in-memory filesystem tree.

Parameters
fileFile to insert.
pathFormatFull path to the file to insert.
Returns
Pointer to the newly created FileCache, or NULL on failure.

Definition at line 731 of file FileSystemServer.cpp.

References assert, FileSystemPath::base(), findFileCache(), File::getInode(), HashTable< K, V >::insert(), String::length(), m_inodeMap, m_root, NULL, FileSystemPath::parent(), and ZERO.

Referenced by registerFile(), and setRoot().

◆ lookupFile()

FileCache * FileSystemServer::lookupFile ( const FileSystemPath path)
protected

Retrieve a File from storage.

This function is responsible for walking the given FileSystemPath, retrieving each uncached File into the FileCache, and returning a pointer to corresponding FileCache of the last entry in the given path.

Parameters
pathA path to lookup from storage.
Returns
Pointer to a FileCache on success, ZERO otherwise.

Definition at line 680 of file FileSystemServer.cpp.

References assert, Associative< K, V >::contains(), FileSystem::DirectoryFile, FileCache::entries, FileCache::file, File::getInode(), File::getType(), ListIterator< T >::hasCurrent(), HashTable< K, V >::insert(), Directory::lookup(), m_inodeMap, m_root, NULL, FileSystemPath::split(), HashTable< K, V >::value(), and ZERO.

Referenced by processRequest().

◆ mount()

FileSystem::Result FileSystemServer::mount ( )

◆ mountHandler()

void FileSystemServer::mountHandler ( FileSystemMessage msg)

◆ pathHandler()

void FileSystemServer::pathHandler ( FileSystemMessage msg)

Process an incoming filesystem request using a path.

This message handler is responsible for processing any kind of FileSystemMessages which have an FileSystemAction using the path field, such as OpenFile.

Parameters
msgIncoming request message.
See also
FileSystemMessage
FileSystemAction

Definition at line 194 of file FileSystemServer.cpp.

References List< T >::append(), assert, m_requests, NULL, processRequest(), and FileSystem::RetryAgain.

Referenced by FileSystemServer().

◆ processRequest()

FileSystem::Result FileSystemServer::processRequest ( FileSystemRequest req)
protected

◆ redirectRequest()

bool FileSystemServer::redirectRequest ( const char *  path,
FileSystemMessage msg 
)
protected

◆ registerDirectory()

FileSystem::Result FileSystemServer::registerDirectory ( Directory dir,
const char *  path 
)

Register a new Directory.

Parameters
dirDirectory object pointer
pathPath to the directory
Returns
Result code

Definition at line 138 of file FileSystemServer.cpp.

References ERROR, getParentDirectory(), FileSystem::NotFound, registerFile(), FileSystem::Success, and ZERO.

Referenced by UDP::initialize(), ICMP::initialize(), Ethernet::initialize(), IPV4::initialize(), ARP::initialize(), and main().

◆ registerFile()

FileSystem::Result FileSystemServer::registerFile ( File file,
const char *  path 
)

◆ removeFileFromCache()

void FileSystemServer::removeFileFromCache ( FileCache cache,
File file 
)
protected

Remove a File from the cache.

Parameters
cacheCache entry to start searching at
fileFile pointer to remove

Definition at line 794 of file FileSystemServer.cpp.

References assert, FileCache::entries, FileCache::file, HashIterator< K, V >::hasCurrent(), FileCache::name, and ZERO.

Referenced by clearFileCache().

◆ retryRequests()

bool FileSystemServer::retryRequests ( )
virtual

Retry any pending requests.

Returns
True if retry is needed again, false if all requests processed

Reimplemented from ChannelServer< FileSystemServer, FileSystemMessage >.

Reimplemented in NetworkServer.

Definition at line 629 of file FileSystemServer.cpp.

References DEBUG, ListIterator< T >::hasCurrent(), m_requests, processRequest(), and FileSystem::RetryAgain.

Referenced by NetworkServer::retryRequests().

◆ sendResponse()

void FileSystemServer::sendResponse ( FileSystemMessage msg) const
protected

◆ setRoot()

void FileSystemServer::setRoot ( Directory newRoot)
protected

Change the filesystem root directory.

This function set the root member to the given Directory pointer. Additionally, it inserts '/.' and '/..' references to the file cache.

Parameters
newRootA Directory pointer to set as the new root.
See also
root
insertFileCache

Definition at line 649 of file FileSystemServer.cpp.

References insertFileCache(), m_root, and ZERO.

Referenced by FileSystemServer(), and LinnFileSystem::LinnFileSystem().

◆ unregisterFile()

FileSystem::Result FileSystemServer::unregisterFile ( const char *  path)

◆ waitFileHandler()

FileSystem::Result FileSystemServer::waitFileHandler ( FileSystemRequest req)
protected

Field Documentation

◆ m_inodeMap

HashTable<u32, File *> FileSystemServer::m_inodeMap
protected

Contains a mapping of inode number to file of all cached files.

Definition at line 308 of file FileSystemServer.h.

Referenced by clearFileCache(), getNextInode(), inodeHandler(), insertFileCache(), lookupFile(), and waitFileHandler().

◆ m_mountPath

const char* FileSystemServer::m_mountPath
protected

Mount point path.

Definition at line 311 of file FileSystemServer.h.

Referenced by getMountPath(), DeviceServer::initialize(), mount(), and processRequest().

◆ m_mounts

FileSystemMount* FileSystemServer::m_mounts
protected

Table with mounted file systems (only used by the root file system).

Definition at line 314 of file FileSystemServer.h.

Referenced by getFileSystemsHandler(), mount(), mountHandler(), and redirectRequest().

◆ m_pid

const ProcessID FileSystemServer::m_pid
protected

Process identifier.

Definition at line 302 of file FileSystemServer.h.

Referenced by mount(), and processRequest().

◆ m_requests

List<FileSystemRequest *>* FileSystemServer::m_requests
protected

Contains ongoing requests.

Definition at line 317 of file FileSystemServer.h.

Referenced by pathHandler(), retryRequests(), and ~FileSystemServer().

◆ m_root

FileCache* FileSystemServer::m_root
protected

Root entry of the filesystem tree.

Definition at line 305 of file FileSystemServer.h.

Referenced by clearFileCache(), findFileCache(), getParentDirectory(), insertFileCache(), lookupFile(), setRoot(), and ~FileSystemServer().

◆ MaximumFileSystemMounts

const Size FileSystemServer::MaximumFileSystemMounts = 32
staticprivate

Maximum number of supported file system mount entries.

Definition at line 49 of file FileSystemServer.h.

Referenced by getFileSystemsHandler(), mount(), mountHandler(), and redirectRequest().

◆ MaximumWaitSetCount

const Size FileSystemServer::MaximumWaitSetCount = 32
staticprivate

Maximum number of WaitSet entries supported.

Definition at line 52 of file FileSystemServer.h.

Referenced by waitFileHandler().


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