[OLE32]
authorChristoph von Wittich <christoph_vw@reactos.org>
Sun, 21 Mar 2010 13:00:22 +0000 (13:00 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Sun, 21 Mar 2010 13:00:22 +0000 (13:00 +0000)
sync ole32 with wine 1.1.41

svn path=/trunk/; revision=46295

reactos/dll/win32/ole32/compobj.c
reactos/dll/win32/ole32/ifs.h [deleted file]
reactos/dll/win32/ole32/ole16.c [deleted file]
reactos/dll/win32/ole32/stg_bigblockfile.c
reactos/dll/win32/ole32/stg_prop.c
reactos/dll/win32/ole32/storage32.c
reactos/dll/win32/ole32/storage32.h

index 583a9cb..12f8314 100644 (file)
@@ -2956,7 +2956,7 @@ HRESULT WINAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID clsidNew)
     HRESULT res = S_OK;
     LONG len = sizeof(szClsidNew);
 
-    FIXME("(%s,%p)\n", debugstr_guid(clsidOld), clsidNew);
+    TRACE("(%s,%p)\n", debugstr_guid(clsidOld), clsidNew);
     *clsidNew = *clsidOld; /* copy over old value */
 
     res = COM_OpenKeyForCLSID(clsidOld, wszTreatAs, KEY_READ, &hkey);
