Vincent Povirk : ole32: Update storage header saving code based on the latest MS spec.

Alexandre Julliard julliard at winehq.org
Mon Jul 19 11:05:32 CDT 2010


Module: wine
Branch: master
Commit: 7f3c92b2a0daf53dbcc22ac111929ecf0c22e6f7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7f3c92b2a0daf53dbcc22ac111929ecf0c22e6f7

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Sat Jul 17 09:46:43 2010 -0500

ole32: Update storage header saving code based on the latest MS spec.

These fields are needed for the MS storage implementation to load
files that were created by Wine with a block size of 4096.

---

 dlls/ole32/storage32.c |   52 +++++++++++++++++++++++++++++++++++++++++------
 dlls/ole32/storage32.h |    4 +++
 2 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c
index 98df144..15fe143 100644
--- a/dlls/ole32/storage32.c
+++ b/dlls/ole32/storage32.c
@@ -1306,6 +1306,8 @@ static HRESULT StorageImpl_CreateDirEntry(
         entryIndex,
         emptyData);
     }
+
+    StorageImpl_SaveFileHeader(storage);
   }
 
   UpdateRawDirEntry(currentData, newData);
@@ -3465,6 +3467,7 @@ static void StorageImpl_SaveFileHeader(
   HRESULT hr;
   ULARGE_INTEGER offset;
   DWORD bytes_read, bytes_written;
+  DWORD major_version, dirsectorcount;
 
   /*
    * Get a pointer to the big block of data containing the header.
@@ -3475,6 +3478,16 @@ static void StorageImpl_SaveFileHeader(
   if (SUCCEEDED(hr) && bytes_read != HEADER_SIZE)
     hr = STG_E_FILENOTFOUND;
 
+  if (This->bigBlockSizeBits == 0x9)
+    major_version = 3;
+  else if (This->bigBlockSizeBits == 0xc)
+    major_version = 4;
+  else
+  {
+    ERR("invalid big block shift 0x%x\n", This->bigBlockSizeBits);
+    major_version = 4;
+  }
+
   /*
    * If the block read failed, the file is probably new.
    */
@@ -3489,13 +3502,6 @@ static void StorageImpl_SaveFileHeader(
      * Initialize the magic number.
      */
     memcpy(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic));
-
-    /*
-     * And a bunch of things we don't know what they mean
-     */
-    StorageUtl_WriteWord(headerBigBlock,  0x18, 0x3b);
-    StorageUtl_WriteWord(headerBigBlock,  0x1a, 0x3);
-    StorageUtl_WriteWord(headerBigBlock,  0x1c, (WORD)-2);
   }
 
   /*
@@ -3503,6 +3509,21 @@ static void StorageImpl_SaveFileHeader(
    */
   StorageUtl_WriteWord(
     headerBigBlock,
+    OFFSET_MINORVERSION,
+    0x3e);
+
+  StorageUtl_WriteWord(
+    headerBigBlock,
+    OFFSET_MAJORVERSION,
+    major_version);
+
+  StorageUtl_WriteWord(
+    headerBigBlock,
+    OFFSET_BYTEORDERMARKER,
+    (WORD)-2);
+
+  StorageUtl_WriteWord(
+    headerBigBlock,
     OFFSET_BIGBLOCKSIZEBITS,
     This->bigBlockSizeBits);
 
@@ -3511,6 +3532,23 @@ static void StorageImpl_SaveFileHeader(
     OFFSET_SMALLBLOCKSIZEBITS,
     This->smallBlockSizeBits);
 
+  if (major_version >= 4)
+  {
+    if (This->rootBlockChain)
+      dirsectorcount = BlockChainStream_GetCount(This->rootBlockChain);
+    else
+      /* This file is being created, and it will start out with one block. */
+      dirsectorcount = 1;
+  }
+  else
+    /* This field must be 0 in versions older than 4 */
+    dirsectorcount = 0;
+
+  StorageUtl_WriteDWord(
+    headerBigBlock,
+    OFFSET_DIRSECTORCOUNT,
+    dirsectorcount);
+
   StorageUtl_WriteDWord(
     headerBigBlock,
     OFFSET_BBDEPOTCOUNT,
diff --git a/dlls/ole32/storage32.h b/dlls/ole32/storage32.h
index 19f3f2d..524ff7d 100644
--- a/dlls/ole32/storage32.h
+++ b/dlls/ole32/storage32.h
@@ -42,8 +42,12 @@
 /*
  * Definitions for the file format offsets.
  */
+static const ULONG OFFSET_MINORVERSION       = 0x00000018;
+static const ULONG OFFSET_MAJORVERSION       = 0x0000001a;
+static const ULONG OFFSET_BYTEORDERMARKER    = 0x0000001c;
 static const ULONG OFFSET_BIGBLOCKSIZEBITS   = 0x0000001e;
 static const ULONG OFFSET_SMALLBLOCKSIZEBITS = 0x00000020;
+static const ULONG OFFSET_DIRSECTORCOUNT     = 0x00000028;
 static const ULONG OFFSET_BBDEPOTCOUNT	     = 0x0000002C;
 static const ULONG OFFSET_ROOTSTARTBLOCK     = 0x00000030;
 static const ULONG OFFSET_SMALLBLOCKLIMIT    = 0x00000038;




More information about the wine-cvs mailing list