LibreOffice Module sot (master) 1
stgstrms.hxx
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#ifndef INCLUDED_SOT_SOURCE_SDSTOR_STGSTRMS_HXX
21#define INCLUDED_SOT_SOURCE_SDSTOR_STGSTRMS_HXX
22
23#include <tools/stream.hxx>
25#include <rtl/ref.hxx>
26#include <vector>
27#include <memory>
28
29class StgIo;
30class StgStrm;
31class StgPage;
32class StgDirEntry;
33
34// The FAT class performs FAT operations on an underlying storage stream.
35// This stream is either the physical FAT stream (bPhys == true ) or a normal
36// storage stream, which then holds the FAT for small data allocations.
37
38class StgFAT
39{ // FAT allocator
40 StgStrm& m_rStrm; // underlying stream
41 sal_Int32 m_nMaxPage; // highest page allocated so far
42 short m_nPageSize; // physical page size
43 short m_nEntries; // FAT entries per page
44 short m_nOffset; // current offset within page
45 sal_Int32 m_nLimit; // search limit recommendation
46 bool m_bPhys; // true: physical FAT
47 rtl::Reference< StgPage > GetPhysPage( sal_Int32 nPage );
48 bool MakeChain( sal_Int32 nStart, sal_Int32 nPages );
49 bool InitNew( sal_Int32 nPage1 );
50public:
51 StgFAT( StgStrm& rStrm, bool bMark );
52 sal_Int32 FindBlock( sal_Int32& nPages );
53 sal_Int32 GetNextPage( sal_Int32 nPg );
54 sal_Int32 AllocPages( sal_Int32 nStart, sal_Int32 nPages );
55 bool FreePages( sal_Int32 nStart, bool bAll );
56 sal_Int32 GetMaxPage() const { return m_nMaxPage; }
57 void SetLimit( sal_Int32 n ) { m_nLimit = n; }
58};
59
60// The base stream class provides basic functionality for seeking
61// and accessing the data on a physical basis. It uses the built-in
62// FAT class for the page allocations.
63
64class StgStrm { // base class for all streams
65private:
66 sal_Int32 m_nPos; // current byte position
67 bool m_bBytePosValid; // what Pos2Page returns for m_nPos
68protected:
69 StgIo& m_rIo; // I/O system
70 std::unique_ptr<StgFAT> m_pFat; // FAT stream for allocations
71 StgDirEntry* m_pEntry; // dir entry (for ownership)
72 sal_Int32 m_nStart; // 1st data page
73 sal_Int32 m_nSize; // stream size in bytes
74 sal_Int32 m_nPage; // current logical page
75 short m_nOffset; // offset into current page
76 short m_nPageSize; // logical page size
77 std::vector<sal_Int32> m_aPagesCache;
79 sal_Int32 scanBuildPageChainCache();
80 bool Copy( sal_Int32 nFrom, sal_Int32 nBytes );
81 void SetPos(sal_Int32 nPos, bool bValid) { m_nPos = nPos; m_bBytePosValid = bValid; }
82 explicit StgStrm( StgIo& );
83public:
84 virtual ~StgStrm();
85 StgIo& GetIo() { return m_rIo; }
86 sal_Int32 GetPos() const { return m_nPos; }
87 sal_Int32 GetStart() const { return m_nStart; }
88 sal_Int32 GetSize() const { return m_nSize; }
89 sal_Int32 GetPage() const { return m_nPage; }
90 sal_Int32 GetPages() const { return ( m_nSize + m_nPageSize - 1 ) / m_nPageSize;}
91 short GetOffset() const { return m_nOffset;}
92 void SetEntry( StgDirEntry& );
93 virtual bool SetSize( sal_Int32 );
94 virtual bool Pos2Page( sal_Int32 nBytePos );
95 virtual sal_Int32 Read( void*, sal_Int32 ) { return 0; }
96 virtual sal_Int32 Write( const void*, sal_Int32 ) { return 0; }
97 virtual bool IsSmallStrm() const { return false; }
98};
99
100// The FAT stream class provides physical access to the master FAT.
101// Since this access is implemented as a StgStrm, we can use the
102// FAT allocator.
103
104class StgFATStrm : public StgStrm { // the master FAT stream
105 virtual bool Pos2Page( sal_Int32 nBytePos ) override;
106 bool SetPage( short, sal_Int32 );
107public:
108 explicit StgFATStrm(StgIo&, sal_Int32 nFatStrmSize);
109 using StgStrm::GetPage;
110 sal_Int32 GetPage(sal_Int32, bool, sal_uInt16 *pnMasterAlloc = nullptr);
111 virtual bool SetSize( sal_Int32 ) override;
112};
113
114// The stream has a size increment which normally is 1, but which can be
115// set to any value is you want the size to be incremented by certain values.
116
117class StgDataStrm : public StgStrm // a physical data stream
118{
119 short m_nIncr; // size adjust increment
120 void Init( sal_Int32 nBgn, sal_Int32 nLen );
121public:
122 StgDataStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen=-1 );
124 void* GetPtr( sal_Int32 nPos, bool bDirty );
125 void SetIncrement( short n ) { m_nIncr = n ; }
126 virtual bool SetSize( sal_Int32 ) override;
127 virtual sal_Int32 Read( void*, sal_Int32 ) override;
128 virtual sal_Int32 Write( const void*, sal_Int32 ) override;
129};
130
131// The small stream class provides access to streams with a size < 4096 bytes.
132// This stream is a StgStream containing small pages. The FAT for this stream
133// is also a StgStream. The start of the FAT is in the header at DataRootPage,
134// the stream itself is pointed to by the root entry (it holds start & size).
135
136class StgSmallStrm : public StgStrm // a logical data stream
137{
138 StgStrm* m_pData; // the data stream
139 void Init( sal_Int32 nBgn, sal_Int32 nLen );
140public:
141 StgSmallStrm( StgIo&, sal_Int32 nBgn );
143 virtual sal_Int32 Read( void*, sal_Int32 ) override;
144 virtual sal_Int32 Write( const void*, sal_Int32 ) override;
145 virtual bool IsSmallStrm() const override { return true; }
146};
147
149{
150 OUString m_aName;
153 virtual std::size_t GetData( void* pData, std::size_t nSize ) override;
154 virtual std::size_t PutData( const void* pData, std::size_t nSize ) override;
155 virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) override;
156 virtual void FlushData() override;
157
158public:
159 explicit StgTmpStrm( sal_uInt64=16 );
160 virtual ~StgTmpStrm() override;
161 bool Copy( StgTmpStrm& );
162 virtual void SetSize( sal_uInt64 ) override;
163 sal_uInt64 GetSize() const;
164};
165
166#endif
167
168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 Read(void *, sal_Int32) override
Definition: stgstrms.cxx:917
void SetIncrement(short n)
Definition: stgstrms.hxx:125
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
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
void SetLimit(sal_Int32 n)
Definition: stgstrms.hxx:57
short m_nEntries
Definition: stgstrms.hxx:43
sal_Int32 GetMaxPage() const
Definition: stgstrms.hxx:56
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
Definition: stgio.hxx:42
StgSmallStrm(StgIo &, sal_Int32 nBgn)
Definition: stgstrms.cxx:1040
virtual bool IsSmallStrm() const override
Definition: stgstrms.hxx:145
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
sal_Int32 GetStart() const
Definition: stgstrms.hxx:87
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
virtual bool IsSmallStrm() const
Definition: stgstrms.hxx:97
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
const void * GetData()
std::size_t nSize
std::size_t nPos
sal_Int64 n
sal_uInt16 nPos