gdiplus: Don't use gdi32 to draw to bitmaps with formats it can't handle.
[wine/hacks.git] / dlls / ole32 / storage32.h
blob98ec6d121a578ed63e826b840f80e54232cead36
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_SMALLBLOCKLIMIT = 0x00000038;
50 static const ULONG OFFSET_SBDEPOTSTART = 0x0000003C;
51 static const ULONG OFFSET_SBDEPOTCOUNT = 0x00000040;
52 static const ULONG OFFSET_EXTBBDEPOTSTART = 0x00000044;
53 static const ULONG OFFSET_EXTBBDEPOTCOUNT = 0x00000048;
54 static const ULONG OFFSET_BBDEPOTSTART = 0x0000004C;
55 static const ULONG OFFSET_PS_NAME = 0x00000000;
56 static const ULONG OFFSET_PS_NAMELENGTH = 0x00000040;
57 static const ULONG OFFSET_PS_STGTYPE = 0x00000042;
58 static const ULONG OFFSET_PS_LEFTCHILD = 0x00000044;
59 static const ULONG OFFSET_PS_RIGHTCHILD = 0x00000048;
60 static const ULONG OFFSET_PS_DIRROOT = 0x0000004C;
61 static const ULONG OFFSET_PS_GUID = 0x00000050;
62 static const ULONG OFFSET_PS_CTIMELOW = 0x00000064;
63 static const ULONG OFFSET_PS_CTIMEHIGH = 0x00000068;
64 static const ULONG OFFSET_PS_MTIMELOW = 0x0000006C;
65 static const ULONG OFFSET_PS_MTIMEHIGH = 0x00000070;
66 static const ULONG OFFSET_PS_STARTBLOCK = 0x00000074;
67 static const ULONG OFFSET_PS_SIZE = 0x00000078;
68 static const WORD DEF_BIG_BLOCK_SIZE_BITS = 0x0009;
69 static const WORD DEF_SMALL_BLOCK_SIZE_BITS = 0x0006;
70 static const WORD DEF_BIG_BLOCK_SIZE = 0x0200;
71 static const WORD DEF_SMALL_BLOCK_SIZE = 0x0040;
72 static const ULONG BLOCK_EXTBBDEPOT = 0xFFFFFFFC;
73 static const ULONG BLOCK_SPECIAL = 0xFFFFFFFD;
74 static const ULONG BLOCK_END_OF_CHAIN = 0xFFFFFFFE;
75 static const ULONG BLOCK_UNUSED = 0xFFFFFFFF;
76 static const ULONG DIRENTRY_NULL = 0xFFFFFFFF;
78 #define DIRENTRY_NAME_MAX_LEN 0x20
79 #define DIRENTRY_NAME_BUFFER_LEN 0x40
81 #define RAW_DIRENTRY_SIZE 0x00000080
83 #define HEADER_SIZE 512
85 #define MIN_BIG_BLOCK_SIZE 0x200
86 #define MAX_BIG_BLOCK_SIZE 0x1000
89 * Type of child entry link
91 #define DIRENTRY_RELATION_PREVIOUS 0
92 #define DIRENTRY_RELATION_NEXT 1
93 #define DIRENTRY_RELATION_DIR 2
96 * type constant used in files for the root storage
98 #define STGTY_ROOT 0x05
100 #define COUNT_BBDEPOTINHEADER 109
102 /* FIXME: This value is stored in the header, but we hard-code it to 0x1000. */
103 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
105 #define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
106 #define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
107 #define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
109 #define STGM_KNOWN_FLAGS (0xf0ff | \
110 STGM_TRANSACTED | STGM_CONVERT | STGM_PRIORITY | STGM_NOSCRATCH | \
111 STGM_NOSNAPSHOT | STGM_DIRECT_SWMR | STGM_DELETEONRELEASE | STGM_SIMPLE)
114 * Forward declarations of all the structures used by the storage
115 * module.
117 typedef struct StorageBaseImpl StorageBaseImpl;
118 typedef struct StorageBaseImplVtbl StorageBaseImplVtbl;
119 typedef struct StorageImpl StorageImpl;
120 typedef struct BlockChainStream BlockChainStream;
121 typedef struct SmallBlockChainStream SmallBlockChainStream;
122 typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl;
123 typedef struct DirEntry DirEntry;
124 typedef struct StgStreamImpl StgStreamImpl;
127 * A reference to a directory entry in the file or a transacted cache.
129 typedef ULONG DirRef;
132 * This utility structure is used to read/write the information in a directory
133 * entry.
135 struct DirEntry
137 WCHAR name[DIRENTRY_NAME_MAX_LEN];
138 WORD sizeOfNameString;
139 BYTE stgType;
140 DirRef leftChild;
141 DirRef rightChild;
142 DirRef dirRootEntry;
143 GUID clsid;
144 FILETIME ctime;
145 FILETIME mtime;
146 ULONG startingBlock;
147 ULARGE_INTEGER size;
150 /*************************************************************************
151 * Big Block File support
153 * The big block file is an abstraction of a flat file separated in
154 * same sized blocks. The implementation for the methods described in
155 * this section appear in stg_bigblockfile.c
158 typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
161 * Declaration of the functions used to manipulate the BigBlockFile
162 * data structure.
164 BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
165 ILockBytes* pLkByt,
166 DWORD openFlags,
167 BOOL fileBased);
168 void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
169 HRESULT BIGBLOCKFILE_Expand(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
170 HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
171 HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
172 void* buffer, ULONG size, ULONG* bytesRead);
173 HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
174 const void* buffer, ULONG size, ULONG* bytesRead);
176 /*************************************************************************
177 * Ole Convert support
180 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage);
181 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName);
184 /****************************************************************************
185 * Storage32BaseImpl definitions.
187 * This structure defines the base information contained in all implementations
188 * of IStorage32 contained in this file storage implementation.
190 * In OOP terms, this is the base class for all the IStorage32 implementations
191 * contained in this file.
193 struct StorageBaseImpl
195 const IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct
196 * since we want to cast this in a Storage32 pointer */
198 const IPropertySetStorageVtbl *pssVtbl; /* interface for adding a properties stream */
201 * Stream tracking list
204 struct list strmHead;
207 * Storage tracking list
209 struct list storageHead;
212 * Reference count of this object
214 LONG ref;
217 * TRUE if this object has been invalidated
219 int reverted;
222 * Index of the directory entry of this storage
224 DirRef storageDirEntry;
227 * virtual methods.
229 const StorageBaseImplVtbl *baseVtbl;
232 * flags that this storage was opened or created with
234 DWORD openFlags;
237 * State bits appear to only be preserved while running. No in the stream
239 DWORD stateBits;
241 /* If set, this overrides the root storage name returned by IStorage_Stat */
242 LPCWSTR filename;
244 BOOL create; /* Was the storage created or opened.
245 The behaviour of STGM_SIMPLE depends on this */
247 * If this storage was opened in transacted mode, the object that implements
248 * the transacted snapshot or cache.
250 StorageBaseImpl *transactedChild;
253 /* virtual methods for StorageBaseImpl objects */
254 struct StorageBaseImplVtbl {
255 void (*Destroy)(StorageBaseImpl*);
256 void (*Invalidate)(StorageBaseImpl*);
257 HRESULT (*CreateDirEntry)(StorageBaseImpl*,const DirEntry*,DirRef*);
258 HRESULT (*WriteDirEntry)(StorageBaseImpl*,DirRef,const DirEntry*);
259 HRESULT (*ReadDirEntry)(StorageBaseImpl*,DirRef,DirEntry*);
260 HRESULT (*DestroyDirEntry)(StorageBaseImpl*,DirRef);
261 HRESULT (*StreamReadAt)(StorageBaseImpl*,DirRef,ULARGE_INTEGER,ULONG,void*,ULONG*);
262 HRESULT (*StreamWriteAt)(StorageBaseImpl*,DirRef,ULARGE_INTEGER,ULONG,const void*,ULONG*);
263 HRESULT (*StreamSetSize)(StorageBaseImpl*,DirRef,ULARGE_INTEGER);
266 static inline void StorageBaseImpl_Destroy(StorageBaseImpl *This)
268 This->baseVtbl->Destroy(This);
271 static inline void StorageBaseImpl_Invalidate(StorageBaseImpl *This)
273 This->baseVtbl->Invalidate(This);
276 static inline HRESULT StorageBaseImpl_CreateDirEntry(StorageBaseImpl *This,
277 const DirEntry *newData, DirRef *index)
279 return This->baseVtbl->CreateDirEntry(This, newData, index);
282 static inline HRESULT StorageBaseImpl_WriteDirEntry(StorageBaseImpl *This,
283 DirRef index, const DirEntry *data)
285 return This->baseVtbl->WriteDirEntry(This, index, data);
288 static inline HRESULT StorageBaseImpl_ReadDirEntry(StorageBaseImpl *This,
289 DirRef index, DirEntry *data)
291 return This->baseVtbl->ReadDirEntry(This, index, data);
294 static inline HRESULT StorageBaseImpl_DestroyDirEntry(StorageBaseImpl *This,
295 DirRef index)
297 return This->baseVtbl->DestroyDirEntry(This, index);
300 /* Read up to size bytes from this directory entry's stream at the given offset. */
301 static inline HRESULT StorageBaseImpl_StreamReadAt(StorageBaseImpl *This,
302 DirRef index, ULARGE_INTEGER offset, ULONG size, void *buffer, ULONG *bytesRead)
304 return This->baseVtbl->StreamReadAt(This, index, offset, size, buffer, bytesRead);
307 /* Write size bytes to this directory entry's stream at the given offset,
308 * growing the stream if necessary. */
309 static inline HRESULT StorageBaseImpl_StreamWriteAt(StorageBaseImpl *This,
310 DirRef index, ULARGE_INTEGER offset, ULONG size, const void *buffer, ULONG *bytesWritten)
312 return This->baseVtbl->StreamWriteAt(This, index, offset, size, buffer, bytesWritten);
315 static inline HRESULT StorageBaseImpl_StreamSetSize(StorageBaseImpl *This,
316 DirRef index, ULARGE_INTEGER newsize)
318 return This->baseVtbl->StreamSetSize(This, index, newsize);
321 /****************************************************************************
322 * StorageBaseImpl stream list handlers
325 void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm);
326 void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm);
328 /* Number of BlockChainStream objects to cache in a StorageImpl */
329 #define BLOCKCHAIN_CACHE_SIZE 4
331 /****************************************************************************
332 * Storage32Impl definitions.
334 * This implementation of the IStorage32 interface represents a root
335 * storage. Basically, a document file.
337 struct StorageImpl
339 struct StorageBaseImpl base;
342 * The following data members are specific to the Storage32Impl
343 * class
345 HANDLE hFile; /* Physical support for the Docfile */
346 LPOLESTR pwcsName; /* Full path of the document file */
349 * File header
351 WORD bigBlockSizeBits;
352 WORD smallBlockSizeBits;
353 ULONG bigBlockSize;
354 ULONG smallBlockSize;
355 ULONG bigBlockDepotCount;
356 ULONG rootStartBlock;
357 ULONG smallBlockLimit;
358 ULONG smallBlockDepotStart;
359 ULONG extBigBlockDepotStart;
360 ULONG extBigBlockDepotCount;
361 ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
363 ULONG blockDepotCached[MAX_BIG_BLOCK_SIZE / 4];
364 ULONG indexBlockDepotCached;
365 ULONG prevFreeBlock;
367 /* All small blocks before this one are known to be in use. */
368 ULONG firstFreeSmallBlock;
371 * Abstraction of the big block chains for the chains of the header.
373 BlockChainStream* rootBlockChain;
374 BlockChainStream* smallBlockDepotChain;
375 BlockChainStream* smallBlockRootChain;
377 /* Cache of block chain streams objects for directory entries */
378 BlockChainStream* blockChainCache[BLOCKCHAIN_CACHE_SIZE];
379 UINT blockChainToEvict;
382 * Pointer to the big block file abstraction
384 BigBlockFile* bigBlockFile;
387 HRESULT StorageImpl_ReadRawDirEntry(
388 StorageImpl *This,
389 ULONG index,
390 BYTE *buffer);
392 void UpdateRawDirEntry(
393 BYTE *buffer,
394 const DirEntry *newData);
396 HRESULT StorageImpl_WriteRawDirEntry(
397 StorageImpl *This,
398 ULONG index,
399 const BYTE *buffer);
401 HRESULT StorageImpl_ReadDirEntry(
402 StorageImpl* This,
403 DirRef index,
404 DirEntry* buffer);
406 HRESULT StorageImpl_WriteDirEntry(
407 StorageImpl* This,
408 DirRef index,
409 const DirEntry* buffer);
411 BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
412 StorageImpl* This,
413 SmallBlockChainStream** ppsbChain);
415 SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
416 StorageImpl* This,
417 BlockChainStream** ppbbChain);
419 /****************************************************************************
420 * StgStreamImpl definitions.
422 * This class implements the IStream32 interface and represents a stream
423 * located inside a storage object.
425 struct StgStreamImpl
427 const IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct
428 * since we want to cast this to an IStream pointer */
431 * We are an entry in the storage object's stream handler list
434 struct list StrmListEntry;
437 * Reference count
439 LONG ref;
442 * Storage that is the parent(owner) of the stream
444 StorageBaseImpl* parentStorage;
447 * Access mode of this stream.
449 DWORD grfMode;
452 * Index of the directory entry that owns (points to) this stream.
454 DirRef dirEntry;
457 * This is the current position of the cursor in the stream
459 ULARGE_INTEGER currentPosition;
463 * Method definition for the StgStreamImpl class.
465 StgStreamImpl* StgStreamImpl_Construct(
466 StorageBaseImpl* parentStorage,
467 DWORD grfMode,
468 DirRef dirEntry);
471 /******************************************************************************
472 * Endian conversion macros
474 #ifdef WORDS_BIGENDIAN
476 #define htole32(x) RtlUlongByteSwap(x)
477 #define htole16(x) RtlUshortByteSwap(x)
478 #define lendian32toh(x) RtlUlongByteSwap(x)
479 #define lendian16toh(x) RtlUshortByteSwap(x)
481 #else
483 #define htole32(x) (x)
484 #define htole16(x) (x)
485 #define lendian32toh(x) (x)
486 #define lendian16toh(x) (x)
488 #endif
490 /******************************************************************************
491 * The StorageUtl_ functions are miscellaneous utility functions. Most of which
492 * are abstractions used to read values from file buffers without having to
493 * worry about bit order
495 void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
496 void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
497 void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value);
498 void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value);
499 void StorageUtl_ReadULargeInteger(const BYTE* buffer, ULONG offset,
500 ULARGE_INTEGER* value);
501 void StorageUtl_WriteULargeInteger(BYTE* buffer, ULONG offset,
502 const ULARGE_INTEGER *value);
503 void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value);
504 void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value);
505 void StorageUtl_CopyDirEntryToSTATSTG(StorageBaseImpl *storage,STATSTG* destination,
506 const DirEntry* source, int statFlags);
508 /****************************************************************************
509 * BlockChainStream definitions.
511 * The BlockChainStream class is a utility class that is used to create an
512 * abstraction of the big block chains in the storage file.
514 struct BlockChainStream
516 StorageImpl* parentStorage;
517 ULONG* headOfStreamPlaceHolder;
518 DirRef ownerDirEntry;
519 ULONG lastBlockNoInSequence;
520 ULONG lastBlockNoInSequenceIndex;
521 ULONG tailIndex;
522 ULONG numBlocks;
526 * Methods for the BlockChainStream class.
528 BlockChainStream* BlockChainStream_Construct(
529 StorageImpl* parentStorage,
530 ULONG* headOfStreamPlaceHolder,
531 DirRef dirEntry);
533 void BlockChainStream_Destroy(
534 BlockChainStream* This);
536 HRESULT BlockChainStream_ReadAt(
537 BlockChainStream* This,
538 ULARGE_INTEGER offset,
539 ULONG size,
540 void* buffer,
541 ULONG* bytesRead);
543 HRESULT BlockChainStream_WriteAt(
544 BlockChainStream* This,
545 ULARGE_INTEGER offset,
546 ULONG size,
547 const void* buffer,
548 ULONG* bytesWritten);
550 BOOL BlockChainStream_SetSize(
551 BlockChainStream* This,
552 ULARGE_INTEGER newSize);
554 /****************************************************************************
555 * SmallBlockChainStream definitions.
557 * The SmallBlockChainStream class is a utility class that is used to create an
558 * abstraction of the small block chains in the storage file.
560 struct SmallBlockChainStream
562 StorageImpl* parentStorage;
563 DirRef ownerDirEntry;
564 ULONG* headOfStreamPlaceHolder;
568 * Methods of the SmallBlockChainStream class.
570 SmallBlockChainStream* SmallBlockChainStream_Construct(
571 StorageImpl* parentStorage,
572 ULONG* headOfStreamPlaceHolder,
573 DirRef dirEntry);
575 void SmallBlockChainStream_Destroy(
576 SmallBlockChainStream* This);
578 HRESULT SmallBlockChainStream_ReadAt(
579 SmallBlockChainStream* This,
580 ULARGE_INTEGER offset,
581 ULONG size,
582 void* buffer,
583 ULONG* bytesRead);
585 HRESULT SmallBlockChainStream_WriteAt(
586 SmallBlockChainStream* This,
587 ULARGE_INTEGER offset,
588 ULONG size,
589 const void* buffer,
590 ULONG* bytesWritten);
592 BOOL SmallBlockChainStream_SetSize(
593 SmallBlockChainStream* This,
594 ULARGE_INTEGER newSize);
597 #endif /* __STORAGE32_H__ */