|
The Pedigree Project 0.1
|
#include <VFS.h>
Collaboration diagram for VFS:Classes | |
| struct | ActiveInvocation |
| struct | CallbackState |
| class | FilesystemPin |
| struct | MountCallbackItem |
| class | MountIdentity |
| struct | MountInfo |
| class | MountOperation |
| struct | MountSnapshot |
| class | NamespaceMutation |
| struct | ProbeCallbackItem |
| struct | TrackedFile |
Public Types | |
| typedef void(* | MountCallback) () |
Public Member Functions | |
| uint64_t | namespaceGeneration () const |
| VfsMountView * | mountView () const |
| VfsMountView * | bootMountView () const |
| bool | shutdownMountView (Vector< Filesystem * > &ownedBackings) |
| bool | initialiseMountView () |
| bool | acquireMount (Filesystem *key, MountOperation &operation) const |
| bool | pinFilesystem (Filesystem *key, FilesystemPin &pin) const |
| bool | diskMount (uint32_t id, MountIdentity &identity) const |
| bool | snapshotDiskMounts (Vector< MountIdentity > &mounts) const |
| VFS () | |
| ~VFS () | |
| bool | mount (Disk *pDisk, String &stableName, Filesystem **pMountedFs=nullptr) |
| String | registerFilesystem (Filesystem *pFs, const String &preferredStableName) |
| bool | unregisterFilesystem (Filesystem *pFs, bool canDelete=true, bool terminal=false) |
| bool | retireOwnedFilesystem (Filesystem *filesystem) |
| bool | removeDiskFilesystem (Filesystem *filesystem, bool deviceAvailable=false) |
| bool | setRootFilesystem (Filesystem *pFs) |
| Filesystem * | getRootFilesystem () const |
| bool | getMountPath (Filesystem *pFs, String &path) const |
| Filesystem * | getFilesystemAt (const String &path) const |
| void | getMounts (Vector< MountSnapshot > &mounts) const |
| Filesystem::SyncStatus | syncFilesystem (Filesystem *key) |
| Filesystem::SyncStatus | syncAll () |
| bool | removeEphemeralFiles () |
| File * | find (const String &path, File *pStartNode=0) |
| File * | findRetained (const String &path, Directory::ChildLease &result, File *pStartNode=nullptr) |
| 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) |
| bool | remove (const String &path, File *pStartNode, File *expected) |
| bool | rename (const String &oldPath, File *oldStart, const String &newPath, File *newStart, bool noReplace=false) |
| void | addProbeCallback (Filesystem::ProbeCallback callback) |
| bool | removeProbeCallback (Filesystem::ProbeCallback callback) |
| void | addMountCallback (MountCallback callback) |
| bool | removeMountCallback (MountCallback callback) |
| void | trackFile (File *pFile) |
| Track a File object that exists. It is necessary to keep track of File objects, or at least those that are stored in Directory caches and Filesystem objects, such that they can be correctly tidied up when no more usages exist. | |
| bool | tryTrackFile (File *pFile) |
| MUST_USE_RESULT bool | retainTrackedFile (File *pFile) |
| bool | untrackFile (File *pFile, bool destroy=true) |
Static Public Member Functions | |
| static Module::UnloadAdmission | unloadAdmission (bool terminal) |
| static VFS & | instance () |
| static bool | checkAccess (File *pFile, bool bRead, bool bWrite, bool bExecute) |
| static bool | checkAccess (File *file, bool read, bool write, bool execute, const FilesystemCredentials &credentials) |
| static bool | checkAccess (File *pFile, bool bRead, bool bWrite, bool bExecute, int64_t userId, int64_t groupId, const Vector< int64_t > &supplementalGroups) |
Private Types | |
| typedef Tree< Filesystem *, MountInfo * > | MountTable |
Private Attributes | |
| Mutex | m_PathMutationLock |
| uint64_t | m_PathGeneration |
| VfsMountView * | m_MountView |
| Mutex | m_MountMutationLock |
| Mutex | m_MountTableLock |
| Filesystem * | m_pRootFilesystem |
| MountTable | m_Mounts |
| List< ProbeCallbackItem * > | m_ProbeCallbacks |
| List< MountCallbackItem * > | m_MountCallbacks |
| Spinlock | m_CallbackLock |
| size_t | m_NextCallbackSequence |
| ActiveInvocation * | m_pActiveCallbacks |
| bool | m_CallbacksClosing |
| LruCache< String, File * > | m_FindCache |
| Mutex | m_TrackedFilesLock |
| RcuPointer< TrackedFile > | m_TrackedFiles [TrackedFileBuckets] |
Static Private Attributes | |
| static constexpr size_t | TrackedFileBuckets = 256 |
| static VFS | m_Instance |
| static File * | m_EmptyFile |
Set to zero to disable the builtin VFS LRU caches. This class implements a single-root virtual filesystem namespace.
| typedef void(* VFS::MountCallback) () |
|
private |
| VFS::~VFS | ( | ) |
Destructor
Definition at line 335 of file VFS.cc.
References Spinlock::acquire(), Tree< K, E >::begin(), Tree< K, E >::clear(), Tree< K, E >::end(), Vector< T >::pushBack(), and Spinlock::release().
| bool VFS::acquireMount | ( | Filesystem * | key, |
| MountOperation & | operation | ||
| ) | const |
Compares key without dereferencing it, then admits live filesystem access.
Definition at line 290 of file VFS.cc.
References Tree< K, E >::lookup().
|
private |
|
private |
| void VFS::addMountCallback | ( | MountCallback | callback | ) |
Adds a mount callback - the function is called when a disk is mounted or unmounted. Duplicate registration is idempotent and revives an entry closed by a deferred removal which has no external drainer.
Definition at line 1151 of file VFS.cc.
References Spinlock::acquire(), and Spinlock::release().
| void VFS::addProbeCallback | ( | Filesystem::ProbeCallback | callback | ) |
Adds a filesystem probe callback - this is called when a device is mounted. Duplicate registration is idempotent and revives an entry closed by a deferred removal which has no external drainer.
Definition at line 1050 of file VFS.cc.
References Spinlock::acquire(), and Spinlock::release().
|
private |
| VfsMountView * VFS::bootMountView | ( | ) | const |
Definition at line 37 of file VFS-mount-view.cc.
|
static |
|
static |
Checks if the current user can access the given file.
Definition at line 1502 of file VFS.cc.
References checkAccess().
Referenced by UnixSocketSyscalls::bind(), checkAccess(), checkAccess(), Filesystem::createDirectory(), Filesystem::createFile(), Filesystem::createLink(), Filesystem::createSymlink(), Filesystem::findNode(), PosixSubsystem::invoke(), and Filesystem::remove().
Here is the caller graph for this function:
|
static |
Checks access using an explicit, immutable credential snapshot.
Definition at line 1521 of file VFS.cc.
References checkAccess(), and Vector< T >::count().
Attempts to create a directory.
Definition at line 1464 of file VFS.cc.
References Filesystem::createDirectory().
Attempts to create a file.
Definition at line 1459 of file VFS.cc.
References Filesystem::createFile().
Attempts to create a hard link.
Definition at line 1479 of file VFS.cc.
References Filesystem::createLink().
Attempts to create a symlink.
Definition at line 1474 of file VFS.cc.
References Filesystem::createSymlink().
| bool VFS::diskMount | ( | uint32_t | id, |
| MountIdentity & | identity | ||
| ) | const |
|
private |
|
private |
Attempts to obtain a File for a specific path.
Definition at line 1023 of file VFS.cc.
References Filesystem::find(), and String::view().
Referenced by ProcFs::initialise().
Here is the caller graph for this function:| File * VFS::findRetained | ( | const String & | path, |
| Directory::ChildLease & | result, | ||
| File * | pStartNode = nullptr |
||
| ) |
Find a File while retaining its VFS lifetime in result.
Definition at line 1042 of file VFS.cc.
References Filesystem::findRetained(), and String::view().
Referenced by Symlink::followLinkRetained(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), removeDiskFilesystem(), and unregisterFilesystem().
Here is the caller graph for this function:
|
private |
| Filesystem * VFS::getFilesystemAt | ( | const String & | path | ) | const |
Find the filesystem mounted at an exact absolute path. The returned pointer is borrowed and is not pinned against unregistration.
Definition at line 843 of file VFS.cc.
References Tree< K, E >::begin(), and Tree< K, E >::end().
| bool VFS::getMountPath | ( | Filesystem * | pFs, |
| String & | path | ||
| ) | const |
Obtain the canonical mount path for a filesystem.
Definition at line 832 of file VFS.cc.
References Tree< K, E >::lookup().
Referenced by mount().
Here is the caller graph for this function:| void VFS::getMounts | ( | Vector< MountSnapshot > & | mounts | ) | const |
|
private |
| Filesystem * VFS::getRootFilesystem | ( | ) | const |
Returns a borrowed pointer; the lookup does not pin filesystem lifetime.
Definition at line 742 of file VFS.cc.
Referenced by mount(), removeDiskFilesystem(), and MountService::serve().
Here is the caller graph for this function:| bool VFS::initialiseMountView | ( | ) |
Definition at line 50 of file VFS-mount-view.cc.
|
static |
Returns the singleton VFS instance.
Definition at line 311 of file VFS.cc.
References m_Instance.
Referenced by Directory::addCachedDirectoryEntry(), Directory::addDirectoryEntry(), Directory::addEphemeralFile(), UnixSocketSyscalls::bind(), Directory::enumerate(), Filesystem::findNode(), Filesystem::findParent(), Symlink::followLinkRetained(), File::getFullPath(), SysFs::initialise(), DevFs::initialise(), ProcFs::initialise(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), Directory::lookupChildAt(), PtmxFile::open(), File::releaseVfsReference(), Filesystem::removeChild(), Directory::removeEphemeralFiles(), File::retainDetachedParent(), Symlink::retainTarget(), File::retainVfsReference(), MountService::serve(), and File::~File().
Here is the caller graph for this function:
|
private |
| bool VFS::mount | ( | Disk * | pDisk, |
| String & | stableName, | ||
| Filesystem ** | pMountedFs = nullptr |
||
| ) |
Probe and register a filesystem backed by a disk.
Definition at line 419 of file VFS.cc.
References Spinlock::acquire(), getMountPath(), getRootFilesystem(), Filesystem::getVolumeLabel(), ProcessorBase::information(), registerFilesystem(), Spinlock::release(), and unregisterFilesystem().
Referenced by removeEphemeralFiles().
Here is the caller graph for this function:| VfsMountView * VFS::mountView | ( | ) | const |
Definition at line 25 of file VFS-mount-view.cc.
| uint64_t VFS::namespaceGeneration | ( | ) | const |
Odd while a namespace writer owns admission; readers never hold it for I/O.
Definition at line 22 of file VFS-mount-view.cc.
| bool VFS::pinFilesystem | ( | Filesystem * | key, |
| FilesystemPin & | pin | ||
| ) | const |
| String VFS::registerFilesystem | ( | Filesystem * | pFs, |
| const String & | preferredStableName | ||
| ) |
|
private |
Remove a path only if its terminal entry still has the expected identity.
Definition at line 1488 of file VFS.cc.
References Filesystem::remove().
| bool VFS::removeDiskFilesystem | ( | Filesystem * | filesystem, |
| bool | deviceAvailable = false |
||
| ) |
Withdraw a removed disk's mounts while retained paths keep inert nodes alive.
Definition at line 660 of file VFS.cc.
References OperationBarrier::close(), Filesystem::deviceRemoved(), findRetained(), InodeEventSource::finishRetirement(), Directory::fromFile(), getRootFilesystem(), File::isDirectory(), Tree< K, E >::lookup(), Directory::setReparsePoint(), Tree< K, E >::take(), and OperationBarrier::wait().
| bool VFS::removeEphemeralFiles | ( | ) |
Retire transient names before their providers unload; namespace writers must be stopped.
Definition at line 1000 of file VFS.cc.
References Tree< K, E >::begin(), Tree< K, E >::end(), Directory::fromFile(), Filesystem::getRoot(), File::isDirectory(), mount(), Vector< T >::pushBack(), and Directory::removeEphemeralFiles().
| bool VFS::removeMountCallback | ( | MountCallback | callback | ) |
Removes a mount callback before its implementation unloads.
Definition at line 1194 of file VFS.cc.
References Spinlock::acquire(), ProcessorBase::executionContext(), ProcessorBase::information(), and Spinlock::release().
| bool VFS::removeProbeCallback | ( | Filesystem::ProbeCallback | callback | ) |
Removes a filesystem probe callback before its implementation unloads.
Definition at line 1093 of file VFS.cc.
References Spinlock::acquire(), ProcessorBase::executionContext(), ProcessorBase::information(), and Spinlock::release().
| bool VFS::retainTrackedFile | ( | File * | pFile | ) |
Retain an already tracked File without publishing an untracked pointer.
Definition at line 1640 of file VFS.cc.
Referenced by Filesystem::findParent(), Directory::lookupChildAt(), Directory::removeEphemeralFiles(), and File::retainVfsReference().
Here is the caller graph for this function:| bool VFS::retireOwnedFilesystem | ( | Filesystem * | filesystem | ) |
Surrenders an attachment-owned registration. Existing admissions drain asynchronously; the last release deletes the backend outside VFS locks.
Definition at line 629 of file VFS.cc.
References OperationBarrier::close(), Tree< K, E >::lookup(), and Tree< K, E >::take().
| bool VFS::setRootFilesystem | ( | Filesystem * | pFs | ) |
Select the filesystem that supplies the root namespace.
Definition at line 716 of file VFS.cc.
References Filesystem::getVolumeLabel(), and Tree< K, E >::lookup().
| bool VFS::shutdownMountView | ( | Vector< Filesystem * > & | ownedBackings | ) |
Terminal-only: detach a drained namespace and return attachment-owned backends.
Definition at line 40 of file VFS-mount-view.cc.
| bool VFS::snapshotDiskMounts | ( | Vector< MountIdentity > & | mounts | ) | const |
| Filesystem::SyncStatus VFS::syncAll | ( | ) |
Pins all registered filesystems, attempts each, and returns the first error.
Definition at line 939 of file VFS.cc.
References Tree< K, E >::begin(), Tree< K, E >::count(), Dec, and Tree< K, E >::end().
| Filesystem::SyncStatus VFS::syncFilesystem | ( | Filesystem * | key | ) |
Pins one registered backing filesystem before calling its sync operation.
Definition at line 918 of file VFS.cc.
References Tree< K, E >::lookup(), and SharedPointer< T >::tryAllocate().
|
private |
| void VFS::trackFile | ( | File * | pFile | ) |
Track a File object that exists. It is necessary to keep track of File objects, or at least those that are stored in Directory caches and Filesystem objects, such that they can be correctly tidied up when no more usages exist.
It is almost never safe to directly delete a File pointer so this helps maintain that safety.
Definition at line 1625 of file VFS.cc.
Referenced by Directory::addCachedDirectoryEntry(), Directory::addDirectoryEntry(), Directory::addEphemeralFile(), UnixSocketSyscalls::bind(), SysFs::initialise(), DevFs::initialise(), and PtmxFile::open().
Here is the caller graph for this function:| bool VFS::tryTrackFile | ( | File * | pFile | ) |
|
static |
| bool VFS::unregisterFilesystem | ( | Filesystem * | pFs, |
| bool | canDelete = true, |
||
| bool | terminal = false |
||
| ) |
Remove a registered filesystem and optionally destroy it. When canDelete is true, the caller must provide exclusive ownership; success consumes the pointer, while false leaves it unconsumed. When canDelete is false, ownership always remains external. Live FilesystemPins reject unregistration without changing publication or closing admission.
Definition at line 580 of file VFS.cc.
References findRetained(), Directory::fromFile(), Filesystem::getVolumeLabel(), File::isDirectory(), Tree< K, E >::lookup(), Directory::setReparsePoint(), Filesystem::shutdown(), and Tree< K, E >::take().
Referenced by mount().
Here is the caller graph for this function:| bool VFS::untrackFile | ( | File * | pFile, |
| bool | destroy = true |
||
| ) |
Stop tracking a File object, destroying by default if it is no longer tracked by any other owners.
Definition at line 1670 of file VFS.cc.
Referenced by Filesystem::findParent(), File::releaseVfsReference(), Directory::removeEphemeralFiles(), and File::~File().
Here is the caller graph for this function:
|
staticprivate |
|
staticprivate |
The static instance object.
Definition at line 423 of file VFS.h.
Referenced by instance().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |