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