The Pedigree Project 0.1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Filesystem Class Referenceabstract

#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
 

Detailed Description

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.

Member Typedef Documentation

◆ ProbeCallback

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.

Member Enumeration Documentation

◆ SyncStatus

enum class Filesystem::SyncStatus
strong

Definition at line 52 of file Filesystem.h.

Constructor & Destructor Documentation

◆ Filesystem() [1/2]

Filesystem::Filesystem ( )

Constructor - creates a blank object.

Definition at line 39 of file Filesystem.cc.

◆ ~Filesystem()

Filesystem::~Filesystem ( )
virtual

Destructor

Definition at line 43 of file Filesystem.cc.

References OperationBarrier::closeAndWait().

◆ Filesystem() [2/2]

Filesystem::Filesystem ( const Filesystem &  )
private

Copy constructor.

Note
NOT implemented.

Member Function Documentation

◆ beginDeviceRemoval()

bool Filesystem::beginDeviceRemoval ( bool  deviceAvailable)
protected

Definition at line 71 of file Filesystem.cc.

◆ createDirectory() [1/2]

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:

◆ createDirectory() [2/2]

virtual bool Filesystem::createDirectory ( File *  parent,
const String &  filename,
uint32_t  mask 
)
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.

◆ createFile() [1/2]

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:

◆ createFile() [2/2]

virtual bool Filesystem::createFile ( File *  parent,
const String &  filename,
uint32_t  mask 
)
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.

◆ createLink() [1/2]

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:

◆ createLink() [2/2]

bool Filesystem::createLink ( File *  parent,
const String &  filename,
File *  target 
)
protectedvirtual

createLink calls this after it has parsed the string path.

Reimplemented in Ext2Filesystem, and RamFs.

Definition at line 988 of file Filesystem.cc.

◆ createSymlink() [1/2]

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:

◆ createSymlink() [2/2]

virtual bool Filesystem::createSymlink ( File *  parent,
const String &  filename,
const String &  value 
)
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.

◆ decodeFileHandle()

FileHandleStatus Filesystem::decodeFileHandle ( const FileHandle &  handle,
RetainedFile &  file 
)
virtual

Definition at line 115 of file Filesystem.cc.

◆ deviceRemoved()

bool Filesystem::deviceRemoved ( bool  deviceAvailable = false)
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:

◆ encodeFileHandle()

FileHandleStatus Filesystem::encodeFileHandle ( File &  file,
FileHandle &  handle 
)
virtual

Caller holds a VFS mount operation through handle access and publication.

Reimplemented in Ext2Filesystem.

Definition at line 110 of file Filesystem.cc.

◆ fileHandleFsid()

FileHandleStatus Filesystem::fileHandleFsid ( FileSystemId &  id)
virtual

Definition at line 120 of file Filesystem.cc.

◆ find() [1/4]

File * Filesystem::find ( const String &  path)
virtual

Definition at line 187 of file Filesystem.cc.

◆ find() [2/4]

File * Filesystem::find ( const String &  path,
File *  pStartNode 
)
virtual

Definition at line 197 of file Filesystem.cc.

◆ find() [3/4]

File * Filesystem::find ( const StringView &  path)
virtual

Attempt to find a file or directory in this filesystem.

Parameters
pathThe path to the file, in UTF-8 format, without filesystem identifier (e.g. not "root:/file", but "/file").
pStartNodeThe node to start parsing 'path' from - defaults to / but is expected to contain the current working directory.
Returns
The file if one was found, or 0 otherwise or if there was an error.

Definition at line 183 of file Filesystem.cc.

References findNode().

Referenced by VFS::find().

+ Here is the caller graph for this function:

◆ find() [4/4]

File * Filesystem::find ( const StringView &  path,
File *  pStartNode 
)
virtual

Definition at line 191 of file Filesystem.cc.

◆ findNode() [1/2]

File * Filesystem::findNode ( File *  pNode,
StringView  path 
)
private

Internal function to find a node - Returns 0 on failure or the node.

Parameters
pNodeThe node to start parsing 'path' from.
pathThe 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:

◆ findNode() [2/2]

File * Filesystem::findNode ( File *  pNode,
StringView  path,
File *  stableStart,
File *  trueRoot,
File **  retainedResult 
)
private

◆ findParent()

File * Filesystem::findParent ( StringView  path,
File *  pStartNode,
String &  filename,
File **  retainedParent = nullptr 
)
private

Internal function to find a node's parent directory.

Parameters
pathThe path from pStartNode to the original file.
pStartNodeThe node to start parsing 'path' from.
[out]filenameThe 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:

◆ findRetained()

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:

◆ getDisk()

Disk * Filesystem::getDisk ( )
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:

◆ getRoot()

virtual File * Filesystem::getRoot ( ) const
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:

◆ getUuid()

virtual bool Filesystem::getUuid ( String &  uuid) const
inlinevirtual

Returns the canonical filesystem UUID when this filesystem has one.

Reimplemented in FatFilesystem, and Ext2Filesystem.

Definition at line 98 of file Filesystem.h.

◆ getVolumeLabel()

virtual const String & Filesystem::getVolumeLabel ( ) const
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:

◆ initialise()

virtual bool Filesystem::initialise ( Disk *  pDisk)
pure virtual

Populates this filesystem with data from the given Disk device.

Returns
true on success, false on failure.

Implemented in SysFs, DevFs, ProcFs, UnixFilesystem, ConsoleManager, Ext2Filesystem, Iso9660Filesystem, RawFs, FatFilesystem, and RamFs.

◆ isCaseSensitive()

virtual bool Filesystem::isCaseSensitive ( )
inlinevirtual

Does the filesystem care about case sensitivity?

Definition at line 155 of file Filesystem.h.

◆ isDeviceRemoved()

bool Filesystem::isDeviceRemoved ( ) const

Definition at line 59 of file Filesystem.cc.

◆ isReadOnly()

bool Filesystem::isReadOnly ( )
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:

◆ operator=()

void Filesystem::operator= ( const Filesystem &  )
private

Assignment operator.

Note
NOT implemented.

◆ quotaControl()

QuotaStatus Filesystem::quotaControl ( const QuotaRequest &  ,
QuotaResponse &  ,
File *  quotaFile = nullptr 
)
virtual

Definition at line 7 of file Quota.cc.

◆ remove() [1/3]

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

◆ remove() [2/3]

bool Filesystem::remove ( const StringView &  path,
File *  pStartNode = 0 
)

Removes a file, directory or symlink.

Note
Will fail if it is a directory and is not empty. The failure mode is unspecified.

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() [3/3]

bool Filesystem::remove ( File *  parent,
File *  file 
)

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

◆ removeChild()

bool Filesystem::removeChild ( File *  parent,
const String &  filename,
File *  expected,
const FilesystemPathRef *  parentPath = nullptr 
)
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:

◆ removeNode()

virtual bool Filesystem::removeNode ( File *  parent,
const String &  filename,
File *  file 
)
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:

◆ rename()

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

◆ renameChildren()

bool Filesystem::renameChildren ( File *  oldParent,
const String &  oldName,
File *  newParent,
const String &  newName,
bool  noReplace,
bool  sourceMustBeDirectory,
const FilesystemPathRef *  oldPath = nullptr,
const FilesystemPathRef *  newPath = nullptr 
)
private

Definition at line 490 of file Filesystem.cc.

◆ renameNode()

bool Filesystem::renameNode ( Directory *  oldParent,
const String &  oldName,
File *  source,
Directory *  newParent,
const String &  newName,
File *  replaced 
)
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.

◆ shutdown()

Filesystem::SyncStatus Filesystem::shutdown ( )
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:

◆ sync()

Filesystem::SyncStatus Filesystem::sync ( )
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:

◆ tryAcquireOperation()

bool Filesystem::tryAcquireOperation ( OperationBarrier::Lease &  operation) const

Definition at line 47 of file Filesystem.cc.

Friends And Related Symbol Documentation

◆ Directory

friend class Directory
friend

Definition at line 45 of file Filesystem.h.

◆ VFS

friend class VFS
friend

VFS can access nAliases

Definition at line 48 of file Filesystem.h.

◆ VfsMountView

friend class VfsMountView
friend

Definition at line 49 of file Filesystem.h.

Member Data Documentation

◆ m_bReadOnly

bool Filesystem::m_bReadOnly
protected

◆ m_DiskUse

DiskUse Filesystem::m_DiskUse
protected

Definition at line 189 of file Filesystem.h.

◆ m_Operations

OperationBarrier Filesystem::m_Operations
mutableprotected

Definition at line 190 of file Filesystem.h.

◆ m_pDisk

Disk* Filesystem::m_pDisk
protected

◆ m_RemovalOwner

Atomic<Thread*> Filesystem::m_RemovalOwner = nullptr
private

Definition at line 194 of file Filesystem.h.

◆ m_StructureLock

Mutex Filesystem::m_StructureLock
staticprivate

Serializes changes to directory ancestry against removal.

Definition at line 199 of file Filesystem.h.

Referenced by removeChild().


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