diff --git a/reactos/dll/win32/ole32/ifs.h b/reactos/dll/win32/ole32/ifs.h
deleted file mode 100644 (file)
index 4c4287f..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 1997 Marcus Meissner
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef __WINE_OLE_IFS_H
-#define __WINE_OLE_IFS_H
-
-#include <stdarg.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "objbase.h"
-
-typedef CHAR OLECHAR16;
-typedef LPSTR LPOLESTR16;
-typedef LPCSTR LPCOLESTR16;
-
-#define STDMETHOD16CALLTYPE __cdecl
-#define STDMETHOD16(m) HRESULT (STDMETHOD16CALLTYPE *m)
-#define STDMETHOD16_(t,m) t (STDMETHOD16CALLTYPE *m)
-
-
-/***********************************************************************
- * IMalloc16 interface
- */
-
-typedef struct IMalloc16 *LPMALLOC16;
-
-#define INTERFACE IMalloc16
-DECLARE_INTERFACE_(IMalloc16,IUnknown)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD16_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
-    STDMETHOD16_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD16_(ULONG,Release)(THIS) PURE;
-    /*** IMalloc16 methods ***/
-    STDMETHOD16_(LPVOID,Alloc)(THIS_ DWORD   cb) PURE;
-    STDMETHOD16_(LPVOID,Realloc)(THIS_ LPVOID  pv, DWORD  cb) PURE;
-    STDMETHOD16_(void,Free)(THIS_ LPVOID  pv) PURE;
-    STDMETHOD16_(DWORD,GetSize)(THIS_ LPVOID  pv) PURE;
-    STDMETHOD16_(INT16,DidAlloc)(THIS_ LPVOID  pv) PURE;
-    STDMETHOD16_(LPVOID,HeapMinimize)(THIS) PURE;
-};
-#undef INTERFACE
-
-/**********************************************************************/
-
-typedef struct ILockBytes16 *LPLOCKBYTES16;
-
-#define INTERFACE ILockBytes16
-DECLARE_INTERFACE_(ILockBytes16,IUnknown)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD16_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
-    STDMETHOD16_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD16_(ULONG,Release)(THIS) PURE;
-    /*** ILockBytes16 methods ***/
-    STDMETHOD16(ReadAt)(THIS_ ULARGE_INTEGER ulOffset, void *pv, ULONG  cb, ULONG *pcbRead) PURE;
-    STDMETHOD16(WriteAt)(THIS_ ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten) PURE;
-    STDMETHOD16(Flush)(THIS) PURE;
-    STDMETHOD16(SetSize)(THIS_ ULARGE_INTEGER cb) PURE;
-    STDMETHOD16(LockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER  cb, DWORD dwLockType) PURE;
-    STDMETHOD16(UnlockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER  cb, DWORD dwLockType) PURE;
-    STDMETHOD16(Stat)(THIS_ STATSTG *pstatstg, DWORD grfStatFlag) PURE;
-};
-#undef INTERFACE
-
-/**********************************************************************/
-
-typedef struct tagSTATSTG16
-{
-    LPOLESTR16 pwcsName;
-    DWORD type;
-    ULARGE_INTEGER cbSize;
-    FILETIME mtime;
-    FILETIME ctime;
-    FILETIME atime;
-    DWORD grfMode;
-    DWORD grfLocksSupported;
-    CLSID clsid;
-    DWORD grfStateBits;
-    DWORD reserved;
-} STATSTG16;
-
-typedef struct IStream16 *LPSTREAM16;
-
-#define INTERFACE IStream16
-DECLARE_INTERFACE_(IStream16,ISequentialStream)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD16_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
-    STDMETHOD16_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD16_(ULONG,Release)(THIS) PURE;
-    /*** ISequentialStream methods ***/
-    STDMETHOD16_(HRESULT,Read)(THIS_ void* pv, ULONG cb, ULONG* pcbRead) PURE;
-    STDMETHOD16_(HRESULT,Write)(THIS_ const void* pv, ULONG cb, ULONG* pcbWritten) PURE;
-    /*** IStream16 methods ***/
-    STDMETHOD16(Seek)(THIS_ LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) PURE;
-    STDMETHOD16(SetSize)(THIS_ ULARGE_INTEGER libNewSize) PURE;
-    STDMETHOD16(CopyTo)(THIS_ IStream16* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) PURE;
-    STDMETHOD16(Commit)(THIS_ DWORD grfCommitFlags) PURE;
-    STDMETHOD16(Revert)(THIS) PURE;
-    STDMETHOD16(LockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE;
-    STDMETHOD16(UnlockRegion)(THIS_ ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) PURE;
-    STDMETHOD16(Stat)(THIS_ STATSTG* pstatstg, DWORD grfStatFlag) PURE;
-    STDMETHOD16(Clone)(THIS_ IStream16** ppstm) PURE;
-};
-#undef INTERFACE
-
-/**********************************************************************/
-
-typedef OLECHAR16 **SNB16;
-
-typedef struct IStorage16 *LPSTORAGE16;
-
-#define INTERFACE IStorage16
-DECLARE_INTERFACE_(IStorage16,IUnknown)
-{
-    /*** IUnknown methods ***/
-    STDMETHOD16_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
-    STDMETHOD16_(ULONG,AddRef)(THIS) PURE;
-    STDMETHOD16_(ULONG,Release)(THIS) PURE;
-    /*** IStorage16 methods ***/
-    STDMETHOD16_(HRESULT,CreateStream)(THIS_ LPCOLESTR16 pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream16** ppstm) PURE;
-    STDMETHOD16_(HRESULT,OpenStream)(THIS_ LPCOLESTR16 pwcsName, void* reserved1, DWORD grfMode, DWORD reserved2, IStream16** ppstm) PURE;
-    STDMETHOD16_(HRESULT,CreateStorage)(THIS_ LPCOLESTR16 pwcsName, DWORD grfMode, DWORD dwStgFmt, DWORD reserved2, IStorage16** ppstg) PURE;
-    STDMETHOD16_(HRESULT,OpenStorage)(THIS_ LPCOLESTR16 pwcsName, IStorage16* pstgPriority, DWORD grfMode, SNB16 snbExclude, DWORD reserved, IStorage16** ppstg) PURE;
-    STDMETHOD16_(HRESULT,CopyTo)(THIS_ DWORD ciidExclude, const IID* rgiidExclude, SNB16 snbExclude, IStorage16* pstgDest) PURE;
-    STDMETHOD16_(HRESULT,MoveElementTo)(THIS_ LPCOLESTR16 pwcsName, IStorage16* pstgDest, LPCOLESTR16 pwcsNewName, DWORD grfFlags) PURE;
-    STDMETHOD16_(HRESULT,Commit)(THIS_ DWORD grfCommitFlags) PURE;
-    STDMETHOD16_(HRESULT,Revert)(THIS) PURE;
-    STDMETHOD16_(HRESULT,EnumElements)(THIS_ DWORD reserved1, void* reserved2, DWORD reserved3, IEnumSTATSTG** ppenum) PURE;
-    STDMETHOD16_(HRESULT,DestroyElement)(THIS_ LPCOLESTR16 pwcsName) PURE;
-    STDMETHOD16_(HRESULT,RenameElement)(THIS_ LPCOLESTR16 pwcsOldName, LPCOLESTR16 pwcsNewName) PURE;
-    STDMETHOD16_(HRESULT,SetElementTimes)(THIS_ LPCOLESTR16 pwcsName, const FILETIME* pctime, const FILETIME* patime, const FILETIME* pmtime) PURE;
-    STDMETHOD16_(HRESULT,SetClass)(THIS_ REFCLSID clsid) PURE;
-    STDMETHOD16_(HRESULT,SetStateBits)(THIS_ DWORD grfStateBits, DWORD grfMask) PURE;
-    STDMETHOD16_(HRESULT,Stat)(THIS_ STATSTG* pstatstg, DWORD grfStatFlag) PURE;
-};
-#undef INTERFACE
-
-#endif /* __WINE_OLE_IFS_H */
diff --git a/reactos/dll/win32/ole32/ole16.c b/reactos/dll/win32/ole32/ole16.c
deleted file mode 100644 (file)
index 1e1cf45..0000000
+++ /dev/null
@@ -1,675 +0,0 @@
-/*
- * 16 bit ole functions
- *
- * Copyright 1995 Martin von Loewis
- * Copyright 1998 Justin Bradford
- * Copyright 1999 Francis Beaudet
- * Copyright 1999 Sylvain St-Germain
- * Copyright 2002 Marcus Meissner
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "objbase.h"
-#include "ole2.h"
-#include "rpc.h"
-#include "winerror.h"
-#include "winreg.h"
-#include "wownt32.h"
-#include "wtypes.h"
-#include "wine/unicode.h"
-#include "wine/winbase16.h"
-#include "compobj_private.h"
-#include "ifs.h"
-
-#include "wine/debug.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(ole);
-
-static HTASK16 hETask = 0;
-static WORD Table_ETask[62];
-
-static LPMALLOC16 currentMalloc16=NULL;
-
-/* --- IMalloc16 implementation */
-
-
-typedef struct
-{
-        /* IUnknown fields */
-        const IMalloc16Vtbl    *lpVtbl;
-        DWORD                   ref;
-        /* IMalloc16 fields */
-} IMalloc16Impl;
-
-/******************************************************************************
- *             IMalloc16_QueryInterface        [COMPOBJ.500]
- */
-HRESULT CDECL IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) {
-        IMalloc16Impl *This = (IMalloc16Impl *)iface;
-
-       TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
-       if (    !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
-               !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc))
-       ) {
-               *obj = This;
-               return 0;
-       }
-       return OLE_E_ENUM_NOMORE;
-}
-
-/******************************************************************************
- *             IMalloc16_AddRef        [COMPOBJ.501]
- */
-ULONG CDECL IMalloc16_fnAddRef(IMalloc16* iface) {
-        IMalloc16Impl *This = (IMalloc16Impl *)iface;
-       TRACE("(%p)->AddRef()\n",This);
-       return 1; /* cannot be freed */
-}
-
-/******************************************************************************
- *             IMalloc16_Release       [COMPOBJ.502]
- */
-ULONG CDECL IMalloc16_fnRelease(IMalloc16* iface) {
-        IMalloc16Impl *This = (IMalloc16Impl *)iface;
-       TRACE("(%p)->Release()\n",This);
-       return 1; /* cannot be freed */
-}
-
-/******************************************************************************
- * IMalloc16_Alloc [COMPOBJ.503]
- */
-SEGPTR CDECL IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) {
-        IMalloc16Impl *This = (IMalloc16Impl *)iface;
-       TRACE("(%p)->Alloc(%d)\n",This,cb);
-        return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) );
-}
-
-/******************************************************************************
- * IMalloc16_Free [COMPOBJ.505]
- */
-VOID CDECL IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv)
-{
-    void *ptr = MapSL(pv);
-    IMalloc16Impl *This = (IMalloc16Impl *)iface;
-    TRACE("(%p)->Free(%08x)\n",This,pv);
-    UnMapLS(pv);
-    HeapFree( GetProcessHeap(), 0, ptr );
-}
-
-/******************************************************************************
- * IMalloc16_Realloc [COMPOBJ.504]
- */
-SEGPTR CDECL IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb)
-{
-    SEGPTR ret;
-    IMalloc16Impl *This = (IMalloc16Impl *)iface;
-    TRACE("(%p)->Realloc(%08x,%d)\n",This,pv,cb);
-    if (!pv) 
-       ret = IMalloc16_fnAlloc(iface, cb);
-    else if (cb) {
-        ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) );
-        UnMapLS(pv);
-    } else {
-       IMalloc16_fnFree(iface, pv);
-       ret = 0;
-    }
-    return ret;
-}
-
-/******************************************************************************
- * IMalloc16_GetSize [COMPOBJ.506]
- */
-DWORD CDECL IMalloc16_fnGetSize(IMalloc16* iface,SEGPTR pv)
-{
-       IMalloc16Impl *This = (IMalloc16Impl *)iface;
-        TRACE("(%p)->GetSize(%08x)\n",This,pv);
-        return HeapSize( GetProcessHeap(), 0, MapSL(pv) );
-}
-
-/******************************************************************************
- * IMalloc16_DidAlloc [COMPOBJ.507]
- */
-INT16 CDECL IMalloc16_fnDidAlloc(IMalloc16* iface,LPVOID pv) {
-        IMalloc16 *This = iface;
-       TRACE("(%p)->DidAlloc(%p)\n",This,pv);
-       return (INT16)-1;
-}
-
-/******************************************************************************
- * IMalloc16_HeapMinimize [COMPOBJ.508]
- */
-LPVOID CDECL IMalloc16_fnHeapMinimize(IMalloc16* iface) {
-        IMalloc16Impl *This = (IMalloc16Impl *)iface;
-       TRACE("(%p)->HeapMinimize()\n",This);
-       return NULL;
-}
-
-/******************************************************************************
- * IMalloc16_Constructor [VTABLE]
- */
-static LPMALLOC16
-IMalloc16_Constructor(void)
-{
-    static IMalloc16Vtbl vt16;
-    static SEGPTR msegvt16;
-    IMalloc16Impl* This;
-    HMODULE16 hcomp = GetModuleHandle16("COMPOBJ");
-
-    This = HeapAlloc( GetProcessHeap(), 0, sizeof(IMalloc16Impl) );
-    if (!msegvt16)
-    {
-#define VTENT(x) vt16.x = (void*)GetProcAddress16(hcomp,"IMalloc16_"#x);assert(vt16.x)
-        VTENT(QueryInterface);
-        VTENT(AddRef);
-        VTENT(Release);
-        VTENT(Alloc);
-        VTENT(Realloc);
-        VTENT(Free);
-        VTENT(GetSize);
-        VTENT(DidAlloc);
-        VTENT(HeapMinimize);
-#undef VTENT
-        msegvt16 = MapLS( &vt16 );
-    }
-    This->lpVtbl = (const IMalloc16Vtbl*)msegvt16;
-    This->ref = 1;
-    return (LPMALLOC16)MapLS( This );
-}
-
-
-/***********************************************************************
- *           CoGetMalloc    [COMPOBJ.4]
- *
- * Retrieve the current win16 IMalloc interface.
- *
- * RETURNS
- *     The current win16 IMalloc
- */
-HRESULT WINAPI CoGetMalloc16(
-       DWORD dwMemContext,     /* [in] unknown */
-       LPMALLOC16 * lpMalloc   /* [out] current win16 malloc interface */
-) {
-    if(!currentMalloc16)
-       currentMalloc16 = IMalloc16_Constructor();
-    *lpMalloc = currentMalloc16;
-    return S_OK;
-}
-
-/***********************************************************************
- *           CoCreateStandardMalloc [COMPOBJ.71]
- */
-HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
-                                         LPMALLOC16 *lpMalloc)
-{
-    /* FIXME: docu says we shouldn't return the same allocator as in
-     * CoGetMalloc16 */
-    *lpMalloc = IMalloc16_Constructor();
-    return S_OK;
-}
-
-/******************************************************************************
- *             CoInitialize    [COMPOBJ.2]
- * Set the win16 IMalloc used for memory management
- */
-HRESULT WINAPI CoInitialize16(
-       LPVOID lpReserved       /* [in] pointer to win16 malloc interface */
-) {
-    currentMalloc16 = (LPMALLOC16)lpReserved;
-    return S_OK;
-}
-
-/***********************************************************************
- *           CoUninitialize   [COMPOBJ.3]
- * Don't know what it does.
- * 3-Nov-98 -- this was originally misspelled, I changed it to what I
- *   believe is the correct spelling
- */
-void WINAPI CoUninitialize16(void)
-{
-  TRACE("()\n");
-  CoFreeAllLibraries();
-}
-
-/***********************************************************************
- *           IsEqualGUID [COMPOBJ.18]
- *
- * Compares two Unique Identifiers.
- *
- * RETURNS
- *     TRUE if equal
- */
-BOOL16 WINAPI IsEqualGUID16(
-       GUID* g1,       /* [in] unique id 1 */
-       GUID* g2)       /* [in] unique id 2 */
-{
-    return !memcmp( g1, g2, sizeof(GUID) );
-}
-
-/******************************************************************************
- *             CLSIDFromString [COMPOBJ.20]
- * Converts a unique identifier from its string representation into
- * the GUID struct.
- *
- * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
- *
- * RETURNS
- *     the converted GUID
- */
-HRESULT WINAPI CLSIDFromString16(
-       LPCOLESTR16 idstr,      /* [in] string representation of guid */
-       CLSID *id)              /* [out] GUID converted from string */
-{
-  const BYTE *s;
-  int  i;
-  BYTE table[256];
-
-  if (!idstr) {
-    memset( id, 0, sizeof (CLSID) );
-    return S_OK;
-  }
-
-  /* validate the CLSID string */
-  if (strlen(idstr) != 38)
-    return CO_E_CLASSSTRING;
-
-  s = (const BYTE *) idstr;
-  if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
-    return CO_E_CLASSSTRING;
-
-  for (i=1; i<37; i++) {
-    if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
-    if (!(((s[i] >= '0') && (s[i] <= '9'))  ||
-          ((s[i] >= 'a') && (s[i] <= 'f'))  ||
-          ((s[i] >= 'A') && (s[i] <= 'F'))))
-       return CO_E_CLASSSTRING;
-  }
-
-  TRACE("%s -> %p\n", s, id);
-
-  /* quick lookup table */
-  memset(table, 0, 256);
-
-  for (i = 0; i < 10; i++) {
-    table['0' + i] = i;
-  }
-  for (i = 0; i < 6; i++) {
-    table['A' + i] = i+10;
-    table['a' + i] = i+10;
-  }
-
-  /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
-
-  id->Data1 = (table[s[1]] << 28 | table[s[2]] << 24 | table[s[3]] << 20 | table[s[4]] << 16 |
-               table[s[5]] << 12 | table[s[6]] << 8  | table[s[7]] << 4  | table[s[8]]);
-  id->Data2 = table[s[10]] << 12 | table[s[11]] << 8 | table[s[12]] << 4 | table[s[13]];
-  id->Data3 = table[s[15]] << 12 | table[s[16]] << 8 | table[s[17]] << 4 | table[s[18]];
-
-  /* these are just sequential bytes */
-  id->Data4[0] = table[s[20]] << 4 | table[s[21]];
-  id->Data4[1] = table[s[22]] << 4 | table[s[23]];
-  id->Data4[2] = table[s[25]] << 4 | table[s[26]];
-  id->Data4[3] = table[s[27]] << 4 | table[s[28]];
-  id->Data4[4] = table[s[29]] << 4 | table[s[30]];
-  id->Data4[5] = table[s[31]] << 4 | table[s[32]];
-  id->Data4[6] = table[s[33]] << 4 | table[s[34]];
-  id->Data4[7] = table[s[35]] << 4 | table[s[36]];
-
-  return S_OK;
-}
-
-/******************************************************************************
- *             _xmalloc16      [internal]
- * Allocates size bytes from the standard ole16 allocator.
- *
- * RETURNS
- *     the allocated segmented pointer and a HRESULT
- */
-static HRESULT
-_xmalloc16(DWORD size, SEGPTR *ptr) {
-  LPMALLOC16 mllc;
-  DWORD args[2];
-
-  if (CoGetMalloc16(0,&mllc))
-    return E_OUTOFMEMORY;
-
-  args[0] = (DWORD)mllc;
-  args[1] = size;
-  /* No need for a Callback entry, we have WOWCallback16Ex which does
-   * everything we need.
-   */
-  if (!WOWCallback16Ex(
-      (DWORD)((const IMalloc16Vtbl*)MapSL(
-         (SEGPTR)((LPMALLOC16)MapSL((SEGPTR)mllc))->lpVtbl  )
-      )->Alloc,
-      WCB16_CDECL,
-      2*sizeof(DWORD),
-      (LPVOID)args,
-      (LPDWORD)ptr
-  )) {
-      ERR("CallTo16 IMalloc16 (%d) failed\n",size);
-      return E_FAIL;
-  }
-  return S_OK;
-}
-
-/******************************************************************************
- *             StringFromCLSID [COMPOBJ.19]
- * Converts a GUID into the respective string representation.
- * The target string is allocated using the OLE IMalloc.
- *
- * RETURNS
- *     the string representation and HRESULT
- */
-
-HRESULT WINAPI StringFromCLSID16(
-  REFCLSID id,         /* [in] the GUID to be converted */
-  LPOLESTR16 *idstr    /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
-
-) {
-  HRESULT ret;
-
-  ret = _xmalloc16(40,(SEGPTR*)idstr);
-  if (ret != S_OK)
-    return ret;
-  return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
-}
-
-/******************************************************************************
- * ProgIDFromCLSID [COMPOBJ.62]
- *
- * Converts a class id into the respective Program ID. (By using a registry lookup)
- *
- * RETURNS
- *  S_OK on success
- *  riid associated with the progid
- */
-HRESULT WINAPI ProgIDFromCLSID16(
-  REFCLSID clsid, /* [in] class id as found in registry */
-  LPOLESTR16 *lplpszProgID/* [out] associated Program ID */
-) {
-  static const WCHAR wszProgID[] = {'P','r','o','g','I','D',0};
-  HKEY     hkey;
-  HRESULT  ret;
-  LONG     len;
-  char    *buffer;
-
-  ret = COM_OpenKeyForCLSID(clsid, wszProgID, KEY_READ, &hkey);
-  if (FAILED(ret))
-    return ret;
-  
-  if (RegQueryValueA(hkey, NULL, NULL, &len))
-    ret = REGDB_E_READREGDB;
-
-  if (ret == S_OK)
-  {
-    buffer = HeapAlloc(GetProcessHeap(), 0, len);
-    if (RegQueryValueA(hkey, NULL, buffer, &len))
-      ret = REGDB_E_READREGDB;
-
-    if (ret == S_OK)
-    {
-      ret = _xmalloc16(len, (SEGPTR*)lplpszProgID);
-      if (ret == S_OK)
-        strcpy(MapSL((SEGPTR)*lplpszProgID),buffer);
-    }
-    HeapFree(GetProcessHeap(), 0, buffer);
-  }
-  RegCloseKey(hkey);
-  return ret;
-}
-
-/***********************************************************************
- *           LookupETask (COMPOBJ.94)
- */
-HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
-       FIXME("(%p,%p),stub!\n",hTask,p);
-       if ((*hTask = GetCurrentTask()) == hETask) {
-               memcpy(p, Table_ETask, sizeof(Table_ETask));
-       }
-       return 0;
-}
-
-/***********************************************************************
- *           SetETask (COMPOBJ.95)
- */
-HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
-        FIXME("(%04x,%p),stub!\n",hTask,p);
-       hETask = hTask;
-       return 0;
-}
-
-/***********************************************************************
- *           CALLOBJECTINWOW (COMPOBJ.201)
- */
-HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
-       FIXME("(%p,%p),stub!\n",p1,p2);
-       return 0;
-}
-
-/******************************************************************************
- *             CoRegisterClassObject   [COMPOBJ.5]
- *
- * Don't know where it registers it ...
- */
-HRESULT WINAPI CoRegisterClassObject16(
-       REFCLSID rclsid,
-       LPUNKNOWN pUnk,
-       DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
-       DWORD flags,        /* [in] REGCLS flags indicating how connections are made */
-       LPDWORD lpdwRegister
-) {
-       FIXME("(%s,%p,0x%08x,0x%08x,%p),stub\n",
-               debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister
-       );
-       return 0;
-}
-
-/******************************************************************************
- *      CoRevokeClassObject [COMPOBJ.6]
- *
- */
-HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
-{
-    FIXME("(0x%08x),stub!\n", dwRegister);
-    return 0;
-}
-
-/******************************************************************************
- *      CoFileTimeToDosDateTime [COMPOBJ.30]
- */
-BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
-{
-    return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
-}
-
-/******************************************************************************
- *      CoDosDateTimeToFileTime [COMPOBJ.31]
- */
-BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
-{
-    return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
-}
-
-/******************************************************************************
- *             CoRegisterMessageFilter [COMPOBJ.27]
- */
-HRESULT WINAPI CoRegisterMessageFilter16(
-       LPMESSAGEFILTER lpMessageFilter,
-       LPMESSAGEFILTER *lplpMessageFilter
-) {
-       FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
-       return 0;
-}
-
-/******************************************************************************
- *             CoLockObjectExternal    [COMPOBJ.63]
- */
-HRESULT WINAPI CoLockObjectExternal16(
-    LPUNKNOWN pUnk,            /* [in] object to be locked */
-    BOOL16 fLock,              /* [in] do lock */
-    BOOL16 fLastUnlockReleases /* [in] ? */
-) {
-    FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
-    return S_OK;
-}
-
-/***********************************************************************
- *           CoGetState [COMPOBJ.115]
- */
-HRESULT WINAPI CoGetState16(LPDWORD state)
-{
-    FIXME("(%p),stub!\n", state);
-
-    *state = 0;
-    return S_OK;
-}
-
-/***********************************************************************
- *      DllEntryPoint                   [COMPOBJ.116]
- *
- *    Initialization code for the COMPOBJ DLL
- *
- * RETURNS:
- */
-BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
-{
-        TRACE("(%08x, %04x, %04x, %04x, %08x, %04x)\n", Reason, hInst, ds, HeapSize, res1, res2);
-        return TRUE;
-}
-
-/***********************************************************************
- *           CoMemAlloc [COMPOBJ.151]
- */
-SEGPTR WINAPI CoMemAlloc(DWORD size, DWORD dwMemContext, DWORD x) {
-       HRESULT         hres;
-       SEGPTR          segptr;
-
-       /* FIXME: check context handling */
-       TRACE("(%d, 0x%08x, 0x%08x)\n", size, dwMemContext, x);
-       hres = _xmalloc16(size, &segptr);
-       if (hres != S_OK)
-               return 0;
-       return segptr;
-}
-
-/******************************************************************************
- *             CLSIDFromProgID [COMPOBJ.61]
- *
- * Converts a program ID into the respective GUID.
- *
- * PARAMS
- *  progid       [I] program id as found in registry
- *  riid         [O] associated CLSID
- *
- * RETURNS
- *     Success: S_OK
- *  Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
- */
-HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid)
-{
-       char    *buf,buf2[80];
-       LONG    buf2len;
-       HRESULT err;
-       HKEY    xhkey;
-
-       buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
-       sprintf(buf,"%s\\CLSID",progid);
-       if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
-               HeapFree(GetProcessHeap(),0,buf);
-                return CO_E_CLASSSTRING;
-       }
-       HeapFree(GetProcessHeap(),0,buf);
-       buf2len = sizeof(buf2);
-       if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
-               RegCloseKey(xhkey);
-                return CO_E_CLASSSTRING;
-       }
-       RegCloseKey(xhkey);
-       return CLSIDFromString16(buf2,riid);
-}
-
-/***********************************************************************
- *           CoGetClassObject [COMPOBJ.7]
- *
- */
-HRESULT WINAPI CoGetClassObject16(
-    REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
-    REFIID iid, LPVOID *ppv)
-{
-    FIXME(", stub!\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
-
-    if (pServerInfo) {
-       FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
-       FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
-    }
-    return E_NOTIMPL;
-}
-
-/***********************************************************************
- *           CoCreateInstance [COMPOBJ.13]
- */
-HRESULT WINAPI CoCreateInstance16(
-       REFCLSID rclsid,
-       LPUNKNOWN pUnkOuter,
-       DWORD dwClsContext,
-       REFIID iid,
-       LPVOID *ppv)
-{
-  FIXME("(%s, %p, %x, %s, %p), stub!\n",
-       debugstr_guid(rclsid), pUnkOuter, dwClsContext, debugstr_guid(iid),
-       ppv
-  );
-  return E_NOTIMPL;
-}
-
-/***********************************************************************
- *           CoDisconnectObject [COMPOBJ.15]
- */
-HRESULT WINAPI CoDisconnectObject16( LPUNKNOWN lpUnk, DWORD reserved )
-{
-  FIXME("(%p, 0x%08x): stub!\n", lpUnk, reserved);
-  return E_NOTIMPL;
-}
-
-/***********************************************************************
- *           DllGetClassObject                          [OLE2.4]
- */
-HRESULT WINAPI DllGetClassObject16(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
-{
-  FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
-  return E_NOTIMPL;
-}
-
-/******************************************************************************
- *             GetRunningObjectTable (OLE2.30)
- */
-HRESULT WINAPI
-GetRunningObjectTable16(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
-{
-    FIXME("(%d,%p),stub!\n",reserved,pprot);
-    return E_NOTIMPL;
-}
index 19151b9..77abbf6 100644 (file)
@@ -63,19 +63,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage);
 /* We map in PAGE_SIZE-sized chunks. Must be a multiple of 4096. */
 #define PAGE_SIZE       131072
 
-#define BLOCKS_PER_PAGE (PAGE_SIZE / BIG_BLOCK_SIZE)
-
 /* We keep a list of recently-discarded pages. This controls the
  * size of that list. */
 #define MAX_VICTIM_PAGES 16
 
-/* This structure provides one bit for each block in a page.
- * Use BIGBLOCKFILE_{Test,Set,Clear}Bit to manipulate it. */
-typedef struct
-{
-    unsigned int bits[BLOCKS_PER_PAGE / (CHAR_BIT * sizeof(unsigned int))];
-} BlockBits;
-
 /***
  * This structure identifies the paged that are mapped
  * from the file and their position in memory. It is
@@ -96,16 +87,12 @@ struct MappedPage
     DWORD  mapped_bytes;
     LPVOID lpBytes;
     LONG   refcnt;
-
-    BlockBits readable_blocks;
-    BlockBits writable_blocks;
 };
 
 struct BigBlockFile
 {
     BOOL fileBased;
     ULARGE_INTEGER filesize;
-    ULONG blocksize;
     HANDLE hfile;
     HANDLE hfilemap;
     DWORD flProtect;
@@ -123,39 +110,6 @@ struct BigBlockFile
  * pass expressions with side effects. */
 #define ROUND_UP(a, b) ((((a) + (b) - 1)/(b))*(b))
 
-/***********************************************************
- * Blockbits functions.
- */
-static inline BOOL BIGBLOCKFILE_TestBit(const BlockBits *bb,
-                                       unsigned int index)
-{
-    unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
-    unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
-
-    return bb->bits[array_index] & (1 << bit_index);
-}
-
-static inline void BIGBLOCKFILE_SetBit(BlockBits *bb, unsigned int index)
-{
-    unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
-    unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
-
-    bb->bits[array_index] |= (1 << bit_index);
-}
-
-static inline void BIGBLOCKFILE_ClearBit(BlockBits *bb, unsigned int index)
-{
-    unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
-    unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
-
-    bb->bits[array_index] &= ~(1 << bit_index);
-}
-
-static inline void BIGBLOCKFILE_Zero(BlockBits *bb)
-{
-    memset(bb->bits, 0, sizeof(bb->bits));
-}
-
 /******************************************************************************
  *      BIGBLOCKFILE_FileInit
  *
@@ -302,9 +256,6 @@ static MappedPage *BIGBLOCKFILE_CreatePage(BigBlockFile *This, ULONG page_index)
         return NULL;
     }
 
-    BIGBLOCKFILE_Zero(&page->readable_blocks);
-    BIGBLOCKFILE_Zero(&page->writable_blocks);
-
     return page;
 }
 
@@ -328,9 +279,6 @@ static void * BIGBLOCKFILE_GetMappedView(
        if (page)
        {
            This->num_victim_pages--;
-
-           BIGBLOCKFILE_Zero(&page->readable_blocks);
-           BIGBLOCKFILE_Zero(&page->writable_blocks);
        }
     }
 
@@ -709,7 +657,7 @@ static HRESULT ImplBIGBLOCKFILE_WriteAt(
  * and the blocks in use list.
  */
 BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD openFlags,
-                                     ULONG blocksize, BOOL fileBased)
+                                     BOOL fileBased)
 {
     BigBlockFile *This;
 
@@ -720,7 +668,6 @@ BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD ope
 
     This->fileBased = fileBased;
     This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags);
