The Pedigree Project  0.1
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
VFS Class Reference

#include <VFS.h>

+ Collaboration diagram for VFS:

Public Types

typedef void(* MountCallback) ()
 
typedef HashTable< String, Filesystem *, HashedStringViewAliasTable
 

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)
 
AliasTablegetAliases ()
 
Tree< Filesystem *, List< String * > * > & getMounts ()
 
void removeAlias (const String &alias)
 
void removeAllAliases (Filesystem *pFs, bool canDelete=true)
 
FilesystemlookupFilesystem (const String &alias)
 
FilesystemlookupFilesystem (const HashedStringView &alias)
 
Filefind (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 VFSinstance ()
 
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 Filem_EmptyFile
 

Detailed Description

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.

Definition at line 57 of file VFS.h.

Member Typedef Documentation

Type of the alias lookup table.

Definition at line 64 of file VFS.h.

typedef void(* VFS::MountCallback) ()

Callback type, called when a disk is mounted or unmounted.

Definition at line 61 of file VFS.h.

Constructor & Destructor Documentation

VFS::VFS ( )

Constructor

Definition at line 61 of file VFS.cc.

VFS::~VFS ( )

Member Function Documentation

void VFS::addAlias ( Filesystem pFs,
const String alias 
)

Adds an alias to an existing filesystem.

Parameters
pFsThe filesystem to add an alias for.
pAliasThe 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().

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

bool VFS::checkAccess ( File pFile,
bool  bRead,
bool  bWrite,
bool  bExecute 
)
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().

+ Here is the caller graph for this function:

bool VFS::createDirectory ( const String path,
uint32_t  mask,
File pStartNode = 0 
)

Attempts to create a directory.

Definition at line 338 of file VFS.cc.

References Filesystem::createDirectory(), and lookupFilesystem().

Referenced by Filesystem::isCaseSensitive().

+ Here is the caller graph for this function:

bool VFS::createFile ( const String path,
uint32_t  mask,
File pStartNode = 0 
)

Attempts to create a file.

Definition at line 312 of file VFS.cc.

References Filesystem::createFile(), and lookupFilesystem().

Referenced by Filesystem::isCaseSensitive().

+ Here is the caller graph for this function:

bool VFS::createLink ( const String path,
File target,
File pStartNode = 0 
)

Attempts to create a hard link.

Definition at line 397 of file VFS.cc.

References Filesystem::createLink(), and lookupFilesystem().

Referenced by Filesystem::isCaseSensitive().

+ Here is the caller graph for this function:

bool VFS::createSymlink ( const String path,
const String value,
File pStartNode = 0 
)

Attempts to create a symlink.

Definition at line 370 of file VFS.cc.

References Filesystem::createSymlink(), and lookupFilesystem().

Referenced by Filesystem::isCaseSensitive().

+ Here is the caller graph for this function:

File * VFS::find ( const String path,
File pStartNode = 0 
)
AliasTable& VFS::getAliases ( )
inline

Obtains a list of all filesystem aliases

Definition at line 92 of file VFS.h.

Tree<Filesystem *, List<String *> *>& VFS::getMounts ( )
inline

Obtains a list of all mounted filesystems

Definition at line 98 of file VFS.h.

String VFS::getUniqueAlias ( const String alias)

Gets a unique alias for a filesystem.

Definition at line 153 of file VFS.cc.

References aliasExists().

Referenced by mount().

+ Here is the caller graph for this function:

VFS & VFS::instance ( )
static
Filesystem * VFS::lookupFilesystem ( const String alias)

Looks up the Filesystem from a given alias.

Parameters
pAliasThe alias to search for.
Returns
The filesystem aliased by pAlias or 0 if none found.

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().

+ Here is the caller graph for this function:

bool VFS::mount ( Disk pDisk,
String alias 
)

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().

static constexpr const char* VFS::mountSeparator ( )
inlinestatic

Separator between mount point and filesystem path.

Definition at line 152 of file VFS.h.

bool VFS::remove ( const String path,
File pStartNode = 0 
)

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.

Parameters
pAliasThe alias to remove.
Todo:
Remove from m_Mounts

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.

Parameters
pFsThe filesystem to destroy.
Todo:
Locking.

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().

Member Data Documentation

File* VFS::m_EmptyFile
staticprivate

A static File object representing an invalid file

Definition at line 164 of file VFS.h.

VFS VFS::m_Instance
staticprivate

The static instance object.

Todo:
Figure out a way to clean up files after deletion. Directory::remove() is not the right place to do this. There needs to be a way to add a File to some sort of queue that cleans it up once it hits refcount zero or something like that.

Definition at line 161 of file VFS.h.

Referenced by instance().


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