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