The Pedigree Project
0.1
|
#include <Directory.h>
Classes | |
struct | DirectoryEntryMetadata |
Public Member Functions | |
Directory () | |
Directory (const String &name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime, Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs, size_t size, File *pParent) | |
virtual | ~Directory () |
virtual bool | isDirectory () |
File * | getChild (size_t n) |
size_t | getNumChildren () |
virtual void | cacheDirectoryContents () |
virtual bool | isCachePopulated () const |
File * | lookup (const HashedStringView &s) const |
void | remove (const HashedStringView &s) |
Directory * | getReparsePoint () const |
Get the reparse point attached to this directory. Reparse points allow locations on the filesystem to redirect lookups to a separate directory. While the reparse point is active, the target directory is used for lookups instead of this one. | |
void | setReparsePoint (Directory *pTarget) |
bool | addEphemeralFile (File *pFile) |
Add an ephemeral file to the directory. More... | |
bool | empty () |
Public Member Functions inherited from File | |
File () | |
File (const String &name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime, Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs, size_t size, File *pParent) | |
virtual | ~File () |
virtual uint64_t | read (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
virtual uint64_t | write (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
virtual physical_uintptr_t | getPhysicalPage (size_t offset) |
virtual void | returnPhysicalPage (size_t offset) |
virtual void | sync () |
virtual void | sync (size_t offset, bool async) |
Time::Timestamp | getCreationTime () |
void | setCreationTime (Time::Timestamp t) |
Time::Timestamp | getAccessedTime () |
void | setAccessedTime (Time::Timestamp t) |
Time::Timestamp | getModifiedTime () |
void | setModifiedTime (Time::Timestamp t) |
String | getName () const |
void | getName (String &s) const |
virtual String | getFullPath (bool bWithLabel=true) |
virtual void | truncate () |
size_t | getSize () |
void | setSize (size_t sz) |
virtual bool | isSymlink () |
virtual bool | isPipe () const |
virtual bool | isFifo () const |
virtual bool | isSocket () const |
uintptr_t | getInode () const |
virtual void | setInode (uintptr_t inode) |
Filesystem * | getFilesystem () const |
void | setFilesystem (Filesystem *pFs) |
virtual void | fileAttributeChanged () |
virtual void | increaseRefCount (bool bIsWriter) |
virtual void | decreaseRefCount (bool bIsWriter) |
void | setPermissions (uint32_t perms) |
uint32_t | getPermissions () const |
void | setUid (size_t uid) |
size_t | getUid () const |
void | setGid (size_t gid) |
size_t | getGid () const |
File * | getParent () const |
virtual int | select (bool bWriting=false, int timeout=0) |
void | monitor (Thread *pThread, Event *pEvent) |
void | cullMonitorTargets (Thread *pThread) |
virtual bool | supports (const size_t command) const |
virtual int | command (const size_t command, void *buffer) |
virtual size_t | getBlockSize () const |
void | enableDirect () |
void | disableDirect () |
virtual void | preallocate (size_t expectedSize, bool zero=true) |
virtual File * | open () |
Static Public Member Functions | |
static Directory * | fromFile (File *pF) |
Protected Types | |
typedef LazyEvaluate< File, DirectoryEntryMetadata, evaluateEntry, destroyEntry > | DirectoryEntry |
Protected Member Functions | |
virtual const DirectoryEntryCache & | getCache () |
void | markCachePopulated () |
void | addDirectoryEntry (const String &name, File *pTarget) |
void | addDirectoryEntry (const String &name, DirectoryEntryMetadata &&meta) |
void | preallocateDirectoryEntries (size_t count) |
virtual File * | convertToFile (const DirectoryEntryMetadata &meta) |
Protected Member Functions inherited from File | |
virtual uint64_t | readBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
virtual uint64_t | writeBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
virtual uintptr_t | readBlock (uint64_t location) |
virtual void | writeBlock (uint64_t location, uintptr_t addr) |
virtual void | extend (size_t newSize) |
virtual void | extend (size_t newSize, uint64_t location, uint64_t size) |
void | dataChanged () |
void | getFilesystemLabel (HugeStaticString &s) |
virtual void | pinBlock (uint64_t location) |
virtual void | unpinBlock (uint64_t location) |
void | evict (uint64_t location) |
void | setPermissionsOnly (uint32_t perms) |
void | setUidOnly (size_t uid) |
void | setGidOnly (size_t gid) |
Private Types | |
typedef HashTable< String, DirectoryEntry *, HashedStringView > | DirectoryEntryCache |
Private Member Functions | |
Directory (const Directory &file) | |
Directory & | operator= (const Directory &) |
virtual bool | isBytewise () const |
Static Private Member Functions | |
static File * | evaluateEntry (const DirectoryEntryMetadata &meta) |
static void | destroyEntry (File *file) |
Private Attributes | |
DirectoryEntryCache | m_Cache |
bool | m_bCachePopulated |
Directory * | m_ReparseTarget = nullptr |
Friends | |
class | Filesystem |
Additional Inherited Members | |
Static Protected Member Functions inherited from File | |
static void | writeCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta) |
Protected Attributes inherited from File | |
String | m_Name |
Time::Timestamp | m_AccessedTime |
Time::Timestamp | m_ModifiedTime |
Time::Timestamp | m_CreationTime |
uintptr_t | m_Inode |
class Filesystem * | m_pFilesystem |
size_t | m_Size |
File * | m_pParent |
size_t | m_nWriters |
size_t | m_nReaders |
size_t | m_Uid |
size_t | m_Gid |
uint32_t | m_Permissions |
HashTable< DataCacheKey, uintptr_t > | m_DataCache |
bool | m_bDirect |
Cache | m_FillCache |
Mutex | m_Lock |
List< MonitorTarget * > | m_MonitorTargets |
A Directory node.
Definition at line 44 of file Directory.h.
Directory::Directory | ( | ) |
Constructor, creates an invalid directory.
Definition at line 30 of file Directory.cc.
|
private |
Copy constructors are hidden - unused!
Directory::Directory | ( | const String & | name, |
Time::Timestamp | accessedTime, | ||
Time::Timestamp | modifiedTime, | ||
Time::Timestamp | creationTime, | ||
uintptr_t | inode, | ||
class Filesystem * | pFs, | ||
size_t | size, | ||
File * | pParent | ||
) |
Constructor, should be called only by a Filesystem.
Definition at line 34 of file Directory.cc.
|
virtual |
Add an entry to the directory.
Definition at line 114 of file Directory.cc.
References ERROR, HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::insert(), m_bCachePopulated, and m_Cache.
Referenced by RawFsDir::addEntry(), FatDirectory::addEntry(), Ext2Directory::addEntry(), FatDirectory::cacheDirectoryContents(), Ext2Directory::cacheDirectoryContents(), and Iso9660Directory::cacheDirectoryContents().
|
protected |
Add a lazily-evaluated entry to the directory.
Definition at line 131 of file Directory.cc.
References ERROR, HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::insert(), m_bCachePopulated, and m_Cache.
bool Directory::addEphemeralFile | ( | File * | pFile | ) |
Add an ephemeral file to the directory.
This is used to store files that need to be visible in the VFS but are not backed by a "real" file on disk. For example, a socket might need to be present with a filesystem path but should not be written to disk.
Definition at line 159 of file Directory.cc.
References cacheDirectoryContents(), File::getName(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::insert(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), m_bCachePopulated, m_Cache, and UNLIKELY.
Referenced by UnixSocketSyscalls::bind().
|
virtual |
Load the directory's contents into the cache.
Reimplemented in UnixDirectory, RamDir, Iso9660Directory, Ext2Directory, FatDirectory, and RawFsDir.
Definition at line 85 of file Directory.cc.
Referenced by addEphemeralFile(), Filesystem::findNode(), getChild(), getNumChildren(), and UnixFilesystem::getVolumeLabel().
|
protectedvirtual |
Convert given metadata into a useful File object.
Reimplemented in Ext2Directory.
Definition at line 222 of file Directory.cc.
Referenced by empty().
|
staticprivate |
Definition at line 214 of file Directory.cc.
bool Directory::empty | ( | ) |
Empty the entire directory, deleting all files within it (non-recursively). This does NOT check that the directory is "empty" first.
Definition at line 180 of file Directory.cc.
References HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::clear(), convertToFile(), m_Cache, Vector< T >::pushBack(), and Filesystem::remove().
Referenced by Filesystem::remove().
Eases the pain of casting, and performs a sanity check.
Definition at line 50 of file Directory.h.
References FATAL, File::isDirectory(), and Filesystem::operator=().
Referenced by UnixSocketSyscalls::bind(), UnixFilesystem::createDirectory(), UnixFilesystem::createFile(), FatFilesystem::createFile(), FatFilesystem::createSymlink(), Filesystem::findNode(), Filesystem::findParent(), UnixFilesystem::getVolumeLabel(), ProcFs::initialise(), FatFilesystem::remove(), UnixFilesystem::remove(), Filesystem::remove(), and UnixSocket::~UnixSocket().
|
inlineprotectedvirtual |
Provides subclasses with direct access to the directory's listing.
Definition at line 181 of file Directory.h.
Referenced by Filesystem::remove().
File * Directory::getChild | ( | size_t | n | ) |
Returns the n'th child of this directory, or an invalid file.
Definition at line 55 of file Directory.cc.
References cacheDirectoryContents(), HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::getNth(), m_bCachePopulated, m_Cache, and UNLIKELY.
size_t Directory::getNumChildren | ( | ) |
Returns the number of children in this directory.
Definition at line 74 of file Directory.cc.
References cacheDirectoryContents(), m_bCachePopulated, m_Cache, and UNLIKELY.
Referenced by Filesystem::remove().
|
inlineprivatevirtual |
File subclasses can define this and return true if they require read() calls to perform actual data reads, and false if readBlock() is otherwise sufficient.
Reimplemented from File.
Definition at line 151 of file Directory.h.
|
inlinevirtual |
Does this directory have cache?
Definition at line 90 of file Directory.h.
Referenced by FatDirectory::addEntry(), Ext2Directory::cacheDirectoryContents(), Filesystem::findNode(), and FatDirectory::removeEntry().
|
inlinevirtual |
Returns true if the File is actually a directory.
Reimplemented from File.
Definition at line 75 of file Directory.h.
File * Directory::lookup | ( | const HashedStringView & | s | ) | const |
Look up the given filename in the directory.
Definition at line 89 of file Directory.cc.
References LIKELY, HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), m_bCachePopulated, and m_Cache.
Referenced by Filesystem::findNode().
|
inlineprotected |
Mark the directory cache as populated now.
Definition at line 187 of file Directory.h.
Referenced by Ext2Directory::cacheDirectoryContents(), FatDirectory::cacheDirectoryContents(), and Iso9660Directory::cacheDirectoryContents().
|
protected |
Preallocate space for the given number of directory entries.
Definition at line 227 of file Directory.cc.
References m_Cache, and HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::reserve().
void Directory::remove | ( | const HashedStringView & | s | ) |
Remove the given filename in the directory.
Definition at line 102 of file Directory.cc.
References HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::lookup(), m_Cache, and HashTable< K, V, SiblingK, InitialBuckets, QuadraticProbe, GrowthFactor >::remove().
Referenced by Filesystem::remove(), and UnixSocket::~UnixSocket().
void Directory::setReparsePoint | ( | Directory * | pTarget | ) |
Set/unset the reparse point for this directory.
Definition at line 154 of file Directory.cc.
References m_ReparseTarget.
|
private |
Whether the directory cache is populated with entries or still needs to be loaded. Directories are lazy-loaded using this.
Definition at line 174 of file Directory.h.
Referenced by addDirectoryEntry(), addEphemeralFile(), getChild(), getNumChildren(), and lookup().
|
private |
Directory contents cache.
Definition at line 168 of file Directory.h.
Referenced by addDirectoryEntry(), addEphemeralFile(), empty(), getChild(), getNumChildren(), lookup(), preallocateDirectoryEntries(), remove(), and ~Directory().
|
private |
Reparse target.
Definition at line 177 of file Directory.h.
Referenced by getReparsePoint(), and setReparsePoint().