The Pedigree Project  0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Directory Class Reference

#include <Directory.h>

+ Inheritance diagram for Directory:
+ Collaboration diagram for Directory:

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 ()
 
FilegetChild (size_t n)
 
size_t getNumChildren ()
 
virtual void cacheDirectoryContents ()
 
virtual bool isCachePopulated () const
 
Filelookup (const HashedStringView &s) const
 
void remove (const HashedStringView &s)
 
DirectorygetReparsePoint () 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)
 
FilesystemgetFilesystem () 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
 
FilegetParent () 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 Fileopen ()
 

Static Public Member Functions

static DirectoryfromFile (File *pF)
 

Protected Types

typedef LazyEvaluate< File, DirectoryEntryMetadata, evaluateEntry, destroyEntryDirectoryEntry
 

Protected Member Functions

virtual const DirectoryEntryCachegetCache ()
 
void markCachePopulated ()
 
void addDirectoryEntry (const String &name, File *pTarget)
 
void addDirectoryEntry (const String &name, DirectoryEntryMetadata &&meta)
 
void preallocateDirectoryEntries (size_t count)
 
virtual FileconvertToFile (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 *, HashedStringViewDirectoryEntryCache
 

Private Member Functions

 Directory (const Directory &file)
 
Directoryoperator= (const Directory &)
 
virtual bool isBytewise () const
 

Static Private Member Functions

static FileevaluateEntry (const DirectoryEntryMetadata &meta)
 
static void destroyEntry (File *file)
 

Private Attributes

DirectoryEntryCache m_Cache
 
bool m_bCachePopulated
 
Directorym_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 Filesystemm_pFilesystem
 
size_t m_Size
 
Filem_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
 

Detailed Description

A Directory node.

Todo:
Need to add a way to count # of times a particular lookup has happened so we can potentially offer a way to cull directory entries that are otherwise just consuming space.

Definition at line 44 of file Directory.h.

Constructor & Destructor Documentation

Directory::Directory ( )

Constructor, creates an invalid directory.

Definition at line 30 of file Directory.cc.

Directory::Directory ( const Directory file)
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.

Directory::~Directory ( )
virtual

Destructor - doesn't do anything.

Definition at line 45 of file Directory.cc.

References m_Cache.

Member Function Documentation

void Directory::addDirectoryEntry ( const String name,
File pTarget 
)
protected
void Directory::addDirectoryEntry ( const String name,
DirectoryEntryMetadata &&  meta 
)
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.

Todo:
removal will still want to hit the Filesystem here! not good!

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

+ Here is the caller graph for this function:

void Directory::cacheDirectoryContents ( )
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().

+ Here is the caller graph for this function:

File * Directory::convertToFile ( const DirectoryEntryMetadata meta)
protectedvirtual

Convert given metadata into a useful File object.

Reimplemented in Ext2Directory.

Definition at line 222 of file Directory.cc.

Referenced by empty().

+ Here is the caller graph for this function:

void Directory::destroyEntry ( File file)
staticprivate
Todo:
figure out how to destroy File objects!

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.

Note
partial failure - some entries have been deleted by this point!

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

+ Here is the caller graph for this function:

static Directory* Directory::fromFile ( File pF)
inlinestatic
virtual const DirectoryEntryCache& Directory::getCache ( )
inlineprotectedvirtual

Provides subclasses with direct access to the directory's listing.

Definition at line 181 of file Directory.h.

Referenced by Filesystem::remove().

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

virtual bool Directory::isBytewise ( ) const
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.

virtual bool Directory::isCachePopulated ( ) const
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().

+ Here is the caller graph for this function:

virtual bool Directory::isDirectory ( )
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().

+ Here is the caller graph for this function:

void Directory::markCachePopulated ( )
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().

+ Here is the caller graph for this function:

void Directory::preallocateDirectoryEntries ( size_t  count)
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.

Todo:
add sibling keys for other HashTable functions

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

+ Here is the caller graph for this function:

void Directory::setReparsePoint ( Directory pTarget)

Set/unset the reparse point for this directory.

Definition at line 154 of file Directory.cc.

References m_ReparseTarget.

Member Data Documentation

bool Directory::m_bCachePopulated
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().

DirectoryEntryCache Directory::m_Cache
private
Directory* Directory::m_ReparseTarget = nullptr
private

Reparse target.

Definition at line 177 of file Directory.h.

Referenced by getReparsePoint(), and setReparsePoint().


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