ole32: Change ReadDirEntry return type to HRESULT.
[wine/multimedia.git] / dlls / ole32 / storage32.h
blob5d6f651177e25fdf76cfcd8322316e48955d9b26
1 /*
2 * Compound Storage (32 bit version)
4 * Implemented using the documentation of the LAOLA project at
5 * <URL:http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/index.html>
6 * (Thanks to Martin Schwartz <schwartz@cs.tu-berlin.de>)
8 * This include file contains definitions of types and function
9 * prototypes that are used in the many files implementing the
10 * storage functionality
12 * Copyright 1998,1999 Francis Beaudet
13 * Copyright 1998,1999 Thuy Nguyen
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #ifndef __STORAGE32_H__
30 #define __STORAGE32_H__
32 #include <stdarg.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winnt.h"
37 #include "objbase.h"
38 #include "winreg.h"
39 #include "winternl.h"
40 #include "wine/list.h"
43 * Definitions for the file format offsets.
45 static const ULONG OFFSET_BIGBLOCKSIZEBITS = 0x0000001e;
46 static const ULONG OFFSET_SMALLBLOCKSIZEBITS = 0x00000020;
47 static const ULONG OFFSET_BBDEPOTCOUNT = 0x0000002C;
48 static const ULONG OFFSET_ROOTSTARTBLOCK = 0x00000030;
49 static const ULONG OFFSET_SBDEPOTSTART = 0x0000003C;
50 static const ULONG OFFSET_SBDEPOTCOUNT = 0x00000040;
51 static const ULONG OFFSET_EXTBBDEPOTSTART = 0x00000044;
52 static const ULONG OFFSET_EXTBBDEPOTCOUNT = 0x00000048;
53 static const ULONG OFFSET_BBDEPOTSTART = 0x0000004C;
54 static const ULONG OFFSET_PS_NAME = 0x00000000;
55 static const ULONG OFFSET_PS_NAMELENGTH = 0x00000040;
56 static const ULONG OFFSET_PS_STGTYPE = 0x00000042;
57 static const ULONG OFFSET_PS_LEFTCHILD = 0x00000044;
58 static const ULONG OFFSET_PS_RIGHTCHILD = 0x00000048;
59 static const ULONG OFFSET_PS_DIRROOT = 0x0000004C;
60 static const ULONG OFFSET_PS_GUID = 0x00000050;
61 static const ULONG OFFSET_PS_CTIMELOW = 0x00000064;
62 static const ULONG OFFSET_PS_CTIMEHIGH = 0x00000068;
63 static const ULONG OFFSET_PS_MTIMELOW = 0x0000006C;
64 static const ULONG OFFSET_PS_MTIMEHIGH = 0x00000070;
65 static const ULONG OFFSET_PS_STARTBLOCK = 0x00000074;
66 static const ULONG OFFSET_PS_SIZE = 0x00000078;
67 static const WORD DEF_BIG_BLOCK_SIZE_BITS = 0x0009;
68 static const WORD DEF_SMALL_BLOCK_SIZE_BITS = 0x0006;
69 static const WORD DEF_BIG_BLOCK_SIZE = 0x0200;
70 static const WORD DEF_SMALL_BLOCK_SIZE = 0x0040;
71 static const ULONG BLOCK_EXTBBDEPOT = 0xFFFFFFFC;
72 static const ULONG BLOCK_SPECIAL = 0xFFFFFFFD;
73 static const ULONG BLOCK_END_OF_CHAIN = 0xFFFFFFFE;
74 static const ULONG BLOCK_UNUSED = 0xFFFFFFFF;
75 static const ULONG DIRENTRY_NULL = 0xFFFFFFFF;
77 #define DIRENTRY_NAME_MAX_LEN 0x20
78 #define DIRENTRY_NAME_BUFFER_LEN 0x40
80 #define RAW_DIRENTRY_SIZE 0x00000080
83 * Type of child entry link
85 #define DIRENTRY_RELATION_PREVIOUS 0
86 #define DIRENTRY_RELATION_NEXT 1
87 #define DIRENTRY_RELATION_DIR 2
90 * type constant used in files for the root storage
92 #define STGTY_ROOT 0x05
95 * These defines assume a hardcoded blocksize. The code will assert
96 * if the blocksize is different. Some changes will have to be done if it
97 * becomes the case.
99 #define BIG_BLOCK_SIZE 0x200
100 #define COUNT_BBDEPOTINHEADER 109
101 #define LIMIT_TO_USE_SMALL_BLOCK 0x1000
102 #define NUM_BLOCKS_PER_DEPOT_BLOCK 128
104 #define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
105 #define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
106 #define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
108 #define STGM_KNOWN_FLAGS (0xf0ff | \
109 STGM_TRANSACTED | STGM_CONVERT | STGM_PRIORITY | STGM_NOSCRATCH | \
110 STGM_NOSNAPSHOT | STGM_DIRECT_SWMR | STGM_DELETEONRELEASE | STGM_SIMPLE)
113 * Forward declarations of all the structures used by the storage
114 * module.
116 typedef struct StorageBaseImpl StorageBaseImpl;
117 typedef struct StorageBaseImplVtbl StorageBaseImplVtbl;
118 typedef struct StorageImpl StorageImpl;
119 typedef struct BlockChainStream BlockChainStream;
120 typedef struct SmallBlockChainStream SmallBlockChainStream;
121 typedef struct IEnumSTATSTGImpl IEnumSTATSTGImpl;
122 typedef struct DirEntry DirEntry;
123 typedef struct StgStreamImpl StgStreamImpl;
126 * A reference to a directory entry in the file or a transacted cache.
128 typedef ULONG DirRef;
131 * This utility structure is used to read/write the information in a directory
132 * entry.
134 struct DirEntry
136 WCHAR name[DIRENTRY_NAME_MAX_LEN];
137 WORD sizeOfNameString;
138 BYTE stgType;
139 DirRef leftChild;
140 DirRef rightChild;
141 DirRef dirRootEntry;
142 GUID clsid;
143 FILETIME ctime;
144 FILETIME mtime;
145 ULONG startingBlock;
146 ULARGE_INTEGER size;
149 /*************************************************************************
150 * Big Block File support
152 * The big block file is an abstraction of a flat file separated in
153 * same sized blocks. The implementation for the methods described in
154 * this section appear in stg_bigblockfile.c
157 typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
160 * Declaration of the functions used to manipulate the BigBlockFile
161 * data structure.
163 BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
164 ILockBytes* pLkByt,
165 DWORD openFlags,
166 ULONG blocksize,
167 BOOL fileBased);
168 void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
169 HRESULT BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
170 HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
171 HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
172 void* buffer, ULONG size, ULONG* bytesRead);
173 HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
174 const void* buffer, ULONG size, ULONG* bytesRead);
176 /*************************************************************************
177 * Ole Convert support
180 void OLECONVERT_CreateOleStream(LPSTORAGE pStorage);
181 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName);
184 /****************************************************************************
185 * Storage32BaseImpl definitions.
187 * This structure defines the base information contained in all implementations
188 * of IStorage32 contained in this file storage implementation.
190 * In OOP terms, this is the base class for all the IStorage32 implementations
191 * contained in this file.
193 struct StorageBaseImpl
195 const IStorageVtbl *lpVtbl; /* Needs to be the first item in the struct
196 * since we want to cast this in a Storage32 pointer */
198 const IPropertySetStorageVtbl *pssVtbl; /* interface for adding a properties stream */
201 * Stream tracking list
204 struct list strmHead;
207 * Storage tracking list
209 struct list storageHead;
212 * Reference count of this object
214 LONG ref;
217 * Ancestor storage (top level)
219 StorageImpl* ancestorStorage;
222 * Index of the directory entry of this storage
224 DirRef storageDirEntry;
227 * virtual methods.
229 const StorageBaseImplVtbl *baseVtbl;
232 * flags that this storage was opened or created with
234 DWORD openFlags;
237 * State bits appear to only be preserved while running. No in the stream
239 DWORD stateBits;
241 /* If set, this overrides the root storage name returned by IStorage_Stat */
242 WCHAR filename[DIRENTRY_NAME_BUFFER_LEN];
244 BOOL create; /* Was the storage created or opened.
245 The behaviour of STGM_SIMPLE depends on this */
248 /* virtual methods for StorageBaseImpl objects */
249 struct StorageBaseImplVtbl {
250 void (*Destroy)(StorageBaseImpl*);
251 HRESULT (*CreateDirEntry)(StorageBaseImpl*,const DirEntry*,DirRef*);
254 static inline void StorageBaseImpl_Destroy(StorageBaseImpl *This)
256 This->baseVtbl->Destroy(This);
259 static inline HRESULT StorageBaseImpl_CreateDirEntry(StorageBaseImpl *This,
260 const DirEntry *newData, DirRef *index)
262 return This->baseVtbl->CreateDirEntry(This, newData, index);
265 /****************************************************************************
266 * StorageBaseImpl stream list handlers
269 void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm);
270 void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm);
272 /****************************************************************************
273 * Storage32Impl definitions.
275 * This implementation of the IStorage32 interface represents a root
276 * storage. Basically, a document file.
278 struct StorageImpl
280 struct StorageBaseImpl base;
283 * The following data members are specific to the Storage32Impl
284 * class
286 HANDLE hFile; /* Physical support for the Docfile */
287 LPOLESTR pwcsName; /* Full path of the document file */
290 * File header
292 WORD bigBlockSizeBits;
293 WORD smallBlockSizeBits;
294 ULONG bigBlockSize;
295 ULONG smallBlockSize;
296 ULONG bigBlockDepotCount;
297 ULONG rootStartBlock;
298 ULONG smallBlockDepotStart;
299 ULONG extBigBlockDepotStart;
300 ULONG extBigBlockDepotCount;
301 ULONG bigBlockDepotStart[COUNT_BBDEPOTINHEADER];
303 ULONG blockDepotCached[NUM_BLOCKS_PER_DEPOT_BLOCK];
304 ULONG indexBlockDepotCached;
305 ULONG prevFreeBlock;
308 * Abstraction of the big block chains for the chains of the header.
310 BlockChainStream* rootBlockChain;
311 BlockChainStream* smallBlockDepotChain;
312 BlockChainStream* smallBlockRootChain;
315 * Pointer to the big block file abstraction
317 BigBlockFile* bigBlockFile;
320 HRESULT StorageImpl_ReadRawDirEntry(
321 StorageImpl *This,
322 ULONG index,
323 BYTE *buffer);
325 void UpdateRawDirEntry(
326 BYTE *buffer,
327 const DirEntry *newData);
329 HRESULT StorageImpl_WriteRawDirEntry(
330 StorageImpl *This,
331 ULONG index,
332 const BYTE *buffer);
334 HRESULT StorageImpl_ReadDirEntry(
335 StorageImpl* This,
336 DirRef index,
337 DirEntry* buffer);
339 HRESULT StorageImpl_WriteDirEntry(
340 StorageImpl* This,
341 DirRef index,
342 const DirEntry* buffer);
344 BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
345 StorageImpl* This,
346 SmallBlockChainStream** ppsbChain);
348 SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
349 StorageImpl* This,
350 BlockChainStream** ppbbChain);
352 /****************************************************************************
353 * StgStreamImpl definitions.
355 * This class implements the IStream32 interface and represents a stream
356 * located inside a storage object.
358 struct StgStreamImpl
360 const IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct
361 * since we want to cast this to an IStream pointer */
364 * We are an entry in the storage object's stream handler list
367 struct list StrmListEntry;
370 * Reference count
372 LONG ref;
375 * Storage that is the parent(owner) of the stream
377 StorageBaseImpl* parentStorage;
380 * Access mode of this stream.
382 DWORD grfMode;
385 * Index of the directory entry that owns (points to) this stream.
387 DirRef dirEntry;
390 * Helper variable that contains the size of the stream
392 ULARGE_INTEGER streamSize;
395 * This is the current position of the cursor in the stream
397 ULARGE_INTEGER currentPosition;
400 * The information in the stream is represented by a chain of small blocks
401 * or a chain of large blocks. Depending on the case, one of the two
402 * following variables points to that information.
404 BlockChainStream* bigBlockChain;
405 SmallBlockChainStream* smallBlockChain;
409 * Method definition for the StgStreamImpl class.
411 StgStreamImpl* StgStreamImpl_Construct(
412 StorageBaseImpl* parentStorage,
413 DWORD grfMode,
414 DirRef dirEntry);
417 /******************************************************************************
418 * Endian conversion macros
420 #ifdef WORDS_BIGENDIAN
422 #define htole32(x) RtlUlongByteSwap(x)
423 #define htole16(x) RtlUshortByteSwap(x)
424 #define lendian32toh(x) RtlUlongByteSwap(x)
425 #define lendian16toh(x) RtlUshortByteSwap(x)
427 #else
429 #define htole32(x) (x)
430 #define htole16(x) (x)
431 #define lendian32toh(x) (x)
432 #define lendian16toh(x) (x)
434 #endif
436 /******************************************************************************
437 * The StorageUtl_ functions are miscellaneous utility functions. Most of which
438 * are abstractions used to read values from file buffers without having to
439 * worry about bit order
441 void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value);
442 void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value);
443 void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value);
444 void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value);
445 void StorageUtl_ReadULargeInteger(const BYTE* buffer, ULONG offset,
446 ULARGE_INTEGER* value);
447 void StorageUtl_WriteULargeInteger(BYTE* buffer, ULONG offset,
448 const ULARGE_INTEGER *value);
449 void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value);
450 void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value);
451 void StorageUtl_CopyDirEntryToSTATSTG(StorageBaseImpl *storage,STATSTG* destination,
452 const DirEntry* source, int statFlags);
454 /****************************************************************************
455 * BlockChainStream definitions.
457 * The BlockChainStream class is a utility class that is used to create an
458 * abstraction of the big block chains in the storage file.
460 struct BlockChainStream
462 StorageImpl* parentStorage;
463 ULONG* headOfStreamPlaceHolder;
464 DirRef ownerDirEntry;
465 ULONG lastBlockNoInSequence;
466 ULONG lastBlockNoInSequenceIndex;
467 ULONG tailIndex;
468 ULONG numBlocks;
472 * Methods for the BlockChainStream class.
474 BlockChainStream* BlockChainStream_Construct(
475 StorageImpl* parentStorage,
476 ULONG* headOfStreamPlaceHolder,
477 DirRef dirEntry);
479 void BlockChainStream_Destroy(
480 BlockChainStream* This);
482 HRESULT BlockChainStream_ReadAt(
483 BlockChainStream* This,
484 ULARGE_INTEGER offset,
485 ULONG size,
486 void* buffer,
487 ULONG* bytesRead);
489 HRESULT BlockChainStream_WriteAt(
490 BlockChainStream* This,
491 ULARGE_INTEGER offset,
492 ULONG size,
493 const void* buffer,
494 ULONG* bytesWritten);
496 BOOL BlockChainStream_SetSize(
497 BlockChainStream* This,
498 ULARGE_INTEGER newSize);
500 /****************************************************************************
501 * SmallBlockChainStream definitions.
503 * The SmallBlockChainStream class is a utility class that is used to create an
504 * abstraction of the small block chains in the storage file.
506 struct SmallBlockChainStream
508 StorageImpl* parentStorage;
509 DirRef ownerDirEntry;
510 ULONG* headOfStreamPlaceHolder;
514 * Methods of the SmallBlockChainStream class.
516 SmallBlockChainStream* SmallBlockChainStream_Construct(
517 StorageImpl* parentStorage,
518 ULONG* headOfStreamPlaceHolder,
519 DirRef dirEntry);
521 void SmallBlockChainStream_Destroy(
522 SmallBlockChainStream* This);
524 HRESULT SmallBlockChainStream_ReadAt(
525 SmallBlockChainStream* This,
526 ULARGE_INTEGER offset,
527 ULONG size,
528 void* buffer,
529 ULONG* bytesRead);
531 HRESULT SmallBlockChainStream_WriteAt(
532 SmallBlockChainStream* This,
533 ULARGE_INTEGER offset,
534 ULONG size,
535 const void* buffer,
536 ULONG* bytesWritten);
538 BOOL SmallBlockChainStream_SetSize(
539 SmallBlockChainStream* This,
540 ULARGE_INTEGER newSize);
543 #endif /* __STORAGE32_H__ */