Use DrawFrameControl instead of bitmaps in certain cases.
[wine] / dlls / ole32 / storage32.h
1 /*
2  * Compound Storage (32 bit version)
3  *
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>)
7  *
8  * This include file contains definitions of types and function
9  * prototypes that are used in the many files implementing the 
10  * storage functionality
11  *
12  * Copyright 1998,1999 Francis Beaudet
13  * Copyright 1998,1999 Thuy Nguyen
14  */
15 #ifndef __STORAGE32_H__
16 #define __STORAGE32_H__
17
18 #include "wtypes.h"
19 #include "winnt.h"
20 #include "wine/obj_base.h"
21 #include "wine/obj_storage.h"
22
23 /*
24  * Definitions for the file format offsets.
25  */
26 static const ULONG OFFSET_BIGBLOCKSIZEBITS   = 0x0000001e;
27 static const ULONG OFFSET_SMALLBLOCKSIZEBITS = 0x00000020;
28 static const ULONG OFFSET_BBDEPOTCOUNT       = 0x0000002C;
29 static const ULONG OFFSET_ROOTSTARTBLOCK     = 0x00000030;
30 static const ULONG OFFSET_SBDEPOTSTART       = 0x0000003C;
31 static const ULONG OFFSET_EXTBBDEPOTSTART    = 0x00000044;
32 static const ULONG OFFSET_EXTBBDEPOTCOUNT    = 0x00000048;
33 static const ULONG OFFSET_BBDEPOTSTART       = 0x0000004C;
34 static const ULONG OFFSET_PS_NAME            = 0x00000000;
35 static const ULONG OFFSET_PS_NAMELENGTH      = 0x00000040;
36 static const ULONG OFFSET_PS_PROPERTYTYPE    = 0x00000042;
37 static const ULONG OFFSET_PS_PREVIOUSPROP    = 0x00000044;
38 static const ULONG OFFSET_PS_NEXTPROP        = 0x00000048;   
39 static const ULONG OFFSET_PS_DIRPROP         = 0x0000004C;
40 static const ULONG OFFSET_PS_GUID            = 0x00000050;
41 static const ULONG OFFSET_PS_TSS1            = 0x00000064;
42 static const ULONG OFFSET_PS_TSD1            = 0x00000068;
43 static const ULONG OFFSET_PS_TSS2            = 0x0000006C;
44 static const ULONG OFFSET_PS_TSD2            = 0x00000070;
45 static const ULONG OFFSET_PS_STARTBLOCK      = 0x00000074; 
46 static const ULONG OFFSET_PS_SIZE            = 0x00000078; 
47 static const WORD  DEF_BIG_BLOCK_SIZE_BITS   = 0x0009;
48 static const WORD  DEF_SMALL_BLOCK_SIZE_BITS = 0x0006;
49 static const WORD  DEF_BIG_BLOCK_SIZE        = 0x0200;
50 static const WORD  DEF_SMALL_BLOCK_SIZE      = 0x0040;
51 static const ULONG BLOCK_EXTBBDEPOT          = 0xFFFFFFFC;
52 static const ULONG BLOCK_SPECIAL             = 0xFFFFFFFD;
53 static const ULONG BLOCK_END_OF_CHAIN        = 0xFFFFFFFE;
54 static const ULONG BLOCK_UNUSED              = 0xFFFFFFFF;
55 static const ULONG PROPERTY_NULL             = 0xFFFFFFFF;
56
57 #define PROPERTY_NAME_MAX_LEN    0x20
58 #define PROPERTY_NAME_BUFFER_LEN 0x40             
59
60 #define PROPSET_BLOCK_SIZE 0x00000080
61
62 /*
63  * Property type of relation
64  */
65 #define PROPERTY_RELATION_PREVIOUS 0
66 #define PROPERTY_RELATION_NEXT     1
67 #define PROPERTY_RELATION_DIR      2
68
69 /*
70  * Property type constants
71  */
72 #define PROPTYPE_STORAGE 0x01
73 #define PROPTYPE_STREAM  0x02
74 #define PROPTYPE_ROOT    0x05
75
76 /*
77  * These defines assume a hardcoded blocksize. The code will assert
78  * if the blocksize is different. Some changes will have to be done if it
79  * becomes the case.
80  */
81 #define BIG_BLOCK_SIZE           0x200
82 #define COUNT_BBDEPOTINHEADER    109
83 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
84 #define NUM_BLOCKS_PER_DEPOT_BLOCK 128
85
86 /*
87  * These are signatures to detect the type of Document file.
88  */
89 static const BYTE STORAGE_magic[8]    ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
90 static const BYTE STORAGE_oldmagic[8] ={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
91
92 /*
93  * Forward declarations of all the structures used by the storage
94  * module.
95  */
96 typedef struct StorageBaseImpl     StorageBaseImpl;
97 typedef struct StorageImpl         StorageImpl;
98 typedef struct StorageInternalImpl StorageInternalImpl;
99 typedef struct BlockChainStream      BlockChainStream;
100 typedef struct SmallBlockChainStream SmallBlockChainStream;
101 typedef struct IEnumSTATSTGImpl      IEnumSTATSTGImpl;
102 typedef struct StgProperty           StgProperty;
103 typedef struct StgStreamImpl         StgStreamImpl;
104
105 /*
106  * This utility structure is used to read/write the information in a storage
107  * property.
108  */
109 struct StgProperty
110 {
111   WCHAR          name[PROPERTY_NAME_MAX_LEN];
112   WORD           sizeOfNameString;
113   BYTE           propertyType;
114   ULONG          previousProperty;
115   ULONG          nextProperty;
116   ULONG          dirProperty;
117   GUID           propertyUniqueID;
118   ULONG          timeStampS1;
119   ULONG          timeStampD1;
120   ULONG          timeStampS2;
121   ULONG          timeStampD2;
122   ULONG          startingBlock;
123   ULARGE_INTEGER size;
124 };
125
126 /*************************************************************************
127  * Big Block File support
128  *
129  * The big block file is an abstraction of a flat file separated in
130  * same sized blocks. The implementation for the methods described in 
131  * this section appear in stg_bigblockfile.c
132  */
133
134 /*
135  * Declaration of the data structures
136  */
137 typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
138 typedef struct MappedPage   MappedPage,*LPMAPPEDPAGE;
139
140 struct BigBlockFile
141 {
142   BOOL fileBased;
143   ULARGE_INTEGER filesize;
144   ULONG blocksize;
145   HANDLE hfile;
146   HANDLE hfilemap;
147   DWORD flProtect;
148   MappedPage *maplist;
149   MappedPage *victimhead, *victimtail;
150   ULONG num_victim_pages;
151   ILockBytes *pLkbyt;
152   HGLOBAL hbytearray;
153   LPVOID pbytearray;
154 };
155
156 /*
157  * Declaration of the functions used to manipulate the BigBlockFile
158  * data structure.
159  */
160 BigBlockFile*  BIGBLOCKFILE_Construct(HANDLE hFile,
161                                       ILockBytes* pLkByt,
162                                       DWORD openFlags,
163                                       ULONG blocksize,
164                                       BOOL fileBased);
165 void           BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
166 void*          BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index);
167 void*          BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index);
168 void           BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock);
169 void           BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
170 ULARGE_INTEGER BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This);
171
172 /*************************************************************************
173  * Ole Convert support
174  */
175
176 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage);
177 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName);
178
179 /****************************************************************************
180  * Storage32BaseImpl definitions.
181  *
182  * This stucture defines the base information contained in all implementations
183  * of IStorage32 contained in this filee storage implementation.
184  *
185  * In OOP terms, this is the base class for all the IStorage32 implementations
186  * contained in this file.
187  */
188 struct StorageBaseImpl
189 {
190   ICOM_VFIELD(IStorage);   /* Needs to be the first item in the stuct
191                             * since we want to cast this in a Storage32 pointer */
192
193   /*
194    * Reference count of this object
195    */
196   ULONG ref;
197   
198   /* 
199    * Ancestor storage (top level) 
200    */
201   StorageImpl* ancestorStorage;          
202   
203   /*
204    * Index of the property for the root of
205    * this storage
206    */
207   ULONG rootPropertySetIndex;
208   
209   /* 
210    * virtual Destructor method.
211    */
212   void (*v_destructor)(StorageBaseImpl*);
213 };
214
215
216 /*
217  * Prototypes for the methods of the Storage32BaseImpl class.
218  */
219 HRESULT WINAPI StorageBaseImpl_QueryInterface(
220             IStorage*        iface,
221             REFIID             riid,
222             void**             ppvObject);
223         
224 ULONG WINAPI StorageBaseImpl_AddRef( 
225             IStorage*        iface);
226         
227 ULONG WINAPI StorageBaseImpl_Release( 
228             IStorage*        iface);
229         
230 HRESULT WINAPI StorageBaseImpl_OpenStream( 
231             IStorage*        iface,
232             const OLECHAR*   pwcsName,  /* [string][in] */
233             void*              reserved1, /* [unique][in] */
234             DWORD              grfMode,   /* [in] */        
235             DWORD              reserved2, /* [in] */        
236             IStream**        ppstm);    /* [out] */   
237     
238 HRESULT WINAPI StorageBaseImpl_OpenStorage( 
239             IStorage*        iface,
240             const OLECHAR*   pwcsName,      /* [string][unique][in] */ 
241             IStorage*        pstgPriority,  /* [unique][in] */         
242             DWORD              grfMode,       /* [in] */                 
243             SNB              snbExclude,    /* [unique][in] */         
244             DWORD              reserved,      /* [in] */                 
245             IStorage**       ppstg);        /* [out] */                
246           
247 HRESULT WINAPI StorageBaseImpl_EnumElements( 
248             IStorage*        iface,
249             DWORD              reserved1, /* [in] */                  
250             void*              reserved2, /* [size_is][unique][in] */ 
251             DWORD              reserved3, /* [in] */                  
252             IEnumSTATSTG**     ppenum);   /* [out] */   
253
254 HRESULT WINAPI StorageBaseImpl_Stat( 
255             IStorage*        iface,
256             STATSTG*           pstatstg,     /* [out] */ 
257             DWORD              grfStatFlag); /* [in] */  
258
259 HRESULT WINAPI StorageBaseImpl_RenameElement(
260             IStorage*        iface,
261             const OLECHAR*   pwcsOldName,  /* [string][in] */
262             const OLECHAR*   pwcsNewName); /* [string][in] */
263
264 HRESULT WINAPI StorageBaseImpl_CreateStream(
265             IStorage*        iface,
266             const OLECHAR*   pwcsName,  /* [string][in] */
267             DWORD              grfMode,   /* [in] */
268             DWORD              reserved1, /* [in] */
269             DWORD              reserved2, /* [in] */
270             IStream**        ppstm);    /* [out] */
271
272 HRESULT WINAPI StorageBaseImpl_SetClass(
273             IStorage*        iface,
274             REFCLSID           clsid);  /* [in] */
275
276 /****************************************************************************
277  * Storage32Impl definitions.
278  *
279  * This implementation of the IStorage32 interface represents a root
280  * storage. Basically, a document file.
281  */
282 struct StorageImpl
283 {
284   ICOM_VFIELD(IStorage);   /* Needs to be the first item in the stuct
285                                       * since we want to cast this in a Storage32 pointer */
286
287   /*
288    * Declare the member of the Storage32BaseImpl class to allow
289    * casting as a Storage32BaseImpl
290    */
291   ULONG                 ref;
292   struct StorageImpl* ancestorStorage;           
293   ULONG                 rootPropertySetIndex;
294   void (*v_destructor)(struct StorageImpl*);
295   
296   /*
297    * The following data members are specific to the Storage32Impl
298    * class
299    */
300   HANDLE           hFile;      /* Physical support for the Docfile */
301   LPOLESTR         pwcsName;   /* Full path of the document file */
302
303   /*
304    * File header
305    */
306   WORD  bigBlockSizeBits;
307   WORD  smallBlockSizeBits;
308   ULONG bigBlockSize;
309   ULONG smallBlockSize;
310   ULONG bigBlockDepotCount;
311   ULONG rootStartBlock;
312   ULONG smallBlockDepotStart;
313   ULONG extBigBlockDepotStart;
314   ULONG extBigBlockDepotCount;
315   ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
316
317   ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK];
318   ULONG indexBlockDepotCached;
319   ULONG prevFreeBlock;
320
321   /*
322    * Abstraction of the big block chains for the chains of the header.
323    */
324   BlockChainStream* rootBlockChain;
325   BlockChainStream* smallBlockDepotChain;
326   BlockChainStream* smallBlockRootChain;  
327
328   /*
329    * Pointer to the big block file abstraction
330    */
331   BigBlockFile* bigBlockFile; 
332 };
333
334 /*
335  * Method declaration for the Storage32Impl class
336  */        
337
338 HRESULT WINAPI StorageImpl_CreateStorage( 
339             IStorage*      iface,
340             const OLECHAR* pwcsName,  /* [string][in] */ 
341             DWORD            grfMode,   /* [in] */ 
342             DWORD            dwStgFmt,  /* [in] */ 
343             DWORD            reserved2, /* [in] */ 
344             IStorage**     ppstg);    /* [out] */ 
345         
346 HRESULT WINAPI StorageImpl_CopyTo( 
347             IStorage*      iface,
348             DWORD          ciidExclude,  /* [in] */ 
349             const IID*     rgiidExclude, /* [size_is][unique][in] */ 
350             SNB            snbExclude, /* [unique][in] */ 
351             IStorage*    pstgDest);    /* [unique][in] */ 
352         
353 HRESULT WINAPI StorageImpl_MoveElementTo( 
354             IStorage*      iface,
355             const OLECHAR* pwcsName,    /* [string][in] */ 
356             IStorage*      pstgDest,    /* [unique][in] */ 
357             const OLECHAR* pwcsNewName, /* [string][in] */ 
358             DWORD            grfFlags);   /* [in] */ 
359         
360 HRESULT WINAPI StorageImpl_Commit( 
361             IStorage*      iface,
362             DWORD          grfCommitFlags); /* [in] */ 
363         
364 HRESULT WINAPI StorageImpl_Revert( 
365             IStorage*      iface);
366         
367 HRESULT WINAPI StorageImpl_DestroyElement( 
368             IStorage*      iface,
369             const OLECHAR* pwcsName); /* [string][in] */ 
370         
371 HRESULT WINAPI StorageImpl_SetElementTimes( 
372             IStorage*      iface,
373             const OLECHAR* pwcsName, /* [string][in] */ 
374             const FILETIME*  pctime,   /* [in] */ 
375             const FILETIME*  patime,   /* [in] */ 
376             const FILETIME*  pmtime);  /* [in] */ 
377
378 HRESULT WINAPI StorageImpl_SetStateBits( 
379             IStorage*      iface,
380             DWORD          grfStateBits, /* [in] */ 
381             DWORD          grfMask);     /* [in] */ 
382
383 HRESULT WINAPI StorageImpl_Stat(IStorage* iface,
384                                 STATSTG*  pstatstg,     /* [out] */
385                                 DWORD     grfStatFlag); /* [in] */
386
387 void StorageImpl_Destroy(
388             StorageImpl* This);
389
390 HRESULT StorageImpl_Construct(
391             StorageImpl* This,
392             HANDLE       hFile,
393             LPCOLESTR    pwcsName,
394             ILockBytes*  pLkbyt,
395             DWORD        openFlags,
396             BOOL         fileBased,
397             BOOL         fileCreate);
398
399 BOOL StorageImpl_ReadBigBlock(
400             StorageImpl* This,
401             ULONG          blockIndex,
402             void*          buffer);
403
404 BOOL StorageImpl_WriteBigBlock(
405             StorageImpl* This,
406             ULONG          blockIndex,
407             void*          buffer);
408
409 void* StorageImpl_GetROBigBlock(
410             StorageImpl* This,
411             ULONG          blockIndex);
412
413 void* StorageImpl_GetBigBlock(
414             StorageImpl* This,
415             ULONG          blockIndex);
416
417 void StorageImpl_ReleaseBigBlock(
418             StorageImpl* This,
419             void*          pBigBlock);
420
421 ULONG StorageImpl_GetNextFreeBigBlock(
422             StorageImpl* This);
423
424 void StorageImpl_FreeBigBlock(
425             StorageImpl* This,
426             ULONG blockIndex);
427
428 ULONG StorageImpl_GetNextBlockInChain(
429             StorageImpl* This,
430             ULONG blockIndex);
431
432 void StorageImpl_SetNextBlockInChain(
433             StorageImpl* This,
434             ULONG blockIndex,
435       ULONG nextBlock);
436
437 HRESULT StorageImpl_LoadFileHeader(
438             StorageImpl* This);
439
440 void StorageImpl_SaveFileHeader(
441             StorageImpl* This);
442
443 BOOL StorageImpl_ReadProperty(
444             StorageImpl* This,
445             ULONG          index,
446             StgProperty*    buffer);
447
448 BOOL StorageImpl_WriteProperty(
449             StorageImpl* This,
450             ULONG          index,
451             StgProperty*   buffer);
452
453 BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
454                       StorageImpl* This,
455                       SmallBlockChainStream** ppsbChain);
456
457 ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This,
458                                          ULONG blockIndex);
459
460 void Storage32Impl_AddBlockDepot(StorageImpl* This,
461                                  ULONG blockIndex);
462
463 ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This);
464
465 ULONG Storage32Impl_GetExtDepotBlock(StorageImpl* This,
466                                      ULONG depotIndex);
467
468 void Storage32Impl_SetExtDepotBlock(StorageImpl* This,
469                                     ULONG depotIndex,
470                                     ULONG blockIndex);
471 /****************************************************************************
472  * Storage32InternalImpl definitions.
473  *
474  * Definition of the implementation structure for the IStorage32 interface.
475  * This one implements the IStorage32 interface for storage that are
476  * inside another storage.
477  */
478 struct StorageInternalImpl
479 {
480   ICOM_VFIELD(IStorage);        /* Needs to be the first item in the stuct
481                                  * since we want to cast this in a Storage32 pointer */
482
483   /*
484    * Declare the member of the Storage32BaseImpl class to allow
485    * casting as a Storage32BaseImpl
486    */
487   ULONG                      ref;
488   struct StorageImpl* ancestorStorage;           
489   ULONG                    rootPropertySetIndex;
490   void (*v_destructor)(struct StorageInternalImpl*);
491
492   /*
493    * There is no specific data for this class.
494    */
495 };
496
497 /*
498  * Method definitions for the Storage32InternalImpl class.
499  */
500 StorageInternalImpl* StorageInternalImpl_Construct(
501             StorageImpl* ancestorStorage,       
502             ULONG          rootTropertyIndex);
503
504 void StorageInternalImpl_Destroy(
505             StorageInternalImpl* This);
506
507 HRESULT WINAPI StorageInternalImpl_Commit( 
508             IStorage*            iface,
509             DWORD                  grfCommitFlags); /* [in] */ 
510
511 HRESULT WINAPI StorageInternalImpl_Revert( 
512             IStorage*            iface);
513
514
515 /****************************************************************************
516  * IEnumSTATSTGImpl definitions.
517  *
518  * Definition of the implementation structure for the IEnumSTATSTGImpl interface.
519  * This class allows iterating through the content of a storage and to find
520  * specific items inside it.
521  */
522 struct IEnumSTATSTGImpl
523 {
524   ICOM_VFIELD(IEnumSTATSTG);    /* Needs to be the first item in the stuct
525                                          * since we want to cast this in a IEnumSTATSTG pointer */
526   
527   ULONG          ref;                   /* Reference count */
528   StorageImpl* parentStorage;         /* Reference to the parent storage */
529   ULONG          firstPropertyNode;     /* Index of the root of the storage to enumerate */
530
531   /*
532    * The current implementation of the IEnumSTATSTGImpl class uses a stack
533    * to walk the property sets to get the content of a storage. This stack
534    * is implemented by the following 3 data members
535    */
536   ULONG          stackSize;
537   ULONG          stackMaxSize;
538   ULONG*         stackToVisit;
539
540 #define ENUMSTATSGT_SIZE_INCREMENT 10
541 };
542
543 /*
544  * Method definitions for the IEnumSTATSTGImpl class.
545  */
546 HRESULT WINAPI IEnumSTATSTGImpl_QueryInterface(
547             IEnumSTATSTG*     iface,
548             REFIID            riid,
549             void**            ppvObject);
550         
551 ULONG WINAPI IEnumSTATSTGImpl_AddRef(
552             IEnumSTATSTG*     iface); 
553         
554 ULONG WINAPI IEnumSTATSTGImpl_Release(
555             IEnumSTATSTG*     iface);
556         
557 HRESULT WINAPI IEnumSTATSTGImpl_Next(
558             IEnumSTATSTG*     iface,
559             ULONG             celt,
560             STATSTG*          rgelt,
561             ULONG*            pceltFetched);
562         
563 HRESULT WINAPI IEnumSTATSTGImpl_Skip(
564             IEnumSTATSTG*     iface,
565             ULONG             celt);
566         
567 HRESULT WINAPI IEnumSTATSTGImpl_Reset(
568             IEnumSTATSTG* iface);
569         
570 HRESULT WINAPI IEnumSTATSTGImpl_Clone(
571             IEnumSTATSTG*     iface,
572             IEnumSTATSTG**    ppenum);
573
574 IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct(
575             StorageImpl* This,
576             ULONG          firstPropertyNode);
577
578 void IEnumSTATSTGImpl_Destroy(
579             IEnumSTATSTGImpl* This);
580
581 void IEnumSTATSTGImpl_PushSearchNode(
582             IEnumSTATSTGImpl* This,
583             ULONG             nodeToPush);
584
585 ULONG IEnumSTATSTGImpl_PopSearchNode(
586             IEnumSTATSTGImpl* This,
587             BOOL            remove);
588
589 ULONG IEnumSTATSTGImpl_FindProperty(
590             IEnumSTATSTGImpl* This,
591             const OLECHAR*  lpszPropName,
592             StgProperty*      buffer);
593
594 INT IEnumSTATSTGImpl_FindParentProperty(
595   IEnumSTATSTGImpl *This,
596   ULONG             childProperty,
597   StgProperty      *currentProperty,
598   ULONG            *propertyId);
599
600
601 /****************************************************************************
602  * StgStreamImpl definitions.
603  *
604  * This class imlements the IStream32 inteface and represents a stream
605  * located inside a storage object.
606  */
607 struct StgStreamImpl
608 {
609   ICOM_VFIELD(IStream);  /* Needs to be the first item in the stuct
610                                     * since we want to cast this in a IStream pointer */
611   
612   /*
613    * Reference count
614    */
615   ULONG              ref;
616
617   /*
618    * Storage that is the parent(owner) of the stream
619    */
620   StorageBaseImpl* parentStorage;
621
622   /*
623    * Access mode of this stream.
624    */
625   DWORD grfMode;
626
627   /*
628    * Index of the property that owns (points to) this stream.
629    */
630   ULONG              ownerProperty;
631
632   /*
633    * Helper variable that contains the size of the stream
634    */
635   ULARGE_INTEGER     streamSize;
636
637   /*
638    * This is the current position of the cursor in the stream
639    */
640   ULARGE_INTEGER     currentPosition;
641   
642   /*
643    * The information in the stream is represented by a chain of small blocks
644    * or a chain of large blocks. Depending on the case, one of the two
645    * following variabled points to that information.
646    */
647   BlockChainStream*      bigBlockChain;
648   SmallBlockChainStream* smallBlockChain;
649 };
650
651 /*
652  * Method definition for the StgStreamImpl class.
653  */
654 StgStreamImpl* StgStreamImpl_Construct(
655                 StorageBaseImpl* parentStorage,
656     DWORD            grfMode,
657     ULONG            ownerProperty);
658
659 void StgStreamImpl_Destroy(
660                 StgStreamImpl* This);
661
662 void StgStreamImpl_OpenBlockChain(
663                 StgStreamImpl* This);
664
665 HRESULT WINAPI StgStreamImpl_QueryInterface(
666                 IStream*      iface,
667                 REFIID         riid,            /* [in] */          
668                 void**         ppvObject);  /* [iid_is][out] */ 
669         
670 ULONG WINAPI StgStreamImpl_AddRef(
671                 IStream*      iface);
672         
673 ULONG WINAPI StgStreamImpl_Release(
674                 IStream*      iface);
675         
676 HRESULT WINAPI StgStreamImpl_Read( 
677                 IStream*      iface,
678                 void*          pv,        /* [length_is][size_is][out] */
679                 ULONG          cb,        /* [in] */                     
680                 ULONG*         pcbRead);  /* [out] */                    
681         
682 HRESULT WINAPI StgStreamImpl_Write(
683                 IStream*      iface,
684                 const void*    pv,          /* [size_is][in] */ 
685                 ULONG          cb,          /* [in] */          
686                 ULONG*         pcbWritten); /* [out] */         
687         
688 HRESULT WINAPI StgStreamImpl_Seek( 
689                 IStream*      iface,
690                 LARGE_INTEGER   dlibMove,         /* [in] */ 
691                 DWORD           dwOrigin,         /* [in] */ 
692                 ULARGE_INTEGER* plibNewPosition); /* [out] */
693         
694 HRESULT WINAPI StgStreamImpl_SetSize( 
695                 IStream*      iface,
696                 ULARGE_INTEGER  libNewSize);  /* [in] */ 
697         
698 HRESULT WINAPI StgStreamImpl_CopyTo( 
699                 IStream*      iface,
700                 IStream*      pstm,         /* [unique][in] */ 
701                 ULARGE_INTEGER  cb,           /* [in] */         
702                 ULARGE_INTEGER* pcbRead,      /* [out] */        
703                 ULARGE_INTEGER* pcbWritten);  /* [out] */        
704
705 HRESULT WINAPI StgStreamImpl_Commit( 
706                 IStream*      iface,
707                 DWORD           grfCommitFlags); /* [in] */ 
708         
709 HRESULT WINAPI StgStreamImpl_Revert( 
710                 IStream*  iface);
711         
712 HRESULT WINAPI StgStreamImpl_LockRegion( 
713                 IStream*     iface,
714                 ULARGE_INTEGER libOffset,   /* [in] */ 
715                 ULARGE_INTEGER cb,          /* [in] */ 
716                 DWORD          dwLockType); /* [in] */ 
717         
718 HRESULT WINAPI StgStreamImpl_UnlockRegion( 
719                 IStream*     iface,
720                 ULARGE_INTEGER libOffset,   /* [in] */ 
721                 ULARGE_INTEGER cb,          /* [in] */ 
722                 DWORD          dwLockType); /* [in] */ 
723         
724 HRESULT WINAPI StgStreamImpl_Stat( 
725                 IStream*     iface,
726                 STATSTG*       pstatstg,     /* [out] */
727                 DWORD          grfStatFlag); /* [in] */ 
728         
729 HRESULT WINAPI StgStreamImpl_Clone( 
730                 IStream*     iface,
731                 IStream**    ppstm);       /* [out] */ 
732
733
734 /********************************************************************************
735  * The StorageUtl_ functions are miscelaneous utility functions. Most of which are
736  * abstractions used to read values from file buffers without having to worry 
737  * about bit order
738  */
739 void StorageUtl_ReadWord(void* buffer, ULONG offset, WORD* value);
740 void StorageUtl_WriteWord(void* buffer, ULONG offset, WORD value);
741 void StorageUtl_ReadDWord(void* buffer, ULONG offset, DWORD* value);
742 void StorageUtl_WriteDWord(void* buffer, ULONG offset, DWORD value);
743 void StorageUtl_ReadGUID(void* buffer, ULONG offset, GUID* value);
744 void StorageUtl_WriteGUID(void* buffer, ULONG offset, GUID* value);
745 void StorageUtl_CopyPropertyToSTATSTG(STATSTG*     destination,
746                                              StgProperty* source,
747                                              int          statFlags);
748
749 /****************************************************************************
750  * BlockChainStream definitions.
751  *
752  * The BlockChainStream class is a utility class that is used to create an
753  * abstraction of the big block chains in the storage file.
754  */
755 struct BlockChainStream
756 {
757   StorageImpl* parentStorage;
758   ULONG*       headOfStreamPlaceHolder;
759   ULONG        ownerPropertyIndex;
760   ULONG        lastBlockNoInSequence;
761   ULONG        lastBlockNoInSequenceIndex;
762   ULONG        tailIndex;
763   ULONG        numBlocks;
764 };
765
766 /*
767  * Methods for the BlockChainStream class.
768  */
769 BlockChainStream* BlockChainStream_Construct(
770                 StorageImpl* parentStorage,     
771                 ULONG*         headOfStreamPlaceHolder,
772                 ULONG          propertyIndex);
773
774 void BlockChainStream_Destroy(
775                 BlockChainStream* This);
776
777 ULONG BlockChainStream_GetHeadOfChain(
778                 BlockChainStream* This);
779
780 BOOL BlockChainStream_ReadAt(
781                 BlockChainStream* This,
782                 ULARGE_INTEGER offset,
783                 ULONG          size,
784                 void*          buffer,
785                 ULONG*         bytesRead);
786
787 BOOL BlockChainStream_WriteAt(
788                 BlockChainStream* This,
789                 ULARGE_INTEGER offset,
790                 ULONG          size,
791                 const void*    buffer,
792                 ULONG*         bytesWritten);
793
794 BOOL BlockChainStream_SetSize(
795                 BlockChainStream* This,
796                 ULARGE_INTEGER    newSize);
797
798 ULARGE_INTEGER BlockChainStream_GetSize(
799     BlockChainStream* This);
800
801 ULONG BlockChainStream_GetCount(
802     BlockChainStream* This);
803
804 /****************************************************************************
805  * SmallBlockChainStream definitions.
806  *
807  * The SmallBlockChainStream class is a utility class that is used to create an
808  * abstraction of the small block chains in the storage file.
809  */
810 struct SmallBlockChainStream
811 {
812   StorageImpl* parentStorage;
813   ULONG          ownerPropertyIndex;
814 };
815
816 /*
817  * Methods of the SmallBlockChainStream class.
818  */
819 SmallBlockChainStream* SmallBlockChainStream_Construct(
820                StorageImpl* parentStorage,      
821                ULONG          propertyIndex);
822
823 void SmallBlockChainStream_Destroy(
824                SmallBlockChainStream* This);
825
826 ULONG SmallBlockChainStream_GetHeadOfChain(
827                SmallBlockChainStream* This);
828
829 ULONG SmallBlockChainStream_GetNextBlockInChain(
830                SmallBlockChainStream* This,
831                ULONG                  blockIndex);
832
833 void SmallBlockChainStream_SetNextBlockInChain(
834          SmallBlockChainStream* This,
835          ULONG                  blockIndex,
836          ULONG                  nextBlock);
837
838 void SmallBlockChainStream_FreeBlock(
839          SmallBlockChainStream* This,
840          ULONG                  blockIndex);
841
842 ULONG SmallBlockChainStream_GetNextFreeBlock(
843          SmallBlockChainStream* This);
844
845 BOOL SmallBlockChainStream_ReadAt(
846                SmallBlockChainStream* This,
847                ULARGE_INTEGER offset,
848                ULONG          size,
849                void*          buffer,
850                ULONG*         bytesRead);
851
852 BOOL SmallBlockChainStream_WriteAt(
853                SmallBlockChainStream* This,
854                ULARGE_INTEGER offset,
855                ULONG          size,
856                const void*    buffer,
857                ULONG*         bytesWritten);
858
859 BOOL SmallBlockChainStream_SetSize(
860                SmallBlockChainStream* This,
861                ULARGE_INTEGER          newSize);
862
863 ULARGE_INTEGER SmallBlockChainStream_GetSize(
864          SmallBlockChainStream* This);
865
866 ULONG SmallBlockChainStream_GetCount(
867          SmallBlockChainStream* This);
868
869
870 #endif /* __STORAGE32_H__ */
871
872
873