LibreOffice Module sot (master) 1
stgstrms.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <algorithm>
21
22#include <string.h>
23#include <sal/log.hxx>
24#include <o3tl/safeint.hxx>
25#include <osl/file.hxx>
26#include <unotools/tempfile.hxx>
27
28#include "stgelem.hxx"
29#include "stgcache.hxx"
30#include "stgstrms.hxx"
31#include "stgdir.hxx"
32#include "stgio.hxx"
33#include <memory>
34
36
37// The FAT class performs FAT operations on an underlying storage stream.
38// This stream is either the master FAT stream (m == true ) or a normal
39// storage stream, which then holds the FAT for small data allocations.
40
41StgFAT::StgFAT( StgStrm& r, bool m ) : m_rStrm( r )
42{
43 m_bPhys = m;
46 m_nOffset = 0;
47 m_nMaxPage = 0;
48 m_nLimit = 0;
49}
50
51// Retrieve the physical page for a given byte offset.
52
54{
56 // Position within the underlying stream
57 // use the Pos2Page() method of the stream
58 if( m_rStrm.Pos2Page( nByteOff ) )
59 {
61 sal_Int32 nPhysPage = m_rStrm.GetPage();
62 // get the physical page (must be present)
63 pPg = m_rStrm.GetIo().Get( nPhysPage, true );
64 }
65 return pPg;
66}
67
68// Get the follow page for a certain FAT page.
69
70sal_Int32 StgFAT::GetNextPage( sal_Int32 nPg )
71{
72 if (nPg >= 0)
73 {
74 if (nPg > (SAL_MAX_INT32 >> 2))
75 return STG_EOF;
76 rtl::Reference< StgPage > pPg = GetPhysPage( nPg << 2 );
77 nPg = pPg.is() ? StgCache::GetFromPage( pPg, m_nOffset >> 2 ) : STG_EOF;
78 }
79 return nPg;
80}
81
82// Find the best fit block for the given size. Return
83// the starting block and its size or STG_EOF and 0.
84// nLastPage is a stopper which tells the current
85// underlying stream size. It is treated as a recommendation
86// to abort the search to inhibit excessive file growth.
87
88sal_Int32 StgFAT::FindBlock( sal_Int32& nPgs )
89{
90 sal_Int32 nMinStart = STG_EOF, nMinLen = 0;
91 sal_Int32 nMaxStart = STG_EOF, nMaxLen = 0x7FFFFFFFL;
92 sal_Int32 nTmpStart = STG_EOF, nTmpLen = 0;
93 sal_Int32 nPages = m_rStrm.GetSize() >> 2;
94 bool bFound = false;
96 short nEntry = 0;
97 for( sal_Int32 i = 0; i < nPages; i++, nEntry++ )
98 {
99 if( !( nEntry % m_nEntries ) )
100 {
101 // load the next page for that stream
102 nEntry = 0;
103 pPg = GetPhysPage( i << 2 );
104 if( !pPg.is() )
105 return STG_EOF;
106 }
107 sal_Int32 nCur = StgCache::GetFromPage( pPg, nEntry );
108 if( nCur == STG_FREE )
109 {
110 // count the size of this area
111 if( nTmpLen )
112 nTmpLen++;
113 else
114 {
115 nTmpStart = i;
116 nTmpLen = 1;
117 }
118 if( nTmpLen == nPgs
119 // If we already did find a block, stop when reaching the limit
120 || ( bFound && ( nEntry >= m_nLimit ) ) )
121 break;
122 }
123 else if( nTmpLen )
124 {
125 if( nTmpLen > nPgs && nTmpLen < nMaxLen )
126 {
127 // block > requested size
128 nMaxLen = nTmpLen;
129 nMaxStart = nTmpStart;
130 bFound = true;
131 }
132 else if( nTmpLen >= nMinLen )
133 {
134 // block < requested size
135 nMinLen = nTmpLen;
136 nMinStart = nTmpStart;
137 bFound = true;
138 if( nTmpLen == nPgs )
139 break;
140 }
141 nTmpStart = STG_EOF;
142 nTmpLen = 0;
143 }
144 }
145 // Determine which block to use.
146 if( nTmpLen )
147 {
148 if( nTmpLen > nPgs && nTmpLen < nMaxLen )
149 {
150 // block > requested size
151 nMaxLen = nTmpLen;
152 nMaxStart = nTmpStart;
153 }
154 else if( nTmpLen >= nMinLen )
155 {
156 // block < requested size
157 nMinLen = nTmpLen;
158 nMinStart = nTmpStart;
159 }
160 }
161 if( nMinStart != STG_EOF && nMaxStart != STG_EOF )
162 {
163 // two areas found; return the best fit area
164 sal_Int32 nMinDiff = nPgs - nMinLen;
165 sal_Int32 nMaxDiff = nMaxLen - nPgs;
166 if( nMinDiff > nMaxDiff )
167 nMinStart = STG_EOF;
168 }
169 if( nMinStart != STG_EOF )
170 {
171 nPgs = nMinLen; return nMinStart;
172 }
173 else
174 {
175 return nMaxStart;
176 }
177}
178
179// Set up the consecutive chain for a given block.
180
181bool StgFAT::MakeChain( sal_Int32 nStart, sal_Int32 nPgs )
182{
183 sal_Int32 nPos = nStart << 2;
185 if( !pPg.is() || !nPgs )
186 return false;
187 while( --nPgs )
188 {
189 if( m_nOffset >= m_nPageSize )
190 {
191 pPg = GetPhysPage( nPos );
192 if( !pPg.is() )
193 return false;
194 }
195 m_rStrm.GetIo().SetToPage( pPg, m_nOffset >> 2, ++nStart );
196 m_nOffset += 4;
197 nPos += 4;
198 }
199 if( m_nOffset >= m_nPageSize )
200 {
201 pPg = GetPhysPage( nPos );
202 if( !pPg.is() )
203 return false;
204 }
205 m_rStrm.GetIo().SetToPage( pPg, m_nOffset >> 2, STG_EOF );
206 return true;
207}
208
209// Allocate a block of data from the given page number on.
210// It the page number is != STG_EOF, chain the block.
211
212sal_Int32 StgFAT::AllocPages( sal_Int32 nBgn, sal_Int32 nPgs )
213{
214 sal_Int32 nOrig = nBgn;
215 sal_Int32 nLast = nBgn;
216 sal_Int32 nBegin = STG_EOF;
217 sal_Int32 nAlloc;
218 sal_Int32 nPages = m_rStrm.GetSize() >> 2;
219 short nPasses = 0;
220 // allow for two passes
221 while( nPasses < 2 )
222 {
223 // try to satisfy the request from the pool of free pages
224 while( nPgs )
225 {
226 nAlloc = nPgs;
227 nBegin = FindBlock( nAlloc );
228 // no more blocks left in present alloc chain
229 if( nBegin == STG_EOF )
230 break;
231 if( ( nBegin + nAlloc ) > m_nMaxPage )
232 m_nMaxPage = nBegin + nAlloc;
233 if( !MakeChain( nBegin, nAlloc ) )
234 return STG_EOF;
235 if( nOrig == STG_EOF )
236 nOrig = nBegin;
237 else
238 {
239 // Patch the chain
240 rtl::Reference< StgPage > pPg = GetPhysPage( nLast << 2 );
241 if( !pPg.is() )
242 return STG_EOF;
243 m_rStrm.GetIo().SetToPage( pPg, m_nOffset >> 2, nBegin );
244 }
245 nLast = nBegin + nAlloc - 1;
246 nPgs -= nAlloc;
247 }
248 if( nPgs && !nPasses )
249 {
250 // we need new, fresh space, so allocate and retry
251 if( !m_rStrm.SetSize( ( nPages + nPgs ) << 2 ) )
252 return STG_EOF;
253 if( !m_bPhys && !InitNew( nPages ) )
254 return 0;
255 // FIXME: this was originally "FALSE", whether or not that
256 // makes sense (or should be STG_EOF instead, say?)
257 nPages = m_rStrm.GetSize() >> 2;
258 nPasses++;
259 }
260 else
261 break;
262 }
263 // now we should have a chain for the complete block
264 if( nBegin == STG_EOF || nPgs )
265 {
267 return STG_EOF; // bad structure
268 }
269 return nOrig;
270}
271
272// Initialize newly allocated pages for a standard FAT stream
273// It can be assumed that the stream size is always on
274// a page boundary
275
276bool StgFAT::InitNew( sal_Int32 nPage1 )
277{
278 sal_Int32 n = ( ( m_rStrm.GetSize() >> 2 ) - nPage1 ) / m_nEntries;
279 if ( n > 0 )
280 {
281 while( n-- )
282 {
284 // Position within the underlying stream
285 // use the Pos2Page() method of the stream
286 m_rStrm.Pos2Page( nPage1 << 2 );
287 // Initialize the page
288 pPg = m_rStrm.GetIo().Copy( m_rStrm.GetPage() );
289 if ( !pPg.is() )
290 return false;
291 for( short i = 0; i < m_nEntries; i++ )
292 m_rStrm.GetIo().SetToPage( pPg, i, STG_FREE );
293 nPage1++;
294 }
295 }
296 return true;
297}
298
299// Release a chain
300
301bool StgFAT::FreePages( sal_Int32 nStart, bool bAll )
302{
303 while( nStart >= 0 )
304 {
305 rtl::Reference< StgPage > pPg = GetPhysPage( nStart << 2 );
306 if( !pPg.is() )
307 return false;
308 nStart = StgCache::GetFromPage( pPg, m_nOffset >> 2 );
309 // The first released page is either set to EOF or FREE
310 m_rStrm.GetIo().SetToPage( pPg, m_nOffset >> 2, bAll ? STG_FREE : STG_EOF );
311 bAll = true;
312 }
313 return true;
314}
315
317
318// The base stream class provides basic functionality for seeking
319// and accessing the data on a physical basis. It uses the built-in
320// FAT class for the page allocations.
321
323 : m_nPos(0),
324 m_bBytePosValid(true),
325 m_rIo(r),
326 m_pEntry(nullptr),
327 m_nStart(STG_EOF),
328 m_nSize(0),
329 m_nPage(STG_EOF),
330 m_nOffset(0),
331 m_nPageSize(m_rIo.GetPhysPageSize())
332{
333}
334
336{
337}
338
339// Attach the stream to the given entry.
340
342{
345 m_pEntry = &r;
346 r.SetDirty();
347}
348
349/*
350 * The page chain, is basically a singly linked list of slots each
351 * point to the next page. Instead of traversing the file structure
352 * for this each time build a simple flat in-memory vector list
353 * of pages.
354 */
356{
357 if (m_nSize > 0)
358 {
361 }
362
363 bool bError = false;
364 sal_Int32 nBgn = m_nStart;
365 sal_Int32 nOptSize = 0;
366
367 // Track already scanned PageNumbers here and use them to
368 // see if an already counted page is re-visited
369 while( nBgn >= 0 && !bError )
370 {
371 m_aPagesCache.push_back(nBgn);
372 nBgn = m_pFat->GetNextPage( nBgn );
373
374 //returned second is false if it already exists
375 if (!m_aUsedPageNumbers.insert(nBgn).second)
376 {
377 SAL_WARN ("sot", "Error: page number " << nBgn << " already in chain for stream");
378 bError = true;
379 }
380
381 nOptSize += m_nPageSize;
382 }
383 if (bError)
384 {
385 SAL_WARN("sot", "returning wrong format error");
387 m_aPagesCache.clear();
389 }
390 return nOptSize;
391}
392
393// Compute page number and offset for the given byte position.
394// If the position is behind the size, set the stream right
395// behind the EOF.
396bool StgStrm::Pos2Page( sal_Int32 nBytePos )
397{
398 if ( !m_pFat )
399 return false;
400
401 // Values < 0 seek to the end
402 if( nBytePos < 0 || nBytePos >= m_nSize )
403 nBytePos = m_nSize;
404 // Adjust the position back to offset 0
405 m_nPos -= m_nOffset;
406 sal_Int32 nMask = ~( m_nPageSize - 1 );
407 sal_Int32 nOld = m_nPos & nMask;
408 sal_Int32 nNew = nBytePos & nMask;
409 m_nOffset = static_cast<short>( nBytePos & ~nMask );
410 m_nPos = nBytePos;
411 if (nOld == nNew)
412 return m_bBytePosValid;
413
414 // See fdo#47644 for a .doc with a vast amount of pages where seeking around the
415 // document takes a colossal amount of time
416
417 // Please Note: we build the pagescache incrementally as we go if necessary,
418 // so that a corrupted FAT doesn't poison the stream state for earlier reads
419 size_t nIdx = nNew / m_nPageSize;
420 if( nIdx >= m_aPagesCache.size() )
421 {
422 // Extend the FAT cache ! ...
423 size_t nToAdd = nIdx + 1;
424
425 if (m_aPagesCache.empty())
426 {
427 m_aPagesCache.push_back( m_nStart );
428 assert(m_aUsedPageNumbers.empty());
430 }
431
432 nToAdd -= m_aPagesCache.size();
433
434 sal_Int32 nBgn = m_aPagesCache.back();
435
436 // Start adding pages while we can
437 while (nToAdd > 0 && nBgn >= 0)
438 {
439 sal_Int32 nOldBgn = nBgn;
440 nBgn = m_pFat->GetNextPage(nOldBgn);
441 if( nBgn >= 0 )
442 {
443 //returned second is false if it already exists
444 if (!m_aUsedPageNumbers.insert(nBgn).second)
445 {
446 SAL_WARN ("sot", "Error: page number " << nBgn << " already in chain for stream");
447 break;
448 }
449
450 //very much the normal case
451 m_aPagesCache.push_back(nBgn);
452 --nToAdd;
453 }
454 }
455 }
456
457 if ( nIdx > m_aPagesCache.size() )
458 {
459 SAL_WARN("sot", "seek to index " << nIdx <<
460 " beyond page cache size " << m_aPagesCache.size());
461 // fdo#84229 - handle seek to end and back as eg. XclImpStream expects
463 m_nOffset = 0;
464 // Intriguingly in the past we didn't reset nPos to match the real
465 // length of the stream thus:
466 // nIdx = m_aPagesCache.size();
467 // nPos = nPageSize * nIdx;
468 // so retain this behavior for now.
469 m_bBytePosValid = false;
470 return false;
471 }
472
473 // special case: seek to 1st byte of new, unallocated page
474 // (in case the file size is a multiple of the page size)
475 if( nBytePos == m_nSize && !m_nOffset && nIdx > 0 && nIdx == m_aPagesCache.size() )
476 {
477 nIdx--;
479 }
480 else if ( nIdx == m_aPagesCache.size() )
481 {
483 m_bBytePosValid = false;
484 return false;
485 }
486
487 m_nPage = m_aPagesCache[ nIdx ];
488
490 return m_bBytePosValid;
491}
492
493// Copy an entire stream. Both streams are allocated in the FAT.
494// The target stream is this stream.
495
496bool StgStrm::Copy( sal_Int32 nFrom, sal_Int32 nBytes )
497{
498 if ( !m_pFat )
499 return false;
500
501 m_aPagesCache.clear();
503
504 sal_Int32 nTo = m_nStart;
505 sal_Int32 nPgs = ( nBytes + m_nPageSize - 1 ) / m_nPageSize;
506 while( nPgs-- )
507 {
508 if( nTo < 0 )
509 {
511 return false;
512 }
513 m_rIo.Copy( nTo, nFrom );
514 if( nFrom >= 0 )
515 {
516 nFrom = m_pFat->GetNextPage( nFrom );
517 if( nFrom < 0 )
518 {
520 return false;
521 }
522 }
523 nTo = m_pFat->GetNextPage( nTo );
524 }
525 return true;
526}
527
528bool StgStrm::SetSize( sal_Int32 nBytes )
529{
530 if ( nBytes < 0 || !m_pFat )
531 return false;
532
533 m_aPagesCache.clear();
535
536 // round up to page size
537 sal_Int32 nOld = ( ( m_nSize + m_nPageSize - 1 ) / m_nPageSize ) * m_nPageSize;
538 sal_Int32 nNew = ( ( nBytes + m_nPageSize - 1 ) / m_nPageSize ) * m_nPageSize;
539 if( nNew > nOld )
540 {
541 if( !Pos2Page( m_nSize ) )
542 return false;
543 sal_Int32 nBgn = m_pFat->AllocPages( m_nPage, ( nNew - nOld ) / m_nPageSize );
544 if( nBgn == STG_EOF )
545 return false;
546 if( m_nStart == STG_EOF )
547 m_nStart = m_nPage = nBgn;
548 }
549 else if( nNew < nOld )
550 {
551 bool bAll = ( nBytes == 0 );
552 if( !Pos2Page( nBytes ) || !m_pFat->FreePages( m_nPage, bAll ) )
553 return false;
554 if( bAll )
556 }
557 if( m_pEntry )
558 {
559 // change the dir entry?
560 if( !m_nSize || !nBytes )
562 m_pEntry->m_aEntry.SetSize( nBytes );
564 }
565 m_nSize = nBytes;
566 m_pFat->SetLimit( GetPages() );
567 return true;
568}
569
570// Return the # of allocated pages
571
572
574
575// The FAT stream class provides physical access to the master FAT.
576// Since this access is implemented as a StgStrm, we can use the
577// FAT allocator.
578
579StgFATStrm::StgFATStrm(StgIo& r, sal_Int32 nFatStrmSize) : StgStrm( r )
580{
581 m_pFat.reset( new StgFAT( *this, true ) );
582 m_nSize = nFatStrmSize;
583}
584
585bool StgFATStrm::Pos2Page( sal_Int32 nBytePos )
586{
587 // Values < 0 seek to the end
588 if( nBytePos < 0 || nBytePos >= m_nSize )
589 nBytePos = m_nSize ? m_nSize - 1 : 0;
590 m_nPage = nBytePos / m_nPageSize;
591 m_nOffset = static_cast<short>( nBytePos % m_nPageSize );
592 m_nPage = GetPage(m_nPage, false);
593 bool bValid = m_nPage >= 0;
594 SetPos(nBytePos, bValid);
595 return bValid;
596}
597
598// Get the page number entry for the given page offset.
599
600sal_Int32 StgFATStrm::GetPage(sal_Int32 nOff, bool bMake, sal_uInt16 *pnMasterAlloc)
601{
602 OSL_ENSURE( nOff >= 0, "The offset may not be negative!" );
603 if( pnMasterAlloc ) *pnMasterAlloc = 0;
604 if( nOff < StgHeader::GetFAT1Size() )
605 return m_rIo.m_aHdr.GetFATPage( nOff );
606 sal_Int32 nMaxPage = m_nSize >> 2;
607 nOff = nOff - StgHeader::GetFAT1Size();
608 // number of master pages that we need to iterate through
609 sal_uInt16 nMasterCount = ( m_nPageSize >> 2 ) - 1;
610 sal_uInt16 nBlocks = nOff / nMasterCount;
611 // offset in the last master page
612 nOff = nOff % nMasterCount;
613
616 sal_Int32 nFAT = m_rIo.m_aHdr.GetFATChain();
617 for( sal_uInt16 nCount = 0; nCount <= nBlocks; nCount++ )
618 {
619 if( nFAT == STG_EOF || nFAT == STG_FREE )
620 {
621 if( bMake )
622 {
623 m_aPagesCache.clear();
625
626 // create a new master page
627 nFAT = nMaxPage++;
628 pMaster = m_rIo.Copy( nFAT );
629 if ( pMaster.is() )
630 {
631 for( short k = 0; k < static_cast<short>( m_nPageSize >> 2 ); k++ )
632 m_rIo.SetToPage( pMaster, k, STG_FREE );
633 // chaining
634 if( !pOldPage.is() )
635 m_rIo.m_aHdr.SetFATChain( nFAT );
636 else
637 m_rIo.SetToPage( pOldPage, nMasterCount, nFAT );
638 if( nMaxPage >= m_rIo.GetPhysPages() )
639 if( !m_rIo.SetSize( nMaxPage ) )
640 return STG_EOF;
641 // mark the page as used
642 // make space for Masterpage
643 if( !pnMasterAlloc ) // create space oneself
644 {
645 if( !Pos2Page( nFAT << 2 ) )
646 return STG_EOF;
648 if( !pPg.is() )
649 return STG_EOF;
650 m_rIo.SetToPage( pPg, m_nOffset >> 2, STG_MASTER );
651 }
652 else
653 (*pnMasterAlloc)++;
655 pOldPage = pMaster;
656 }
657 }
658 }
659 else
660 {
661 pMaster = m_rIo.Get( nFAT, true );
662 if ( pMaster.is() )
663 {
664 nFAT = StgCache::GetFromPage( pMaster, nMasterCount );
665 pOldPage = pMaster;
666 }
667 }
668 }
669 if( pMaster.is() )
670 return StgCache::GetFromPage( pMaster, nOff );
672 return STG_EOF;
673}
674
675
676// Set the page number entry for the given page offset.
677
678bool StgFATStrm::SetPage( short nOff, sal_Int32 nNewPage )
679{
680 OSL_ENSURE( nOff >= 0, "The offset may not be negative!" );
681 m_aPagesCache.clear();
683
684 bool bRes = true;
685 if( nOff < StgHeader::GetFAT1Size() )
686 m_rIo.m_aHdr.SetFATPage( nOff, nNewPage );
687 else
688 {
689 nOff = nOff - StgHeader::GetFAT1Size();
690 // number of master pages that we need to iterate through
691 sal_uInt16 nMasterCount = ( m_nPageSize >> 2 ) - 1;
692 sal_uInt16 nBlocks = nOff / nMasterCount;
693 // offset in the last master page
694 nOff = nOff % nMasterCount;
695
697 sal_Int32 nFAT = m_rIo.m_aHdr.GetFATChain();
698 for( sal_uInt16 nCount = 0; nCount <= nBlocks; nCount++ )
699 {
700 if( nFAT == STG_EOF || nFAT == STG_FREE )
701 {
702 pMaster = nullptr;
703 break;
704 }
705 pMaster = m_rIo.Get( nFAT, true );
706 if ( pMaster.is() )
707 nFAT = StgCache::GetFromPage( pMaster, nMasterCount );
708 }
709 if( pMaster.is() )
710 m_rIo.SetToPage( pMaster, nOff, nNewPage );
711 else
712 {
714 bRes = false;
715 }
716 }
717
718 // lock the page against access
719 if( bRes )
720 {
721 Pos2Page( nNewPage << 2 );
723 if( pPg.is() )
724 m_rIo.SetToPage( pPg, m_nOffset >> 2, STG_FAT );
725 else
726 bRes = false;
727 }
728 return bRes;
729}
730
731bool StgFATStrm::SetSize( sal_Int32 nBytes )
732{
733 if ( nBytes < 0 )
734 return false;
735
736 m_aPagesCache.clear();
738
739 // Set the number of entries to a multiple of the page size
740 short nOld = static_cast<short>( ( m_nSize + ( m_nPageSize - 1 ) ) / m_nPageSize );
741 short nNew = static_cast<short>(
742 ( nBytes + ( m_nPageSize - 1 ) ) / m_nPageSize ) ;
743 if( nNew < nOld )
744 {
745 // release master pages
746 for( short i = nNew; i < nOld; i++ )
747 SetPage( i, STG_FREE );
748 }
749 else
750 {
751 while( nOld < nNew )
752 {
753 // allocate master pages
754 // find a free master page slot
755 sal_Int32 nPg = 0;
756 sal_uInt16 nMasterAlloc = 0;
757 nPg = GetPage( nOld, true, &nMasterAlloc );
758 if( nPg == STG_EOF )
759 return false;
760 // 4 Bytes have been used for Allocation of each MegaMasterPage
761 nBytes += nMasterAlloc << 2;
762
763 // find a free page using the FAT allocator
764 sal_Int32 n = 1;
765 OSL_ENSURE( m_pFat, "The pointer is always initializer here!" );
766 sal_Int32 nNewPage = m_pFat->FindBlock( n );
767 if( nNewPage == STG_EOF )
768 {
769 // no free pages found; create a new page
770 // Since all pages are allocated, extend
771 // the file size for the next page!
772 nNewPage = m_nSize >> 2;
773 // if a MegaMasterPage was created avoid taking
774 // the same Page
775 nNewPage += nMasterAlloc;
776 // adjust the file size if necessary
777 if( nNewPage >= m_rIo.GetPhysPages() )
778 if( !m_rIo.SetSize( nNewPage + 1 ) )
779 return false;
780 }
781 // Set up the page with empty entries
782 rtl::Reference< StgPage > pPg = m_rIo.Copy( nNewPage );
783 if ( !pPg.is() )
784 return false;
785 for( short j = 0; j < static_cast<short>( m_nPageSize >> 2 ); j++ )
786 m_rIo.SetToPage( pPg, j, STG_FREE );
787
788 // store the page number into the master FAT
789 // Set the size before so the correct FAT can be found
790 m_nSize = ( nOld + 1 ) * m_nPageSize;
791 SetPage( nOld, nNewPage );
792
793 // MegaMasterPages were created, mark it them as used
794
795 sal_uInt32 nMax = m_rIo.m_aHdr.GetMasters( );
796 sal_uInt32 nFAT = m_rIo.m_aHdr.GetFATChain();
797 if( nMasterAlloc )
798 for( sal_uInt32 nCount = 0; nCount < nMax; nCount++ )
799 {
800 if( !Pos2Page( nFAT << 2 ) )
801 return false;
802 if( nMax - nCount <= nMasterAlloc )
803 {
805 if( !piPg.is() )
806 return false;
807 m_rIo.SetToPage( piPg, m_nOffset >> 2, STG_MASTER );
808 }
809 rtl::Reference< StgPage > pPage = m_rIo.Get( nFAT, true );
810 if( !pPage.is() ) return false;
811 nFAT = StgCache::GetFromPage( pPage, (m_nPageSize >> 2 ) - 1 );
812 }
813
814 nOld++;
815 // We have used up 4 bytes for the STG_FAT entry
816 nBytes += 4;
817 nNew = static_cast<short>(
818 ( nBytes + ( m_nPageSize - 1 ) ) / m_nPageSize );
819 }
820 }
821 m_nSize = nNew * m_nPageSize;
822 m_rIo.m_aHdr.SetFATSize( nNew );
823 return true;
824}
825
827
828// This class is a normal physical stream which can be initialized
829// either with an existing dir entry or an existing FAT chain.
830// The stream has a size increment which normally is 1, but which can be
831// set to any value is you want the size to be incremented by certain values.
832
833StgDataStrm::StgDataStrm( StgIo& r, sal_Int32 nBgn, sal_Int32 nLen ) : StgStrm( r )
834{
835 Init( nBgn, nLen );
836}
837
839{
840 m_pEntry = &p;
841 Init( p.m_aEntry.GetLeaf( STG_DATA ),
842 p.m_aEntry.GetSize() );
843}
844
845void StgDataStrm::Init( sal_Int32 nBgn, sal_Int32 nLen )
846{
847 if ( m_rIo.m_pFAT )
848 m_pFat.reset( new StgFAT( *m_rIo.m_pFAT, true ) );
849
850 OSL_ENSURE( m_pFat, "The pointer should not be empty!" );
851
852 m_nStart = m_nPage = nBgn;
853 m_nSize = nLen;
854 m_nIncr = 1;
855 m_nOffset = 0;
856 if( nLen < 0 && m_pFat )
857 {
858 // determine the actual size of the stream by scanning
859 // the FAT chain and counting the # of pages allocated
861 }
862}
863
864// Set the size of a physical stream.
865
866bool StgDataStrm::SetSize( sal_Int32 nBytes )
867{
868 if ( !m_pFat )
869 return false;
870
871 nBytes = ( ( nBytes + m_nIncr - 1 ) / m_nIncr ) * m_nIncr;
872 sal_Int32 nOldSz = m_nSize;
873 if( nOldSz != nBytes )
874 {
875 if( !StgStrm::SetSize( nBytes ) )
876 return false;
877 sal_Int32 nMaxPage = m_pFat->GetMaxPage();
878 if( nMaxPage > m_rIo.GetPhysPages() )
879 if( !m_rIo.SetSize( nMaxPage ) )
880 return false;
881 // If we only allocated one page or less, create this
882 // page in the cache for faster throughput. The current
883 // position is the former EOF point.
884 if( ( m_nSize - 1 ) / m_nPageSize - ( nOldSz - 1 ) / m_nPageSize == 1 )
885 {
886 Pos2Page( nBytes );
887 if( m_nPage >= 0 )
888 m_rIo.Copy( m_nPage );
889 }
890 }
891 return true;
892}
893
894// Get the address of the data byte at a specified offset.
895// If bForce = true, a read of non-existent data causes
896// a read fault.
897
898void* StgDataStrm::GetPtr( sal_Int32 Pos, bool bDirty )
899{
900 if( Pos2Page( Pos ) )
901 {
902 rtl::Reference< StgPage > pPg = m_rIo.Get( m_nPage, true/*bForce*/ );
903 if (pPg.is() && m_nOffset < pPg->GetSize())
904 {
905 if( bDirty )
906 m_rIo.SetDirty( pPg );
907 return static_cast<sal_uInt8 *>(pPg->GetData()) + m_nOffset;
908 }
909 }
910 return nullptr;
911}
912
913// This could easily be adapted to a better algorithm by determining
914// the amount of consecutable blocks before doing a read. The result
915// is the number of bytes read. No error is generated on EOF.
916
917sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
918{
919 if ( n < 0 )
920 return 0;
921
922 const auto nAvailable = m_nSize - GetPos();
923 if (n > nAvailable)
924 n = nAvailable;
925 sal_Int32 nDone = 0;
926 while( n )
927 {
928 short nBytes = m_nPageSize - m_nOffset;
930 if( static_cast<sal_Int32>(nBytes) > n )
931 nBytes = static_cast<short>(n);
932 if( nBytes )
933 {
934 short nRes;
935 void *p = static_cast<sal_uInt8 *>(pBuf) + nDone;
936 if( nBytes == m_nPageSize )
937 {
938 pPg = m_rIo.Find( m_nPage );
939 if( pPg.is() )
940 {
941 // data is present, so use the cached data
942 memcpy( p, pPg->GetData(), nBytes );
943 nRes = nBytes;
944 }
945 else
946 // do a direct (unbuffered) read
947 nRes = static_cast<short>(m_rIo.Read( m_nPage, p )) * m_nPageSize;
948 }
949 else
950 {
951 // partial block read through the cache.
952 pPg = m_rIo.Get( m_nPage, false );
953 if( !pPg.is() )
954 break;
955 memcpy( p, static_cast<sal_uInt8*>(pPg->GetData()) + m_nOffset, nBytes );
956 nRes = nBytes;
957 }
958 nDone += nRes;
959 SetPos(GetPos() + nRes, true);
960 n -= nRes;
961 m_nOffset = m_nOffset + nRes;
962 if( nRes != nBytes )
963 break; // read error or EOF
964 }
965 // Switch to next page if necessary
966 if (m_nOffset >= m_nPageSize && !Pos2Page(GetPos()))
967 break;
968 }
969 return nDone;
970}
971
972sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
973{
974 if ( n < 0 )
975 return 0;
976
977 sal_Int32 nDone = 0;
978 if( ( GetPos() + n ) > m_nSize )
979 {
980 sal_Int32 nOld = GetPos();
981 if( !SetSize( nOld + n ) )
982 return 0;
983 Pos2Page( nOld );
984 }
985 while( n )
986 {
987 short nBytes = m_nPageSize - m_nOffset;
989 if( static_cast<sal_Int32>(nBytes) > n )
990 nBytes = static_cast<short>(n);
991 if( nBytes )
992 {
993 short nRes;
994 const void *p = static_cast<const sal_uInt8 *>(pBuf) + nDone;
995 if( nBytes == m_nPageSize )
996 {
997 pPg = m_rIo.Find( m_nPage );
998 if( pPg.is() )
999 {
1000 // data is present, so use the cached data
1001 memcpy( pPg->GetData(), p, nBytes );
1002 m_rIo.SetDirty( pPg );
1003 nRes = nBytes;
1004 }
1005 else
1006 // do a direct (unbuffered) write
1007 nRes = static_cast<short>(m_rIo.Write( m_nPage, p )) * m_nPageSize;
1008 }
1009 else
1010 {
1011 // partial block read through the cache.
1012 pPg = m_rIo.Get( m_nPage, false );
1013 if( !pPg.is() )
1014 break;
1015 memcpy( static_cast<sal_uInt8*>(pPg->GetData()) + m_nOffset, p, nBytes );
1016 m_rIo.SetDirty( pPg );
1017 nRes = nBytes;
1018 }
1019 nDone += nRes;
1020 SetPos(GetPos() + nRes, true);
1021 n -= nRes;
1022 m_nOffset = m_nOffset + nRes;
1023 if( nRes != nBytes )
1024 break; // read error
1025 }
1026 // Switch to next page if necessary
1027 if( m_nOffset >= m_nPageSize && !Pos2Page(GetPos()) )
1028 break;
1029 }
1030 return nDone;
1031}
1032
1034
1035// The small stream class provides access to streams with a size < 4096 bytes.
1036// This stream is a StgStream containing small pages. The FAT for this stream
1037// is also a StgStream. The start of the FAT is in the header at DataRootPage,
1038// the stream itself is pointed to by the root entry (it holds start & size).
1039
1040StgSmallStrm::StgSmallStrm( StgIo& r, sal_Int32 nBgn ) : StgStrm( r )
1041{
1042 Init( nBgn, 0 );
1043}
1044
1046{
1047 m_pEntry = &p;
1048 Init( p.m_aEntry.GetLeaf( STG_DATA ),
1049 p.m_aEntry.GetSize() );
1050}
1051
1052void StgSmallStrm::Init( sal_Int32 nBgn, sal_Int32 nLen )
1053{
1054 if ( m_rIo.m_pDataFAT )
1055 m_pFat.reset( new StgFAT( *m_rIo.m_pDataFAT, false ) );
1057 OSL_ENSURE( m_pFat && m_pData, "The pointers should not be empty!" );
1058
1060 m_nStart =
1061 m_nPage = nBgn;
1062 m_nSize = nLen;
1063}
1064
1065// This could easily be adapted to a better algorithm by determining
1066// the amount of consecutable blocks before doing a read. The result
1067// is the number of bytes read. No error is generated on EOF.
1068
1069sal_Int32 StgSmallStrm::Read( void* pBuf, sal_Int32 n )
1070{
1071 // We can safely assume that reads are not huge, since the
1072 // small stream is likely to be < 64 KBytes.
1073 sal_Int32 nBytePos = GetPos();
1074 if( ( nBytePos + n ) > m_nSize )
1075 n = m_nSize - nBytePos;
1076 sal_Int32 nDone = 0;
1077 while( n )
1078 {
1079 short nBytes = m_nPageSize - m_nOffset;
1080 if( static_cast<sal_Int32>(nBytes) > n )
1081 nBytes = static_cast<short>(n);
1082 if( nBytes )
1083 {
1084 if (!m_pData)
1085 break;
1086 sal_Int32 nPos;
1087 if (o3tl::checked_multiply<sal_Int32>(m_nPage, m_nPageSize, nPos))
1088 break;
1089 if (!m_pData->Pos2Page(nPos + m_nOffset))
1090 break;
1091 // all reading through the stream
1092 short nRes = static_cast<short>(m_pData->Read( static_cast<sal_uInt8*>(pBuf) + nDone, nBytes ));
1093 nDone += nRes;
1094 SetPos(GetPos() + nRes, true);
1095 n -= nRes;
1096 m_nOffset = m_nOffset + nRes;
1097 // read problem?
1098 if( nRes != nBytes )
1099 break;
1100 }
1101 // Switch to next page if necessary
1102 if (m_nOffset >= m_nPageSize && !Pos2Page(GetPos()))
1103 break;
1104 }
1105 return nDone;
1106}
1107
1108sal_Int32 StgSmallStrm::Write( const void* pBuf, sal_Int32 n )
1109{
1110 // you can safely assume that reads are not huge, since the
1111 // small stream is likely to be < 64 KBytes.
1112 sal_Int32 nDone = 0;
1113 sal_Int32 nOldPos = GetPos();
1114 if( ( nOldPos + n ) > m_nSize )
1115 {
1116 if (!SetSize(nOldPos + n))
1117 return 0;
1118 Pos2Page(nOldPos);
1119 }
1120 while( n )
1121 {
1122 short nBytes = m_nPageSize - m_nOffset;
1123 if( static_cast<sal_Int32>(nBytes) > n )
1124 nBytes = static_cast<short>(n);
1125 if( nBytes )
1126 {
1127 // all writing goes through the stream
1128 sal_Int32 nDataPos = m_nPage * m_nPageSize + m_nOffset;
1129 if ( !m_pData
1130 || ( m_pData->GetSize() < ( nDataPos + nBytes )
1131 && !m_pData->SetSize( nDataPos + nBytes ) ) )
1132 break;
1133 if( !m_pData->Pos2Page( nDataPos ) )
1134 break;
1135 short nRes = static_cast<short>(m_pData->Write( static_cast<sal_uInt8 const *>(pBuf) + nDone, nBytes ));
1136 nDone += nRes;
1137 SetPos(GetPos() + nRes, true);
1138 n -= nRes;
1139 m_nOffset = m_nOffset + nRes;
1140 // write problem?
1141 if( nRes != nBytes )
1142 break;
1143 }
1144 // Switch to next page if necessary
1145 if( m_nOffset >= m_nPageSize && !Pos2Page(GetPos()) )
1146 break;
1147 }
1148 return nDone;
1149}
1150
1152
1153// The temporary stream uses a memory stream if < 32K, otherwise a
1154// temporary file.
1155
1156#define THRESHOLD 32768L
1157
1158StgTmpStrm::StgTmpStrm( sal_uInt64 nInitSize )
1159 : SvMemoryStream( nInitSize > THRESHOLD
1160 ? 16
1161 : ( nInitSize ? nInitSize : 16 ), 4096 )
1162{
1163 m_pStrm = nullptr;
1164 // this calls FlushData, so all members should be set by this time
1165 SetBufferSize( 0 );
1166 if( nInitSize > THRESHOLD )
1167 SetSize( nInitSize );
1168}
1169
1171{
1172 sal_uInt64 n = rSrc.GetSize();
1173 const sal_uInt64 nCur = rSrc.Tell();
1174 SetSize( n );
1175 if( GetError() == ERRCODE_NONE )
1176 {
1177 std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]);
1178 rSrc.Seek( 0 );
1179 Seek( 0 );
1180 while( n )
1181 {
1182 const sal_uInt64 nn = std::min<sal_uInt64>(n, 4096);
1183 if (rSrc.ReadBytes( p.get(), nn ) != nn)
1184 break;
1185 if (WriteBytes( p.get(), nn ) != nn)
1186 break;
1187 n -= nn;
1188 }
1189 p.reset();
1190 rSrc.Seek( nCur );
1191 Seek( nCur );
1192 return n == 0;
1193 }
1194 else
1195 return false;
1196}
1197
1199{
1200 if( m_pStrm )
1201 {
1202 m_pStrm->Close();
1203 osl::File::remove( m_aName );
1204 delete m_pStrm;
1205 }
1206}
1207
1208sal_uInt64 StgTmpStrm::GetSize() const
1209{
1210 sal_uInt64 n;
1211 if( m_pStrm )
1212 {
1213 n = m_pStrm->TellEnd();
1214 }
1215 else
1216 n = nEndOfData;
1217 return n;
1218}
1219
1220void StgTmpStrm::SetSize(sal_uInt64 n)
1221{
1222 if( m_pStrm )
1224 else
1225 {
1226 if( n > THRESHOLD )
1227 {
1229 std::unique_ptr<SvFileStream> s(new SvFileStream( m_aName, StreamMode::READWRITE ));
1230 const sal_uInt64 nCur = Tell();
1231 sal_uInt64 i = nEndOfData;
1232 std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]);
1233 if( i )
1234 {
1235 Seek( 0 );
1236 while( i )
1237 {
1238 const sal_uInt64 nb = std::min<sal_uInt64>(i, 4096);
1239 if (ReadBytes(p.get(), nb) == nb
1240 && s->WriteBytes(p.get(), nb) == nb)
1241 i -= nb;
1242 else
1243 break;
1244 }
1245 }
1246 if( !i && n > nEndOfData )
1247 {
1248 // We have to write one byte at the end of the file
1249 // if the file is bigger than the memstream to see
1250 // if it fits on disk
1251 s->Seek(nEndOfData);
1252 memset(p.get(), 0x00, 4096);
1253 i = n - nEndOfData;
1254 while (i)
1255 {
1256 const sal_uInt64 nb = std::min<sal_uInt64>(i, 4096);
1257 if (s->WriteBytes(p.get(), nb) == nb)
1258 i -= nb;
1259 else
1260 break; // error
1261 }
1262 s->Flush();
1263 if( s->GetError() != ERRCODE_NONE )
1264 i = 1;
1265 }
1266 Seek( nCur );
1267 s->Seek( nCur );
1268 if( i )
1269 {
1270 SetError( s->GetError() );
1271 return;
1272 }
1273 m_pStrm = s.release();
1274 // Shrink the memory to 16 bytes, which seems to be the minimum
1275 ReAllocateMemory( - ( static_cast<tools::Long>(nEndOfData) - 16 ) );
1276 }
1277 else
1278 {
1279 if( n > nEndOfData )
1280 {
1282 }
1283 else
1284 nEndOfData = n;
1285 }
1286 }
1287}
1288
1289std::size_t StgTmpStrm::GetData( void* pData, std::size_t n )
1290{
1291 if( m_pStrm )
1292 {
1293 n = m_pStrm->ReadBytes( pData, n );
1295 return n;
1296 }
1297 else
1298 return SvMemoryStream::GetData( pData, n );
1299}
1300
1301std::size_t StgTmpStrm::PutData( const void* pData, std::size_t n )
1302{
1303 sal_uInt32 nCur = Tell();
1304 sal_uInt32 nNew = nCur + n;
1305 if( nNew > THRESHOLD && !m_pStrm )
1306 {
1307 SetSize( nNew );
1308 if( GetError() != ERRCODE_NONE )
1309 return 0;
1310 }
1311 if( m_pStrm )
1312 {
1313 nNew = m_pStrm->WriteBytes( pData, n );
1315 }
1316 else
1317 nNew = SvMemoryStream::PutData( pData, n );
1318 return nNew;
1319}
1320
1321sal_uInt64 StgTmpStrm::SeekPos(sal_uInt64 n)
1322{
1323 // check if a truncated STREAM_SEEK_TO_END was passed
1324 assert(n != SAL_MAX_UINT32);
1325 if( n == STREAM_SEEK_TO_END )
1326 n = GetSize();
1327 if( n > THRESHOLD && !m_pStrm )
1328 {
1329 SetSize( n );
1330 if( GetError() != ERRCODE_NONE )
1331 return Tell();
1332 else
1333 return n;
1334 }
1335 else if( m_pStrm )
1336 {
1337 n = m_pStrm->Seek( n );
1339 return n;
1340 }
1341 else
1342 return SvMemoryStream::SeekPos( n );
1343}
1344
1346{
1347 if( m_pStrm )
1348 {
1349 m_pStrm->Flush();
1351 }
1352 else
1354}
1355
1356/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int32 GetFromPage(const rtl::Reference< StgPage > &rPage, short nOff)
Definition: stgcache.hxx:117
rtl::Reference< StgPage > Get(sal_Int32, bool)
Definition: stgcache.cxx:162
rtl::Reference< StgPage > Copy(sal_Int32, sal_Int32=STG_FREE)
Definition: stgcache.cxx:182
bool Write(sal_Int32 nPage, void const *pBuf)
Definition: stgcache.cxx:361
short GetPhysPageSize() const
Definition: stgcache.hxx:69
rtl::Reference< StgPage > Find(sal_Int32)
Definition: stgcache.cxx:148
bool SetSize(sal_Int32 nPages)
Definition: stgcache.cxx:390
void SetToPage(const rtl::Reference< StgPage > &rPage, short nOff, sal_Int32 nVal)
Definition: stgcache.cxx:55
sal_Int32 GetPhysPages() const
Definition: stgcache.hxx:68
void SetDirty(const rtl::Reference< StgPage > &rPage)
Definition: stgcache.cxx:266
void SetError(ErrCode)
Definition: stgcache.cxx:401
bool Read(sal_Int32 nPage, void *pBuf)
Definition: stgcache.cxx:312
virtual sal_Int32 Read(void *, sal_Int32) override
Definition: stgstrms.cxx:917
virtual bool SetSize(sal_Int32) override
Definition: stgstrms.cxx:866
void Init(sal_Int32 nBgn, sal_Int32 nLen)
Definition: stgstrms.cxx:845
short m_nIncr
Definition: stgstrms.hxx:119
StgDataStrm(StgIo &, sal_Int32 nBgn, sal_Int32 nLen=-1)
Definition: stgstrms.cxx:833
virtual sal_Int32 Write(const void *, sal_Int32) override
Definition: stgstrms.cxx:972
void * GetPtr(sal_Int32 nPos, bool bDirty)
Definition: stgstrms.cxx:898
StgEntry m_aEntry
Definition: stgdir.hxx:53
void SetDirty()
Definition: stgdir.hxx:70
void SetLeaf(StgEntryRef, sal_Int32)
Definition: stgelem.cxx:349
void SetSize(sal_Int32 n)
Definition: stgelem.hxx:131
bool SetPage(short, sal_Int32)
Definition: stgstrms.cxx:678
virtual bool Pos2Page(sal_Int32 nBytePos) override
Definition: stgstrms.cxx:585
sal_Int32 GetPage() const
Definition: stgstrms.hxx:89
StgFATStrm(StgIo &, sal_Int32 nFatStrmSize)
Definition: stgstrms.cxx:579
virtual bool SetSize(sal_Int32) override
Definition: stgstrms.cxx:731
rtl::Reference< StgPage > GetPhysPage(sal_Int32 nPage)
Definition: stgstrms.cxx:53
short m_nPageSize
Definition: stgstrms.hxx:42
StgStrm & m_rStrm
Definition: stgstrms.hxx:40
bool InitNew(sal_Int32 nPage1)
Definition: stgstrms.cxx:276
sal_Int32 m_nMaxPage
Definition: stgstrms.hxx:41
sal_Int32 AllocPages(sal_Int32 nStart, sal_Int32 nPages)
Definition: stgstrms.cxx:212
sal_Int32 GetNextPage(sal_Int32 nPg)
Definition: stgstrms.cxx:70
short m_nEntries
Definition: stgstrms.hxx:43
bool FreePages(sal_Int32 nStart, bool bAll)
Definition: stgstrms.cxx:301
sal_Int32 FindBlock(sal_Int32 &nPages)
Definition: stgstrms.cxx:88
sal_Int32 m_nLimit
Definition: stgstrms.hxx:45
StgFAT(StgStrm &rStrm, bool bMark)
Definition: stgstrms.cxx:41
short m_nOffset
Definition: stgstrms.hxx:44
bool MakeChain(sal_Int32 nStart, sal_Int32 nPages)
Definition: stgstrms.cxx:181
bool m_bPhys
Definition: stgstrms.hxx:46
void SetFATPage(short, sal_Int32)
Definition: stgelem.cxx:217
static short GetFAT1Size()
Definition: stgelem.hxx:80
void SetMasters(sal_Int32 n)
Definition: stgelem.cxx:274
sal_Int32 GetFATChain() const
Definition: stgelem.hxx:76
sal_Int32 GetFATPage(short) const
Definition: stgelem.cxx:209
sal_Int32 GetMasters() const
Definition: stgelem.hxx:78
void SetFATChain(sal_Int32 n)
Definition: stgelem.cxx:265
void SetFATSize(sal_Int32 n)
Definition: stgelem.cxx:256
Definition: stgio.hxx:42
short GetDataPageSize() const
Definition: stgio.cxx:125
StgDataStrm * m_pDataFAT
Definition: stgio.hxx:51
StgDataStrm * m_pDataStrm
Definition: stgio.hxx:52
StgFATStrm * m_pFAT
Definition: stgio.hxx:49
StgHeader m_aHdr
Definition: stgio.hxx:48
StgSmallStrm(StgIo &, sal_Int32 nBgn)
Definition: stgstrms.cxx:1040
virtual sal_Int32 Write(const void *, sal_Int32) override
Definition: stgstrms.cxx:1108
virtual sal_Int32 Read(void *, sal_Int32) override
Definition: stgstrms.cxx:1069
StgStrm * m_pData
Definition: stgstrms.hxx:138
void Init(sal_Int32 nBgn, sal_Int32 nLen)
Definition: stgstrms.cxx:1052
void SetEntry(StgDirEntry &)
Definition: stgstrms.cxx:341
virtual sal_Int32 Read(void *, sal_Int32)
Definition: stgstrms.hxx:95
o3tl::sorted_vector< sal_Int32 > m_aUsedPageNumbers
Definition: stgstrms.hxx:78
sal_Int32 m_nPage
Definition: stgstrms.hxx:74
virtual sal_Int32 Write(const void *, sal_Int32)
Definition: stgstrms.hxx:96
void SetPos(sal_Int32 nPos, bool bValid)
Definition: stgstrms.hxx:81
virtual ~StgStrm()
Definition: stgstrms.cxx:335
StgStrm(StgIo &)
Definition: stgstrms.cxx:322
short GetOffset() const
Definition: stgstrms.hxx:91
sal_Int32 m_nPos
Definition: stgstrms.hxx:66
virtual bool SetSize(sal_Int32)
Definition: stgstrms.cxx:528
sal_Int32 scanBuildPageChainCache()
Definition: stgstrms.cxx:355
bool m_bBytePosValid
Definition: stgstrms.hxx:67
sal_Int32 GetPos() const
Definition: stgstrms.hxx:86
sal_Int32 m_nStart
Definition: stgstrms.hxx:72
sal_Int32 GetPages() const
Definition: stgstrms.hxx:90
sal_Int32 GetSize() const
Definition: stgstrms.hxx:88
std::vector< sal_Int32 > m_aPagesCache
Definition: stgstrms.hxx:77
short m_nPageSize
Definition: stgstrms.hxx:76
StgIo & GetIo()
Definition: stgstrms.hxx:85
short m_nOffset
Definition: stgstrms.hxx:75
sal_Int32 GetPage() const
Definition: stgstrms.hxx:89
StgIo & m_rIo
Definition: stgstrms.hxx:69
sal_Int32 m_nSize
Definition: stgstrms.hxx:73
StgDirEntry * m_pEntry
Definition: stgstrms.hxx:71
std::unique_ptr< StgFAT > m_pFat
Definition: stgstrms.hxx:70
bool Copy(sal_Int32 nFrom, sal_Int32 nBytes)
Definition: stgstrms.cxx:496
virtual bool Pos2Page(sal_Int32 nBytePos)
Definition: stgstrms.cxx:396
StgTmpStrm(sal_uInt64=16)
Definition: stgstrms.cxx:1158
virtual void SetSize(sal_uInt64) override
Definition: stgstrms.cxx:1220
OUString m_aName
Definition: stgstrms.hxx:150
const void * GetData()
virtual ~StgTmpStrm() override
Definition: stgstrms.cxx:1198
SvFileStream * m_pStrm
Definition: stgstrms.hxx:151
virtual std::size_t PutData(const void *pData, std::size_t nSize) override
Definition: stgstrms.cxx:1301
virtual void FlushData() override
Definition: stgstrms.cxx:1345
virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override
Definition: stgstrms.cxx:1321
bool Copy(StgTmpStrm &)
Definition: stgstrms.cxx:1170
sal_uInt64 GetSize() const
Definition: stgstrms.cxx:1208
std::size_t nEndOfData
const void * GetData()
virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override
virtual std::size_t PutData(const void *pData, std::size_t nSize) override
bool ReAllocateMemory(tools::Long nDiff)
virtual void SetSize(sal_uInt64 nSize) override
virtual void FlushData() override
sal_uInt64 Tell() const
virtual sal_uInt64 TellEnd()
void SetBufferSize(sal_uInt16 m_nBufSize)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool SetStreamSize(sal_uInt64 nSize)
void SetError(ErrCode nErrorCode)
sal_uInt64 Seek(sal_uInt64 nPos)
void Flush()
std::size_t ReadBytes(void *pData, std::size_t nSize)
ErrCode GetError() const
void reserve(size_type amount)
bool empty() const
std::pair< const_iterator, bool > insert(Value &&x)
int nCount
#define SVSTREAM_FILEFORMAT_ERROR
#define ERRCODE_IO_WRONGFORMAT
#define SVSTREAM_GENERALERROR
#define ERRCODE_NONE
size_t m_nPos
void * p
sal_Int64 n
sal_uInt16 nPos
sal_uInt16 m_nPageSize
sal_uInt32 m_nSize
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
int i
m
long Long
OUString CreateTempURL(const OUString *pParent, bool bDirectory)
#define STG_FREE
Definition: stgelem.hxx:139
@ STG_DATA
Definition: stgelem.hxx:96
#define STG_MASTER
Definition: stgelem.hxx:142
#define STG_FAT
Definition: stgelem.hxx:141
#define STG_EOF
Definition: stgelem.hxx:140
#define THRESHOLD
Definition: stgstrms.cxx:1156
#define STREAM_SEEK_TO_END
unsigned char sal_uInt8
#define SAL_MAX_INT32
#define SAL_MAX_UINT32