Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

451 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. spcabp.h
  5. Abstract:
  6. Cabinet stuff (file compression/decompression)
  7. Author:
  8. Calin Negreanu (calinn) 27-Apr-2000
  9. Revision History:
  10. Jay Krell (a-JayK) November 2000
  11. ported from windows\winstate\cobra\... to admin\ntsetup\textmode\kernel\spcab.h
  12. --*/
  13. #pragma once
  14. #include "nt.h"
  15. #include "ntrtl.h"
  16. #include "nturtl.h"
  17. #include "windows.h"
  18. #include <stdio.h>
  19. #if defined(ULONG_MAX) && !defined(_INC_LIMITS)
  20. #undef ULONG_MAX
  21. #endif
  22. #include <limits.h>
  23. #if !defined(NUMBER_OF)
  24. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  25. #endif
  26. #if !defined(MAXDWORD)
  27. #define MAXDWORD (~(DWORD)0)
  28. #endif
  29. #define MAX_WCHAR_PATH 260
  30. void SpDebugMessage(int level, const char* string);
  31. #define DEBUGMSG(x) (SpDebugMessage(x))
  32. #define DBG_ERROR /* nothing */
  33. #include "spcab.h"
  34. #include "fdi.h"
  35. #include "fci.h"
  36. //
  37. // This work was not quite finished, and it turns out for now (November 26, 2000),
  38. // we don't need it.
  39. //
  40. #define SETUP_CABP_SMALL_FILE_OPTIMIZATION 0
  41. #if SETUP_CABP_SMALL_FILE_OPTIMIZATION
  42. typedef struct _SETUP_CABP_FILE_VTABLE {
  43. /*
  44. read
  45. write
  46. seek
  47. close
  48. */
  49. int x;
  50. } SETUP_CABP_FILE_VTABLE, *PSETUP_CABP_FILE_VTABLE;
  51. typedef struct _SETUP_CABP_NT_FILE_DATA {
  52. HANDLE NtHandle;
  53. } SETUP_CABP_NT_FILE_DATA;
  54. typedef struct _SETUP_CABP_SMALL_FILE_CACHE_ENTRY_KEY {
  55. UNICODE_STRING Path;
  56. } SETUP_CABP_SMALL_FILE_CACHE_ENTRY_KEY, *PSETUP_CABP_SMALL_FILE_CACHE_ENTRY_KEY;
  57. typedef struct _SETUP_CABP_SMALL_FILE_CACHE_DATA {
  58. UCHAR Buffer[100];
  59. LONG OpenCount;
  60. ULONG Access;
  61. ULONG Share;
  62. LONG Size;
  63. } SETUP_CABP_SMALL_FILE_CACHE_ENTRY, *PSETUP_CABP_SMALL_FILE_CACHE_ENTRY;
  64. typedef struct _SETUP_CABP_SMALL_FILE_CACHE_ENTRY {
  65. SETUP_CABP_SMALL_FILE_CACHE_KEY Key; // This must be first.
  66. SETUP_CABP_SMALL_FILE_CACHE_DATA Data
  67. } SETUP_CABP_SMALL_FILE_CACHE_ENTRY, *PSETUP_CABP_SMALL_FILE_CACHE_ENTRY;
  68. typedef struct _SETUP_CABP_SMALL_FILE_OPENED_DATA {
  69. PSETUP_CABP_SMALL_FILE_CACHE_ENTRY CacheEntry;
  70. LONG SeekPointer;
  71. ULONG Access;
  72. ULONG Share;
  73. } SETUP_CABP_SMALL_FILE_OPENED_DATA, *PSETUP_CABP_SMALL_FILE_OPENED_DATA;
  74. //
  75. // returns either STATUS_SUCCESS or STATUS_SHARING_VIOLATION
  76. // or maybe STATUS_ACCESS_DENIED in the future
  77. //
  78. NTSTATUS
  79. SpAccessCheck(
  80. PSETUP_CABP_SMALL_FILE_CACHE_ENTRY CacheEntry,
  81. ACCESS_MASK Access,
  82. ULONG Share
  83. );
  84. typedef union _SETUP_CABP_FILE_DATA {
  85. #if SETUP_CABP_SMALL_FILE_OPTIMIZATION
  86. SETUP_CABP_SMALL_FILE_OPENED_DATA Small;
  87. #endif
  88. SETUP_CABP_NT_FILE_DATA Nt;
  89. } SETUP_CABP_FILE_DATA, *PSETUP_CABP_FILE_DATA;
  90. typedef struct _SETUP_CABP_FILE_WITH_VTABLE {
  91. PSETUP_CABP_FILE_VTABLE VTable;
  92. SETUP_CABP_FILE_DATA Data;
  93. } SETUP_CABP_FILE_WITH_VTABLE, *PSETUP_CABP_FILE_WITH_VTABLE;
  94. #ifndef KERNELMODE
  95. typedef FAST_MUTEX SETUP_CABP_LOCK;
  96. #define SpInitializeLock ExInitializeFastMutex
  97. #define SpAcquireLock ExAcquireFastMutex
  98. #define SpReleaseLock ExReleaseFastMutex
  99. #define SpDeleteLock /* nothing */
  100. #else
  101. typedef RTL_CRITICAL_SECTION SETUP_CABP_LOCK;
  102. #define SpInitializeLock RtlInitializeCriticalSection
  103. #define SpAcquireLock RtlEnterCriticalSection
  104. #define SpReleaseLock RtlLeaveCriticalSection
  105. #define SpDeleteLock RtlDeleteCriticalSection
  106. #endif
  107. typedef struct _SETUP_CABP_SMALL_FILE_CACHE {
  108. RTL_AVL_TABLE Table;
  109. SETUP_CABP_LOCK Lock;
  110. } SETUP_CABP_SMALL_FILE_CACHE;
  111. extern SETUP_CABP_SMALL_FILE_CACHE SpSmallFileCache;
  112. extern const SETUP_CABP_FILE_VTABLE SpSmallFileVTable;
  113. extern const SETUP_CABP_FILE_VTABLE SpNtFileVTable;
  114. NTSTATUS
  115. SpConvertSmallFileToNtFile(
  116. ...
  117. );
  118. #endif
  119. BOOL
  120. SpIsStatusFileNotFoundEtc(
  121. NTSTATUS Status
  122. );
  123. VOID
  124. SpCloseHandle(
  125. HANDLE* HandlePointer
  126. );
  127. VOID
  128. SpFree(
  129. PVOID* PointerPointer
  130. );
  131. #if SETUP_CABP_SMALL_FILE_OPTIMIZATION
  132. VOID
  133. SpFreeSmallFileCacheEntry(
  134. PSETUP_CABP_SMALL_FILE_CACHE_ENTRY* SmallFileCacheEntryPointerPointer
  135. );
  136. NTSTATUS
  137. SpOpenFile(
  138. UNICODE_STRING Path,
  139. ULONG Access,
  140. ULONG Share,
  141. ULONG OpenOrCreate,
  142. PSETUP_CABP_FILE_WITH_VTABLE* FileOut
  143. );
  144. #endif
  145. // from windows\winstate\...\cablib.c
  146. typedef struct _FCI_CAB_HANDLE {
  147. ANSI_STRING PathA;
  148. ANSI_STRING FileFormatA;
  149. ANSI_STRING DiskFormatA;
  150. UNICODE_STRING PathW;
  151. UNICODE_STRING FileFormatW;
  152. UNICODE_STRING DiskFormatW;
  153. PCABGETCABINETNAMESA GetCabinetNamesA;
  154. PCABGETCABINETNAMESW GetCabinetNamesW;
  155. HFCI FciHandle;
  156. ERF FciErrorStruct;
  157. CCAB FciCabParams;
  158. UINT FileCount;
  159. UINT CabCount;
  160. LONGLONG FileSize;
  161. LONGLONG CompressedSize;
  162. LARGE_INTEGER StartTime;
  163. ULONG SmallFileSize;
  164. TCOMP CompressionType;
  165. TCOMP SmallFileCompressionType;
  166. }
  167. FCI_CAB_HANDLE , *PFCI_CAB_HANDLE,
  168. FCI_CAB_HANDLEA, *PFCI_CAB_HANDLEA,
  169. FCI_CAB_HANDLEW, *PFCI_CAB_HANDLEW
  170. ;
  171. // from windows\winstate\...\cablib.c
  172. typedef struct {
  173. ANSI_STRING PathA;
  174. ANSI_STRING FileA;
  175. UNICODE_STRING PathW;
  176. UNICODE_STRING FileW;
  177. HFDI FdiHandle;
  178. ERF FdiErrorStruct;
  179. FDICABINETINFO FdiCabinetInfo;
  180. PVOID Gauge;
  181. }
  182. FDI_CAB_HANDLE , *PFDI_CAB_HANDLE ,
  183. FDI_CAB_HANDLEA, *PFDI_CAB_HANDLEA,
  184. FDI_CAB_HANDLEW, *PFDI_CAB_HANDLEW
  185. ;
  186. // from windows\winstate\...\cablib.c
  187. typedef struct {
  188. ANSI_STRING ExtractPathA;
  189. UNICODE_STRING ExtractPathW;
  190. PCABNOTIFICATIONA NotificationA;
  191. PCABNOTIFICATIONW NotificationW;
  192. }
  193. CAB_DATA , *PCAB_DATA ,
  194. CAB_DATAA, *PCAB_DATAA,
  195. CAB_DATAW, *PCAB_DATAW
  196. ;
  197. // from windows\winstate\...\cablib.c
  198. INT
  199. DIAMONDAPI
  200. pCabFilePlacedW(
  201. IN PCCAB FciCabParams,
  202. IN PSTR FileName,
  203. IN LONG FileSize,
  204. IN BOOL Continuation,
  205. IN PVOID Context
  206. );
  207. // from windows\winstate\...\cablib.c
  208. PVOID
  209. DIAMONDAPI
  210. pCabAlloc (
  211. IN ULONG Size
  212. );
  213. // from windows\winstate\...\cablib.c
  214. VOID
  215. DIAMONDAPI
  216. pCabFree (
  217. IN PVOID Memory
  218. );
  219. // from windows\winstate\...\cablib.c
  220. INT_PTR
  221. DIAMONDAPI
  222. pCabOpenA (
  223. IN PSTR FileName,
  224. IN INT oFlag,
  225. IN INT pMode,
  226. OUT PINT Error,
  227. IN PVOID Context
  228. );
  229. // from windows\winstate\...\cablib.c
  230. INT_PTR
  231. DIAMONDAPI
  232. pCabOpen1A (
  233. IN PSTR FileName,
  234. IN INT oFlag,
  235. IN INT pMode
  236. );
  237. // from windows\winstate\...\cablib.c
  238. UINT
  239. DIAMONDAPI
  240. pCabRead (
  241. IN INT_PTR FileHandle,
  242. IN PVOID Buffer,
  243. IN UINT Size,
  244. OUT PINT Error,
  245. IN PVOID Context
  246. );
  247. // from windows\winstate\...\cablib.c
  248. UINT
  249. DIAMONDAPI
  250. pCabRead1 (
  251. IN INT_PTR FileHandle,
  252. IN PVOID Buffer,
  253. IN UINT Size
  254. );
  255. // from windows\winstate\...\cablib.c
  256. UINT
  257. DIAMONDAPI
  258. pCabWrite (
  259. IN INT_PTR FileHandle,
  260. IN PVOID Buffer,
  261. IN UINT Size,
  262. OUT PINT Error,
  263. IN PVOID Context
  264. );
  265. // from windows\winstate\...\cablib.c
  266. UINT
  267. DIAMONDAPI
  268. pCabWrite1 (
  269. IN INT_PTR FileHandle,
  270. IN PVOID Buffer,
  271. IN UINT Size
  272. );
  273. // from windows\winstate\...\cablib.c
  274. INT
  275. DIAMONDAPI
  276. pCabClose (
  277. IN INT_PTR FileHandle,
  278. OUT PINT Error,
  279. IN PVOID Context
  280. );
  281. // from windows\winstate\...\cablib.c
  282. INT
  283. DIAMONDAPI
  284. pCabClose1 (
  285. IN INT_PTR FileHandle
  286. );
  287. // from windows\winstate\...\cablib.c
  288. LONG
  289. DIAMONDAPI
  290. pCabSeek (
  291. IN INT_PTR FileHandle,
  292. IN LONG Distance,
  293. IN INT SeekType,
  294. OUT PINT Error,
  295. IN PVOID Context
  296. );
  297. // from windows\winstate\...\cablib.c
  298. LONG
  299. DIAMONDAPI
  300. pCabSeek1 (
  301. IN INT_PTR FileHandle,
  302. IN LONG Distance,
  303. IN INT SeekType
  304. );
  305. // from windows\winstate\...\cablib.c
  306. INT
  307. DIAMONDAPI
  308. pCabDeleteA (
  309. IN PSTR FileName,
  310. OUT PINT Error,
  311. IN PVOID Context
  312. );
  313. // from windows\winstate\...\cablib.c
  314. BOOL
  315. DIAMONDAPI
  316. pCabGetTempFileA (
  317. OUT PSTR FileName,
  318. IN INT FileNameLen,
  319. IN PVOID Context
  320. );
  321. // from windows\winstate\...\cablib.c
  322. BOOL
  323. DIAMONDAPI
  324. pCabGetNextCabinetA (
  325. IN PCCAB FciCabParams,
  326. IN ULONG PrevCabinetSize,
  327. IN PVOID Context
  328. );
  329. // from windows\winstate\...\cablib.c
  330. BOOL
  331. DIAMONDAPI
  332. pCabGetNextCabinetW (
  333. IN PCCAB FciCabParams,
  334. IN ULONG PrevCabinetSize,
  335. IN PVOID Context
  336. );
  337. // from windows\winstate\...\cablib.c
  338. LONG
  339. DIAMONDAPI
  340. pCabStatusA (
  341. IN UINT StatusType,
  342. IN ULONG Size1,
  343. IN ULONG Size2,
  344. IN PVOID Context
  345. );
  346. // from windows\winstate\...\cablib.c
  347. LONG
  348. DIAMONDAPI
  349. pCabStatusW (
  350. IN UINT StatusType,
  351. IN ULONG Size1,
  352. IN ULONG Size2,
  353. IN PVOID Context
  354. );
  355. // from windows\winstate\...\cablib.c
  356. INT_PTR
  357. DIAMONDAPI
  358. pCabGetOpenInfoA (
  359. IN PSTR FileName,
  360. OUT USHORT *Date,
  361. OUT USHORT *Time,
  362. OUT USHORT *Attributes,
  363. OUT PINT Error,
  364. IN PVOID Context
  365. );
  366. // from windows\winstate\...\cablib.c
  367. INT_PTR
  368. DIAMONDAPI
  369. pCabNotification (
  370. IN FDINOTIFICATIONTYPE FdiNotificationType,
  371. IN OUT PFDINOTIFICATION FdiNotification
  372. );
  373. typedef const unsigned char* PCBYTE;
  374. INT
  375. DIAMONDAPI
  376. pCabFilePlacedA(
  377. IN PCCAB FciCabParams,
  378. IN PSTR FileName,
  379. IN LONG FileSize,
  380. IN BOOL Continuation,
  381. IN PVOID Context
  382. );