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