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