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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef __STORAGE32_H__
30 #define __STORAGE32_H__
40 * Definitions for the file format offsets.
42 static const ULONG OFFSET_BIGBLOCKSIZEBITS
= 0x0000001e;
43 static const ULONG OFFSET_SMALLBLOCKSIZEBITS
= 0x00000020;
44 static const ULONG OFFSET_BBDEPOTCOUNT
= 0x0000002C;
45 static const ULONG OFFSET_ROOTSTARTBLOCK
= 0x00000030;
46 static const ULONG OFFSET_SBDEPOTSTART
= 0x0000003C;
47 static const ULONG OFFSET_SBDEPOTCOUNT
= 0x00000040;
48 static const ULONG OFFSET_EXTBBDEPOTSTART
= 0x00000044;
49 static const ULONG OFFSET_EXTBBDEPOTCOUNT
= 0x00000048;
50 static const ULONG OFFSET_BBDEPOTSTART
= 0x0000004C;
51 static const ULONG OFFSET_PS_NAME
= 0x00000000;
52 static const ULONG OFFSET_PS_NAMELENGTH
= 0x00000040;
53 static const ULONG OFFSET_PS_PROPERTYTYPE
= 0x00000042;
54 static const ULONG OFFSET_PS_PREVIOUSPROP
= 0x00000044;
55 static const ULONG OFFSET_PS_NEXTPROP
= 0x00000048;
56 static const ULONG OFFSET_PS_DIRPROP
= 0x0000004C;
57 static const ULONG OFFSET_PS_GUID
= 0x00000050;
58 static const ULONG OFFSET_PS_TSS1
= 0x00000064;
59 static const ULONG OFFSET_PS_TSD1
= 0x00000068;
60 static const ULONG OFFSET_PS_TSS2
= 0x0000006C;
61 static const ULONG OFFSET_PS_TSD2
= 0x00000070;
62 static const ULONG OFFSET_PS_STARTBLOCK
= 0x00000074;
63 static const ULONG OFFSET_PS_SIZE
= 0x00000078;
64 static const WORD DEF_BIG_BLOCK_SIZE_BITS
= 0x0009;
65 static const WORD DEF_SMALL_BLOCK_SIZE_BITS
= 0x0006;
66 static const WORD DEF_BIG_BLOCK_SIZE
= 0x0200;
67 static const WORD DEF_SMALL_BLOCK_SIZE
= 0x0040;
68 static const ULONG BLOCK_EXTBBDEPOT
= 0xFFFFFFFC;
69 static const ULONG BLOCK_SPECIAL
= 0xFFFFFFFD;
70 static const ULONG BLOCK_END_OF_CHAIN
= 0xFFFFFFFE;
71 static const ULONG BLOCK_UNUSED
= 0xFFFFFFFF;
72 static const ULONG PROPERTY_NULL
= 0xFFFFFFFF;
74 #define PROPERTY_NAME_MAX_LEN 0x20
75 #define PROPERTY_NAME_BUFFER_LEN 0x40
77 #define PROPSET_BLOCK_SIZE 0x00000080
80 * Property type of relation
82 #define PROPERTY_RELATION_PREVIOUS 0
83 #define PROPERTY_RELATION_NEXT 1
84 #define PROPERTY_RELATION_DIR 2
87 * Property type constants
89 #define PROPTYPE_STORAGE 0x01
90 #define PROPTYPE_STREAM 0x02
91 #define PROPTYPE_ROOT 0x05
94 * These defines assume a hardcoded blocksize. The code will assert
95 * if the blocksize is different. Some changes will have to be done if it
98 #define BIG_BLOCK_SIZE 0x200
99 #define COUNT_BBDEPOTINHEADER 109
100 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
101 #define NUM_BLOCKS_PER_DEPOT_BLOCK 128
103 #define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
104 #define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
105 #define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
107 #define STGM_KNOWN_FLAGS (0xf0ff | \
108 STGM_TRANSACTED | STGM_CONVERT | STGM_PRIORITY | STGM_NOSCRATCH | \
109 STGM_NOSNAPSHOT | STGM_DIRECT_SWMR | STGM_DELETEONRELEASE | STGM_SIMPLE)
112 * These are signatures to detect the type of Document file.
114 static const BYTE STORAGE_magic
[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
115 static const BYTE STORAGE_oldmagic
[8] ={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
118 * Forward declarations of all the structures used by the storage
121 typedef struct StorageBaseImpl StorageBaseImpl
;
122 typedef struct StorageImpl StorageImpl
;
123 typedef struct StorageInternalImpl StorageInternalImpl
;
124 typedef struct BlockChainStream BlockChainStream
;
125 typedef struct SmallBlockChainStream SmallBlockChainStream
;
126 typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl
;
127 typedef struct StgProperty StgProperty
;
128 typedef struct StgStreamImpl StgStreamImpl
;
131 * This utility structure is used to read/write the information in a storage
136 WCHAR name
[PROPERTY_NAME_MAX_LEN
];
137 WORD sizeOfNameString
;
139 ULONG previousProperty
;
142 GUID propertyUniqueID
;
151 /*************************************************************************
152 * Big Block File support
154 * The big block file is an abstraction of a flat file separated in
155 * same sized blocks. The implementation for the methods described in
156 * this section appear in stg_bigblockfile.c
160 * Declaration of the data structures
162 typedef struct BigBlockFile BigBlockFile
,*LPBIGBLOCKFILE
;
163 typedef struct MappedPage MappedPage
,*LPMAPPEDPAGE
;
168 ULARGE_INTEGER filesize
;
174 MappedPage
*victimhead
, *victimtail
;
175 ULONG num_victim_pages
;
182 * Declaration of the functions used to manipulate the BigBlockFile
185 BigBlockFile
* BIGBLOCKFILE_Construct(HANDLE hFile
,
190 void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This
);
191 void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This
, ULONG index
);
192 void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This
, ULONG index
);
193 void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This
, void *pBlock
);
194 void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This
, ULARGE_INTEGER newSize
);
195 ULARGE_INTEGER
BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This
);
197 /*************************************************************************
198 * Ole Convert support
201 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage
);
202 HRESULT
OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage
, LPCSTR strOleTypeName
);
204 /****************************************************************************
205 * Storage32BaseImpl definitions.
207 * This structure defines the base information contained in all implementations
208 * of IStorage32 contained in this file storage implementation.
210 * In OOP terms, this is the base class for all the IStorage32 implementations
211 * contained in this file.
213 struct StorageBaseImpl
215 IStorageVtbl
*lpVtbl
; /* Needs to be the first item in the struct
216 * since we want to cast this in a Storage32 pointer */
218 IPropertySetStorageVtbl
*pssVtbl
; /* interface for adding a properties stream */
221 * Reference count of this object
226 * Ancestor storage (top level)
228 StorageImpl
* ancestorStorage
;
231 * Index of the property for the root of
234 ULONG rootPropertySetIndex
;
237 * virtual Destructor method.
239 void (*v_destructor
)(StorageBaseImpl
*);
243 /****************************************************************************
244 * Storage32Impl definitions.
246 * This implementation of the IStorage32 interface represents a root
247 * storage. Basically, a document file.
251 struct StorageBaseImpl base
;
254 * The following data members are specific to the Storage32Impl
257 HANDLE hFile
; /* Physical support for the Docfile */
258 LPOLESTR pwcsName
; /* Full path of the document file */
260 /* FIXME: should this be in Storage32BaseImpl ? */
261 WCHAR filename
[PROPERTY_NAME_BUFFER_LEN
];
266 WORD bigBlockSizeBits
;
267 WORD smallBlockSizeBits
;
269 ULONG smallBlockSize
;
270 ULONG bigBlockDepotCount
;
271 ULONG rootStartBlock
;
272 ULONG smallBlockDepotStart
;
273 ULONG extBigBlockDepotStart
;
274 ULONG extBigBlockDepotCount
;
275 ULONG bigBlockDepotStart
[COUNT_BBDEPOTINHEADER
];
277 ULONG blockDepotCached
[NUM_BLOCKS_PER_DEPOT_BLOCK
];
278 ULONG indexBlockDepotCached
;
282 * Abstraction of the big block chains for the chains of the header.
284 BlockChainStream
* rootBlockChain
;
285 BlockChainStream
* smallBlockDepotChain
;
286 BlockChainStream
* smallBlockRootChain
;
289 * Pointer to the big block file abstraction
291 BigBlockFile
* bigBlockFile
;
294 void StorageImpl_Destroy(
295 StorageBaseImpl
* This
);
297 HRESULT
StorageImpl_Construct(
306 BOOL
StorageImpl_ReadBigBlock(
311 BOOL
StorageImpl_WriteBigBlock(
316 void* StorageImpl_GetROBigBlock(
320 void* StorageImpl_GetBigBlock(
324 void StorageImpl_ReleaseBigBlock(
328 ULONG
StorageImpl_GetNextFreeBigBlock(
331 void StorageImpl_FreeBigBlock(
335 HRESULT
StorageImpl_GetNextBlockInChain(
338 ULONG
* nextBlockIndex
);
340 void StorageImpl_SetNextBlockInChain(
345 HRESULT
StorageImpl_LoadFileHeader(
348 void StorageImpl_SaveFileHeader(
351 BOOL
StorageImpl_ReadProperty(
354 StgProperty
* buffer
);
356 BOOL
StorageImpl_WriteProperty(
359 StgProperty
* buffer
);
361 BlockChainStream
* Storage32Impl_SmallBlocksToBigBlocks(
363 SmallBlockChainStream
** ppsbChain
);
365 ULONG
Storage32Impl_GetNextExtendedBlock(StorageImpl
* This
,
368 void Storage32Impl_AddBlockDepot(StorageImpl
* This
,
371 ULONG
Storage32Impl_AddExtBlockDepot(StorageImpl
* This
);
373 ULONG
Storage32Impl_GetExtDepotBlock(StorageImpl
* This
,
376 void Storage32Impl_SetExtDepotBlock(StorageImpl
* This
,
379 /****************************************************************************
380 * Storage32InternalImpl definitions.
382 * Definition of the implementation structure for the IStorage32 interface.
383 * This one implements the IStorage32 interface for storage that are
384 * inside another storage.
386 struct StorageInternalImpl
388 struct StorageBaseImpl base
;
391 * There is no specific data for this class.
396 * Method definitions for the Storage32InternalImpl class.
398 StorageInternalImpl
* StorageInternalImpl_Construct(
399 StorageImpl
* ancestorStorage
,
400 ULONG rootTropertyIndex
);
402 void StorageInternalImpl_Destroy(
403 StorageBaseImpl
* This
);
405 HRESULT WINAPI
StorageInternalImpl_Commit(
407 DWORD grfCommitFlags
); /* [in] */
409 HRESULT WINAPI
StorageInternalImpl_Revert(
413 /****************************************************************************
414 * IEnumSTATSTGImpl definitions.
416 * Definition of the implementation structure for the IEnumSTATSTGImpl interface.
417 * This class allows iterating through the content of a storage and to find
418 * specific items inside it.
420 struct IEnumSTATSTGImpl
422 IEnumSTATSTGVtbl
*lpVtbl
; /* Needs to be the first item in the struct
423 * since we want to cast this in an IEnumSTATSTG pointer */
425 ULONG ref
; /* Reference count */
426 StorageImpl
* parentStorage
; /* Reference to the parent storage */
427 ULONG firstPropertyNode
; /* Index of the root of the storage to enumerate */
430 * The current implementation of the IEnumSTATSTGImpl class uses a stack
431 * to walk the property sets to get the content of a storage. This stack
432 * is implemented by the following 3 data members
438 #define ENUMSTATSGT_SIZE_INCREMENT 10
441 IEnumSTATSTGImpl
* IEnumSTATSTGImpl_Construct(
443 ULONG firstPropertyNode
);
445 void IEnumSTATSTGImpl_Destroy(
446 IEnumSTATSTGImpl
* This
);
448 void IEnumSTATSTGImpl_PushSearchNode(
449 IEnumSTATSTGImpl
* This
,
452 ULONG
IEnumSTATSTGImpl_PopSearchNode(
453 IEnumSTATSTGImpl
* This
,
456 ULONG
IEnumSTATSTGImpl_FindProperty(
457 IEnumSTATSTGImpl
* This
,
458 const OLECHAR
* lpszPropName
,
459 StgProperty
* buffer
);
461 INT
IEnumSTATSTGImpl_FindParentProperty(
462 IEnumSTATSTGImpl
*This
,
464 StgProperty
*currentProperty
,
468 /****************************************************************************
469 * StgStreamImpl definitions.
471 * This class imlements the IStream32 inteface and represents a stream
472 * located inside a storage object.
476 IStreamVtbl
*lpVtbl
; /* Needs to be the first item in the struct
477 * since we want to cast this to an IStream pointer */
485 * Storage that is the parent(owner) of the stream
487 StorageBaseImpl
* parentStorage
;
490 * Access mode of this stream.
495 * Index of the property that owns (points to) this stream.
500 * Helper variable that contains the size of the stream
502 ULARGE_INTEGER streamSize
;
505 * This is the current position of the cursor in the stream
507 ULARGE_INTEGER currentPosition
;
510 * The information in the stream is represented by a chain of small blocks
511 * or a chain of large blocks. Depending on the case, one of the two
512 * following variabled points to that information.
514 BlockChainStream
* bigBlockChain
;
515 SmallBlockChainStream
* smallBlockChain
;
519 * Method definition for the StgStreamImpl class.
521 StgStreamImpl
* StgStreamImpl_Construct(
522 StorageBaseImpl
* parentStorage
,
524 ULONG ownerProperty
);
527 /********************************************************************************
528 * The StorageUtl_ functions are miscelaneous utility functions. Most of which are
529 * abstractions used to read values from file buffers without having to worry
532 void StorageUtl_ReadWord(const BYTE
* buffer
, ULONG offset
, WORD
* value
);
533 void StorageUtl_WriteWord(BYTE
* buffer
, ULONG offset
, WORD value
);
534 void StorageUtl_ReadDWord(const BYTE
* buffer
, ULONG offset
, DWORD
* value
);
535 void StorageUtl_WriteDWord(BYTE
* buffer
, ULONG offset
, DWORD value
);
536 void StorageUtl_ReadGUID(const BYTE
* buffer
, ULONG offset
, GUID
* value
);
537 void StorageUtl_WriteGUID(BYTE
* buffer
, ULONG offset
, const GUID
* value
);
538 void StorageUtl_CopyPropertyToSTATSTG(STATSTG
* destination
,
542 /****************************************************************************
543 * BlockChainStream definitions.
545 * The BlockChainStream class is a utility class that is used to create an
546 * abstraction of the big block chains in the storage file.
548 struct BlockChainStream
550 StorageImpl
* parentStorage
;
551 ULONG
* headOfStreamPlaceHolder
;
552 ULONG ownerPropertyIndex
;
553 ULONG lastBlockNoInSequence
;
554 ULONG lastBlockNoInSequenceIndex
;
560 * Methods for the BlockChainStream class.
562 BlockChainStream
* BlockChainStream_Construct(
563 StorageImpl
* parentStorage
,
564 ULONG
* headOfStreamPlaceHolder
,
565 ULONG propertyIndex
);
567 void BlockChainStream_Destroy(
568 BlockChainStream
* This
);
570 ULONG
BlockChainStream_GetHeadOfChain(
571 BlockChainStream
* This
);
573 BOOL
BlockChainStream_ReadAt(
574 BlockChainStream
* This
,
575 ULARGE_INTEGER offset
,
580 BOOL
BlockChainStream_WriteAt(
581 BlockChainStream
* This
,
582 ULARGE_INTEGER offset
,
585 ULONG
* bytesWritten
);
587 BOOL
BlockChainStream_SetSize(
588 BlockChainStream
* This
,
589 ULARGE_INTEGER newSize
);
591 ULARGE_INTEGER
BlockChainStream_GetSize(
592 BlockChainStream
* This
);
594 ULONG
BlockChainStream_GetCount(
595 BlockChainStream
* This
);
597 /****************************************************************************
598 * SmallBlockChainStream definitions.
600 * The SmallBlockChainStream class is a utility class that is used to create an
601 * abstraction of the small block chains in the storage file.
603 struct SmallBlockChainStream
605 StorageImpl
* parentStorage
;
606 ULONG ownerPropertyIndex
;
610 * Methods of the SmallBlockChainStream class.
612 SmallBlockChainStream
* SmallBlockChainStream_Construct(
613 StorageImpl
* parentStorage
,
614 ULONG propertyIndex
);
616 void SmallBlockChainStream_Destroy(
617 SmallBlockChainStream
* This
);
619 ULONG
SmallBlockChainStream_GetHeadOfChain(
620 SmallBlockChainStream
* This
);
622 HRESULT
SmallBlockChainStream_GetNextBlockInChain(
623 SmallBlockChainStream
* This
,
625 ULONG
* nextBlockIndex
);
627 void SmallBlockChainStream_SetNextBlockInChain(
628 SmallBlockChainStream
* This
,
632 void SmallBlockChainStream_FreeBlock(
633 SmallBlockChainStream
* This
,
636 ULONG
SmallBlockChainStream_GetNextFreeBlock(
637 SmallBlockChainStream
* This
);
639 BOOL
SmallBlockChainStream_ReadAt(
640 SmallBlockChainStream
* This
,
641 ULARGE_INTEGER offset
,
646 BOOL
SmallBlockChainStream_WriteAt(
647 SmallBlockChainStream
* This
,
648 ULARGE_INTEGER offset
,
651 ULONG
* bytesWritten
);
653 BOOL
SmallBlockChainStream_SetSize(
654 SmallBlockChainStream
* This
,
655 ULARGE_INTEGER newSize
);
657 ULARGE_INTEGER
SmallBlockChainStream_GetSize(
658 SmallBlockChainStream
* This
);
660 ULONG
SmallBlockChainStream_GetCount(
661 SmallBlockChainStream
* This
);
664 #endif /* __STORAGE32_H__ */