00001 /* 00002 * Pod.h 00003 * 00004 * Part of Fly! Legacy project 00005 * 00006 * Copyright 2003-2005 Chris Wallace 00007 * 00008 * Fly! Legacy is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Fly! Legacy is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Fly! Legacy; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00029 #ifndef POD_H 00030 #define POD_H 00031 00032 #ifdef _MSC_VER 00033 #pragma warning( disable : 4786 ) 00034 #endif 00035 00036 // 00037 // Pod filesystem performance metrics are only supported on Windows until an 00038 // alternative to LARGE_INTEGER is implemented. 00039 // 00040 #ifdef _WIN32 00041 #define POD_PERFORMANCE_METRICS 00042 #define WIN32_LEAN_AND_MEAN 00043 #include <windows.h> 00044 #endif 00045 00046 #include <map> 00047 #include <set> 00048 #include <string> 00049 #include "../Include/LogFile.h" 00050 00051 00052 // Pod format signatures 00053 static const unsigned int PodSignatureEpd = 'extd'; 00054 static const unsigned int PodSignaturePod2 = 'POD2'; 00055 static const unsigned int PodSignaturePod3 = 'POD3'; 00056 00057 // Pod formats 00058 typedef enum { 00059 PodFormatUnknown = 0, 00060 PodFormatEpd, 00061 PodFormatPod2, 00062 PodFormatPod3 00063 } EPodFormat; 00064 00065 // 00066 // EPD/POD macro definitions 00067 // 00068 00069 #define EPD_VOLUME_LENGTH (0x100) 00070 #define EPD_FILENAME_LENGTH (0x40) 00071 #define POD_VOLUME_LENGTH (0x50) 00072 #define POD_AUDIT_USERNAME_LENGTH (0x20) 00073 #define POD_FILENAME_LENGTH (0x100) 00074 #define POD_AUTHOR_LENGTH (0x50) 00075 #define POD_COPYRIGHT_LENGTH (0x50) 00076 00077 // 00078 // Enumerated type describing the source for a file within the pod filesystem. A file 00079 // can reside either as a discrete file on disk, or within a POD archive. 00080 // 00081 typedef enum { 00082 PODFILE_SOURCE_POD, 00083 PODFILE_SOURCE_DISK 00084 } EContentSource; 00085 00086 00087 // 00088 // The following structure represents summarized information about a single 00089 // POD archive file within a pod filesystem. The podList member of the PFS 00090 // struct is composed a list of these structs. 00091 // 00092 typedef struct { 00093 char name[1024]; // Full path and filename of the POD 00094 EPodFormat format; // Specific POD format 00095 unsigned int nAuditEntries; // Number of entries in audit trail 00096 unsigned int checksum; // Checksum 00097 unsigned int revision; // Revision 00098 unsigned int priority; // Mount priority 00099 00100 FILE* file; // FILE* 00101 int refs; // Number of active references to the POD 00102 } PFSPOD; 00103 00104 // 00105 // The following structure summarizes information about a single file within 00106 // a POD archive. Instances of this struct are contained in the fileList 00107 // member of the PFSPOD struct. The (relative) filename, the starting offset 00108 // of the file within the pod, its size in bytes and its mount priority are 00109 // recorded. 00110 // 00111 typedef struct { 00112 PFSPOD* pod; // Reference to containing POD 00113 char name[POD_FILENAME_LENGTH+1]; // Name of file within the POD 00114 unsigned int offset; // Starting offset within the POD 00115 unsigned int size; // Size in bytes 00116 unsigned int timestamp; // Timestamp 00117 unsigned int checksum; // Checksum 00118 unsigned int priority; // Mount priority 00119 } PFSPODFILE; 00120 00121 // 00122 // The following data structure is the top-level representation of a pod filesystem. 00123 // Applications must first create an instance of this struct and pass it to 00124 // pinit() for initialization, specifying the policy of whether popen() should 00125 // look first in PODs or on disk when opening a file, and the root folder for 00126 // the filesystem. 00127 // 00128 typedef struct { 00129 bool searchPodFilesFirst; // Whether to open from PODs or disk first 00130 char root[1024]; // Root folder for filesystem 00131 CLogFile *log; // Optional activity logging 00132 std::map<std::string,PFSPOD*> podList; // Map of pods in the filesystem 00133 00134 // Filesystem files residing in pods 00135 std::multimap<std::string,PFSPODFILE*> podFileList; 00136 00137 // Set of filesystem files residing on disk 00138 std::set<std::string> diskFileList; 00139 00140 #ifdef POD_PERFORMANCE_METRICS 00141 // Performance statistics 00142 int popenSuccess, popenFailure; 00143 LARGE_INTEGER popenSuccessTotalTime; 00144 LARGE_INTEGER popenFailureTotalTime; 00145 #endif 00146 } PFS; 00147 00148 // 00149 // The following struct is the application's interface to a file within the 00150 // POD filesystem. It may represent either a file within a POD or a discrete 00151 // disk file; the application should not care where the file is stored. All 00152 // POD filesystem functions operate using pointers to this struct type. 00153 // 00154 typedef struct { 00155 char filename[64]; // Relative filename 00156 EContentSource source; // Source for file, either disk or POD 00157 FILE* pFile; // stdio FILE* handle to the file, regardless of whether 00158 // it is a POD or a discrete file. 00159 PFSPOD* pPod; // Only valid if file is within a POD; this linkage to the 00160 // POD struct allows for decrementing the reference count 00161 // and closing the FILE associated with the POD if 00162 // necessary. 00163 long offset; // Starting offset of the file within the FILE*; this will 00164 // be either 0 for disk files, or some byte offset for 00165 // POD files. 00166 long size; // Size in bytes of the content 00167 long pos; // Current read position within the stdio FILE*. This will 00168 // be initialized to 'offset' when starting to read the 00169 // content, and incremented with each read operation. 00170 } PODFILE; 00171 00172 00173 // 00174 // Initialize a new pod filesystem. The application "owns" the pod filesystem 00175 // represented by the PFS struct. It must be statically or dynamically 00176 // allocated by the application, and a reference passed in to this function 00177 // before any other operations can be performed. The root argument specifies 00178 // the root folder for the filesystem. This folder will be used as the 00179 // top-level folder when searching for normal disk files to add to the 00180 // filesystem; pinit will recursively process all sub-folders and add all 00181 // normal (non-POD) files into the filesystem. The root folder is also used 00182 // by the paddpodfolder() function as the base from which the relative 00183 // folder is determined. The searchPodFilesFirst argument determines 00184 // the behaviour of popen(), in the case where the same filename exists both 00185 // within a POD and as a normal disk file. If searchPodFilesFirst is true, 00186 // then popen() will open the normal disk file; if it is false, then popen() 00187 // will return the file within the POD. 00188 // 00189 void pinit (PFS* pPfs, const char* root, bool searchPodFilesFirst); 00190 00191 // 00192 // Shut down and clean up a pod filesystem. 00193 // 00194 void pshutdown (PFS* pPfs); 00195 00196 // 00197 // Add a new pod to the existing pod filesystem. The pod filename is relative 00198 // to the root folder for the filesystem 00199 // 00200 void paddpod (PFS *pPfs, const char* filename); 00201 00202 // 00203 // Remove the specified pod from the filesystem. The pod filename is relative 00204 // to the root folder for the filesystem 00205 // 00206 void premovepod (PFS *pPfs, const char* filename); 00207 00208 // 00209 // Add a new folder to an existing pod filesystem. The folder name is relative 00210 // to the root folder for the filesystem, e.g. if the root folder is 00211 // "C:\Fly! II" and the folder argument was "Aircraft", then all pods in the 00212 // "C:\Fly! II\Aircraft" folder would be mounted in the filesystem. 00213 // 00214 void paddpodfolder (PFS* pPfs, const char* folder); 00215 00216 // 00217 // Add a new folder to an existing pod filesystem 00218 // 00219 void padddiskfolder (PFS *pPfs, const char* folder); 00220 00221 // 00222 // This function searches for the specified filename in a POD filesystem. 00223 // Only the cached directories are searched; no actual POD file access 00224 // is done. 00225 // 00226 bool pexists (PFS* pPfs, const char* filename); 00227 00228 // 00229 // This function mimics the stdio function "fopen" and opens a file for read 00230 // access only. The PODFILE* reference returned by this function must be 00231 // passed to the other pod library routines below. Even though the files 00232 // are read-only, they should be closed using pclose() when they are no longer 00233 // needed. 00234 // 00235 PODFILE* popen (PFS* pPfs, const char* filename); 00236 00237 // 00238 // This function mimics the stdio function "fread". 00239 // 00240 size_t pread (void* buffer, size_t size, size_t count, PODFILE* f); 00241 00242 // 00243 // This function mimics the stdio function feof(). It returns true if the 00244 // pod file has encounted an end-of-file condition, and false otherwise. 00245 // 00246 int peof (PODFILE* f); 00247 00248 // 00249 // This function mimics the stdio function fgetc() and returns a single character 00250 // read from the pod file. 00251 // 00252 int pgetc (PODFILE* f); 00253 00254 // 00255 // This function mimics the stdio function fgets(), reading a line of text 00256 // from the pod file up until the next newline character. 00257 // 00258 char* pgets (char* s, int n, PODFILE* f); 00259 00260 // 00261 // This function mimics the stdio function fseek(), repositioning the read 00262 // pointer for the pod file. 00263 // 00264 int pseek (PODFILE* f, long offset, int origin); 00265 00266 // 00267 // This function mimics the stdio function ftell(). 00268 // 00269 long ptell (PODFILE* f); 00270 00271 // 00272 // This function mimics the stdio function frewind(). 00273 // 00274 void prewind (PODFILE* f); 00275 00276 // 00277 // This function mimics the stdio function fclose() and should be used to close 00278 // a pod file when it has been fully processed. 00279 // 00280 void pclose (PODFILE* f); 00281 00282 // 00283 // This function dumps the contents of a pod filesystem to the specified 00284 // stdio FILE* 00285 // 00286 void pfsdump (PFS *pfs, FILE *f); 00287 00288 #endif // POD_H 00289
|
|
Documentation generated by
|