3 * Implemented using the documentation of the LAOLA project at
4 * <URL:http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/index.html>
5 * (Thanks to Martin Schwartz <schwartz@cs.tu-berlin.de>)
7 * Copyright 1998 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include <sys/types.h>
30 #define NONAMELESSUNION
36 #include "wine/winbase16.h"
39 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
44 WINE_DECLARE_DEBUG_CHANNEL(relay
);
46 struct storage_header
{
47 BYTE magic
[8]; /* 00: magic */
48 BYTE unknown1
[36]; /* 08: unknown */
49 DWORD num_of_bbd_blocks
;/* 2C: length of big datablocks */
50 DWORD root_startblock
;/* 30: root storage first big block */
51 DWORD unknown2
[2]; /* 34: unknown */
52 DWORD sbd_startblock
; /* 3C: small block depot first big block */
53 DWORD unknown3
[3]; /* 40: unknown */
54 DWORD bbd_list
[109]; /* 4C: big data block list (up to end of sector)*/
56 struct storage_pps_entry
{
57 WCHAR pps_rawname
[32];/* 00: \0 terminated widechar name */
58 WORD pps_sizeofname
; /* 40: namelength in bytes */
59 BYTE pps_type
; /* 42: flags, 1 storage/dir, 2 stream, 5 root */
60 BYTE pps_unknown0
; /* 43: unknown */
61 DWORD pps_prev
; /* 44: previous pps */
62 DWORD pps_next
; /* 48: next pps */
63 DWORD pps_dir
; /* 4C: directory pps */
64 GUID pps_guid
; /* 50: class ID */
65 DWORD pps_unknown1
; /* 60: unknown */
66 FILETIME pps_ft1
; /* 64: filetime1 */
67 FILETIME pps_ft2
; /* 6C: filetime2 */
68 DWORD pps_sb
; /* 74: data startblock */
69 DWORD pps_size
; /* 78: datalength. (<0x1000)?small:big blocks*/
70 DWORD pps_unknown2
; /* 7C: unknown */
73 #define STORAGE_CHAINENTRY_FAT 0xfffffffd
74 #define STORAGE_CHAINENTRY_ENDOFCHAIN 0xfffffffe
75 #define STORAGE_CHAINENTRY_FREE 0xffffffff
78 static const BYTE STORAGE_magic
[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
83 #define SMALLBLOCKS_PER_BIGBLOCK (BIGSIZE/SMALLSIZE)
85 #define READ_HEADER(str) STORAGE_get_big_block(str,-1,(LPBYTE)&sth);assert(!memcmp(STORAGE_magic,sth.magic,sizeof(STORAGE_magic)));
86 static IStorage16Vtbl stvt16
;
87 static const IStorage16Vtbl
*segstvt16
= NULL
;
88 static IStream16Vtbl strvt16
;
89 static const IStream16Vtbl
*segstrvt16
= NULL
;
91 /*ULONG WINAPI IStorage16_AddRef(LPSTORAGE16 this);*/
92 static void _create_istorage16(LPSTORAGE16
*stg
);
93 static void _create_istream16(LPSTREAM16
*str
);
97 /* The following is taken from the CorVu implementation of docfiles, and
98 * documents things about the file format that are not implemented here, and
99 * not documented by the LAOLA project. The CorVu implementation was posted
100 * to wine-devel in February 2004, and released under the LGPL at the same
101 * time. Because that implementation is in C++, it's not directly usable in
102 * Wine, but does have documentation value.
105 * #define DF_EXT_VTOC -4
106 * #define DF_VTOC_VTOC -3
107 * #define DF_VTOC_EOF -2
108 * #define DF_VTOC_FREE -1
109 * #define DF_NAMELEN 0x20 // Maximum entry name length - 31 characters plus
110 * // a NUL terminator
112 * #define DF_FT_STORAGE 1
113 * #define DF_FT_STREAM 2
114 * #define DF_FT_LOCKBYTES 3 // Not used -- How the bloody hell did I manage
115 * #define DF_FT_PROPERTY 4 // Not Used -- to figure these two out?
116 * #define DF_FT_ROOT 5
118 * #define DF_BLOCK_SIZE 0x200
119 * #define DF_VTOC_SIZE 0x80
120 * #define DF_DE_PER_BLOCK 4
121 * #define DF_STREAM_BLOCK_SIZE 0x40
123 * A DocFile is divided into blocks of 512 bytes.
124 * The first block contains the header.
126 * The file header contains The first 109 entries in the VTOC of VTOCs.
128 * Each block pointed to by a VTOC of VTOCs contains a VTOC, which
129 * includes block chains - just like FAT. This is a somewhat poor
130 * design for the following reasons:
132 * 1. FAT was a poor file system design to begin with, and
133 * has long been known to be horrendously inefficient
134 * for day to day operations.
136 * 2. The problem is compounded here, since the file
137 * level streams are generally *not* read sequentially.
138 * This means that a significant percentage of reads
139 * require seeking from the start of the chain.
141 * Data chains also contain an internal VTOC. The block size for
142 * the standard VTOC is 512. The block size for the internal VTOC
145 * Now, the 109 blocks in the VTOC of VTOCs allows for files of
146 * up to around 7MB. So what do you think happens if that's
147 * exceeded? Well, there's an entry in the header block which
148 * points to the first block used as additional storage for
151 * Now we can get up to around 15MB. Now, guess how the file
152 * format adds in another block to the VTOC of VTOCs. Come on,
153 * it's no big surprise. That's right - the last entry in each
154 * block extending the VTOC of VTOCs is, you guessed it, the
155 * block number of the next block containing an extension to
156 * the VTOC of VTOCs. The VTOC of VTOCs is chained!!!!
160 * 1. If you are using a FAT file system, the location of
161 * your file's blocks is stored in chains.
163 * 2. At the abstract level, the file contains a VTOC of VTOCs,
164 * which is stored in the most inefficient possible format for
165 * random access - a chain (AKA list).
167 * 3. The VTOC of VTOCs contains descriptions of three file level
170 * a. The Directory stream
172 * c. The Data VTOC stream
174 * These are, of course, represented as chains.
176 * 4. The Data VTOC contains data describing the chains of blocks
177 * within the Data stream.
179 * That's right - we have a total of four levels of block chains!
181 * Now, is that complicated enough for you? No? OK, there's another
182 * complication. If an individual stream (ie. an IStream) reaches
183 * 4096 bytes in size, it gets moved from the Data Stream to
184 * a new file level stream. Now, if the stream then gets truncated
185 * back to less than 4096 bytes, it returns to the data stream.
187 * The effect of using this format can be seen very easily. Pick
188 * an arbitrary application with a grid data representation that
189 * can export to both Lotus 123 and Excel 5 or higher. Export
190 * a large file to Lotus 123 and time it. Export the same thing
191 * to Excel 5 and time that. The difference is the inefficiency
192 * of the Microsoft DocFile format.
195 * #define TOTAL_SIMPLE_VTOCS 109
197 * struct DocFile_Header
199 * df_byte iMagic1; // 0xd0
200 * df_byte iMagic2; // 0xcf
201 * df_byte iMagic3; // 0x11
202 * df_byte iMagic4; // 0xe0 - Spells D0CF11E0, or DocFile
203 * df_byte iMagic5; // 161 (igi upside down)
204 * df_byte iMagic6; // 177 (lli upside down - see below
205 * df_byte iMagic7; // 26 (gz upside down)
206 * df_byte iMagic8; // 225 (szz upside down) - see below
207 * df_int4 aiUnknown1[4];
208 * df_int4 iVersion; // DocFile Version - 0x03003E
209 * df_int4 aiUnknown2[4];
210 * df_int4 nVTOCs; // Number of VTOCs
211 * df_int4 iFirstDirBlock; // First Directory Block
212 * df_int4 aiUnknown3[2];
213 * df_int4 iFirstDataVTOC; // First data VTOC block
214 * df_int4 iHasData; // 1 if there is data in the file - yes, this is important
215 * df_int4 iExtendedVTOC; // Extended VTOC location
216 * df_int4 iExtendedVTOCSize; // Size of extended VTOC (+1?)
217 * df_int4 aiVTOCofVTOCs[TOTAL_SIMPLE_VTOCS];
220 * struct DocFile_VTOC
222 * df_int4 aiBlocks[DF_VTOC_SIZE];
226 * The meaning of the magic numbers
228 * 0xd0cf11e0 is DocFile with a zero on the end (sort of)
230 * If you key 177161 into a calculator, then turn the calculator
231 * upside down, you get igilli, which may be a reference to
232 * somebody's name, or to the Hebrew word for "angel".
234 * If you key 26225 into a calculator, then turn it upside down, you
235 * get szzgz. Microsoft has a tradition of creating nonsense words
236 * using the letters s, g, z and y. We think szzgz may be one of the
237 * Microsoft placeholder variables, along the lines of foo, bar and baz.
238 * Alternatively, it could be 22526, which would be gzszz.
241 * struct DocFile_DirEnt
243 * df_char achEntryName[DF_NAMELEN]; // Entry Name
244 * df_int2 iNameLen; // Name length in bytes, including NUL terminator
245 * df_byte iFileType; // Entry type
246 * df_byte iColour; // 1 = Black, 0 = Red
247 * df_int4 iLeftSibling; // Next Left Sibling Entry - See below
248 * df_int4 iRightSibling; // Next Right Sibling Entry
249 * df_int4 iFirstChild; // First Child Entry
250 * df_byte achClassID[16]; // Class ID
251 * df_int4 iStateBits; // [GS]etStateBits value
252 * df_int4 iCreatedLow; // Low DWORD of creation time
253 * df_int4 iCreatedHigh; // High DWORD of creation time
254 * df_int4 iModifiedLow; // Low DWORD of modification time
255 * df_int4 iModifiedHigh; // High DWORD of modification time
256 * df_int4 iVTOCPosition; // VTOC Position
257 * df_int4 iFileSize; // Size of the stream
258 * df_int4 iZero; // We think this is part of the 64 bit stream size - must be 0
264 * Siblings are stored in an obscure but incredibly elegant
265 * data structure called a red-black tree. This is generally
266 * defined as a 2-3-4 tree stored in a binary tree.
268 * A red-black tree can always be balanced very easily. The rules
269 * for a red-black tree are as follows:
271 * 1. The root node is always black.
272 * 2. The parent of a red node is always black.
274 * There is a Java demo of red-black trees at:
276 * http://langevin.usc.edu/BST/RedBlackTree-Example.html
278 * This demo is an excellent tool for learning how red-black
279 * trees work, without having to go through the process of
280 * learning how they were derived.
282 * Within the tree, elements are ordered by the length of the
283 * name and within that, ASCII order by name. This causes the
284 * apparently bizarre reordering you see when you use dfview.
286 * This is a somewhat bizarre choice. It suggests that the
287 * designer of the DocFile format was trying to optimise
288 * searching through the directory entries. However searching
289 * through directory entries is a relatively rare operation.
290 * Reading and seeking within a stream are much more common
291 * operations, especially within the file level streams, yet
292 * these use the horrendously inefficient FAT chains.
294 * This suggests that the designer was probably somebody
295 * fresh out of university, who had some basic knowledge of
296 * basic data structures, but little knowledge of anything
297 * more practical. It is bizarre to attempt to optimise
298 * directory searches while not using a more efficient file
299 * block locating system than FAT (seedling/sapling/tree
300 * would result in a massive improvement - in fact we have
301 * an alternative to docfiles that we use internally that
302 * uses seedling/sapling/tree and *is* far more efficient).
304 * It is worth noting that the MS implementation of red-black
305 * trees is incorrect (I can tell you're surprised) and
306 * actually causes more operations to occur than are really
307 * needed. Fortunately the fact that our implementation is
308 * correct will not cause any problems - the MS implementation
309 * still appears to cause the tree to satisfy the rules, albeit
310 * a sequence of the same insertions in the different
311 * implementations may result in a different, and possibly
312 * deeper (but never shallower) tree.
319 /* --- IStorage16 implementation struct */
323 IStorage16 IStorage16_iface
;
325 /* IStorage16 fields */
326 SEGPTR thisptr
; /* pointer to this struct as segmented */
327 struct storage_pps_entry stde
;
333 /******************************************************************************
334 * STORAGE_get_big_block [Internal]
336 * Reading OLE compound storage
339 STORAGE_get_big_block(stream_access16
*str
,int n
,BYTE
*block
)
345 if ((SetFilePointer( str
->hf
, (n
+1)*BIGSIZE
, NULL
,
346 SEEK_SET
) == INVALID_SET_FILE_POINTER
) && GetLastError())
348 WARN("(%p,%d,%p), seek failed (%d)\n",str
->hf
, n
, block
, GetLastError());
351 if (!ReadFile( str
->hf
, block
, BIGSIZE
, &result
, NULL
) || result
!= BIGSIZE
)
353 WARN("(hf=%p, block size %d): read didn't read (%d)\n",str
->hf
,n
,GetLastError());
361 args
[0] = (DWORD
)str
->lockbytes
; /* iface */
362 args
[1] = (n
+1)*BIGSIZE
;
363 args
[2] = 0; /* ULARGE_INTEGER offset */
364 args
[3] = WOWGlobalAllocLock16( 0, BIGSIZE
, &hsig
); /* sig */
368 if (!WOWCallback16Ex(
369 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
370 (SEGPTR
)((LPLOCKBYTES16
)MapSL(str
->lockbytes
))->lpVtbl
)
377 ERR("CallTo16 ILockBytes16::ReadAt() failed, hres %x\n",hres
);
380 memcpy(block
, MapSL(args
[3]), BIGSIZE
);
381 WOWGlobalUnlockFree16(args
[3]);
387 _ilockbytes16_writeat(SEGPTR lockbytes
, DWORD offset
, DWORD length
, void *buffer
) {
391 args
[0] = (DWORD
)lockbytes
; /* iface */
393 args
[2] = 0; /* ULARGE_INTEGER offset */
394 args
[3] = (DWORD
)MapLS( buffer
);
398 /* THIS_ ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten); */
400 if (!WOWCallback16Ex(
401 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
402 (SEGPTR
)((LPLOCKBYTES16
)MapSL(lockbytes
))->lpVtbl
)
409 ERR("CallTo16 ILockBytes16::WriteAt() failed, hres %x\n",hres
);
416 /******************************************************************************
417 * STORAGE_put_big_block [INTERNAL]
420 STORAGE_put_big_block(stream_access16
*str
,int n
,BYTE
*block
)
426 if ((SetFilePointer( str
->hf
, (n
+1)*BIGSIZE
, NULL
,
427 SEEK_SET
) == INVALID_SET_FILE_POINTER
) && GetLastError())
429 WARN("seek failed (%d)\n",GetLastError());
432 if (!WriteFile( str
->hf
, block
, BIGSIZE
, &result
, NULL
) || result
!= BIGSIZE
)
434 WARN(" write failed (%d)\n",GetLastError());
439 _ilockbytes16_writeat(str
->lockbytes
, (n
+1)*BIGSIZE
, BIGSIZE
, block
);
444 /******************************************************************************
445 * STORAGE_get_next_big_blocknr [INTERNAL]
448 STORAGE_get_next_big_blocknr(stream_access16
*str
,int blocknr
) {
449 INT bbs
[BIGSIZE
/sizeof(INT
)];
450 struct storage_header sth
;
454 assert(blocknr
>>7<sth
.num_of_bbd_blocks
);
455 if (sth
.bbd_list
[blocknr
>>7]==0xffffffff)
457 if (!STORAGE_get_big_block(str
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
))
459 assert(bbs
[blocknr
&0x7f]!=STORAGE_CHAINENTRY_FREE
);
460 return bbs
[blocknr
&0x7f];
463 /******************************************************************************
464 * STORAGE_get_nth_next_big_blocknr [INTERNAL]
467 STORAGE_get_nth_next_big_blocknr(stream_access16
*str
,int blocknr
,int nr
) {
468 INT bbs
[BIGSIZE
/sizeof(INT
)];
470 struct storage_header sth
;
472 TRACE("(blocknr=%d, nr=%d)\n", blocknr
, nr
);
477 assert((blocknr
>>7)<sth
.num_of_bbd_blocks
);
478 assert(sth
.bbd_list
[blocknr
>>7]!=0xffffffff);
480 /* simple caching... */
481 if (lastblock
!=sth
.bbd_list
[blocknr
>>7]) {
482 BOOL ret
= STORAGE_get_big_block(str
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
);
484 lastblock
= sth
.bbd_list
[blocknr
>>7];
486 blocknr
= bbs
[blocknr
&0x7f];
491 /******************************************************************************
492 * STORAGE_get_root_pps_entry [Internal]
495 STORAGE_get_root_pps_entry(stream_access16
* str
,struct storage_pps_entry
*pstde
) {
498 struct storage_pps_entry
*stde
=(struct storage_pps_entry
*)block
;
499 struct storage_header sth
;
502 blocknr
= sth
.root_startblock
;
503 TRACE("startblock is %d\n", blocknr
);
505 BOOL ret
= STORAGE_get_big_block(str
,blocknr
,block
);
508 if (!stde
[i
].pps_sizeofname
)
510 if (stde
[i
].pps_type
==5) {
515 blocknr
=STORAGE_get_next_big_blocknr(str
,blocknr
);
516 TRACE("next block is %d\n", blocknr
);
521 /******************************************************************************
522 * STORAGE_get_small_block [INTERNAL]
525 STORAGE_get_small_block(stream_access16
*str
,int blocknr
,BYTE
*sblock
) {
528 struct storage_pps_entry root
;
531 TRACE("(blocknr=%d)\n", blocknr
);
533 ret
= STORAGE_get_root_pps_entry(str
,&root
);
535 bigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
536 assert(bigblocknr
>=0);
537 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
540 memcpy(sblock
,((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),SMALLSIZE
);
544 /******************************************************************************
545 * STORAGE_put_small_block [INTERNAL]
548 STORAGE_put_small_block(stream_access16
*str
,int blocknr
,const BYTE
*sblock
) {
551 struct storage_pps_entry root
;
555 TRACE("(blocknr=%d)\n", blocknr
);
557 ret
= STORAGE_get_root_pps_entry(str
,&root
);
559 bigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
560 assert(bigblocknr
>=0);
561 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
564 memcpy(((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),sblock
,SMALLSIZE
);
565 ret
= STORAGE_put_big_block(str
,bigblocknr
,block
);
570 /******************************************************************************
571 * STORAGE_get_next_small_blocknr [INTERNAL]
574 STORAGE_get_next_small_blocknr(stream_access16
*str
,int blocknr
) {
576 LPINT sbd
= (LPINT
)block
;
578 struct storage_header sth
;
581 TRACE("(blocknr=%d)\n", blocknr
);
584 bigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,sth
.sbd_startblock
,blocknr
/128);
585 assert(bigblocknr
>=0);
586 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
588 assert(sbd
[blocknr
& 127]!=STORAGE_CHAINENTRY_FREE
);
589 return sbd
[blocknr
& (128-1)];
592 /******************************************************************************
593 * STORAGE_get_nth_next_small_blocknr [INTERNAL]
596 STORAGE_get_nth_next_small_blocknr(stream_access16
*str
,int blocknr
,int nr
) {
597 int lastblocknr
=-129;
599 LPINT sbd
= (LPINT
)block
;
600 struct storage_header sth
;
603 TRACE("(blocknr=%d, nr=%d)\n", blocknr
, nr
);
606 while ((nr
--) && (blocknr
>=0)) {
607 if (lastblocknr
/128!=blocknr
/128) {
609 bigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,sth
.sbd_startblock
,blocknr
/128);
610 assert(bigblocknr
>=0);
611 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
613 lastblocknr
= blocknr
;
615 assert(lastblocknr
>=0);
617 blocknr
=sbd
[blocknr
& (128-1)];
618 assert(blocknr
!=STORAGE_CHAINENTRY_FREE
);
623 /******************************************************************************
624 * STORAGE_get_pps_entry [INTERNAL]
627 STORAGE_get_pps_entry(stream_access16
*str
,int n
,struct storage_pps_entry
*pstde
) {
630 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
631 struct storage_header sth
;
634 TRACE("(n=%d)\n", n
);
636 /* we have 4 pps entries per big block */
637 blocknr
= STORAGE_get_nth_next_big_blocknr(str
,sth
.root_startblock
,n
/4);
639 ret
= STORAGE_get_big_block(str
,blocknr
,block
);
646 /******************************************************************************
647 * STORAGE_put_pps_entry [Internal]
650 STORAGE_put_pps_entry(stream_access16
*str
,int n
,const struct storage_pps_entry
*pstde
) {
653 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
654 struct storage_header sth
;
657 TRACE("(n=%d)\n", n
);
659 /* we have 4 pps entries per big block */
660 blocknr
= STORAGE_get_nth_next_big_blocknr(str
,sth
.root_startblock
,n
/4);
662 ret
= STORAGE_get_big_block(str
,blocknr
,block
);
665 ret
= STORAGE_put_big_block(str
,blocknr
,block
);
670 /******************************************************************************
671 * STORAGE_look_for_named_pps [Internal]
674 STORAGE_look_for_named_pps(stream_access16
*str
,int n
,LPOLESTR name
) {
675 struct storage_pps_entry stde
;
678 TRACE("(n=%d,name=%s)\n", n
, debugstr_w(name
));
681 if (1!=STORAGE_get_pps_entry(str
,n
,&stde
))
684 if (!wcscmp(name
,stde
.pps_rawname
))
686 if (stde
.pps_prev
!= -1) {
687 ret
=STORAGE_look_for_named_pps(str
,stde
.pps_prev
,name
);
691 if (stde
.pps_next
!= -1) {
692 ret
=STORAGE_look_for_named_pps(str
,stde
.pps_next
,name
);
699 /******************************************************************************
700 * STORAGE_dump_pps_entry [Internal]
702 * This function is there to simplify debugging. It is otherwise unused.
705 STORAGE_dump_pps_entry(struct storage_pps_entry
*stde
) {
708 WideCharToMultiByte( CP_ACP
, 0, stde
->pps_rawname
, -1, name
, sizeof(name
), NULL
, NULL
);
709 if (!stde
->pps_sizeofname
)
711 TRACE("name: %s\n",name
);
712 TRACE("type: %d\n",stde
->pps_type
);
713 TRACE("prev pps: %d\n",stde
->pps_prev
);
714 TRACE("next pps: %d\n",stde
->pps_next
);
715 TRACE("dir pps: %d\n",stde
->pps_dir
);
716 TRACE("guid: %s\n",debugstr_guid(&(stde
->pps_guid
)));
717 if (stde
->pps_type
!=2) {
720 RtlTimeToSecondsSince1970((LARGE_INTEGER
*)&(stde
->pps_ft1
),&dw
);
722 TRACE("ts1: %s\n",ctime(&t
));
723 RtlTimeToSecondsSince1970((LARGE_INTEGER
*)&(stde
->pps_ft2
),&dw
);
725 TRACE("ts2: %s\n",ctime(&t
));
727 TRACE("startblock: %d\n",stde
->pps_sb
);
728 TRACE("size: %d\n",stde
->pps_size
);
731 /******************************************************************************
732 * STORAGE_init_storage [INTERNAL]
735 STORAGE_init_storage(stream_access16
*str
) {
738 struct storage_header
*sth
;
739 struct storage_pps_entry
*stde
;
743 SetFilePointer( str
->hf
, 0, NULL
, SEEK_SET
);
744 /* block -1 is the storage header */
745 sth
= (struct storage_header
*)block
;
746 memcpy(sth
->magic
,STORAGE_magic
,8);
747 memset(sth
->unknown1
,0,sizeof(sth
->unknown1
));
748 memset(sth
->unknown2
,0,sizeof(sth
->unknown2
));
749 memset(sth
->unknown3
,0,sizeof(sth
->unknown3
));
750 sth
->num_of_bbd_blocks
= 1;
751 sth
->root_startblock
= 1;
752 sth
->sbd_startblock
= 0xffffffff;
753 memset(sth
->bbd_list
,0xff,sizeof(sth
->bbd_list
));
754 sth
->bbd_list
[0] = 0;
756 if (!WriteFile( str
->hf
, block
, BIGSIZE
, &result
, NULL
) || result
!= BIGSIZE
) return FALSE
;
758 if (!_ilockbytes16_writeat(str
->lockbytes
, 0, BIGSIZE
, block
)) return FALSE
;
760 /* block 0 is the big block directory */
762 memset(block
,0xff,sizeof(block
)); /* mark all blocks as free */
763 bbs
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for this block */
764 bbs
[1]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for directory entry */
766 if (!WriteFile( str
->hf
, block
, BIGSIZE
, &result
, NULL
) || result
!= BIGSIZE
) return FALSE
;
768 if (!_ilockbytes16_writeat(str
->lockbytes
, BIGSIZE
, BIGSIZE
, block
)) return FALSE
;
770 /* block 1 is the root directory entry */
771 memset(block
,0x00,sizeof(block
));
772 stde
= (struct storage_pps_entry
*)block
;
773 MultiByteToWideChar(CP_ACP
, 0, "RootEntry", -1, stde
->pps_rawname
,
774 ARRAY_SIZE(stde
->pps_rawname
));
775 stde
->pps_sizeofname
= (lstrlenW(stde
->pps_rawname
)+1) * sizeof(WCHAR
);
780 stde
->pps_sb
= 0xffffffff;
783 return (WriteFile( str
->hf
, block
, BIGSIZE
, &result
, NULL
) && result
== BIGSIZE
);
785 return _ilockbytes16_writeat(str
->lockbytes
, BIGSIZE
, BIGSIZE
, block
);
789 /******************************************************************************
790 * STORAGE_set_big_chain [Internal]
793 STORAGE_set_big_chain(stream_access16
*str
,int blocknr
,INT type
) {
795 LPINT bbd
= (LPINT
)block
;
796 int nextblocknr
,bigblocknr
;
797 struct storage_header sth
;
801 assert(blocknr
!=type
);
803 bigblocknr
= sth
.bbd_list
[blocknr
/128];
804 assert(bigblocknr
>=0);
805 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
808 nextblocknr
= bbd
[blocknr
&(128-1)];
809 bbd
[blocknr
&(128-1)] = type
;
812 ret
= STORAGE_put_big_block(str
,bigblocknr
,block
);
814 type
= STORAGE_CHAINENTRY_FREE
;
815 blocknr
= nextblocknr
;
820 /******************************************************************************
821 * STORAGE_set_small_chain [Internal]
824 STORAGE_set_small_chain(stream_access16
*str
,int blocknr
,INT type
) {
826 LPINT sbd
= (LPINT
)block
;
827 int lastblocknr
,nextsmallblocknr
,bigblocknr
;
828 struct storage_header sth
;
833 assert(blocknr
!=type
);
834 lastblocknr
=-129;bigblocknr
=-2;
836 /* cache block ... */
837 if (lastblocknr
/128!=blocknr
/128) {
838 bigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,sth
.sbd_startblock
,blocknr
/128);
839 assert(bigblocknr
>=0);
840 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
843 lastblocknr
= blocknr
;
844 nextsmallblocknr
= sbd
[blocknr
&(128-1)];
845 sbd
[blocknr
&(128-1)] = type
;
846 ret
= STORAGE_put_big_block(str
,bigblocknr
,block
);
850 type
= STORAGE_CHAINENTRY_FREE
;
851 blocknr
= nextsmallblocknr
;
856 /******************************************************************************
857 * STORAGE_get_free_big_blocknr [Internal]
860 STORAGE_get_free_big_blocknr(stream_access16
*str
) {
862 LPINT sbd
= (LPINT
)block
;
863 int lastbigblocknr
,i
,bigblocknr
;
864 unsigned int curblock
;
865 struct storage_header sth
;
871 bigblocknr
= sth
.bbd_list
[curblock
];
872 while (curblock
<sth
.num_of_bbd_blocks
) {
873 assert(bigblocknr
>=0);
874 ret
= STORAGE_get_big_block(str
,bigblocknr
,block
);
877 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
878 sbd
[i
] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
879 ret
= STORAGE_put_big_block(str
,bigblocknr
,block
);
881 memset(block
,0x42,sizeof(block
));
882 ret
= STORAGE_put_big_block(str
,i
+curblock
*128,block
);
884 return i
+curblock
*128;
886 lastbigblocknr
= bigblocknr
;
887 bigblocknr
= sth
.bbd_list
[++curblock
];
889 bigblocknr
= curblock
*128;
890 /* since we have marked all blocks from 0 up to curblock*128-1
891 * the next free one is curblock*128, where we happily put our
892 * next large block depot.
894 memset(block
,0xff,sizeof(block
));
895 /* mark the block allocated and returned by this function */
896 sbd
[1] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
897 ret
= STORAGE_put_big_block(str
,bigblocknr
,block
);
900 /* if we had a bbd block already (most likely) we need
901 * to link the new one into the chain
903 if (lastbigblocknr
!=-1) {
904 ret
= STORAGE_set_big_chain(str
,lastbigblocknr
,bigblocknr
);
907 sth
.bbd_list
[curblock
]=bigblocknr
;
908 sth
.num_of_bbd_blocks
++;
909 assert(sth
.num_of_bbd_blocks
==curblock
+1);
910 ret
= STORAGE_put_big_block(str
,-1,(LPBYTE
)&sth
);
913 /* Set the end of the chain for the bigblockdepots */
914 ret
= STORAGE_set_big_chain(str
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
);
916 /* add 1, for the first entry is used for the additional big block
917 * depot. (means we already used bigblocknr) */
918 memset(block
,0x42,sizeof(block
));
919 /* allocate this block (filled with 0x42) */
920 ret
= STORAGE_put_big_block(str
,bigblocknr
+1,block
);
926 /******************************************************************************
927 * STORAGE_get_free_small_blocknr [Internal]
930 STORAGE_get_free_small_blocknr(stream_access16
*str
) {
932 LPINT sbd
= (LPINT
)block
;
933 int lastbigblocknr
,newblocknr
,i
,curblock
,bigblocknr
;
934 struct storage_pps_entry root
;
935 struct storage_header sth
;
938 bigblocknr
= sth
.sbd_startblock
;
942 while (bigblocknr
>=0) {
943 if (!STORAGE_get_big_block(str
,bigblocknr
,block
))
946 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
947 sbd
[i
]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
948 newblocknr
= i
+curblock
*128;
953 lastbigblocknr
= bigblocknr
;
954 bigblocknr
= STORAGE_get_next_big_blocknr(str
,bigblocknr
);
957 if (newblocknr
==-1) {
958 bigblocknr
= STORAGE_get_free_big_blocknr(str
);
962 memset(block
,0xff,sizeof(block
));
963 sbd
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
964 if (!STORAGE_put_big_block(str
,bigblocknr
,block
))
966 if (lastbigblocknr
==-1) {
967 sth
.sbd_startblock
= bigblocknr
;
968 if (!STORAGE_put_big_block(str
,-1,(LPBYTE
)&sth
)) /* need to write it */
971 if (!STORAGE_set_big_chain(str
,lastbigblocknr
,bigblocknr
))
974 if (!STORAGE_set_big_chain(str
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
976 newblocknr
= curblock
*128;
978 /* allocate enough big blocks for storing the allocated small block */
979 if (!STORAGE_get_root_pps_entry(str
,&root
))
984 lastbigblocknr
= STORAGE_get_nth_next_big_blocknr(str
,root
.pps_sb
,(root
.pps_size
-1)/BIGSIZE
);
985 while (root
.pps_size
< (newblocknr
*SMALLSIZE
+SMALLSIZE
-1)) {
986 /* we need to allocate more stuff */
987 bigblocknr
= STORAGE_get_free_big_blocknr(str
);
991 if (root
.pps_sb
==-1) {
992 root
.pps_sb
= bigblocknr
;
993 root
.pps_size
+= BIGSIZE
;
995 if (!STORAGE_set_big_chain(str
,lastbigblocknr
,bigblocknr
))
997 root
.pps_size
+= BIGSIZE
;
999 lastbigblocknr
= bigblocknr
;
1001 if (!STORAGE_set_big_chain(str
,lastbigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1003 if (!STORAGE_put_pps_entry(str
,0,&root
))
1008 /******************************************************************************
1009 * STORAGE_get_free_pps_entry [Internal]
1012 STORAGE_get_free_pps_entry(stream_access16
*str
) {
1013 int blocknr
, i
, curblock
, lastblocknr
=-1;
1014 BYTE block
[BIGSIZE
];
1015 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)block
;
1016 struct storage_header sth
;
1019 blocknr
= sth
.root_startblock
;
1022 while (blocknr
>=0) {
1023 if (!STORAGE_get_big_block(str
,blocknr
,block
))
1026 if (stde
[i
].pps_sizeofname
==0) /* free */
1027 return curblock
*4+i
;
1028 lastblocknr
= blocknr
;
1029 blocknr
= STORAGE_get_next_big_blocknr(str
,blocknr
);
1032 assert(blocknr
==STORAGE_CHAINENTRY_ENDOFCHAIN
);
1033 blocknr
= STORAGE_get_free_big_blocknr(str
);
1034 /* sth invalidated */
1038 if (!STORAGE_set_big_chain(str
,lastblocknr
,blocknr
))
1040 if (!STORAGE_set_big_chain(str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1042 memset(block
,0,sizeof(block
));
1043 STORAGE_put_big_block(str
,blocknr
,block
);
1047 /* --- IStream16 implementation */
1051 IStream16 IStream16_iface
;
1053 /* IStream16 fields */
1054 SEGPTR thisptr
; /* pointer to this struct as segmented */
1055 struct storage_pps_entry stde
;
1057 ULARGE_INTEGER offset
;
1058 stream_access16 str
;
1061 static inline IStream16Impl
*impl_from_IStream16(IStream16
*iface
)
1063 return CONTAINING_RECORD(iface
, IStream16Impl
, IStream16_iface
);
1066 /******************************************************************************
1067 * IStream16_QueryInterface [STORAGE.518]
1069 HRESULT CDECL
IStream16_fnQueryInterface(IStream16
*iface
, REFIID refiid
, void **obj
)
1071 IStream16Impl
*This
= impl_from_IStream16(iface
);
1072 TRACE_(relay
)("(%p)->(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
1073 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1077 return OLE_E_ENUM_NOMORE
;
1081 /******************************************************************************
1082 * IStream16_AddRef [STORAGE.519]
1084 ULONG CDECL
IStream16_fnAddRef(IStream16
*iface
)
1086 IStream16Impl
*This
= impl_from_IStream16(iface
);
1087 return InterlockedIncrement(&This
->ref
);
1091 _ilockbytes16_addref(SEGPTR lockbytes
) {
1095 args
[0] = (DWORD
)lockbytes
; /* iface */
1096 if (!WOWCallback16Ex(
1097 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
1098 (SEGPTR
)((LPLOCKBYTES16
)MapSL(lockbytes
))->lpVtbl
)
1105 ERR("CallTo16 ILockBytes16::AddRef() failed, hres %x\n",hres
);
1109 _ilockbytes16_release(SEGPTR lockbytes
) {
1113 args
[0] = (DWORD
)lockbytes
; /* iface */
1114 if (!WOWCallback16Ex(
1115 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
1116 (SEGPTR
)((LPLOCKBYTES16
)MapSL(lockbytes
))->lpVtbl
)
1123 ERR("CallTo16 ILockBytes16::Release() failed, hres %x\n",hres
);
1127 _ilockbytes16_flush(SEGPTR lockbytes
) {
1131 args
[0] = (DWORD
)lockbytes
; /* iface */
1132 if (!WOWCallback16Ex(
1133 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
1134 (SEGPTR
)((LPLOCKBYTES16
)MapSL(lockbytes
))->lpVtbl
)
1141 ERR("CallTo16 ILockBytes16::Flush() failed, hres %x\n",hres
);
1144 /******************************************************************************
1145 * IStream16_Release [STORAGE.520]
1147 ULONG CDECL
IStream16_fnRelease(IStream16
*iface
)
1149 IStream16Impl
*This
= impl_from_IStream16(iface
);
1153 FlushFileBuffers(This
->str
.hf
);
1155 _ilockbytes16_flush(This
->str
.lockbytes
);
1156 ref
= InterlockedDecrement(&This
->ref
);
1161 CloseHandle(This
->str
.hf
);
1163 _ilockbytes16_release(This
->str
.lockbytes
);
1164 UnMapLS( This
->thisptr
);
1165 HeapFree( GetProcessHeap(), 0, This
);
1169 /******************************************************************************
1170 * IStream16_Seek [STORAGE.523]
1173 * Does not handle 64 bits
1175 HRESULT CDECL
IStream16_fnSeek(IStream16
*iface
, LARGE_INTEGER offset
, DWORD whence
,
1176 ULARGE_INTEGER
*newpos
)
1178 IStream16Impl
*This
= impl_from_IStream16(iface
);
1179 TRACE_(relay
)("(%p)->([%d.%d],%d,%p)\n",This
,offset
.u
.HighPart
,offset
.u
.LowPart
,whence
,newpos
);
1182 case STREAM_SEEK_SET
:
1183 This
->offset
.QuadPart
= offset
.QuadPart
;
1185 case STREAM_SEEK_CUR
:
1186 if ((offset
.QuadPart
< 0 && -offset
.QuadPart
> This
->offset
.QuadPart
) ||
1187 (offset
.QuadPart
> 0 && -offset
.QuadPart
<= This
->offset
.QuadPart
))
1188 return STG_E_INVALIDFUNCTION
;
1189 This
->offset
.QuadPart
+= offset
.QuadPart
;
1191 case STREAM_SEEK_END
:
1192 if (-offset
.QuadPart
> This
->stde
.pps_size
)
1193 return STG_E_INVALIDFUNCTION
;
1195 This
->offset
.QuadPart
= This
->stde
.pps_size
+ offset
.QuadPart
;
1199 if (This
->offset
.QuadPart
>This
->stde
.pps_size
)
1200 This
->offset
.QuadPart
=This
->stde
.pps_size
;
1201 if (newpos
) *newpos
= This
->offset
;
1205 /******************************************************************************
1206 * IStream16_Read [STORAGE.521]
1208 HRESULT CDECL
IStream16_fnRead(IStream16
*iface
, void *pv
, ULONG cb
, ULONG
*pcbRead
)
1210 IStream16Impl
*This
= impl_from_IStream16(iface
);
1211 BYTE block
[BIGSIZE
];
1212 ULONG
*bytesread
=pcbRead
,xxread
;
1216 TRACE_(relay
)("(%p)->(%p,%d,%p)\n",This
,pv
,cb
,pcbRead
);
1217 if (!pcbRead
) bytesread
=&xxread
;
1220 if (cb
>This
->stde
.pps_size
-This
->offset
.u
.LowPart
)
1221 cb
=This
->stde
.pps_size
-This
->offset
.u
.LowPart
;
1222 if (This
->stde
.pps_size
< 0x1000) {
1223 /* use small block reader */
1224 blocknr
= STORAGE_get_nth_next_small_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->offset
.u
.LowPart
/SMALLSIZE
);
1228 if (!STORAGE_get_small_block(&This
->str
,blocknr
,block
)) {
1229 WARN("small block read failed!!!\n");
1233 if (cc
>SMALLSIZE
-(This
->offset
.u
.LowPart
&(SMALLSIZE
-1)))
1234 cc
=SMALLSIZE
-(This
->offset
.u
.LowPart
&(SMALLSIZE
-1));
1235 memcpy(pbv
,block
+(This
->offset
.u
.LowPart
&(SMALLSIZE
-1)),cc
);
1236 This
->offset
.u
.LowPart
+=cc
;
1240 blocknr
= STORAGE_get_next_small_blocknr(&This
->str
,blocknr
);
1243 /* use big block reader */
1244 blocknr
= STORAGE_get_nth_next_big_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->offset
.u
.LowPart
/BIGSIZE
);
1248 if (!STORAGE_get_big_block(&This
->str
,blocknr
,block
)) {
1249 WARN("big block read failed!!!\n");
1253 if (cc
>BIGSIZE
-(This
->offset
.u
.LowPart
&(BIGSIZE
-1)))
1254 cc
=BIGSIZE
-(This
->offset
.u
.LowPart
&(BIGSIZE
-1));
1255 memcpy(pbv
,block
+(This
->offset
.u
.LowPart
&(BIGSIZE
-1)),cc
);
1256 This
->offset
.u
.LowPart
+=cc
;
1260 blocknr
=STORAGE_get_next_big_blocknr(&This
->str
,blocknr
);
1266 /******************************************************************************
1267 * IStream16_Write [STORAGE.522]
1269 HRESULT CDECL
IStream16_fnWrite(IStream16
*iface
, const void *pv
, ULONG cb
, ULONG
*pcbWrite
)
1271 IStream16Impl
*This
= impl_from_IStream16(iface
);
1272 BYTE block
[BIGSIZE
];
1273 ULONG
*byteswritten
=pcbWrite
,xxwritten
;
1274 int oldsize
,newsize
,i
,curoffset
=0,lastblocknr
,blocknr
,cc
;
1275 const BYTE
* pbv
= pv
;
1277 if (!pcbWrite
) byteswritten
=&xxwritten
;
1280 TRACE_(relay
)("(%p)->(%p,%d,%p)\n",This
,pv
,cb
,pcbWrite
);
1281 /* do we need to junk some blocks? */
1282 newsize
= This
->offset
.u
.LowPart
+cb
;
1283 oldsize
= This
->stde
.pps_size
;
1284 if (newsize
< oldsize
) {
1285 if (oldsize
< 0x1000) {
1286 /* only small blocks */
1287 blocknr
=STORAGE_get_nth_next_small_blocknr(&This
->str
,This
->stde
.pps_sb
,newsize
/SMALLSIZE
);
1291 /* will set the rest of the chain to 'free' */
1292 if (!STORAGE_set_small_chain(&This
->str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1295 if (newsize
>= 0x1000) {
1296 blocknr
=STORAGE_get_nth_next_big_blocknr(&This
->str
,This
->stde
.pps_sb
,newsize
/BIGSIZE
);
1299 /* will set the rest of the chain to 'free' */
1300 if (!STORAGE_set_big_chain(&This
->str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1303 /* Migrate large blocks to small blocks
1304 * (we just migrate newsize bytes)
1306 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,newsize
+BIGSIZE
);
1310 blocknr
= This
->stde
.pps_sb
;
1313 if (!STORAGE_get_big_block(&This
->str
,blocknr
,curdata
)) {
1314 HeapFree(GetProcessHeap(),0,data
);
1319 blocknr
= STORAGE_get_next_big_blocknr(&This
->str
,blocknr
);
1321 /* frees complete chain for this stream */
1322 if (!STORAGE_set_big_chain(&This
->str
,This
->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
1325 blocknr
= This
->stde
.pps_sb
= STORAGE_get_free_small_blocknr(&This
->str
);
1330 if (!STORAGE_put_small_block(&This
->str
,blocknr
,curdata
))
1334 if (!STORAGE_set_small_chain(&This
->str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1338 int newblocknr
= STORAGE_get_free_small_blocknr(&This
->str
);
1341 if (!STORAGE_set_small_chain(&This
->str
,blocknr
,newblocknr
))
1343 blocknr
= newblocknr
;
1345 curdata
+= SMALLSIZE
;
1349 HeapFree(GetProcessHeap(),0,data
);
1354 This
->stde
.pps_size
= newsize
;
1357 if (newsize
> oldsize
) {
1358 if (oldsize
>= 0x1000) {
1359 /* should return the block right before the 'endofchain' */
1360 blocknr
= STORAGE_get_nth_next_big_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->stde
.pps_size
/BIGSIZE
);
1362 lastblocknr
= blocknr
;
1363 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
1364 blocknr
= STORAGE_get_free_big_blocknr(&This
->str
);
1367 if (!STORAGE_set_big_chain(&This
->str
,lastblocknr
,blocknr
))
1369 lastblocknr
= blocknr
;
1371 if (!STORAGE_set_big_chain(&This
->str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1374 if (newsize
< 0x1000) {
1375 /* find startblock */
1377 This
->stde
.pps_sb
= blocknr
= STORAGE_get_free_small_blocknr(&This
->str
);
1379 blocknr
= STORAGE_get_nth_next_small_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->stde
.pps_size
/SMALLSIZE
);
1383 /* allocate required new small blocks */
1384 lastblocknr
= blocknr
;
1385 for (i
=oldsize
/SMALLSIZE
;i
<newsize
/SMALLSIZE
;i
++) {
1386 blocknr
= STORAGE_get_free_small_blocknr(&This
->str
);
1389 if (!STORAGE_set_small_chain(&This
->str
,lastblocknr
,blocknr
))
1391 lastblocknr
= blocknr
;
1393 /* and terminate the chain */
1394 if (!STORAGE_set_small_chain(&This
->str
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1398 /* no single block allocated yet */
1399 blocknr
=STORAGE_get_free_big_blocknr(&This
->str
);
1402 This
->stde
.pps_sb
= blocknr
;
1404 /* Migrate small blocks to big blocks */
1405 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,oldsize
+BIGSIZE
);
1409 blocknr
= This
->stde
.pps_sb
;
1413 if (!STORAGE_get_small_block(&This
->str
,blocknr
,curdata
))
1415 curdata
+= SMALLSIZE
;
1417 blocknr
= STORAGE_get_next_small_blocknr(&This
->str
,blocknr
);
1419 /* free small block chain */
1420 if (!STORAGE_set_small_chain(&This
->str
,This
->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
1423 blocknr
= This
->stde
.pps_sb
= STORAGE_get_free_big_blocknr(&This
->str
);
1426 /* put the data into the big blocks */
1427 cc
= This
->stde
.pps_size
;
1429 if (!STORAGE_put_big_block(&This
->str
,blocknr
,curdata
))
1433 if (!STORAGE_set_big_chain(&This
->str
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1437 int newblocknr
= STORAGE_get_free_big_blocknr(&This
->str
);
1440 if (!STORAGE_set_big_chain(&This
->str
,blocknr
,newblocknr
))
1442 blocknr
= newblocknr
;
1448 HeapFree(GetProcessHeap(),0,data
);
1452 /* generate big blocks to fit the new data */
1453 lastblocknr
= blocknr
;
1454 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
1455 blocknr
= STORAGE_get_free_big_blocknr(&This
->str
);
1458 if (!STORAGE_set_big_chain(&This
->str
,lastblocknr
,blocknr
))
1460 lastblocknr
= blocknr
;
1462 /* terminate chain */
1463 if (!STORAGE_set_big_chain(&This
->str
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
1467 This
->stde
.pps_size
= newsize
;
1470 /* There are just some cases where we didn't modify it, we write it out
1473 if (!STORAGE_put_pps_entry(&This
->str
,This
->ppsent
,&(This
->stde
)))
1476 /* finally the write pass */
1477 if (This
->stde
.pps_size
< 0x1000) {
1478 blocknr
= STORAGE_get_nth_next_small_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->offset
.u
.LowPart
/SMALLSIZE
);
1481 /* we ensured that it is allocated above */
1483 /* Read old block every time, since we can have
1484 * overlapping data at START and END of the write
1486 if (!STORAGE_get_small_block(&This
->str
,blocknr
,block
))
1489 cc
= SMALLSIZE
-(This
->offset
.u
.LowPart
&(SMALLSIZE
-1));
1492 memcpy( ((LPBYTE
)block
)+(This
->offset
.u
.LowPart
&(SMALLSIZE
-1)),
1496 if (!STORAGE_put_small_block(&This
->str
,blocknr
,block
))
1501 This
->offset
.u
.LowPart
+= cc
;
1502 *byteswritten
+= cc
;
1503 blocknr
= STORAGE_get_next_small_blocknr(&This
->str
,blocknr
);
1506 blocknr
= STORAGE_get_nth_next_big_blocknr(&This
->str
,This
->stde
.pps_sb
,This
->offset
.u
.LowPart
/BIGSIZE
);
1509 /* we ensured that it is allocated above, so it better is */
1511 /* read old block every time, since we can have
1512 * overlapping data at START and END of the write
1514 if (!STORAGE_get_big_block(&This
->str
,blocknr
,block
))
1517 cc
= BIGSIZE
-(This
->offset
.u
.LowPart
&(BIGSIZE
-1));
1520 memcpy( ((LPBYTE
)block
)+(This
->offset
.u
.LowPart
&(BIGSIZE
-1)),
1524 if (!STORAGE_put_big_block(&This
->str
,blocknr
,block
))
1529 This
->offset
.u
.LowPart
+= cc
;
1530 *byteswritten
+= cc
;
1531 blocknr
= STORAGE_get_next_big_blocknr(&This
->str
,blocknr
);
1537 /******************************************************************************
1538 * _create_istream16 [Internal]
1540 static void _create_istream16(LPSTREAM16
*str
) {
1541 IStream16Impl
* lpst
;
1543 if (!strvt16
.QueryInterface
) {
1544 HMODULE16 wp
= GetModuleHandle16("STORAGE");
1546 /* FIXME: what is This GetProcAddress16. Should the name be IStream16_QueryInterface of IStream16_fnQueryInterface */
1547 #define VTENT(xfn) strvt16.xfn = (void*)GetProcAddress16(wp,"IStream16_"#xfn);assert(strvt16.xfn)
1548 VTENT(QueryInterface
);
1559 VTENT(UnlockRegion
);
1563 segstrvt16
= (const IStream16Vtbl
*)MapLS( &strvt16
);
1565 #define VTENT(xfn) strvt16.xfn = IStream16_fn##xfn;
1566 VTENT(QueryInterface
);
1578 VTENT(UnlockRegion);
1583 segstrvt16
= &strvt16
;
1586 lpst
= HeapAlloc( GetProcessHeap(), 0, sizeof(*lpst
) );
1587 lpst
->IStream16_iface
.lpVtbl
= segstrvt16
;
1589 lpst
->thisptr
= MapLS( lpst
);
1590 lpst
->str
.hf
= NULL
;
1591 lpst
->str
.lockbytes
= 0;
1592 *str
= (void*)lpst
->thisptr
;
1595 static inline IStorage16Impl
*impl_from_IStorage16(IStorage16
*iface
)
1597 return CONTAINING_RECORD(iface
, IStorage16Impl
, IStorage16_iface
);
1600 /******************************************************************************
1601 * IStorage16_QueryInterface [STORAGE.500]
1603 HRESULT CDECL
IStorage16_fnQueryInterface(IStorage16
*iface
, REFIID refiid
, void **obj
)
1605 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1607 TRACE_(relay
)("(%p)->(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
1609 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1613 return OLE_E_ENUM_NOMORE
;
1616 /******************************************************************************
1617 * IStorage16_AddRef [STORAGE.501]
1619 ULONG CDECL
IStorage16_fnAddRef(IStorage16
*iface
)
1621 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1622 return InterlockedIncrement(&This
->ref
);
1625 /******************************************************************************
1626 * IStorage16_Release [STORAGE.502]
1628 ULONG CDECL
IStorage16_fnRelease(IStorage16
*iface
)
1630 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1632 ref
= InterlockedDecrement(&This
->ref
);
1635 UnMapLS( This
->thisptr
);
1636 HeapFree( GetProcessHeap(), 0, This
);
1641 /******************************************************************************
1642 * IStorage16_Stat [STORAGE.517]
1644 HRESULT CDECL
IStorage16_fnStat(IStorage16
*iface
, STATSTG16
*pstatstg
, DWORD grfStatFlag
)
1646 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1647 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, This
->stde
.pps_rawname
, -1, NULL
, 0, NULL
, NULL
);
1648 LPSTR nameA
= HeapAlloc( GetProcessHeap(), 0, len
);
1650 TRACE("(%p)->(%p,0x%08x)\n",
1651 This
,pstatstg
,grfStatFlag
1653 WideCharToMultiByte( CP_ACP
, 0, This
->stde
.pps_rawname
, -1, nameA
, len
, NULL
, NULL
);
1654 pstatstg
->pwcsName
=(LPOLESTR16
)MapLS( nameA
);
1655 pstatstg
->type
= This
->stde
.pps_type
;
1656 pstatstg
->cbSize
.u
.LowPart
= This
->stde
.pps_size
;
1657 pstatstg
->mtime
= This
->stde
.pps_ft1
; /* FIXME */ /* why? */
1658 pstatstg
->atime
= This
->stde
.pps_ft2
; /* FIXME */
1659 pstatstg
->ctime
= This
->stde
.pps_ft2
; /* FIXME */
1660 pstatstg
->grfMode
= 0; /* FIXME */
1661 pstatstg
->grfLocksSupported
= 0; /* FIXME */
1662 pstatstg
->clsid
= This
->stde
.pps_guid
;
1663 pstatstg
->grfStateBits
= 0; /* FIXME */
1664 pstatstg
->reserved
= 0;
1668 /******************************************************************************
1669 * IStorage16_Commit [STORAGE.509]
1671 HRESULT CDECL
IStorage16_fnCommit(IStorage16
*iface
, DWORD commitflags
)
1673 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1674 FIXME("(%p)->(0x%08x),STUB!\n",
1680 /******************************************************************************
1681 * IStorage16_CopyTo [STORAGE.507]
1683 HRESULT CDECL
IStorage16_fnCopyTo(IStorage16
*iface
, DWORD ciidExclude
, const IID
*rgiidExclude
,
1684 SNB16 SNB16Exclude
, IStorage16
*pstgDest
)
1686 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1687 FIXME("IStorage16(%p)->(0x%08x,%s,%p,%p),stub!\n",
1688 This
,ciidExclude
,debugstr_guid(rgiidExclude
),SNB16Exclude
,pstgDest
1694 /******************************************************************************
1695 * IStorage16_CreateStorage [STORAGE.505]
1697 HRESULT CDECL
IStorage16_fnCreateStorage(IStorage16
*iface
, LPCOLESTR16 pwcsName
, DWORD grfMode
,
1698 DWORD dwStgFormat
, DWORD reserved2
, IStorage16
**ppstg
)
1700 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1701 IStorage16Impl
* lpstg
;
1703 struct storage_pps_entry stde
;
1704 struct storage_header sth
;
1708 READ_HEADER(&This
->str
);
1709 TRACE("(%p)->(%s,0x%08x,0x%08x,0x%08x,%p)\n",
1710 This
,pwcsName
,grfMode
,dwStgFormat
,reserved2
,ppstg
1712 if (grfMode
& STGM_TRANSACTED
)
1713 FIXME("We do not support transacted Compound Storage. Using direct mode.\n");
1714 _create_istorage16(ppstg
);
1715 lpstg
= MapSL((SEGPTR
)*ppstg
);
1717 DuplicateHandle( GetCurrentProcess(), This
->str
.hf
, GetCurrentProcess(),
1718 &lpstg
->str
.hf
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
1720 lpstg
->str
.lockbytes
= This
->str
.lockbytes
;
1721 _ilockbytes16_addref(This
->str
.lockbytes
);
1724 ppsent
=STORAGE_get_free_pps_entry(&lpstg
->str
);
1728 if (stde
.pps_dir
==-1) {
1729 stde
.pps_dir
= ppsent
;
1732 FIXME(" use prev chain too ?\n");
1734 if (1!=STORAGE_get_pps_entry(&lpstg
->str
,x
,&stde
))
1736 while (stde
.pps_next
!=-1) {
1738 if (1!=STORAGE_get_pps_entry(&lpstg
->str
,x
,&stde
))
1741 stde
.pps_next
= ppsent
;
1743 ret
= STORAGE_put_pps_entry(&lpstg
->str
,x
,&stde
);
1745 nPPSEntries
= STORAGE_get_pps_entry(&lpstg
->str
,ppsent
,&(lpstg
->stde
));
1746 assert(nPPSEntries
== 1);
1747 MultiByteToWideChar(CP_ACP
, 0, pwcsName
, -1, lpstg
->stde
.pps_rawname
,
1748 ARRAY_SIZE(lpstg
->stde
.pps_rawname
));
1749 lpstg
->stde
.pps_sizeofname
= (lstrlenW(lpstg
->stde
.pps_rawname
)+1)*sizeof(WCHAR
);
1750 lpstg
->stde
.pps_next
= -1;
1751 lpstg
->stde
.pps_prev
= -1;
1752 lpstg
->stde
.pps_dir
= -1;
1753 lpstg
->stde
.pps_sb
= -1;
1754 lpstg
->stde
.pps_size
= 0;
1755 lpstg
->stde
.pps_type
= 1;
1756 lpstg
->ppsent
= ppsent
;
1757 /* FIXME: timestamps? */
1758 if (!STORAGE_put_pps_entry(&lpstg
->str
,ppsent
,&(lpstg
->stde
)))
1763 /******************************************************************************
1764 * IStorage16_CreateStream [STORAGE.503]
1766 HRESULT CDECL
IStorage16_fnCreateStream(IStorage16
*iface
, LPCOLESTR16 pwcsName
, DWORD grfMode
,
1767 DWORD reserved1
, DWORD reserved2
, IStream16
**ppstm
)
1769 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1770 IStream16Impl
* lpstr
;
1772 struct storage_pps_entry stde
;
1776 TRACE("(%p)->(%s,0x%08x,0x%08x,0x%08x,%p)\n",
1777 This
,pwcsName
,grfMode
,reserved1
,reserved2
,ppstm
1779 if (grfMode
& STGM_TRANSACTED
)
1780 FIXME("We do not support transacted Compound Storage. Using direct mode.\n");
1781 _create_istream16(ppstm
);
1782 lpstr
= MapSL((SEGPTR
)*ppstm
);
1784 DuplicateHandle( GetCurrentProcess(), This
->str
.hf
, GetCurrentProcess(),
1785 &lpstr
->str
.hf
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
1787 lpstr
->str
.lockbytes
= This
->str
.lockbytes
;
1788 _ilockbytes16_addref(This
->str
.lockbytes
);
1790 lpstr
->offset
.u
.LowPart
= 0;
1791 lpstr
->offset
.u
.HighPart
= 0;
1793 ppsent
=STORAGE_get_free_pps_entry(&lpstr
->str
);
1797 if (stde
.pps_next
==-1)
1800 while (stde
.pps_next
!=-1) {
1802 if (1!=STORAGE_get_pps_entry(&lpstr
->str
,x
,&stde
))
1805 stde
.pps_next
= ppsent
;
1806 ret
= STORAGE_put_pps_entry(&lpstr
->str
,x
,&stde
);
1808 nPPSEntries
= STORAGE_get_pps_entry(&lpstr
->str
,ppsent
,&(lpstr
->stde
));
1809 assert(nPPSEntries
== 1);
1810 MultiByteToWideChar(CP_ACP
, 0, pwcsName
, -1, lpstr
->stde
.pps_rawname
,
1811 ARRAY_SIZE(lpstr
->stde
.pps_rawname
));
1812 lpstr
->stde
.pps_sizeofname
= (lstrlenW(lpstr
->stde
.pps_rawname
)+1) * sizeof(WCHAR
);
1813 lpstr
->stde
.pps_next
= -1;
1814 lpstr
->stde
.pps_prev
= -1;
1815 lpstr
->stde
.pps_dir
= -1;
1816 lpstr
->stde
.pps_sb
= -1;
1817 lpstr
->stde
.pps_size
= 0;
1818 lpstr
->stde
.pps_type
= 2;
1819 lpstr
->ppsent
= ppsent
;
1821 /* FIXME: timestamps? */
1822 if (!STORAGE_put_pps_entry(&lpstr
->str
,ppsent
,&(lpstr
->stde
)))
1827 /******************************************************************************
1828 * IStorage16_OpenStorage [STORAGE.506]
1830 HRESULT CDECL
IStorage16_fnOpenStorage(IStorage16
*iface
, LPCOLESTR16 pwcsName
,
1831 IStorage16
*pstgPrio
, DWORD grfMode
, SNB16 snbExclude
, DWORD reserved
, IStorage16
**ppstg
)
1833 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1834 IStorage16Impl
*lpstg
;
1838 TRACE("(%p)->(%s,%p,0x%08x,%p,0x%08x,%p)\n",
1839 This
,pwcsName
,pstgPrio
,grfMode
,snbExclude
,reserved
,ppstg
1841 if (grfMode
& STGM_TRANSACTED
)
1842 FIXME("We do not support transacted Compound Storage. Using direct mode.\n");
1843 _create_istorage16(ppstg
);
1844 lpstg
= MapSL((SEGPTR
)*ppstg
);
1846 DuplicateHandle( GetCurrentProcess(), This
->str
.hf
, GetCurrentProcess(),
1847 &lpstg
->str
.hf
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
1849 lpstg
->str
.lockbytes
= This
->str
.lockbytes
;
1850 _ilockbytes16_addref(This
->str
.lockbytes
);
1852 MultiByteToWideChar(CP_ACP
, 0, pwcsName
, -1, name
, ARRAY_SIZE(name
));
1853 newpps
= STORAGE_look_for_named_pps(&lpstg
->str
,This
->stde
.pps_dir
,name
);
1855 IStorage16_fnRelease(&lpstg
->IStorage16_iface
);
1860 if (1!=STORAGE_get_pps_entry(&lpstg
->str
,newpps
,&(lpstg
->stde
))) {
1861 IStorage16_fnRelease(&lpstg
->IStorage16_iface
);
1865 lpstg
->ppsent
= newpps
;
1869 /******************************************************************************
1870 * IStorage16_OpenStream [STORAGE.504]
1872 HRESULT CDECL
IStorage16_fnOpenStream(IStorage16
*iface
, LPCOLESTR16 pwcsName
, void *reserved1
,
1873 DWORD grfMode
, DWORD reserved2
, IStream16
**ppstm
)
1875 IStorage16Impl
*This
= impl_from_IStorage16(iface
);
1876 IStream16Impl
* lpstr
;
1880 TRACE("(%p)->(%s,%p,0x%08x,0x%08x,%p)\n",
1881 This
,pwcsName
,reserved1
,grfMode
,reserved2
,ppstm
1883 if (grfMode
& STGM_TRANSACTED
)
1884 FIXME("We do not support transacted Compound Storage. Using direct mode.\n");
1885 _create_istream16(ppstm
);
1886 lpstr
= MapSL((SEGPTR
)*ppstm
);
1888 DuplicateHandle( GetCurrentProcess(), This
->str
.hf
, GetCurrentProcess(),
1889 &lpstr
->str
.hf
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
1891 lpstr
->str
.lockbytes
= This
->str
.lockbytes
;
1892 _ilockbytes16_addref(This
->str
.lockbytes
);
1894 MultiByteToWideChar(CP_ACP
, 0, pwcsName
, -1, name
, ARRAY_SIZE(name
));
1895 newpps
= STORAGE_look_for_named_pps(&lpstr
->str
,This
->stde
.pps_dir
,name
);
1897 IStream16_fnRelease(&lpstr
->IStream16_iface
);
1902 if (1!=STORAGE_get_pps_entry(&lpstr
->str
,newpps
,&(lpstr
->stde
))) {
1903 IStream16_fnRelease(&lpstr
->IStream16_iface
);
1907 lpstr
->offset
.u
.LowPart
= 0;
1908 lpstr
->offset
.u
.HighPart
= 0;
1909 lpstr
->ppsent
= newpps
;
1913 /******************************************************************************
1914 * _create_istorage16 [INTERNAL]
1916 static void _create_istorage16(LPSTORAGE16
*stg
) {
1917 IStorage16Impl
* lpst
;
1919 if (!stvt16
.QueryInterface
) {
1920 HMODULE16 wp
= GetModuleHandle16("STORAGE");
1922 #define VTENT(xfn) stvt16.xfn = (void*)GetProcAddress16(wp,"IStorage16_"#xfn);
1923 VTENT(QueryInterface
)
1928 VTENT(CreateStorage
)
1931 VTENT(MoveElementTo
)
1935 VTENT(DestroyElement
)
1936 VTENT(RenameElement
)
1937 VTENT(SetElementTimes
)
1942 segstvt16
= (const IStorage16Vtbl
*)MapLS( &stvt16
);
1944 #define VTENT(xfn) stvt16.xfn = IStorage16_fn##xfn;
1945 VTENT(QueryInterface
)
1950 VTENT(CreateStorage
)
1954 /* not (yet) implemented ...
1955 VTENT(MoveElementTo)
1958 VTENT(DestroyElement)
1959 VTENT(RenameElement)
1960 VTENT(SetElementTimes)
1966 segstvt16
= &stvt16
;
1969 lpst
= HeapAlloc( GetProcessHeap(), 0, sizeof(*lpst
) );
1970 lpst
->IStorage16_iface
.lpVtbl
= segstvt16
;
1971 lpst
->str
.hf
= NULL
;
1972 lpst
->str
.lockbytes
= 0;
1974 lpst
->thisptr
= MapLS(lpst
);
1975 *stg
= (void*)lpst
->thisptr
;
1978 /******************************************************************************
1979 * Storage API functions
1982 /******************************************************************************
1983 * StgCreateDocFileA [STORAGE.1]
1985 HRESULT WINAPI
StgCreateDocFile16(
1986 LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD reserved
,IStorage16
**ppstgOpen
1990 IStorage16Impl
* lpstg
;
1991 struct storage_pps_entry stde
;
1993 TRACE("(%s,0x%08x,0x%08x,%p)\n",
1994 pwcsName
,grfMode
,reserved
,ppstgOpen
1996 _create_istorage16(ppstgOpen
);
1997 hf
= CreateFileA(pwcsName
,GENERIC_READ
|GENERIC_WRITE
,0,NULL
,CREATE_NEW
,0,0);
1998 if (hf
==INVALID_HANDLE_VALUE
) {
1999 WARN("couldn't open file for storage:%d\n",GetLastError());
2002 lpstg
= MapSL((SEGPTR
)*ppstgOpen
);
2004 lpstg
->str
.lockbytes
= 0;
2005 /* FIXME: check for existence before overwriting? */
2006 if (!STORAGE_init_storage(&lpstg
->str
)) {
2011 while (!ret
) { /* neither 1 nor <0 */
2012 ret
=STORAGE_get_pps_entry(&lpstg
->str
,i
,&stde
);
2013 if ((ret
==1) && (stde
.pps_type
==5)) {
2021 IStorage16_fnRelease(&lpstg
->IStorage16_iface
);
2028 /******************************************************************************
2029 * StgIsStorageFile [STORAGE.5]
2031 HRESULT WINAPI
StgIsStorageFile16(LPCOLESTR16 fn
) {
2032 UNICODE_STRING strW
;
2035 RtlCreateUnicodeStringFromAsciiz(&strW
, fn
);
2036 ret
= StgIsStorageFile( strW
.Buffer
);
2037 RtlFreeUnicodeString( &strW
);
2042 /******************************************************************************
2043 * StgOpenStorage [STORAGE.3]
2045 HRESULT WINAPI
StgOpenStorage16(
2046 LPCOLESTR16 pwcsName
,IStorage16
*pstgPriority
,DWORD grfMode
,
2047 SNB16 snbExclude
,DWORD reserved
, IStorage16
**ppstgOpen
2051 IStorage16Impl
* lpstg
;
2052 struct storage_pps_entry stde
;
2054 TRACE("(%s,%p,0x%08x,%p,%d,%p)\n",
2055 pwcsName
,pstgPriority
,grfMode
,snbExclude
,reserved
,ppstgOpen
2057 _create_istorage16(ppstgOpen
);
2058 hf
= CreateFileA(pwcsName
,GENERIC_READ
,FILE_SHARE_READ
,NULL
,OPEN_EXISTING
,FILE_ATTRIBUTE_NORMAL
,0);
2059 if (hf
==INVALID_HANDLE_VALUE
) {
2060 WARN("Couldn't open file for storage\n");
2063 lpstg
= MapSL((SEGPTR
)*ppstgOpen
);
2067 while (!ret
) { /* neither 1 nor <0 */
2068 ret
=STORAGE_get_pps_entry(&lpstg
->str
,i
,&stde
);
2069 if ((ret
==1) && (stde
.pps_type
==5)) {
2076 IStorage16_fnRelease(&lpstg
->IStorage16_iface
);
2083 /******************************************************************************
2084 * StgIsStorageILockBytes [STORAGE.6]
2086 * Determines if the ILockBytes contains a storage object.
2088 HRESULT WINAPI
StgIsStorageILockBytes16(SEGPTR plkbyt
)
2094 args
[0] = (DWORD
)plkbyt
; /* iface */
2095 args
[1] = args
[2] = 0; /* ULARGE_INTEGER offset */
2096 args
[3] = WOWGlobalAllocLock16( 0, 8, &hsig
); /* sig */
2100 if (!WOWCallback16Ex(
2101 (DWORD
)((const ILockBytes16Vtbl
*)MapSL(
2102 (SEGPTR
)((LPLOCKBYTES16
)MapSL(plkbyt
))->lpVtbl
)
2109 ERR("CallTo16 ILockBytes16::ReadAt() failed, hres %x\n",hres
);
2112 if (memcmp(MapSL(args
[3]), STORAGE_magic
, sizeof(STORAGE_magic
)) == 0) {
2113 WOWGlobalUnlockFree16(args
[3]);
2116 WOWGlobalUnlockFree16(args
[3]);
2120 /******************************************************************************
2121 * StgOpenStorageOnILockBytes [STORAGE.4]
2124 * plkbyt FIXME: Should probably be an ILockBytes16 *.
2126 HRESULT WINAPI
StgOpenStorageOnILockBytes16(
2128 IStorage16
*pstgPriority
,
2132 IStorage16
**ppstgOpen
)
2134 IStorage16Impl
* lpstg
;
2136 struct storage_pps_entry stde
;
2138 FIXME("(%x, %p, 0x%08x, %d, %x, %p)\n", plkbyt
, pstgPriority
, grfMode
, (int)snbExclude
, reserved
, ppstgOpen
);
2139 if ((plkbyt
== 0) || (ppstgOpen
== 0))
2140 return STG_E_INVALIDPOINTER
;
2144 _create_istorage16(ppstgOpen
);
2145 lpstg
= MapSL((SEGPTR
)*ppstgOpen
);
2146 lpstg
->str
.hf
= NULL
;
2147 lpstg
->str
.lockbytes
= plkbyt
;
2149 while (!ret
) { /* neither 1 nor <0 */
2150 ret
=STORAGE_get_pps_entry(&lpstg
->str
,i
,&stde
);
2151 if ((ret
==1) && (stde
.pps_type
==5)) {
2158 IStorage16_fnRelease(&lpstg
->IStorage16_iface
);