-    This->blocksize = blocksize;
 
     This->maplist = NULL;
     This->victimhead = NULL;
@@ -863,31 +810,19 @@ static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size)
 }
 
 /******************************************************************************
- *      BIGBLOCKFILE_EnsureExists
+ *      BIGBLOCKFILE_Expand
  *
- * Grows the file if necessary to make sure the block is valid.
+ * Grows the file to the specified size if necessary.
  */
-HRESULT BIGBLOCKFILE_EnsureExists(BigBlockFile *This, ULONG index)
+HRESULT BIGBLOCKFILE_Expand(BigBlockFile *This, ULARGE_INTEGER newSize)
 {
     ULARGE_INTEGER size;
     HRESULT hr;
 
-    /* Block index starts at -1 translate to zero based index */
-    if (index == 0xffffffff)
-        index = 0;
-    else
-        index++;
-
     hr = BIGBLOCKFILE_GetSize(This, &size);
     if(FAILED(hr)) return hr;
 
-    /* make sure that the block physically exists */
-    if ((This->blocksize * (index + 1)) > size.QuadPart)
-    {
-        ULARGE_INTEGER newSize;
-
-        newSize.QuadPart = This->blocksize * (index + 1);
+    if (newSize.QuadPart > size.QuadPart)
         hr = BIGBLOCKFILE_SetSize(This, newSize);
-    }
     return hr;
 }
