Pyrogenesis  trunk
Public Member Functions | Private Member Functions | Private Attributes | List of all members
VFS Class Reference
Inheritance diagram for VFS:
Inheritance graph
[legend]
Collaboration diagram for VFS:
Collaboration graph
[legend]

Public Member Functions

 VFS (size_t cacheSize)
 
virtual Status Mount (const VfsPath &mountPoint, const OsPath &path, size_t flags, size_t priority)
 mount a directory into the VFS. More...
 
virtual Status GetFileInfo (const VfsPath &pathname, CFileInfo *pfileInfo) const
 Retrieve information about a file (similar to POSIX stat). More...
 
virtual Status GetFilePriority (const VfsPath &pathname, size_t *ppriority) const
 Retrieve mount priority for a file. More...
 
virtual Status GetDirectoryEntries (const VfsPath &path, CFileInfos *fileInfos, DirectoryNames *subdirectoryNames) const
 Retrieve lists of all files and subdirectories in a directory. More...
 
virtual Status CreateFile (const VfsPath &pathname, const shared_ptr< u8 > &fileContents, size_t size)
 Create a file with the given contents. More...
 
virtual Status ReplaceFile (const VfsPath &pathname, const shared_ptr< u8 > &fileContents, size_t size)
 Replace a file with the given contents. More...
 
virtual Status LoadFile (const VfsPath &pathname, shared_ptr< u8 > &fileContents, size_t &size)
 Read an entire file into memory. More...
 
virtual std::wstring TextRepresentation () const
 
virtual Status GetRealPath (const VfsPath &pathname, OsPath &realPathname)
 retrieve the real (POSIX) pathname underlying a VFS file. More...
 
virtual Status GetDirectoryRealPath (const VfsPath &pathname, OsPath &realPathname)
 retrieve the real (POSIX) pathname underlying a VFS directory. More...
 
virtual Status GetVirtualPath (const OsPath &realPathname, VfsPath &pathname)
 retrieve the VFS pathname that corresponds to a real file. More...
 
virtual Status RemoveFile (const VfsPath &pathname)
 remove file from the virtual directory listing and evict its data from the cache. More...
 
virtual Status RepopulateDirectory (const VfsPath &path)
 request the directory be re-populated when it is next accessed. More...
 
virtual void Clear ()
 empty the contents of the filesystem. More...
 
- Public Member Functions inherited from IVFS
virtual ~IVFS ()
 

Private Member Functions

Status FindRealPathR (const OsPath &realPath, const VfsDirectory &directory, const VfsPath &curPath, VfsPath &path)
 

Private Attributes

size_t m_cacheSize
 
FileCache m_fileCache
 
PITrace m_trace
 
VfsDirectory m_rootDirectory
 

Constructor & Destructor Documentation

VFS::VFS ( size_t  cacheSize)
inline

Member Function Documentation

virtual void VFS::Clear ( )
inlinevirtual

empty the contents of the filesystem.

this is typically only necessary when changing the set of mounted directories, e.g. when switching mods. NB: open files are not affected.

Implements IVFS.

virtual Status VFS::CreateFile ( const VfsPath pathname,
const shared_ptr< u8 > &  fileContents,
size_t  size 
)
inlinevirtual

Create a file with the given contents.

Parameters
pathname
fileContents
size[bytes] of the contents, will match that of the file.
Returns
Status.

rationale: disallowing partial writes simplifies file cache coherency (we need only invalidate cached data when closing a newly written file).

Implements IVFS.

Status VFS::FindRealPathR ( const OsPath realPath,
const VfsDirectory directory,
const VfsPath curPath,
VfsPath path 
)
inlineprivate
virtual Status VFS::GetDirectoryEntries ( const VfsPath path,
CFileInfos fileInfos,
DirectoryNames subdirectoryNames 
) const
inlinevirtual

Retrieve lists of all files and subdirectories in a directory.

