fdi.h 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2002 Patrik Stridvall
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 20 21
 */

#ifndef __WINE_FDI_H
#define __WINE_FDI_H

22 23
#include <basetsd.h>

24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif /* defined(__cplusplus) */

28
#ifndef _WIN64
29
#include <pshpack4.h>
30
#endif
31 32 33 34 35 36 37 38

#ifndef INCLUDED_TYPES_FCI_FDI
#define INCLUDED_TYPES_FCI_FDI 1

/***********************************************************************
 * Common FCI/TDI declarations
 */

39
typedef ULONG CHECKSUM;
40

41 42
typedef ULONG UOFF;
typedef ULONG COFF;
43 44 45 46 47 48 49

/**********************************************************************/

typedef struct {
    int   erfOper;  /* FCI/FDI error code - see {FCI,FDI}ERROR_XXX for details. */
    int   erfType;  /* Optional error value filled in by FCI/FDI. */
    BOOL  fError;   /* TRUE => error present */
50
} ERF, *PERF;
51 52 53 54

/**********************************************************************/

#define CB_MAX_CHUNK         32768U
55
#define CB_MAX_DISK          __MSABI_LONG(0x7fffffff)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
#define CB_MAX_FILENAME      256
#define CB_MAX_CABINET_NAME  256
#define CB_MAX_CAB_PATH      256
#define CB_MAX_DISK_NAME     256

/**********************************************************************/

typedef unsigned short TCOMP;

#define tcompMASK_TYPE          0x000F  /* Mask for compression type */
#define tcompTYPE_NONE          0x0000  /* No compression */
#define tcompTYPE_MSZIP         0x0001  /* MSZIP */
#define tcompTYPE_QUANTUM       0x0002  /* Quantum */
#define tcompTYPE_LZX           0x0003  /* LZX */
#define tcompBAD                0x000F  /* Unspecified compression type */

#define tcompMASK_LZX_WINDOW    0x1F00  /* Mask for LZX Compression Memory */
#define tcompLZX_WINDOW_LO      0x0F00  /* Lowest LZX Memory (15) */
#define tcompLZX_WINDOW_HI      0x1500  /* Highest LZX Memory (21) */
#define tcompSHIFT_LZX_WINDOW        8  /* Amount to shift over to get int */

#define tcompMASK_QUANTUM_LEVEL 0x00F0  /* Mask for Quantum Compression Level */
#define tcompQUANTUM_LEVEL_LO   0x0010  /* Lowest Quantum Level (1) */
#define tcompQUANTUM_LEVEL_HI   0x0070  /* Highest Quantum Level (7) */
#define tcompSHIFT_QUANTUM_LEVEL     4  /* Amount to shift over to get int */

#define tcompMASK_QUANTUM_MEM   0x1F00  /* Mask for Quantum Compression Memory */
#define tcompQUANTUM_MEM_LO     0x0A00  /* Lowest Quantum Memory (10) */
#define tcompQUANTUM_MEM_HI     0x1500  /* Highest Quantum Memory (21) */
#define tcompSHIFT_QUANTUM_MEM       8  /* Amount to shift over to get int */

#define tcompMASK_RESERVED      0xE000  /* Reserved bits (high 3 bits) */

/**********************************************************************/

#define CompressionTypeFromTCOMP(tc) \
    ((tc) & tcompMASK_TYPE)

#define CompressionLevelFromTCOMP(tc) \
    (((tc) & tcompMASK_QUANTUM_LEVEL) >> tcompSHIFT_QUANTUM_LEVEL)

#define CompressionMemoryFromTCOMP(tc) \
    (((tc) & tcompMASK_QUANTUM_MEM) >> tcompSHIFT_QUANTUM_MEM)

#define TCOMPfromTypeLevelMemory(t, l, m) \
    (((m) << tcompSHIFT_QUANTUM_MEM  ) | \
     ((l) << tcompSHIFT_QUANTUM_LEVEL) | \
     ( t                             ))

#define LZXCompressionWindowFromTCOMP(tc) \
    (((tc) & tcompMASK_LZX_WINDOW) >> tcompSHIFT_LZX_WINDOW)

