FreeNOS
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
FileSystemClient Class Reference

FileSystemClient provides a simple interface to a FileSystemServer. More...

#include <FileSystemClient.h>

Public Member Functions

 FileSystemClient (const ProcessID pid=ANY)
 Class constructor function. More...
 
const StringgetCurrentDirectory () const
 Get current directory String. More...
 
void setCurrentDirectory (const String &directory)
 Set new current directory. More...
 
void setCurrentDirectory (String *directory)
 Set new current directory. More...
 
FileSystem::Result createFile (const char *path, const FileSystem::FileType type, const FileSystem::FileModes mode) const
 Create a new file. More...
 
FileSystem::Result statFile (const char *path, FileSystem::FileStat *st) const
 Retrieve status of a file. More...
 
FileSystem::Result openFile (const char *path, Size &descriptor) const
 Open a file. More...
 
FileSystem::Result closeFile (const Size descriptor) const
 Close a file. More...
 
FileSystem::Result readFile (const Size descriptor, void *buf, Size *size) const
 Read a file. More...
 
FileSystem::Result writeFile (const Size descriptor, const void *buf, Size *size) const
 Write a file. More...
 
FileSystem::Result deleteFile (const char *path) const
 Remove a file from the file system. More...
 
FileSystem::Result waitFile (const char *filesystemPath, const FileSystem::WaitSet *waitSet, const Size count, const Size msecTimeout) const
 Wait for one or more files to become readable/writable. More...
 
FileSystem::Result mountFileSystem (const char *mountPath) const
 Mount the current process as a file system on the rootfs. More...
 
FileSystem::Result waitFileSystem (const char *path) const
 Blocking wait for a mounted filesystem. More...
 
FileSystemMountgetFileSystems (Size &numberOfMounts) const
 Get file system mounts table. More...
 

Private Member Functions

FileSystem::Result request (const char *path, FileSystemMessage &msg) const
 Send an IPC request to the target file system. More...
 
FileSystem::Result request (const ProcessID pid, FileSystemMessage &msg) const
 Send an IPC request to the target file system. More...
 
ProcessID findMount (const char *path) const
 Retrieve the ProcessID of the FileSystemMount for the given path. More...
 

Private Attributes

const ProcessID m_pid
 ProcessID of the target file system or ANY to lookup in mounts table. More...
 

Static Private Attributes

static const Size MaximumFileSystemMounts = 16
 Maximum number of mounted filesystems. More...
 
static FileSystemMount m_mounts [MaximumFileSystemMounts] = {}
 FileSystem mounts table. More...
 
static Stringm_currentDirectory = (String *) NULL
 Current directory path is prefixed to relative path inputs. More...
 

Detailed Description

FileSystemClient provides a simple interface to a FileSystemServer.

See also
FileSystemServer

Definition at line 42 of file FileSystemClient.h.

Constructor & Destructor Documentation

◆ FileSystemClient()

FileSystemClient::FileSystemClient ( const ProcessID  pid = ANY)

Class constructor function.

Parameters
pidOptional ProcessID of the target file system. If set to ANY the cached mounts table will be used to lookup the ProcessID.

Definition at line 29 of file FileSystemClient.cpp.

Member Function Documentation

◆ closeFile()

FileSystem::Result FileSystemClient::closeFile ( const Size  descriptor) const

Close a file.

Parameters
descriptorFile descriptor number
Returns
Result code

Definition at line 218 of file FileSystemClient.cpp.

References FileDescriptor::closeEntry(), StrictSingleton< FileDescriptor >::instance(), FileSystem::IOError, FileSystem::Success, and FileDescriptor::Success.

Referenced by close(), NetworkClient::close(), and RecoveryServer::reloadProgram().

◆ createFile()

FileSystem::Result FileSystemClient::createFile ( const char *  path,
const FileSystem::FileType  type,
const FileSystem::FileModes  mode 
) const

