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
19 #include "interfaces.h"
26 static const BYTE STORAGE_magic
[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
27 static const BYTE STORAGE_notmagic
[8]={0x0e,0x11,0xfc,0x0d,0xd0,0xcf,0x11,0xe0};
28 static const BYTE STORAGE_oldmagic
[8]={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
33 #define SMALLBLOCKS_PER_BIGBLOCK (BIGSIZE/SMALLSIZE)
35 #define READ_HEADER assert(STORAGE_get_big_block(hf,-1,(LPBYTE)&sth));assert(!memcmp(STORAGE_magic,sth.magic,sizeof(STORAGE_magic)));
36 static IStorage16_VTable stvt16
;
37 static IStorage16_VTable
*segstvt16
= NULL
;
38 static IStorage32_VTable stvt32
;
39 static IStream16_VTable strvt16
;
40 static IStream16_VTable
*segstrvt16
= NULL
;
41 static IStream32_VTable strvt32
;
43 /*ULONG WINAPI IStorage16_AddRef(LPSTORAGE16 this);*/
44 static void _create_istorage16(LPSTORAGE16
*stg
);
45 static void _create_istream16(LPSTREAM16
*str
);
49 /******************************************************************************
50 * STORAGE_get_big_block [Internal]
52 * Reading OLE compound storage
55 STORAGE_get_big_block(HFILE32 hf
,int n
,BYTE
*block
) {
57 if (-1==_llseek32(hf
,(n
+1)*BIGSIZE
,SEEK_SET
)) {
58 WARN(ole
," seek failed (%ld)\n",GetLastError());
61 assert((n
+1)*BIGSIZE
==_llseek32(hf
,0,SEEK_CUR
));
62 if (BIGSIZE
!=_lread32(hf
,block
,BIGSIZE
)) {
63 WARN(ole
,"(block size %d): read didn't read (%ld)\n",n
,GetLastError());
70 /******************************************************************************
71 * STORAGE_put_big_block [INTERNAL]
74 STORAGE_put_big_block(HFILE32 hf
,int n
,BYTE
*block
) {
76 if (-1==_llseek32(hf
,(n
+1)*BIGSIZE
,SEEK_SET
)) {
77 WARN(ole
," seek failed (%ld)\n",GetLastError());
80 assert((n
+1)*BIGSIZE
==_llseek32(hf
,0,SEEK_CUR
));
81 if (BIGSIZE
!=_lwrite32(hf
,block
,BIGSIZE
)) {
82 WARN(ole
," write failed (%ld)\n",GetLastError());
88 /******************************************************************************
89 * STORAGE_get_next_big_blocknr [INTERNAL]
92 STORAGE_get_next_big_blocknr(HFILE32 hf
,int blocknr
) {
93 INT32 bbs
[BIGSIZE
/sizeof(INT32
)];
94 struct storage_header sth
;
98 assert(blocknr
>>7<sth
.num_of_bbd_blocks
);
99 if (sth
.bbd_list
[blocknr
>>7]==0xffffffff)
101 if (!STORAGE_get_big_block(hf
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
))
103 assert(bbs
[blocknr
&0x7f]!=STORAGE_CHAINENTRY_FREE
);
104 return bbs
[blocknr
&0x7f];
107 /******************************************************************************
108 * STORAGE_get_nth_next_big_blocknr [INTERNAL]
111 STORAGE_get_nth_next_big_blocknr(HFILE32 hf
,int blocknr
,int nr
) {
112 INT32 bbs
[BIGSIZE
/sizeof(INT32
)];
114 struct storage_header sth
;
120 assert((blocknr
>>7)<sth
.num_of_bbd_blocks
);
121 assert(sth
.bbd_list
[blocknr
>>7]!=0xffffffff);
123 /* simple caching... */
124 if (lastblock
!=sth
.bbd_list
[blocknr
>>7]) {
125 assert(STORAGE_get_big_block(hf
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
));
126 lastblock
= sth
.bbd_list
[blocknr
>>7];
128 blocknr
= bbs
[blocknr
&0x7f];
133 /******************************************************************************
134 * STORAGE_get_root_pps_entry [Internal]
137 STORAGE_get_root_pps_entry(HFILE32 hf
,struct storage_pps_entry
*pstde
) {
140 struct storage_pps_entry
*stde
=(struct storage_pps_entry
*)block
;
141 struct storage_header sth
;
144 blocknr
= sth
.root_startblock
;
146 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
148 if (!stde
[i
].pps_sizeofname
)
150 if (stde
[i
].pps_type
==5) {
155 blocknr
=STORAGE_get_next_big_blocknr(hf
,blocknr
);
160 /******************************************************************************
161 * STORAGE_get_small_block [INTERNAL]
164 STORAGE_get_small_block(HFILE32 hf
,int blocknr
,BYTE
*sblock
) {
167 struct storage_pps_entry root
;
170 assert(STORAGE_get_root_pps_entry(hf
,&root
));
171 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
172 assert(bigblocknr
>=0);
173 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
175 memcpy(sblock
,((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),SMALLSIZE
);
179 /******************************************************************************
180 * STORAGE_put_small_block [INTERNAL]
183 STORAGE_put_small_block(HFILE32 hf
,int blocknr
,BYTE
*sblock
) {
186 struct storage_pps_entry root
;
190 assert(STORAGE_get_root_pps_entry(hf
,&root
));
191 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
192 assert(bigblocknr
>=0);
193 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
195 memcpy(((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),sblock
,SMALLSIZE
);
196 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
200 /******************************************************************************
201 * STORAGE_get_next_small_blocknr [INTERNAL]
204 STORAGE_get_next_small_blocknr(HFILE32 hf
,int blocknr
) {
206 LPINT32 sbd
= (LPINT32
)block
;
208 struct storage_header sth
;
212 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
213 assert(bigblocknr
>=0);
214 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
215 assert(sbd
[blocknr
& 127]!=STORAGE_CHAINENTRY_FREE
);
216 return sbd
[blocknr
& (128-1)];
219 /******************************************************************************
220 * STORAGE_get_nth_next_small_blocknr [INTERNAL]
223 STORAGE_get_nth_next_small_blocknr(HFILE32 hf
,int blocknr
,int nr
) {
226 LPINT32 sbd
= (LPINT32
)block
;
227 struct storage_header sth
;
232 while ((nr
--) && (blocknr
>=0)) {
233 if (lastblocknr
/128!=blocknr
/128) {
235 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
236 assert(bigblocknr
>=0);
237 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
238 lastblocknr
= blocknr
;
240 assert(lastblocknr
>=0);
242 blocknr
=sbd
[blocknr
& (128-1)];
243 assert(blocknr
!=STORAGE_CHAINENTRY_FREE
);
248 /******************************************************************************
249 * STORAGE_get_pps_entry [INTERNAL]
252 STORAGE_get_pps_entry(HFILE32 hf
,int n
,struct storage_pps_entry
*pstde
) {
255 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
256 struct storage_header sth
;
259 /* we have 4 pps entries per big block */
260 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.root_startblock
,n
/4);
262 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
268 /******************************************************************************
269 * STORAGE_put_pps_entry [Internal]
272 STORAGE_put_pps_entry(HFILE32 hf
,int n
,struct storage_pps_entry
*pstde
) {
275 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
276 struct storage_header sth
;
280 /* we have 4 pps entries per big block */
281 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.root_startblock
,n
/4);
283 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
285 assert(STORAGE_put_big_block(hf
,blocknr
,block
));
289 /******************************************************************************
290 * STORAGE_look_for_named_pps [Internal]
293 STORAGE_look_for_named_pps(HFILE32 hf
,int n
,LPOLESTR32 name
) {
294 struct storage_pps_entry stde
;
299 if (1!=STORAGE_get_pps_entry(hf
,n
,&stde
))
302 if (!lstrcmp32W(name
,stde
.pps_rawname
))
304 if (stde
.pps_prev
!= -1) {
305 ret
=STORAGE_look_for_named_pps(hf
,stde
.pps_prev
,name
);
309 if (stde
.pps_next
!= -1) {
310 ret
=STORAGE_look_for_named_pps(hf
,stde
.pps_next
,name
);
317 /******************************************************************************
318 * STORAGE_dump_pps_entry [Internal]
324 STORAGE_dump_pps_entry(struct storage_pps_entry
*stde
) {
325 char name
[33],xguid
[50];
327 WINE_StringFromCLSID(&(stde
->pps_guid
),xguid
);
329 lstrcpyWtoA(name
,stde
->pps_rawname
);
330 if (!stde
->pps_sizeofname
)
332 DUMP("name: %s\n",name
);
333 DUMP("type: %d\n",stde
->pps_type
);
334 DUMP("prev pps: %ld\n",stde
->pps_prev
);
335 DUMP("next pps: %ld\n",stde
->pps_next
);
336 DUMP("dir pps: %ld\n",stde
->pps_dir
);
337 DUMP("guid: %s\n",xguid
);
338 if (stde
->pps_type
!=2) {
341 t
= DOSFS_FileTimeToUnixTime(&(stde
->pps_ft1
),NULL
);
342 DUMP("ts1: %s\n",ctime(&t
));
343 t
= DOSFS_FileTimeToUnixTime(&(stde
->pps_ft2
),NULL
);
344 DUMP("ts2: %s\n",ctime(&t
));
346 DUMP("startblock: %ld\n",stde
->pps_sb
);
347 DUMP("size: %ld\n",stde
->pps_size
);
350 /******************************************************************************
351 * STORAGE_init_storage [INTERNAL]
354 STORAGE_init_storage(HFILE32 hf
) {
357 struct storage_header
*sth
;
358 struct storage_pps_entry
*stde
;
360 assert(-1!=_llseek32(hf
,0,SEEK_SET
));
361 /* block -1 is the storage header */
362 sth
= (struct storage_header
*)block
;
363 memcpy(sth
->magic
,STORAGE_magic
,8);
364 memset(sth
->unknown1
,0,sizeof(sth
->unknown1
));
365 memset(sth
->unknown2
,0,sizeof(sth
->unknown2
));
366 memset(sth
->unknown3
,0,sizeof(sth
->unknown3
));
367 sth
->num_of_bbd_blocks
= 1;
368 sth
->root_startblock
= 1;
369 sth
->sbd_startblock
= 0xffffffff;
370 memset(sth
->bbd_list
,0xff,sizeof(sth
->bbd_list
));
371 sth
->bbd_list
[0] = 0;
372 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
373 /* block 0 is the big block directory */
375 memset(block
,0xff,sizeof(block
)); /* mark all blocks as free */
376 bbs
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for this block */
377 bbs
[1]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for directory entry */
378 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
379 /* block 1 is the root directory entry */
380 memset(block
,0x00,sizeof(block
));
381 stde
= (struct storage_pps_entry
*)block
;
382 lstrcpyAtoW(stde
->pps_rawname
,"RootEntry");
383 stde
->pps_sizeofname
= lstrlen32W(stde
->pps_rawname
)*2+2;
388 stde
->pps_sb
= 0xffffffff;
390 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
394 /******************************************************************************
395 * STORAGE_set_big_chain [Internal]
398 STORAGE_set_big_chain(HFILE32 hf
,int blocknr
,INT32 type
) {
400 LPINT32 bbd
= (LPINT32
)block
;
401 int nextblocknr
,bigblocknr
;
402 struct storage_header sth
;
405 assert(blocknr
!=type
);
407 bigblocknr
= sth
.bbd_list
[blocknr
/128];
408 assert(bigblocknr
>=0);
409 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
411 nextblocknr
= bbd
[blocknr
&(128-1)];
412 bbd
[blocknr
&(128-1)] = type
;
415 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
416 type
= STORAGE_CHAINENTRY_FREE
;
417 blocknr
= nextblocknr
;
422 /******************************************************************************
423 * STORAGE_set_small_chain [INTERNAL]
426 STORAGE_set_small_chain(HFILE32 hf
,int blocknr
,INT32 type
) {
428 LPINT32 sbd
= (LPINT32
)block
;
429 int lastblocknr
,nextsmallblocknr
,bigblocknr
;
430 struct storage_header sth
;
434 assert(blocknr
!=type
);
435 lastblocknr
=-129;bigblocknr
=-2;
437 /* cache block ... */
438 if (lastblocknr
/128!=blocknr
/128) {
439 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
440 assert(bigblocknr
>=0);
441 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
443 lastblocknr
= blocknr
;
444 nextsmallblocknr
= sbd
[blocknr
&(128-1)];
445 sbd
[blocknr
&(128-1)] = type
;
446 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
449 type
= STORAGE_CHAINENTRY_FREE
;
450 blocknr
= nextsmallblocknr
;
455 /******************************************************************************
456 * STORAGE_get_free_big_blocknr [Internal]
459 STORAGE_get_free_big_blocknr(HFILE32 hf
) {
461 LPINT32 sbd
= (LPINT32
)block
;
462 int lastbigblocknr
,i
,curblock
,bigblocknr
;
463 struct storage_header sth
;
468 bigblocknr
= sth
.bbd_list
[curblock
];
469 while (curblock
<sth
.num_of_bbd_blocks
) {
470 assert(bigblocknr
>=0);
471 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
473 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
474 sbd
[i
] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
475 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
476 memset(block
,0x42,sizeof(block
));
477 assert(STORAGE_put_big_block(hf
,i
+curblock
*128,block
));
478 return i
+curblock
*128;
480 lastbigblocknr
= bigblocknr
;
481 bigblocknr
= sth
.bbd_list
[++curblock
];
483 bigblocknr
= curblock
*128;
484 /* since we have marked all blocks from 0 up to curblock*128-1
485 * the next free one is curblock*128, where we happily put our
486 * next large block depot.
488 memset(block
,0xff,sizeof(block
));
489 /* mark the block allocated and returned by this function */
490 sbd
[1] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
491 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
493 /* if we had a bbd block already (mostlikely) we need
494 * to link the new one into the chain
496 if (lastbigblocknr
!=-1)
497 assert(STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
));
498 sth
.bbd_list
[curblock
]=bigblocknr
;
499 sth
.num_of_bbd_blocks
++;
500 assert(sth
.num_of_bbd_blocks
==curblock
+1);
501 assert(STORAGE_put_big_block(hf
,-1,(LPBYTE
)&sth
));
503 /* Set the end of the chain for the bigblockdepots */
504 assert(STORAGE_set_big_chain(hf
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
));
505 /* add 1, for the first entry is used for the additional big block
506 * depot. (means we already used bigblocknr) */
507 memset(block
,0x42,sizeof(block
));
508 /* allocate this block (filled with 0x42) */
509 assert(STORAGE_put_big_block(hf
,bigblocknr
+1,block
));
514 /******************************************************************************
515 * STORAGE_get_free_small_blocknr [Internal]
518 STORAGE_get_free_small_blocknr(HFILE32 hf
) {
520 LPINT32 sbd
= (LPINT32
)block
;
521 int lastbigblocknr
,newblocknr
,i
,curblock
,bigblocknr
;
522 struct storage_pps_entry root
;
523 struct storage_header sth
;
526 bigblocknr
= sth
.sbd_startblock
;
530 while (bigblocknr
>=0) {
531 if (!STORAGE_get_big_block(hf
,bigblocknr
,block
))
534 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
535 sbd
[i
]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
536 newblocknr
= i
+curblock
*128;
541 lastbigblocknr
= bigblocknr
;
542 bigblocknr
= STORAGE_get_next_big_blocknr(hf
,bigblocknr
);
545 if (newblocknr
==-1) {
546 bigblocknr
= STORAGE_get_free_big_blocknr(hf
);
550 memset(block
,0xff,sizeof(block
));
551 sbd
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
552 if (!STORAGE_put_big_block(hf
,bigblocknr
,block
))
554 if (lastbigblocknr
==-1) {
555 sth
.sbd_startblock
= bigblocknr
;
556 if (!STORAGE_put_big_block(hf
,-1,(LPBYTE
)&sth
)) /* need to write it */
559 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
))
562 if (!STORAGE_set_big_chain(hf
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
564 newblocknr
= curblock
*128;
566 /* allocate enough big blocks for storing the allocated small block */
567 if (!STORAGE_get_root_pps_entry(hf
,&root
))
572 lastbigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,(root
.pps_size
-1)/BIGSIZE
);
573 while (root
.pps_size
< (newblocknr
*SMALLSIZE
+SMALLSIZE
-1)) {
574 /* we need to allocate more stuff */
575 bigblocknr
= STORAGE_get_free_big_blocknr(hf
);
579 if (root
.pps_sb
==-1) {
580 root
.pps_sb
= bigblocknr
;
581 root
.pps_size
+= BIGSIZE
;
583 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
))
585 root
.pps_size
+= BIGSIZE
;
587 lastbigblocknr
= bigblocknr
;
589 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
591 if (!STORAGE_put_pps_entry(hf
,0,&root
))
596 /******************************************************************************
597 * STORAGE_get_free_pps_entry [Internal]
600 STORAGE_get_free_pps_entry(HFILE32 hf
) {
601 int blocknr
,i
,curblock
,lastblocknr
;
603 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)block
;
604 struct storage_header sth
;
607 blocknr
= sth
.root_startblock
;
611 if (!STORAGE_get_big_block(hf
,blocknr
,block
))
614 if (stde
[i
].pps_sizeofname
==0) /* free */
616 lastblocknr
= blocknr
;
617 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
620 assert(blocknr
==STORAGE_CHAINENTRY_ENDOFCHAIN
);
621 blocknr
= STORAGE_get_free_big_blocknr(hf
);
622 /* sth invalidated */
626 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
628 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
630 memset(block
,0,sizeof(block
));
631 STORAGE_put_big_block(hf
,blocknr
,block
);
635 /******************************************************************************
636 * IStream16_QueryInterface [STORAGE.518]
638 HRESULT WINAPI
IStream16_QueryInterface(
639 LPSTREAM16
this,REFIID refiid
,LPVOID
*obj
643 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
644 TRACE(relay
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
645 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
649 return OLE_E_ENUM_NOMORE
;
653 /******************************************************************************
654 * IStream16_AddRef [STORAGE.519]
656 ULONG WINAPI
IStream16_AddRef(LPSTREAM16
this) {
657 return ++(this->ref
);
660 /******************************************************************************
661 * IStream16_Release [STORAGE.520]
663 ULONG WINAPI
IStream16_Release(LPSTREAM16
this) {
664 FlushFileBuffers(this->hf
);
667 CloseHandle(this->hf
);
674 /******************************************************************************
675 * IStream16_Seek [STORAGE.523]
678 * Does not handle 64 bits
680 HRESULT WINAPI
IStream16_Seek(
681 LPSTREAM16
this,LARGE_INTEGER offset
,DWORD whence
,ULARGE_INTEGER
*newpos
683 TRACE(relay
,"(%p)->([%ld.%ld],%ld,%p)\n",this,offset
.HighPart
,offset
.LowPart
,whence
,newpos
);
686 /* unix SEEK_xx should be the same as win95 ones */
688 /* offset must be ==0 (<0 is invalid, and >0 cannot be handled
691 assert(offset
.HighPart
==0);
692 this->offset
.HighPart
= offset
.HighPart
;
693 this->offset
.LowPart
= offset
.LowPart
;
696 if (offset
.HighPart
< 0) {
697 /* FIXME: is this negation correct ? */
698 offset
.HighPart
= -offset
.HighPart
;
699 offset
.LowPart
= (0xffffffff ^ offset
.LowPart
)+1;
701 assert(offset
.HighPart
==0);
702 assert(this->offset
.LowPart
>= offset
.LowPart
);
703 this->offset
.LowPart
-= offset
.LowPart
;
705 assert(offset
.HighPart
==0);
706 this->offset
.LowPart
+= offset
.LowPart
;
710 assert(offset
.HighPart
==0);
711 this->offset
.LowPart
= this->stde
.pps_size
-offset
.LowPart
;
714 if (this->offset
.LowPart
>this->stde
.pps_size
)
715 this->offset
.LowPart
=this->stde
.pps_size
;
716 if (newpos
) *newpos
= this->offset
;
720 /******************************************************************************
721 * IStream16_Read [STORAGE.521]
723 HRESULT WINAPI
IStream16_Read(
724 LPSTREAM16
this,void *pv
,ULONG cb
,ULONG
*pcbRead
727 ULONG
*bytesread
=pcbRead
,xxread
;
730 TRACE(relay
,"(%p)->(%p,%ld,%p)\n",this,pv
,cb
,pcbRead
);
731 if (!pcbRead
) bytesread
=&xxread
;
734 if (cb
>this->stde
.pps_size
-this->offset
.LowPart
)
735 cb
=this->stde
.pps_size
-this->offset
.LowPart
;
736 if (this->stde
.pps_size
< 0x1000) {
737 /* use small block reader */
738 blocknr
= STORAGE_get_nth_next_small_blocknr(this->hf
,this->stde
.pps_sb
,this->offset
.LowPart
/SMALLSIZE
);
742 if (!STORAGE_get_small_block(this->hf
,blocknr
,block
)) {
743 WARN(ole
,"small block read failed!!!\n");
747 if (cc
>SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1)))
748 cc
=SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1));
749 memcpy((LPBYTE
)pv
,block
+(this->offset
.LowPart
&(SMALLSIZE
-1)),cc
);
750 this->offset
.LowPart
+=cc
;
754 blocknr
= STORAGE_get_next_small_blocknr(this->hf
,blocknr
);
757 /* use big block reader */
758 blocknr
= STORAGE_get_nth_next_big_blocknr(this->hf
,this->stde
.pps_sb
,this->offset
.LowPart
/BIGSIZE
);
762 if (!STORAGE_get_big_block(this->hf
,blocknr
,block
)) {
763 WARN(ole
,"big block read failed!!!\n");
767 if (cc
>BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1)))
768 cc
=BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1));
769 memcpy((LPBYTE
)pv
,block
+(this->offset
.LowPart
&(BIGSIZE
-1)),cc
);
770 this->offset
.LowPart
+=cc
;
774 blocknr
=STORAGE_get_next_big_blocknr(this->hf
,blocknr
);
780 /******************************************************************************
781 * IStream16_Write [STORAGE.522]
783 HRESULT WINAPI
IStream16_Write(
784 LPSTREAM16
this,const void *pv
,ULONG cb
,ULONG
*pcbWrite
787 ULONG
*byteswritten
=pcbWrite
,xxwritten
;
788 int oldsize
,newsize
,i
,curoffset
=0,lastblocknr
,blocknr
,cc
;
789 HFILE32 hf
= this->hf
;
791 if (!pcbWrite
) byteswritten
=&xxwritten
;
794 TRACE(relay
,"(%p)->(%p,%ld,%p)\n",this,pv
,cb
,pcbWrite
);
795 /* do we need to junk some blocks? */
796 newsize
= this->offset
.LowPart
+cb
;
797 oldsize
= this->stde
.pps_size
;
798 if (newsize
< oldsize
) {
799 if (oldsize
< 0x1000) {
800 /* only small blocks */
801 blocknr
=STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,newsize
/SMALLSIZE
);
805 /* will set the rest of the chain to 'free' */
806 if (!STORAGE_set_small_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
809 if (newsize
>= 0x1000) {
810 blocknr
=STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,newsize
/BIGSIZE
);
813 /* will set the rest of the chain to 'free' */
814 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
817 /* Migrate large blocks to small blocks
818 * (we just migrate newsize bytes)
820 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,newsize
+BIGSIZE
);
822 blocknr
= this->stde
.pps_sb
;
825 if (!STORAGE_get_big_block(hf
,blocknr
,curdata
)) {
826 HeapFree(GetProcessHeap(),0,data
);
831 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
833 /* frees complete chain for this stream */
834 if (!STORAGE_set_big_chain(hf
,this->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
837 blocknr
= this->stde
.pps_sb
= STORAGE_get_free_small_blocknr(hf
);
842 if (!STORAGE_put_small_block(hf
,blocknr
,curdata
))
846 if (!STORAGE_set_small_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
850 int newblocknr
= STORAGE_get_free_small_blocknr(hf
);
853 if (!STORAGE_set_small_chain(hf
,blocknr
,newblocknr
))
855 blocknr
= newblocknr
;
857 curdata
+= SMALLSIZE
;
859 HeapFree(GetProcessHeap(),0,data
);
862 this->stde
.pps_size
= newsize
;
865 if (newsize
> oldsize
) {
866 if (oldsize
>= 0x1000) {
867 /* should return the block right before the 'endofchain' */
868 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,this->stde
.pps_size
/BIGSIZE
);
870 lastblocknr
= blocknr
;
871 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
872 blocknr
= STORAGE_get_free_big_blocknr(hf
);
875 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
877 lastblocknr
= blocknr
;
879 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
882 if (newsize
< 0x1000) {
883 /* find startblock */
885 this->stde
.pps_sb
= blocknr
= STORAGE_get_free_small_blocknr(hf
);
887 blocknr
= STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,this->stde
.pps_size
/SMALLSIZE
);
891 /* allocate required new small blocks */
892 lastblocknr
= blocknr
;
893 for (i
=oldsize
/SMALLSIZE
;i
<newsize
/SMALLSIZE
;i
++) {
894 blocknr
= STORAGE_get_free_small_blocknr(hf
);
897 if (!STORAGE_set_small_chain(hf
,lastblocknr
,blocknr
))
899 lastblocknr
= blocknr
;
901 /* and terminate the chain */
902 if (!STORAGE_set_small_chain(hf
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
906 /* no single block allocated yet */
907 blocknr
=STORAGE_get_free_big_blocknr(hf
);
910 this->stde
.pps_sb
= blocknr
;
912 /* Migrate small blocks to big blocks */
913 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,oldsize
+BIGSIZE
);
915 blocknr
= this->stde
.pps_sb
;
919 if (!STORAGE_get_small_block(hf
,blocknr
,curdata
)) {
920 HeapFree(GetProcessHeap(),0,data
);
923 curdata
+= SMALLSIZE
;
925 blocknr
= STORAGE_get_next_small_blocknr(hf
,blocknr
);
927 /* free small block chain */
928 if (!STORAGE_set_small_chain(hf
,this->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
931 blocknr
= this->stde
.pps_sb
= STORAGE_get_free_big_blocknr(hf
);
934 /* put the data into the big blocks */
935 cc
= this->stde
.pps_size
;
937 if (!STORAGE_put_big_block(hf
,blocknr
,curdata
))
941 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
945 int newblocknr
= STORAGE_get_free_big_blocknr(hf
);
948 if (!STORAGE_set_big_chain(hf
,blocknr
,newblocknr
))
950 blocknr
= newblocknr
;
954 HeapFree(GetProcessHeap(),0,data
);
956 /* generate big blocks to fit the new data */
957 lastblocknr
= blocknr
;
958 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
959 blocknr
= STORAGE_get_free_big_blocknr(hf
);
962 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
964 lastblocknr
= blocknr
;
966 /* terminate chain */
967 if (!STORAGE_set_big_chain(hf
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
971 this->stde
.pps_size
= newsize
;
974 /* There are just some cases where we didn't modify it, we write it out
977 if (!STORAGE_put_pps_entry(hf
,this->ppsent
,&(this->stde
)))
980 /* finally the write pass */
981 if (this->stde
.pps_size
< 0x1000) {
982 blocknr
= STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,this->offset
.LowPart
/SMALLSIZE
);
985 /* we ensured that it is allocated above */
987 /* Read old block everytime, since we can have
988 * overlapping data at START and END of the write
990 if (!STORAGE_get_small_block(hf
,blocknr
,block
))
993 cc
= SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1));
996 memcpy( ((LPBYTE
)block
)+(this->offset
.LowPart
&(SMALLSIZE
-1)),
997 (LPBYTE
)(pv
+curoffset
),
1000 if (!STORAGE_put_small_block(hf
,blocknr
,block
))
1005 this->offset
.LowPart
+= cc
;
1006 *byteswritten
+= cc
;
1007 blocknr
= STORAGE_get_next_small_blocknr(hf
,blocknr
);
1010 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,this->offset
.LowPart
/BIGSIZE
);
1013 /* we ensured that it is allocated above, so it better is */
1015 /* read old block everytime, since we can have
1016 * overlapping data at START and END of the write
1018 if (!STORAGE_get_big_block(hf
,blocknr
,block
))
1021 cc
= BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1));
1024 memcpy( ((LPBYTE
)block
)+(this->offset
.LowPart
&(BIGSIZE
-1)),
1025 (LPBYTE
)(pv
+curoffset
),
1028 if (!STORAGE_put_big_block(hf
,blocknr
,block
))
1033 this->offset
.LowPart
+= cc
;
1034 *byteswritten
+= cc
;
1035 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
1041 /******************************************************************************
1042 * _create_istream16 [Internal]
1044 static void _create_istream16(LPSTREAM16
*str
) {
1047 if (!strvt16
.fnQueryInterface
) {
1048 HMODULE16 wp
= GetModuleHandle16("STORAGE");
1050 #define VTENT(x) strvt16.fn##x = (void*)WIN32_GetProcAddress16(wp,"IStream16_"#x);
1051 VTENT(QueryInterface
)
1066 segstrvt16
= SEGPTR_NEW(IStream16_VTable
);
1067 memcpy(segstrvt16
,&strvt16
,sizeof(strvt16
));
1068 segstrvt16
= (LPSTREAM16_VTABLE
)SEGPTR_GET(segstrvt16
);
1070 #define VTENT(x) strvt16.fn##x = IStream16_##x;
1071 VTENT(QueryInterface
)
1088 segstrvt16
= &strvt16
;
1091 lpst
= SEGPTR_NEW(IStream16
);
1092 lpst
->lpvtbl
= segstrvt16
;
1094 lpst
->thisptr
= SEGPTR_GET(lpst
);
1095 *str
= (void*)lpst
->thisptr
;
1098 /*****************************************************************************
1099 * IStream32_QueryInterface [VTABLE]
1101 HRESULT WINAPI
IStream32_QueryInterface(
1102 LPSTREAM32
this,REFIID refiid
,LPVOID
*obj
1106 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1107 TRACE(relay
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1108 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1112 return OLE_E_ENUM_NOMORE
;
1116 /******************************************************************************
1117 * IStream32_AddRef [VTABLE]
1119 ULONG WINAPI
IStream32_AddRef(LPSTREAM32
this) {
1120 return ++(this->ref
);
1123 /******************************************************************************
1124 * IStream32_Release [VTABLE]
1126 ULONG WINAPI
IStream32_Release(LPSTREAM32
this) {
1127 FlushFileBuffers(this->hf
);
1130 CloseHandle(this->hf
);
1137 static IStream32_VTable strvt32
= {
1138 IStream32_QueryInterface
,
1152 /******************************************************************************
1153 * IStorage16_QueryInterface [STORAGE.500]
1155 HRESULT WINAPI
IStorage16_QueryInterface(
1156 LPSTORAGE16
this,REFIID refiid
,LPVOID
*obj
1160 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1161 TRACE(relay
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1163 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1167 return OLE_E_ENUM_NOMORE
;
1170 /******************************************************************************
1171 * IStorage16_AddRef [STORAGE.501]
1173 ULONG WINAPI
IStorage16_AddRef(LPSTORAGE16
this) {
1174 return ++(this->ref
);
1177 /******************************************************************************
1178 * IStorage16_Release [STORAGE.502]
1180 ULONG WINAPI
IStorage16_Release(LPSTORAGE16
this) {
1188 /******************************************************************************
1189 * IStorage16_Stat [STORAGE.517]
1191 HRESULT WINAPI
IStorage16_Stat(
1192 LPSTORAGE16
this,STATSTG
*pstatstg
, DWORD grfStatFlag
1194 TRACE(ole
,"(%p)->(%p,0x%08lx)\n",
1195 this,pstatstg
,grfStatFlag
1197 pstatstg
->pwcsName
=(LPOLESTR16
)SEGPTR_GET(SEGPTR_STRDUP_WtoA(this->stde
.pps_rawname
));
1198 pstatstg
->type
= this->stde
.pps_type
;
1199 pstatstg
->cbSize
.LowPart
= this->stde
.pps_size
;
1200 pstatstg
->mtime
= this->stde
.pps_ft1
; /* FIXME */ /* why? */
1201 pstatstg
->atime
= this->stde
.pps_ft2
; /* FIXME */
1202 pstatstg
->ctime
= this->stde
.pps_ft2
; /* FIXME */
1203 pstatstg
->grfMode
= 0; /* FIXME */
1204 pstatstg
->grfLocksSupported
= 0; /* FIXME */
1205 pstatstg
->clsid
= this->stde
.pps_guid
;
1206 pstatstg
->grfStateBits
= 0; /* FIXME */
1207 pstatstg
->reserved
= 0;
1211 /******************************************************************************
1212 * IStorage16_Commit [STORAGE.509]
1214 HRESULT WINAPI
IStorage16_Commit(
1215 LPSTORAGE16
this,DWORD commitflags
1217 FIXME(ole
,"(%p)->(0x%08lx),STUB!\n",
1223 /******************************************************************************
1224 * IStorage16_CopyTo [STORAGE.507]
1226 HRESULT WINAPI
IStorage16_CopyTo(LPSTORAGE16
this,DWORD ciidExclude
,const IID
*rgiidExclude
,SNB16 SNB16Exclude
,IStorage16
*pstgDest
) {
1230 WINE_StringFromCLSID(rgiidExclude
,xguid
);
1232 strcpy(xguid
,"<no guid>");
1233 FIXME(ole
,"IStorage16(%p)->(0x%08lx,%s,%p,%p),stub!\n",
1234 this,ciidExclude
,xguid
,SNB16Exclude
,pstgDest
1240 /******************************************************************************
1241 * IStorage16_CreateStorage [STORAGE.505]
1243 HRESULT WINAPI
IStorage16_CreateStorage(
1244 LPSTORAGE16
this,LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD dwStgFormat
,DWORD reserved2
, IStorage16
**ppstg
1248 struct storage_pps_entry stde
;
1249 struct storage_header sth
;
1250 HFILE32 hf
=this->hf
;
1254 TRACE(ole
,"(%p)->(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1255 this,pwcsName
,grfMode
,dwStgFormat
,reserved2
,ppstg
1257 if (grfMode
& STGM_TRANSACTED
)
1258 FIXME(ole
,"We do not support transacted Compound Storage. Using direct mode.\n");
1259 _create_istorage16(ppstg
);
1260 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstg
);
1261 lpstg
->hf
= this->hf
;
1263 ppsent
=STORAGE_get_free_pps_entry(lpstg
->hf
);
1267 if (stde
.pps_dir
==-1) {
1268 stde
.pps_dir
= ppsent
;
1271 FIXME(ole
," use prev chain too ?\n");
1273 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,x
,&stde
))
1275 while (stde
.pps_next
!=-1) {
1277 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,x
,&stde
))
1280 stde
.pps_next
= ppsent
;
1282 assert(STORAGE_put_pps_entry(lpstg
->hf
,x
,&stde
));
1283 assert(1==STORAGE_get_pps_entry(lpstg
->hf
,ppsent
,&(lpstg
->stde
)));
1284 lstrcpyAtoW(lpstg
->stde
.pps_rawname
,pwcsName
);
1285 lpstg
->stde
.pps_sizeofname
= lstrlen32A(pwcsName
)*2+2;
1286 lpstg
->stde
.pps_next
= -1;
1287 lpstg
->stde
.pps_prev
= -1;
1288 lpstg
->stde
.pps_dir
= -1;
1289 lpstg
->stde
.pps_sb
= -1;
1290 lpstg
->stde
.pps_size
= 0;
1291 lpstg
->stde
.pps_type
= 1;
1292 lpstg
->ppsent
= ppsent
;
1293 /* FIXME: timestamps? */
1294 if (!STORAGE_put_pps_entry(lpstg
->hf
,ppsent
,&(lpstg
->stde
)))
1299 /******************************************************************************
1300 * IStorage16_CreateStream [STORAGE.503]
1302 HRESULT WINAPI
IStorage16_CreateStream(
1303 LPSTORAGE16
this,LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD reserved1
,DWORD reserved2
, IStream16
**ppstm
1307 struct storage_pps_entry stde
;
1309 TRACE(ole
,"(%p)->(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1310 this,pwcsName
,grfMode
,reserved1
,reserved2
,ppstm
1312 if (grfMode
& STGM_TRANSACTED
)
1313 FIXME(ole
,"We do not support transacted Compound Storage. Using direct mode.\n");
1314 _create_istream16(ppstm
);
1315 lpstr
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstm
);
1316 lpstr
->hf
= FILE_Dup(this->hf
);
1317 lpstr
->offset
.LowPart
= 0;
1318 lpstr
->offset
.HighPart
= 0;
1320 ppsent
=STORAGE_get_free_pps_entry(lpstr
->hf
);
1324 if (stde
.pps_next
==-1)
1327 while (stde
.pps_next
!=-1) {
1329 if (1!=STORAGE_get_pps_entry(lpstr
->hf
,x
,&stde
))
1332 stde
.pps_next
= ppsent
;
1333 assert(STORAGE_put_pps_entry(lpstr
->hf
,x
,&stde
));
1334 assert(1==STORAGE_get_pps_entry(lpstr
->hf
,ppsent
,&(lpstr
->stde
)));
1335 lstrcpyAtoW(lpstr
->stde
.pps_rawname
,pwcsName
);
1336 lpstr
->stde
.pps_sizeofname
= lstrlen32A(pwcsName
)*2+2;
1337 lpstr
->stde
.pps_next
= -1;
1338 lpstr
->stde
.pps_prev
= -1;
1339 lpstr
->stde
.pps_dir
= -1;
1340 lpstr
->stde
.pps_sb
= -1;
1341 lpstr
->stde
.pps_size
= 0;
1342 lpstr
->stde
.pps_type
= 2;
1343 lpstr
->ppsent
= ppsent
;
1344 /* FIXME: timestamps? */
1345 if (!STORAGE_put_pps_entry(lpstr
->hf
,ppsent
,&(lpstr
->stde
)))
1350 /******************************************************************************
1351 * IStorage16_OpenStorage [STORAGE.506]
1353 HRESULT WINAPI
IStorage16_OpenStorage(
1354 LPSTORAGE16
this,LPCOLESTR16 pwcsName
, IStorage16
*pstgPrio
, DWORD grfMode
, SNB16 snbExclude
, DWORD reserved
, IStorage16
**ppstg
1360 TRACE(relay
,"(%p)->(%s,%p,0x%08lx,%p,0x%08lx,%p)\n",
1361 this,pwcsName
,pstgPrio
,grfMode
,snbExclude
,reserved
,ppstg
1363 if (grfMode
& STGM_TRANSACTED
)
1364 FIXME(ole
,"We do not support transacted Compound Storage. Using direct mode.\n");
1365 _create_istorage16(ppstg
);
1366 lpstg
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstg
);
1367 lpstg
->hf
= FILE_Dup(this->hf
);
1368 lstrcpyAtoW(name
,pwcsName
);
1369 newpps
= STORAGE_look_for_named_pps(lpstg
->hf
,this->stde
.pps_dir
,name
);
1371 IStream16_Release(lpstg
);
1375 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,newpps
,&(lpstg
->stde
))) {
1376 IStream16_Release(lpstg
);
1379 lpstg
->ppsent
= newpps
;
1383 /******************************************************************************
1384 * IStorage16_OpenStream [STORAGE.504]
1386 HRESULT WINAPI
IStorage16_OpenStream(
1387 LPSTORAGE16
this,LPCOLESTR16 pwcsName
, void *reserved1
, DWORD grfMode
, DWORD reserved2
, IStream16
**ppstm
1393 TRACE(relay
,"(%p)->(%s,%p,0x%08lx,0x%08lx,%p)\n",
1394 this,pwcsName
,reserved1
,grfMode
,reserved2
,ppstm
1396 if (grfMode
& STGM_TRANSACTED
)
1397 FIXME(ole
,"We do not support transacted Compound Storage. Using direct mode.\n");
1398 _create_istream16(ppstm
);
1399 lpstr
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstm
);
1400 lpstr
->hf
= FILE_Dup(this->hf
);
1401 lstrcpyAtoW(name
,pwcsName
);
1402 newpps
= STORAGE_look_for_named_pps(lpstr
->hf
,this->stde
.pps_dir
,name
);
1404 IStream16_Release(lpstr
);
1408 if (1!=STORAGE_get_pps_entry(lpstr
->hf
,newpps
,&(lpstr
->stde
))) {
1409 IStream16_Release(lpstr
);
1412 lpstr
->offset
.LowPart
= 0;
1413 lpstr
->offset
.HighPart
= 0;
1414 lpstr
->ppsent
= newpps
;
1418 /******************************************************************************
1419 * _create_istorage16 [INTERNAL]
1421 static void _create_istorage16(LPSTORAGE16
*stg
) {
1424 if (!stvt16
.fnQueryInterface
) {
1425 HMODULE16 wp
= GetModuleHandle16("STORAGE");
1427 #define VTENT(x) stvt16.fn##x = (void*)WIN32_GetProcAddress16(wp,"IStorage16_"#x);
1428 VTENT(QueryInterface
)
1433 VTENT(CreateStorage
)
1436 VTENT(MoveElementTo
)
1440 VTENT(DestroyElement
)
1441 VTENT(RenameElement
)
1442 VTENT(SetElementTimes
)
1447 segstvt16
= SEGPTR_NEW(IStorage16_VTable
);
1448 memcpy(segstvt16
,&stvt16
,sizeof(stvt16
));
1449 segstvt16
= (LPSTORAGE16_VTABLE
)SEGPTR_GET(segstvt16
);
1451 #define VTENT(x) stvt16.fn##x = IStorage16_##x;
1452 VTENT(QueryInterface
)
1457 VTENT(CreateStorage
)
1461 /* not (yet) implemented ...
1462 VTENT(MoveElementTo)
1465 VTENT(DestroyElement)
1466 VTENT(RenameElement)
1467 VTENT(SetElementTimes)
1473 segstvt16
= &stvt16
;
1476 lpst
= SEGPTR_NEW(IStorage16
);
1477 lpst
->lpvtbl
= segstvt16
;
1479 lpst
->thisptr
= SEGPTR_GET(lpst
);
1480 *stg
= (void*)lpst
->thisptr
;
1483 /******************************************************************************
1484 * IStorage32_QueryInterface [VTABLE]
1486 HRESULT WINAPI
IStorage32_QueryInterface(
1487 LPSTORAGE32
this,REFIID refiid
,LPVOID
*obj
1491 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1492 TRACE(relay
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1494 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1498 return OLE_E_ENUM_NOMORE
;
1501 /******************************************************************************
1502 * IStorage32_AddRef [VTABLE]
1504 ULONG WINAPI
IStorage32_AddRef(LPSTORAGE32
this) {
1505 return ++(this->ref
);
1508 /******************************************************************************
1509 * IStorage32_Release [VTABLE]
1511 ULONG WINAPI
IStorage32_Release(LPSTORAGE32
this) {
1515 HeapFree(GetProcessHeap(),0,this);
1519 /******************************************************************************
1520 * IStorage32_CreateStream [VTABLE]
1522 HRESULT WINAPI
IStorage32_CreateStream(
1523 LPSTORAGE32
this,LPCOLESTR32 pwcsName
,DWORD grfMode
,DWORD reserved1
,DWORD reserved2
, IStream32
**ppstm
1525 TRACE(ole
,"(%p)->(%p,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1526 this,pwcsName
,grfMode
,reserved1
,reserved2
,ppstm
1528 *ppstm
= (IStream32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStream32
));
1529 (*ppstm
)->lpvtbl
= &strvt32
;
1535 /******************************************************************************
1536 * IStorage32_OpenStream [VTABLE]
1538 HRESULT WINAPI
IStorage32_OpenStream(
1539 LPSTORAGE32
this,LPCOLESTR32 pwcsName
, void *reserved1
, DWORD grfMode
, DWORD reserved2
, IStream32
**ppstm
1541 TRACE(ole
,"(%p)->(%p,%p,0x%08lx,0x%08lx,%p)\n",
1542 this,pwcsName
,reserved1
,grfMode
,reserved2
,ppstm
1544 *ppstm
= (IStream32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStream32
));
1545 (*ppstm
)->lpvtbl
= &strvt32
;
1550 static IStorage32_VTable stvt32
= {
1551 IStorage32_QueryInterface
,
1554 IStorage32_CreateStream
,
1555 IStorage32_OpenStream
,
1568 /******************************************************************************
1569 * Storage API functions
1572 /******************************************************************************
1573 * StgCreateDocFile16 [STORAGE.1]
1575 OLESTATUS WINAPI
StgCreateDocFile16(
1576 LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD reserved
,IStorage16
**ppstgOpen
1581 struct storage_pps_entry stde
;
1583 TRACE(ole
,"(%s,0x%08lx,0x%08lx,%p)\n",
1584 pwcsName
,grfMode
,reserved
,ppstgOpen
1586 _create_istorage16(ppstgOpen
);
1587 hf
= CreateFile32A(pwcsName
,GENERIC_READ
|GENERIC_WRITE
,0,NULL
,CREATE_NEW
,0,0);
1588 if (hf
==INVALID_HANDLE_VALUE32
) {
1589 WARN(ole
,"couldn't open file for storage:%ld\n",GetLastError());
1592 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstgOpen
);
1594 /* FIXME: check for existance before overwriting? */
1595 if (!STORAGE_init_storage(hf
)) {
1600 while (!ret
) { /* neither 1 nor <0 */
1601 ret
=STORAGE_get_pps_entry(hf
,i
,&stde
);
1602 if ((ret
==1) && (stde
.pps_type
==5)) {
1610 IStorage16_Release(lpstg
); /* will remove it */
1616 /******************************************************************************
1617 * StgCreateDocFile32 [OLE32.144]
1619 OLESTATUS WINAPI
StgCreateDocFile32(
1620 LPCOLESTR32 pwcsName
,DWORD grfMode
,DWORD reserved
,IStorage32
**ppstgOpen
1622 TRACE(ole
,"(%p,0x%08lx,0x%08lx,%p)\n",
1623 pwcsName
,grfMode
,reserved
,ppstgOpen
1625 *ppstgOpen
= (IStorage32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStorage32
));
1626 (*ppstgOpen
)->ref
= 1;
1627 (*ppstgOpen
)->lpvtbl
= &stvt32
;
1631 /******************************************************************************
1632 * StgIsStorageFile16 [STORAGE.5]
1634 OLESTATUS WINAPI
StgIsStorageFile16(LPCOLESTR16 fn
) {
1639 TRACE(ole
,"(\'%s\')\n",fn
);
1640 hf
= OpenFile32(fn
,&ofs
,OF_SHARE_DENY_NONE
);
1641 if (hf
==HFILE_ERROR32
)
1642 return STG_E_FILENOTFOUND
;
1643 if (24!=_lread32(hf
,magic
,24)) {
1644 WARN(ole
," too short\n");
1648 if (!memcmp(magic
,STORAGE_magic
,8)) {
1649 WARN(ole
," -> YES\n");
1653 if (!memcmp(magic
,STORAGE_notmagic
,8)) {
1654 WARN(ole
," -> NO\n");
1658 if (!memcmp(magic
,STORAGE_oldmagic
,8)) {
1659 WARN(ole
," -> old format\n");
1661 return STG_E_OLDFORMAT
;
1663 WARN(ole
," -> Invalid header.\n");
1665 return STG_E_INVALIDHEADER
;
1668 /******************************************************************************
1669 * StgIsStorageFile32 [OLE32.146]
1672 StgIsStorageFile32(LPCOLESTR32 fn
)
1674 LPOLESTR16 xfn
= HEAP_strdupWtoA(GetProcessHeap(),0,fn
);
1675 OLESTATUS ret
= StgIsStorageFile16(xfn
);
1677 HeapFree(GetProcessHeap(),0,xfn
);
1682 /******************************************************************************
1683 * StgOpenStorage16 [STORAGE.3]
1685 OLESTATUS WINAPI
StgOpenStorage16(
1686 const OLECHAR16
* pwcsName
,IStorage16
*pstgPriority
,DWORD grfMode
,
1687 SNB16 snbExclude
,DWORD reserved
, IStorage16
**ppstgOpen
1692 struct storage_pps_entry stde
;
1694 TRACE(ole
,"(%s,%p,0x%08lx,%p,%ld,%p)\n",
1695 pwcsName
,pstgPriority
,grfMode
,snbExclude
,reserved
,ppstgOpen
1697 _create_istorage16(ppstgOpen
);
1698 hf
= CreateFile32A(pwcsName
,GENERIC_READ
,0,NULL
,0,0,0);
1699 if (hf
==INVALID_HANDLE_VALUE32
) {
1700 WARN(ole
,"Couldn't open file for storage\n");
1703 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstgOpen
);
1707 while (!ret
) { /* neither 1 nor <0 */
1708 ret
=STORAGE_get_pps_entry(hf
,i
,&stde
);
1709 if ((ret
==1) && (stde
.pps_type
==5)) {
1716 IStorage16_Release(lpstg
); /* will remove it */
1723 /******************************************************************************
1724 * StgOpenStorage32 [OLE32.148]
1726 OLESTATUS WINAPI
StgOpenStorage32(
1727 const OLECHAR32
* pwcsName
,IStorage32
*pstgPriority
,DWORD grfMode
,
1728 SNB32 snbExclude
,DWORD reserved
, IStorage32
**ppstgOpen
1730 FIXME(ole
,"StgOpenStorage32(%p,%p,0x%08lx,%p,%ld,%p),stub!\n",
1731 pwcsName
,pstgPriority
,grfMode
,snbExclude
,reserved
,
1733 *ppstgOpen
= (IStorage32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStorage32
));
1734 (*ppstgOpen
)->ref
= 1;
1735 (*ppstgOpen
)->lpvtbl
= &stvt32
;