2009-04-01 22:03:56 +00:00
# include "hash.h"
2013-06-23 02:17:02 +00:00
2014-10-05 20:04:11 +00:00
/*
Threading :
When the main thread will harm the filesystem tree / hash , it will first lock fs_thread_mutex ( FIXME : make a proper rwlock ) .
Worker threads must thus lock that mutex for any opens ( to avoid it changing underneath it ) , but can unlock it as soon as the open call returns .
Files may be shared between threads , but not simultaneously .
The filesystem driver is responsible for closing the pak / pk3 once all files are closed , and must ensure that opens + reads + closes as well as archive closure are thread safe .
*/
2013-08-06 10:48:51 +00:00
# define FSVER 2
2013-06-23 02:17:02 +00:00
2014-10-05 20:04:11 +00:00
2014-03-30 08:55:06 +00:00
# define FF_NOTFOUND (0u) //file wasn't found
# define FF_FOUND (1u<<0u) //file was found
# define FF_SYMLINK (1u<<1u) //file contents are the name of a different file (symlink). do a recursive lookup on the name
# define FF_DIRECTORY (1u<<2u)
2014-01-13 02:42:25 +00:00
2012-05-09 15:30:53 +00:00
typedef struct
{
bucket_t buck ;
int depth ; /*shallower files will remove deeper files*/
} fsbucket_t ;
2009-04-01 22:03:56 +00:00
extern hashtable_t filesystemhash ; //this table is the one to build your hash references into
extern int fs_hash_dups ; //for tracking efficiency. no functional use.
extern int fs_hash_files ; //for tracking efficiency. no functional use.
2014-03-30 08:55:06 +00:00
extern qboolean fs_readonly ; //if true, fopen(, "w") should always fail.
2014-10-05 20:04:11 +00:00
extern void * fs_thread_mutex ;
2009-04-01 22:03:56 +00:00
2013-03-31 04:21:08 +00:00
struct searchpath_s ;
2013-06-23 02:17:02 +00:00
struct searchpathfuncs_s
{
2014-01-13 02:42:25 +00:00
int fsver ;
void ( QDECL * ClosePath ) ( searchpathfuncs_t * handle ) ;
2013-06-23 02:17:02 +00:00
2014-02-07 08:38:40 +00:00
void ( QDECL * GetPathDetails ) ( searchpathfuncs_t * handle , char * outdetails , size_t sizeofdetails ) ;
2014-01-13 02:42:25 +00:00
void ( QDECL * BuildHash ) ( searchpathfuncs_t * handle , int depth , void ( QDECL * FS_AddFileHash ) ( int depth , const char * fname , fsbucket_t * filehandle , void * pathhandle ) ) ;
unsigned int ( QDECL * FindFile ) ( searchpathfuncs_t * handle , flocation_t * loc , const char * name , void * hashedresult ) ; //true if found (hashedresult can be NULL)
2009-04-01 22:03:56 +00:00
//note that if rawfile and offset are set, many Com_FileOpens will read the raw file
//otherwise ReadFile will be called instead.
2014-01-13 02:42:25 +00:00
void ( QDECL * ReadFile ) ( searchpathfuncs_t * handle , flocation_t * loc , char * buffer ) ; //reads the entire file in one go (size comes from loc, so make sure the loc is valid, this is for performance with compressed archives)
2014-02-07 08:38:40 +00:00
int ( QDECL * EnumerateFiles ) ( searchpathfuncs_t * handle , const char * match , int ( QDECL * func ) ( const char * fname , qofs_t fsize , void * parm , searchpathfuncs_t * spath ) , void * parm ) ;
2009-04-01 22:03:56 +00:00
2014-01-13 02:42:25 +00:00
int ( QDECL * GeneratePureCRC ) ( searchpathfuncs_t * handle , int seed , int usepure ) ;
2009-04-01 22:03:56 +00:00
2014-01-13 02:42:25 +00:00
vfsfile_t * ( QDECL * OpenVFS ) ( searchpathfuncs_t * handle , flocation_t * loc , const char * mode ) ;
2012-05-09 15:30:53 +00:00
2014-01-13 02:42:25 +00:00
qboolean ( QDECL * PollChanges ) ( searchpathfuncs_t * handle ) ; //returns true if there were changes
2013-08-06 10:48:51 +00:00
2014-01-13 02:42:25 +00:00
qboolean ( QDECL * RenameFile ) ( searchpathfuncs_t * handle , const char * oldname , const char * newname ) ; //returns true on success, false if source doesn't exist, or if dest does.
qboolean ( QDECL * RemoveFile ) ( searchpathfuncs_t * handle , const char * filename ) ; //returns true on success, false if it wasn't found or is readonly.
qboolean ( QDECL * MkDir ) ( searchpathfuncs_t * handle , const char * filename ) ; //is this really needed?
2013-06-23 02:17:02 +00:00
} ;
//searchpathfuncs_t *(QDECL *OpenNew)(vfsfile_t *file, const char *desc); //returns a handle to a new pak/path
2009-04-01 22:03:56 +00:00
//the stdio filesystem is special as that's the starting point of the entire filesystem
//warning: the handle is known to be a string pointer to the dir name
2013-06-23 02:17:02 +00:00
extern searchpathfuncs_t * ( QDECL VFSOS_OpenPath ) ( vfsfile_t * file , const char * desc ) ;
extern searchpathfuncs_t * ( QDECL FSZIP_LoadArchive ) ( vfsfile_t * packhandle , const char * desc ) ;
extern searchpathfuncs_t * ( QDECL FSPAK_LoadArchive ) ( vfsfile_t * packhandle , const char * desc ) ;
extern searchpathfuncs_t * ( QDECL FSDWD_LoadArchive ) ( vfsfile_t * packhandle , const char * desc ) ;
2013-05-03 04:28:08 +00:00
vfsfile_t * QDECL VFSOS_Open ( const char * osname , const char * mode ) ;
2013-06-23 02:17:02 +00:00
vfsfile_t * FS_DecompressGZip ( vfsfile_t * infile , vfsfile_t * outfile ) ;
2009-04-01 22:03:56 +00:00
2013-06-23 02:17:02 +00:00
int FS_RegisterFileSystemType ( void * module , const char * extension , searchpathfuncs_t * ( QDECL * OpenNew ) ( vfsfile_t * file , const char * desc ) , qboolean loadscan ) ;
2009-04-02 22:25:54 +00:00
void FS_UnRegisterFileSystemType ( int idx ) ;
2013-05-03 04:28:08 +00:00
void FS_UnRegisterFileSystemModule ( void * module ) ;
2013-06-23 02:17:02 +00:00
2014-03-30 08:55:06 +00:00
void FS_EnumerateKnownGames ( qboolean ( * callback ) ( void * usr , ftemanifest_t * man ) , void * usr ) ;
2013-06-23 02:17:02 +00:00
# define SPF_REFERENCED 1 //something has been loaded from this path. should filter out client references...
# define SPF_COPYPROTECTED 2 //downloads are not allowed fom here.
# define SPF_TEMPORARY 4 //a map-specific path, purged at map change.
# define SPF_EXPLICIT 8 //a root gamedir (bumps depth on gamedir depth checks).
# define SPF_UNTRUSTED 16 //has been downloaded from somewhere. configs inside it should never be execed with local access rights.
2014-03-30 08:55:06 +00:00
# define SPF_PRIVATE 32 //private to the client. ie: the fte dir.
2013-06-23 02:17:02 +00:00
qboolean FS_LoadPackageFromFile ( vfsfile_t * vfs , char * pname , char * localname , int * crc , unsigned int flags ) ;