1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* Compound Storage (32 bit version)
|
|
|
|
* Stream implementation
|
|
|
|
*
|
|
|
|
* This file contains the implementation of the stream interface
|
|
|
|
* for streams contained in a compound storage.
|
|
|
|
*
|
|
|
|
* Copyright 1999 Francis Beaudet
|
|
|
|
* Copyright 1999 Thuy Nguyen
|
|
|
|
*/
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1999-02-28 19:14:33 +00:00
|
|
|
#include "winbase.h"
|
1999-01-30 13:24:23 +00:00
|
|
|
#include "winerror.h"
|
1999-07-04 16:02:24 +00:00
|
|
|
#include "debugtools.h"
|
1999-02-02 16:14:23 +00:00
|
|
|
#include "wine/obj_storage.h"
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
#include "storage32.h"
|
|
|
|
|
1999-05-02 11:41:10 +00:00
|
|
|
DEFAULT_DEBUG_CHANNEL(storage)
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual function table for the StgStreamImpl class.
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
static ICOM_VTABLE(IStream) StgStreamImpl_Vtbl =
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
1999-05-22 11:41:38 +00:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl_QueryInterface,
|
|
|
|
StgStreamImpl_AddRef,
|
|
|
|
StgStreamImpl_Release,
|
|
|
|
StgStreamImpl_Read,
|
|
|
|
StgStreamImpl_Write,
|
|
|
|
StgStreamImpl_Seek,
|
|
|
|
StgStreamImpl_SetSize,
|
|
|
|
StgStreamImpl_CopyTo,
|
|
|
|
StgStreamImpl_Commit,
|
|
|
|
StgStreamImpl_Revert,
|
|
|
|
StgStreamImpl_LockRegion,
|
|
|
|
StgStreamImpl_UnlockRegion,
|
|
|
|
StgStreamImpl_Stat,
|
|
|
|
StgStreamImpl_Clone
|
1999-01-30 13:24:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** StgStreamImpl implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is the constructor for the StgStreamImpl class.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* parentStorage - Pointer to the storage that contains the stream to open
|
|
|
|
* ownerProperty - Index of the property that points to this stream.
|
|
|
|
*/
|
|
|
|
StgStreamImpl* StgStreamImpl_Construct(
|
1999-02-26 11:11:13 +00:00
|
|
|
StorageBaseImpl* parentStorage,
|
2000-02-25 20:58:25 +00:00
|
|
|
DWORD grfMode,
|
|
|
|
ULONG ownerProperty)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
|
|
|
StgStreamImpl* newStream;
|
|
|
|
|
|
|
|
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
|
|
|
|
|
|
|
|
if (newStream!=0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set-up the virtual function table and reference count.
|
|
|
|
*/
|
1999-10-31 01:59:23 +00:00
|
|
|
ICOM_VTBL(newStream) = &StgStreamImpl_Vtbl;
|
|
|
|
newStream->ref = 0;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to nail-down the reference to the storage in case the
|
|
|
|
* stream out-lives the storage in the client application.
|
|
|
|
*/
|
|
|
|
newStream->parentStorage = parentStorage;
|
1999-02-26 11:11:13 +00:00
|
|
|
IStorage_AddRef((IStorage*)newStream->parentStorage);
|
2000-02-25 20:58:25 +00:00
|
|
|
|
|
|
|
newStream->grfMode = grfMode;
|
1999-01-30 13:24:23 +00:00
|
|
|
newStream->ownerProperty = ownerProperty;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the stream at the begining.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
newStream->currentPosition.s.HighPart = 0;
|
|
|
|
newStream->currentPosition.s.LowPart = 0;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the rest of the data.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
newStream->streamSize.s.HighPart = 0;
|
|
|
|
newStream->streamSize.s.LowPart = 0;
|
1999-01-30 13:24:23 +00:00
|
|
|
newStream->bigBlockChain = 0;
|
|
|
|
newStream->smallBlockChain = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the size from the property and determine if the blocks forming
|
|
|
|
* this stream are large or small.
|
|
|
|
*/
|
|
|
|
StgStreamImpl_OpenBlockChain(newStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is the destructor of the StgStreamImpl class.
|
|
|
|
*
|
|
|
|
* This method will clean-up all the resources used-up by the given StgStreamImpl
|
|
|
|
* class. The pointer passed-in to this function will be freed and will not
|
|
|
|
* be valid anymore.
|
|
|
|
*/
|
|
|
|
void StgStreamImpl_Destroy(StgStreamImpl* This)
|
|
|
|
{
|
1999-07-04 16:02:24 +00:00
|
|
|
TRACE("(%p)\n", This);
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* Release the reference we are holding on the parent storage.
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
IStorage_Release((IStorage*)This->parentStorage);
|
1999-01-30 13:24:23 +00:00
|
|
|
This->parentStorage = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we clean-up the block chain stream objects that we were using.
|
|
|
|
*/
|
|
|
|
if (This->bigBlockChain != 0)
|
|
|
|
{
|
|
|
|
BlockChainStream_Destroy(This->bigBlockChain);
|
|
|
|
This->bigBlockChain = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->smallBlockChain != 0)
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_Destroy(This->smallBlockChain);
|
|
|
|
This->smallBlockChain = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, free the memory used-up by the class.
|
|
|
|
*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method QueryInterface for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_QueryInterface(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
REFIID riid, /* [in] */
|
|
|
|
void** ppvObject) /* [iid_is][out] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if (ppvObject==0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the return parameter.
|
|
|
|
*/
|
|
|
|
*ppvObject = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare the riid with the interface IDs implemented by this object.
|
|
|
|
*/
|
|
|
|
if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
*ppvObject = (IStream*)This;
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
1999-04-24 12:00:31 +00:00
|
|
|
else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
*ppvObject = (IStream*)This;
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl_AddRef(iface);
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
return S_OK;;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method AddRef for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
ULONG WINAPI StgStreamImpl_AddRef(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ref++;
|
|
|
|
|
|
|
|
return This->ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This implements the IUnknown method Release for this
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
ULONG WINAPI StgStreamImpl_Release(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
ULONG newRef;
|
|
|
|
|
|
|
|
This->ref--;
|
|
|
|
|
|
|
|
newRef = This->ref;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
|
|
|
if (newRef==0)
|
|
|
|
{
|
|
|
|
StgStreamImpl_Destroy(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method will open the block chain pointed by the property
|
|
|
|
* that describes the stream.
|
|
|
|
* If the stream's size is null, no chain is opened.
|
|
|
|
*/
|
|
|
|
void StgStreamImpl_OpenBlockChain(
|
|
|
|
StgStreamImpl* This)
|
|
|
|
{
|
|
|
|
StgProperty curProperty;
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL readSucessful;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure no old object is staying behind.
|
|
|
|
*/
|
|
|
|
if (This->smallBlockChain != 0)
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_Destroy(This->smallBlockChain);
|
|
|
|
This->smallBlockChain = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->bigBlockChain != 0)
|
|
|
|
{
|
|
|
|
BlockChainStream_Destroy(This->bigBlockChain);
|
|
|
|
This->bigBlockChain = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the information from the property.
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ownerProperty,
|
|
|
|
&curProperty);
|
|
|
|
|
|
|
|
if (readSucessful)
|
|
|
|
{
|
|
|
|
This->streamSize = curProperty.size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code supports only streams that are <32 bits in size.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
assert(This->streamSize.s.HighPart == 0);
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
if(curProperty.startingBlock == BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
assert( (This->streamSize.s.HighPart == 0) && (This->streamSize.s.LowPart == 0) );
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
if ( (This->streamSize.s.HighPart == 0) &&
|
|
|
|
(This->streamSize.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
|
|
|
This->smallBlockChain = SmallBlockChainStream_Construct(
|
|
|
|
This->parentStorage->ancestorStorage,
|
|
|
|
This->ownerProperty);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
This->bigBlockChain = BlockChainStream_Construct(
|
|
|
|
This->parentStorage->ancestorStorage,
|
|
|
|
NULL,
|
|
|
|
This->ownerProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the ISequentialStream interface.
|
|
|
|
*
|
|
|
|
* If reads a block of information from the stream at the current
|
|
|
|
* position. It then moves the current position at the end of the
|
|
|
|
* read block
|
|
|
|
*
|
|
|
|
* See the documentation of ISequentialStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Read(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
void* pv, /* [length_is][size_is][out] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbRead) /* [out] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
ULONG bytesReadBuffer;
|
|
|
|
ULONG bytesToReadFromBuffer;
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-07-04 16:02:24 +00:00
|
|
|
TRACE("(%p, %p, %ld, %p)\n",
|
1999-05-02 11:41:10 +00:00
|
|
|
iface, pv, cb, pcbRead);
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* If the caller is not interested in the nubmer of bytes read,
|
|
|
|
* we use another buffer to avoid "if" statements in the code.
|
|
|
|
*/
|
|
|
|
if (pcbRead==0)
|
|
|
|
pcbRead = &bytesReadBuffer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Using the known size of the stream, calculate the number of bytes
|
|
|
|
* to read from the block chain
|
|
|
|
*/
|
2000-03-25 21:44:35 +00:00
|
|
|
bytesToReadFromBuffer = min( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on the type of chain that was opened when the stream was constructed,
|
|
|
|
* we delegate the work to the method that read the block chains.
|
|
|
|
*/
|
|
|
|
if (This->smallBlockChain!=0)
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_ReadAt(This->smallBlockChain,
|
|
|
|
This->currentPosition,
|
|
|
|
bytesToReadFromBuffer,
|
|
|
|
pv,
|
|
|
|
pcbRead);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (This->bigBlockChain!=0)
|
|
|
|
{
|
|
|
|
BlockChainStream_ReadAt(This->bigBlockChain,
|
|
|
|
This->currentPosition,
|
|
|
|
bytesToReadFromBuffer,
|
|
|
|
pv,
|
|
|
|
pcbRead);
|
|
|
|
}
|
|
|
|
else
|
1999-07-10 10:13:50 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Small and big block chains are both NULL. This case will happen
|
|
|
|
* when a stream starts with BLOCK_END_OF_CHAIN and has size zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
*pcbRead = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We should always be able to read the proper amount of data from the
|
|
|
|
* chain.
|
|
|
|
*/
|
|
|
|
assert(bytesToReadFromBuffer == *pcbRead);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Advance the pointer for the number of positions read.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
This->currentPosition.s.LowPart += *pcbRead;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The function returns S_OK if the buffer was filled completely
|
|
|
|
* it returns S_FALSE if the end of the stream is reached before the
|
|
|
|
* buffer is filled
|
|
|
|
*/
|
|
|
|
if(*pcbRead == cb)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the ISequentialStream interface.
|
|
|
|
*
|
|
|
|
* It writes a block of information to the stream at the current
|
|
|
|
* position. It then moves the current position at the end of the
|
|
|
|
* written block. If the stream is too small to fit the block,
|
|
|
|
* the stream is grown to fit.
|
|
|
|
*
|
|
|
|
* See the documentation of ISequentialStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Write(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
const void* pv, /* [size_is][in] */
|
|
|
|
ULONG cb, /* [in] */
|
|
|
|
ULONG* pcbWritten) /* [out] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER newSize;
|
|
|
|
ULONG bytesWritten = 0;
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-07-04 16:02:24 +00:00
|
|
|
TRACE("(%p, %p, %ld, %p)\n",
|
1999-05-02 11:41:10 +00:00
|
|
|
iface, pv, cb, pcbWritten);
|
2000-01-26 02:04:44 +00:00
|
|
|
|
2000-05-03 17:39:21 +00:00
|
|
|
/*
|
|
|
|
* Do we have permission to write to this stream?
|
|
|
|
*/
|
|
|
|
if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE))) {
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
2000-01-26 02:04:44 +00:00
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* If the caller is not interested in the number of bytes written,
|
|
|
|
* we use another buffer to avoid "if" statements in the code.
|
|
|
|
*/
|
|
|
|
if (pcbWritten == 0)
|
|
|
|
pcbWritten = &bytesWritten;
|
|
|
|
|
1999-05-02 11:41:10 +00:00
|
|
|
/*
|
|
|
|
* Initialize the out parameter
|
|
|
|
*/
|
|
|
|
*pcbWritten = 0;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
if (cb == 0)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
newSize.s.HighPart = 0;
|
|
|
|
newSize.s.LowPart = This->currentPosition.s.LowPart + cb;
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify if we need to grow the stream
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
if (newSize.s.LowPart > This->streamSize.s.LowPart)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
|
|
|
/* grow stream */
|
1999-05-02 11:41:10 +00:00
|
|
|
IStream_SetSize(iface, newSize);
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on the type of chain that was opened when the stream was constructed,
|
|
|
|
* we delegate the work to the method that readwrites to the block chains.
|
|
|
|
*/
|
|
|
|
if (This->smallBlockChain!=0)
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_WriteAt(This->smallBlockChain,
|
|
|
|
This->currentPosition,
|
|
|
|
cb,
|
|
|
|
pv,
|
|
|
|
pcbWritten);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (This->bigBlockChain!=0)
|
|
|
|
{
|
|
|
|
BlockChainStream_WriteAt(This->bigBlockChain,
|
|
|
|
This->currentPosition,
|
|
|
|
cb,
|
|
|
|
pv,
|
|
|
|
pcbWritten);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(FALSE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Advance the position pointer for the number of positions written.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
This->currentPosition.s.LowPart += *pcbWritten;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will move the current stream pointer according to the parameters
|
|
|
|
* given.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Seek(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
LARGE_INTEGER dlibMove, /* [in] */
|
|
|
|
DWORD dwOrigin, /* [in] */
|
|
|
|
ULARGE_INTEGER* plibNewPosition) /* [out] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER newPosition;
|
|
|
|
|
1999-07-04 16:02:24 +00:00
|
|
|
TRACE("(%p, %ld, %ld, %p)\n",
|
1999-09-19 14:20:33 +00:00
|
|
|
iface, dlibMove.s.LowPart, dwOrigin, plibNewPosition);
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* The caller is allowed to pass in NULL as the new position return value.
|
|
|
|
* If it happens, we assign it to a dynamic variable to avoid special cases
|
|
|
|
* in the code below.
|
|
|
|
*/
|
|
|
|
if (plibNewPosition == 0)
|
|
|
|
{
|
|
|
|
plibNewPosition = &newPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The file pointer is moved depending on the given "function"
|
|
|
|
* parameter.
|
|
|
|
*/
|
|
|
|
switch (dwOrigin)
|
|
|
|
{
|
|
|
|
case STREAM_SEEK_SET:
|
1999-09-19 14:20:33 +00:00
|
|
|
plibNewPosition->s.HighPart = 0;
|
|
|
|
plibNewPosition->s.LowPart = 0;
|
1999-01-30 13:24:23 +00:00
|
|
|
break;
|
|
|
|
case STREAM_SEEK_CUR:
|
|
|
|
*plibNewPosition = This->currentPosition;
|
|
|
|
break;
|
|
|
|
case STREAM_SEEK_END:
|
|
|
|
*plibNewPosition = This->streamSize;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
}
|
|
|
|
|
2000-02-25 20:58:25 +00:00
|
|
|
#if SIZEOF_LONG_LONG >= 8
|
|
|
|
plibNewPosition->QuadPart += dlibMove.QuadPart;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* do some multiword arithmetic:
|
|
|
|
* treat HighPart as a signed value
|
|
|
|
* treat LowPart as unsigned
|
|
|
|
* NOTE: this stuff is two's complement specific!
|
|
|
|
*/
|
|
|
|
if (dlibMove.s.HighPart < 0) { /* dlibMove is < 0 */
|
|
|
|
/* calculate the absolute value of dlibMove ... */
|
|
|
|
dlibMove.s.HighPart = -dlibMove.s.HighPart;
|
|
|
|
dlibMove.s.LowPart ^= -1;
|
|
|
|
/* ... and subtract with carry */
|
|
|
|
if (dlibMove.s.LowPart > plibNewPosition->s.LowPart) {
|
|
|
|
/* carry needed, This accounts for any underflows at [1]*/
|
|
|
|
plibNewPosition->s.HighPart -= 1;
|
|
|
|
}
|
|
|
|
plibNewPosition->s.LowPart -= dlibMove.s.LowPart; /* [1] */
|
|
|
|
plibNewPosition->s.HighPart -= dlibMove.s.HighPart;
|
|
|
|
} else {
|
|
|
|
/* add directly */
|
|
|
|
int initialLowPart = plibNewPosition->s.LowPart;
|
|
|
|
plibNewPosition->s.LowPart += dlibMove.s.LowPart;
|
|
|
|
if((plibNewPosition->s.LowPart < initialLowPart) ||
|
|
|
|
(plibNewPosition->s.LowPart < dlibMove.s.LowPart)) {
|
|
|
|
/* LowPart has rolled over => add the carry digit to HighPart */
|
|
|
|
plibNewPosition->s.HighPart++;
|
|
|
|
}
|
|
|
|
plibNewPosition->s.HighPart += dlibMove.s.HighPart;
|
|
|
|
}
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
2000-02-25 20:58:25 +00:00
|
|
|
* Check if we end-up before the beginning of the file. That should
|
|
|
|
* trigger an error.
|
1999-01-30 13:24:23 +00:00
|
|
|
*/
|
2000-02-25 20:58:25 +00:00
|
|
|
if (plibNewPosition->s.HighPart < 0) {
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
}
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
2000-02-25 20:58:25 +00:00
|
|
|
* We currently don't support files with offsets of >32 bits.
|
|
|
|
* Note that we have checked for a negative offset already
|
1999-01-30 13:24:23 +00:00
|
|
|
*/
|
2000-02-25 20:58:25 +00:00
|
|
|
assert(plibNewPosition->s.HighPart <= 0);
|
|
|
|
|
|
|
|
#endif
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
2000-02-25 20:58:25 +00:00
|
|
|
* tell the caller what we calculated
|
1999-01-30 13:24:23 +00:00
|
|
|
*/
|
|
|
|
This->currentPosition = *plibNewPosition;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will change the size of a stream.
|
|
|
|
*
|
|
|
|
* TODO: Switch from small blocks to big blocks and vice versa.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_SetSize(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER libNewSize) /* [in] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
StgProperty curProperty;
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL Success;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
TRACE("(%p, %ld)\n", iface, libNewSize.s.LowPart);
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
if (libNewSize.s.HighPart != 0)
|
1999-01-30 13:24:23 +00:00
|
|
|
return STG_E_INVALIDFUNCTION;
|
2000-02-25 20:58:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have permission?
|
|
|
|
*/
|
|
|
|
if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
if (This->streamSize.s.LowPart == libNewSize.s.LowPart)
|
1999-01-30 13:24:23 +00:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This will happen if we're creating a stream
|
|
|
|
*/
|
|
|
|
if ((This->smallBlockChain == 0) && (This->bigBlockChain == 0))
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
if (libNewSize.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
|
|
|
This->smallBlockChain = SmallBlockChainStream_Construct(
|
|
|
|
This->parentStorage->ancestorStorage,
|
|
|
|
This->ownerProperty);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
This->bigBlockChain = BlockChainStream_Construct(
|
|
|
|
This->parentStorage->ancestorStorage,
|
|
|
|
NULL,
|
|
|
|
This->ownerProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read this stream's property to see if it's small blocks or big blocks
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ownerProperty,
|
|
|
|
&curProperty);
|
|
|
|
/*
|
1999-02-13 12:10:15 +00:00
|
|
|
* Determine if we have to switch from small to big blocks or vice versa
|
1999-05-02 11:41:10 +00:00
|
|
|
*/
|
|
|
|
if ( (This->smallBlockChain!=0) &&
|
1999-09-19 14:20:33 +00:00
|
|
|
(curProperty.size.s.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
|
1999-02-13 12:10:15 +00:00
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
if (libNewSize.s.LowPart >= LIMIT_TO_USE_SMALL_BLOCK)
|
1999-02-13 12:10:15 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Transform the small block chain into a big block chain
|
|
|
|
*/
|
|
|
|
This->bigBlockChain = Storage32Impl_SmallBlocksToBigBlocks(
|
|
|
|
This->parentStorage->ancestorStorage,
|
|
|
|
&This->smallBlockChain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
if (This->smallBlockChain!=0)
|
|
|
|
{
|
|
|
|
Success = SmallBlockChainStream_SetSize(This->smallBlockChain, libNewSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Success = BlockChainStream_SetSize(This->bigBlockChain, libNewSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to the property the new information about this stream
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ownerProperty,
|
|
|
|
&curProperty);
|
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
curProperty.size.s.HighPart = libNewSize.s.HighPart;
|
|
|
|
curProperty.size.s.LowPart = libNewSize.s.LowPart;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
if (Success)
|
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
StorageImpl_WriteProperty(This->parentStorage->ancestorStorage,
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ownerProperty,
|
|
|
|
&curProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
This->streamSize = libNewSize;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-15 15:47:48 +00:00
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* It will copy the 'cb' Bytes to 'pstm' IStream.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
1999-01-30 13:24:23 +00:00
|
|
|
HRESULT WINAPI StgStreamImpl_CopyTo(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
|
|
|
IStream* pstm, /* [unique][in] */
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
ULARGE_INTEGER* pcbRead, /* [out] */
|
|
|
|
ULARGE_INTEGER* pcbWritten) /* [out] */
|
|
|
|
{
|
1999-04-15 15:47:48 +00:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BYTE tmpBuffer[128];
|
|
|
|
ULONG bytesRead, bytesWritten, copySize;
|
|
|
|
ULARGE_INTEGER totalBytesRead;
|
|
|
|
ULARGE_INTEGER totalBytesWritten;
|
|
|
|
|
1999-07-04 16:02:24 +00:00
|
|
|
TRACE("(%p, %p, %ld, %p, %p)\n",
|
1999-09-19 14:20:33 +00:00
|
|
|
iface, pstm, cb.s.LowPart, pcbRead, pcbWritten);
|
1999-05-02 11:41:10 +00:00
|
|
|
|
1999-04-15 15:47:48 +00:00
|
|
|
/*
|
|
|
|
* Sanity check
|
|
|
|
*/
|
|
|
|
if ( pstm == 0 )
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
totalBytesRead.s.LowPart = totalBytesRead.s.HighPart = 0;
|
|
|
|
totalBytesWritten.s.LowPart = totalBytesWritten.s.HighPart = 0;
|
1999-04-15 15:47:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* use stack to store data temporarly
|
|
|
|
* there is surely more performant way of doing it, for now this basic
|
|
|
|
* implementation will do the job
|
|
|
|
*/
|
1999-09-19 14:20:33 +00:00
|
|
|
while ( cb.s.LowPart > 0 )
|
1999-04-15 15:47:48 +00:00
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
if ( cb.s.LowPart >= 128 )
|
1999-04-15 15:47:48 +00:00
|
|
|
copySize = 128;
|
|
|
|
else
|
1999-09-19 14:20:33 +00:00
|
|
|
copySize = cb.s.LowPart;
|
1999-04-15 15:47:48 +00:00
|
|
|
|
1999-05-02 11:41:10 +00:00
|
|
|
IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
|
1999-04-15 15:47:48 +00:00
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
totalBytesRead.s.LowPart += bytesRead;
|
1999-04-15 15:47:48 +00:00
|
|
|
|
1999-05-02 11:41:10 +00:00
|
|
|
IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
|
1999-04-15 15:47:48 +00:00
|
|
|
|
1999-09-19 14:20:33 +00:00
|
|
|
totalBytesWritten.s.LowPart += bytesWritten;
|
1999-04-15 15:47:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that read & write operations were succesfull
|
|
|
|
*/
|
1999-05-02 11:41:10 +00:00
|
|
|
if (bytesRead != bytesWritten)
|
1999-04-15 15:47:48 +00:00
|
|
|
{
|
|
|
|
hr = STG_E_MEDIUMFULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-05-02 11:41:10 +00:00
|
|
|
if (bytesRead!=copySize)
|
1999-09-19 14:20:33 +00:00
|
|
|
cb.s.LowPart = 0;
|
1999-05-02 11:41:10 +00:00
|
|
|
else
|
1999-09-19 14:20:33 +00:00
|
|
|
cb.s.LowPart -= bytesRead;
|
1999-04-15 15:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update number of bytes read and written
|
|
|
|
*/
|
|
|
|
if (pcbRead)
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
pcbRead->s.LowPart = totalBytesRead.s.LowPart;
|
|
|
|
pcbRead->s.HighPart = totalBytesRead.s.HighPart;
|
1999-04-15 15:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pcbWritten)
|
|
|
|
{
|
1999-09-19 14:20:33 +00:00
|
|
|
pcbWritten->s.LowPart = totalBytesWritten.s.LowPart;
|
|
|
|
pcbWritten->s.HighPart = totalBytesWritten.s.HighPart;
|
1999-04-15 15:47:48 +00:00
|
|
|
}
|
|
|
|
return hr;
|
1999-01-30 13:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* For streams contained in structured storages, this method
|
|
|
|
* does nothing. This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Commit(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
DWORD grfCommitFlags) /* [in] */
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* For streams contained in structured storages, this method
|
|
|
|
* does nothing. This is what the documentation tells us.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Revert(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface)
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI StgStreamImpl_LockRegion(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
|
|
|
{
|
1999-07-04 16:02:24 +00:00
|
|
|
FIXME("not implemented!\n");
|
1999-01-30 13:24:23 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI StgStreamImpl_UnlockRegion(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
ULARGE_INTEGER libOffset, /* [in] */
|
|
|
|
ULARGE_INTEGER cb, /* [in] */
|
|
|
|
DWORD dwLockType) /* [in] */
|
|
|
|
{
|
1999-07-04 16:02:24 +00:00
|
|
|
FIXME("not implemented!\n");
|
1999-01-30 13:24:23 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This method is part of the IStream interface.
|
|
|
|
*
|
|
|
|
* This method returns information about the current
|
|
|
|
* stream.
|
|
|
|
*
|
|
|
|
* See the documentation of IStream for more info.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgStreamImpl_Stat(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
1999-01-30 13:24:23 +00:00
|
|
|
STATSTG* pstatstg, /* [out] */
|
|
|
|
DWORD grfStatFlag) /* [in] */
|
|
|
|
{
|
1999-02-18 13:26:22 +00:00
|
|
|
StgStreamImpl* const This=(StgStreamImpl*)iface;
|
|
|
|
|
1999-01-30 13:24:23 +00:00
|
|
|
StgProperty curProperty;
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL readSucessful;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the information from the property.
|
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
readSucessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
|
1999-01-30 13:24:23 +00:00
|
|
|
This->ownerProperty,
|
|
|
|
&curProperty);
|
|
|
|
|
|
|
|
if (readSucessful)
|
|
|
|
{
|
|
|
|
StorageUtl_CopyPropertyToSTATSTG(pstatstg,
|
|
|
|
&curProperty,
|
|
|
|
grfStatFlag);
|
2000-02-25 20:58:25 +00:00
|
|
|
|
|
|
|
pstatstg->grfMode = This->grfMode;
|
1999-01-30 13:24:23 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI StgStreamImpl_Clone(
|
1999-02-26 11:11:13 +00:00
|
|
|
IStream* iface,
|
|
|
|
IStream** ppstm) /* [out] */
|
1999-01-30 13:24:23 +00:00
|
|
|
{
|
1999-07-04 16:02:24 +00:00
|
|
|
FIXME("not implemented!\n");
|
1999-01-30 13:24:23 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|