FreeNOS
|
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 String * | getCurrentDirectory () 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... | |
FileSystemMount * | getFileSystems (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 String * | m_currentDirectory = (String *) NULL |
Current directory path is prefixed to relative path inputs. More... | |
FileSystemClient provides a simple interface to a FileSystemServer.
Definition at line 42 of file FileSystemClient.h.
Class constructor function.
pid | Optional 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.
FileSystem::Result FileSystemClient::closeFile | ( | const Size | descriptor | ) | const |
Close a file.
descriptor | File descriptor number |
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().
FileSystem::Result FileSystemClient::createFile | ( | const char * | path, |
const FileSystem::FileType | type, | ||
const FileSystem::FileModes | mode | ||
) | const |
Create a new file.
path | Path to the file |
type | File type of the new file |
mode | Initial access permissions |
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.
FileSystem::Result FileSystemClient::deleteFile | ( | const char * | path | ) | const |
Remove a file from the file system.
path | Path to the file |
Definition at line 286 of file FileSystemClient.cpp.
References FileSystemMessage::action, FileSystemMessage::buffer, FileSystem::DeleteFile, ChannelMessage::Request, request(), and ChannelMessage::type.
Referenced by unlink().
|
private |
Retrieve the ProcessID of the FileSystemMount for the given path.
path | Path to lookup. |
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().
const String * FileSystemClient::getCurrentDirectory | ( | ) | const |
Get current directory String.
Definition at line 146 of file FileSystemClient.cpp.
References m_currentDirectory.
FileSystemMount * FileSystemClient::getFileSystems | ( | Size & | numberOfMounts | ) | const |
Get file system mounts table.
numberOfMounts | Number of entries in the returned array |
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().
FileSystem::Result FileSystemClient::mountFileSystem | ( | const char * | mountPath | ) | const |
Mount the current process as a file system on the rootfs.
mountPath | Absolute path for the mount point to use. |
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().
FileSystem::Result FileSystemClient::openFile | ( | const char * | path, |
Size & | descriptor | ||
) | const |
Open a file.
path | Path to the file |
descriptor | Outputs the file descriptor number |
Definition at line 198 of file FileSystemClient.cpp.
References FileSystem::FileStat::inode, StrictSingleton< FileDescriptor >::instance(), FileSystem::IOError, FileDescriptor::openEntry(), FileSystem::FileStat::pid, statFile(), FileSystem::Success, and FileDescriptor::Success.
Referenced by NetworkClient::createSocket(), FileStorage::initialize(), open(), and RecoveryServer::reloadProgram().
FileSystem::Result FileSystemClient::readFile | ( | const Size | descriptor, |
void * | buf, | ||
Size * | size | ||
) | const |
Read a file.
descriptor | File descriptor number of the file |
buf | Buffer for storing bytes read. |
size | On input, number of bytes to read. On output, actual bytes read. |
Definition at line 229 of file FileSystemClient.cpp.
References FileSystemMessage::action, FileSystemMessage::buffer, FileDescriptor::getEntry(), FileSystemMessage::inode, FileDescriptor::Entry::inode, StrictSingleton< FileDescriptor >::instance(), FileSystem::NotFound, FileSystemMessage::offset, FileDescriptor::Entry::open, FileDescriptor::Entry::pid, FileDescriptor::Entry::position, FileSystem::ReadFile, ChannelMessage::Request, request(), FileSystemMessage::size, FileSystem::Success, and ChannelMessage::type.
Referenced by FileStorage::read(), read(), RecoveryServer::reloadProgram(), and NetworkClient::writeSocketInfo().
|
inlineprivate |
Send an IPC request to the target file system.
path | Path to the file, can be relative or absolute. |
msg | Reference to the FileSystemMessage to send |
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().
|
inlineprivate |
Send an IPC request to the target file system.
pid | Process identifier of the target file system. |
msg | Reference to the FileSystemMessage to send |
Definition at line 58 of file FileSystemClient.cpp.
References FileSystemMessage::action, assert, FileSystemMessage::buffer, MemoryBlock::copy(), ERROR, StrictSingleton< ChannelClient >::instance(), FileSystem::IpcError, m_mounts, MaximumFileSystemMounts, FileSystemMount::options, FileSystemMount::path, FileSystemMessage::pathMountLength, FileSystemMessage::pid, FileSystemMount::procID, FileSystem::ReadFile, FileSystem::RedirectRequest, ChannelMessage::Request, FileSystemMessage::result, ROOTFS_PID, ChannelClient::Success, ChannelClient::syncSendReceive(), ChannelMessage::type, FileSystem::WriteFile, and ZERO.
void FileSystemClient::setCurrentDirectory | ( | const String & | directory | ) |
Set new current directory.
directory | String 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().
void FileSystemClient::setCurrentDirectory | ( | String * | directory | ) |
Set new current directory.
directory | String to use as current directory. |
Definition at line 157 of file FileSystemClient.cpp.
References m_currentDirectory, and NULL.
FileSystem::Result FileSystemClient::statFile | ( | const char * | path, |
FileSystem::FileStat * | st | ||
) | const |
Retrieve status of a file.
path | Path to the file |
st | Output buffer for the file status |
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().
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.
filesystemPath | Path to the destination mounted filesystem |
waitSet | Pointer to a WaitSet array |
count | Number of WaitSet entries |
msecTimeout | Timeout in milliseconds of the wait or ZERO for infinite wait |
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().
FileSystem::Result FileSystemClient::waitFileSystem | ( | const char * | path | ) | const |
Blocking wait for a mounted filesystem.
path | Full path of the mounted filesystem |
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().
FileSystem::Result FileSystemClient::writeFile | ( | const Size | descriptor, |
const void * | buf, | ||
Size * | size | ||
) | const |
Write a file.
descriptor | File descriptor number of the file |
buf | Input buffer for bytes to write. |
size | On input, number of bytes to write. On output, actual bytes written. |
Definition at line 257 of file FileSystemClient.cpp.
References FileSystemMessage::action, FileSystemMessage::buffer, FileDescriptor::getEntry(), FileSystemMessage::inode, FileDescriptor::Entry::inode, StrictSingleton< FileDescriptor >::instance(), FileSystem::NotFound, FileSystemMessage::offset, FileDescriptor::Entry::open, FileDescriptor::Entry::pid, FileDescriptor::Entry::position, ChannelMessage::Request, request(), FileSystemMessage::size, FileSystem::Success, ChannelMessage::type, and FileSystem::WriteFile.
Referenced by FileStorage::write(), write(), and NetworkClient::writeSocketInfo().
Current directory path is prefixed to relative path inputs.
Definition at line 243 of file FileSystemClient.h.
Referenced by findMount(), getCurrentDirectory(), request(), and setCurrentDirectory().
|
staticprivate |
FileSystem mounts table.
Definition at line 240 of file FileSystemClient.h.
Referenced by findMount(), getFileSystems(), and request().
|
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().
|
staticprivate |
Maximum number of mounted filesystems.
Definition at line 47 of file FileSystemClient.h.
Referenced by findMount(), getFileSystems(), and request().