summaryrefslogtreecommitdiffstats
path: root/private/ole32/stg/msf/pbstream.cxx
blob: c50ded3a4767c42a7f8ab4ca40736ecab33505bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1992.
//
//  File:       pbstream.cxx
//
//  Contents:   CPubStream code
//
//  Classes:
//
//  Functions:
//
//  History:    16-Jan-92   PhilipLa    Created.
//              12-Jun-96   MikeHill    Renamed FlushNoException to Write,
//                                      and removed the Commit.
//              21-Jun-96   MikeHill    Fixed an Assert.
//              01-Jul-96   MikeHill    - Removed Win32 SEH from PropSet code.
//                                      - Added propset byte-swapping support.
//              08-Nov-96   MikeHill    Don't call RtlOnMappedStreamEvent unnecessarily.
//
//--------------------------------------------------------------------------

#include "msfhead.cxx"

#pragma hdrstop

#include <sstream.hxx>
#include <publicdf.hxx>
#include <pbstream.hxx>
#ifndef REF
#include <tstream.hxx>
#endif //!REF
#include <docfilep.hxx>
#include <reserved.hxx>
#include <propdbg.hxx>

//+---------------------------------------------------------------------------
//
//  Member:     CPubStream::CPubStream, public
//
//  Synopsis:   Constructor
//
//  History:    16-Jan-92       PhilipLa        Created
//
//----------------------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_CPubStream)
#endif


CPubStream::CPubStream(CPubDocFile *ppdf,
                       DFLAGS df,
                       CDfName const *pdfn)
#ifdef NEWPROPS
#pragma warning(disable: 4355)
    : _PubMappedStream(this)
#pragma warning(default: 4355)
#endif
{
    _psParent = NULL;
    _df = df;
    _ppdfParent = P_TO_BP(CBasedPubDocFilePtr, ppdf);
    _cReferences = 1;
    _dfn.Set(pdfn->GetLength(), pdfn->GetBuffer());
    _ppdfParent->AddChild(this);
    _fDirty = FALSE;
}


//+---------------------------------------------------------------------------
//
//  Member:     CPubStream::Init, public
//
//  Synopsis:   Init function
//
//  Arguments:  [psParent] - Stream in transaction set
//              [dlLUID] - LUID
//
//  History:    16-Jan-92       PhilipLa        Created
//
//----------------------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_Init)
#endif

void CPubStream::Init(PSStream *psParent,
                      DFLUID dlLUID)
{
    _psParent = P_TO_BP(CBasedSStreamPtr, psParent);
    _luid = dlLUID;
}

//+---------------------------------------------------------------------------
//
//  Member:     CPubStream::~CPubStream, public
//
//  Synopsis:   Destructor
//
//  History:    16-Jan-92       PhilipLa        Created
//
//----------------------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_1CPubStream)
#endif

CPubStream::~CPubStream()
{
    msfAssert(_cReferences == 0);

    if (SUCCEEDED(CheckReverted()))
    {
        if (_ppdfParent != NULL)
            _ppdfParent->ReleaseChild(this);
        if (_psParent)
        {
            _psParent->Release();
        }
    }
}


//+-------------------------------------------------------------------------
//
//  Method:     CPubStream::Release, public
//
//  Synopsis:   Release a pubstream object
//
//  Arguments:  None.
//
//  Returns:    S_OK if call completed OK.
//
//  Algorithm:  Delete 'this' - all real work done by destructor.
//
//  History:    24-Jan-92   PhilipLa    Created.
//
//  Notes:
//
//--------------------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_vRelease) // Pubst_Release_TEXT
#endif

void CPubStream::vRelease(VOID)
{
    LONG lRet;
    
    msfDebugOut((DEB_ITRACE,"In CPubStream::Release()\n"));
    msfAssert(_cReferences > 0);
    lRet = InterlockedDecrement(&_cReferences);

#ifndef REF
    msfAssert(!P_TRANSACTED(_df));
#endif //!REF

    if (lRet == 0)
    {
#ifdef NEWPROPS
        _PubMappedStream.Cleanup();
#endif                
        delete this;
    }
    msfDebugOut((DEB_ITRACE,"Out CPubStream::Release()\n"));
}