Returns
Status.

Rationale:

  • this interface avoids having to lock the directory while an iterator is extant.
  • we cannot efficiently provide routines for returning files and subdirectories separately due to the underlying POSIX interface.

Implements IVFS.

virtual Status VFS::GetDirectoryRealPath ( const VfsPath pathname,
OsPath realPathname 
)
inlinevirtual

retrieve the real (POSIX) pathname underlying a VFS directory.

this is useful for passing paths to external libraries.

Implements IVFS.

virtual Status VFS::GetFileInfo ( const VfsPath pathname,
CFileInfo pfileInfo 
) const
inlinevirtual

Retrieve information about a file (similar to POSIX stat).

Parameters
pathname
pfileInforeceives information about the file. Passing NULL suppresses warnings if the file doesn't exist.
Returns
Status.

Implements IVFS.

virtual Status VFS::GetFilePriority ( const VfsPath pathname,
size_t *  ppriority 
) const
inlinevirtual

Retrieve mount priority for a file.

Parameters
pathname
ppriorityreceives priority value, if the file can be found.
Returns
Status.

Implements IVFS.

virtual Status VFS::GetRealPath ( const VfsPath pathname,
OsPath realPathname 
)
inlinevirtual

retrieve the real (POSIX) pathname underlying a VFS file.

this is useful for passing paths to external libraries.

Implements IVFS.

virtual Status VFS::GetVirtualPath ( const OsPath realPathname,
VfsPath pathname 
)
inlinevirtual

retrieve the VFS pathname that corresponds to a real file.

this is useful for reacting to file change notifications.

the current implementation requires time proportional to the number of directories; this could be accelerated by only checking directories below a mount point with a matching real path.

Implements IVFS.

virtual Status VFS::LoadFile ( const VfsPath pathname,
shared_ptr< u8 > &  fileContents,
size_t &  size 
)
inlinevirtual

Read an entire file into memory.

Parameters
pathname
fileContentsreceives a smart pointer to the contents. CAVEAT: this will be taken from the file cache if the VFS was created with cacheSize != 0 and size < cacheSize. There is no provision for Copy-on-Write, which means that such buffers must not be modified (this is enforced via mprotect).
sizereceives the size [bytes] of the file contents.
Returns
Status.

Implements IVFS.

virtual Status VFS::Mount ( const VfsPath mountPoint,
const OsPath path,
size_t  flags,
size_t  priority 
)
inlinevirtual

mount a directory into the VFS.

Parameters
mountPoint(will be created if it does not already exist)
pathreal directory path
flags
priority
Returns
Status.

if files are encountered that already exist in the VFS (sub)directories, the most recent / highest priority/precedence version is preferred.

if files with archive extensions are seen, their contents are added as well.

Implements IVFS.

virtual Status VFS::RemoveFile ( const VfsPath pathname)
inlinevirtual

remove file from the virtual directory listing and evict its data from the cache.

Implements IVFS.

virtual Status VFS::ReplaceFile ( const VfsPath pathname,
const shared_ptr< u8 > &  fileContents,
size_t  size 
)
inlinevirtual

Replace a file with the given contents.

See also
CreateFile

Used to replace a file if it is already present (even if the file is not in the attached vfs directory). Calls CreateFile if the file doesn't yet exist.

Implements IVFS.

virtual Status VFS::RepopulateDirectory ( const VfsPath path)
inlinevirtual

request the directory be re-populated when it is next accessed.

useful for synchronizing with the underlying filesystem after files have been created or their metadata changed.

Implements IVFS.

virtual std::wstring VFS::TextRepresentation ( ) const
inlinevirtual
Returns
a string representation of all files and directories.

Implements IVFS.

Member Data Documentation

size_t VFS::m_cacheSize
private
FileCache VFS::m_fileCache
private
VfsDirectory VFS::m_rootDirectory
mutableprivate
PITrace VFS::m_trace
private

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