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
20 #include "interfaces.h"
28 static const BYTE STORAGE_magic
[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
29 static const BYTE STORAGE_notmagic
[8]={0x0e,0x11,0xfc,0x0d,0xd0,0xcf,0x11,0xe0};
30 static const BYTE STORAGE_oldmagic
[8]={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
35 #define SMALLBLOCKS_PER_BIGBLOCK (BIGSIZE/SMALLSIZE)
37 #define READ_HEADER assert(STORAGE_get_big_block(hf,-1,(LPBYTE)&sth));assert(!memcmp(STORAGE_magic,sth.magic,sizeof(STORAGE_magic)));
38 static IStorage16_VTable stvt16
;
39 static IStorage16_VTable
*segstvt16
= NULL
;
40 static IStorage32_VTable stvt32
;
41 static IStream16_VTable strvt16
;
42 static IStream16_VTable
*segstrvt16
= NULL
;
43 static IStream32_VTable strvt32
;
45 ULONG WINAPI
IStorage16_AddRef(LPSTORAGE16
this);
46 static void _create_istorage16(LPSTORAGE16
*stg
);
47 static void _create_istream16(LPSTREAM16
*str
);
51 /******************************************************************************
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 fprintf(stderr
,"STORAGE_get_big_block: seek failed (%ld)\n",GetLastError());
61 assert((n
+1)*BIGSIZE
==_llseek32(hf
,0,SEEK_CUR
));
62 if (BIGSIZE
!=_lread32(hf
,block
,BIGSIZE
)) {
63 fprintf(stderr
,"STORAGE_get_big_block(%d): read didn't (%ld)\n",n
,GetLastError());
71 STORAGE_put_big_block(HFILE32 hf
,int n
,BYTE
*block
) {
73 if (-1==_llseek32(hf
,(n
+1)*BIGSIZE
,SEEK_SET
)) {
74 fprintf(stderr
,"STORAGE_put_big_block: seek failed (%ld)\n",GetLastError());
77 assert((n
+1)*BIGSIZE
==_llseek32(hf
,0,SEEK_CUR
));
78 if (BIGSIZE
!=_lwrite32(hf
,block
,BIGSIZE
)) {
79 fprintf(stderr
,"STORAGE_put_big_block: write failed (%ld)\n",GetLastError());
86 STORAGE_get_next_big_blocknr(HFILE32 hf
,int blocknr
) {
87 INT32 bbs
[BIGSIZE
/sizeof(INT32
)];
88 struct storage_header sth
;
92 assert(blocknr
>>7<sth
.num_of_bbd_blocks
);
93 if (sth
.bbd_list
[blocknr
>>7]==0xffffffff)
95 if (!STORAGE_get_big_block(hf
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
))
97 assert(bbs
[blocknr
&0x7f]!=STORAGE_CHAINENTRY_FREE
);
98 return bbs
[blocknr
&0x7f];
102 STORAGE_get_nth_next_big_blocknr(HFILE32 hf
,int blocknr
,int nr
) {
103 INT32 bbs
[BIGSIZE
/sizeof(INT32
)];
105 struct storage_header sth
;
111 assert((blocknr
>>7)<sth
.num_of_bbd_blocks
);
112 assert(sth
.bbd_list
[blocknr
>>7]!=0xffffffff);
114 /* simple caching... */
115 if (lastblock
!=sth
.bbd_list
[blocknr
>>7]) {
116 assert(STORAGE_get_big_block(hf
,sth
.bbd_list
[blocknr
>>7],(LPBYTE
)bbs
));
117 lastblock
= sth
.bbd_list
[blocknr
>>7];
119 blocknr
= bbs
[blocknr
&0x7f];
126 STORAGE_get_root_pps_entry(HFILE32 hf
,struct storage_pps_entry
*pstde
) {
129 struct storage_pps_entry
*stde
=(struct storage_pps_entry
*)block
;
130 struct storage_header sth
;
133 blocknr
= sth
.root_startblock
;
135 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
137 if (!stde
[i
].pps_sizeofname
)
139 if (stde
[i
].pps_type
==5) {
144 blocknr
=STORAGE_get_next_big_blocknr(hf
,blocknr
);
150 STORAGE_get_small_block(HFILE32 hf
,int blocknr
,BYTE
*sblock
) {
153 struct storage_pps_entry root
;
156 assert(STORAGE_get_root_pps_entry(hf
,&root
));
157 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
158 assert(bigblocknr
>=0);
159 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
161 memcpy(sblock
,((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),SMALLSIZE
);
166 STORAGE_put_small_block(HFILE32 hf
,int blocknr
,BYTE
*sblock
) {
169 struct storage_pps_entry root
;
173 assert(STORAGE_get_root_pps_entry(hf
,&root
));
174 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,blocknr
/SMALLBLOCKS_PER_BIGBLOCK
);
175 assert(bigblocknr
>=0);
176 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
178 memcpy(((LPBYTE
)block
)+SMALLSIZE
*(blocknr
&(SMALLBLOCKS_PER_BIGBLOCK
-1)),sblock
,SMALLSIZE
);
179 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
185 STORAGE_get_next_small_blocknr(HFILE32 hf
,int blocknr
) {
187 LPINT32 sbd
= (LPINT32
)block
;
189 struct storage_header sth
;
193 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
194 assert(bigblocknr
>=0);
195 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
196 assert(sbd
[blocknr
& 127]!=STORAGE_CHAINENTRY_FREE
);
197 return sbd
[blocknr
& (128-1)];
201 STORAGE_get_nth_next_small_blocknr(HFILE32 hf
,int blocknr
,int nr
) {
204 LPINT32 sbd
= (LPINT32
)block
;
205 struct storage_header sth
;
210 while ((nr
--) && (blocknr
>=0)) {
211 if (lastblocknr
/128!=blocknr
/128) {
213 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
214 assert(bigblocknr
>=0);
215 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
216 lastblocknr
= blocknr
;
218 assert(lastblocknr
>=0);
220 blocknr
=sbd
[blocknr
& (128-1)];
221 assert(blocknr
!=STORAGE_CHAINENTRY_FREE
);
227 STORAGE_get_pps_entry(HFILE32 hf
,int n
,struct storage_pps_entry
*pstde
) {
230 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
231 struct storage_header sth
;
234 /* we have 4 pps entries per big block */
235 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.root_startblock
,n
/4);
237 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
244 STORAGE_put_pps_entry(HFILE32 hf
,int n
,struct storage_pps_entry
*pstde
) {
247 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)(((LPBYTE
)block
)+128*(n
&3));
248 struct storage_header sth
;
252 /* we have 4 pps entries per big block */
253 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.root_startblock
,n
/4);
255 assert(STORAGE_get_big_block(hf
,blocknr
,block
));
257 assert(STORAGE_put_big_block(hf
,blocknr
,block
));
262 STORAGE_look_for_named_pps(HFILE32 hf
,int n
,LPOLESTR32 name
) {
263 struct storage_pps_entry stde
;
268 if (1!=STORAGE_get_pps_entry(hf
,n
,&stde
))
271 if (!lstrcmp32W(name
,stde
.pps_rawname
))
273 if (stde
.pps_prev
!= -1) {
274 ret
=STORAGE_look_for_named_pps(hf
,stde
.pps_prev
,name
);
278 if (stde
.pps_next
!= -1) {
279 ret
=STORAGE_look_for_named_pps(hf
,stde
.pps_next
,name
);
287 STORAGE_dump_pps_entry(struct storage_pps_entry
*stde
) {
288 char name
[33],xguid
[50];
290 WINE_StringFromCLSID(&(stde
->pps_guid
),xguid
);
292 lstrcpyWtoA(name
,stde
->pps_rawname
);
293 if (!stde
->pps_sizeofname
)
295 fprintf(stderr
,"name: %s\n",name
);
296 fprintf(stderr
,"type: %d\n",stde
->pps_type
);
297 fprintf(stderr
,"prev pps: %ld\n",stde
->pps_prev
);
298 fprintf(stderr
,"next pps: %ld\n",stde
->pps_next
);
299 fprintf(stderr
,"dir pps: %ld\n",stde
->pps_dir
);
300 fprintf(stderr
,"guid: %s\n",xguid
);
301 if (stde
->pps_type
!=2) {
304 t
= DOSFS_FileTimeToUnixTime(&(stde
->pps_ft1
),NULL
);
305 fprintf(stderr
,"ts1: %s\n",ctime(&t
));
306 t
= DOSFS_FileTimeToUnixTime(&(stde
->pps_ft2
),NULL
);
307 fprintf(stderr
,"ts2: %s\n",ctime(&t
));
309 fprintf(stderr
,"startblock: %ld\n",stde
->pps_sb
);
310 fprintf(stderr
,"size: %ld\n",stde
->pps_size
);
314 STORAGE_init_storage(HFILE32 hf
) {
317 struct storage_header
*sth
;
318 struct storage_pps_entry
*stde
;
320 assert(-1!=_llseek32(hf
,0,SEEK_SET
));
321 /* block -1 is the storage header */
322 sth
= (struct storage_header
*)block
;
323 memcpy(sth
->magic
,STORAGE_magic
,8);
324 memset(sth
->unknown1
,0,sizeof(sth
->unknown1
));
325 memset(sth
->unknown2
,0,sizeof(sth
->unknown2
));
326 memset(sth
->unknown3
,0,sizeof(sth
->unknown3
));
327 sth
->num_of_bbd_blocks
= 1;
328 sth
->root_startblock
= 1;
329 sth
->sbd_startblock
= 0xffffffff;
330 memset(sth
->bbd_list
,0xff,sizeof(sth
->bbd_list
));
331 sth
->bbd_list
[0] = 0;
332 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
333 /* block 0 is the big block directory */
335 memset(block
,0xff,sizeof(block
)); /* mark all blocks as free */
336 bbs
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for this block */
337 bbs
[1]=STORAGE_CHAINENTRY_ENDOFCHAIN
; /* for directory entry */
338 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
339 /* block 1 is the root directory entry */
340 memset(block
,0x00,sizeof(block
));
341 stde
= (struct storage_pps_entry
*)block
;
342 lstrcpyAtoW(stde
->pps_rawname
,"RootEntry");
343 stde
->pps_sizeofname
= lstrlen32W(stde
->pps_rawname
)*2+2;
348 stde
->pps_sb
= 0xffffffff;
350 assert(BIGSIZE
==_lwrite32(hf
,block
,BIGSIZE
));
355 STORAGE_set_big_chain(HFILE32 hf
,int blocknr
,INT32 type
) {
357 LPINT32 bbd
= (LPINT32
)block
;
358 int nextblocknr
,bigblocknr
;
359 struct storage_header sth
;
362 assert(blocknr
!=type
);
364 bigblocknr
= sth
.bbd_list
[blocknr
/128];
365 assert(bigblocknr
>=0);
366 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
368 nextblocknr
= bbd
[blocknr
&(128-1)];
369 bbd
[blocknr
&(128-1)] = type
;
372 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
373 type
= STORAGE_CHAINENTRY_FREE
;
374 blocknr
= nextblocknr
;
380 STORAGE_set_small_chain(HFILE32 hf
,int blocknr
,INT32 type
) {
382 LPINT32 sbd
= (LPINT32
)block
;
383 int lastblocknr
,nextsmallblocknr
,bigblocknr
;
384 struct storage_header sth
;
388 assert(blocknr
!=type
);
389 lastblocknr
=-129;bigblocknr
=-2;
391 /* cache block ... */
392 if (lastblocknr
/128!=blocknr
/128) {
393 bigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,sth
.sbd_startblock
,blocknr
/128);
394 assert(bigblocknr
>=0);
395 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
397 lastblocknr
= blocknr
;
398 nextsmallblocknr
= sbd
[blocknr
&(128-1)];
399 sbd
[blocknr
&(128-1)] = type
;
400 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
403 type
= STORAGE_CHAINENTRY_FREE
;
404 blocknr
= nextsmallblocknr
;
410 STORAGE_get_free_big_blocknr(HFILE32 hf
) {
412 LPINT32 sbd
= (LPINT32
)block
;
413 int lastbigblocknr
,i
,curblock
,bigblocknr
;
414 struct storage_header sth
;
419 bigblocknr
= sth
.bbd_list
[curblock
];
420 while (curblock
<sth
.num_of_bbd_blocks
) {
421 assert(bigblocknr
>=0);
422 assert(STORAGE_get_big_block(hf
,bigblocknr
,block
));
424 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
425 sbd
[i
] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
426 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
427 memset(block
,0x42,sizeof(block
));
428 assert(STORAGE_put_big_block(hf
,i
+curblock
*128,block
));
429 return i
+curblock
*128;
431 lastbigblocknr
= bigblocknr
;
432 bigblocknr
= sth
.bbd_list
[++curblock
];
434 bigblocknr
= curblock
*128;
435 /* since we have marked all blocks from 0 up to curblock*128-1
436 * the next free one is curblock*128, where we happily put our
437 * next large block depot.
439 memset(block
,0xff,sizeof(block
));
440 /* mark the block allocated and returned by this function */
441 sbd
[1] = STORAGE_CHAINENTRY_ENDOFCHAIN
;
442 assert(STORAGE_put_big_block(hf
,bigblocknr
,block
));
444 /* if we had a bbd block already (mostlikely) we need
445 * to link the new one into the chain
447 if (lastbigblocknr
!=-1)
448 assert(STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
));
449 sth
.bbd_list
[curblock
]=bigblocknr
;
450 sth
.num_of_bbd_blocks
++;
451 assert(sth
.num_of_bbd_blocks
==curblock
+1);
452 assert(STORAGE_put_big_block(hf
,-1,(LPBYTE
)&sth
));
454 /* Set the end of the chain for the bigblockdepots */
455 assert(STORAGE_set_big_chain(hf
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
));
456 /* add 1, for the first entry is used for the additional big block
457 * depot. (means we already used bigblocknr) */
458 memset(block
,0x42,sizeof(block
));
459 /* allocate this block (filled with 0x42) */
460 assert(STORAGE_put_big_block(hf
,bigblocknr
+1,block
));
466 STORAGE_get_free_small_blocknr(HFILE32 hf
) {
468 LPINT32 sbd
= (LPINT32
)block
;
469 int lastbigblocknr
,newblocknr
,i
,curblock
,bigblocknr
;
470 struct storage_pps_entry root
;
471 struct storage_header sth
;
474 bigblocknr
= sth
.sbd_startblock
;
478 while (bigblocknr
>=0) {
479 if (!STORAGE_get_big_block(hf
,bigblocknr
,block
))
482 if (sbd
[i
]==STORAGE_CHAINENTRY_FREE
) {
483 sbd
[i
]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
484 newblocknr
= i
+curblock
*128;
489 lastbigblocknr
= bigblocknr
;
490 bigblocknr
= STORAGE_get_next_big_blocknr(hf
,bigblocknr
);
493 if (newblocknr
==-1) {
494 bigblocknr
= STORAGE_get_free_big_blocknr(hf
);
498 memset(block
,0xff,sizeof(block
));
499 sbd
[0]=STORAGE_CHAINENTRY_ENDOFCHAIN
;
500 if (!STORAGE_put_big_block(hf
,bigblocknr
,block
))
502 if (lastbigblocknr
==-1) {
503 sth
.sbd_startblock
= bigblocknr
;
504 if (!STORAGE_put_big_block(hf
,-1,(LPBYTE
)&sth
)) /* need to write it */
507 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
))
510 if (!STORAGE_set_big_chain(hf
,bigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
512 newblocknr
= curblock
*128;
514 /* allocate enough big blocks for storing the allocated small block */
515 if (!STORAGE_get_root_pps_entry(hf
,&root
))
520 lastbigblocknr
= STORAGE_get_nth_next_big_blocknr(hf
,root
.pps_sb
,(root
.pps_size
-1)/BIGSIZE
);
521 while (root
.pps_size
< (newblocknr
*SMALLSIZE
+SMALLSIZE
-1)) {
522 /* we need to allocate more stuff */
523 bigblocknr
= STORAGE_get_free_big_blocknr(hf
);
527 if (root
.pps_sb
==-1) {
528 root
.pps_sb
= bigblocknr
;
529 root
.pps_size
+= BIGSIZE
;
531 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,bigblocknr
))
533 root
.pps_size
+= BIGSIZE
;
535 lastbigblocknr
= bigblocknr
;
537 if (!STORAGE_set_big_chain(hf
,lastbigblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
539 if (!STORAGE_put_pps_entry(hf
,0,&root
))
545 STORAGE_get_free_pps_entry(HFILE32 hf
) {
546 int blocknr
,i
,curblock
,lastblocknr
;
548 struct storage_pps_entry
*stde
= (struct storage_pps_entry
*)block
;
549 struct storage_header sth
;
552 blocknr
= sth
.root_startblock
;
556 if (!STORAGE_get_big_block(hf
,blocknr
,block
))
559 if (stde
[i
].pps_sizeofname
==0) /* free */
561 lastblocknr
= blocknr
;
562 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
565 assert(blocknr
==STORAGE_CHAINENTRY_ENDOFCHAIN
);
566 blocknr
= STORAGE_get_free_big_blocknr(hf
);
567 /* sth invalidated */
571 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
573 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
575 memset(block
,0,sizeof(block
));
576 STORAGE_put_big_block(hf
,blocknr
,block
);
580 /******************************************************************************
583 HRESULT WINAPI
IStream16_QueryInterface(
584 LPSTREAM16
this,REFIID refiid
,LPVOID
*obj
588 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
589 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
590 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
594 return OLE_E_ENUM_NOMORE
;
598 ULONG WINAPI
IStream16_AddRef(LPSTREAM16
this) {
599 return ++(this->ref
);
602 ULONG WINAPI
IStream16_Release(LPSTREAM16
this) {
603 FlushFileBuffers(this->hf
);
606 CloseHandle(this->hf
);
613 /* FIXME: not handling 64 bit */
614 HRESULT WINAPI
IStream16_Seek(
615 LPSTREAM16
this,LARGE_INTEGER offset
,DWORD whence
,ULARGE_INTEGER
*newpos
617 TRACE(relay
,"(%p)->Seek([%ld.%ld],%ld,%p)\n",this,offset
.HighPart
,offset
.LowPart
,whence
,newpos
);
620 /* unix SEEK_xx should be the same as win95 ones */
622 /* offset must be ==0 (<0 is invalid, and >0 cannot be handled
625 assert(offset
.HighPart
==0);
626 this->offset
.HighPart
= offset
.HighPart
;
627 this->offset
.LowPart
= offset
.LowPart
;
630 if (offset
.HighPart
< 0) {
631 /* FIXME: is this negation correct ? */
632 offset
.HighPart
= -offset
.HighPart
;
633 offset
.LowPart
= (0xffffffff ^ offset
.LowPart
)+1;
635 assert(offset
.HighPart
==0);
636 assert(this->offset
.LowPart
>= offset
.LowPart
);
637 this->offset
.LowPart
-= offset
.LowPart
;
639 assert(offset
.HighPart
==0);
640 this->offset
.LowPart
+= offset
.LowPart
;
644 assert(offset
.HighPart
==0);
645 this->offset
.LowPart
= this->stde
.pps_size
-offset
.LowPart
;
648 if (this->offset
.LowPart
>this->stde
.pps_size
)
649 this->offset
.LowPart
=this->stde
.pps_size
;
650 if (newpos
) *newpos
= this->offset
;
654 HRESULT WINAPI
IStream16_Read(
655 LPSTREAM16
this,void *pv
,ULONG cb
,ULONG
*pcbRead
658 ULONG
*bytesread
=pcbRead
,xxread
;
661 TRACE(relay
,"(%p)->Read(%p,%ld,%p)\n",this,pv
,cb
,pcbRead
);
662 if (!pcbRead
) bytesread
=&xxread
;
665 if (cb
>this->stde
.pps_size
-this->offset
.LowPart
)
666 cb
=this->stde
.pps_size
-this->offset
.LowPart
;
667 if (this->stde
.pps_size
< 0x1000) {
668 /* use small block reader */
669 blocknr
= STORAGE_get_nth_next_small_blocknr(this->hf
,this->stde
.pps_sb
,this->offset
.LowPart
/SMALLSIZE
);
673 if (!STORAGE_get_small_block(this->hf
,blocknr
,block
)) {
674 fprintf(stderr
,"small block read failed!!!!\n");
678 if (cc
>SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1)))
679 cc
=SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1));
680 memcpy((LPBYTE
)pv
,block
+(this->offset
.LowPart
&(SMALLSIZE
-1)),cc
);
681 this->offset
.LowPart
+=cc
;
685 blocknr
= STORAGE_get_next_small_blocknr(this->hf
,blocknr
);
688 /* use big block reader */
689 blocknr
= STORAGE_get_nth_next_big_blocknr(this->hf
,this->stde
.pps_sb
,this->offset
.LowPart
/BIGSIZE
);
693 if (!STORAGE_get_big_block(this->hf
,blocknr
,block
)) {
694 fprintf(stderr
,"big block read failed!!!!\n");
698 if (cc
>BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1)))
699 cc
=BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1));
700 memcpy((LPBYTE
)pv
,block
+(this->offset
.LowPart
&(BIGSIZE
-1)),cc
);
701 this->offset
.LowPart
+=cc
;
705 blocknr
=STORAGE_get_next_big_blocknr(this->hf
,blocknr
);
711 HRESULT WINAPI
IStream16_Write(
712 LPSTREAM16
this,const void *pv
,ULONG cb
,ULONG
*pcbWrite
715 ULONG
*byteswritten
=pcbWrite
,xxwritten
;
716 int oldsize
,newsize
,i
,curoffset
=0,lastblocknr
,blocknr
,cc
;
717 HFILE32 hf
= this->hf
;
719 if (!pcbWrite
) byteswritten
=&xxwritten
;
722 TRACE(relay
,"(%p)->Write(%p,%ld,%p)\n",this,pv
,cb
,pcbWrite
);
723 /* do we need to junk some blocks? */
724 newsize
= this->offset
.LowPart
+cb
;
725 oldsize
= this->stde
.pps_size
;
726 if (newsize
< oldsize
) {
727 if (oldsize
< 0x1000) {
728 /* only small blocks */
729 blocknr
=STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,newsize
/SMALLSIZE
);
733 /* will set the rest of the chain to 'free' */
734 if (!STORAGE_set_small_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
737 if (newsize
>= 0x1000) {
738 blocknr
=STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,newsize
/BIGSIZE
);
741 /* will set the rest of the chain to 'free' */
742 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
745 /* Migrate large blocks to small blocks
746 * (we just migrate newsize bytes)
748 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,newsize
+BIGSIZE
);
750 blocknr
= this->stde
.pps_sb
;
753 if (!STORAGE_get_big_block(hf
,blocknr
,curdata
)) {
754 HeapFree(GetProcessHeap(),0,data
);
759 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
761 /* frees complete chain for this stream */
762 if (!STORAGE_set_big_chain(hf
,this->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
765 blocknr
= this->stde
.pps_sb
= STORAGE_get_free_small_blocknr(hf
);
770 if (!STORAGE_put_small_block(hf
,blocknr
,curdata
))
774 if (!STORAGE_set_small_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
778 int newblocknr
= STORAGE_get_free_small_blocknr(hf
);
781 if (!STORAGE_set_small_chain(hf
,blocknr
,newblocknr
))
783 blocknr
= newblocknr
;
785 curdata
+= SMALLSIZE
;
787 HeapFree(GetProcessHeap(),0,data
);
790 this->stde
.pps_size
= newsize
;
793 if (newsize
> oldsize
) {
794 if (oldsize
>= 0x1000) {
795 /* should return the block right before the 'endofchain' */
796 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,this->stde
.pps_size
/BIGSIZE
);
798 lastblocknr
= blocknr
;
799 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
800 blocknr
= STORAGE_get_free_big_blocknr(hf
);
803 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
805 lastblocknr
= blocknr
;
807 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
810 if (newsize
< 0x1000) {
811 /* find startblock */
813 this->stde
.pps_sb
= blocknr
= STORAGE_get_free_small_blocknr(hf
);
815 blocknr
= STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,this->stde
.pps_size
/SMALLSIZE
);
819 /* allocate required new small blocks */
820 lastblocknr
= blocknr
;
821 for (i
=oldsize
/SMALLSIZE
;i
<newsize
/SMALLSIZE
;i
++) {
822 blocknr
= STORAGE_get_free_small_blocknr(hf
);
825 if (!STORAGE_set_small_chain(hf
,lastblocknr
,blocknr
))
827 lastblocknr
= blocknr
;
829 /* and terminate the chain */
830 if (!STORAGE_set_small_chain(hf
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
834 /* no single block allocated yet */
835 blocknr
=STORAGE_get_free_big_blocknr(hf
);
838 this->stde
.pps_sb
= blocknr
;
840 /* Migrate small blocks to big blocks */
841 LPBYTE curdata
,data
= HeapAlloc(GetProcessHeap(),0,oldsize
+BIGSIZE
);
843 blocknr
= this->stde
.pps_sb
;
847 if (!STORAGE_get_small_block(hf
,blocknr
,curdata
)) {
848 HeapFree(GetProcessHeap(),0,data
);
851 curdata
+= SMALLSIZE
;
853 blocknr
= STORAGE_get_next_small_blocknr(hf
,blocknr
);
855 /* free small block chain */
856 if (!STORAGE_set_small_chain(hf
,this->stde
.pps_sb
,STORAGE_CHAINENTRY_FREE
))
859 blocknr
= this->stde
.pps_sb
= STORAGE_get_free_big_blocknr(hf
);
862 /* put the data into the big blocks */
863 cc
= this->stde
.pps_size
;
865 if (!STORAGE_put_big_block(hf
,blocknr
,curdata
))
869 if (!STORAGE_set_big_chain(hf
,blocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
873 int newblocknr
= STORAGE_get_free_big_blocknr(hf
);
876 if (!STORAGE_set_big_chain(hf
,blocknr
,newblocknr
))
878 blocknr
= newblocknr
;
882 HeapFree(GetProcessHeap(),0,data
);
884 /* generate big blocks to fit the new data */
885 lastblocknr
= blocknr
;
886 for (i
=oldsize
/BIGSIZE
;i
<newsize
/BIGSIZE
;i
++) {
887 blocknr
= STORAGE_get_free_big_blocknr(hf
);
890 if (!STORAGE_set_big_chain(hf
,lastblocknr
,blocknr
))
892 lastblocknr
= blocknr
;
894 /* terminate chain */
895 if (!STORAGE_set_big_chain(hf
,lastblocknr
,STORAGE_CHAINENTRY_ENDOFCHAIN
))
899 this->stde
.pps_size
= newsize
;
902 /* There are just some cases where we didn't modify it, we write it out
905 if (!STORAGE_put_pps_entry(hf
,this->ppsent
,&(this->stde
)))
908 /* finally the write pass */
909 if (this->stde
.pps_size
< 0x1000) {
910 blocknr
= STORAGE_get_nth_next_small_blocknr(hf
,this->stde
.pps_sb
,this->offset
.LowPart
/SMALLSIZE
);
913 /* we ensured that it is allocated above */
915 /* Read old block everytime, since we can have
916 * overlapping data at START and END of the write
918 if (!STORAGE_get_small_block(hf
,blocknr
,block
))
921 cc
= SMALLSIZE
-(this->offset
.LowPart
&(SMALLSIZE
-1));
924 memcpy( ((LPBYTE
)block
)+(this->offset
.LowPart
&(SMALLSIZE
-1)),
925 (LPBYTE
)(pv
+curoffset
),
928 if (!STORAGE_put_small_block(hf
,blocknr
,block
))
933 this->offset
.LowPart
+= cc
;
935 blocknr
= STORAGE_get_next_small_blocknr(hf
,blocknr
);
938 blocknr
= STORAGE_get_nth_next_big_blocknr(hf
,this->stde
.pps_sb
,this->offset
.LowPart
/BIGSIZE
);
941 /* we ensured that it is allocated above, so it better is */
943 /* read old block everytime, since we can have
944 * overlapping data at START and END of the write
946 if (!STORAGE_get_big_block(hf
,blocknr
,block
))
949 cc
= BIGSIZE
-(this->offset
.LowPart
&(BIGSIZE
-1));
952 memcpy( ((LPBYTE
)block
)+(this->offset
.LowPart
&(BIGSIZE
-1)),
953 (LPBYTE
)(pv
+curoffset
),
956 if (!STORAGE_put_big_block(hf
,blocknr
,block
))
961 this->offset
.LowPart
+= cc
;
963 blocknr
= STORAGE_get_next_big_blocknr(hf
,blocknr
);
969 static void _create_istream16(LPSTREAM16
*str
) {
972 if (!strvt16
.fnQueryInterface
) {
973 HMODULE16 wp
= GetModuleHandle16("STORAGE");
975 #define VTENT(x) strvt16.fn##x = (void*)WIN32_GetProcAddress16(wp,"IStream16_"#x);
976 VTENT(QueryInterface
)
991 segstrvt16
= SEGPTR_NEW(IStream16_VTable
);
992 memcpy(segstrvt16
,&strvt16
,sizeof(strvt16
));
993 segstrvt16
= (LPSTREAM16_VTABLE
)SEGPTR_GET(segstrvt16
);
995 #define VTENT(x) strvt16.fn##x = IStream16_##x;
996 VTENT(QueryInterface
)
1013 segstrvt16
= &strvt16
;
1016 lpst
= SEGPTR_NEW(IStream16
);
1017 lpst
->lpvtbl
= segstrvt16
;
1019 lpst
->thisptr
= SEGPTR_GET(lpst
);
1020 *str
= (void*)lpst
->thisptr
;
1023 /*****************************************************************************
1026 HRESULT WINAPI
IStream32_QueryInterface(
1027 LPSTREAM32
this,REFIID refiid
,LPVOID
*obj
1031 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1032 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
1033 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1037 return OLE_E_ENUM_NOMORE
;
1041 ULONG WINAPI
IStream32_AddRef(LPSTREAM32
this) {
1042 return ++(this->ref
);
1045 ULONG WINAPI
IStream32_Release(LPSTREAM32
this) {
1046 FlushFileBuffers(this->hf
);
1049 CloseHandle(this->hf
);
1056 static IStream32_VTable strvt32
= {
1057 IStream32_QueryInterface
,
1070 /******************************************************************************
1073 HRESULT WINAPI
IStorage16_QueryInterface(
1074 LPSTORAGE16
this,REFIID refiid
,LPVOID
*obj
1078 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1079 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
1081 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1085 return OLE_E_ENUM_NOMORE
;
1088 ULONG WINAPI
IStorage16_AddRef(LPSTORAGE16
this) {
1089 return ++(this->ref
);
1092 ULONG WINAPI
IStorage16_Release(LPSTORAGE16
this) {
1100 HRESULT WINAPI
IStorage16_Stat(
1101 LPSTORAGE16
this,STATSTG
*pstatstg
, DWORD grfStatFlag
1103 fprintf(stderr
,"IStorage16(%p)->Stat(%p,0x%08lx)\n",
1104 this,pstatstg
,grfStatFlag
1106 pstatstg
->pwcsName
=SEGPTR_GET(SEGPTR_STRDUP_WtoA(this->stde
.pps_rawname
));
1107 pstatstg
->type
= this->stde
.pps_type
;
1108 pstatstg
->cbSize
.LowPart
= this->stde
.pps_size
;
1109 pstatstg
->mtime
= this->stde
.pps_ft1
; /* FIXME */
1110 pstatstg
->atime
= this->stde
.pps_ft2
; /* FIXME */
1111 pstatstg
->ctime
= this->stde
.pps_ft2
; /* FIXME */
1112 pstatstg
->grfMode
= 0; /* FIXME */
1113 pstatstg
->grfLocksSupported
= 0; /* FIXME */
1114 pstatstg
->clsid
= this->stde
.pps_guid
;
1115 pstatstg
->grfStateBits
= 0; /* FIXME */
1116 pstatstg
->reserved
= 0;
1120 HRESULT WINAPI
IStorage16_Commit(
1121 LPSTORAGE16
this,DWORD commitflags
1123 fprintf(stderr
,"IStorage16(%p)->Commit(0x%08lx),STUB!\n",
1129 HRESULT WINAPI
IStorage16_CopyTo(LPSTORAGE16
this,DWORD ciidExclude
,const IID
*rgiidExclude
,SNB16 SNB16Exclude
,IStorage16
*pstgDest
) {
1133 WINE_StringFromCLSID(rgiidExclude
,xguid
);
1135 strcpy(xguid
,"<no guid>");
1136 fprintf(stderr
,"IStorage16(%p)->CopyTo(0x%08lx,%s,%p,%p),stub!\n",
1137 this,ciidExclude
,xguid
,SNB16Exclude
,pstgDest
1144 HRESULT WINAPI
IStorage16_CreateStorage(
1145 LPSTORAGE16
this,LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD dwStgFormat
,DWORD reserved2
, IStorage16
**ppstg
1149 struct storage_pps_entry stde
;
1150 struct storage_header sth
;
1151 HFILE32 hf
=this->hf
;
1155 fprintf(stderr
,"IStorage16(%p)->CreateStorage(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1156 this,pwcsName
,grfMode
,dwStgFormat
,reserved2
,ppstg
1158 if (grfMode
& STGM_TRANSACTED
)
1159 fprintf(stderr
,"IStorage::CreateStorage:We do not support transacted Compound Storage. Using direct mode.\n");
1160 _create_istorage16(ppstg
);
1161 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstg
);
1162 lpstg
->hf
= this->hf
;
1164 ppsent
=STORAGE_get_free_pps_entry(lpstg
->hf
);
1168 if (stde
.pps_dir
==-1) {
1169 stde
.pps_dir
= ppsent
;
1172 /* FIXME: use prev chain too ? */
1174 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,x
,&stde
))
1176 while (stde
.pps_next
!=-1) {
1178 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,x
,&stde
))
1181 stde
.pps_next
= ppsent
;
1183 assert(STORAGE_put_pps_entry(lpstg
->hf
,x
,&stde
));
1184 assert(1==STORAGE_get_pps_entry(lpstg
->hf
,ppsent
,&(lpstg
->stde
)));
1185 lstrcpyAtoW(lpstg
->stde
.pps_rawname
,pwcsName
);
1186 lpstg
->stde
.pps_sizeofname
= lstrlen32A(pwcsName
)*2+2;
1187 lpstg
->stde
.pps_next
= -1;
1188 lpstg
->stde
.pps_prev
= -1;
1189 lpstg
->stde
.pps_dir
= -1;
1190 lpstg
->stde
.pps_sb
= -1;
1191 lpstg
->stde
.pps_size
= 0;
1192 lpstg
->stde
.pps_type
= 1;
1193 lpstg
->ppsent
= ppsent
;
1194 /* FIXME: timestamps? */
1195 if (!STORAGE_put_pps_entry(lpstg
->hf
,ppsent
,&(lpstg
->stde
)))
1200 HRESULT WINAPI
IStorage16_CreateStream(
1201 LPSTORAGE16
this,LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD reserved1
,DWORD reserved2
, IStream16
**ppstm
1205 struct storage_pps_entry stde
;
1207 fprintf(stderr
,"IStorage16(%p)->CreateStream(%s,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1208 this,pwcsName
,grfMode
,reserved1
,reserved2
,ppstm
1210 if (grfMode
& STGM_TRANSACTED
)
1211 fprintf(stderr
,"IStorage::CreateStream:We do not support transacted Compound Storage. Using direct mode.\n");
1212 _create_istream16(ppstm
);
1213 lpstr
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstm
);
1214 lpstr
->hf
= FILE_Dup(this->hf
);
1215 lpstr
->offset
.LowPart
= 0;
1216 lpstr
->offset
.HighPart
= 0;
1218 ppsent
=STORAGE_get_free_pps_entry(lpstr
->hf
);
1222 if (stde
.pps_next
==-1)
1225 while (stde
.pps_next
!=-1) {
1227 if (1!=STORAGE_get_pps_entry(lpstr
->hf
,x
,&stde
))
1230 stde
.pps_next
= ppsent
;
1231 assert(STORAGE_put_pps_entry(lpstr
->hf
,x
,&stde
));
1232 assert(1==STORAGE_get_pps_entry(lpstr
->hf
,ppsent
,&(lpstr
->stde
)));
1233 lstrcpyAtoW(lpstr
->stde
.pps_rawname
,pwcsName
);
1234 lpstr
->stde
.pps_sizeofname
= lstrlen32A(pwcsName
)*2+2;
1235 lpstr
->stde
.pps_next
= -1;
1236 lpstr
->stde
.pps_prev
= -1;
1237 lpstr
->stde
.pps_dir
= -1;
1238 lpstr
->stde
.pps_sb
= -1;
1239 lpstr
->stde
.pps_size
= 0;
1240 lpstr
->stde
.pps_type
= 2;
1241 lpstr
->ppsent
= ppsent
;
1242 /* FIXME: timestamps? */
1243 if (!STORAGE_put_pps_entry(lpstr
->hf
,ppsent
,&(lpstr
->stde
)))
1248 HRESULT WINAPI
IStorage16_OpenStorage(
1249 LPSTORAGE16
this,LPCOLESTR16 pwcsName
, IStorage16
*pstgPrio
, DWORD grfMode
, SNB16 snbExclude
, DWORD reserved
, IStorage16
**ppstg
1255 TRACE(relay
,"(%p)->OpenStorage(%s,%p,0x%08lx,%p,0x%08lx,%p)\n",
1256 this,pwcsName
,pstgPrio
,grfMode
,snbExclude
,reserved
,ppstg
1258 if (grfMode
& STGM_TRANSACTED
)
1259 fprintf(stderr
,"IStorage::OpenStorage:We do not support transacted Compound Storage. Using direct mode.\n");
1260 _create_istorage16(ppstg
);
1261 lpstg
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstg
);
1262 lpstg
->hf
= FILE_Dup(this->hf
);
1263 lstrcpyAtoW(name
,pwcsName
);
1264 newpps
= STORAGE_look_for_named_pps(lpstg
->hf
,this->stde
.pps_dir
,name
);
1266 IStream16_Release(lpstg
);
1270 if (1!=STORAGE_get_pps_entry(lpstg
->hf
,newpps
,&(lpstg
->stde
))) {
1271 IStream16_Release(lpstg
);
1274 lpstg
->ppsent
= newpps
;
1278 HRESULT WINAPI
IStorage16_OpenStream(
1279 LPSTORAGE16
this,LPCOLESTR16 pwcsName
, void *reserved1
, DWORD grfMode
, DWORD reserved2
, IStream16
**ppstm
1285 TRACE(relay
,"(%p)->OpenStream(%s,%p,0x%08lx,0x%08lx,%p)\n",
1286 this,pwcsName
,reserved1
,grfMode
,reserved2
,ppstm
1288 if (grfMode
& STGM_TRANSACTED
)
1289 fprintf(stderr
,"IStorage::OpenStream:We do not support transacted Compound Storage. Using direct mode.\n");
1290 _create_istream16(ppstm
);
1291 lpstr
= (LPSTREAM16
)PTR_SEG_TO_LIN(*ppstm
);
1292 lpstr
->hf
= FILE_Dup(this->hf
);
1293 lstrcpyAtoW(name
,pwcsName
);
1294 newpps
= STORAGE_look_for_named_pps(lpstr
->hf
,this->stde
.pps_dir
,name
);
1296 IStream16_Release(lpstr
);
1300 if (1!=STORAGE_get_pps_entry(lpstr
->hf
,newpps
,&(lpstr
->stde
))) {
1301 IStream16_Release(lpstr
);
1304 lpstr
->offset
.LowPart
= 0;
1305 lpstr
->offset
.HighPart
= 0;
1306 lpstr
->ppsent
= newpps
;
1310 static void _create_istorage16(LPSTORAGE16
*stg
) {
1313 if (!stvt16
.fnQueryInterface
) {
1314 HMODULE16 wp
= GetModuleHandle16("STORAGE");
1316 #define VTENT(x) stvt16.fn##x = (void*)WIN32_GetProcAddress16(wp,"IStorage16_"#x);
1317 VTENT(QueryInterface
)
1322 VTENT(CreateStorage
)
1325 VTENT(MoveElementTo
)
1329 VTENT(DestroyElement
)
1330 VTENT(RenameElement
)
1331 VTENT(SetElementTimes
)
1336 segstvt16
= SEGPTR_NEW(IStorage16_VTable
);
1337 memcpy(segstvt16
,&stvt16
,sizeof(stvt16
));
1338 segstvt16
= (LPSTORAGE16_VTABLE
)SEGPTR_GET(segstvt16
);
1340 #define VTENT(x) stvt16.fn##x = IStorage16_##x;
1341 VTENT(QueryInterface
)
1346 VTENT(CreateStorage
)
1350 /* not (yet) implemented ...
1351 VTENT(MoveElementTo)
1354 VTENT(DestroyElement)
1355 VTENT(RenameElement)
1356 VTENT(SetElementTimes)
1362 segstvt16
= &stvt16
;
1365 lpst
= SEGPTR_NEW(IStorage16
);
1366 lpst
->lpvtbl
= segstvt16
;
1368 lpst
->thisptr
= SEGPTR_GET(lpst
);
1369 *stg
= (void*)lpst
->thisptr
;
1372 /******************************************************************************
1375 HRESULT WINAPI
IStorage32_QueryInterface(
1376 LPSTORAGE32
this,REFIID refiid
,LPVOID
*obj
1380 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1381 TRACE(relay
,"(%p)->QueryInterface(%s,%p)\n",this,xrefiid
,obj
);
1383 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1387 return OLE_E_ENUM_NOMORE
;
1390 ULONG WINAPI
IStorage32_AddRef(LPSTORAGE32
this) {
1391 return ++(this->ref
);
1394 ULONG WINAPI
IStorage32_Release(LPSTORAGE32
this) {
1398 HeapFree(GetProcessHeap(),0,this);
1402 HRESULT WINAPI
IStorage32_CreateStream(
1403 LPSTORAGE32
this,LPCOLESTR32 pwcsName
,DWORD grfMode
,DWORD reserved1
,DWORD reserved2
, IStream32
**ppstm
1405 fprintf(stderr
,"IStorage32(%p)->CreateStream(%p,0x%08lx,0x%08lx,0x%08lx,%p)\n",
1406 this,pwcsName
,grfMode
,reserved1
,reserved2
,ppstm
1408 *ppstm
= (IStream32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStream32
));
1409 (*ppstm
)->lpvtbl
= &strvt32
;
1415 HRESULT WINAPI
IStorage32_OpenStream(
1416 LPSTORAGE32
this,LPCOLESTR32 pwcsName
, void *reserved1
, DWORD grfMode
, DWORD reserved2
, IStream32
**ppstm
1418 fprintf(stderr
,"IStorage32(%p)->OpenStream(%p,%p,0x%08lx,0x%08lx,%p)\n",
1419 this,pwcsName
,reserved1
,grfMode
,reserved2
,ppstm
1421 *ppstm
= (IStream32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStream32
));
1422 (*ppstm
)->lpvtbl
= &strvt32
;
1427 static IStorage32_VTable stvt32
= {
1428 IStorage32_QueryInterface
,
1431 IStorage32_CreateStream
,
1432 IStorage32_OpenStream
,
1445 /******************************************************************************
1446 * Storage API functions
1449 OLESTATUS WINAPI
StgCreateDocFile16(
1450 LPCOLESTR16 pwcsName
,DWORD grfMode
,DWORD reserved
,IStorage16
**ppstgOpen
1455 struct storage_pps_entry stde
;
1457 fprintf(stderr
,"StgCreateDocfile(%s,0x%08lx,0x%08lx,%p)\n",
1458 pwcsName
,grfMode
,reserved
,ppstgOpen
1460 _create_istorage16(ppstgOpen
);
1461 hf
= CreateFile32A(pwcsName
,GENERIC_READ
|GENERIC_WRITE
,0,NULL
,CREATE_NEW
,0,0);
1462 if (hf
==INVALID_HANDLE_VALUE32
) {
1463 fprintf(stderr
,"couldn't open file for storage:%ld\n",GetLastError());
1466 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstgOpen
);
1468 /* FIXME: check for existance before overwriting? */
1469 if (!STORAGE_init_storage(hf
)) {
1474 while (!ret
) { /* neither 1 nor <0 */
1475 ret
=STORAGE_get_pps_entry(hf
,i
,&stde
);
1476 if ((ret
==1) && (stde
.pps_type
==5)) {
1484 IStorage16_Release(lpstg
); /* will remove it */
1490 OLESTATUS WINAPI
StgCreateDocFile32(
1491 LPCOLESTR32 pwcsName
,DWORD grfMode
,DWORD reserved
,IStorage32
**ppstgOpen
1493 fprintf(stderr
,"StgCreateDocfile(%p,0x%08lx,0x%08lx,%p)\n",
1494 pwcsName
,grfMode
,reserved
,ppstgOpen
1496 *ppstgOpen
= (IStorage32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStorage32
));
1497 (*ppstgOpen
)->ref
= 1;
1498 (*ppstgOpen
)->lpvtbl
= &stvt32
;
1502 OLESTATUS WINAPI
StgIsStorageFile16(LPCOLESTR16 fn
) {
1507 fprintf(stderr
,"StgIsStorageFile(%s)",fn
);
1508 hf
= OpenFile32(fn
,&ofs
,OF_SHARE_DENY_NONE
);
1509 if (hf
==HFILE_ERROR32
)
1510 return STG_E_FILENOTFOUND
;
1511 if (24!=_lread32(hf
,magic
,24)) {
1512 fprintf(stderr
," too short\n");
1516 if (!memcmp(magic
,STORAGE_magic
,8)) {
1517 fprintf(stderr
," -> YES\n");
1521 if (!memcmp(magic
,STORAGE_notmagic
,8)) {
1522 fprintf(stderr
," -> NO\n");
1526 if (!memcmp(magic
,STORAGE_oldmagic
,8)) {
1527 fprintf(stderr
," -> old format\n");
1529 return STG_E_OLDFORMAT
;
1531 fprintf(stderr
," -> Invalid header.\n");
1533 return STG_E_INVALIDHEADER
;
1536 OLESTATUS WINAPI
StgIsStorageFile32(LPCOLESTR32 fn
) {
1537 LPOLESTR16 xfn
= HEAP_strdupWtoA(GetProcessHeap(),0,fn
);
1538 OLESTATUS ret
= StgIsStorageFile16(xfn
);
1540 HeapFree(GetProcessHeap(),0,xfn
);
1546 OLESTATUS WINAPI
StgOpenStorage16(
1547 const OLECHAR16
* pwcsName
,IStorage16
*pstgPriority
,DWORD grfMode
,
1548 SNB16 snbExclude
,DWORD reserved
, IStorage16
**ppstgOpen
1553 struct storage_pps_entry stde
;
1555 fprintf(stderr
,"StgOpenStorage(%s,%p,0x%08lx,%p,%ld,%p)\n",
1556 pwcsName
,pstgPriority
,grfMode
,snbExclude
,reserved
,ppstgOpen
1558 _create_istorage16(ppstgOpen
);
1559 hf
= CreateFile32A(pwcsName
,GENERIC_READ
,0,NULL
,0,0,0);
1560 if (hf
==INVALID_HANDLE_VALUE32
) {
1561 fprintf(stderr
,"couldn't open file for storage\n");
1564 lpstg
= (LPSTORAGE16
)PTR_SEG_TO_LIN(*ppstgOpen
);
1568 while (!ret
) { /* neither 1 nor <0 */
1569 ret
=STORAGE_get_pps_entry(hf
,i
,&stde
);
1570 if ((ret
==1) && (stde
.pps_type
==5)) {
1577 IStorage16_Release(lpstg
); /* will remove it */
1584 OLESTATUS WINAPI
StgOpenStorage32(
1585 const OLECHAR32
* pwcsName
,IStorage32
*pstgPriority
,DWORD grfMode
,
1586 SNB32 snbExclude
,DWORD reserved
, IStorage32
**ppstgOpen
1588 fprintf(stderr
,"StgOpenStorage32(%p,%p,0x%08lx,%p,%ld,%p),stub!\n",
1589 pwcsName
,pstgPriority
,grfMode
,snbExclude
,reserved
,ppstgOpen
1591 *ppstgOpen
= (IStorage32
*)HeapAlloc(GetProcessHeap(),0,sizeof(IStorage32
));
1592 (*ppstgOpen
)->ref
= 1;
1593 (*ppstgOpen
)->lpvtbl
= &stvt32
;