Branch data Line data Source code
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 _STORE_STORDATA_HXX_
21 : : #define _STORE_STORDATA_HXX_
22 : :
23 : : #include "sal/types.h"
24 : : #include "sal/macros.h"
25 : :
26 : : #include "store/types.h"
27 : : #include "storbase.hxx"
28 : :
29 : : namespace store
30 : : {
31 : :
32 : : /*========================================================================
33 : : *
34 : : * OStoreDataPageData.
35 : : *
36 : : *======================================================================*/
37 : : #define STORE_MAGIC_DATAPAGE sal_uInt32(0x94190310)
38 : :
39 : : struct OStoreDataPageData : public store::OStorePageData
40 : : {
41 : : typedef OStorePageData base;
42 : : typedef OStoreDataPageData self;
43 : :
44 : : typedef OStorePageDescriptor D;
45 : :
46 : : /** Representation.
47 : : */
48 : : sal_uInt8 m_pData[1];
49 : :
50 : : /** type.
51 : : */
52 : : static const sal_uInt32 theTypeId = STORE_MAGIC_DATAPAGE;
53 : :
54 : : /** size.
55 : : */
56 : : static const size_t theSize = 0;
57 : : static const sal_uInt16 thePageSize = base::theSize + self::theSize;
58 : : STORE_STATIC_ASSERT(STORE_MINIMUM_PAGESIZE >= self::thePageSize);
59 : :
60 : : /** capacity.
61 : : */
62 : 391878 : static sal_uInt16 capacity (const D& rDescr) // @see inode::ChunkDescriptor
63 : : {
64 : 391878 : return (store::ntohs(rDescr.m_nSize) - self::thePageSize);
65 : : }
66 : 71998 : sal_uInt16 capacity() const
67 : : {
68 : 71998 : return self::capacity (base::m_aDescr);
69 : : }
70 : :
71 : : /** usage.
72 : : */
73 : : sal_uInt16 usage() const
74 : : {
75 : : return (store::ntohs(base::m_aDescr.m_nUsed) - self::thePageSize);
76 : : }
77 : :
78 : : /** Construction.
79 : : */
80 : 35999 : explicit OStoreDataPageData (sal_uInt16 nPageSize = self::thePageSize)
81 : 35999 : : base (nPageSize)
82 : : {
83 : 35999 : base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
84 : 35999 : base::m_aDescr.m_nUsed = store::htons(self::thePageSize);
85 [ + - ]: 35999 : if (capacity()) memset (m_pData, 0, capacity());
86 : 35999 : }
87 : :
88 : : /** guard (external representation).
89 : : */
90 : 35999 : void guard() {}
91 : :
92 : : /** verify (external representation).
93 : : */
94 : 187190 : storeError verify() const { return store_E_None; }
95 : : };
96 : :
97 : : /*========================================================================
98 : : *
99 : : * OStoreDataPageObject.
100 : : *
101 : : *======================================================================*/
102 [ - + ]: 865244 : class OStoreDataPageObject : public store::OStorePageObject
103 : : {
104 : : typedef OStorePageObject base;
105 : : typedef OStoreDataPageData page;
106 : :
107 : : public:
108 : : /** Construction.
109 : : */
110 : 865244 : explicit OStoreDataPageObject (PageHolder const & rxPage = PageHolder())
111 : 865244 : : OStorePageObject (rxPage)
112 : 865244 : {}
113 : :
114 : : /** External representation.
115 : : */
116 : : virtual storeError guard (sal_uInt32 nAddr);
117 : : virtual storeError verify (sal_uInt32 nAddr) const;
118 : : };
119 : :
120 : : /*========================================================================
121 : : *
122 : : * OStoreIndirectionPageData.
123 : : *
124 : : *======================================================================*/
125 : : #define STORE_MAGIC_INDIRECTPAGE sal_uInt32(0x89191107)
126 : :
127 : : struct OStoreIndirectionPageData : public store::OStorePageData
128 : : {
129 : : typedef OStorePageData base;
130 : : typedef OStoreIndirectionPageData self;
131 : :
132 : : typedef OStorePageGuard G;
133 : : typedef OStorePageDescriptor D;
134 : :
135 : : /** Representation.
136 : : */
137 : : G m_aGuard;
138 : : sal_uInt32 m_pData[1];
139 : :
140 : : /** type.
141 : : */
142 : : static const sal_uInt32 theTypeId = STORE_MAGIC_INDIRECTPAGE;
143 : :
144 : : /** size.
145 : : */
146 : : static const size_t theSize = sizeof(G);
147 : : static const sal_uInt16 thePageSize = base::theSize + self::theSize;
148 : : STORE_STATIC_ASSERT(STORE_MINIMUM_PAGESIZE >= self::thePageSize);
149 : :
150 : : /** capacity.
151 : : */
152 : 9862 : static sal_uInt16 capacity (const D& rDescr)
153 : : {
154 : 9862 : return (store::ntohs(rDescr.m_nSize) - self::thePageSize);
155 : : }
156 : 5345 : sal_uInt16 capacity() const
157 : : {
158 : 5345 : return self::capacity (base::m_aDescr);
159 : : }
160 : :
161 : : /** capacityCount.
162 : : */
163 : 4517 : static sal_uInt16 capacityCount (const D& rDescr) // @see DirectoryPageObject::scope()
164 : : {
165 : 4517 : return sal_uInt16(capacity(rDescr) / sizeof(sal_uInt32));
166 : : }
167 : 4521 : sal_uInt16 capacityCount() const
168 : : {
169 : 4521 : return sal_uInt16(capacity() / sizeof(sal_uInt32));
170 : : }
171 : :
172 : : /** Construction.
173 : : */
174 : 37 : explicit OStoreIndirectionPageData (sal_uInt16 nPageSize)
175 : 37 : : base (nPageSize)
176 : : {
177 : 37 : base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
178 : 37 : base::m_aDescr.m_nUsed = store::htons(self::thePageSize);
179 : 37 : self::m_aGuard.m_nMagic = store::htonl(0);
180 : 37 : memset (m_pData, STORE_PAGE_NULL, capacity());
181 : 37 : }
182 : :
183 : : /** guard (external representation).
184 : : */
185 : 681 : void guard()
186 : : {
187 : 681 : sal_uInt32 nCRC32 = 0;
188 : 681 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
189 : 681 : nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
190 : 681 : m_aGuard.m_nCRC32 = store::htonl(nCRC32);
191 : 681 : }
192 : :
193 : : /** verify (external representation).
194 : : */
195 : 106 : storeError verify() const
196 : : {
197 : 106 : sal_uInt32 nCRC32 = 0;
198 : 106 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
199 : 106 : nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
200 [ - + ]: 106 : if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
201 : 0 : return store_E_InvalidChecksum;
202 : : else
203 : 106 : return store_E_None;
204 : : }
205 : : };
206 : :
207 : : /*========================================================================
208 : : *
209 : : * OStoreIndirectionPageObject.
210 : : *
211 : : *======================================================================*/
212 [ - + ]: 4521 : class OStoreIndirectionPageObject : public store::OStorePageObject
213 : : {
214 : : typedef OStorePageObject base;
215 : : typedef OStoreIndirectionPageData page;
216 : :
217 : : public:
218 : : /** Construction.
219 : : */
220 : 4521 : explicit OStoreIndirectionPageObject (PageHolder const & rxPage = PageHolder())
221 : 4521 : : OStorePageObject (rxPage)
222 : 4521 : {}
223 : :
224 : : /** External representation.
225 : : */
226 : : storeError loadOrCreate (
227 : : sal_uInt32 nAddr,
228 : : OStorePageBIOS & rBIOS);
229 : :
230 : : virtual storeError guard (sal_uInt32 nAddr);
231 : : virtual storeError verify (sal_uInt32 nAddr) const;
232 : :
233 : : /** read (indirect data page).
234 : : */
235 : : storeError read (
236 : : sal_uInt16 nSingle,
237 : : OStoreDataPageObject &rData,
238 : : OStorePageBIOS &rBIOS);
239 : :
240 : : storeError read (
241 : : sal_uInt16 nDouble,
242 : : sal_uInt16 nSingle,
243 : : OStoreDataPageObject &rData,
244 : : OStorePageBIOS &rBIOS);
245 : :
246 : : storeError read (
247 : : sal_uInt16 nTriple,
248 : : sal_uInt16 nDouble,
249 : : sal_uInt16 nSingle,
250 : : OStoreDataPageObject &rData,
251 : : OStorePageBIOS &rBIOS);
252 : :
253 : : /** write (indirect data page).
254 : : */
255 : : storeError write (
256 : : sal_uInt16 nSingle,
257 : : OStoreDataPageObject &rData,
258 : : OStorePageBIOS &rBIOS);
259 : :
260 : : storeError write (
261 : : sal_uInt16 nDouble,
262 : : sal_uInt16 nSingle,
263 : : OStoreDataPageObject &rData,
264 : : OStorePageBIOS &rBIOS);
265 : :
266 : : storeError write (
267 : : sal_uInt16 nTriple,
268 : : sal_uInt16 nDouble,
269 : : sal_uInt16 nSingle,
270 : : OStoreDataPageObject &rData,
271 : : OStorePageBIOS &rBIOS);
272 : :
273 : : /** truncate (indirect data page).
274 : : */
275 : : storeError truncate (
276 : : sal_uInt16 nSingle,
277 : : OStorePageBIOS &rBIOS);
278 : :
279 : : storeError truncate (
280 : : sal_uInt16 nDouble,
281 : : sal_uInt16 nSingle,
282 : : OStorePageBIOS &rBIOS);
283 : :
284 : : storeError truncate (
285 : : sal_uInt16 nTriple,
286 : : sal_uInt16 nDouble,
287 : : sal_uInt16 nSingle,
288 : : OStorePageBIOS &rBIOS);
289 : : };
290 : :
291 : : /*========================================================================
292 : : *
293 : : * OStorePageNameBlock.
294 : : *
295 : : *======================================================================*/
296 : : struct OStorePageNameBlock
297 : : {
298 : : typedef OStorePageGuard G;
299 : : typedef OStorePageKey K;
300 : :
301 : : /** Representation.
302 : : */
303 : : G m_aGuard;
304 : : K m_aKey;
305 : : sal_uInt32 m_nAttrib;
306 : : sal_Char m_pData[STORE_MAXIMUM_NAMESIZE];
307 : :
308 : : /** size.
309 : : */
310 : : static const size_t theSize = sizeof(G) + sizeof(K) + sizeof(sal_uInt32) + sizeof(sal_Char[STORE_MAXIMUM_NAMESIZE]);
311 : :
312 : : /** initialize.
313 : : */
314 : : void initialize (void)
315 : : {
316 : : m_aGuard = G();
317 : : m_aKey = K();
318 : : m_nAttrib = 0;
319 : : memset (m_pData, 0, sizeof(m_pData));
320 : : }
321 : :
322 : : /** Construction.
323 : : */
324 : 92838 : OStorePageNameBlock (void)
325 : 92838 : : m_aGuard(), m_aKey(), m_nAttrib (0)
326 : : {
327 : 92838 : memset (m_pData, 0, sizeof(m_pData));
328 : 92838 : }
329 : :
330 : : /** guard (external representation).
331 : : */
332 : 230608 : void guard()
333 : : {
334 : 230608 : sal_uInt32 nCRC32 = 0;
335 : 230608 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
336 : 230608 : nCRC32 = rtl_crc32 (nCRC32, &m_aKey, theSize - sizeof(G));
337 : 230608 : m_aGuard.m_nCRC32 = store::htonl(nCRC32);
338 : 230608 : }
339 : :
340 : : /** verify (external representation).
341 : : */
342 : 375789 : storeError verify() const
343 : : {
344 : 375789 : sal_uInt32 nCRC32 = 0;
345 : 375789 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
346 : 375789 : nCRC32 = rtl_crc32 (nCRC32, &m_aKey, theSize - sizeof(G));
347 [ - + ]: 375789 : if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
348 : 0 : return store_E_InvalidChecksum;
349 : : else
350 : 375789 : return store_E_None;
351 : : }
352 : : };
353 : :
354 : : /*========================================================================
355 : : *
356 : : * OStoreDirectoryDataBlock.
357 : : *
358 : : *======================================================================*/
359 : : #define STORE_LIMIT_DATAPAGE_DIRECT 16
360 : : #define STORE_LIMIT_DATAPAGE_SINGLE 8
361 : : #define STORE_LIMIT_DATAPAGE_DOUBLE 1
362 : : #define STORE_LIMIT_DATAPAGE_TRIPLE 1
363 : :
364 : : struct OStoreDirectoryDataBlock
365 : : {
366 : : typedef OStorePageGuard G;
367 : :
368 : : /** LinkDescriptor.
369 : : */
370 : : struct LinkDescriptor
371 : : {
372 : : /** Representation.
373 : : */
374 : : sal_uInt16 m_nIndex0;
375 : : sal_uInt16 m_nIndex1;
376 : : sal_uInt16 m_nIndex2;
377 : : sal_uInt16 m_nIndex3;
378 : :
379 : : /** Construction.
380 : : */
381 : 355437 : LinkDescriptor (void)
382 : : : m_nIndex0 ((sal_uInt16)(~0)),
383 : : m_nIndex1 ((sal_uInt16)(~0)),
384 : : m_nIndex2 ((sal_uInt16)(~0)),
385 : 355437 : m_nIndex3 ((sal_uInt16)(~0))
386 : 355437 : {}
387 : : };
388 : :
389 : : /** LinkTable.
390 : : */
391 : : struct LinkTable
392 : : {
393 : : /** Representation.
394 : : */
395 : : sal_uInt32 m_pDirect[STORE_LIMIT_DATAPAGE_DIRECT];
396 : : sal_uInt32 m_pSingle[STORE_LIMIT_DATAPAGE_SINGLE];
397 : : sal_uInt32 m_pDouble[STORE_LIMIT_DATAPAGE_DOUBLE];
398 : : sal_uInt32 m_pTriple[STORE_LIMIT_DATAPAGE_TRIPLE];
399 : :
400 : : /** initialize.
401 : : */
402 : 92838 : void initialize (void)
403 : : {
404 : 92838 : memset(m_pDirect, STORE_PAGE_NULL, sizeof(m_pDirect));
405 : 92838 : memset(m_pSingle, STORE_PAGE_NULL, sizeof(m_pSingle));
406 : 92838 : memset(m_pDouble, STORE_PAGE_NULL, sizeof(m_pDouble));
407 : 92838 : memset(m_pTriple, STORE_PAGE_NULL, sizeof(m_pTriple));
408 : 92838 : }
409 : :
410 : : /** Construction.
411 : : */
412 : 92838 : LinkTable (void)
413 : : {
414 : 92838 : initialize();
415 : 92838 : }
416 : : };
417 : :
418 : : /** Representation.
419 : : */
420 : : G m_aGuard;
421 : : LinkTable m_aTable;
422 : : sal_uInt32 m_nDataLen;
423 : :
424 : : /** size.
425 : : */
426 : : static const size_t theSize = sizeof(G) + sizeof(LinkTable) + sizeof(sal_uInt32);
427 : :
428 : : /** initialize.
429 : : */
430 : : void initialize (void)
431 : : {
432 : : m_aGuard = G();
433 : : m_aTable.initialize();
434 : : m_nDataLen = 0;
435 : : }
436 : :
437 : : /** Construction.
438 : : */
439 : 92838 : OStoreDirectoryDataBlock (void)
440 : 92838 : : m_aGuard(), m_aTable(), m_nDataLen (0)
441 : 92838 : {}
442 : :
443 : : /** guard (external representation).
444 : : */
445 : 230608 : void guard()
446 : : {
447 : 230608 : sal_uInt32 nCRC32 = 0;
448 : 230608 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
449 : 230608 : nCRC32 = rtl_crc32 (nCRC32, &m_aTable, theSize - sizeof(G));
450 : 230608 : m_aGuard.m_nCRC32 = store::htonl(nCRC32);
451 : 230608 : }
452 : :
453 : : /** verify (external representation).
454 : : */
455 : 375789 : storeError verify() const
456 : : {
457 : 375789 : sal_uInt32 nCRC32 = 0;
458 : 375789 : nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
459 : 375789 : nCRC32 = rtl_crc32 (nCRC32, &m_aTable, theSize - sizeof(G));
460 [ - + ]: 375789 : if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
461 : 0 : return store_E_InvalidChecksum;
462 : : else
463 : 375789 : return store_E_None;
464 : : }
465 : :
466 : : /** direct.
467 : : */
468 : 898877 : static sal_uInt16 directCount (void)
469 : : {
470 : 898877 : return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_DIRECT));
471 : : }
472 : 487060 : sal_uInt32 directLink (sal_uInt16 nIndex) const
473 : : {
474 [ + - ]: 487060 : if (nIndex < directCount())
475 : 487060 : return store::ntohl(m_aTable.m_pDirect[nIndex]);
476 : : else
477 : 487060 : return STORE_PAGE_NULL;
478 : : }
479 : 47304 : void directLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
480 : : {
481 [ + - ]: 47304 : if (nIndex < directCount())
482 : 47304 : m_aTable.m_pDirect[nIndex] = store::htonl(nAddr);
483 : 47304 : }
484 : :
485 : : /** single.
486 : : */
487 : 163363 : static sal_uInt16 singleCount (void)
488 : : {
489 : 163363 : return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_SINGLE));
490 : : }
491 : 77125 : sal_uInt32 singleLink (sal_uInt16 nIndex) const
492 : : {
493 [ + - ]: 77125 : if (nIndex < singleCount())
494 : 77125 : return store::ntohl(m_aTable.m_pSingle[nIndex]);
495 : : else
496 : 77125 : return STORE_PAGE_NULL;
497 : : }
498 : 72645 : void singleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
499 : : {
500 [ + - ]: 72645 : if (nIndex < singleCount())
501 : 72645 : m_aTable.m_pSingle[nIndex] = store::htonl(nAddr);
502 : 72645 : }
503 : :
504 : : /** double.
505 : : */
506 : 27228 : static sal_uInt16 doubleCount (void)
507 : : {
508 : 27228 : return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_DOUBLE));
509 : : }
510 : 9076 : sal_uInt32 doubleLink (sal_uInt16 nIndex) const
511 : : {
512 [ + - ]: 9076 : if (nIndex < doubleCount())
513 : 9076 : return store::ntohl(m_aTable.m_pDouble[nIndex]);
514 : : else
515 : 9076 : return STORE_PAGE_NULL;
516 : : }
517 : 9076 : void doubleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
518 : : {
519 [ + - ]: 9076 : if (nIndex < doubleCount())
520 : 9076 : m_aTable.m_pDouble[nIndex] = store::htonl(nAddr);
521 : 9076 : }
522 : :
523 : : /** triple.
524 : : */
525 : 27228 : static sal_uInt16 tripleCount (void)
526 : : {
527 : 27228 : return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_TRIPLE));
528 : : }
529 : 9076 : sal_uInt32 tripleLink (sal_uInt16 nIndex) const
530 : : {
531 [ + - ]: 9076 : if (nIndex < tripleCount())
532 : 9076 : return store::ntohl(m_aTable.m_pTriple[nIndex]);
533 : : else
534 : 9076 : return STORE_PAGE_NULL;
535 : : }
536 : 9076 : void tripleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
537 : : {
538 [ + - ]: 9076 : if (nIndex < tripleCount())
539 : 9076 : m_aTable.m_pTriple[nIndex] = store::htonl(nAddr);
540 : 9076 : }
541 : : };
542 : :
543 : : /*========================================================================
544 : : *
545 : : * OStoreDirectoryPageData.
546 : : *
547 : : *======================================================================*/
548 : : #define STORE_MAGIC_DIRECTORYPAGE sal_uInt32(0x62190120)
549 : :
550 : : struct OStoreDirectoryPageData : public store::OStorePageData
551 : : {
552 : : typedef OStorePageData base;
553 : : typedef OStoreDirectoryPageData self;
554 : :
555 : : typedef OStorePageDescriptor D;
556 : : typedef OStorePageNameBlock NameBlock;
557 : : typedef OStoreDirectoryDataBlock DataBlock;
558 : :
559 : : /** Representation.
560 : : */
561 : : NameBlock m_aNameBlock;
562 : : DataBlock m_aDataBlock;
563 : : sal_uInt8 m_pData[1];
564 : :
565 : : /** type.
566 : : */
567 : : static const sal_uInt32 theTypeId = STORE_MAGIC_DIRECTORYPAGE;
568 : :
569 : : /** size.
570 : : */
571 : : static const size_t theSize = NameBlock::theSize + DataBlock::theSize;
572 : : static const sal_uInt16 thePageSize = base::theSize + self::theSize;
573 : : STORE_STATIC_ASSERT(STORE_MINIMUM_PAGESIZE >= self::thePageSize);
574 : :
575 : : /** capacity.
576 : : */
577 : 2714331 : sal_uInt16 capacity() const
578 : : {
579 : 2714331 : return (store::ntohs(base::m_aDescr.m_nSize) - self::thePageSize);
580 : : }
581 : :
582 : : /** usage.
583 : : */
584 : : sal_uInt16 usage() const
585 : : {
586 : : return (store::ntohs(base::m_aDescr.m_nUsed) - self::thePageSize);
587 : : }
588 : :
589 : : /** initialize.
590 : : */
591 : : void initialize (void)
592 : : {
593 : : base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
594 : : base::m_aDescr.m_nUsed = store::htons(self::thePageSize);
595 : :
596 : : m_aNameBlock.initialize();
597 : : m_aDataBlock.initialize();
598 : :
599 : : memset (m_pData, 0, capacity());
600 : : }
601 : :
602 : : /** Construction.
603 : : */
604 : 92838 : explicit OStoreDirectoryPageData (sal_uInt16 nPageSize)
605 : 92838 : : base (nPageSize), m_aNameBlock(), m_aDataBlock()
606 : : {
607 : 92838 : base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
608 : 92838 : base::m_aDescr.m_nUsed = store::htons(self::thePageSize);
609 : 92838 : memset (m_pData, 0, capacity());
610 : 92838 : }
611 : :
612 : : /** guard (external representation).
613 : : */
614 : 230608 : void guard()
615 : : {
616 : 230608 : m_aNameBlock.guard();
617 : 230608 : m_aDataBlock.guard();
618 : 230608 : }
619 : :
620 : : /** verify (external representation).
621 : : */
622 : 375789 : storeError verify() const
623 : : {
624 : 375789 : storeError eErrCode = m_aNameBlock.verify();
625 [ + - ]: 375789 : if (eErrCode == store_E_None)
626 : 375789 : eErrCode = m_aDataBlock.verify();
627 : 375789 : return eErrCode;
628 : : }
629 : :
630 : : /** ChunkDescriptor.
631 : : */
632 : : struct ChunkDescriptor
633 : : {
634 : : /** Representation.
635 : : */
636 : : sal_uInt32 m_nPage;
637 : : sal_uInt16 m_nOffset;
638 : : sal_uInt16 m_nLength;
639 : :
640 : : /** Construction.
641 : : */
642 : 1286895 : ChunkDescriptor (sal_uInt32 nPosition, sal_uInt16 nCapacity)
643 : : {
644 : 1286895 : m_nPage = nPosition / nCapacity;
645 : 1286895 : m_nOffset = (sal_uInt16)((nPosition % nCapacity) & 0xffff);
646 : 1286895 : m_nLength = nCapacity - m_nOffset;
647 : 1286895 : }
648 : : };
649 : :
650 : : /** ChunkScope.
651 : : */
652 : : enum ChunkScope
653 : : {
654 : : SCOPE_INTERNAL,
655 : : SCOPE_EXTERNAL,
656 : : SCOPE_DIRECT,
657 : : SCOPE_SINGLE,
658 : : SCOPE_DOUBLE,
659 : : SCOPE_TRIPLE,
660 : : SCOPE_UNREACHABLE,
661 : : SCOPE_UNKNOWN
662 : : };
663 : :
664 : : /** scope (internal).
665 : : */
666 : 1334580 : ChunkScope scope (sal_uInt32 nPosition) const
667 : : {
668 : 1334580 : sal_uInt32 nCapacity = capacity();
669 [ + + ]: 1334580 : if (nPosition < nCapacity)
670 : 1005624 : return SCOPE_INTERNAL;
671 : : else
672 : 1334580 : return SCOPE_EXTERNAL;
673 : : }
674 : : };
675 : :
676 : : /*========================================================================
677 : : *
678 : : * OStoreDirectoryPageObject.
679 : : *
680 : : *======================================================================*/
681 [ - + ]: 3229540 : class OStoreDirectoryPageObject : public store::OStorePageObject
682 : : {
683 : : typedef OStorePageObject base;
684 : : typedef OStoreDirectoryPageData page;
685 : : typedef OStoreIndirectionPageData indirect;
686 : :
687 : : typedef OStorePageDescriptor D;
688 : :
689 : : public:
690 : : /** Construction.
691 : : */
692 : 3229540 : explicit OStoreDirectoryPageObject (PageHolder const & rxPage = PageHolder())
693 : 3229540 : : OStorePageObject (rxPage)
694 : 3229540 : {}
695 : :
696 : : /** External representation.
697 : : */
698 : : virtual storeError guard (sal_uInt32 nAddr);
699 : : virtual storeError verify (sal_uInt32 nAddr) const;
700 : :
701 : : /** attrib.
702 : : */
703 : 2712838 : sal_uInt32 attrib (void) const
704 : : {
705 : 2712838 : return store::ntohl(PAGE().m_aNameBlock.m_nAttrib);
706 : : }
707 : 92838 : void attrib (sal_uInt32 nAttrib)
708 : : {
709 : 92838 : PAGE().m_aNameBlock.m_nAttrib = store::htonl(nAttrib);
710 : 92838 : touch();
711 : 92838 : }
712 : :
713 : : /** key.
714 : : */
715 : 0 : OStorePageKey key (void) const
716 : : {
717 : 0 : return PAGE().m_aNameBlock.m_aKey;
718 : : }
719 : 92838 : void key (OStorePageKey const & rKey)
720 : : {
721 : 92838 : PAGE().m_aNameBlock.m_aKey = rKey;
722 : 92838 : touch();
723 : 92838 : }
724 : :
725 : : /** path.
726 : : */
727 : 559413 : sal_uInt32 path (void) const
728 : : {
729 : 559413 : page const & rPage = PAGE();
730 : 559413 : const sal_Char * pszName = rPage.m_aNameBlock.m_pData;
731 : 559413 : sal_uInt32 nPath = store::ntohl(rPage.m_aNameBlock.m_aKey.m_nHigh);
732 : 559413 : return rtl_crc32 (nPath, pszName, rtl_str_getLength(pszName));
733 : : }
734 : :
735 : : sal_Size getName (sal_Char * pBuffer, sal_Size nBufsiz) const
736 : : {
737 : : sal_Char const * pszName = PAGE().m_aNameBlock.m_pData;
738 : : sal_Size nLength = rtl_str_getLength(pszName);
739 : : memcpy (pBuffer, pszName, SAL_MIN(nLength, nBufsiz));
740 : : return nLength;
741 : : }
742 : :
743 : : /** dataLength.
744 : : */
745 : 1360354 : sal_uInt32 dataLength (void) const
746 : : {
747 : 1360354 : return store::ntohl(PAGE().m_aDataBlock.m_nDataLen);
748 : : }
749 : 173787 : void dataLength (sal_uInt32 nLength)
750 : : {
751 : 173787 : PAGE().m_aDataBlock.m_nDataLen = store::htonl(nLength);
752 : 173787 : touch();
753 : 173787 : }
754 : :
755 : : /** direct.
756 : : */
757 : 487060 : sal_uInt32 directLink (sal_uInt16 nIndex) const
758 : : {
759 : 487060 : return PAGE().m_aDataBlock.directLink (nIndex);
760 : : }
761 : 47304 : void directLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
762 : : {
763 : 47304 : PAGE().m_aDataBlock.directLink (nIndex, nAddr);
764 : 47304 : touch();
765 : 47304 : }
766 : :
767 : : /** single indirect.
768 : : */
769 : 77125 : sal_uInt32 singleLink (sal_uInt16 nIndex) const
770 : : {
771 : 77125 : return PAGE().m_aDataBlock.singleLink (nIndex);
772 : : }
773 : 72645 : void singleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
774 : : {
775 : 72645 : PAGE().m_aDataBlock.singleLink (nIndex, nAddr);
776 : 72645 : touch();
777 : 72645 : }
778 : :
779 : : /** double indirect.
780 : : */
781 : 9076 : sal_uInt32 doubleLink (sal_uInt16 nIndex) const
782 : : {
783 : 9076 : return PAGE().m_aDataBlock.doubleLink (nIndex);
784 : : }
785 : 9076 : void doubleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
786 : : {
787 : 9076 : PAGE().m_aDataBlock.doubleLink (nIndex, nAddr);
788 : 9076 : touch();
789 : 9076 : }
790 : :
791 : : /** triple indirect.
792 : : */
793 : 9076 : sal_uInt32 tripleLink (sal_uInt16 nIndex) const
794 : : {
795 : 9076 : return PAGE().m_aDataBlock.tripleLink (nIndex);
796 : : }
797 : 9076 : void tripleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
798 : : {
799 : 9076 : PAGE().m_aDataBlock.tripleLink (nIndex, nAddr);
800 : 9076 : touch();
801 : 9076 : }
802 : :
803 : : /** read (external data page).
804 : : */
805 : : storeError read (
806 : : sal_uInt32 nPage,
807 : : OStoreDataPageObject &rData,
808 : : OStorePageBIOS &rBIOS);
809 : :
810 : : /** write (external data page).
811 : : */
812 : : storeError write (
813 : : sal_uInt32 nPage,
814 : : OStoreDataPageObject &rData,
815 : : OStorePageBIOS &rBIOS);
816 : :
817 : : /** truncate (external data page).
818 : : */
819 : : storeError truncate (
820 : : sal_uInt32 nPage,
821 : : OStorePageBIOS &rBIOS);
822 : :
823 : : private:
824 : : /** Representation.
825 : : */
826 : 533868 : page & PAGE()
827 : : {
828 : 533868 : page * pImpl = static_cast<page*>(m_xPage.get());
829 : : OSL_PRECOND(pImpl != 0, "OStoreDirectoryPageObject::PAGE(): Null pointer");
830 : 533868 : return (*pImpl);
831 : : }
832 : 5570379 : page const & PAGE() const
833 : : {
834 : 5570379 : page const * pImpl = static_cast<page const *>(m_xPage.get());
835 : : OSL_PRECOND(pImpl != 0, "OStoreDirectoryPageObject::PAGE(): Null pointer");
836 : 5570379 : return (*pImpl);
837 : : }
838 : :
839 : : /** scope (external data page; private).
840 : : */
841 : : page::ChunkScope scope (
842 : : sal_uInt32 nPage,
843 : : page::DataBlock::LinkDescriptor &rDescr) const;
844 : :
845 : : /** truncate (external data page scope; private).
846 : : */
847 : : storeError truncate (
848 : : page::ChunkScope eScope,
849 : : sal_uInt16 nRemain,
850 : : OStorePageBIOS &rBIOS);
851 : : };
852 : :
853 : : /*========================================================================
854 : : *
855 : : * The End.
856 : : *
857 : : *======================================================================*/
858 : :
859 : : } // namespace store
860 : :
861 : : #endif /* !_STORE_STORDATA_HXX_ */
862 : :
863 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|