Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/file/vfs/vfs.h
/* Copyright (C) 2013 Wildfire Games. | /* Copyright (C) 2017 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | struct IVFS | ||||
virtual Status GetDirectoryEntries(const VfsPath& path, CFileInfos* fileInfos, DirectoryNames* subdirectoryNames) const = 0; | virtual Status GetDirectoryEntries(const VfsPath& path, CFileInfos* fileInfos, DirectoryNames* subdirectoryNames) const = 0; | ||||
/** | /** | ||||
* Create a file with the given contents. | * Create a file with the given contents. | ||||
* @param pathname | * @param pathname | ||||
* @param fileContents | * @param fileContents | ||||
* @param size [bytes] of the contents, will match that of the file. | * @param size [bytes] of the contents, will match that of the file. | ||||
* @return Status. | * @return Status. | ||||
* | |||||
* rationale: disallowing partial writes simplifies file cache coherency | |||||
* (we need only invalidate cached data when closing a newly written file). | |||||
**/ | **/ | ||||
virtual Status CreateFile(const VfsPath& pathname, const shared_ptr<u8>& fileContents, size_t size) = 0; | virtual Status CreateFile(const VfsPath& pathname, const shared_ptr<u8>& fileContents, size_t size) = 0; | ||||
/** | /** | ||||
* Replace a file with the given contents. | * Replace a file with the given contents. | ||||
* | * | ||||
* @see CreateFile | * @see CreateFile | ||||
* | * | ||||
* Used to replace a file if it is already present (even if the file is not | * 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 | * in the attached vfs directory). Calls CreateFile if the file doesn't yet | ||||
* exist. | * exist. | ||||
**/ | **/ | ||||
virtual Status ReplaceFile(const VfsPath& pathname, const shared_ptr<u8>& fileContents, size_t size) = 0; | virtual Status ReplaceFile(const VfsPath& pathname, const shared_ptr<u8>& fileContents, size_t size) = 0; | ||||
/** | /** | ||||
* Read an entire file into memory. | * Read an entire file into memory. | ||||
* | * | ||||
* @param pathname | * @param pathname | ||||
* @param fileContents receives a smart pointer to the contents. | * @param fileContents receives 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). | |||||
* @param size receives the size [bytes] of the file contents. | * @param size receives the size [bytes] of the file contents. | ||||
* @return Status. | * @return Status. | ||||
**/ | **/ | ||||
virtual Status LoadFile(const VfsPath& pathname, shared_ptr<u8>& fileContents, size_t& size) = 0; | virtual Status LoadFile(const VfsPath& pathname, shared_ptr<u8>& fileContents, size_t& size) = 0; | ||||
/** | /** | ||||
* @return a string representation of all files and directories. | * @return a string representation of all files and directories. | ||||
**/ | **/ | ||||
Show All 20 Lines | struct IVFS | ||||
* | * | ||||
* the current implementation requires time proportional to the | * the current implementation requires time proportional to the | ||||
* number of directories; this could be accelerated by only checking | * number of directories; this could be accelerated by only checking | ||||
* directories below a mount point with a matching real path. | * directories below a mount point with a matching real path. | ||||
**/ | **/ | ||||
virtual Status GetVirtualPath(const OsPath& realPathname, VfsPath& pathname) = 0; | virtual Status GetVirtualPath(const OsPath& realPathname, VfsPath& pathname) = 0; | ||||
/** | /** | ||||
* remove file from the virtual directory listing and evict its | * remove file from the virtual directory listing. | ||||
* data from the cache. | |||||
**/ | **/ | ||||
virtual Status RemoveFile(const VfsPath& pathname) = 0; | virtual Status RemoveFile(const VfsPath& pathname) = 0; | ||||
/** | /** | ||||
* request the directory be re-populated when it is next accessed. | * request the directory be re-populated when it is next accessed. | ||||
* useful for synchronizing with the underlying filesystem after | * useful for synchronizing with the underlying filesystem after | ||||
* files have been created or their metadata changed. | * files have been created or their metadata changed. | ||||
**/ | **/ | ||||
virtual Status RepopulateDirectory(const VfsPath& path) = 0; | virtual Status RepopulateDirectory(const VfsPath& path) = 0; | ||||
/** | /** | ||||
* empty the contents of the filesystem. | * empty the contents of the filesystem. | ||||
* this is typically only necessary when changing the set of | * this is typically only necessary when changing the set of | ||||
* mounted directories, e.g. when switching mods. | * mounted directories, e.g. when switching mods. | ||||
* NB: open files are not affected. | * NB: open files are not affected. | ||||
**/ | **/ | ||||
virtual void Clear() = 0; | virtual void Clear() = 0; | ||||
}; | }; | ||||
typedef shared_ptr<IVFS> PIVFS; | typedef shared_ptr<IVFS> PIVFS; | ||||
/** | /** | ||||
* create an instance of a Virtual File System. | * create an instance of a Virtual File System. | ||||
* | * | ||||
* @param cacheSize size [bytes] of memory to reserve for a file cache, | |||||
* or zero to disable it. if small enough to fit, file contents are | |||||
* stored here until no references remain and they are evicted. | |||||
* | |||||
* note: there is no limitation to a single instance, it may make sense | * note: there is no limitation to a single instance, it may make sense | ||||
* to create and destroy VFS instances during each unit test. | * to create and destroy VFS instances during each unit test. | ||||
**/ | **/ | ||||
LIB_API PIVFS CreateVfs(size_t cacheSize); | LIB_API PIVFS CreateVfs(); | ||||
#endif // #ifndef INCLUDED_VFS | #endif // #ifndef INCLUDED_VFS |
Wildfire Games · Phabricator