filesys.h File Reference

Filesystem header file. More...

#include <stdio.h>
Include dependency graph for filesys.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  qFILE_s
struct  filelink_s
 Links one file onto another - like a symlink. More...
struct  packfile_t
struct  pack_s
struct  searchpath_s

Defines

#define BASEDIRNAME   "base"
#define MAX_MAPS   400
#define MAX_QPATH   64
#define MAX_OSPATH   256
#define MAX_FILES   512
#define SFF_ARCH   0x01
#define SFF_HIDDEN   0x02
#define SFF_RDONLY   0x04
#define SFF_SUBDIR   0x08
#define SFF_SYSTEM   0x10

Typedefs

typedef struct qFILE_s qFILE
typedef struct filelink_s filelink_t
 Links one file onto another - like a symlink.
typedef struct pack_s pack_t
typedef struct searchpath_s searchpath_t

Enumerations

enum  fsMode_t { FS_READ, FS_WRITE, FS_APPEND, FS_APPEND_SYNC }
enum  fsOrigin_t { FS_SEEK_CUR, FS_SEEK_END, FS_SEEK_SET }
enum  filemode_t { FILE_READ, FILE_WRITE, FILE_APPEND }

Functions

int FS_FileLength (qFILE *f)
 Returns the size of a given file.
int FS_Seek (qFILE *f, long offset, int origin)
 Sets the file position of the given file.
int FS_WriteFile (const void *buffer, size_t len, const char *filename)
int FS_Write (const void *buffer, int len, qFILE *f)
 Properly handles partial writes.
