comdlg32: Fix some alignment issues in the Dutch translation.
[wine/hramrach.git] / dlls / ole32 / storage32.h
blobf25351bdbe336bd8eeddfdeee028622c0bfbf108
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 MIN_BIG_BLOCK_SIZE_BITS = 0x0009;
70 static const WORD MAX_BIG_BLOCK_SIZE_BITS = 0x000c;
71 static const WORD DEF_SMALL_BLOCK_SIZE_BITS = 0x0006;
72 static const WORD DEF_BIG_BLOCK_SIZE = 0x0200;
73 static const WORD DEF_SMALL_BLOCK_SIZE = 0x0040;
74 static const ULONG BLOCK_EXTBBDEPOT = 0xFFFFFFFC;
75 static const ULONG BLOCK_SPECIAL = 0xFFFFFFFD;
76 static const ULONG BLOCK_END_OF_CHAIN = 0xFFFFFFFE;
77 static const ULONG BLOCK_UNUSED = 0xFFFFFFFF;
78 static const ULONG DIRENTRY_NULL = 0xFFFFFFFF;
80 #define DIRENTRY_NAME_MAX_LEN 0x20
81 #define DIRENTRY_NAME_BUFFER_LEN 0x40
83 #define RAW_DIRENTRY_SIZE 0x00000080
85 #define HEADER_SIZE 512
87 #define MIN_BIG_BLOCK_SIZE 0x200
88 #define MAX_BIG_BLOCK_SIZE 0x1000
91 * Type of child entry link
93 #define DIRENTRY_RELATION_PREVIOUS 0
94 #define DIRENTRY_RELATION_NEXT 1
95 #define DIRENTRY_RELATION_DIR 2
98 * type constant used in files for the root storage
100 #define STGTY_ROOT 0x05
102 #define COUNT_BBDEPOTINHEADER 109
104 /* FIXME: This value is stored in the header, but we hard-code it to 0x1000. */
105 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
107 #define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
108 #define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
109 #define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
111 #define STGM_KNOWN_FLAGS (0xf0ff | \
112 STGM_TRANSACTED | STGM_CONVERT | STGM_PRIORITY | STGM_NOSCRATCH | \
113 STGM_NOSNAPSHOT | STGM_DIRECT_SWMR | STGM_DELETEONRELEASE | STGM_SIMPLE)
116 * Forward declarations of all the structures used by the storage
117 * module.
119 typedef struct StorageBaseImpl StorageBaseImpl;
120 typedef struct StorageBaseImplVtbl StorageBaseImplVtbl;
121 typedef struct StorageImpl StorageImpl;
122 typedef struct BlockChainStream BlockChainStream;
123 typedef struct SmallBlockChainStream SmallBlockChainStream;
124 typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl;
125 typedef struct DirEntry DirEntry;
126 typedef struct StgStreamImpl StgStreamImpl;
129 * A reference to a directory entry in the file or a transacted cache.
131 typedef ULONG DirRef;
134 * This utility structure is used to read/write the information in a directory
135 * entry.
137 struct DirEntry
139 WCHAR name[DIRENTRY_NAME_MAX_LEN];
140 WORD sizeOfNameString;
141 BYTE stgType;
142 DirRef leftChild;
143 DirRef rightChild;
144 DirRef dirRootEntry;
145 GUID clsid;
146 FILETIME ctime;
147 FILETIME mtime;
148 ULONG startingBlock;
149 ULARGE_INTEGER size;
152 /*************************************************************************
153 * Big Block File support
155 * The big block file is an abstraction of a flat file separated in
156 * same sized blocks. The implementation for the methods described in
157 * this section appear in stg_bigblockfile.c
160 typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
163 * Declaration of the functions used to manipulate the BigBlockFile
164 * data structure.
166 BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
167 ILockBytes* pLkByt,
168 DWORD openFlags,
169 BOOL fileBased);
170 void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
171 HRESULT BIGBLOCKFILE_Expand(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
172 HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
173 HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
174 void* buffer, ULONG size, ULONG* bytesRead);
175 HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
176 const void* buffer, ULONG size, ULONG* bytesRead);
178 /*************************************************************************
179 * Ole Convert support
182 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage);
183 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName);
186 /****************************************************************************
187 * Storage32BaseImpl definitions.
189 * This structure defines the base information contained in all implementations
190 * of IStorage32 contained in this file storage implementation.
192 * In OOP terms, this is the base class for all the IStorage32 implementations
193 * contained in this file.
195 struct StorageBaseImpl
197 const IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct
198 * since we want to cast this in a Storage32 pointer */
200 const IPropertySetStorageVtbl *pssVtbl; /* interface for adding a properties stream */
203 * Stream tracking list
206 struct list strmHead;
209 * Storage tracking list
211 struct list storageHead;
214 * Reference count of this object
216 LONG ref;
219 * TRUE if this object has been invalidated
221 int reverted;
224 * Index of the directory entry of this storage
226 DirRef storageDirEntry;
229 * virtual methods.
231 const StorageBaseImplVtbl *baseVtbl;
234 * flags that this storage was opened or created with
236 DWORD openFlags;
239 * State bits appear to only be preserved while running. No in the stream
241 DWORD stateBits;
243 /* If set, this overrides the root storage name returned by IStorage_Stat */
244 LPCWSTR filename;
246 BOOL create; /* Was the storage created or opened.
247 The behaviour of STGM_SIMPLE depends on this */
249 * If this storage was opened in transacted mode, the object that implements
250 * the transacted snapshot or cache.
252 StorageBaseImpl *transactedChild;
255 /* virtual methods for StorageBaseImpl objects */
256 struct StorageBaseImplVtbl {
257 void (*Destroy)(StorageBaseImpl*);
258 void (*Invalidate)(StorageBaseImpl*);
259 HRESULT (*CreateDirEntry)(StorageBaseImpl*,const DirEntry*,DirRef*);
260 HRESULT (*WriteDirEntry)(StorageBaseImpl*,DirRef,const DirEntry*);
261 HRESULT (*ReadDirEntry)(StorageBaseImpl*,DirRef,DirEntry*);
262 HRESULT (*DestroyDirEntry)(StorageBaseImpl*,DirRef);
263 HRESULT (*StreamReadAt)(StorageBaseImpl*,DirRef,ULARGE_INTEGER,ULONG,void*,ULONG*);
264 HRESULT (*StreamWriteAt)(StorageBaseImpl*,DirRef,ULARGE_INTEGER,ULONG,const void*,ULONG*);
265 HRESULT (*StreamSetSize)(StorageBaseImpl*,DirRef,ULARGE_INTEGER);
268 static inline void StorageBaseImpl_Destroy(StorageBaseImpl *This)
270 This->baseVtbl->Destroy(This);
273 static inline void StorageBaseImpl_Invalidate(StorageBaseImpl *This)
275 This->baseVtbl->Invalidate(This);
278 static inline HRESULT StorageBaseImpl_CreateDirEntry(StorageBaseImpl *This,
279 const DirEntry *newData, DirRef *index)
281 return This->baseVtbl->CreateDirEntry(This, newData, index);
284 static inline HRESULT StorageBaseImpl_WriteDirEntry(StorageBaseImpl *This,
285 DirRef index, const DirEntry *data)
287 return This->baseVtbl->WriteDirEntry(This, index, data);
290 static inline HRESULT StorageBaseImpl_ReadDirEntry(StorageBaseImpl *This,
291 DirRef index, DirEntry *data)
293 return This->baseVtbl->ReadDirEntry(This, index, data);
296 static inline HRESULT StorageBaseImpl_DestroyDirEntry(StorageBaseImpl *This,
297 DirRef index)
299 return This->baseVtbl->DestroyDirEntry(This, index);
302 /* Read up to size bytes from this directory entry's stream at the given offset. */
303 static inline HRESULT StorageBaseImpl_StreamReadAt(StorageBaseImpl *This,
304 DirRef index, ULARGE_INTEGER offset, ULONG size, void *buffer, ULONG *bytesRead)
306 return This->baseVtbl->StreamReadAt(This, index, offset, size, buffer, bytesRead);
309 /* Write size bytes to this directory entry's stream at the given offset,
310 * growing the stream if necessary. */
311 static inline HRESULT StorageBaseImpl_StreamWriteAt(StorageBaseImpl *This,
312 DirRef index, ULARGE_INTEGER offset, ULONG size, const void *buffer, ULONG *bytesWritten)
314 return This->baseVtbl->StreamWriteAt(This, index, offset, size, buffer, bytesWritten);
317 static inline HRESULT StorageBaseImpl_StreamSetSize(StorageBaseImpl *This,
318 DirRef index, ULARGE_INTEGER newsize)
320 return This->baseVtbl->StreamSetSize(This, index, newsize);
323 /****************************************************************************
324 * StorageBaseImpl stream list handlers
327 void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm);
328 void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm);
330 /* Number of BlockChainStream objects to cache in a StorageImpl */
331 #define BLOCKCHAIN_CACHE_SIZE 4
333 /****************************************************************************
334 * Storage32Impl definitions.
336 * This implementation of the IStorage32 interface represents a root
337 * storage. Basically, a document file.
339 struct StorageImpl
341 struct StorageBaseImpl base;
344 * The following data members are specific to the Storage32Impl
345 * class
347 HANDLE hFile; /* Physical support for the Docfile */
348 LPOLESTR pwcsName; /* Full path of the document file */
351 * File header
353 WORD bigBlockSizeBits;
354 WORD smallBlockSizeBits;
355 ULONG bigBlockSize;
356 ULONG smallBlockSize;
357 ULONG bigBlockDepotCount;
358 ULONG rootStartBlock;
359 ULONG smallBlockLimit;
360 ULONG smallBlockDepotStart;
361 ULONG extBigBlockDepotStart;
362 ULONG extBigBlockDepotCount;
363 ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
365 ULONG blockDepotCached[MAX_BIG_BLOCK_SIZE / 4];
366 ULONG indexBlockDepotCached;
367 ULONG prevFreeBlock;
369 /* All small blocks before this one are known to be in use. */
370 ULONG firstFreeSmallBlock;
373 * Abstraction of the big block chains for the chains of the header.
375 BlockChainStream* rootBlockChain;
376 BlockChainStream* smallBlockDepotChain;
377 BlockChainStream* smallBlockRootChain;
379 /* Cache of block chain streams objects for directory entries */
380 BlockChainStream* blockChainCache[BLOCKCHAIN_CACHE_SIZE];
381 UINT blockChainToEvict;
384 * Pointer to the big block file abstraction
386 BigBlockFile* bigBlockFile;
389 HRESULT StorageImpl_ReadRawDirEntry(
390 StorageImpl *This,
391 ULONG index,
392 BYTE *buffer);
394 void UpdateRawDirEntry(
395 BYTE *buffer,
396 const DirEntry *newData);
398 HRESULT StorageImpl_WriteRawDirEntry(
399 StorageImpl *This,
400 ULONG index,
401 const BYTE *buffer);
403 HRESULT StorageImpl_ReadDirEntry(
404 StorageImpl* This,
405 DirRef index,
406 DirEntry* buffer);
408 HRESULT StorageImpl_WriteDirEntry(
409 StorageImpl* This,
410 DirRef index,
411 const DirEntry* buffer);
413 BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
414 StorageImpl* This,
415 SmallBlockChainStream** ppsbChain);
417 SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
418 StorageImpl* This,
419 BlockChainStream** ppbbChain);
421 /****************************************************************************
422 * StgStreamImpl definitions.
424 * This class implements the IStream32 interface and represents a stream
425 * located inside a storage object.
427 struct StgStreamImpl
429 const IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct
430 * since we want to cast this to an IStream pointer */
433 * We are an entry in the storage object's stream handler list
436 struct list StrmListEntry;
439 * Reference count
441 LONG ref;
444 * Storage that is the parent(owner) of the stream
446 StorageBaseImpl* parentStorage;
449 * Access mode of this stream.
451 DWORD grfMode;
454 * Index of the directory entry that owns (points to) this stream.
456 DirRef dirEntry;
459 * This is the current position of the cursor in the stream
461 ULARGE_INTEGER currentPosition;
465 * Method definition for the StgStreamImpl class.
467 StgStreamImpl* StgStreamImpl_Construct(
468 StorageBaseImpl* parentStorage,
469 DWORD grfMode,
470 DirRef dirEntry);
473 /******************************************************************************
474 * Endian conversion macros
476 #ifdef WORDS_BIGENDIAN
478 #define htole32(x) RtlUlongByteSwap(x)
479 #define htole16(x) RtlUshortByteSwap(x)
480 #define lendian32toh(x) RtlUlongByteSwap(x)
481 #define lendian16toh(x) RtlUshortByteSwap(x)
483 #else
485 #define htole32(x) (x)
486 #define htole16(x) (x)
487 #define lendian32toh(x) (x)
488 #define lendian16toh(x) (x)
490 #endif
492 /******************************************************************************
493 * The StorageUtl_ functions are miscellaneous utility functions. Most of which
494 * are abstractions used to read values from file buffers without having to
495 * worry about bit order
497 void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
498 void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
499 void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value);
500 void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value);
501 void StorageUtl_ReadULargeInteger(const BYTE* buffer, ULONG offset,
502 ULARGE_INTEGER* value);
503 void StorageUtl_WriteULargeInteger(BYTE* buffer, ULONG offset,
504 const ULARGE_INTEGER *value);
505 void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value);
506 void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value);
507 void StorageUtl_CopyDirEntryToSTATSTG(StorageBaseImpl *storage,STATSTG* destination,
508 const DirEntry* source, int statFlags);
510 /****************************************************************************
511 * BlockChainStream definitions.
513 * The BlockChainStream class is a utility class that is used to create an
514 * abstraction of the big block chains in the storage file.
516 struct BlockChainRun
518 /* This represents a range of blocks that happen reside in consecutive sectors. */
519 ULONG firstSector;
520 ULONG firstOffset;
521 ULONG lastOffset;
524 struct BlockChainStream
526 StorageImpl* parentStorage;
527 ULONG* headOfStreamPlaceHolder;
528 DirRef ownerDirEntry;
529 struct BlockChainRun* indexCache;
530 ULONG indexCacheLen;
531 ULONG indexCacheSize;
532 ULONG tailIndex;
533 ULONG numBlocks;
537 * Methods for the BlockChainStream class.
539 BlockChainStream* BlockChainStream_Construct(
540 StorageImpl* parentStorage,
541 ULONG* headOfStreamPlaceHolder,
542 DirRef dirEntry);
544 void BlockChainStream_Destroy(
545 BlockChainStream* This);
547 HRESULT BlockChainStream_ReadAt(
548 BlockChainStream* This,
549 ULARGE_INTEGER offset,
550 ULONG size,
551 void* buffer,
552 ULONG* bytesRead);
554 HRESULT BlockChainStream_WriteAt(
555 BlockChainStream* This,
556 ULARGE_INTEGER offset,
557 ULONG size,
558 const void* buffer,
559 ULONG* bytesWritten);
561 BOOL BlockChainStream_SetSize(
562 BlockChainStream* This,
563 ULARGE_INTEGER newSize);
565 /****************************************************************************
566 * SmallBlockChainStream definitions.
568 * The SmallBlockChainStream class is a utility class that is used to create an
569 * abstraction of the small block chains in the storage file.
571 struct SmallBlockChainStream
573 StorageImpl* parentStorage;
574 DirRef ownerDirEntry;
575 ULONG* headOfStreamPlaceHolder;
579 * Methods of the SmallBlockChainStream class.
581 SmallBlockChainStream* SmallBlockChainStream_Construct(
582 StorageImpl* parentStorage,
583 ULONG* headOfStreamPlaceHolder,
584 DirRef dirEntry);
586 void SmallBlockChainStream_Destroy(
587 SmallBlockChainStream* This);
589 HRESULT SmallBlockChainStream_ReadAt(
590 SmallBlockChainStream* This,
591 ULARGE_INTEGER offset,
592 ULONG size,
593 void* buffer,
594 ULONG* bytesRead);
596 HRESULT SmallBlockChainStream_WriteAt(
597 SmallBlockChainStream* This,
598 ULARGE_INTEGER offset,
599 ULONG size,
600 const void* buffer,
601 ULONG* bytesWritten);
603 BOOL SmallBlockChainStream_SetSize(
604 SmallBlockChainStream* This,
605 ULARGE_INTEGER newSize);
608 #endif /* __STORAGE32_H__ */