|
The Pedigree Project 0.1
|
#include <Filesystem.h>
Inheritance diagram for Filesystem:
Collaboration diagram for Filesystem:Public Types | |
| enum class | SyncStatus { Success , Unsupported , NoMemory , IoError } |
| typedef Filesystem *(* | ProbeCallback) (Disk *) |
Public Member Functions | |
| Filesystem () | |
| virtual | ~Filesystem () |
| virtual bool | initialise (Disk *pDisk)=0 |
| virtual File * | find (const StringView &path) |
| virtual File * | find (const String &path) |
| virtual File * | find (const StringView &path, File *pStartNode) |
| virtual File * | find (const String &path, File *pStartNode) |
| File * | findRetained (const StringView &path, Directory::ChildLease &result, File *pStartNode=nullptr) |
| virtual File * | getRoot () const =0 |
| virtual const String & | getVolumeLabel () const =0 |
| virtual bool | getUuid (String &uuid) const |
| virtual FileHandleStatus | encodeFileHandle (File &file, FileHandle &handle) |
| virtual FileHandleStatus | decodeFileHandle (const FileHandle &handle, RetainedFile &file) |
| virtual FileHandleStatus | fileHandleFsid (FileSystemId &id) |
| virtual SyncStatus | sync () |
| virtual SyncStatus | shutdown () |
| virtual bool | deviceRemoved (bool deviceAvailable=false) |
| bool | tryAcquireOperation (OperationBarrier::Lease &operation) const |
| bool | isDeviceRemoved () const |
| virtual QuotaStatus | quotaControl (const QuotaRequest &, QuotaResponse &, File *quotaFile=nullptr) |
| bool | createFile (const StringView &path, uint32_t mask, File *pStartNode=0) |
| bool | createDirectory (const StringView &path, uint32_t mask, File *pStartNode=0) |
| bool | createSymlink (const StringView &path, const String &value, File *pStartNode=0) |
| bool | createLink (const StringView &path, File *target, File *pStartNode=0) |
| bool | remove (const StringView &path, File *pStartNode=0) |
| bool | remove (const StringView &path, File *pStartNode, File *expected) |
| bool | rename (const StringView &oldPath, File *oldStart, const StringView &newPath, File *newStart, bool noReplace=false) |
| Disk * | getDisk () |
| bool | isReadOnly () |
| virtual bool | isCaseSensitive () |
| bool | remove (File *parent, File *file) |
Protected Member Functions | |
| virtual bool | createFile (File *parent, const String &filename, uint32_t mask)=0 |
| virtual bool | createDirectory (File *parent, const String &filename, uint32_t mask)=0 |
| virtual bool | createSymlink (File *parent, const String &filename, const String &value)=0 |
| virtual bool | createLink (File *parent, const String &filename, File *target) |
| virtual bool | removeNode (File *parent, const String &filename, File *file)=0 |
| virtual bool | renameNode (Directory *oldParent, const String &oldName, File *source, Directory *newParent, const String &newName, File *replaced) |
| bool | beginDeviceRemoval (bool deviceAvailable) |
Protected Attributes | |
| bool | m_bReadOnly |
| Disk * | m_pDisk |
| DiskUse | m_DiskUse |
| OperationBarrier | m_Operations |
Private Member Functions | |
| bool | removeChild (File *parent, const String &filename, File *expected, const FilesystemPathRef *parentPath=nullptr) |
| bool | renameChildren (File *oldParent, const String &oldName, File *newParent, const String &newName, bool noReplace, bool sourceMustBeDirectory, const FilesystemPathRef *oldPath=nullptr, const FilesystemPathRef *newPath=nullptr) |
| File * | findNode (File *pNode, StringView path) |
| File * | findNode (File *pNode, StringView path, File *stableStart, File *trueRoot, File **retainedResult) |
| File * | findParent (StringView path, File *pStartNode, String &filename, File **retainedParent=nullptr) |
| Filesystem (const Filesystem &) | |
| void | operator= (const Filesystem &) |
Private Attributes | |
| Atomic< Thread * > | m_RemovalOwner = nullptr |
Static Private Attributes | |
| static Mutex | m_StructureLock |
Friends | |
| class | Directory |
| class | VFS |
| class | VfsMountView |
This class provides the abstract skeleton that all filesystems must implement.
Thanks to gr00ber at osdev for the inspiration for the caching algorithms.
Definition at line 44 of file Filesystem.h.
| typedef Filesystem *(* Filesystem::ProbeCallback) (Disk *) |
Type of the probing callback given to the VFS. Probe function - if this filesystem is found on the given Disk device, create a new instance of it and return that. Else return 0.
Definition at line 70 of file Filesystem.h.
|
strong |
Definition at line 52 of file Filesystem.h.
| Filesystem::Filesystem | ( | ) |
Constructor - creates a blank object.
Definition at line 39 of file Filesystem.cc.
|
virtual |
Destructor
Definition at line 43 of file Filesystem.cc.
References OperationBarrier::closeAndWait().
|
private |
Copy constructor.
|
protected |
Definition at line 71 of file Filesystem.cc.
| bool Filesystem::createDirectory | ( | const StringView & | path, |
| uint32_t | mask, | ||
| File * | pStartNode = 0 |
||
| ) |
Creates a directory on the filesystem. Fails if the dir's parent directory does not exist.
Definition at line 262 of file Filesystem.cc.
References VFS::checkAccess(), createDirectory(), and findParent().
Referenced by VFS::createDirectory(), and createDirectory().
Here is the caller graph for this function:
|
protectedpure virtual |
createDirectory calls this after it has parsed the string path.
Implemented in SysFs, DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, FatFilesystem, and RamFs.
| bool Filesystem::createFile | ( | const StringView & | path, |
| uint32_t | mask, | ||
| File * | pStartNode = 0 |
||
| ) |
Creates a file on the filesystem - fails if the file's parent directory does not exist.
Definition at line 223 of file Filesystem.cc.
References VFS::checkAccess(), createFile(), and findParent().
Referenced by VFS::createFile(), and createFile().
Here is the caller graph for this function:
|
protectedpure virtual |
createFile calls this after it has parsed the string path.
Implemented in SysFs, DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, FatFilesystem, and RamFs.
| bool Filesystem::createLink | ( | const StringView & | path, |
| File * | target, | ||
| File * | pStartNode = 0 |
||
| ) |
Creates a hard link on the filesystem to the given target.
Definition at line 340 of file Filesystem.cc.
References VFS::checkAccess(), createLink(), and findParent().
Referenced by VFS::createLink(), and createLink().
Here is the caller graph for this function:
|
protectedvirtual |
createLink calls this after it has parsed the string path.
Reimplemented in Ext2Filesystem, and RamFs.
Definition at line 988 of file Filesystem.cc.
| bool Filesystem::createSymlink | ( | const StringView & | path, |
| const String & | value, | ||
| File * | pStartNode = 0 |
||
| ) |
Creates a symlink on the filesystem, with the given value.
Definition at line 301 of file Filesystem.cc.
References VFS::checkAccess(), createSymlink(), and findParent().
Referenced by VFS::createSymlink(), and createSymlink().
Here is the caller graph for this function:
|
protectedpure virtual |
createSymlink calls this after it has parsed the string path.
Implemented in SysFs, DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, FatFilesystem, and RamFs.
|
virtual |
Definition at line 115 of file Filesystem.cc.
|
virtual |
Rejects backend operations and releases a removed device's ownership.
Reimplemented in Ext2Filesystem, and FatFilesystem.
Definition at line 92 of file Filesystem.cc.
References m_pDisk.
Referenced by Ext2Filesystem::deviceRemoved(), FatFilesystem::deviceRemoved(), and VFS::removeDiskFilesystem().
Here is the caller graph for this function:
|
virtual |
Caller holds a VFS mount operation through handle access and publication.
Reimplemented in Ext2Filesystem.
Definition at line 110 of file Filesystem.cc.
|
virtual |
Definition at line 120 of file Filesystem.cc.
Definition at line 187 of file Filesystem.cc.
Definition at line 197 of file Filesystem.cc.
|
virtual |
Attempt to find a file or directory in this filesystem.
| path | The path to the file, in UTF-8 format, without filesystem identifier (e.g. not "root:/file", but "/file"). |
| pStartNode | The node to start parsing 'path' from - defaults to / but is expected to contain the current working directory. |
Definition at line 183 of file Filesystem.cc.
References findNode().
Referenced by VFS::find().
Here is the caller graph for this function:
|
virtual |
Definition at line 191 of file Filesystem.cc.
|
private |
Internal function to find a node - Returns 0 on failure or the node.
| pNode | The node to start parsing 'path' from. |
| path | The path from pNode to the destination node. |
Definition at line 790 of file Filesystem.cc.
References findNode().
Referenced by find(), findNode(), findNode(), findParent(), and findRetained().
Here is the caller graph for this function:
|
private |
Traverse while retaining the terminal tracked node for a mutation.
Definition at line 799 of file Filesystem.cc.
References Directory::cacheResolvedChildren(), VFS::checkAccess(), findNode(), Symlink::followLinkRetained(), Directory::fromFile(), Symlink::fromFile(), File::getFullPath(), File::getNamespace(), Directory::getReparsePoint(), VFS::instance(), File::isDirectory(), File::isSymlink(), Directory::lookupChild(), StringView::substring(), and UNLIKELY.
|
private |
Internal function to find a node's parent directory.
| path | The path from pStartNode to the original file. | |
| pStartNode | The node to start parsing 'path' from. | |
| [out] | filename | The child file's name. |
Definition at line 921 of file Filesystem.cc.
References findNode(), Directory::fromFile(), Directory::getReparsePoint(), VFS::instance(), File::isDirectory(), VFS::retainTrackedFile(), StringView::substring(), and VFS::untrackFile().
Referenced by createDirectory(), createFile(), createLink(), createSymlink(), remove(), and rename().
Here is the caller graph for this function:| File * Filesystem::findRetained | ( | const StringView & | path, |
| Directory::ChildLease & | result, | ||
| File * | pStartNode = nullptr |
||
| ) |
Find a node and retain its VFS lifetime for the lexical lifetime of result. Filesystem-owned roots are returned without a lease.
Definition at line 201 of file Filesystem.cc.
References findNode().
Referenced by VFS::findRetained(), and Symlink::followLinkRetained().
Here is the caller graph for this function:
|
inline |
Returns the disk in use
Definition at line 145 of file Filesystem.h.
Referenced by MountService::serve().
Here is the caller graph for this function:
|
pure virtual |
Returns the root filesystem node.
Implemented in DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, SysFs, FatFilesystem, and RamFs.
Referenced by File::isStableVfsRoot(), VFS::removeEphemeralFiles(), and File::retainDetachedParent().
Here is the caller graph for this function:
|
inlinevirtual |
Returns the canonical filesystem UUID when this filesystem has one.
Reimplemented in FatFilesystem, and Ext2Filesystem.
Definition at line 98 of file Filesystem.h.
|
pure virtual |
Returns a string identifying the volume label.
Implemented in DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, SysFs, FatFilesystem, and RamFs.
Referenced by File::getFilesystemLabel(), VFS::mount(), MountService::serve(), VFS::setRootFilesystem(), and VFS::unregisterFilesystem().
Here is the caller graph for this function:
|
pure virtual |
Populates this filesystem with data from the given Disk device.
Implemented in SysFs, DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, FatFilesystem, and RamFs.
|
inlinevirtual |
Does the filesystem care about case sensitivity?
Definition at line 155 of file Filesystem.h.
| bool Filesystem::isDeviceRemoved | ( | ) | const |
Definition at line 59 of file Filesystem.cc.
|
inline |
Is the filesystem readonly?
Definition at line 150 of file Filesystem.h.
Referenced by File::allocateRange(), UnixSocketSyscalls::bind(), Ext2File::prepareSharedMapping(), and File::resize().
Here is the caller graph for this function:
|
private |
Assignment operator.
|
virtual |
| bool Filesystem::remove | ( | const StringView & | path, |
| File * | pStartNode, | ||
| File * | expected | ||
| ) |
Remove a path only if its terminal entry still has the expected identity.
Definition at line 393 of file Filesystem.cc.
References VFS::checkAccess(), findParent(), and removeChild().
| bool Filesystem::remove | ( | const StringView & | path, |
| File * | pStartNode = 0 |
||
| ) |
Removes a file, directory or symlink.
Definition at line 385 of file Filesystem.cc.
References remove().
Referenced by Ext2Filesystem::releaseInode(), VFS::remove(), and remove().
Here is the caller graph for this function:Remove the file only if it is still the given child of parent.
Definition at line 435 of file Filesystem.cc.
References File::getName(), and removeChild().
|
private |
Resolve and remove one child at a namespace-locked linearization point.
Definition at line 696 of file Filesystem.cc.
References Directory::fromFile(), VFS::instance(), File::isDirectory(), Directory::isEmpty(), Directory::lookupChild(), m_StructureLock, Directory::namespaceMutationLock(), File::publishEvent(), removeNode(), and String::view().
Referenced by remove(), and remove().
Here is the caller graph for this function:
|
protectedpure virtual |
Remove a backing node while the VFS holds the parent's namespace lock. A successful implementation must retire the parent's cached entry before returning and must recheck directory emptiness while holding the child's namespace lock.
Implemented in DevFs, ProcFs, ConsoleManager, RawFs, SysFs, UnixFilesystem, Ext2Filesystem, Iso9660Filesystem, FatFilesystem, and RamFs.
Referenced by removeChild().
Here is the caller graph for this function:| bool Filesystem::rename | ( | const StringView & | oldPath, |
| File * | oldStart, | ||
| const StringView & | newPath, | ||
| File * | newStart, | ||
| bool | noReplace = false |
||
| ) |
Move one terminal namespace entry without following its symlink target.
Definition at line 447 of file Filesystem.cc.
References findParent().
|
private |
Definition at line 490 of file Filesystem.cc.
|
protectedvirtual |
Change backing entries while the VFS reserves both names and owns their namespace locks. Do not call ordinary lookup/add/remove APIs here. Failure must leave both names unchanged; the VFS publishes cache changes on success.
Reimplemented in UnixFilesystem, Ext2Filesystem, FatFilesystem, and RamFs.
Definition at line 691 of file Filesystem.cc.
|
virtual |
After all users drain, finish teardown writes before backend destruction.
Reimplemented in Ext2Filesystem, RawFs, and FatFilesystem.
Definition at line 105 of file Filesystem.cc.
References m_bReadOnly, m_pDisk, and sync().
Referenced by VFS::unregisterFilesystem().
Here is the caller graph for this function:
|
virtual |
Completes data, metadata and device writeback for changes made before entry.
Reimplemented in Ext2Filesystem, RawFs, DevFs, ProcFs, SysFs, UnixFilesystem, FatFilesystem, and RamFs.
Definition at line 101 of file Filesystem.cc.
References m_bReadOnly.
Referenced by shutdown().
Here is the caller graph for this function:| bool Filesystem::tryAcquireOperation | ( | OperationBarrier::Lease & | operation | ) | const |
Definition at line 47 of file Filesystem.cc.
|
friend |
Definition at line 45 of file Filesystem.h.
|
friend |
VFS can access nAliases
Definition at line 48 of file Filesystem.h.
|
friend |
Definition at line 49 of file Filesystem.h.
|
protected |
is this entire filesystem read-only?
Definition at line 186 of file Filesystem.h.
Referenced by FatFilesystem::createDirectory(), FatFilesystem::createFile(), FatFilesystem::createSymlink(), Ext2Filesystem::deviceRemoved(), Ext2Filesystem::initialise(), Iso9660Filesystem::initialise(), FatFilesystem::removeNode(), Ext2Filesystem::shutdown(), shutdown(), Ext2Filesystem::sync(), and sync().
|
protected |
Definition at line 189 of file Filesystem.h.
|
mutableprotected |
Definition at line 190 of file Filesystem.h.
|
protected |
Disk device(if any).
Definition at line 188 of file Filesystem.h.
Referenced by Ext2Filesystem::deviceRemoved(), deviceRemoved(), Ext2Node::ensureLargeEnough(), Ext2Filesystem::findFreeBlocksInGroup(), Ext2Filesystem::initialise(), FatFilesystem::initialise(), Ext2Filesystem::readBlock(), Ext2File::readPages(), FatFilesystem::readSectorBlock(), Ext2Filesystem::releaseBlockLocked(), Ext2Filesystem::retireInodeLocked(), Ext2Filesystem::shutdown(), shutdown(), Ext2Filesystem::sync(), Ext2File::syncPages(), Ext2Filesystem::writeBlock(), and FatFilesystem::writeSectorBlock().
Definition at line 194 of file Filesystem.h.
|
staticprivate |
Serializes changes to directory ancestry against removal.
Definition at line 199 of file Filesystem.h.
Referenced by removeChild().