Create a new file.

Parameters
pathPath to the file
typeFile type of the new file
modeInitial access permissions
Returns
Result code

Definition at line 169 of file FileSystemClient.cpp.

References FileSystem::FileStat::access, FileSystemMessage::action, FileSystemMessage::buffer, FileSystem::CreateFile, ChannelMessage::Request, request(), FileSystemMessage::stat, ChannelMessage::type, type, and FileSystem::FileStat::type.

Referenced by creat(), mkdir(), and mknod().

◆ deleteFile()

FileSystem::Result FileSystemClient::deleteFile ( const char *  path) const

Remove a file from the file system.

Parameters
pathPath to the file
Returns
Result code

Definition at line 286 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, FileSystem::DeleteFile, ChannelMessage::Request, request(), and ChannelMessage::type.

Referenced by unlink().

◆ findMount()

ProcessID FileSystemClient::findMount ( const char *  path) const
private

Retrieve the ProcessID of the FileSystemMount for the given path.

Parameters
pathPath to lookup.
Returns
ProcessID of the FileSystemMount on success and ZERO otherwise.

Definition at line 105 of file FileSystemClient.cpp.

References String::compareTo(), MemoryBlock::copy(), length, String::length(), m_currentDirectory, m_mounts, MaximumFileSystemMounts, FileSystemPath::MaximumLength, NULL, FileSystemMount::procID, ROOTFS_PID, and ZERO.

Referenced by request(), and waitFile().

◆ getCurrentDirectory()

const String * FileSystemClient::getCurrentDirectory ( ) const

Get current directory String.

Returns
String pointer containing current directory

Definition at line 146 of file FileSystemClient.cpp.

References m_currentDirectory.

Referenced by getcwd(), and spawn().

◆ getFileSystems()

FileSystemMount * FileSystemClient::getFileSystems ( Size numberOfMounts) const

Get file system mounts table.

Parameters
numberOfMountsNumber of entries in the returned array
Returns
FileSystemMount array pointer or NULL on failure

Definition at line 344 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, FileSystem::GetFileSystems, m_mounts, MaximumFileSystemMounts, NULL, ChannelMessage::Request, request(), ROOTFS_PID, FileSystemMessage::size, FileSystem::Success, and ChannelMessage::type.

Referenced by NetCtl::exec(), NetworkClient::initialize(), and Mount::listMounts().

◆ mountFileSystem()

FileSystem::Result FileSystemClient::mountFileSystem ( const char *  mountPath) const

Mount the current process as a file system on the rootfs.

Parameters
mountPathAbsolute path for the mount point to use.
Returns
Result code

Definition at line 324 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, FileSystem::MountFileSystem, ChannelMessage::Request, request(), ROOTFS_PID, and ChannelMessage::type.

Referenced by FileSystemServer::mount().

◆ openFile()

FileSystem::Result FileSystemClient::openFile ( const char *  path,
Size descriptor 
) const

◆ readFile()

FileSystem::Result FileSystemClient::readFile ( const Size  descriptor,
void *  buf,
Size size 
) const

◆ request() [1/2]

FileSystem::Result FileSystemClient::request ( const char *  path,
FileSystemMessage msg 
) const
inlineprivate

Send an IPC request to the target file system.

Parameters
pathPath to the file, can be relative or absolute.
msgReference to the FileSystemMessage to send
Returns
Result code

Definition at line 34 of file FileSystemClient.cpp.

References ANY, FileSystemMessage::buffer, MemoryBlock::copy(), findMount(), m_currentDirectory, m_pid, FileSystemPath::MaximumLength, and NULL.

Referenced by createFile(), deleteFile(), getFileSystems(), mountFileSystem(), readFile(), statFile(), waitFile(), waitFileSystem(), and writeFile().

◆ request() [2/2]

FileSystem::Result FileSystemClient::request ( const ProcessID  pid,
FileSystemMessage msg 
) const
inlineprivate

◆ setCurrentDirectory() [1/2]

void FileSystemClient::setCurrentDirectory ( const String directory)

Set new current directory.

Parameters
directoryString reference to use as current directory.

Definition at line 151 of file FileSystemClient.cpp.

References assert, m_currentDirectory, and NULL.

Referenced by chdir(), and setupMappings().

◆ setCurrentDirectory() [2/2]

void FileSystemClient::setCurrentDirectory ( String directory)

Set new current directory.

Parameters
directoryString to use as current directory.
Note
If the current directory was already set before, the internal String object will be overwritten using the value given by the String input.

Definition at line 157 of file FileSystemClient.cpp.

References m_currentDirectory, and NULL.

◆ statFile()

FileSystem::Result FileSystemClient::statFile ( const char *  path,
FileSystem::FileStat st 
) const

Retrieve status of a file.

Parameters
pathPath to the file
stOutput buffer for the file status
Returns
Result code

Definition at line 186 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, ChannelMessage::Request, request(), FileSystemMessage::stat, FileSystem::StatFile, and ChannelMessage::type.

Referenced by FileStorage::initialize(), openFile(), RecoveryServer::reloadProgram(), stat(), and NetworkClient::writeSocketInfo().

◆ waitFile()

FileSystem::Result FileSystemClient::waitFile ( const char *  filesystemPath,
const FileSystem::WaitSet waitSet,
const Size  count,
const Size  msecTimeout 
) const

Wait for one or more files to become readable/writable.

Parameters
filesystemPathPath to the destination mounted filesystem
waitSetPointer to a WaitSet array
countNumber of WaitSet entries
msecTimeoutTimeout in milliseconds of the wait or ZERO for infinite wait
Returns
Result code

Definition at line 296 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, findMount(), Timer::Info::frequency, Timer::getCurrent(), ChannelMessage::Request, request(), FileSystemMessage::size, KernelTimer::tick(), Timer::Info::ticks, FileSystemMessage::timeout, ChannelMessage::type, and FileSystem::WaitFile.

Referenced by NetworkClient::waitSocket().

◆ waitFileSystem()

FileSystem::Result FileSystemClient::waitFileSystem ( const char *  path) const

Blocking wait for a mounted filesystem.

Parameters
pathFull path of the mounted filesystem
Returns
Result code
Note
Blocks until a filesystem is mounted on the exact given input path

Definition at line 334 of file FileSystemClient.cpp.

References FileSystemMessage::action, FileSystemMessage::buffer, ChannelMessage::Request, request(), ROOTFS_PID, ChannelMessage::type, and FileSystem::WaitFileSystem.

Referenced by main(), and Mount::waitForMount().

◆ writeFile()

FileSystem::Result FileSystemClient::writeFile ( const Size  descriptor,
const void *  buf,
Size size 
) const

Field Documentation

◆ m_currentDirectory

String * FileSystemClient::m_currentDirectory = (String *) NULL
staticprivate

Current directory path is prefixed to relative path inputs.

Definition at line 243 of file FileSystemClient.h.

Referenced by findMount(), getCurrentDirectory(), request(), and setCurrentDirectory().

◆ m_mounts

FileSystemMount FileSystemClient::m_mounts = {}
staticprivate

FileSystem mounts table.

Definition at line 240 of file FileSystemClient.h.

Referenced by findMount(), getFileSystems(), and request().

◆ m_pid

const ProcessID FileSystemClient::m_pid
private

ProcessID of the target file system or ANY to lookup in mounts table.

Definition at line 246 of file FileSystemClient.h.

Referenced by request().

◆ MaximumFileSystemMounts

const Size FileSystemClient::MaximumFileSystemMounts = 16
staticprivate

Maximum number of mounted filesystems.

Definition at line 47 of file FileSystemClient.h.

Referenced by findMount(), getFileSystems(), and request().


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