FreeNOS
|
Abstract filesystem class. More...
#include <FileSystemServer.h>
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 File * | createFile (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... | |
Directory * | getParentDirectory (const char *path) |
Retrieve parent Directory for a file. More... | |
FileCache * | lookupFile (const FileSystemPath &path) |
Retrieve a File from storage. More... | |
FileCache * | findFileCache (const char *path) const |
Search the cache for an entry. More... | |
FileCache * | findFileCache (const String &path) const |
Search the cache for an entry. More... | |
FileCache * | findFileCache (const FileSystemPath &path) const |
Search the cache for an entry. More... | |
FileCache * | insertFileCache (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... | |
FileCache * | m_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... | |
FileSystemMount * | m_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 > | |
FileSystemServer * | m_instance |
Server object instance. More... | |
ChannelClient * | m_client |
Client for sending replies. More... | |
ChannelRegistry & | m_registry |
Contains registered channels. More... | |
MemoryChannel | m_kernelEvent |
Kernel event channel. More... | |
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > | m_ipcHandlers |
IPC handler functions. More... | |
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCount > | m_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... | |
Abstract filesystem class.
Definition at line 44 of file FileSystemServer.h.
FileSystemServer::FileSystemServer | ( | Directory * | root, |
const char * | path | ||
) |
Constructor function.
root | Root directory to use |
path | Path to which we are mounted. |
Definition at line 29 of file FileSystemServer.cpp.
References ChannelServer< FileSystemServer, FileSystemMessage >::addIPCHandler(), FileSystem::CreateFile, FileSystem::DeleteFile, FileSystem::GetFileSystems, getFileSystemsHandler(), FileSystem::MountFileSystem, mountHandler(), pathHandler(), FileSystem::ReadFile, setRoot(), FileSystem::StatFile, FileSystem::WaitFile, FileSystem::WaitFileSystem, and FileSystem::WriteFile.
|
virtual |
Destructor function.
Definition at line 51 of file FileSystemServer.cpp.
References clearFileCache(), m_requests, and m_root.
Cleans up the entire file cache (except opened file caches and root).
cache | Input 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().
|
virtual |
Create a new file.
type | Describes the type of file to create. |
Reimplemented in TmpFileSystem.
Definition at line 110 of file FileSystemServer.cpp.
References ZERO.
Referenced by processRequest().
|
protected |
Search the cache for an entry.
path | Full path of the file to find. |
Definition at line 758 of file FileSystemServer.cpp.
Referenced by findFileCache(), getParentDirectory(), insertFileCache(), processRequest(), and unregisterFile().
|
protected |
Search the cache for an entry.
path | Full path of the file to find. |
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.
Search the cache for an entry.
path | Full path of the file to find. |
Definition at line 764 of file FileSystemServer.cpp.
References findFileCache().
void FileSystemServer::getFileSystemsHandler | ( | FileSystemMessage * | msg | ) |
Read the file system mounts table.
msg | FileSystemMessage pointer |
Definition at line 612 of file FileSystemServer.cpp.
References FileSystemMessage::buffer, ERROR, ChannelMessage::from, FileSystem::IOError, m_mounts, MaximumFileSystemMounts, FileSystemMessage::result, FileSystemMessage::size, FileSystem::Success, API::Success, VMCopy(), and API::Write.
Referenced by FileSystemServer().
const char * FileSystemServer::getMountPath | ( | ) | const |
Get mount path.
Definition at line 61 of file FileSystemServer.cpp.
References m_mountPath.
Referenced by UDP::createSocket(), and ICMP::createSocket().
u32 FileSystemServer::getNextInode | ( | ) |
Get next unused inode.
Definition at line 66 of file FileSystemServer.cpp.
References HashTable< K, V >::get(), m_inodeMap, and ZERO.
Referenced by TmpFileSystem::createFile(), UDP::createSocket(), ICMP::createSocket(), DeviceServer::initialize(), UDP::initialize(), ICMP::initialize(), Ethernet::initialize(), IPV4::initialize(), ARP::initialize(), and main().
|
protected |
Retrieve parent Directory for a file.
path | Path to the file |
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().
|
protected |
Handle a request for a File specified by its inode.
req | FileSystemRequest reference |
Definition at line 246 of file FileSystemServer.cpp.
References FileSystemMessage::action, IOBuffer::bufferedRead(), DEBUG, IOBuffer::flushWrite(), HashTable< K, V >::get(), FileSystemRequest::getBuffer(), IOBuffer::getCount(), FileSystemRequest::getMessage(), FileSystemMessage::inode, m_inodeMap, ChannelServer< FileSystemServer, FileSystemMessage >::m_self, FileSystem::NotFound, FileSystem::NotSupported, FileSystemMessage::offset, File::read(), FileSystem::ReadFile, FileSystemMessage::result, FileSystem::RetryAgain, sendResponse(), FileSystemMessage::size, FileSystem::Success, File::write(), FileSystem::WriteFile, and ZERO.
Referenced by processRequest().
Inserts a file into the in-memory filesystem tree.
file | File to insert. |
pathFormat | Full path to the file to insert. |
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().
|
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.
path | A path to lookup from storage. |
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().
FileSystem::Result FileSystemServer::mount | ( | ) |
Mount the FileSystem.
This function is responsible for mounting the file system.
Definition at line 77 of file FileSystemServer.cpp.
References assert, FileSystem::IOError, m_mountPath, m_mounts, m_pid, MaximumFileSystemMounts, FileSystemClient::mountFileSystem(), NULL, DatastoreClient::registerBuffer(), ROOTFS_PID, MemoryBlock::set(), Datastore::Success, FileSystem::Success, and ZERO.
Referenced by DeviceServer::initialize(), and main().
void FileSystemServer::mountHandler | ( | FileSystemMessage * | msg | ) |
Process a filesystem mount request message.
msg | FileSystemMessage pointer with the requested mount path |
Definition at line 561 of file FileSystemServer.cpp.
References FileSystemMessage::buffer, MemoryBlock::copy(), entry, ERROR, ChannelMessage::from, FileSystem::IOError, m_mounts, MaximumFileSystemMounts, FileSystemPath::MaximumLength, NOTICE, FileSystemMount::options, FileSystemMount::procID, API::Read, FileSystemMessage::result, FileSystem::Success, API::Success, VMCopy(), and ZERO.
Referenced by FileSystemServer().
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.
msg | Incoming request message. |
Definition at line 194 of file FileSystemServer.cpp.
References List< T >::append(), assert, m_requests, NULL, processRequest(), and FileSystem::RetryAgain.
Referenced by FileSystemServer().
|
protected |
Definition at line 383 of file FileSystemServer.cpp.
References FileSystemMessage::action, FileSystem::AlreadyExists, FileSystemMessage::buffer, FileSystem::CreateFile, createFile(), DEBUG, FileSystem::DeleteFile, ERROR, FileCache::file, findFileCache(), ChannelMessage::from, FileSystemPath::full(), FileSystemRequest::getMessage(), inodeHandler(), FileSystem::IOError, String::length(), lookupFile(), m_mountPath, m_pid, ChannelServer< FileSystemServer, FileSystemMessage >::m_self, FileSystemPath::MaximumLength, FileSystem::NotFound, FileSystem::NotSupported, FileSystemMessage::pid, FileSystem::FileStat::pid, API::Read, FileSystem::ReadFile, redirectRequest(), registerFile(), FileSystemMessage::result, FileSystem::RetryAgain, ROOTFS_PID, sendResponse(), FileSystemMessage::stat, FileSystem::StatFile, File::status(), FileSystem::Success, API::Success, unregisterFile(), VMCopy(), FileSystem::WaitFile, waitFileHandler(), FileSystem::WaitFileSystem, API::Write, FileSystem::WriteFile, and ZERO.
Referenced by pathHandler(), and retryRequests().
|
protected |
Try to forward the given FileSystemMessage to a mount file system.
path | Path to access in the request |
msg | FileSystemMessage pointer |
Definition at line 208 of file FileSystemServer.cpp.
References FileSystemMessage::action, String::compareTo(), String::length(), m_mounts, MaximumFileSystemMounts, FileSystemMessage::pathMountLength, FileSystemMessage::pid, FileSystemMount::procID, FileSystem::RedirectRequest, ChannelMessage::Response, FileSystemMessage::result, sendResponse(), FileSystem::Success, ChannelMessage::type, FileSystem::WaitFileSystem, and ZERO.
Referenced by processRequest().
FileSystem::Result FileSystemServer::registerDirectory | ( | Directory * | dir, |
const char * | path | ||
) |
Register a new Directory.
dir | Directory object pointer |
path | Path to the directory |
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().
FileSystem::Result FileSystemServer::registerFile | ( | File * | file, |
const char * | path | ||
) |
Register a new File.
Definition at line 115 of file FileSystemServer.cpp.
References FileSystemPath::base(), getParentDirectory(), File::getType(), Directory::insert(), insertFileCache(), FileSystem::IOError, FileSystem::NotFound, FileSystem::Success, and ZERO.
Referenced by UDP::createSocket(), ICMP::createSocket(), DeviceServer::initialize(), UDP::initialize(), ICMP::initialize(), Ethernet::initialize(), IPV4::initialize(), ARP::initialize(), processRequest(), DeviceServer::registerDevice(), and registerDirectory().
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().
|
virtual |
Retry any pending requests.
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().
|
protected |
Send response for a FileSystemMessage.
msg | The FileSystemMessage to send response for |
Definition at line 536 of file FileSystemServer.cpp.
References FileSystemMessage::action, DEBUG, ERROR, ChannelMessage::from, ChannelRegistry::getProducer(), ChannelServer< FileSystemServer, FileSystemMessage >::m_registry, ChannelServer< FileSystemServer, FileSystemMessage >::m_self, ProcessCtl(), ChannelMessage::Response, FileSystemMessage::result, Channel::Success, ChannelMessage::type, Wakeup, Channel::write(), and ZERO.
Referenced by inodeHandler(), LinnFileSystem::notSupportedHandler(), processRequest(), redirectRequest(), and waitFileHandler().
|
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.
newRoot | A Directory pointer to set as the new root. |
Definition at line 649 of file FileSystemServer.cpp.
References insertFileCache(), m_root, and ZERO.
Referenced by FileSystemServer(), and LinnFileSystem::LinnFileSystem().
FileSystem::Result FileSystemServer::unregisterFile | ( | const char * | path | ) |
Remove a File from the FileSystemServer.
path | Path to the file to remove |
Definition at line 175 of file FileSystemServer.cpp.
References clearFileCache(), HashTable< K, V >::count(), DEBUG, FileCache::entries, findFileCache(), FileSystem::NotFound, FileSystem::PermissionDenied, and FileSystem::Success.
Referenced by processRequest(), UDP::unregisterSockets(), and ICMP::unregisterSockets().
|
protected |
Handle a WaitFile request.
req | FileSystemRequest reference |
Definition at line 301 of file FileSystemServer.cpp.
References FileSystem::WaitSet::current, DEBUG, ERROR, Timer::Info::frequency, ChannelMessage::from, HashTable< K, V >::get(), FileSystemRequest::getBuffer(), FileSystemRequest::getMessage(), Timer::isExpired(), ChannelServer< FileSystemServer, FileSystemMessage >::m_expiry, m_inodeMap, MaximumWaitSetCount, IOBuffer::read(), FileSystem::Readable, FileSystemMessage::result, FileSystem::RetryAgain, sendResponse(), FileSystemMessage::size, FileSystem::Success, KernelTimer::tick(), Timer::Info::ticks, FileSystem::TimedOut, FileSystemMessage::timeout, FileSystem::Writable, IOBuffer::write(), and ZERO.
Referenced by processRequest().
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().
|
protected |
Mount point path.
Definition at line 311 of file FileSystemServer.h.
Referenced by getMountPath(), DeviceServer::initialize(), mount(), and processRequest().
|
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().
|
protected |
Process identifier.
Definition at line 302 of file FileSystemServer.h.
Referenced by mount(), and processRequest().
|
protected |
Contains ongoing requests.
Definition at line 317 of file FileSystemServer.h.
Referenced by pathHandler(), retryRequests(), and ~FileSystemServer().
|
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().
|
staticprivate |
Maximum number of supported file system mount entries.
Definition at line 49 of file FileSystemServer.h.
Referenced by getFileSystemsHandler(), mount(), mountHandler(), and redirectRequest().
|
staticprivate |
Maximum number of WaitSet entries supported.
Definition at line 52 of file FileSystemServer.h.
Referenced by waitFileHandler().