#define TCOMPfromLZXWindow(w) \
    (((w) << tcompSHIFT_LZX_WINDOW) | \
     ( tcompTYPE_LZX              ))

#endif /* !defined(INCLUDED_TYPES_FCI_FDI) */

/***********************************************************************
 * FDI declarations
 */

typedef enum {
    FDIERROR_NONE,
    FDIERROR_CABINET_NOT_FOUND,
    FDIERROR_NOT_A_CABINET,
    FDIERROR_UNKNOWN_CABINET_VERSION,
    FDIERROR_CORRUPT_CABINET,
    FDIERROR_ALLOC_FAIL,
    FDIERROR_BAD_COMPR_TYPE,
    FDIERROR_MDI_FAIL,
    FDIERROR_TARGET_FILE,
    FDIERROR_RESERVE_MISMATCH,
    FDIERROR_WRONG_CABINET,
    FDIERROR_USER_ABORT,
} FDIERROR;

/**********************************************************************/

#ifndef _A_NAME_IS_UTF
#define _A_NAME_IS_UTF  0x80
#endif

#ifndef _A_EXEC
#define _A_EXEC         0x40
#endif

/**********************************************************************/

typedef void *HFDI;

/**********************************************************************/

typedef struct {
150
    LONG    cbCabinet;  /* Total length of cabinet file */
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    USHORT  cFolders;   /* Count of folders in cabinet */
    USHORT  cFiles;     /* Count of files in cabinet */
    USHORT  setID;      /* Cabinet set ID */
    USHORT  iCabinet;   /* Cabinet number in set (0 based) */
    BOOL    fReserve;   /* TRUE => RESERVE present in cabinet */
    BOOL    hasprev;    /* TRUE => Cabinet is chained prev */
    BOOL    hasnext;    /* TRUE => Cabinet is chained next */
} FDICABINETINFO, *PFDICABINETINFO; /* pfdici */

/**********************************************************************/

typedef enum {
    fdidtNEW_CABINET,  /* New cabinet */
    fdidtNEW_FOLDER,   /* New folder */
    fdidtDECRYPT,      /* Decrypt a data block */
} FDIDECRYPTTYPE;

/**********************************************************************/

typedef struct {
    FDIDECRYPTTYPE fdidt; /* Command type (selects union below) */

    void *pvUser; /* Decryption context */

    union {
        struct {                      /* fdidtNEW_CABINET */
	    void   *pHeaderReserve;   /* RESERVE section from CFHEADER */
	    USHORT  cbHeaderReserve;  /* Size of pHeaderReserve */
	    USHORT  setID;            /* Cabinet set ID */
	    int     iCabinet;         /* Cabinet number in set (0 based) */
        } cabinet;

        struct {                      /* fdidtNEW_FOLDER */
	    void   *pFolderReserve;   /* RESERVE section from CFFOLDER */
	    USHORT  cbFolderReserve;  /* Size of pFolderReserve */
	    USHORT  iFolder;          /* Folder number in cabinet (0 based) */
        } folder;

        struct {                      /* fdidtDECRYPT */
	    void   *pDataReserve;     /* RESERVE section from CFDATA */
	    USHORT  cbDataReserve;    /* Size of pDataReserve */
	    void   *pbData;           /* Data buffer */
	    USHORT  cbData;           /* Size of data buffer */
	    BOOL    fSplit;           /* TRUE if this is a split data block */
	    USHORT  cbPartial;        /* 0 if this is not a split block, or
				       * the first piece of a split block;
                                       * Greater than 0 if this is the
                                       * second piece of a split block.
                                       */
        } decrypt;
    } DUMMYUNIONNAME;
} FDIDECRYPT, *PFDIDECRYPT;

/**********************************************************************/

typedef void * (__cdecl *PFNALLOC)(ULONG cb);
#define FNALLOC(fn) void * __cdecl fn(ULONG cb)

typedef void (__cdecl *PFNFREE)(void *pv);
#define FNFREE(fn) void __cdecl fn(void *pv)

