diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index 98df144976c..15fe143c735 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,18 +3502,26 @@ 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); } /* * Write the information to the header. */ + 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, @@ -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 19f3f2d682c..524ff7d851e 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;