:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / ole32 / stg_stream.c
1 /*
2  * Compound Storage (32 bit version)
3  * Stream implementation
4  *
5  * This file contains the implementation of the stream interface
6  * for streams contained in a compound storage.
7  *
8  * Copyright 1999 Francis Beaudet
9  * Copyright 1999 Thuy Nguyen
10  */
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14
15 #include <windows.h>
16 #include <ddk/ntddk.h>
17 #include <ole32/ole32.h>
18 #include "storage32.h"
19
20 #include <debug.h>
21
22
23 /*
24  * Virtual function table for the StgStreamImpl class.
25  */
26 static ICOM_VTABLE(IStream) StgStreamImpl_Vtbl =
27 {
28     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
29     StgStreamImpl_QueryInterface,
30     StgStreamImpl_AddRef,
31     StgStreamImpl_Release,
32     StgStreamImpl_Read,
33     StgStreamImpl_Write,
34     StgStreamImpl_Seek,
35     StgStreamImpl_SetSize,
36     StgStreamImpl_CopyTo,
37     StgStreamImpl_Commit,
38     StgStreamImpl_Revert,
39     StgStreamImpl_LockRegion,
40     StgStreamImpl_UnlockRegion,
41     StgStreamImpl_Stat,
42     StgStreamImpl_Clone
43 };
44
45 /******************************************************************************
46 ** StgStreamImpl implementation
47 */
48
49 /***
50  * This is the constructor for the StgStreamImpl class.
51  *
52  * Params:
53  *    parentStorage - Pointer to the storage that contains the stream to open
54  *    ownerProperty - Index of the property that points to this stream.
55  */
56 StgStreamImpl* StgStreamImpl_Construct(
57                 StorageBaseImpl* parentStorage,
58     DWORD            grfMode,
59     ULONG            ownerProperty)
60 {
61   StgStreamImpl* newStream;
62
63   newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
64   
65   if (newStream!=0)
66   {
67     /*
68      * Set-up the virtual function table and reference count.
69      */
70     ICOM_VTBL(newStream) = &StgStreamImpl_Vtbl;
71     newStream->ref       = 0;
72     
73     /*
74      * We want to nail-down the reference to the storage in case the
75      * stream out-lives the storage in the client application.
76      */
77     newStream->parentStorage = parentStorage;
78     IStorage_AddRef((IStorage*)newStream->parentStorage);
79
80     newStream->grfMode = grfMode;    
81     newStream->ownerProperty = ownerProperty;
82     
83     /*
84      * Start the stream at the begining.
85      */
86     newStream->currentPosition.u.HighPart = 0;
87     newStream->currentPosition.u.LowPart = 0;
88     
89     /*
90      * Initialize the rest of the data.
91      */
92     newStream->streamSize.u.HighPart = 0;
93     newStream->streamSize.u.LowPart  = 0;
94     newStream->bigBlockChain       = 0;
95     newStream->smallBlockChain     = 0;
96     
97     /*
98      * Read the size from the property and determine if the blocks forming
99      * this stream are large or small.
100      */
101     StgStreamImpl_OpenBlockChain(newStream);
102   }
103   
104   return newStream;
105 }
106
107 /***
108  * This is the destructor of the StgStreamImpl class.
109  *
110  * This method will clean-up all the resources used-up by the given StgStreamImpl 
111  * class. The pointer passed-in to this function will be freed and will not
112  * be valid anymore.
113  */
114 void StgStreamImpl_Destroy(StgStreamImpl* This)
115 {
116   Print(MAX_TRACE, ("(%p)\n", This));
117
118   /*
119    * Release the reference we are holding on the parent storage.
120    */
121   IStorage_Release((IStorage*)This->parentStorage);
122   This->parentStorage = 0;
123
124   /*
125    * Make sure we clean-up the block chain stream objects that we were using.
126    */
127   if (This->bigBlockChain != 0)
128   {
129     BlockChainStream_Destroy(This->bigBlockChain);
130     This->bigBlockChain = 0;
131   }
132
133   if (This->smallBlockChain != 0)
134   {
135     SmallBlockChainStream_Destroy(This->smallBlockChain);
136     This->smallBlockChain = 0;
137   }
138
139   /*
140    * Finally, free the memory used-up by the class.
141    */
142   HeapFree(GetProcessHeap(), 0, This);  
143 }
144
145 /***
146  * This implements the IUnknown method QueryInterface for this
147  * class
148  */
149 HRESULT WINAPI StgStreamImpl_QueryInterface(
150                   IStream*     iface,
151                   REFIID         riid,        /* [in] */          
152                   void**         ppvObject)   /* [iid_is][out] */ 
153 {
154   StgStreamImpl* const This=(StgStreamImpl*)iface;
155
156   /*
157    * Perform a sanity check on the parameters.
158    */
159   if (ppvObject==0)
160     return E_INVALIDARG;
161   
162   /*
163    * Initialize the return parameter.
164    */
165   *ppvObject = 0;
166   
167   /*
168    * Compare the riid with the interface IDs implemented by this object.
169    */
170   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 
171   {
172     *ppvObject = (IStream*)This;
173   }
174   else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) 
175   {
176     *ppvObject = (IStream*)This;
177   }
178   
179   /*
180    * Check that we obtained an interface.
181    */
182   if ((*ppvObject)==0)
183     return E_NOINTERFACE;
184   
185   /*
186    * Query Interface always increases the reference count by one when it is
187    * successful
188    */
189   StgStreamImpl_AddRef(iface);
190   
191   return S_OK;;
192 }
193
194 /***
195  * This implements the IUnknown method AddRef for this
196  * class
197  */
198 ULONG WINAPI StgStreamImpl_AddRef(
199                 IStream* iface)
200 {
201   StgStreamImpl* const This=(StgStreamImpl*)iface;
202
203   This->ref++;
204   
205   return This->ref;
206 }
207
208 /***
209  * This implements the IUnknown method Release for this
210  * class
211  */
212 ULONG WINAPI StgStreamImpl_Release(
213                 IStream* iface)
214 {
215   StgStreamImpl* const This=(StgStreamImpl*)iface;
216
217   ULONG newRef;
218   
219   This->ref--;
220   
221   newRef = This->ref;
222   
223   /*
224    * If the reference count goes down to 0, perform suicide.
225    */
226   if (newRef==0)
227   {
228     StgStreamImpl_Destroy(This);
229   }
230   
231   return newRef;
232 }
233
234 /***
235  * This method will open the block chain pointed by the property
236  * that describes the stream.
237  * If the stream's size is null, no chain is opened.
238  */
239 void StgStreamImpl_OpenBlockChain(
240         StgStreamImpl* This)
241 {
242   StgProperty    curProperty;
243   BOOL         readSucessful;
244
245   /*
246    * Make sure no old object is staying behind.
247    */
248   if (This->smallBlockChain != 0)
249   {
250     SmallBlockChainStream_Destroy(This->smallBlockChain);
251     This->smallBlockChain = 0;
252   }
253
254   if (This->bigBlockChain != 0)
255   {
256     BlockChainStream_Destroy(This->bigBlockChain);
257     This->bigBlockChain = 0;
258   }
259
260   /*
261    * Read the information from the property.
262    */
263   readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
264                                              This->ownerProperty,
265                                              &curProperty);
266   
267   if (readSucessful)
268   {
269     This->streamSize = curProperty.size;
270     
271     /*
272      * This code supports only streams that are <32 bits in size.
273      */
274     assert(This->streamSize.u.HighPart == 0);
275     
276     if(curProperty.startingBlock == BLOCK_END_OF_CHAIN)
277     {
278       assert( (This->streamSize.u.HighPart == 0) && (This->streamSize.u.LowPart == 0) );
279     }
280     else
281     {
282       if ( (This->streamSize.u.HighPart == 0) &&
283            (This->streamSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
284       {
285         This->smallBlockChain = SmallBlockChainStream_Construct(
286                                                                 This->parentStorage->ancestorStorage,   
287                                                                 This->ownerProperty);
288       }
289       else
290       {
291         This->bigBlockChain = BlockChainStream_Construct(
292                                                          This->parentStorage->ancestorStorage,
293                                                          NULL,
294                                                          This->ownerProperty);
295       }
296     }
297   }
298 }
299
300 /***
301  * This method is part of the ISequentialStream interface.
302  *
303  * If reads a block of information from the stream at the current
304  * position. It then moves the current position at the end of the
305  * read block
306  *
307  * See the documentation of ISequentialStream for more info.
308  */
309 HRESULT WINAPI StgStreamImpl_Read( 
310                   IStream*     iface,
311                   void*          pv,        /* [length_is][size_is][out] */
312                   ULONG          cb,        /* [in] */                     
313                   ULONG*         pcbRead)   /* [out] */                    
314 {
315   StgStreamImpl* const This=(StgStreamImpl*)iface;
316
317   ULONG bytesReadBuffer;
318   ULONG bytesToReadFromBuffer;
319
320   Print(MAX_TRACE, ("(%p, %p, %ld, %p)\n",
321         iface, pv, cb, pcbRead));
322
323   /* 
324    * If the caller is not interested in the nubmer of bytes read,
325    * we use another buffer to avoid "if" statements in the code.
326    */
327   if (pcbRead==0)
328     pcbRead = &bytesReadBuffer;
329   
330   /*
331    * Using the known size of the stream, calculate the number of bytes
332    * to read from the block chain
333    */
334   bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb);
335   
336   /*
337    * Depending on the type of chain that was opened when the stream was constructed,
338    * we delegate the work to the method that read the block chains.
339    */
340   if (This->smallBlockChain!=0)
341   {
342     SmallBlockChainStream_ReadAt(This->smallBlockChain,
343                                  This->currentPosition,
344                                  bytesToReadFromBuffer,
345                                  pv,
346                                  pcbRead);
347     
348   }
349   else if (This->bigBlockChain!=0)
350   {
351     BlockChainStream_ReadAt(This->bigBlockChain,
352                             This->currentPosition,
353                             bytesToReadFromBuffer,
354                             pv,
355                             pcbRead);
356   }
357   else
358   {
359     /*
360      * Small and big block chains are both NULL. This case will happen
361      * when a stream starts with BLOCK_END_OF_CHAIN and has size zero.
362      */
363
364     *pcbRead = 0;
365     return S_OK;
366   }
367
368   /*
369    * We should always be able to read the proper amount of data from the
370    * chain.
371    */
372   assert(bytesToReadFromBuffer == *pcbRead);
373
374   /*
375    * Advance the pointer for the number of positions read.
376    */
377   This->currentPosition.u.LowPart += *pcbRead;
378   
379   /*
380    * The function returns S_OK if the buffer was filled completely
381    * it returns S_FALSE if the end of the stream is reached before the
382    * buffer is filled
383    */
384   if(*pcbRead == cb)
385     return S_OK;
386   
387   return S_FALSE;
388 }
389         
390 /***
391  * This method is part of the ISequentialStream interface.
392  *
393  * It writes a block of information to the stream at the current
394  * position. It then moves the current position at the end of the
395  * written block. If the stream is too small to fit the block,
396  * the stream is grown to fit.
397  *
398  * See the documentation of ISequentialStream for more info.
399  */
400 HRESULT WINAPI StgStreamImpl_Write(
401                   IStream*     iface,
402                   const void*    pv,          /* [size_is][in] */ 
403                   ULONG          cb,          /* [in] */          
404                   ULONG*         pcbWritten)  /* [out] */         
405 {
406   StgStreamImpl* const This=(StgStreamImpl*)iface;
407
408   ULARGE_INTEGER newSize;
409   ULONG bytesWritten = 0;
410
411   Print(MAX_TRACE, ("(%p, %p, %ld, %p)\n",
412         iface, pv, cb, pcbWritten));
413  
414   /*
415    * Do we have permission to write to this stream?
416    */
417   if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE))) {
418       return STG_E_ACCESSDENIED;
419   }
420
421   /*
422    * If the caller is not interested in the number of bytes written,
423    * we use another buffer to avoid "if" statements in the code.
424    */
425   if (pcbWritten == 0)
426     pcbWritten = &bytesWritten;
427   
428   /*
429    * Initialize the out parameter
430    */
431   *pcbWritten = 0;
432
433   if (cb == 0)
434   {
435     return S_OK;
436   }
437   else
438   {
439     newSize.u.HighPart = 0;
440     newSize.u.LowPart = This->currentPosition.u.LowPart + cb;
441   }
442   
443   /*
444    * Verify if we need to grow the stream
445    */
446   if (newSize.u.LowPart > This->streamSize.u.LowPart)
447   {
448     /* grow stream */
449     IStream_SetSize(iface, newSize);
450   }
451   
452   /*
453    * Depending on the type of chain that was opened when the stream was constructed,
454    * we delegate the work to the method that readwrites to the block chains.
455    */
456   if (This->smallBlockChain!=0)
457   {
458     SmallBlockChainStream_WriteAt(This->smallBlockChain,
459                                   This->currentPosition,
460                                   cb,
461                                   pv,
462                                   pcbWritten);
463     
464   }
465   else if (This->bigBlockChain!=0)
466   {
467     BlockChainStream_WriteAt(This->bigBlockChain,
468                              This->currentPosition,
469                              cb,
470                              pv,
471                              pcbWritten);
472   }
473   else
474     assert(FALSE);
475   
476   /*
477    * Advance the position pointer for the number of positions written.
478    */
479   This->currentPosition.u.LowPart += *pcbWritten;
480   
481   return S_OK;
482 }
483
484 /***
485  * This method is part of the IStream interface.
486  *
487  * It will move the current stream pointer according to the parameters
488  * given.
489  *
490  * See the documentation of IStream for more info.
491  */        
492 HRESULT WINAPI StgStreamImpl_Seek( 
493                   IStream*      iface,
494                   LARGE_INTEGER   dlibMove,         /* [in] */ 
495                   DWORD           dwOrigin,         /* [in] */ 
496                   ULARGE_INTEGER* plibNewPosition) /* [out] */
497 {
498   StgStreamImpl* const This=(StgStreamImpl*)iface;
499
500   ULARGE_INTEGER newPosition;
501   LARGE_INTEGER Position;
502
503   Print(MAX_TRACE, ("(%p, %ld, %ld, %p)\n",
504         iface, dlibMove.u.LowPart, dwOrigin, plibNewPosition));
505
506   /* 
507    * The caller is allowed to pass in NULL as the new position return value.
508    * If it happens, we assign it to a dynamic variable to avoid special cases
509    * in the code below.
510    */
511   if (plibNewPosition == 0)
512   {
513     plibNewPosition = &newPosition;
514   }
515
516   /*
517    * The file pointer is moved depending on the given "function"
518    * parameter.
519    */
520   switch (dwOrigin)
521   {
522     case STREAM_SEEK_SET:
523       plibNewPosition->u.HighPart = 0;
524       plibNewPosition->u.LowPart  = 0;
525       break;
526     case STREAM_SEEK_CUR:
527       *plibNewPosition = This->currentPosition;
528       break;
529     case STREAM_SEEK_END:
530       *plibNewPosition = This->streamSize;
531       break;
532     default:
533       return STG_E_INVALIDFUNCTION;
534   }
535
536   Position = RtlLargeIntegerAdd( *((PLARGE_INTEGER)plibNewPosition), dlibMove );
537
538   plibNewPosition->QuadPart = Position.QuadPart;
539
540   /*
541    * tell the caller what we calculated
542    */
543   This->currentPosition = *plibNewPosition;
544  
545   return S_OK;
546 }
547
548 /***
549  * This method is part of the IStream interface.
550  *
551  * It will change the size of a stream.
552  *
553  * TODO: Switch from small blocks to big blocks and vice versa.
554  *
555  * See the documentation of IStream for more info.
556  */
557 HRESULT WINAPI StgStreamImpl_SetSize( 
558                                      IStream*      iface,
559                                      ULARGE_INTEGER  libNewSize)   /* [in] */ 
560 {
561   StgStreamImpl* const This=(StgStreamImpl*)iface;
562
563   StgProperty    curProperty;
564   BOOL         Success;
565
566   Print(MAX_TRACE, ("(%p, %ld)\n", iface, libNewSize.u.LowPart));
567
568   /*
569    * As documented.
570    */
571   if (libNewSize.u.HighPart != 0)
572     return STG_E_INVALIDFUNCTION;
573
574   /*
575    * Do we have permission?
576    */
577   if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
578     return STG_E_ACCESSDENIED;
579
580   if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
581     return S_OK;
582
583   /*
584    * This will happen if we're creating a stream
585    */
586   if ((This->smallBlockChain == 0) && (This->bigBlockChain == 0))
587   {
588     if (libNewSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK)
589     {
590       This->smallBlockChain = SmallBlockChainStream_Construct(
591                                     This->parentStorage->ancestorStorage,
592                                     This->ownerProperty);
593     }
594     else
595     {
596       This->bigBlockChain = BlockChainStream_Construct(
597                                 This->parentStorage->ancestorStorage,
598                                 NULL,
599                                 This->ownerProperty);
600     }
601   }
602
603   /*
604    * Read this stream's property to see if it's small blocks or big blocks
605    */
606   Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
607                                        This->ownerProperty,
608                                        &curProperty); 
609   /*
610    * Determine if we have to switch from small to big blocks or vice versa
611    */  
612   if ( (This->smallBlockChain!=0) && 
613        (curProperty.size.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
614   {
615     if (libNewSize.u.LowPart >= LIMIT_TO_USE_SMALL_BLOCK)
616     {
617       /*
618        * Transform the small block chain into a big block chain
619        */
620       This->bigBlockChain = Storage32Impl_SmallBlocksToBigBlocks(
621                                 This->parentStorage->ancestorStorage,
622                                 &This->smallBlockChain);
623     }
624   }
625
626   if (This->smallBlockChain!=0)
627   {
628     Success = SmallBlockChainStream_SetSize(This->smallBlockChain, libNewSize);
629   }
630   else
631   {
632     Success = BlockChainStream_SetSize(This->bigBlockChain, libNewSize);
633   }
634
635   /*
636    * Write to the property the new information about this stream
637    */
638   Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
639                                        This->ownerProperty,
640                                        &curProperty);
641
642   curProperty.size.u.HighPart = libNewSize.u.HighPart;
643   curProperty.size.u.LowPart = libNewSize.u.LowPart;
644   
645   if (Success)
646   {
647     StorageImpl_WriteProperty(This->parentStorage->ancestorStorage,
648                                 This->ownerProperty,
649                                 &curProperty);
650   }
651   
652   This->streamSize = libNewSize;
653   
654   return S_OK;
655 }
656         
657 /***
658  * This method is part of the IStream interface.
659  *
660  * It will copy the 'cb' Bytes to 'pstm' IStream.
661  *
662  * See the documentation of IStream for more info.
663  */
664 HRESULT WINAPI StgStreamImpl_CopyTo( 
665                                     IStream*      iface,
666                                     IStream*      pstm,         /* [unique][in] */ 
667                                     ULARGE_INTEGER  cb,           /* [in] */         
668                                     ULARGE_INTEGER* pcbRead,      /* [out] */        
669                                     ULARGE_INTEGER* pcbWritten)   /* [out] */        
670 {
671   HRESULT        hr = S_OK;
672   BYTE           tmpBuffer[128];
673   ULONG          bytesRead, bytesWritten, copySize;
674   ULARGE_INTEGER totalBytesRead;
675   ULARGE_INTEGER totalBytesWritten;
676
677   Print(MAX_TRACE, ("(%p, %p, %ld, %p, %p)\n", 
678         iface, pstm, cb.u.LowPart, pcbRead, pcbWritten));
679
680   /*
681    * Sanity check
682    */
683   if ( pstm == 0 )
684     return STG_E_INVALIDPOINTER;
685
686   totalBytesRead.u.LowPart = totalBytesRead.u.HighPart = 0;
687   totalBytesWritten.u.LowPart = totalBytesWritten.u.HighPart = 0;
688
689   /*
690    * use stack to store data temporarly
691    * there is surely more performant way of doing it, for now this basic
692    * implementation will do the job
693    */
694   while ( cb.u.LowPart > 0 )
695   {
696     if ( cb.u.LowPart >= 128 )
697       copySize = 128;
698     else
699       copySize = cb.u.LowPart;
700     
701     IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
702
703     totalBytesRead.u.LowPart += bytesRead;
704     
705     IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
706
707     totalBytesWritten.u.LowPart += bytesWritten;
708
709     /*
710      * Check that read & write operations were succesfull
711      */
712     if (bytesRead != bytesWritten)
713     {
714       hr = STG_E_MEDIUMFULL;
715       break;
716     }
717     
718     if (bytesRead!=copySize)
719       cb.u.LowPart = 0;
720     else
721       cb.u.LowPart -= bytesRead;
722   }
723
724   /*
725    * Update number of bytes read and written
726    */
727   if (pcbRead)
728   {
729     pcbRead->u.LowPart = totalBytesRead.u.LowPart;
730     pcbRead->u.HighPart = totalBytesRead.u.HighPart;
731   }
732
733   if (pcbWritten)
734   {
735     pcbWritten->u.LowPart = totalBytesWritten.u.LowPart;
736     pcbWritten->u.HighPart = totalBytesWritten.u.HighPart;
737   }
738   return hr;
739 }
740
741 /***
742  * This method is part of the IStream interface.
743  *
744  * For streams contained in structured storages, this method
745  * does nothing. This is what the documentation tells us.
746  *
747  * See the documentation of IStream for more info.
748  */        
749 HRESULT WINAPI StgStreamImpl_Commit( 
750                   IStream*      iface,
751                   DWORD           grfCommitFlags)  /* [in] */ 
752 {
753   return S_OK;
754 }
755
756 /***
757  * This method is part of the IStream interface.
758  *
759  * For streams contained in structured storages, this method
760  * does nothing. This is what the documentation tells us.
761  *
762  * See the documentation of IStream for more info.
763  */        
764 HRESULT WINAPI StgStreamImpl_Revert( 
765                   IStream* iface)
766 {
767   return S_OK;
768 }
769
770 HRESULT WINAPI StgStreamImpl_LockRegion( 
771                                         IStream*     iface,
772                                         ULARGE_INTEGER libOffset,   /* [in] */ 
773                                         ULARGE_INTEGER cb,          /* [in] */ 
774                                         DWORD          dwLockType)  /* [in] */ 
775 {
776   UNIMPLEMENTED;
777   return E_NOTIMPL;
778 }
779
780 HRESULT WINAPI StgStreamImpl_UnlockRegion( 
781                                           IStream*     iface,
782                                           ULARGE_INTEGER libOffset,   /* [in] */ 
783                                           ULARGE_INTEGER cb,          /* [in] */ 
784                                           DWORD          dwLockType)  /* [in] */ 
785 {
786   UNIMPLEMENTED;
787   return E_NOTIMPL;
788 }
789
790 /***
791  * This method is part of the IStream interface.
792  *
793  * This method returns information about the current
794  * stream.
795  *
796  * See the documentation of IStream for more info.
797  */        
798 HRESULT WINAPI StgStreamImpl_Stat( 
799                   IStream*     iface,
800                   STATSTG*       pstatstg,     /* [out] */
801                   DWORD          grfStatFlag)  /* [in] */ 
802 {
803   StgStreamImpl* const This=(StgStreamImpl*)iface;
804
805   StgProperty    curProperty;
806   BOOL         readSucessful;
807   
808   /*
809    * Read the information from the property.
810    */
811   readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
812                                              This->ownerProperty,
813                                              &curProperty);
814   
815   if (readSucessful)
816   {
817     StorageUtl_CopyPropertyToSTATSTG(pstatstg, 
818                                      &curProperty, 
819                                      grfStatFlag);
820
821     pstatstg->grfMode = This->grfMode;
822     
823     return S_OK;
824   }
825   
826   return E_FAIL;
827 }
828         
829 HRESULT WINAPI StgStreamImpl_Clone( 
830                                    IStream*     iface,
831                                    IStream**    ppstm) /* [out] */ 
832 {
833   UNIMPLEMENTED;
834   return E_NOTIMPL;
835 }