push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / ole32 / stg_stream.c
blob53555942faff871161bda9c1d44808fea6917081
1 /*
2 * Compound Storage (32 bit version)
3 * Stream implementation
5 * This file contains the implementation of the stream interface
6 * for streams contained in a compound storage.
8 * Copyright 1999 Francis Beaudet
9 * Copyright 1999 Thuy Nguyen
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
32 #define COBJMACROS
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winerror.h"
39 #include "winternl.h"
40 #include "wine/debug.h"
42 #include "storage32.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(storage);
47 /***
48 * This is the destructor of the StgStreamImpl class.
50 * This method will clean-up all the resources used-up by the given StgStreamImpl
51 * class. The pointer passed-in to this function will be freed and will not
52 * be valid anymore.
54 static void StgStreamImpl_Destroy(StgStreamImpl* This)
56 TRACE("(%p)\n", This);
59 * Release the reference we are holding on the parent storage.
60 * IStorage_Release((IStorage*)This->parentStorage);
62 * No, don't do this. Some apps call IStorage_Release without
63 * calling IStream_Release first. If we grab a reference the
64 * file is not closed, and the app fails when it tries to
65 * reopen the file (Easy-PC, for example). Just inform the
66 * storage that we have closed the stream
69 if(This->parentStorage) {
71 StorageBaseImpl_RemoveStream(This->parentStorage, This);
75 This->parentStorage = 0;
78 * Make sure we clean-up the block chain stream objects that we were using.
80 if (This->bigBlockChain != 0)
82 BlockChainStream_Destroy(This->bigBlockChain);
83 This->bigBlockChain = 0;
86 if (This->smallBlockChain != 0)
88 SmallBlockChainStream_Destroy(This->smallBlockChain);
89 This->smallBlockChain = 0;
93 * Finally, free the memory used-up by the class.
95 HeapFree(GetProcessHeap(), 0, This);
98 /***
99 * This implements the IUnknown method QueryInterface for this
100 * class
102 static HRESULT WINAPI StgStreamImpl_QueryInterface(
103 IStream* iface,
104 REFIID riid, /* [in] */
105 void** ppvObject) /* [iid_is][out] */
107 StgStreamImpl* const This=(StgStreamImpl*)iface;
110 * Perform a sanity check on the parameters.
112 if (ppvObject==0)
113 return E_INVALIDARG;
116 * Initialize the return parameter.
118 *ppvObject = 0;
121 * Compare the riid with the interface IDs implemented by this object.
123 if (IsEqualIID(&IID_IUnknown, riid) ||
124 IsEqualIID(&IID_IPersist, riid) ||
125 IsEqualIID(&IID_IPersistStream, riid) ||
126 IsEqualIID(&IID_ISequentialStream, riid) ||
127 IsEqualIID(&IID_IStream, riid))
129 *ppvObject = This;
133 * Check that we obtained an interface.
135 if ((*ppvObject)==0)
136 return E_NOINTERFACE;
139 * Query Interface always increases the reference count by one when it is
140 * successful
142 IStream_AddRef(iface);
144 return S_OK;
147 /***
148 * This implements the IUnknown method AddRef for this
149 * class
151 static ULONG WINAPI StgStreamImpl_AddRef(
152 IStream* iface)
154 StgStreamImpl* const This=(StgStreamImpl*)iface;
155 return InterlockedIncrement(&This->ref);
158 /***
159 * This implements the IUnknown method Release for this
160 * class
162 static ULONG WINAPI StgStreamImpl_Release(
163 IStream* iface)
165 StgStreamImpl* const This=(StgStreamImpl*)iface;
167 ULONG ref;
169 ref = InterlockedDecrement(&This->ref);
172 * If the reference count goes down to 0, perform suicide.
174 if (ref==0)
176 StgStreamImpl_Destroy(This);
179 return ref;
182 /***
183 * This method will open the block chain pointed by the directory entry
184 * that describes the stream.
185 * If the stream's size is null, no chain is opened.
187 static void StgStreamImpl_OpenBlockChain(
188 StgStreamImpl* This)
190 DirEntry currentEntry;
191 BOOL readSuccessful;
194 * Make sure no old object is left over.
196 if (This->smallBlockChain != 0)
198 SmallBlockChainStream_Destroy(This->smallBlockChain);
199 This->smallBlockChain = 0;
202 if (This->bigBlockChain != 0)
204 BlockChainStream_Destroy(This->bigBlockChain);
205 This->bigBlockChain = 0;
209 * Read the information from the directory entry.
211 readSuccessful = StorageImpl_ReadDirEntry(This->parentStorage->ancestorStorage,
212 This->dirEntry,
213 &currentEntry);
215 if (readSuccessful)
217 This->streamSize = currentEntry.size;
220 * This code supports only streams that are <32 bits in size.
222 assert(This->streamSize.u.HighPart == 0);
224 if(currentEntry.startingBlock == BLOCK_END_OF_CHAIN)
226 assert( (This->streamSize.u.HighPart == 0) && (This->streamSize.u.LowPart == 0) );
228 else
230 if ( (This->streamSize.u.HighPart == 0) &&
231 (This->streamSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
233 This->smallBlockChain = SmallBlockChainStream_Construct(
234 This->parentStorage->ancestorStorage,
235 NULL,
236 This->dirEntry);
238 else
240 This->bigBlockChain = BlockChainStream_Construct(
241 This->parentStorage->ancestorStorage,
242 NULL,
243 This->dirEntry);
249 /***
250 * This method is part of the ISequentialStream interface.
252 * It reads a block of information from the stream at the current
253 * position. It then moves the current position at the end of the
254 * read block
256 * See the documentation of ISequentialStream for more info.
258 static HRESULT WINAPI StgStreamImpl_Read(
259 IStream* iface,
260 void* pv, /* [length_is][size_is][out] */
261 ULONG cb, /* [in] */
262 ULONG* pcbRead) /* [out] */
264 StgStreamImpl* const This=(StgStreamImpl*)iface;
266 ULONG bytesReadBuffer;
267 ULONG bytesToReadFromBuffer;
268 HRESULT res;
270 TRACE("(%p, %p, %d, %p)\n",
271 iface, pv, cb, pcbRead);
273 if (!This->parentStorage)
275 WARN("storage reverted\n");
276 return STG_E_REVERTED;
280 * If the caller is not interested in the number of bytes read,
281 * we use another buffer to avoid "if" statements in the code.
283 if (pcbRead==0)
284 pcbRead = &bytesReadBuffer;
287 * Using the known size of the stream, calculate the number of bytes
288 * to read from the block chain
290 bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb);
293 * Depending on the type of chain that was opened when the stream was constructed,
294 * we delegate the work to the method that reads the block chains.
296 if (This->smallBlockChain!=0)
298 res = SmallBlockChainStream_ReadAt(This->smallBlockChain,
299 This->currentPosition,
300 bytesToReadFromBuffer,
302 pcbRead);
305 else if (This->bigBlockChain!=0)
307 res = BlockChainStream_ReadAt(This->bigBlockChain,
308 This->currentPosition,
309 bytesToReadFromBuffer,
311 pcbRead);
313 else
316 * Small and big block chains are both NULL. This case will happen
317 * when a stream starts with BLOCK_END_OF_CHAIN and has size zero.
320 *pcbRead = 0;
321 res = S_OK;
322 goto end;
325 if (SUCCEEDED(res))
328 * We should always be able to read the proper amount of data from the
329 * chain.
331 assert(bytesToReadFromBuffer == *pcbRead);
334 * Advance the pointer for the number of positions read.
336 This->currentPosition.u.LowPart += *pcbRead;
339 end:
340 TRACE("<-- %08x\n", res);
341 return res;
344 /***
345 * This method is part of the ISequentialStream interface.
347 * It writes a block of information to the stream at the current
348 * position. It then moves the current position at the end of the
349 * written block. If the stream is too small to fit the block,
350 * the stream is grown to fit.
352 * See the documentation of ISequentialStream for more info.
354 static HRESULT WINAPI StgStreamImpl_Write(
355 IStream* iface,
356 const void* pv, /* [size_is][in] */
357 ULONG cb, /* [in] */
358 ULONG* pcbWritten) /* [out] */
360 StgStreamImpl* const This=(StgStreamImpl*)iface;
362 ULARGE_INTEGER newSize;
363 ULONG bytesWritten = 0;
364 HRESULT res;
366 TRACE("(%p, %p, %d, %p)\n",
367 iface, pv, cb, pcbWritten);
370 * Do we have permission to write to this stream?
372 switch(STGM_ACCESS_MODE(This->grfMode))
374 case STGM_WRITE:
375 case STGM_READWRITE:
376 break;
377 default:
378 WARN("access denied by flags: 0x%x\n", STGM_ACCESS_MODE(This->grfMode));
379 return STG_E_ACCESSDENIED;
382 if (!pv)
383 return STG_E_INVALIDPOINTER;
385 if (!This->parentStorage)
387 WARN("storage reverted\n");
388 return STG_E_REVERTED;
392 * If the caller is not interested in the number of bytes written,
393 * we use another buffer to avoid "if" statements in the code.
395 if (pcbWritten == 0)
396 pcbWritten = &bytesWritten;
399 * Initialize the out parameter
401 *pcbWritten = 0;
403 if (cb == 0)
405 TRACE("<-- S_OK, written 0\n");
406 return S_OK;
408 else
410 newSize.u.HighPart = 0;
411 newSize.u.LowPart = This->currentPosition.u.LowPart + cb;
415 * Verify if we need to grow the stream
417 if (newSize.u.LowPart > This->streamSize.u.LowPart)
419 /* grow stream */
420 res = IStream_SetSize(iface, newSize);
421 if (FAILED(res))
422 return res;
426 * Depending on the type of chain that was opened when the stream was constructed,
427 * we delegate the work to the method that readwrites to the block chains.
429 if (This->smallBlockChain!=0)
431 res = SmallBlockChainStream_WriteAt(This->smallBlockChain,
432 This->currentPosition,
435 pcbWritten);
438 else if (This->bigBlockChain!=0)
440 res = BlockChainStream_WriteAt(This->bigBlockChain,
441 This->currentPosition,
444 pcbWritten);
446 else
448 /* this should never happen because the IStream_SetSize call above will
449 * make sure a big or small block chain is created */
450 assert(FALSE);
451 res = 0;
455 * Advance the position pointer for the number of positions written.
457 This->currentPosition.u.LowPart += *pcbWritten;
459 TRACE("<-- S_OK, written %u\n", *pcbWritten);
460 return res;
463 /***
464 * This method is part of the IStream interface.
466 * It will move the current stream pointer according to the parameters
467 * given.
469 * See the documentation of IStream for more info.
471 static HRESULT WINAPI StgStreamImpl_Seek(
472 IStream* iface,
473 LARGE_INTEGER dlibMove, /* [in] */
474 DWORD dwOrigin, /* [in] */
475 ULARGE_INTEGER* plibNewPosition) /* [out] */
477 StgStreamImpl* const This=(StgStreamImpl*)iface;
479 ULARGE_INTEGER newPosition;
481 TRACE("(%p, %d, %d, %p)\n",
482 iface, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
485 * fail if the stream has no parent (as does windows)
488 if (!This->parentStorage)
490 WARN("storage reverted\n");
491 return STG_E_REVERTED;
495 * The caller is allowed to pass in NULL as the new position return value.
496 * If it happens, we assign it to a dynamic variable to avoid special cases
497 * in the code below.
499 if (plibNewPosition == 0)
501 plibNewPosition = &newPosition;
505 * The file pointer is moved depending on the given "function"
506 * parameter.
508 switch (dwOrigin)
510 case STREAM_SEEK_SET:
511 plibNewPosition->u.HighPart = 0;
512 plibNewPosition->u.LowPart = 0;
513 break;
514 case STREAM_SEEK_CUR:
515 *plibNewPosition = This->currentPosition;
516 break;
517 case STREAM_SEEK_END:
518 *plibNewPosition = This->streamSize;
519 break;
520 default:
521 WARN("invalid dwOrigin %d\n", dwOrigin);
522 return STG_E_INVALIDFUNCTION;
525 plibNewPosition->QuadPart += dlibMove.QuadPart;
528 * tell the caller what we calculated
530 This->currentPosition = *plibNewPosition;
532 return S_OK;
535 /***
536 * This method is part of the IStream interface.
538 * It will change the size of a stream.
540 * See the documentation of IStream for more info.
542 static HRESULT WINAPI StgStreamImpl_SetSize(
543 IStream* iface,
544 ULARGE_INTEGER libNewSize) /* [in] */
546 StgStreamImpl* const This=(StgStreamImpl*)iface;
548 DirEntry currentEntry;
549 BOOL Success;
551 TRACE("(%p, %d)\n", iface, libNewSize.u.LowPart);
553 if(!This->parentStorage)
555 WARN("storage reverted\n");
556 return STG_E_REVERTED;
560 * As documented.
562 if (libNewSize.u.HighPart != 0)
564 WARN("invalid value for libNewSize.u.HighPart %d\n", libNewSize.u.HighPart);
565 return STG_E_INVALIDFUNCTION;
569 * Do we have permission?
571 if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
573 WARN("access denied\n");
574 return STG_E_ACCESSDENIED;
577 /* In simple mode keep the stream size above the small block limit */
578 if (This->parentStorage->openFlags & STGM_SIMPLE)
579 libNewSize.u.LowPart = max(libNewSize.u.LowPart, LIMIT_TO_USE_SMALL_BLOCK);
581 if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
582 return S_OK;
585 * This will happen if we're creating a stream
587 if ((This->smallBlockChain == 0) && (This->bigBlockChain == 0))
589 if (libNewSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK)
591 This->smallBlockChain = SmallBlockChainStream_Construct(
592 This->parentStorage->ancestorStorage,
593 NULL,
594 This->dirEntry);
596 else
598 This->bigBlockChain = BlockChainStream_Construct(
599 This->parentStorage->ancestorStorage,
600 NULL,
601 This->dirEntry);
606 * Read this stream's size to see if it's small blocks or big blocks
608 Success = StorageImpl_ReadDirEntry(This->parentStorage->ancestorStorage,
609 This->dirEntry,
610 &currentEntry);
612 * Determine if we have to switch from small to big blocks or vice versa
614 if ( (This->smallBlockChain!=0) &&
615 (currentEntry.size.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
617 if (libNewSize.u.LowPart >= LIMIT_TO_USE_SMALL_BLOCK)
620 * Transform the small block chain into a big block chain
622 This->bigBlockChain = Storage32Impl_SmallBlocksToBigBlocks(
623 This->parentStorage->ancestorStorage,
624 &This->smallBlockChain);
627 else if ( (This->bigBlockChain!=0) &&
628 (currentEntry.size.u.LowPart >= LIMIT_TO_USE_SMALL_BLOCK) )
630 if (libNewSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK)
633 * Transform the big block chain into a small block chain
635 This->smallBlockChain = Storage32Impl_BigBlocksToSmallBlocks(
636 This->parentStorage->ancestorStorage,
637 &This->bigBlockChain);
641 if (This->smallBlockChain!=0)
643 Success = SmallBlockChainStream_SetSize(This->smallBlockChain, libNewSize);
645 else
647 Success = BlockChainStream_SetSize(This->bigBlockChain, libNewSize);
651 * Write the new information about this stream to the directory entry
653 Success = StorageImpl_ReadDirEntry(This->parentStorage->ancestorStorage,
654 This->dirEntry,
655 &currentEntry);
657 currentEntry.size.u.HighPart = libNewSize.u.HighPart;
658 currentEntry.size.u.LowPart = libNewSize.u.LowPart;
660 if (Success)
662 StorageImpl_WriteDirEntry(This->parentStorage->ancestorStorage,
663 This->dirEntry,
664 &currentEntry);
667 This->streamSize = libNewSize;
669 return S_OK;
672 /***
673 * This method is part of the IStream interface.
675 * It will copy the 'cb' Bytes to 'pstm' IStream.
677 * See the documentation of IStream for more info.
679 static HRESULT WINAPI StgStreamImpl_CopyTo(
680 IStream* iface,
681 IStream* pstm, /* [unique][in] */
682 ULARGE_INTEGER cb, /* [in] */
683 ULARGE_INTEGER* pcbRead, /* [out] */
684 ULARGE_INTEGER* pcbWritten) /* [out] */
686 StgStreamImpl* const This=(StgStreamImpl*)iface;
687 HRESULT hr = S_OK;
688 BYTE tmpBuffer[128];
689 ULONG bytesRead, bytesWritten, copySize;
690 ULARGE_INTEGER totalBytesRead;
691 ULARGE_INTEGER totalBytesWritten;
693 TRACE("(%p, %p, %d, %p, %p)\n",
694 iface, pstm, cb.u.LowPart, pcbRead, pcbWritten);
697 * Sanity check
700 if (!This->parentStorage)
702 WARN("storage reverted\n");
703 return STG_E_REVERTED;
706 if ( pstm == 0 )
707 return STG_E_INVALIDPOINTER;
709 totalBytesRead.QuadPart = 0;
710 totalBytesWritten.QuadPart = 0;
712 while ( cb.QuadPart > 0 )
714 if ( cb.QuadPart >= sizeof(tmpBuffer) )
715 copySize = sizeof(tmpBuffer);
716 else
717 copySize = cb.u.LowPart;
719 IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
721 totalBytesRead.QuadPart += bytesRead;
723 IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
725 totalBytesWritten.QuadPart += bytesWritten;
728 * Check that read & write operations were successful
730 if (bytesRead != bytesWritten)
732 hr = STG_E_MEDIUMFULL;
733 WARN("medium full\n");
734 break;
737 if (bytesRead!=copySize)
738 cb.QuadPart = 0;
739 else
740 cb.QuadPart -= bytesRead;
743 if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
744 if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
746 return hr;
749 /***
750 * This method is part of the IStream interface.
752 * For streams contained in structured storages, this method
753 * does nothing. This is what the documentation tells us.
755 * See the documentation of IStream for more info.
757 static HRESULT WINAPI StgStreamImpl_Commit(
758 IStream* iface,
759 DWORD grfCommitFlags) /* [in] */
761 StgStreamImpl* const This=(StgStreamImpl*)iface;
763 if (!This->parentStorage)
765 WARN("storage reverted\n");
766 return STG_E_REVERTED;
769 return S_OK;
772 /***
773 * This method is part of the IStream interface.
775 * For streams contained in structured storages, this method
776 * does nothing. This is what the documentation tells us.
778 * See the documentation of IStream for more info.
780 static HRESULT WINAPI StgStreamImpl_Revert(
781 IStream* iface)
783 return S_OK;
786 static HRESULT WINAPI StgStreamImpl_LockRegion(
787 IStream* iface,
788 ULARGE_INTEGER libOffset, /* [in] */
789 ULARGE_INTEGER cb, /* [in] */
790 DWORD dwLockType) /* [in] */
792 StgStreamImpl* const This=(StgStreamImpl*)iface;
794 if (!This->parentStorage)
796 WARN("storage reverted\n");
797 return STG_E_REVERTED;
800 FIXME("not implemented!\n");
801 return E_NOTIMPL;
804 static HRESULT WINAPI StgStreamImpl_UnlockRegion(
805 IStream* iface,
806 ULARGE_INTEGER libOffset, /* [in] */
807 ULARGE_INTEGER cb, /* [in] */
808 DWORD dwLockType) /* [in] */
810 StgStreamImpl* const This=(StgStreamImpl*)iface;
812 if (!This->parentStorage)
814 WARN("storage reverted\n");
815 return STG_E_REVERTED;
818 FIXME("not implemented!\n");
819 return E_NOTIMPL;
822 /***
823 * This method is part of the IStream interface.
825 * This method returns information about the current
826 * stream.
828 * See the documentation of IStream for more info.
830 static HRESULT WINAPI StgStreamImpl_Stat(
831 IStream* iface,
832 STATSTG* pstatstg, /* [out] */
833 DWORD grfStatFlag) /* [in] */
835 StgStreamImpl* const This=(StgStreamImpl*)iface;
837 DirEntry currentEntry;
838 BOOL readSuccessful;
840 TRACE("%p %p %d\n", This, pstatstg, grfStatFlag);
843 * if stream has no parent, return STG_E_REVERTED
846 if (!This->parentStorage)
848 WARN("storage reverted\n");
849 return STG_E_REVERTED;
853 * Read the information from the directory entry.
855 readSuccessful = StorageImpl_ReadDirEntry(This->parentStorage->ancestorStorage,
856 This->dirEntry,
857 &currentEntry);
859 if (readSuccessful)
861 StorageUtl_CopyDirEntryToSTATSTG(This->parentStorage,
862 pstatstg,
863 &currentEntry,
864 grfStatFlag);
866 pstatstg->grfMode = This->grfMode;
868 /* In simple create mode cbSize is the current pos */
869 if((This->parentStorage->openFlags & STGM_SIMPLE) && This->parentStorage->create)
870 pstatstg->cbSize = This->currentPosition;
872 return S_OK;
875 WARN("failed to read entry\n");
876 return E_FAIL;
879 /***
880 * This method is part of the IStream interface.
882 * This method returns a clone of the interface that allows for
883 * another seek pointer
885 * See the documentation of IStream for more info.
887 * I am not totally sure what I am doing here but I presume that this
888 * should be basically as simple as creating a new stream with the same
889 * parent etc and positioning its seek cursor.
891 static HRESULT WINAPI StgStreamImpl_Clone(
892 IStream* iface,
893 IStream** ppstm) /* [out] */
895 StgStreamImpl* const This=(StgStreamImpl*)iface;
896 HRESULT hres;
897 StgStreamImpl* new_stream;
898 LARGE_INTEGER seek_pos;
900 TRACE("%p %p\n", This, ppstm);
903 * Sanity check
906 if (!This->parentStorage)
907 return STG_E_REVERTED;
909 if ( ppstm == 0 )
910 return STG_E_INVALIDPOINTER;
912 new_stream = StgStreamImpl_Construct (This->parentStorage, This->grfMode, This->dirEntry);
914 if (!new_stream)
915 return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
917 *ppstm = (IStream*) new_stream;
918 IStream_AddRef(*ppstm);
920 seek_pos.QuadPart = This->currentPosition.QuadPart;
922 hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
924 assert (SUCCEEDED(hres));
926 return S_OK;
930 * Virtual function table for the StgStreamImpl class.
932 static const IStreamVtbl StgStreamImpl_Vtbl =
934 StgStreamImpl_QueryInterface,
935 StgStreamImpl_AddRef,
936 StgStreamImpl_Release,
937 StgStreamImpl_Read,
938 StgStreamImpl_Write,
939 StgStreamImpl_Seek,
940 StgStreamImpl_SetSize,
941 StgStreamImpl_CopyTo,
942 StgStreamImpl_Commit,
943 StgStreamImpl_Revert,
944 StgStreamImpl_LockRegion,
945 StgStreamImpl_UnlockRegion,
946 StgStreamImpl_Stat,
947 StgStreamImpl_Clone
950 /******************************************************************************
951 ** StgStreamImpl implementation
954 /***
955 * This is the constructor for the StgStreamImpl class.
957 * Params:
958 * parentStorage - Pointer to the storage that contains the stream to open
959 * dirEntry - Index of the directory entry that points to this stream.
961 StgStreamImpl* StgStreamImpl_Construct(
962 StorageBaseImpl* parentStorage,
963 DWORD grfMode,
964 DirRef dirEntry)
966 StgStreamImpl* newStream;
968 newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
970 if (newStream!=0)
973 * Set-up the virtual function table and reference count.
975 newStream->lpVtbl = &StgStreamImpl_Vtbl;
976 newStream->ref = 0;
978 newStream->parentStorage = parentStorage;
981 * We want to nail-down the reference to the storage in case the
982 * stream out-lives the storage in the client application.
984 * -- IStorage_AddRef((IStorage*)newStream->parentStorage);
986 * No, don't do this. Some apps call IStorage_Release without
987 * calling IStream_Release first. If we grab a reference the
988 * file is not closed, and the app fails when it tries to
989 * reopen the file (Easy-PC, for example)
992 newStream->grfMode = grfMode;
993 newStream->dirEntry = dirEntry;
996 * Start the stream at the beginning.
998 newStream->currentPosition.u.HighPart = 0;
999 newStream->currentPosition.u.LowPart = 0;
1002 * Initialize the rest of the data.
1004 newStream->streamSize.u.HighPart = 0;
1005 newStream->streamSize.u.LowPart = 0;
1006 newStream->bigBlockChain = 0;
1007 newStream->smallBlockChain = 0;
1010 * Read the size from the directory entry and determine if the blocks forming
1011 * this stream are large or small.
1013 StgStreamImpl_OpenBlockChain(newStream);
1015 /* add us to the storage's list of active streams */
1016 StorageBaseImpl_AddStream(parentStorage, newStream);
1019 return newStream;