Sync with trunk (r48545)
[reactos.git] / include / psdk / fdi.h
1 /*
2 * Copyright (C) 2002 Patrik Stridvall
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #ifndef __WINE_FDI_H
20 #define __WINE_FDI_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif /* defined(__cplusplus) */
25
26 #include <pshpack4.h>
27
28 #ifndef INCLUDED_TYPES_FCI_FDI
29 #define INCLUDED_TYPES_FCI_FDI 1
30
31 /***********************************************************************
32 * Common FCI/TDI declarations
33 */
34
35 typedef ULONG CHECKSUM;
36
37 typedef ULONG UOFF;
38 typedef ULONG COFF;
39
40 /**********************************************************************/
41
42 typedef struct {
43 int erfOper; /* FCI/FDI error code - see {FCI,FDI}ERROR_XXX for details. */
44 int erfType; /* Optional error value filled in by FCI/FDI. */
45 BOOL fError; /* TRUE => error present */
46 } ERF, *PERF;
47
48 /**********************************************************************/
49
50 #define CB_MAX_CHUNK 32768U
51 #define CB_MAX_DISK 0x7fffffffL
52 #define CB_MAX_FILENAME 256
53 #define CB_MAX_CABINET_NAME 256
54 #define CB_MAX_CAB_PATH 256
55 #define CB_MAX_DISK_NAME 256
56
57 /**********************************************************************/
58
59 typedef unsigned short TCOMP;
60
61 #define tcompMASK_TYPE 0x000F /* Mask for compression type */
62 #define tcompTYPE_NONE 0x0000 /* No compression */
63 #define tcompTYPE_MSZIP 0x0001 /* MSZIP */
64 #define tcompTYPE_QUANTUM 0x0002 /* Quantum */
65 #define tcompTYPE_LZX 0x0003 /* LZX */
66 #define tcompBAD 0x000F /* Unspecified compression type */
67
68 #define tcompMASK_LZX_WINDOW 0x1F00 /* Mask for LZX Compression Memory */
69 #define tcompLZX_WINDOW_LO 0x0F00 /* Lowest LZX Memory (15) */
70 #define tcompLZX_WINDOW_HI 0x1500 /* Highest LZX Memory (21) */
71 #define tcompSHIFT_LZX_WINDOW 8 /* Amount to shift over to get int */
72
73 #define tcompMASK_QUANTUM_LEVEL 0x00F0 /* Mask for Quantum Compression Level */
74 #define tcompQUANTUM_LEVEL_LO 0x0010 /* Lowest Quantum Level (1) */
75 #define tcompQUANTUM_LEVEL_HI 0x0070 /* Highest Quantum Level (7) */
76 #define tcompSHIFT_QUANTUM_LEVEL 4 /* Amount to shift over to get int */
77
78 #define tcompMASK_QUANTUM_MEM 0x1F00 /* Mask for Quantum Compression Memory */
79 #define tcompQUANTUM_MEM_LO 0x0A00 /* Lowest Quantum Memory (10) */
80 #define tcompQUANTUM_MEM_HI 0x1500 /* Highest Quantum Memory (21) */
81 #define tcompSHIFT_QUANTUM_MEM 8 /* Amount to shift over to get int */
82
83 #define tcompMASK_RESERVED 0xE000 /* Reserved bits (high 3 bits) */
84
85 /**********************************************************************/
86
87 #define CompressionTypeFromTCOMP(tc) \
88 ((tc) & tcompMASK_TYPE)
89
90 #define CompressionLevelFromTCOMP(tc) \
91 (((tc) & tcompMASK_QUANTUM_LEVEL) >> tcompSHIFT_QUANTUM_LEVEL)
92
93 #define CompressionMemoryFromTCOMP(tc) \
94 (((tc) & tcompMASK_QUANTUM_MEM) >> tcompSHIFT_QUANTUM_MEM)
95
96 #define TCOMPfromTypeLevelMemory(t, l, m) \
97 (((m) << tcompSHIFT_QUANTUM_MEM ) | \
98 ((l) << tcompSHIFT_QUANTUM_LEVEL) | \
99 ( t ))
100
101 #define LZXCompressionWindowFromTCOMP(tc) \
102 (((tc) & tcompMASK_LZX_WINDOW) >> tcompSHIFT_LZX_WINDOW)
103
104 #define TCOMPfromLZXWindow(w) \
105 (((w) << tcompSHIFT_LZX_WINDOW) | \
106 ( tcompTYPE_LZX ))
107
108 #endif /* !defined(INCLUDED_TYPES_FCI_FDI) */
109
110 /***********************************************************************
111 * FDI declarations
112 */
113
114 typedef enum {
115 FDIERROR_NONE,
116 FDIERROR_CABINET_NOT_FOUND,
117 FDIERROR_NOT_A_CABINET,
118 FDIERROR_UNKNOWN_CABINET_VERSION,
119 FDIERROR_CORRUPT_CABINET,
120 FDIERROR_ALLOC_FAIL,
121 FDIERROR_BAD_COMPR_TYPE,
122 FDIERROR_MDI_FAIL,
123 FDIERROR_TARGET_FILE,
124 FDIERROR_RESERVE_MISMATCH,
125 FDIERROR_WRONG_CABINET,
126 FDIERROR_USER_ABORT,
127 } FDIERROR;
128
129 /**********************************************************************/
130
131 #ifndef _A_NAME_IS_UTF
132 #define _A_NAME_IS_UTF 0x80
133 #endif
134
135 #ifndef _A_EXEC
136 #define _A_EXEC 0x40
137 #endif
138
139 /**********************************************************************/
140
141 typedef void *HFDI;
142
143 /**********************************************************************/
144
145 typedef struct {
146 LONG cbCabinet; /* Total length of cabinet file */
147 USHORT cFolders; /* Count of folders in cabinet */
148 USHORT cFiles; /* Count of files in cabinet */
149 USHORT setID; /* Cabinet set ID */
150 USHORT iCabinet; /* Cabinet number in set (0 based) */
151 BOOL fReserve; /* TRUE => RESERVE present in cabinet */
152 BOOL hasprev; /* TRUE => Cabinet is chained prev */
153 BOOL hasnext; /* TRUE => Cabinet is chained next */
154 } FDICABINETINFO, *PFDICABINETINFO; /* pfdici */
155
156 /**********************************************************************/
157
158 typedef enum {
159 fdidtNEW_CABINET, /* New cabinet */
160 fdidtNEW_FOLDER, /* New folder */
161 fdidtDECRYPT, /* Decrypt a data block */
162 } FDIDECRYPTTYPE;
163
164 /**********************************************************************/
165
166 typedef struct {
167 FDIDECRYPTTYPE fdidt; /* Command type (selects union below) */
168
169 void *pvUser; /* Decryption context */
170
171 union {
172 struct { /* fdidtNEW_CABINET */
173 void *pHeaderReserve; /* RESERVE section from CFHEADER */
174 USHORT cbHeaderReserve; /* Size of pHeaderReserve */
175 USHORT setID; /* Cabinet set ID */
176 int iCabinet; /* Cabinet number in set (0 based) */
177 } cabinet;
178
179 struct { /* fdidtNEW_FOLDER */
180 void *pFolderReserve; /* RESERVE section from CFFOLDER */
181 USHORT cbFolderReserve; /* Size of pFolderReserve */
182 USHORT iFolder; /* Folder number in cabinet (0 based) */
183 } folder;
184
185 struct { /* fdidtDECRYPT */
186 void *pDataReserve; /* RESERVE section from CFDATA */
187 USHORT cbDataReserve; /* Size of pDataReserve */
188 void *pbData; /* Data buffer */
189 USHORT cbData; /* Size of data buffer */
190 BOOL fSplit; /* TRUE if this is a split data block */
191 USHORT cbPartial; /* 0 if this is not a split block, or
192 * the first piece of a split block;
193 * Greater than 0 if this is the
194 * second piece of a split block.
195 */
196 } decrypt;
197 } DUMMYUNIONNAME;
198 } FDIDECRYPT, *PFDIDECRYPT;
199
200 /**********************************************************************/
201
202 typedef void * (__cdecl *PFNALLOC)(ULONG cb);
203 #define FNALLOC(fn) void * __cdecl fn(ULONG cb)
204
205 typedef void (__cdecl *PFNFREE)(void *pv);
206 #define FNFREE(fn) void __cdecl fn(void *pv)
207
208 typedef INT_PTR (__cdecl *PFNOPEN) (char *pszFile, int oflag, int pmode);
209 #define FNOPEN(fn) INT_PTR __cdecl fn(char *pszFile, int oflag, int pmode)
210
211 typedef UINT (__cdecl *PFNREAD) (INT_PTR hf, void *pv, UINT cb);
212 #define FNREAD(fn) UINT __cdecl fn(INT_PTR hf, void *pv, UINT cb)
213
214 typedef UINT (__cdecl *PFNWRITE)(INT_PTR hf, void *pv, UINT cb);
215 #define FNWRITE(fn) UINT __cdecl fn(INT_PTR hf, void *pv, UINT cb)
216
217 typedef int (__cdecl *PFNCLOSE)(INT_PTR hf);
218 #define FNCLOSE(fn) int __cdecl fn(INT_PTR hf)
219
220 typedef LONG (__cdecl *PFNSEEK) (INT_PTR hf, LONG dist, int seektype);
221 #define FNSEEK(fn) LONG __cdecl fn(INT_PTR hf, LONG dist, int seektype)
222
223 typedef int (__cdecl *PFNFDIDECRYPT)(PFDIDECRYPT pfdid);
224 #define FNFDIDECRYPT(fn) int __cdecl fn(PFDIDECRYPT pfdid)
225
226 typedef struct {
227 LONG cb;
228 char *psz1;
229 char *psz2;
230 char *psz3; /* Points to a 256 character buffer */
231 void *pv; /* Value for client */
232
233 INT_PTR hf;
234
235 USHORT date;
236 USHORT time;
237 USHORT attribs;
238
239 USHORT setID; /* Cabinet set ID */
240 USHORT iCabinet; /* Cabinet number (0-based) */
241 USHORT iFolder; /* Folder number (0-based) */
242
243 FDIERROR fdie;
244 } FDINOTIFICATION, *PFDINOTIFICATION;
245
246 typedef enum {
247 fdintCABINET_INFO, /* General information about cabinet */
248 fdintPARTIAL_FILE, /* First file in cabinet is continuation */
249 fdintCOPY_FILE, /* File to be copied */
250 fdintCLOSE_FILE_INFO, /* Close the file, set relevant info */
251 fdintNEXT_CABINET, /* File continued to next cabinet */
252 fdintENUMERATE, /* Enumeration status */
253 } FDINOTIFICATIONTYPE;
254
255 typedef INT_PTR (__cdecl *PFNFDINOTIFY)(FDINOTIFICATIONTYPE fdint,
256 PFDINOTIFICATION pfdin);
257 #define FNFDINOTIFY(fn) INT_PTR __cdecl fn(FDINOTIFICATIONTYPE fdint, \
258 PFDINOTIFICATION pfdin)
259
260 #include <pshpack1.h>
261
262 typedef struct {
263 char ach[2]; /* Set to { '*', '\0' } */
264 LONG cbFile; /* Required spill file size */
265 } FDISPILLFILE, *PFDISPILLFILE;
266
267 #include <poppack.h>
268
269 #define cpuUNKNOWN (-1) /* FDI does detection */
270 #define cpu80286 (0) /* '286 opcodes only */
271 #define cpu80386 (1) /* '386 opcodes used */
272
273 /**********************************************************************/
274
275 HFDI __cdecl FDICreate(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE,
276 PFNCLOSE, PFNSEEK, int, PERF);
277 BOOL __cdecl FDIIsCabinet(HFDI, INT_PTR, PFDICABINETINFO);
278 BOOL __cdecl FDICopy(HFDI, char *, char *, int, PFNFDINOTIFY,
279 PFNFDIDECRYPT, void *pvUser);
280 BOOL __cdecl FDIDestroy(HFDI);
281 BOOL __cdecl FDITruncateCabinet(HFDI, char *, USHORT);
282
283 /**********************************************************************/
284
285 #include <poppack.h>
286
287 #ifdef __cplusplus
288 } /* extern "C" */
289 #endif /* defined(__cplusplus) */
290
291 #endif /* __WINE_FDI_H */