index 52153a2..b3362bc 100644 (file)
@@ -181,7 +181,9 @@ static HRESULT WINAPI IPropertyStorage_fnQueryInterface(
 {
     PropertyStorage_impl *This = (PropertyStorage_impl *)iface;
 
-    if ( (This==0) || (ppvObject==0) )
+    TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
+
+    if (!ppvObject)
         return E_INVALIDARG;
 
     *ppvObject = 0;
index 837365b..f1706da 100644 (file)
@@ -269,14 +269,9 @@ static void IEnumSTATSTGImpl_Destroy(IEnumSTATSTGImpl* This);
 ** Block Functions
 */
 
-static ULONG BLOCK_GetBigBlockOffset(ULONG index)
+static ULONG StorageImpl_GetBigBlockOffset(StorageImpl* This, ULONG index)
 {
-    if (index == 0xffffffff)
-        index = 0;
-    else
-        index ++;
-
-    return index * BIG_BLOCK_SIZE;
+    return (index+1) * This->bigBlockSize;
 }
 
 /************************************************************************
@@ -1599,11 +1594,15 @@ static HRESULT WINAPI StorageBaseImpl_CopyTo(
   SNB         snbExclude,   /* [unique][in] */
   IStorage*   pstgDest)     /* [unique][in] */
 {
+  StorageBaseImpl* const This=(StorageBaseImpl*)iface;
+
   IEnumSTATSTG *elements     = 0;
   STATSTG      curElement, strStat;
   HRESULT      hr;
   IStorage     *pstgTmp, *pstgChild;
   IStream      *pstrTmp, *pstrChild;
+  DirRef       srcEntryRef;
+  DirEntry     srcEntry;
   BOOL         skip = FALSE, skip_storage = FALSE, skip_stream = FALSE;
   int          i;
 
@@ -1728,11 +1727,25 @@ static HRESULT WINAPI StorageBaseImpl_CopyTo(
         goto cleanup;
 
       /*
-       * open child stream storage
+       * open child stream storage. This operation must succeed even if the
+       * stream is already open, so we use internal functions to do it.
        */
-      hr = IStorage_OpenStream( iface, curElement.pwcsName, NULL,
-                               STGM_READ|STGM_SHARE_EXCLUSIVE,
-                               0, &pstrChild );
+      srcEntryRef = findElement( This, This->storageDirEntry, curElement.pwcsName,
+        &srcEntry);
+      if (!srcEntryRef)
+      {
+        ERR("source stream not found\n");
+        hr = STG_E_DOCFILECORRUPT;
+      }
+
+      if (hr == S_OK)
+      {
+        pstrChild = (IStream*)StgStreamImpl_Construct(This, STGM_READ|STGM_SHARE_EXCLUSIVE, srcEntryRef);
+        if (pstrChild)
+          IStream_AddRef(pstrChild);
+        else
+          hr = E_OUTOFMEMORY;
+      }
 
       if (hr == S_OK)
       {
@@ -2626,7 +2639,6 @@ static HRESULT StorageImpl_Construct(
   This->bigBlockFile   = BIGBLOCKFILE_Construct(hFile,
                                                 pLkbyt,
                                                 openFlags,
-                                                This->bigBlockSize,
                                                 fileBased);
 
   if (This->bigBlockFile == 0)
@@ -2638,7 +2650,7 @@ static HRESULT StorageImpl_Construct(
   if (create)
   {
     ULARGE_INTEGER size;
-    BYTE bigBlockBuffer[BIG_BLOCK_SIZE];
+    BYTE bigBlockBuffer[MAX_BIG_BLOCK_SIZE];
 
     /*
      * Initialize all header variables:
@@ -2835,13 +2847,14 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
   StorageImpl* This)
 {
   ULONG depotBlockIndexPos;
-  BYTE depotBuffer[BIG_BLOCK_SIZE];
+  BYTE depotBuffer[MAX_BIG_BLOCK_SIZE];
   BOOL success;
   ULONG depotBlockOffset;
   ULONG blocksPerDepot    = This->bigBlockSize / sizeof(ULONG);
   ULONG nextBlockIndex    = BLOCK_SPECIAL;
   int   depotIndex        = 0;
   ULONG freeBlock         = BLOCK_UNUSED;
+  ULARGE_INTEGER neededSize;
 
   depotIndex = This->prevFreeBlock / blocksPerDepot;
   depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
@@ -2955,7 +2968,8 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
   /*
    * make sure that the block physically exists before using it
    */
-  BIGBLOCKFILE_EnsureExists(This->bigBlockFile, freeBlock);
+  neededSize.QuadPart = StorageImpl_GetBigBlockOffset(This, freeBlock)+This->bigBlockSize;
+  BIGBLOCKFILE_Expand(This->bigBlockFile, neededSize);
 
   This->prevFreeBlock = freeBlock;
 
@@ -2970,7 +2984,7 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
  */
 static void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex)
 {
-  BYTE blockBuffer[BIG_BLOCK_SIZE];
+  BYTE blockBuffer[MAX_BIG_BLOCK_SIZE];
 
   /*
    * Initialize blocks as free
@@ -3053,7 +3067,7 @@ static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This)
 {
   ULONG numExtBlocks           = This->extBigBlockDepotCount;
   ULONG nextExtBlock           = This->extBigBlockDepotStart;
-  BYTE  depotBuffer[BIG_BLOCK_SIZE];
+  BYTE  depotBuffer[MAX_BIG_BLOCK_SIZE];
   ULONG index                  = BLOCK_UNUSED;
   ULONG nextBlockOffset        = This->bigBlockSize - sizeof(ULONG);
   ULONG blocksPerDepotBlock    = This->bigBlockSize / sizeof(ULONG);
@@ -3143,10 +3157,10 @@ static HRESULT StorageImpl_GetNextBlockInChain(
   ULONG offsetInDepot    = blockIndex * sizeof (ULONG);
   ULONG depotBlockCount  = offsetInDepot / This->bigBlockSize;
   ULONG depotBlockOffset = offsetInDepot % This->bigBlockSize;
-  BYTE depotBuffer[BIG_BLOCK_SIZE];
+  BYTE depotBuffer[MAX_BIG_BLOCK_SIZE];
   BOOL success;
   ULONG depotBlockIndexPos;
-  int index;
+  int index, num_blocks;
 
   *nextBlockIndex   = BLOCK_SPECIAL;
 
@@ -3181,7 +3195,9 @@ static HRESULT StorageImpl_GetNextBlockInChain(
     if (!success)
       return STG_E_READFAULT;
 
-    for (index = 0; index < NUM_BLOCKS_PER_DEPOT_BLOCK; index++)
+    num_blocks = This->bigBlockSize / 4;
+
+    for (index = 0; index < num_blocks; index++)
     {
       StorageUtl_ReadDWord(depotBuffer, index*sizeof(ULONG), nextBlockIndex);
       This->blockDepotCached[index] = *nextBlockIndex;
@@ -3272,26 +3288,31 @@ static void StorageImpl_SetNextBlockInChain(
 /******************************************************************************
  *      Storage32Impl_LoadFileHeader
  *
- * This method will read in the file header, i.e. big block index -1.
+ * This method will read in the file header
  */
 static HRESULT StorageImpl_LoadFileHeader(
           StorageImpl* This)
 {
-  HRESULT hr = STG_E_FILENOTFOUND;
-  BYTE    headerBigBlock[BIG_BLOCK_SIZE];
-  BOOL    success;
+  HRESULT hr;
+  BYTE    headerBigBlock[HEADER_SIZE];
   int     index;
+  ULARGE_INTEGER offset;
+  DWORD bytes_read;
 
   TRACE("\n");
   /*
    * Get a pointer to the big block of data containing the header.
    */
-  success = StorageImpl_ReadBigBlock(This, -1, headerBigBlock);
+  offset.u.HighPart = 0;
+  offset.u.LowPart = 0;
+  hr = StorageImpl_ReadAt(This, offset, headerBigBlock, HEADER_SIZE, &bytes_read);
+  if (SUCCEEDED(hr) && bytes_read != HEADER_SIZE)
+    hr = STG_E_FILENOTFOUND;
 
   /*
    * Extract the information from the header.
    */
-  if (success)
+  if (SUCCEEDED(hr))
   {
     /*
      * Check for the "magic number" signature and return an error if it is not
@@ -3360,7 +3381,7 @@ static HRESULT StorageImpl_LoadFileHeader(
      * Right now, the code is making some assumptions about the size of the
      * blocks, just make sure they are what we're expecting.
      */
-    if (This->bigBlockSize != DEF_BIG_BLOCK_SIZE ||
+    if ((This->bigBlockSize != MIN_BIG_BLOCK_SIZE && This->bigBlockSize != MAX_BIG_BLOCK_SIZE) ||
        This->smallBlockSize != DEF_SMALL_BLOCK_SIZE)
     {
        WARN("Broken OLE storage file\n");
@@ -3376,29 +3397,35 @@ static HRESULT StorageImpl_LoadFileHeader(
 /******************************************************************************
  *      Storage32Impl_SaveFileHeader
  *
- * This method will save to the file the header, i.e. big block -1.
+ * This method will save to the file the header
  */
 static void StorageImpl_SaveFileHeader(
           StorageImpl* This)
 {
-  BYTE   headerBigBlock[BIG_BLOCK_SIZE];
+  BYTE   headerBigBlock[HEADER_SIZE];
   int    index;
-  BOOL success;
+  HRESULT hr;
+  ULARGE_INTEGER offset;
+  DWORD bytes_read, bytes_written;
 
   /*
    * Get a pointer to the big block of data containing the header.
    */
-  success = StorageImpl_ReadBigBlock(This, -1, headerBigBlock);
+  offset.u.HighPart = 0;
+  offset.u.LowPart = 0;
+  hr = StorageImpl_ReadAt(This, offset, headerBigBlock, HEADER_SIZE, &bytes_read);
+  if (SUCCEEDED(hr) && bytes_read != HEADER_SIZE)
+    hr = STG_E_FILENOTFOUND;
 
   /*
    * If the block read failed, the file is probably new.
    */
-  if (!success)
+  if (FAILED(hr))
   {
     /*
      * Initialize for all unknown fields.
      */
-    memset(headerBigBlock, 0, BIG_BLOCK_SIZE);
+    memset(headerBigBlock, 0, HEADER_SIZE);
 
     /*
      * Initialize the magic number.
@@ -3469,7 +3496,7 @@ static void StorageImpl_SaveFileHeader(
   /*
    * Write the big block back to the file.
    */
-  StorageImpl_WriteBigBlock(This, -1, headerBigBlock);
+  StorageImpl_WriteAt(This, offset, headerBigBlock, HEADER_SIZE, &bytes_written);
 }
 
 /******************************************************************************
@@ -3711,7 +3738,7 @@ static BOOL StorageImpl_ReadBigBlock(
   DWORD  read;
 
   ulOffset.u.HighPart = 0;
-  ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
+  ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This, blockIndex);
 
   StorageImpl_ReadAt(This, ulOffset, buffer, This->bigBlockSize, &read);
   return (read == This->bigBlockSize);
@@ -3728,7 +3755,7 @@ static BOOL StorageImpl_ReadDWordFromBigBlock(
   DWORD  tmp;
 
   ulOffset.u.HighPart = 0;
-  ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
+  ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This, blockIndex);
   ulOffset.u.LowPart += offset;
 
   StorageImpl_ReadAt(This, ulOffset, &tmp, sizeof(DWORD), &read);
@@ -3745,7 +3772,7 @@ static BOOL StorageImpl_WriteBigBlock(
   DWORD  wrote;
 
   ulOffset.u.HighPart = 0;
-  ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
+  ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This, blockIndex);
 
   StorageImpl_WriteAt(This, ulOffset, buffer, This->bigBlockSize, &wrote);
   return (wrote == This->bigBlockSize);
@@ -3761,7 +3788,7 @@ static BOOL StorageImpl_WriteDWordToBigBlock(
   DWORD  wrote;
 
   ulOffset.u.HighPart = 0;
-  ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
+  ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This, blockIndex);
   ulOffset.u.LowPart += offset;
 
   value = htole32(value);
@@ -5151,7 +5178,7 @@ HRESULT BlockChainStream_ReadAt(BlockChainStream* This,
 
      TRACE("block %i\n",blockIndex);
      ulOffset.u.HighPart = 0;
-     ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex) +
+     ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This->parentStorage, blockIndex) +
                              offsetInBlock;
 
      StorageImpl_ReadAt(This->parentStorage,
@@ -5247,7 +5274,7 @@ HRESULT BlockChainStream_WriteAt(BlockChainStream* This,
 
     TRACE("block %i\n",blockIndex);
     ulOffset.u.HighPart = 0;
-    ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex) +
+    ulOffset.u.LowPart = StorageImpl_GetBigBlockOffset(This->parentStorage, blockIndex) +
                              offsetInBlock;
 
     StorageImpl_WriteAt(This->parentStorage,
@@ -5721,7 +5748,7 @@ static ULONG SmallBlockChainStream_GetNextFreeBlock(
 
       ULONG sbdIndex = This->parentStorage->smallBlockDepotStart;
       ULONG nextBlock, newsbdIndex;
-      BYTE smallBlockDepot[BIG_BLOCK_SIZE];
+      BYTE smallBlockDepot[MAX_BIG_BLOCK_SIZE];
 
       nextBlock = sbdIndex;
       while (nextBlock != BLOCK_END_OF_CHAIN)
index 03328b2..fad5d77 100644 (file)
@@ -79,6 +79,11 @@ static const ULONG DIRENTRY_NULL             = 0xFFFFFFFF;
 
 #define RAW_DIRENTRY_SIZE 0x00000080
 
+#define HEADER_SIZE 512
+
+#define MIN_BIG_BLOCK_SIZE 0x200
+#define MAX_BIG_BLOCK_SIZE 0x1000
+
 /*
  * Type of child entry link
  */
@@ -91,15 +96,8 @@ static const ULONG DIRENTRY_NULL             = 0xFFFFFFFF;
  */
 #define STGTY_ROOT 0x05
 
-/*
- * These defines assume a hardcoded blocksize. The code will assert
- * if the blocksize is different. Some changes will have to be done if it
- * becomes the case.
- */
-#define BIG_BLOCK_SIZE           0x200
 #define COUNT_BBDEPOTINHEADER    109
 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
-#define NUM_BLOCKS_PER_DEPOT_BLOCK 128
 
 #define STGM_ACCESS_MODE(stgm)   ((stgm)&0x0000f)
 #define STGM_SHARE_MODE(stgm)    ((stgm)&0x000f0)
@@ -163,10 +161,9 @@ typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
 BigBlockFile*  BIGBLOCKFILE_Construct(HANDLE hFile,
                                       ILockBytes* pLkByt,
                                       DWORD openFlags,
-                                      ULONG blocksize,
                                       BOOL fileBased);
 void           BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
-HRESULT        BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
+HRESULT        BIGBLOCKFILE_Expand(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
 HRESULT        BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
 HRESULT        BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
            void* buffer, ULONG size, ULONG* bytesRead);
@@ -359,7 +356,7 @@ struct StorageImpl
   ULONG extBigBlockDepotCount;
   ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
 
-  ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK];
+  ULONG blockDepotCached[MAX_BIG_BLOCK_SIZE / 4];
   ULONG indexBlockDepotCached;
   ULONG prevFreeBlock;