stgio.cxx (046d9d1f) stgio.cxx (297a844a)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 52 unchanged lines hidden (view full) ---

61 {
62 if( aHdr.Load( *this ) )
63 {
64 if( aHdr.Check() )
65 SetupStreams();
66 else
67 return sal_False;
68 }
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 52 unchanged lines hidden (view full) ---

61 {
62 if( aHdr.Load( *this ) )
63 {
64 if( aHdr.Check() )
65 SetupStreams();
66 else
67 return sal_False;
68 }
69 else
70 return sal_False;
69 }
70 return Good();
71}
72
73// Set up an initial, empty storage
74
75sal_Bool StgIo::Init()
76{

--- 17 unchanged lines hidden (view full) ---

94 pFAT = new StgFATStrm( *this );
95 pTOC = new StgDirStrm( *this );
96 if( !GetError() )
97 {
98 StgDirEntry* pRoot = pTOC->GetRoot();
99 if( pRoot )
100 {
101 pDataFAT = new StgDataStrm( *this, aHdr.GetDataFATStart(), -1 );
71 }
72 return Good();
73}
74
75// Set up an initial, empty storage
76
77sal_Bool StgIo::Init()
78{

--- 17 unchanged lines hidden (view full) ---

96 pFAT = new StgFATStrm( *this );
97 pTOC = new StgDirStrm( *this );
98 if( !GetError() )
99 {
100 StgDirEntry* pRoot = pTOC->GetRoot();
101 if( pRoot )
102 {
103 pDataFAT = new StgDataStrm( *this, aHdr.GetDataFATStart(), -1 );
102 pDataStrm = new StgDataStrm( *this, pRoot );
104 pDataStrm = new StgDataStrm( *this, *pRoot );
103 pDataFAT->SetIncrement( 1 << aHdr.GetPageSize() );
104 pDataStrm->SetIncrement( GetDataPageSize() );
105 pDataStrm->SetEntry( *pRoot );
106 }
107 else
108 SetError( SVSTREAM_FILEFORMAT_ERROR );
109 }
110}

--- 5 unchanged lines hidden (view full) ---

116 return 1 << aHdr.GetDataPageSize();
117}
118
119// Commit everything
120
121sal_Bool StgIo::CommitAll()
122{
123 // Store the data (all streams and the TOC)
105 pDataFAT->SetIncrement( 1 << aHdr.GetPageSize() );
106 pDataStrm->SetIncrement( GetDataPageSize() );
107 pDataStrm->SetEntry( *pRoot );
108 }
109 else
110 SetError( SVSTREAM_FILEFORMAT_ERROR );
111 }
112}

--- 5 unchanged lines hidden (view full) ---

