23 #include "precompiled.h"
111 fileInfos->reserve(files.size());
112 for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it)
114 const VfsFile& file = it->second;
119 if(subdirectoryNames)
122 subdirectoryNames->clear();
123 subdirectoryNames->reserve(subdirectories.size());
124 for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it)
125 subdirectoryNames->push_back(it->first);
150 const VfsFile file(name, size, time(0), realDirectory->Priority(), realDirectory);
153 m_trace->NotifyStore(pathname, size);
169 return CreateFile(pathname, fileContents, size);
182 m_trace->NotifyStore(pathname, size);
219 m_trace->NotifyLoad(pathname, size);
227 std::wstring textRepresentation;
228 textRepresentation.reserve(100*
KiB);
230 return textRepresentation;
257 pathname = path / realPathname.
Filename();
294 if(realDirectory && realDirectory->Path() == realPath)
301 for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it)
303 const OsPath& subdirectoryName = it->first;
VfsDirectory m_rootDirectory
VfsFile * AddFile(const VfsFile &file)
Status vfs_Lookup(const VfsPath &pathname, VfsDirectory *startDirectory, VfsDirectory *&directory, VfsFile **pfile, size_t flags)
Resolve a pathname.
virtual Status GetVirtualPath(const OsPath &realPathname, VfsPath &pathname)
retrieve the VFS pathname that corresponds to a real file.
const Status VFS_ALREADY_MOUNTED
const VfsPath & Name() const
const Status VFS_DIR_NOT_FOUND
shared_ptr< ITrace > PITrace
void RemoveFile(const VfsPath &name)
remove the given file from the virtual directory (no effect on the physical file).
virtual Status LoadFile(const VfsPath &pathname, shared_ptr< u8 > &fileContents, size_t &size)
Read an entire file into memory.
virtual void Clear()
empty the contents of the filesystem.
void DirectoryDescriptionR(std::wstring &descriptions, const VfsDirectory &directory, size_t indentLevel)
append each directory's files' description to the given string.
virtual std::wstring TextRepresentation() const
static const uintptr_t maxSectorSize
virtual Status ReplaceFile(const VfsPath &pathname, const shared_ptr< u8 > &fileContents, size_t size)
Replace a file with the given contents.
virtual Status GetDirectoryRealPath(const VfsPath &pathname, OsPath &realPathname)
retrieve the real (POSIX) pathname underlying a VFS directory.
bool Retrieve(const VfsPath &pathname, shared_ptr< u8 > &data, size_t &size)
Attempt to retrieve a file's contents from the file cache.
const VfsFiles & Files() const
const PRealDirectory & AssociatedDirectory() const
virtual Status GetFilePriority(const VfsPath &pathname, size_t *ppriority) const
Retrieve mount priority for a file.
virtual Status GetDirectoryEntries(const VfsPath &path, CFileInfos *fileInfos, DirectoryNames *subdirectoryNames) const
Retrieve lists of all files and subdirectories in a directory.
Status FindRealPathR(const OsPath &realPath, const VfsDirectory &directory, const VfsPath &curPath, VfsPath &path)
virtual Status GetFileInfo(const VfsPath &pathname, CFileInfo *pfileInfo) const
Retrieve information about a file (similar to POSIX stat).
virtual Status CreateFile(const VfsPath &pathname, const shared_ptr< u8 > &fileContents, size_t size)
Create a file with the given contents.
return ERR::VFS_DIR_NOT_FOUND if the given real path doesn't exist.
cache of file contents with support for zero-copy IO.
const VfsSubdirectories & Subdirectories() const
#define WARN_RETURN_STATUS_IF_ERR(expression)
PIVFS CreateVfs(size_t cacheSize)
create an instance of a Virtual File System.
virtual Status RepopulateDirectory(const VfsPath &path)
request the directory be re-populated when it is next accessed.
virtual Status GetRealPath(const VfsPath &pathname, OsPath &realPathname)
retrieve the real (POSIX) pathname underlying a VFS file.
shared_ptr< RealDirectory > PRealDirectory
Status vfs_Attach(VfsDirectory *directory, const PRealDirectory &realDirectory)
attach a real directory to a VFS directory.
const Status VFS_FILE_NOT_FOUND
int pthread_mutex_lock(pthread_mutex_t *m)
static pthread_mutex_t vfs_mutex
i64 Status
Error handling system.
shared_ptr< T > DummySharedPtr(T *ptr)
#define stats_io_user_request(user_size)
#define STATUS_ADD_DEFINITIONS(definitions)
add a module's array of StatusDefinition to the list.
const PIFileLoader & Loader() const
void Remove(const VfsPath &pathname)
Remove a file's contents from the cache (if it exists).
shared_ptr< u8 > Reserve(size_t size)
Reserve a chunk of the cache's memory region.
static Status AllocateAligned(shared_ptr< T > &p, size_t size, size_t alignment=cacheLineSize)
void Clear()
empty file and subdirectory lists (e.g.
int pthread_mutex_unlock(pthread_mutex_t *m)
std::vector< OsPath > DirectoryNames
std::map< VfsPath, VfsFile > VfsFiles
PITrace CreateDummyTrace(size_t maxSize)
#define stats_cache(cr, size)
void RequestRepopulate()
ensure the next ShouldPopulate returns true.
void Add(const VfsPath &pathname, const shared_ptr< u8 > &data, size_t size, size_t cost=1)
Add a file's contents to the cache.
std::map< VfsPath, VfsDirectory > VfsSubdirectories
#define PTHREAD_MUTEX_INITIALIZER
Status CreateDirectories(const OsPath &path, mode_t mode)
bool DirectoryExists(const OsPath &path)
std::vector< CFileInfo > CFileInfos
virtual Status RemoveFile(const VfsPath &pathname)
remove file from the virtual directory listing and evict its data from the cache. ...
static const StatusDefinition vfsStatusDefinitions[]
const Status PATH_NOT_FOUND
virtual Status Mount(const VfsPath &mountPoint, const OsPath &path, size_t flags, size_t priority)
mount a directory into the VFS.
#define RETURN_STATUS_IF_ERR(expression)