goblib.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*****************************************
  2. *
  3. * GOB File System
  4. *
  5. * Here's what Merriam-Webster says about "gob": --Chuck
  6. * Entry: gob
  7. * Function: noun
  8. * Etymology: Middle English gobbe, from Middle French gobe large piece of food,
  9. * back-formation from gobet
  10. * Date: 14th century
  11. * 1 : LUMP
  12. * 2 : a large amount -- usually used in plural <gobs of money>
  13. *
  14. * Purpose: Provide fast, efficient disk access on a variety of platforms.
  15. *
  16. * Implementation:
  17. * The GOB system maintains two files -- GOB and GFC. The GOB file is actually
  18. * an archive of many files split into variable size, compressed blocks. The GFC,
  19. * GOB File Control, contains 3 tables -- a block table, basic file table, and
  20. * extended file table. The block table is analogous to a DOS FAT. The basic
  21. * file table contains a minimal set of file information to handle basic reading
  22. * tasks. The extended file table is optionally loaded and contains additional
  23. * file information. File names are case insensitive.
  24. *
  25. * Files can be read in a normal manner. Open, read, seek and close
  26. * operations are all provided. Files can only be written in a single
  27. * contiguous chunk of blocks at the end of an archive. Reads are processed
  28. * through a configurable number of read ahead buffers to in an effort to
  29. * minimize both reads and seeks. Other operations including delete, verify,
  30. * access, and get size are also supported on files inside an archive.
  31. *
  32. * The system supports read profiling. By supplying a file read callback
  33. * function, the library will output the block number of each read. This can
  34. * be used rearrange block in the archive to minimize seek times. The
  35. * GOBRearrange sorts files in an archive.
  36. *
  37. * Supports block based caching. Primarily aimed at caching files off a DVD/CD
  38. * to a faster hard disk.
  39. *
  40. * Future Work:
  41. *
  42. * Dependencies: vvInt, snprintf, zlib
  43. * Owner: Chris McEvoy
  44. * History:
  45. * 09/23/2001 Original version
  46. * 10/28/2002 Merged into vvtech
  47. *
  48. * Copyright (C) 2002, Vicarious Visions, Inc. All Rights Reserved.
  49. *
  50. * UNPUBLISHED -- Rights reserved under the copyright laws of the
  51. * United States. Use of a copyright notice is precautionary only and
  52. * does not imply publication or disclosure.
  53. *
  54. * THIS DOCUMENTATION CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION
  55. * OF VICARIOUS VISIONS, INC. ANY DUPLICATION, MODIFICATION,
  56. * DISTRIBUTION, OR DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR
  57. * EXPRESS WRITTEN PERMISSION OF VICARIOUS VISIONS, INC.
  58. *
  59. *****************************************/
  60. /*
  61. This is an unofficial branch of GOB, for Jedi Academy
  62. Maintainer: Brian Osman
  63. */
  64. #ifndef GOBLIB_H__
  65. #define GOBLIB_H__
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. #define GOB_MAGIC_IDENTIFIER 0x8008
  70. #define GOB_MAX_FILE_NAME_LEN 96
  71. #define GOB_MAX_OPEN_FILES 16
  72. #define GOB_MAX_CODECS 2
  73. #define GOB_INFINITE_RATIO 1000
  74. #define GOB_READ_RETRYS 3
  75. #define GOB_MAX_FILES (16*1024)
  76. #define GOB_MAX_BLOCKS 32767
  77. #define GOB_BLOCK_SIZE (64*1024)
  78. #define GOB_BLOCK_ALIGNMENT 2048
  79. #define GOB_MEM_ALIGNMENT 64
  80. #define GOB_COMPRESS_OVERHEAD 1024
  81. #define GOB_INVALID_SIZE 0xFFFFFFFF
  82. #define GOB_INVALID_BLOCK 0xFFFFFFFF
  83. #define GOB_TRUE 1
  84. #define GOB_FALSE 0
  85. #define GOBERR_OK 0
  86. #define GOBERR_NOT_INIT 1
  87. #define GOBERR_FILE_NOT_FOUND 2
  88. #define GOBERR_FILE_READ 3
  89. #define GOBERR_FILE_WRITE 4
  90. #define GOBERR_NO_MEMORY 5
  91. #define GOBERR_ALREADY_INIT 6
  92. #define GOBERR_ALREADY_OPEN 7
  93. #define GOBERR_INVALID_ACCESS 8
  94. #define GOBERR_NOT_GOB_FILE 9
  95. #define GOBERR_NOT_OPEN 10
  96. #define GOBERR_CANNOT_CREATE 11
  97. #define GOBERR_TOO_MANY_OPEN 12
  98. #define GOBERR_INVALID_SEEK 13
  99. #define GOBERR_TOO_MANY_FILES 14
  100. #define GOBERR_FILE_RENAME 15
  101. #define GOBERR_PROFILE_OFF 16
  102. #define GOBERR_PROFILE_ON 17
  103. #define GOBERR_NO_EXTENDED 18
  104. #define GOBERR_DUP_HASH 19
  105. #define GOBERR_TOO_MANY_BLOCKS 20
  106. #define GOBERR_COMPRESS_FAIL 21
  107. #define GOBERR_NO_SUITABLE_CODEC 22
  108. #define GOBACCESS_READ 0
  109. #define GOBACCESS_WRITE 1
  110. #define GOBACCESS_RW 2
  111. #define GOBSEEK_START 0
  112. #define GOBSEEK_CURRENT 1
  113. #define GOBSEEK_END 2
  114. #define GOB_CODEC_MASK(n) ((GOBUInt32)(1u<<(n)))
  115. #define GOB_CODEC_MASK_ANY ((GOBUInt32)(-1))
  116. #define GOBMARKER_STARTBLOCK ('L' | 'B' << 8 | 'T' << 16 | 'S' << 24)
  117. #define GOBMARKER_ENDBLOCK ('L' | 'B' << 8 | 'N' << 16 | 'E' << 24)
  118. typedef int int32;
  119. typedef unsigned int uint32;
  120. //#define bool int
  121. //#define false 0
  122. //#define true 1
  123. typedef unsigned long ulong;
  124. typedef unsigned char byte;
  125. typedef int32 GOBInt32;
  126. typedef uint32 GOBUInt32;
  127. typedef char GOBChar;
  128. typedef bool GOBBool;
  129. typedef int32 GOBError;
  130. typedef int32 GOBSeekType;
  131. typedef int32 GOBHandle;
  132. typedef int32 GOBAccessType;
  133. typedef void* GOBFSHandle;
  134. typedef void GOBVoid;
  135. typedef GOBFSHandle (*GOBFileSysOpenFunc)(GOBChar*, GOBAccessType);
  136. typedef GOBBool (*GOBFileSysCloseFunc)(GOBFSHandle*);
  137. typedef GOBInt32 (*GOBFileSysReadFunc)(GOBFSHandle, GOBVoid*, GOBInt32);
  138. typedef GOBInt32 (*GOBFileSysWriteFunc)(GOBFSHandle, GOBVoid*, GOBInt32);
  139. typedef GOBInt32 (*GOBFileSysSeekFunc)(GOBFSHandle, GOBInt32, GOBSeekType);
  140. typedef GOBInt32 (*GOBFileSysRenameFunc)(GOBChar*, GOBChar*);
  141. typedef GOBVoid* (*GOBMemAllocFunc)(GOBUInt32);
  142. typedef GOBVoid (*GOBMemFreeFunc)(GOBVoid*);
  143. typedef GOBInt32 (*GOBCompressFunc)(GOBVoid*, GOBUInt32, GOBVoid*, GOBUInt32*);
  144. typedef GOBInt32 (*GOBDecompressFunc)(GOBVoid*, GOBUInt32, GOBVoid*, GOBUInt32*);
  145. typedef GOBBool (*GOBCacheFileOpenFunc)(GOBUInt32);
  146. typedef GOBBool (*GOBCacheFileCloseFunc)(GOBVoid);
  147. typedef GOBInt32 (*GOBCacheFileReadFunc)(GOBVoid*, GOBInt32);
  148. typedef GOBInt32 (*GOBCacheFileWriteFunc)(GOBVoid*, GOBInt32);
  149. typedef GOBInt32 (*GOBCacheFileSeekFunc)(GOBInt32);
  150. struct GOBBlockTableEntry
  151. {
  152. GOBUInt32 size; // compressed size
  153. GOBUInt32 offset;
  154. GOBUInt32 next;
  155. };
  156. struct GOBFileTableBasicEntry
  157. {
  158. GOBUInt32 hash;
  159. GOBUInt32 size; // decompressed size
  160. GOBUInt32 block;
  161. };
  162. struct GOBFileTableExtEntry
  163. {
  164. GOBChar name[GOB_MAX_FILE_NAME_LEN];
  165. GOBUInt32 crc;
  166. GOBUInt32 time;
  167. };
  168. struct GOBMemoryFuncSet
  169. {
  170. GOBMemAllocFunc alloc;
  171. GOBMemFreeFunc free;
  172. };
  173. struct GOBSingleCodecDesc
  174. {
  175. GOBChar tag;
  176. GOBInt32 max_ratio;
  177. GOBCompressFunc compress;
  178. GOBDecompressFunc decompress;
  179. };
  180. struct GOBCodecFuncSet
  181. {
  182. GOBInt32 codecs;
  183. struct GOBSingleCodecDesc codec[GOB_MAX_CODECS];
  184. };
  185. struct GOBFileSysFuncSet
  186. {
  187. GOBFileSysOpenFunc open;
  188. GOBFileSysCloseFunc close;
  189. GOBFileSysReadFunc read;
  190. GOBFileSysWriteFunc write;
  191. GOBFileSysSeekFunc seek;
  192. };
  193. struct GOBCacheFileFuncSet
  194. {
  195. GOBCacheFileOpenFunc open;
  196. GOBCacheFileCloseFunc close;
  197. GOBCacheFileReadFunc read;
  198. GOBCacheFileWriteFunc write;
  199. GOBCacheFileSeekFunc seek;
  200. };
  201. struct GOBReadStats
  202. {
  203. GOBUInt32 bufferUsed;
  204. GOBUInt32 bytesRead;
  205. GOBUInt32 cacheBytesRead;
  206. GOBUInt32 cacheBytesWrite;
  207. GOBUInt32 totalSeeks;
  208. GOBUInt32 farSeeks;
  209. GOBUInt32 filesOpened;
  210. };
  211. extern GOBError GOBInit(struct GOBMemoryFuncSet* mem,
  212. struct GOBFileSysFuncSet* file,
  213. struct GOBCodecFuncSet* codec,
  214. struct GOBCacheFileFuncSet* cache);
  215. extern GOBError GOBShutdown(GOBVoid);
  216. extern GOBError GOBArchiveCreate(const GOBChar* file);
  217. extern GOBError GOBArchiveOpen(const GOBChar* file, GOBAccessType atype,
  218. GOBBool extended, GOBBool safe);
  219. extern GOBError GOBArchiveClose(GOBVoid);
  220. extern GOBError GOBArchiveCheckMarkers(GOBVoid);
  221. extern GOBError GOBOpen(GOBChar* file, GOBHandle* handle);
  222. extern GOBError GOBOpenCode(GOBInt32 code, GOBHandle* handle);
  223. extern GOBError GOBClose(GOBHandle handle);
  224. extern GOBUInt32 GOBRead(GOBVoid* buffer, GOBUInt32 size, GOBHandle handle);
  225. extern GOBError GOBSeek(GOBHandle handle, GOBUInt32 offset, GOBSeekType type, GOBUInt32* pos);
  226. extern GOBError GOBWrite(GOBVoid* buffer, GOBUInt32 size, GOBUInt32 mtime, const GOBChar* file, GOBUInt32 codec_mask);
  227. extern GOBError GOBDelete(const GOBChar* file);
  228. extern GOBError GOBRearrange(const GOBChar* file, const GOBUInt32* xlat, GOBFileSysRenameFunc _rename);
  229. extern GOBError GOBVerify(const GOBChar* file, GOBBool* status);
  230. extern GOBError GOBGetSize(const GOBChar* file, GOBUInt32* decomp, GOBUInt32* comp, GOBUInt32* slack);
  231. extern GOBError GOBGetTime(const GOBChar* file, GOBUInt32* time);
  232. extern GOBError GOBGetCRC(const GOBChar* file, GOBUInt32* crc);
  233. extern GOBError GOBAccess(const GOBChar* file, GOBBool* status);
  234. extern GOBInt32 GOBGetFileCode(const GOBChar* file);
  235. extern GOBError GOBGetFileTables(struct GOBFileTableBasicEntry** basic, struct GOBFileTableExtEntry** ext);
  236. extern GOBError GOBGetBlockTable(struct GOBBlockTableEntry** table, GOBUInt32* num);
  237. extern GOBUInt32 GOBGetSlack(GOBUInt32 x);
  238. extern GOBError GOBSetCacheSize(GOBUInt32 num);
  239. extern GOBError GOBSetReadBufferSize(GOBUInt32 size);
  240. extern struct GOBReadStats GOBGetReadStats(GOBVoid);
  241. typedef GOBVoid (*GOBProfileReadFunc)(GOBUInt32);
  242. struct GOBProfileFuncSet
  243. {
  244. GOBProfileReadFunc read;
  245. };
  246. extern GOBVoid GOBSetProfileFuncs(struct GOBProfileFuncSet* fset);
  247. extern GOBError GOBStartProfile(GOBVoid);
  248. extern GOBError GOBStopProfile(GOBVoid);
  249. #ifdef __cplusplus
  250. } /* extern "C" */
  251. #endif
  252. #endif /* GOBLIB_H__ */