//+--------------------------------------------------------------
//
//  Member:     CPubStream::Stat, public
//
//  Synopsis:   Fills in a stat buffer
//
//  Arguments:  [pstatstg] - Buffer
//              [grfStatFlag] - stat flags
//
//  Returns:    S_OK or error code
//
//  Modifies:   [pstatstg]
//
//  History:    24-Mar-92       DrewB   Created
//
//---------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_Stat) // Stat_TEXT
#endif

SCODE CPubStream::Stat(STATSTGW *pstatstg, DWORD grfStatFlag)
{
    SCODE sc = S_OK;

    msfDebugOut((DEB_ITRACE, "In  CPubStream::Stat(%p)\n", pstatstg));
    msfChk(CheckReverted());

    msfAssert(_ppdfParent != NULL);
    pstatstg->grfMode = DFlagsToMode(_df);

    pstatstg->clsid = CLSID_NULL;
    pstatstg->grfStateBits = 0;

    pstatstg->pwcsName = NULL;
    if ((grfStatFlag & STATFLAG_NONAME) == 0)
    {
        msfMem(pstatstg->pwcsName = (WCHAR *)TaskMemAlloc(_dfn.GetLength()));
        memcpy(pstatstg->pwcsName, _dfn.GetBuffer(), _dfn.GetLength());
    }

    ULONG cbSize;
    _psParent->GetSize(&cbSize);
    ULISet32(pstatstg->cbSize, cbSize);
    msfDebugOut((DEB_ITRACE, "Out CPubStream::Stat\n"));

Err:
    return sc;
}

//+--------------------------------------------------------------
//
//  Member:     CPubStream::RevertFromAbove, public
//
//  Synopsis:   Parent has asked for reversion
//
//  History:    29-Jan-92       DrewB   Created
//
//---------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_RevertFromAbove) // Pubdf_Revert_TEXT
#endif

void CPubStream::RevertFromAbove(void)
{
    msfDebugOut((DEB_ITRACE, "In  CPubStream::RevertFromAbove:%p()\n", this));
    _df |= DF_REVERTED;
    _psParent->Release();
#if DBG == 1
    _psParent = NULL;
#endif
    msfDebugOut((DEB_ITRACE, "Out CPubStream::RevertFromAbove\n"));
}

//+--------------------------------------------------------------
//
//  Member:         CPubStream::FlushBufferedData, public
//
//  Synopsis:   Flush out the property buffers.
//
//  History:    5-May-1995      BillMo Created
//
//---------------------------------------------------------------

#ifdef NEWPROPS
#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_RevertFromAbove) // Pubdf_Revert_TEXT
#endif

SCODE CPubStream::FlushBufferedData(int recursionlevel)
{
    SCODE sc = S_OK;

    msfDebugOut((DEB_ITRACE, "In  CPubStream::FlushBufferedData:%p()\n", this));

    _PubMappedStream.Flush(&sc);

    msfDebugOut((DEB_ITRACE, "Out CPubStream::FlushBufferedData\n"));

    PropDbg((DEB_PROP_MAP, "CPubStream(%08X):FlushBufferedData returns %08X\n",
        this, sc));

    return sc;
}
#endif

//+---------------------------------------------------------------------------
//
//  Member:     CPubStream::Commit, public
//
//  Synopsis:   Flush stream changes to disk in the direct case.
//
//  Arguments:  None
//
//  Returns:    Appropriate status code
//
//  History:    12-Jan-93       PhilipLa        Created
//
//----------------------------------------------------------------------------

#ifdef CODESEGMENTS
#pragma code_seg(SEG_CPubStream_Commit) // Pubdf_Commit_TEXT
#endif

SCODE CPubStream::Commit(DWORD dwFlags)
{
    SCODE sc = S_OK;
    msfDebugOut((DEB_ITRACE, "In  CPubStream::Commit:%p()\n", this));

#ifndef REF
    msfAssert(!P_TRANSACTED(_df));
#endif //!REF
    if (SUCCEEDED(sc = CheckReverted()))
    {
        if (P_WRITE(_df))
        {
#ifndef REF
            if (_ppdfParent->GetTransactedDepth() == 0)
            {
                //Parent is direct, so call commit on it and return.
#endif //!REF
                sc = _ppdfParent->GetBaseMS()->Flush(FLUSH_CACHE(dwFlags));
#ifndef REF
            }
#endif //!REF
            SetClean();
        }
    }
    msfDebugOut((DEB_ITRACE, "Out CPubStream::Commit\n"));
    return sc;
}

