The Pedigree Project
0.1
|
#include <VFS.h>
Public Types | |
typedef void(* | MountCallback) () |
typedef HashTable< String, Filesystem *, HashedStringView > | AliasTable |
Public Member Functions | |
VFS () | |
~VFS () | |
bool | mount (Disk *pDisk, String &alias) |
void | addAlias (Filesystem *pFs, const String &alias) |
void | addAlias (const String &oldAlias, const String &newAlias) |
String | getUniqueAlias (const String &alias) |
bool | aliasExists (const String &alias) |
AliasTable & | getAliases () |
Tree< Filesystem *, List< String * > * > & | getMounts () |
void | removeAlias (const String &alias) |
void | removeAllAliases (Filesystem *pFs, bool canDelete=true) |
Filesystem * | lookupFilesystem (const String &alias) |
Filesystem * | lookupFilesystem (const HashedStringView &alias) |
File * | find (const String &path, File *pStartNode=0) |
bool | createFile (const String &path, uint32_t mask, File *pStartNode=0) |
bool | createDirectory (const String &path, uint32_t mask, File *pStartNode=0) |
bool | createSymlink (const String &path, const String &value, File *pStartNode=0) |
bool | createLink (const String &path, File *target, File *pStartNode=0) |
bool | remove (const String &path, File *pStartNode=0) |
void | addProbeCallback (Filesystem::ProbeCallback callback) |
void | addMountCallback (MountCallback callback) |
Static Public Member Functions | |
static VFS & | instance () |
static bool | checkAccess (File *pFile, bool bRead, bool bWrite, bool bExecute) |
static constexpr const char * | mountSeparator () |
Private Member Functions | |
ssize_t | findColon (const String &path) |
Private Attributes | |
AliasTable | m_Aliases |
Tree< Filesystem *, List< String * > * > | m_Mounts |
List< Filesystem::ProbeCallback * > | m_ProbeCallbacks |
List< MountCallback * > | m_MountCallbacks |
LruCache< String, Filesystem * > | m_AliasCache |
LruCache< String, File * > | m_FindCache |
Static Private Attributes | |
static VFS | m_Instance |
static File * | m_EmptyFile |
This class implements a virtual file system.
The pedigree VFS is structured in a similar way to windows' - every filesystem is identified by a unique name and accessed thus:
myfs:/mydir/myfile
No UNIX-style mounting of filesystems inside filesystems is possible. A filesystem may be referred to by multiple names - a reference count is maintained by the filesystem - when no aliases point to it, it is unmounted totally.
The 'root' filesystem - that is the FS with system data on, is visible by the alias 'root', thus; 'root:/System/Boot/kernel' could be used to access the kernel image.
typedef HashTable<String, Filesystem *, HashedStringView> VFS::AliasTable |
typedef void(* VFS::MountCallback) () |
VFS::~VFS | ( | ) |
Destructor
Definition at line 65 of file VFS.cc.
References List< T, nodePoolSize >::begin(), Tree< K, E >::begin(), List< T, nodePoolSize >::end(), and Tree< K, E >::end().
void VFS::addAlias | ( | Filesystem * | pFs, |
const String & | alias | ||
) |
Adds an alias to an existing filesystem.
pFs | The filesystem to add an alias for. |
pAlias | The alias to add. |
Definition at line 123 of file VFS.cc.
References Tree< K, E >::insert(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::insert(), Tree< K, E >::lookup(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), and Filesystem::m_nAliases.
Referenced by RawFs::getRoot(), and mount().
void VFS::addMountCallback | ( | MountCallback | callback | ) |
Adds a mount callback - the function is called when a disk is mounted or unmounted.
Definition at line 305 of file VFS.cc.
References List< T, nodePoolSize >::pushBack().
Referenced by RawFs::getRoot().
void VFS::addProbeCallback | ( | Filesystem::ProbeCallback | callback | ) |
Adds a filesystem probe callback - this is called when a device is mounted.
Definition at line 298 of file VFS.cc.
References List< T, nodePoolSize >::pushBack().
Referenced by Ext2Filesystem::releaseInode(), Iso9660Filesystem::remove(), and FatFilesystem::remove().
bool VFS::aliasExists | ( | const String & | alias | ) |
Does a given alias exist?
Definition at line 174 of file VFS.cc.
References HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::contains().
Referenced by getUniqueAlias().
|
static |
Checks if the current user can access the given file.
Definition at line 448 of file VFS.cc.
References Process::getUserId(), Processor::information(), NOTICE, and Oct.
Referenced by Filesystem::createDirectory(), Filesystem::createFile(), Filesystem::createLink(), Filesystem::createSymlink(), Filesystem::findNode(), PosixSubsystem::invoke(), Filesystem::remove(), and PosixSubsystem::threadRemoved().
Attempts to create a directory.
Definition at line 338 of file VFS.cc.
References Filesystem::createDirectory(), and lookupFilesystem().
Referenced by Filesystem::isCaseSensitive().
Attempts to create a file.
Definition at line 312 of file VFS.cc.
References Filesystem::createFile(), and lookupFilesystem().
Referenced by Filesystem::isCaseSensitive().
Attempts to create a hard link.
Definition at line 397 of file VFS.cc.
References Filesystem::createLink(), and lookupFilesystem().
Referenced by Filesystem::isCaseSensitive().
Attempts to create a symlink.
Definition at line 370 of file VFS.cc.
References Filesystem::createSymlink(), and lookupFilesystem().
Referenced by Filesystem::isCaseSensitive().
Attempts to obtain a File for a specific path.
Definition at line 243 of file VFS.cc.
References Filesystem::find(), LruCache< K, T, Slots >::get(), lookupFilesystem(), LruCache< K, T, Slots >::store(), and String::view().
Referenced by UnixSocketSyscalls::bind(), UnixSocketSyscalls::connect(), PosixSubsystem::findFile(), ProcFs::initialise(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), and UnixSocketSyscalls::sendto_msg().
|
inline |
|
inline |
Gets a unique alias for a filesystem.
Definition at line 153 of file VFS.cc.
References aliasExists().
Referenced by mount().
|
static |
Returns the singleton VFS instance.
Definition at line 56 of file VFS.cc.
References m_Instance.
Referenced by UnixSocketSyscalls::bind(), UnixSocketSyscalls::connect(), PosixSubsystem::findFile(), RawFs::getRoot(), PosixProcess::getType(), ProcFs::initialise(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), Ext2Filesystem::releaseInode(), Iso9660Filesystem::remove(), FatFilesystem::remove(), and UnixSocketSyscalls::sendto_msg().
Filesystem * VFS::lookupFilesystem | ( | const String & | alias | ) |
Looks up the Filesystem from a given alias.
pAlias | The alias to search for. |
Definition at line 221 of file VFS.cc.
References LruCache< K, T, Slots >::get(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), LruCache< K, T, Slots >::store(), and String::view().
Referenced by createDirectory(), createFile(), createLink(), createSymlink(), find(), PosixSubsystem::findFile(), PosixProcess::getType(), and remove().
Mounts a Disk device as the alias "alias". If alias is zero-length, the Filesystem is asked for its preferred name (usually a volume name of some sort), and returned in "alias"
Definition at line 88 of file VFS.cc.
References addAlias(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), getUniqueAlias(), Filesystem::getVolumeLabel(), Tree< K, E >::insert(), and Tree< K, E >::lookup().
|
inlinestatic |
Attempts to remove a file/directory/symlink. WILL FAIL IF DIRECTORY NOT EMPTY
Definition at line 423 of file VFS.cc.
References lookupFilesystem(), and Filesystem::remove().
void VFS::removeAlias | ( | const String & | alias | ) |
Removes an alias from a filesystem. If no aliases remain for that filesystem, the filesystem is destroyed.
pAlias | The alias to remove. |
Definition at line 179 of file VFS.cc.
References HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::remove().
void VFS::removeAllAliases | ( | Filesystem * | pFs, |
bool | canDelete = true |
||
) |
Removes all aliases from a filesystem - the filesystem is destroyed.
pFs | The filesystem to destroy. |
Definition at line 185 of file VFS.cc.
References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::erase(), Tree< K, E >::lookup(), and Tree< K, E >::remove().
|
staticprivate |
|
staticprivate |
The static instance object.
Definition at line 161 of file VFS.h.
Referenced by instance().