118 return 1 << aHdr.GetDataPageSize();
119}
120
121// Commit everything
122
123sal_Bool StgIo::CommitAll()
124{
125 // Store the data (all streams and the TOC)
124 if( pTOC->Store() )
126 if( pTOC && pTOC->Store() && pDataFAT )
125 {
126 if( Commit( NULL ) )
127 {
128 aHdr.SetDataFATStart( pDataFAT->GetStart() );
129 aHdr.SetDataFATSize( pDataFAT->GetPages() );
130 aHdr.SetTOCStart( pTOC->GetStart() );
131 if( aHdr.Store( *this ) )
132 {

--- 20 unchanged lines hidden (view full) ---

153 sal_Int32 nPageSize;
154
155public:
156 EasyFat( StgIo & rIo, StgStrm *pFatStream, sal_Int32 nPSize );
157 ~EasyFat() { delete[] pFat; delete[] pFree; }
158
159 sal_Int32 GetPageSize() { return nPageSize; }
160 sal_Int32 Count() { return nPages; }
127 {
128 if( Commit( NULL ) )
129 {
130 aHdr.SetDataFATStart( pDataFAT->GetStart() );
131 aHdr.SetDataFATSize( pDataFAT->GetPages() );
132 aHdr.SetTOCStart( pTOC->GetStart() );
133 if( aHdr.Store( *this ) )
134 {

--- 20 unchanged lines hidden (view full) ---

155 sal_Int32 nPageSize;
156
157public:
158 EasyFat( StgIo & rIo, StgStrm *pFatStream, sal_Int32 nPSize );
159 ~EasyFat() { delete[] pFat; delete[] pFree; }
160
161 sal_Int32 GetPageSize() { return nPageSize; }
162 sal_Int32 Count() { return nPages; }
161 sal_Int32 operator[]( sal_Int32 nOffset ) { return pFat[ nOffset ]; }
163 sal_Int32 operator[]( sal_Int32 nOffset )
164 {
165 OSL_ENSURE( nOffset >= 0 && nOffset < nPages, "Unexpected offset!" );
166 return nOffset >= 0 && nOffset < nPages ? pFat[ nOffset ] : -2;
167 }
162
163 sal_uLong Mark( sal_Int32 nPage, sal_Int32 nCount, sal_Int32 nExpect );
164 sal_Bool HasUnrefChains();
165};
166
167EasyFat::EasyFat( StgIo& rIo, StgStrm* pFatStream, sal_Int32 nPSize )
168{
169 nPages = pFatStream->GetSize() >> 2;

--- 31 unchanged lines hidden (view full) ---

201sal_uLong EasyFat::Mark( sal_Int32 nPage, sal_Int32 nCount, sal_Int32 nExpect )
202{
203 if( nCount > 0 )
204 --nCount /= GetPageSize(), nCount++;
205
206 sal_Int32 nCurPage = nPage;
207 while( nCount != 0 )
208 {
168
169 sal_uLong Mark( sal_Int32 nPage, sal_Int32 nCount, sal_Int32 nExpect );
170 sal_Bool HasUnrefChains();
171};
172
173EasyFat::EasyFat( StgIo& rIo, StgStrm* pFatStream, sal_Int32 nPSize )
174{
175 nPages = pFatStream->GetSize() >> 2;

--- 31 unchanged lines hidden (view full) ---

207sal_uLong EasyFat::Mark( sal_Int32 nPage, sal_Int32 nCount, sal_Int32 nExpect )
208{
209 if( nCount > 0 )
210 --nCount /= GetPageSize(), nCount++;
211
212 sal_Int32 nCurPage = nPage;
213 while( nCount != 0 )
214 {
215 if( nCurPage < 0 || nCurPage >= nPages )
216 return FAT_OUTOFBOUNDS;
209 pFree[ nCurPage ] = sal_False;
210 nCurPage = pFat[ nCurPage ];
211 //Stream zu lang
212 if( nCurPage != nExpect && nCount == 1 )
213 return FAT_WRONGLENGTH;
214 //Stream zu kurz
215 if( nCurPage == nExpect && nCount != 1 && nCount != -1 )
216 return FAT_WRONGLENGTH;
217 // letzter Block bei Stream ohne Laenge
218 if( nCurPage == nExpect && nCount == -1 )
219 nCount = 1;
220 if( nCount != -1 )
221 nCount--;
217 pFree[ nCurPage ] = sal_False;
218 nCurPage = pFat[ nCurPage ];
219 //Stream zu lang
220 if( nCurPage != nExpect && nCount == 1 )
221 return FAT_WRONGLENGTH;
222 //Stream zu kurz
223 if( nCurPage == nExpect && nCount != 1 && nCount != -1 )
224 return FAT_WRONGLENGTH;
225 // letzter Block bei Stream ohne Laenge
226 if( nCurPage == nExpect && nCount == -1 )
227 nCount = 1;
228 if( nCount != -1 )
229 nCount--;
222 // Naechster Block nicht in der FAT
223 if( nCount && ( nCurPage < 0 || nCurPage >= nPages ) )
224 return FAT_OUTOFBOUNDS;
225 }
226 return FAT_OK;
227}
228
229class Validator
230{
231 sal_uLong nError;
232

--- 27 unchanged lines hidden (view full) ---

260 else if( ( nErr = FindUnrefedChains()) != FAT_OK )
261 nError = nErr;
262}
263
264sal_uLong Validator::ValidateMasterFATs()
265{
266 sal_Int32 nCount = rIo.aHdr.GetFATSize();
267 sal_uLong nErr;
230 }
231 return FAT_OK;
232}
233
234class Validator
235{
236 sal_uLong nError;
237

--- 27 unchanged lines hidden (view full) ---

265 else if( ( nErr = FindUnrefedChains()) != FAT_OK )
266 nError = nErr;
267}
268
269sal_uLong Validator::ValidateMasterFATs()
270{
271 sal_Int32 nCount = rIo.aHdr.GetFATSize();
272 sal_uLong nErr;
273 if ( !rIo.pFAT )
274 return FAT_INMEMORYERROR;
275
268 for( sal_Int32 i = 0; i < nCount; i++ )
269 {
270 if( ( nErr = aFat.Mark(rIo.pFAT->GetPage( short(i), sal_False ), aFat.GetPageSize(), -3 )) != FAT_OK )
271 return nErr;
272 }
273 if( rIo.aHdr.GetMasters() )
274 if( ( nErr = aFat.Mark(rIo.aHdr.GetFATChain( ), aFat.GetPageSize(), -4 )) != FAT_OK )
275 return nErr;
276 for( sal_Int32 i = 0; i < nCount; i++ )
277 {
278 if( ( nErr = aFat.Mark(rIo.pFAT->GetPage( short(i), sal_False ), aFat.GetPageSize(), -3 )) != FAT_OK )
279 return nErr;
280 }
281 if( rIo.aHdr.GetMasters() )
282 if( ( nErr = aFat.Mark(rIo.aHdr.GetFATChain( ), aFat.GetPageSize(), -4 )) != FAT_OK )
283 return nErr;
284
276 return FAT_OK;
277}
278
279sal_uLong Validator::MarkAll( StgDirEntry *pEntry )
280{
285 return FAT_OK;
286}
287
288sal_uLong Validator::MarkAll( StgDirEntry *pEntry )
289{
290 if ( !pEntry )
291 return FAT_INMEMORYERROR;
292
281 StgIterator aIter( *pEntry );
282 sal_uLong nErr = FAT_OK;
283 for( StgDirEntry* p = aIter.First(); p ; p = aIter.Next() )
284 {
285 if( p->aEntry.GetType() == STG_STORAGE )
286 {
287 nErr = MarkAll( p );
288 if( nErr != FAT_OK )

--- 10 unchanged lines hidden (view full) ---

299 return nErr;
300 }
301 }
302 return FAT_OK;
303}
304
305sal_uLong Validator::ValidateDirectoryEntries()
306{
293 StgIterator aIter( *pEntry );
294 sal_uLong nErr = FAT_OK;
295 for( StgDirEntry* p = aIter.First(); p ; p = aIter.Next() )
296 {
297 if( p->aEntry.GetType() == STG_STORAGE )
298 {
299 nErr = MarkAll( p );
300 if( nErr != FAT_OK )

--- 10 unchanged lines hidden (view full) ---

311 return nErr;
312 }
313 }
314 return FAT_OK;
315}
316
317sal_uLong Validator::ValidateDirectoryEntries()
318{
319 if ( !rIo.pTOC )
320 return FAT_INMEMORYERROR;
321
307 // Normale DirEntries
308 sal_uLong nErr = MarkAll( rIo.pTOC->GetRoot() );
309 if( nErr != FAT_OK )
310 return nErr;
311 // Small Data
312 nErr = aFat.Mark( rIo.pTOC->GetRoot()->aEntry.GetStartPage(),
313 rIo.pTOC->GetRoot()->aEntry.GetSize(), -2 );
314 if( nErr != FAT_OK )

--- 33 unchanged lines hidden (view full) ---

348
349sal_uLong StgIo::ValidateFATs()
350{
351 if( bFile )
352 {
353 Validator *pV = new Validator( *this );
354 sal_Bool bRet1 = !pV->IsError(), bRet2 = sal_True ;
355 delete pV;
322 // Normale DirEntries
323 sal_uLong nErr = MarkAll( rIo.pTOC->GetRoot() );
324 if( nErr != FAT_OK )
325 return nErr;
326 // Small Data
327 nErr = aFat.Mark( rIo.pTOC->GetRoot()->aEntry.GetStartPage(),
328 rIo.pTOC->GetRoot()->aEntry.GetSize(), -2 );
329 if( nErr != FAT_OK )

--- 33 unchanged lines hidden (view full) ---

363
364sal_uLong StgIo::ValidateFATs()
365{
366 if( bFile )
367 {
368 Validator *pV = new Validator( *this );
369 sal_Bool bRet1 = !pV->IsError(), bRet2 = sal_True ;
370 delete pV;
371
356 SvFileStream *pFileStrm = ( SvFileStream *) GetStrm();
372 SvFileStream *pFileStrm = ( SvFileStream *) GetStrm();
373 if ( !pFileStrm )
374 return FAT_INMEMORYERROR;
375
357 StgIo aIo;
358 if( aIo.Open( pFileStrm->GetFileName(),
359 STREAM_READ | STREAM_SHARE_DENYNONE) &&
360 aIo.Load() )
361 {
362 pV = new Validator( aIo );
363 bRet2 = !pV->IsError();
364 delete pV;

--- 20 unchanged lines hidden ---
376 StgIo aIo;
377 if( aIo.Open( pFileStrm->GetFileName(),
378 STREAM_READ | STREAM_SHARE_DENYNONE) &&
379 aIo.Load() )
380 {
381 pV = new Validator( aIo );
382 bRet2 = !pV->IsError();
383 delete pV;

--- 20 unchanged lines hidden ---