#ifdef NEWPROPS
//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Open
//
//  Synopsis:   Opens mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Gets the size of the underlying stream and reads it
//              into memory so that it can be "mapped." 
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Open(IN VOID *powner, OUT LONG *phr)
{
    *phr = S_OK;
    olAssert(!_fLowMem);

    // If given a pointer to the owner of this mapped stream,
    // save it.  This could be NULL (i.e., when called from
    // ReOpen).

    if( NULL != powner  )
        _powner = P_TO_BP( CBasedBytePtr, ((BYTE*) powner) );

    if (_pb == NULL)
    {
        VOID *pv;

        _cbUsed = 0;

        *phr = _pst->GetSize(&_cbOriginalStreamSize);
        if (*phr != S_OK)
            goto Throw;

        if (_cbOriginalStreamSize > CBMAXPROPSETSTREAM)
        {
            *phr = STG_E_INVALIDHEADER;
            goto Throw;
        }

        _cbUsed = _cbOriginalStreamSize;

        pv = GetMalloc()->Alloc(_cbOriginalStreamSize);

        if (pv == NULL)
        {
            pv = g_ReservedMemory.LockMemory();   // could wait until previous
                                               // property call completes
            _fLowMem = TRUE;
        }
        _pb = P_TO_BP(CBasedBytePtr, ((BYTE*)pv));
        *phr = _pst->ReadAt(0, 
                      pv, 
                      _cbOriginalStreamSize, 
                      &_cbUsed);

#ifdef _MAC
        // Notify our owner that we've read in new data.
        if (*phr == S_OK && _powner != NULL && 0 != _cbUsed)
        {
            *phr = RtlOnMappedStreamEvent( BP_TO_P(VOID*, _powner), pv, _cbUsed );
        }
#endif

        if (*phr != S_OK)
        {
            if (_fLowMem)
                g_ReservedMemory.UnlockMemory();
            else
                GetMalloc()->Free(pv);

            _pb = NULL;
            _cbUsed = 0;
            _fLowMem = FALSE;
            goto Throw;
        }

    }

    PropDbg((DEB_PROP_MAP, "CPubStream(%08X):Open returns normally\n", this));
    return;

Throw:

    PropDbg((DEB_PROP_MAP, "CPubStream(%08X):Open exception returns %08X\n", this, *phr));

    return;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Flush
//
//  Synopsis:   Flush the mapped Stream to the underlying Stream,
//              and Commit that Stream.
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Flush(OUT LONG *phr)
{
    // Write out any data we have cached to the Stream.
    *phr = Write();

    // Commite the Stream.
    if( S_OK == *phr )
    {
        *phr = _pst->Commit(STGC_DEFAULT);
    }

    return;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Close
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Does nothing because the object may be mapped in
//              another process.
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Close(OUT LONG *phr)
{
    // Write the changes.  We don't need to Commit them,
    // they will be implicitely committed when the 
    // Stream is Released.

    *phr = Write();

    if( FAILED(*phr) )
    {
        PropDbg((DEB_PROP_MAP, "CPubStream(%08X)::Close exception returns %08X\n", this, *phr));
    }

    return;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::ReOpen
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Combined open and map.
//
//--------------------------------------------------------------------

VOID CPubMappedStream::ReOpen(IN OUT VOID **ppv, OUT LONG *phr)
{
    *ppv = NULL;

    Open(NULL,  // Unspecified owner.
         phr);

    if( SUCCEEDED(*phr) )
        *ppv = BP_TO_P(VOID*, _pb); 

    return;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Quiesce
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Meaningless for docfile mapped stream.
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Quiesce(VOID)
{
    olAssert(_pb != NULL); 
    DfpdbgCheckUnusedMemory();
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Map
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Return the address of the "mapping" buffer.
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Map(BOOLEAN fCreate, VOID **ppv) 
{ 
    olAssert(_pb != NULL); 
    DfpdbgCheckUnusedMemory();
    *ppv = BP_TO_P(VOID*, _pb); 
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Unmap
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:      Unmapping is merely zeroing the pointer.  We don't
//              flush because that's done explicitly by the 
//              CPropertyStorage class.
//              
//
//--------------------------------------------------------------------

VOID CPubMappedStream::Unmap(BOOLEAN fFlush, VOID **pv)
{
    DfpdbgCheckUnusedMemory();
    *pv = NULL;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Write
//
//  Synopsis:   Writes a mapped view of an exposed Stream to the
//              underlying Stream.  Used by RtlCreatePropertySet et al.
//
//  Notes:      The Stream is not commited.  To commit the Stream, in
//              addition to writing it, the Flush method should be used.
//              The Commit is omitted so that it can be skipped in
//              the Property Set Close path, thus eliminating a
//              performance penalty.
//
//--------------------------------------------------------------------

HRESULT CPubMappedStream::Write ()
{
    HRESULT hr;
    ULONG cbWritten;

    if (!_fDirty)
    {
        PropDbg((DEB_PROP_MAP, "CPubStream(%08X):Flush returns with not-dirty\n", this));

        return S_OK;     // flushing a stream which isn't a property stream
                         // this could be optimized by propagating a 'no property streams'
                         // flag up the storage hierachy such that FlushBufferedData is
                         // not even called for non-property streams.
    }

    olAssert( _pst != NULL );
    olAssert( _pb != NULL );
    olAssert( _powner != NULL );

#ifdef _MAC
    // Notify our owner that we're about to perform a Write.
    hr = RtlOnMappedStreamEvent( BP_TO_P(VOID*, _powner), BP_TO_P(VOID *, _pb), _cbUsed );
    if( S_OK != hr ) goto Exit;
#endif

    hr = _pst->WriteAt(0, BP_TO_P(VOID *, _pb), _cbUsed, &cbWritten);
    if( S_OK != hr ) goto Exit;

#ifdef _MAC
    // Notify our owner that we're done with the Write.
    hr = RtlOnMappedStreamEvent( BP_TO_P(VOID*, _powner), BP_TO_P(VOID *, _pb), _cbUsed );
    if( S_OK != hr ) goto Exit;
#endif

    if (_cbUsed < _cbOriginalStreamSize)
    {
        // if the stream is shrinking, this is a good time to do it.
        hr = _pst->SetSize(_cbUsed);
        if( S_OK != hr ) goto Exit;
    }

    //  ----
    //  Exit
    //  ----

Exit:

    if (hr == S_OK || hr == STG_E_REVERTED)
    {
        _fDirty = FALSE;
    }

    PropDbg((DEB_PROP_MAP, "CPubStream(%08X):Flush %s returns hr=%08X\n",
        this, hr != S_OK ? "exception" : "", hr));

    return hr;

}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::GetSize
//
//  Synopsis:   Returns size of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//--------------------------------------------------------------------

ULONG CPubMappedStream::GetSize(OUT LONG *phr)
{
    *phr = S_OK;

    if (_pb == NULL)
        Open(NULL,  // Unspecified owner
             phr);

    if( SUCCEEDED(*phr) )
    {
        olAssert(_pb != NULL); 
        DfpdbgCheckUnusedMemory();
    }
    
    return _cbUsed;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::SetSize
//
//  Synopsis:   Sets size of "map." Called by 
//              NtCreatePropertySet et al.
//
//  Arguments:  [cb] -- requested size.
//		[fPersistent] -- FALSE if expanding in-memory read-only image
//              [ppv] -- new mapped address.
//
//  Signals:    Not enough disk space.
//
//  Notes:      In a low memory situation we may not be able to
//              get the requested amount of memory.  In this
//              case we must fall back on disk storage as the
//              actual map.
//
//--------------------------------------------------------------------

VOID
CPubMappedStream::SetSize(ULONG cb, IN BOOLEAN fPersistent, VOID **ppv, OUT LONG *phr)
{
    VOID *pv;

    *phr = S_OK;
    olAssert(cb != 0);    
    
    DfpdbgCheckUnusedMemory();

    //
    // if we are growing the data, we should grow the stream
    //

    if (fPersistent && cb > _cbUsed)
    {
        *phr = _pst->SetSize(cb);
        if (*phr != S_OK)
            goto Throw;
    }
    
    if (!_fLowMem)
    {
        pv = GetMalloc()->Realloc(BP_TO_P(VOID*, _pb), cb);
        
        if (pv == NULL)
        {
            // allocation failed: we need to try using a backup mechanism for
            // more memory.
            // copy the data to the global reserved chunk... we will wait until
            // someone else has released it.  it will be released on the way out
            // of the property code.

            _fLowMem = TRUE;
            pv = g_ReservedMemory.LockMemory();
            if (NULL != BP_TO_P(BYTE*, _pb))
	    {
                memcpy(pv, BP_TO_P(VOID*, _pb), _cbUsed);
	    }
            GetMalloc()->Free(BP_TO_P(VOID*, _pb));
        }
	_pb = P_TO_BP(CBasedBytePtr, ((BYTE*)pv));
	*ppv = pv;
    }
    else
    {
        *ppv = BP_TO_P(VOID*, _pb);
    }       
            
    _cbUsed = cb;
    DfpdbgFillUnusedMemory();

Throw:

    PropDbg((DEB_PROP_MAP, "CPubStream(%08X):SetSize %s returns hr=%08X\n",
        this, *phr != S_OK ? "exception" : "", *phr));

}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Lock
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//              the exposed stream has enforced the locking.
//
//              we use the lock to indicate whether the object is
//              dirty
//
//--------------------------------------------------------------------

NTSTATUS CPubMappedStream::Lock(BOOLEAN fExclusive)
{
    return(STATUS_SUCCESS);
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::Unlock
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

NTSTATUS CPubMappedStream::Unlock(VOID)
{
    // if at the end of the properties set/get call we have the low
    // memory region locked, we flush to disk.
    HRESULT hr = S_OK;

    if (_fLowMem)
    {
        Flush(&hr);

        g_ReservedMemory.UnlockMemory();
        _pb = NULL;
        _cbUsed = 0;
        _fLowMem = FALSE;
        PropDbg((DEB_PROP_MAP, "CPubStream(%08X):Unlock low-mem returns NTSTATUS=%08X\n",
            this, hr));
    }

    return(hr);
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::QueryTimeStamps
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

VOID CPubMappedStream::QueryTimeStamps(STATPROPSETSTG *pspss, BOOLEAN fNonSimple) const
{
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::QueryModifyTime
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

BOOLEAN CPubMappedStream::QueryModifyTime(OUT LONGLONG *pll) const
{
    return(FALSE);
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::QuerySecurity
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

BOOLEAN CPubMappedStream::QuerySecurity(OUT ULONG *pul) const
{
    return(FALSE);
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::QueryTimeStamps
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

BOOLEAN CPubMappedStream::IsWriteable() const
{
    return TRUE;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::SetChangePending
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

#if DBGPROP
BOOLEAN CPubMappedStream::SetChangePending(BOOLEAN f)
{
    BOOL fOld = _fChangePending;
    _fChangePending = f;
    return(_fChangePending);
}
#endif

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::IsNtMappedStream
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

#if DBGPROP
BOOLEAN CPubMappedStream::IsNtMappedStream(VOID) const
{
    return(FALSE);
}
#endif


//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::GetHandle
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

HANDLE CPubMappedStream::GetHandle(VOID) const
{
    return(INVALID_HANDLE_VALUE);
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::SetModified
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

VOID CPubMappedStream::SetModified(VOID)
{
    _fDirty = TRUE;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::IsModified
//
//  Synopsis:   Operates on mapped view of exposed stream. Called by 
//              NtCreatePropertySet et al.
//
//  Notes:
//
//--------------------------------------------------------------------

BOOLEAN CPubMappedStream::IsModified(VOID) const
{
    return _fDirty;
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::DfpdbgFillUnusedMemory
//
//--------------------------------------------------------------------

#if DBG
VOID CPubMappedStream::DfpdbgFillUnusedMemory(VOID)
{

    if (_pb == NULL)
        return;

    BYTE * pbEndPlusOne = BP_TO_P(BYTE*, _pb) + BytesCommitted();

    for (BYTE *pbUnused = BP_TO_P(BYTE*, _pb) + _cbUsed;
         pbUnused < pbEndPlusOne;
         pbUnused++)
    {
        *pbUnused = (BYTE)(DWORD)pbUnused;
    }
}

//+-------------------------------------------------------------------
//
//  Member:     CPubMappedStream::DfpdbgCheckUnusedMemory
//
//--------------------------------------------------------------------

VOID CPubMappedStream::DfpdbgCheckUnusedMemory(VOID)
{

    if (_pb == NULL)
        return;

    if (_cbUsed == 0)
        return;

    BYTE * pbEndPlusOne = BP_TO_P(BYTE*, _pb) + BytesCommitted();

    for (BYTE *pbUnused = BP_TO_P(BYTE*, _pb + _cbUsed) ;
         pbUnused < pbEndPlusOne;
         pbUnused ++)
    {
        olAssert(*pbUnused == (BYTE)(DWORD)pbUnused);
    }
}

#endif    // DBG
#endif