int FS_Printf (qFILE *f, const char *msg,...) __attribute__((format(__printf__
int void FS_InitFilesystem (qboolean writeToHomeDir)
void FS_RestartFilesystem (void)
 Restart the filesystem (reload all pk3 files).
const char * FS_Gamedir (void)
 Called to find where to write a file (savegames, etc).
const char * FS_NextPath (const char *prevpath)
 Allows enumerating all of the directories in the search path.
void FS_ExecAutoexec (void)
const char * FS_GetCwd (void)
 Return current working dir.
void FS_NormPath (char *path)
 Convert operating systems path separators to ufo virtual filesystem separators (/).
qboolean FS_FileExists (const char *filename)
 Checks whether a file exists (not in virtual filesystem).
void FS_SkipBlock (const char **text)
void FS_GetMaps (qboolean reset)
 File the fs_maps array with valid maps.
int FS_OpenFile (const char *filename, qFILE *file, filemode_t mode)
void FS_CloseFile (qFILE *f)
 Closes a file handle.
qboolean FS_RenameFile (const char *from, const char *to, qboolean relative)
 Renames a file.
void FS_RemoveFile (const char *osPath)
void FS_CopyFile (const char *fromOSPath, const char *toOSPath)
 Copy a fully specified file from one place to another.
int FS_LoadFile (const char *path, byte **buffer)
 Filenames are relative to the quake search path.
int FS_Read (void *buffer, int len, qFILE *f)
 Read a file into a given buffer in memory.
void FS_FreeFile (void *buffer)
int FS_CheckFile (const char *fmt,...) __attribute__((format(printf
int int FS_BuildFileList (const char *files)
 Build a filelist.
const char * FS_NextFileFromFileList (const char *files)
char * FS_NextScriptHeader (const char *files, const char **name, const char **text)
void FS_CreatePath (const char *path)
 Creates any directories needed to store the given filename.
char ** FS_ListFiles (const char *findname, int *numfiles, unsigned musthave, unsigned canthave)
 Builds a qsorted filelist.
const char * FS_GetFileData (const char *files)
 Returns the buffer of a file.
void FS_Shutdown (void)
 cleanup function

Variables

char * fs_maps [MAX_MAPS]
int fs_numInstalledMaps

Detailed Description

Filesystem header file.

Definition in file filesys.h.


Define Documentation

#define BASEDIRNAME   "base"
#define MAX_FILES   512

Definition at line 47 of file filesys.h.

Referenced by FS_ListFiles().

#define MAX_MAPS   400

Definition at line 37 of file filesys.h.

Referenced by FS_GetMaps().

#define MAX_OSPATH   256
#define MAX_QPATH   64
#define SFF_ARCH   0x01

Definition at line 116 of file filesys.h.

Referenced by CompareAttributes().

#define SFF_HIDDEN   0x02

Definition at line 117 of file filesys.h.

Referenced by CompareAttributes(), FS_AddGameDirectory(), FS_BuildFileList(), and FS_GetMaps().

#define SFF_RDONLY   0x04

Definition at line 118 of file filesys.h.

Referenced by CompareAttributes().

#define SFF_SUBDIR   0x08

Definition at line 119 of file filesys.h.

Referenced by CompareAttributes(), and FS_AddGameDirectory().

#define SFF_SYSTEM   0x10

Definition at line 120 of file filesys.h.

Referenced by CompareAttributes(), FS_AddGameDirectory(), FS_BuildFileList(), and FS_GetMaps().


Typedef Documentation

typedef struct filelink_s filelink_t

Links one file onto another - like a symlink.

typedef struct pack_s pack_t
typedef struct qFILE_s qFILE
typedef struct searchpath_s searchpath_t

Enumeration Type Documentation

enum filemode_t

file opening modes

Enumerator:
FILE_READ 
FILE_WRITE 
FILE_APPEND 

Definition at line 103 of file filesys.h.

enum fsMode_t
Enumerator:
FS_READ 
FS_WRITE 
FS_APPEND 
FS_APPEND_SYNC 

Definition at line 62 of file filesys.h.

enum fsOrigin_t
Enumerator:
FS_SEEK_CUR 
FS_SEEK_END 
FS_SEEK_SET 

Definition at line 69 of file filesys.h.


Function Documentation

int int FS_BuildFileList ( const char *  fileList  ) 
int FS_CheckFile ( const char *  fmt,
  ... 
)
void FS_CloseFile ( qFILE f  ) 
void FS_CopyFile ( const char *  fromOSPath,
const char *  toOSPath 
)

Copy a fully specified file from one place to another.

Todo:
Allow copy of pk3 file content

Definition at line 1607 of file files.c.

References byte, com_fileSysPool, Com_Printf(), f, FS_CreatePath(), len, Mem_Free, Mem_PoolAlloc, SEEK_END, SEEK_SET, and Sys_Error().

void FS_CreatePath ( const char *  path  ) 

Creates any directories needed to store the given filename.

See also:
Sys_Mkdir
Note:
Paths should already be normalized
See also:
FS_NormPath

Definition at line 97 of file files.c.

References MAX_OSPATH, ofs, Q_strncpyz(), and Sys_Mkdir().

Referenced by CL_StartHTTPDownload(), FS_AddHomeAsGameDirectory(), FS_CopyFile(), and FS_OpenFileSingle().

void FS_ExecAutoexec ( void   ) 

Referenced by Qcommon_Init().

qboolean FS_FileExists ( const char *  filename  ) 

Checks whether a file exists (not in virtual filesystem).

See also:
FS_CheckFile
Parameters:
[in] filename Full filesystem path to the file

Definition at line 1532 of file files.c.

Referenced by CL_LanguageTest().

int FS_FileLength ( qFILE f  ) 

Returns the size of a given file.

Todo:
Implement for pk3

Definition at line 75 of file files.c.

References dbuffer::end, qFILE_s::f, pos, SEEK_END, and SEEK_SET.

Referenced by ASE_Load(), FS_OpenFileSingle(), FS_WriteFile(), MP_LoadTeamMultiplayer(), and SAV_GameLoad().

void FS_FreeFile ( void *  buffer  ) 
const char* FS_Gamedir ( void   ) 

Called to find where to write a file (savegames, etc).

Note:
We will use the searchpath that isn't a pack and has highest priority

Definition at line 49 of file files.c.

References searchpath_s::filename, searchpath_s::next, and searchpath_s::pack.

Referenced by CL_CheckAndQueueDownload(), CL_FinishHTTPDownload(), CL_StartHTTPDownload(), FS_InitFilesystem(), FS_NextPath(), FS_OpenFileSingle(), FS_RenameFile(), FS_WriteFile(), Key_WriteBindings(), R_ScreenShot(), and SV_InitGameProgs().

const char* FS_GetCwd ( void   ) 

Return current working dir.

Definition at line 1519 of file files.c.

References FS_NormPath(), MAX_OSPATH, Q_strncpyz(), and Sys_Cwd().

Referenced by CL_Init(), and CL_LanguageTest().

const char* FS_GetFileData ( const char *  files  ) 

Returns the buffer of a file.

Parameters:
[in] files If NULL, reset the filelist If not NULL it may be something like *.cfg to get a list of all config files in base/. Calling FS_GetFileData("*.cfg"); until it returns NULL is sufficient to get one buffer after another.
Note:
You don't have to free the file buffer on the calling side. This is done in this function, too

Definition at line 1072 of file files.c.

References block(), byte, Com_Printf(), linkedList_s::data, listBlock_s::files, FS_BuildFileList(), FS_FreeFile(), FS_LoadFile(), MAX_QPATH, linkedList_s::next, listBlock_s::next, listBlock_s::path, and Q_strncpyz().

Referenced by Com_GetScriptChecksum().

void FS_GetMaps ( qboolean  reset  ) 

File the fs_maps array with valid maps.

Parameters:
[in] reset If true the directory is scanned every time for new maps (useful for dedicated servers). If false we only use the maps array (for clients e.g.)

Todo:
paths are normalized here?

Definition at line 1310 of file files.c.

References CheckBSPFile(), com_fileSysPool, Com_Printf(), Com_SkipPath(), Com_sprintf(), Com_StripExtension(), searchpath_s::filename, pack_s::files, FS_ListFiles(), FS_MapDefSort(), FS_NormPath(), MAX_MAPS, MAX_OSPATH, MAX_QPATH, Mem_Free, Mem_PoolAlloc, packfile_t::name, searchpath_s::next, pack_s::numfiles, searchpath_s::pack, Q_strncpyz(), qtrue, SFF_HIDDEN, and SFF_SYSTEM.

Referenced by SV_CompleteMapCommand(), and SV_ListMaps_f().

int void FS_InitFilesystem ( qboolean  writeToHomeDir  ) 
char** FS_ListFiles ( const char *  findname,
int *  numfiles,
unsigned  musthave,
unsigned  canthave 
)

Builds a qsorted filelist.

See also:
Sys_FindFirst
Sys_FindNext
Sys_FindClose
Note:
Don't forget to free the filelist array and the file itself

Definition at line 564 of file files.c.

References com_fileSysPool, i, MAX_FILES, MAX_OSPATH, Mem_PoolAlloc, Mem_PoolStrDup, Q_StringSort(), Q_strlwr(), Q_strncpyz(), Sys_FindClose(), Sys_FindFirst(), and Sys_FindNext().

Referenced by FS_AddGameDirectory(), FS_BuildFileList(), and FS_GetMaps().

int FS_LoadFile ( const char *  path,
byte **  buffer 
)
const char* FS_NextFileFromFileList ( const char *  files  ) 
const char* FS_NextPath ( const char *  prevpath  ) 

Allows enumerating all of the directories in the search path.

Note:
ignore pk3 here

Definition at line 618 of file files.c.

References searchpath_s::filename, FS_Gamedir(), searchpath_s::next, and searchpath_s::pack.

Referenced by SV_GetGameAPI().

char* FS_NextScriptHeader ( const char *  files,
const char **  name,
const char **  text 
)
void FS_NormPath ( char *  path  ) 

Convert operating systems path separators to ufo virtual filesystem separators (/).

See also:
Sys_NormPath

Definition at line 66 of file files.c.

References Sys_NormPath().

Referenced by FS_BuildFileList(), FS_GetCwd(), and FS_GetMaps().

int FS_OpenFile ( const char *  filename,
qFILE file,
filemode_t  mode 
)
int FS_Printf ( qFILE f,
const char *  msg,
  ... 
)
int FS_Read ( void *  buffer,
int  len,
qFILE f 
)

Read a file into a given buffer in memory.

Parameters:
[out] buffer Pointer to memory where file contents are written to.
[in] len The length of the supplied memory area.
[in] f The file which is to be read into the memory area.
Returns:
The length of the file contents successfully read and written to memory.
Note:
buffer is not null-terminated at the end of file reading
This function properly handles partial reads so check that the returned length matches len.
Reads in blocks of 64k.
See also:
FS_LoadFile
FS_OpenFile

Definition at line 324 of file files.c.

References block(), byte, qFILE_s::f, MAX_READ, Sys_Error(), unzReadCurrentFile(), and qFILE_s::z.

Referenced by ASE_Load(), CheckBSPFile(), CIN_OGM_LoadBlockToSync(), CIN_ROQ_DecodeChunk(), CIN_ROQ_PlayCinematic(), Com_MD5File(), FS_LoadFile(), FS_Seek(), MP_LoadTeamMultiplayer(), MP_MultiplayerTeamSlotComments_f(), SAV_GameLoad(), SAV_GameReadGameComment(), and SAV_GameSaveNameCleanup_f().

void FS_RemoveFile ( const char *  osPath  ) 
See also:
FS_CopyFile

Definition at line 1649 of file files.c.

References Com_Printf(), and Sys_Error().

Referenced by CL_FinishHTTPDownload(), and Key_WriteBindings().

qboolean FS_RenameFile ( const char *  from,
const char *  to,
qboolean  relative 
)

Renames a file.

See also:
FS_RemoveFile
FS_CopyFile
Parameters:
[in] from The source filename
[in] to The filename we want after the rename
[in] relative If relative is true we have to add the FS_Gamedir path for writing

Definition at line 1666 of file files.c.

References Com_sprintf(), FS_Gamedir(), MAX_OSPATH, qfalse, qtrue, and Sys_Error().

Referenced by CL_FinishHTTPDownload().

void FS_RestartFilesystem ( void   ) 

Restart the filesystem (reload all pk3 files).

Note:
Call this after you finished a download
See also:
FS_Shutdown
FS_InitFilesystem

if we can't find default.cfg, assume that the paths are busted and error out now, rather than getting an unreadable graphics screen when the font fails to load

Definition at line 1585 of file files.c.

References FS_CheckFile(), FS_InitFilesystem(), FS_Shutdown(), qtrue, and Sys_Error().

Referenced by CL_FinishHTTPDownload().

int FS_Seek ( qFILE f,
long  offset,
int  origin 
)

Sets the file position of the given file.

Parameters:
[in] f The opened file handle
[in] origin fsOrigin_t
[in] offset The offset you want to do the
See also:
FS_Read

Definition at line 228 of file files.c.

References byte, qFILE_s::f, qFILE_s::filepos, FS_Read(), FS_SEEK_CUR, FS_SEEK_END, FS_SEEK_SET, PK3_SEEK_BUFFER_SIZE, SEEK_CUR, SEEK_END, SEEK_SET, Sys_Error(), unzOpenCurrentFile(), unzSetCurrentFileInfoPosition(), and qFILE_s::z.

void FS_Shutdown ( void   ) 
void FS_SkipBlock ( const char **  text  ) 
int FS_Write ( const void *  buffer,
int  len,
qFILE f 
)

Properly handles partial writes.

Definition at line 1453 of file files.c.

References block(), byte, Com_Printf(), and qFILE_s::f.

Referenced by AddLump(), Com_vPrintf(), Con_SaveConsoleHistory(), FS_WriteFile(), R_WriteCompressedTGA(), WriteBSPFile(), WriteTGA24(), and WriteToFile().

int FS_WriteFile ( const void *  buffer,
size_t  len,
const char *  filename 
)

Variable Documentation

char* fs_maps[MAX_MAPS]

Definition at line 1244 of file files.c.

Referenced by SV_CompleteMapCommand(), and SV_ListMaps_f().

Definition at line 1245 of file files.c.

Referenced by SV_CompleteMapCommand(), and SV_ListMaps_f().


Generated by  doxygen 1.6.2