d3d10: Add ID3D10EffectShaderVariableVtbl.
[wine.git] / dlls / ole32 / storage32.h
blob93561869c2d09dfcf0262f1515a37d6779744e3f
1 /*
2 * Compound Storage (32 bit version)
4 * Implemented using the documentation of the LAOLA project at
5 * <URL:http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/index.html>
6 * (Thanks to Martin Schwartz <schwartz@cs.tu-berlin.de>)
8 * This include file contains definitions of types and function
9 * prototypes that are used in the many files implementing the
10 * storage functionality
12 * Copyright 1998,1999 Francis Beaudet
13 * Copyright 1998,1999 Thuy Nguyen
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #ifndef __STORAGE32_H__
30 #define __STORAGE32_H__
32 #include <stdarg.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winnt.h"
37 #include "objbase.h"
38 #include "winreg.h"
39 #include "winternl.h"
40 #include "wine/list.h"
43 * Definitions for the file format offsets.
45 static const ULONG OFFSET_BIGBLOCKSIZEBITS = 0x0000001e;
46 static const ULONG OFFSET_SMALLBLOCKSIZEBITS = 0x00000020;
47 static const ULONG OFFSET_BBDEPOTCOUNT = 0x0000002C;
48 static const ULONG OFFSET_ROOTSTARTBLOCK = 0x00000030;
49 static const ULONG OFFSET_SBDEPOTSTART = 0x0000003C;
50 static const ULONG OFFSET_SBDEPOTCOUNT = 0x00000040;
51 static const ULONG OFFSET_EXTBBDEPOTSTART = 0x00000044;
52 static const ULONG OFFSET_EXTBBDEPOTCOUNT = 0x00000048;
53 static const ULONG OFFSET_BBDEPOTSTART = 0x0000004C;
54 static const ULONG OFFSET_PS_NAME = 0x00000000;
55 static const ULONG OFFSET_PS_NAMELENGTH = 0x00000040;
56 static const ULONG OFFSET_PS_PROPERTYTYPE = 0x00000042;
57 static const ULONG OFFSET_PS_RIGHTCHILD = 0x00000044;
58 static const ULONG OFFSET_PS_LEFTCHILD = 0x00000048;
59 static const ULONG OFFSET_PS_DIRPROP = 0x0000004C;
60 static const ULONG OFFSET_PS_GUID = 0x00000050;
61 static const ULONG OFFSET_PS_CTIMELOW = 0x00000064;
62 static const ULONG OFFSET_PS_CTIMEHIGH = 0x00000068;
63 static const ULONG OFFSET_PS_MTIMELOW = 0x0000006C;
64 static const ULONG OFFSET_PS_MTIMEHIGH = 0x00000070;
65 static const ULONG OFFSET_PS_STARTBLOCK = 0x00000074;
66 static const ULONG OFFSET_PS_SIZE = 0x00000078;
67 static const WORD DEF_BIG_BLOCK_SIZE_BITS = 0x0009;
68 static const WORD DEF_SMALL_BLOCK_SIZE_BITS = 0x0006;
69 static const WORD DEF_BIG_BLOCK_SIZE = 0x0200;
70 static const WORD DEF_SMALL_BLOCK_SIZE = 0x0040;
71 static const ULONG BLOCK_EXTBBDEPOT = 0xFFFFFFFC;
72 static const ULONG BLOCK_SPECIAL = 0xFFFFFFFD;
73 static const ULONG BLOCK_END_OF_CHAIN = 0xFFFFFFFE;
74 static const ULONG BLOCK_UNUSED = 0xFFFFFFFF;
75 static const ULONG PROPERTY_NULL = 0xFFFFFFFF;
77 #define PROPERTY_NAME_MAX_LEN 0x20
78 #define PROPERTY_NAME_BUFFER_LEN 0x40
80 #define PROPSET_BLOCK_SIZE 0x00000080
83 * Property type of relation
85 #define PROPERTY_RELATION_PREVIOUS 0
86 #define PROPERTY_RELATION_NEXT 1
87 #define PROPERTY_RELATION_DIR 2
90 * Property type constants
92 #define PROPTYPE_STORAGE 0x01
93 #define PROPTYPE_STREAM 0x02
94 #define PROPTYPE_ROOT 0x05
97 * These defines assume a hardcoded blocksize. The code will assert
98 * if the blocksize is different. Some changes will have to be done if it
99 * becomes the case.
101 #define BIG_BLOCK_SIZE 0x200
102 #define COUNT_BBDEPOTINHEADER 109
103 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
104 #define NUM_BLOCKS_PER_DEPOT_BLOCK 128
106 #define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
107 #define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
108 #define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
110 #define STGM_KNOWN_FLAGS (0xf0ff | \
111 STGM_TRANSACTED | STGM_CONVERT | STGM_PRIORITY | STGM_NOSCRATCH | \
112 STGM_NOSNAPSHOT | STGM_DIRECT_SWMR | STGM_DELETEONRELEASE | STGM_SIMPLE)
115 * Forward declarations of all the structures used by the storage
116 * module.
118 typedef struct StorageBaseImpl StorageBaseImpl;
119 typedef struct StorageImpl StorageImpl;
120 typedef struct BlockChainStream BlockChainStream;
121 typedef struct SmallBlockChainStream SmallBlockChainStream;
122 typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl;
123 typedef struct StgProperty StgProperty;
124 typedef struct StgStreamImpl StgStreamImpl;
127 * This utility structure is used to read/write the information in a storage
128 * property.
130 struct StgProperty
132 WCHAR name[PROPERTY_NAME_MAX_LEN];
133 WORD sizeOfNameString;
134 BYTE propertyType;
135 ULONG leftChild;
136 ULONG rightChild;
137 ULONG dirProperty;
138 GUID propertyUniqueID;
139 FILETIME ctime;
140 FILETIME mtime;
141 ULONG startingBlock;
142 ULARGE_INTEGER size;
145 /*************************************************************************
146 * Big Block File support
148 * The big block file is an abstraction of a flat file separated in
149 * same sized blocks. The implementation for the methods described in
150 * this section appear in stg_bigblockfile.c
153 typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
156 * Declaration of the functions used to manipulate the BigBlockFile
157 * data structure.
159 BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
160 ILockBytes* pLkByt,
161 DWORD openFlags,
162 ULONG blocksize,
163 BOOL fileBased);
164 void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
165 HRESULT BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
166 HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
167 HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
168 void* buffer, ULONG size, ULONG* bytesRead);
169 HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
170 const void* buffer, ULONG size, ULONG* bytesRead);
172 /*************************************************************************
173 * Ole Convert support
176 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage);
177 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName);
179 /****************************************************************************
180 * Storage32BaseImpl definitions.
182 * This structure defines the base information contained in all implementations
183 * of IStorage32 contained in this file storage implementation.
185 * In OOP terms, this is the base class for all the IStorage32 implementations
186 * contained in this file.
188 struct StorageBaseImpl
190 const IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct
191 * since we want to cast this in a Storage32 pointer */
193 const IPropertySetStorageVtbl *pssVtbl; /* interface for adding a properties stream */
196 * Stream tracking list
199 struct list strmHead;
202 * Reference count of this object
204 LONG ref;
207 * Ancestor storage (top level)
209 StorageImpl* ancestorStorage;
212 * Index of the property for the root of
213 * this storage
215 ULONG rootPropertySetIndex;
218 * virtual Destructor method.
220 void (*v_destructor)(StorageBaseImpl*);
223 * flags that this storage was opened or created with
225 DWORD openFlags;
228 * State bits appear to only be preserved while running. No in the stream
230 DWORD stateBits;
233 /****************************************************************************
234 * StorageBaseImpl stream list handlers
237 void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm);
238 void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm);
240 /****************************************************************************
241 * Storage32Impl definitions.
243 * This implementation of the IStorage32 interface represents a root
244 * storage. Basically, a document file.
246 struct StorageImpl
248 struct StorageBaseImpl base;
251 * The following data members are specific to the Storage32Impl
252 * class
254 HANDLE hFile; /* Physical support for the Docfile */
255 LPOLESTR pwcsName; /* Full path of the document file */
256 BOOL create; /* Was the storage created or opened.
257 The behaviour of STGM_SIMPLE depends on this */
259 /* FIXME: should this be in Storage32BaseImpl ? */
260 WCHAR filename[PROPERTY_NAME_BUFFER_LEN];
263 * File header
265 WORD bigBlockSizeBits;
266 WORD smallBlockSizeBits;
267 ULONG bigBlockSize;
268 ULONG smallBlockSize;
269 ULONG bigBlockDepotCount;
270 ULONG rootStartBlock;
271 ULONG smallBlockDepotStart;
272 ULONG extBigBlockDepotStart;
273 ULONG extBigBlockDepotCount;
274 ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
276 ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK];
277 ULONG indexBlockDepotCached;
278 ULONG prevFreeBlock;
281 * Abstraction of the big block chains for the chains of the header.
283 BlockChainStream* rootBlockChain;
284 BlockChainStream* smallBlockDepotChain;
285 BlockChainStream* smallBlockRootChain;
288 * Pointer to the big block file abstraction
290 BigBlockFile* bigBlockFile;
293 BOOL StorageImpl_ReadProperty(
294 StorageImpl* This,
295 ULONG index,
296 StgProperty* buffer);
298 BOOL StorageImpl_WriteProperty(
299 StorageImpl* This,
300 ULONG index,
301 const StgProperty* buffer);
303 BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
304 StorageImpl* This,
305 SmallBlockChainStream** ppsbChain);
307 SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
308 StorageImpl* This,
309 BlockChainStream** ppbbChain);
311 /****************************************************************************
312 * StgStreamImpl definitions.
314 * This class implements the IStream32 interface and represents a stream
315 * located inside a storage object.
317 struct StgStreamImpl
319 const IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct
320 * since we want to cast this to an IStream pointer */
323 * We are an entry in the storage object's stream handler list
326 struct list StrmListEntry;
329 * Reference count
331 LONG ref;
334 * Storage that is the parent(owner) of the stream
336 StorageBaseImpl* parentStorage;
339 * Access mode of this stream.
341 DWORD grfMode;
344 * Index of the property that owns (points to) this stream.
346 ULONG ownerProperty;
349 * Helper variable that contains the size of the stream
351 ULARGE_INTEGER streamSize;
354 * This is the current position of the cursor in the stream
356 ULARGE_INTEGER currentPosition;
359 * The information in the stream is represented by a chain of small blocks
360 * or a chain of large blocks. Depending on the case, one of the two
361 * following variables points to that information.
363 BlockChainStream* bigBlockChain;
364 SmallBlockChainStream* smallBlockChain;
368 * Method definition for the StgStreamImpl class.
370 StgStreamImpl* StgStreamImpl_Construct(
371 StorageBaseImpl* parentStorage,
372 DWORD grfMode,
373 ULONG ownerProperty);
376 /******************************************************************************
377 * Endian conversion macros
379 #ifdef WORDS_BIGENDIAN
381 #define htole32(x) RtlUlongByteSwap(x)
382 #define htole16(x) RtlUshortByteSwap(x)
383 #define lendian32toh(x) RtlUlongByteSwap(x)
384 #define lendian16toh(x) RtlUshortByteSwap(x)
386 #else
388 #define htole32(x) (x)
389 #define htole16(x) (x)
390 #define lendian32toh(x) (x)
391 #define lendian16toh(x) (x)
393 #endif
395 /******************************************************************************
396 * The StorageUtl_ functions are miscellaneous utility functions. Most of which
397 * are abstractions used to read values from file buffers without having to
398 * worry about bit order
400 void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
401 void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
402 void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value);
403 void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value);
404 void StorageUtl_ReadULargeInteger(const BYTE* buffer, ULONG offset,
405 ULARGE_INTEGER* value);
406 void StorageUtl_WriteULargeInteger(BYTE* buffer, ULONG offset,
407 const ULARGE_INTEGER *value);
408 void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value);
409 void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value);
410 void StorageUtl_CopyPropertyToSTATSTG(STATSTG* destination, const StgProperty* source,
411 int statFlags);
413 /****************************************************************************
414 * BlockChainStream definitions.
416 * The BlockChainStream class is a utility class that is used to create an
417 * abstraction of the big block chains in the storage file.
419 struct BlockChainStream
421 StorageImpl* parentStorage;
422 ULONG* headOfStreamPlaceHolder;
423 ULONG ownerPropertyIndex;
424 ULONG lastBlockNoInSequence;
425 ULONG lastBlockNoInSequenceIndex;
426 ULONG tailIndex;
427 ULONG numBlocks;
431 * Methods for the BlockChainStream class.
433 BlockChainStream* BlockChainStream_Construct(
434 StorageImpl* parentStorage,
435 ULONG* headOfStreamPlaceHolder,
436 ULONG propertyIndex);
438 void BlockChainStream_Destroy(
439 BlockChainStream* This);
441 HRESULT BlockChainStream_ReadAt(
442 BlockChainStream* This,
443 ULARGE_INTEGER offset,
444 ULONG size,
445 void* buffer,
446 ULONG* bytesRead);
448 HRESULT BlockChainStream_WriteAt(
449 BlockChainStream* This,
450 ULARGE_INTEGER offset,
451 ULONG size,
452 const void* buffer,
453 ULONG* bytesWritten);
455 BOOL BlockChainStream_SetSize(
456 BlockChainStream* This,
457 ULARGE_INTEGER newSize);
459 /****************************************************************************
460 * SmallBlockChainStream definitions.
462 * The SmallBlockChainStream class is a utility class that is used to create an
463 * abstraction of the small block chains in the storage file.
465 struct SmallBlockChainStream
467 StorageImpl* parentStorage;
468 ULONG ownerPropertyIndex;
469 ULONG* headOfStreamPlaceHolder;
473 * Methods of the SmallBlockChainStream class.
475 SmallBlockChainStream* SmallBlockChainStream_Construct(
476 StorageImpl* parentStorage,
477 ULONG* headOfStreamPlaceHolder,
478 ULONG propertyIndex);
480 void SmallBlockChainStream_Destroy(
481 SmallBlockChainStream* This);
483 HRESULT SmallBlockChainStream_ReadAt(
484 SmallBlockChainStream* This,
485 ULARGE_INTEGER offset,
486 ULONG size,
487 void* buffer,
488 ULONG* bytesRead);
490 HRESULT SmallBlockChainStream_WriteAt(
491 SmallBlockChainStream* This,
492 ULARGE_INTEGER offset,
493 ULONG size,
494 const void* buffer,
495 ULONG* bytesWritten);
497 BOOL SmallBlockChainStream_SetSize(
498 SmallBlockChainStream* This,
499 ULARGE_INTEGER newSize);
502 #endif /* __STORAGE32_H__ */