ole32: Remove knowledge of block sizes from the BigBlockFile object.
authorVincent Povirk <vincent@codeweavers.com>
Wed, 10 Mar 2010 21:03:35 +0000 (15:03 -0600)
committerTest Robot <wine-patches-test@office.etersoft.ru>
Fri, 4 Mar 2011 19:28:04 +0000 (22:28 +0300)
We can't determine the correct block size until we read the header, and we
can't create the BigBlockFile until we know the correct block size. To
solve this dilemma, have StorageImpl calculate the file size it needs instead
of asking the BigBlockFile to "ensure a big block exists".

dlls/ole32/stg_bigblockfile.c
dlls/ole32/storage32.c
dlls/ole32/storage32.h

index 4aa302649fb8aab5ed5fe3f5546d692dec921f5c..77abbf6286bef392ad8320f367156b82dd58c634 100644 (file)
@@ -93,7 +93,6 @@ struct BigBlockFile
 {
     BOOL fileBased;
     ULARGE_INTEGER filesize;
-    ULONG blocksize;
     HANDLE hfile;
     HANDLE hfilemap;
     DWORD flProtect;
@@ -658,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;
 
@@ -669,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;
@@ -812,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 afead73bf3613f3553dd0a3065059ca94808b937..9d99429a1227e4f7e471f4be25decb94355ed689 100644 (file)
@@ -2436,7 +2436,6 @@ static HRESULT StorageImpl_Construct(
   This->bigBlockFile   = BIGBLOCKFILE_Construct(hFile,
                                                 pLkbyt,
                                                 openFlags,
-                                                This->bigBlockSize,
                                                 fileBased);
 
   if (This->bigBlockFile == 0)
@@ -2620,6 +2619,7 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
   ULONG nextBlockIndex    = BLOCK_SPECIAL;
   int   depotIndex        = 0;
   ULONG freeBlock         = BLOCK_UNUSED;
+  ULARGE_INTEGER neededSize;
 
   depotIndex = This->prevFreeBlock / blocksPerDepot;
   depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
@@ -2733,7 +2733,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;
 
index 53e06779d07eee3bd0c1292193c01d7527c78012..de2a4688dc50b3149bffcaec6f14afd8dcc7857f 100644 (file)
@@ -159,10 +159,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);