typedef INT_PTR (__cdecl *PFNOPEN) (char *pszFile, int oflag, int pmode);
#define FNOPEN(fn) INT_PTR __cdecl fn(char *pszFile, int oflag, int pmode)

typedef UINT (__cdecl *PFNREAD) (INT_PTR hf, void *pv, UINT cb);
#define FNREAD(fn) UINT __cdecl fn(INT_PTR hf, void *pv, UINT cb)

typedef UINT (__cdecl *PFNWRITE)(INT_PTR hf, void *pv, UINT cb);
#define FNWRITE(fn) UINT __cdecl fn(INT_PTR hf, void *pv, UINT cb)

typedef int  (__cdecl *PFNCLOSE)(INT_PTR hf);
#define FNCLOSE(fn) int __cdecl fn(INT_PTR hf)

224 225
typedef LONG (__cdecl *PFNSEEK) (INT_PTR hf, LONG dist, int seektype);
#define FNSEEK(fn) LONG __cdecl fn(INT_PTR hf, LONG dist, int seektype)
226 227 228 229 230

typedef int (__cdecl *PFNFDIDECRYPT)(PFDIDECRYPT pfdid);
#define FNFDIDECRYPT(fn) int __cdecl fn(PFDIDECRYPT pfdid)

typedef struct {
231
    LONG  cb;
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    char *psz1;
    char *psz2;
    char *psz3;  /* Points to a 256 character buffer */
    void *pv;    /* Value for client */

    INT_PTR hf;

    USHORT date;
    USHORT time;
    USHORT attribs;

    USHORT setID;     /* Cabinet set ID */
    USHORT iCabinet;  /* Cabinet number (0-based) */
    USHORT iFolder;   /* Folder number (0-based) */

    FDIERROR fdie;
} FDINOTIFICATION, *PFDINOTIFICATION;

typedef enum {
    fdintCABINET_INFO,     /* General information about cabinet */
    fdintPARTIAL_FILE,     /* First file in cabinet is continuation */
    fdintCOPY_FILE,        /* File to be copied */
    fdintCLOSE_FILE_INFO,  /* Close the file, set relevant info */
    fdintNEXT_CABINET,     /* File continued to next cabinet */
    fdintENUMERATE,        /* Enumeration status */
} FDINOTIFICATIONTYPE;

typedef INT_PTR (__cdecl *PFNFDINOTIFY)(FDINOTIFICATIONTYPE fdint,
					PFDINOTIFICATION  pfdin);
#define FNFDINOTIFY(fn) INT_PTR __cdecl fn(FDINOTIFICATIONTYPE fdint, \
					   PFDINOTIFICATION pfdin)

264
#ifndef _WIN64
265
#include <pshpack1.h>
266
#endif
267 268 269

typedef struct {
    char ach[2];  /* Set to { '*', '\0' } */
270
    LONG cbFile;  /* Required spill file size */
271 272
} FDISPILLFILE, *PFDISPILLFILE;

273
#ifndef _WIN64
274
#include <poppack.h>
275
#endif
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

#define cpuUNKNOWN (-1)  /* FDI does detection */
#define cpu80286   (0)   /* '286 opcodes only */
#define cpu80386   (1)   /* '386 opcodes used */

/**********************************************************************/

HFDI __cdecl FDICreate(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE,
		       PFNCLOSE, PFNSEEK, int, PERF);
BOOL __cdecl FDIIsCabinet(HFDI, INT_PTR, PFDICABINETINFO);
BOOL __cdecl FDICopy(HFDI, char *, char *, int, PFNFDINOTIFY,
		     PFNFDIDECRYPT, void *pvUser);
BOOL __cdecl FDIDestroy(HFDI);
BOOL __cdecl FDITruncateCabinet(HFDI, char *, USHORT);

/**********************************************************************/

293
#ifndef _WIN64
294
#include <poppack.h>
295
#endif
296 297 298 299 300 301

#ifdef __cplusplus
} /* extern "C" */
#endif /* defined(__cplusplus) */

#endif  /* __WINE_FDI_H */