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