LCOV - code coverage report
Current view: top level - libreoffice/store/source - stordata.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 217 40.1 %
Date: 2012-12-17 Functions: 30 65 46.2 %
Legend: Lines: hit not hit

          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       31074 :     static sal_uInt16 capacity (const D& rDescr) // @see inode::ChunkDescriptor
      63             :     {
      64       31074 :         return (store::ntohs(rDescr.m_nSize) - self::thePageSize);
      65             :     }
      66           0 :     sal_uInt16 capacity() const
      67             :     {
      68           0 :         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           0 :     explicit OStoreDataPageData (sal_uInt16 nPageSize = self::thePageSize)
      81           0 :         : base (nPageSize)
      82             :     {
      83           0 :         base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
      84           0 :         base::m_aDescr.m_nUsed  = store::htons(self::thePageSize);
      85           0 :         if (capacity()) memset (m_pData, 0, capacity());
      86           0 :     }
      87             : 
      88             :     /** guard (external representation).
      89             :     */
      90           0 :     void guard() {}
      91             : 
      92             :     /** verify (external representation).
      93             :     */
      94       27772 :     storeError verify() const { return store_E_None; }
      95             : };
      96             : 
      97             : /*========================================================================
      98             :  *
      99             :  * OStoreDataPageObject.
     100             :  *
     101             :  *======================================================================*/
     102       84842 : class OStoreDataPageObject : public store::OStorePageObject
     103             : {
     104             :     typedef OStorePageObject     base;
     105             :     typedef OStoreDataPageData   page;
     106             : 
     107             : public:
     108             :     /** Construction.
     109             :     */
     110       84842 :     explicit OStoreDataPageObject (PageHolder const & rxPage = PageHolder())
     111       84842 :         : OStorePageObject (rxPage)
     112       84842 :     {}
     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        1084 :     static sal_uInt16 capacity (const D& rDescr)
     153             :     {
     154        1084 :         return (store::ntohs(rDescr.m_nSize) - self::thePageSize);
     155             :     }
     156         554 :     sal_uInt16 capacity() const
     157             :     {
     158         554 :         return self::capacity (base::m_aDescr);
     159             :     }
     160             : 
     161             :     /** capacityCount.
     162             :     */
     163         530 :     static sal_uInt16 capacityCount (const D& rDescr) // @see DirectoryPageObject::scope()
     164             :     {
     165         530 :         return sal_uInt16(capacity(rDescr) / sizeof(sal_uInt32));
     166             :     }
     167         530 :     sal_uInt16 capacityCount() const
     168             :     {
     169         530 :         return sal_uInt16(capacity() / sizeof(sal_uInt32));
     170             :     }
     171             : 
     172             :     /** Construction.
     173             :     */
     174           0 :     explicit OStoreIndirectionPageData (sal_uInt16 nPageSize)
     175           0 :         : base (nPageSize)
     176             :     {
     177           0 :         base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
     178           0 :         base::m_aDescr.m_nUsed  = store::htons(self::thePageSize);
     179           0 :         self::m_aGuard.m_nMagic = store::htonl(0);
     180           0 :         memset (m_pData, STORE_PAGE_NULL, capacity());
     181           0 :     }
     182             : 
     183             :     /** guard (external representation).
     184             :     */
     185           0 :     void guard()
     186             :     {
     187           0 :         sal_uInt32 nCRC32 = 0;
     188           0 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     189           0 :         nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
     190           0 :         m_aGuard.m_nCRC32 = store::htonl(nCRC32);
     191           0 :     }
     192             : 
     193             :     /** verify (external representation).
     194             :     */
     195          24 :     storeError verify() const
     196             :     {
     197          24 :         sal_uInt32 nCRC32 = 0;
     198          24 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     199          24 :         nCRC32 = rtl_crc32 (nCRC32, m_pData, capacity());
     200          24 :         if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
     201           0 :             return store_E_InvalidChecksum;
     202             :         else
     203          24 :             return store_E_None;
     204             :     }
     205             : };
     206             : 
     207             : /*========================================================================
     208             :  *
     209             :  * OStoreIndirectionPageObject.
     210             :  *
     211             :  *======================================================================*/
     212         530 : class OStoreIndirectionPageObject : public store::OStorePageObject
     213             : {
     214             :     typedef OStorePageObject          base;
     215             :     typedef OStoreIndirectionPageData page;
     216             : 
     217             : public:
     218             :     /** Construction.
     219             :     */
     220         530 :     explicit OStoreIndirectionPageObject (PageHolder const & rxPage = PageHolder())
     221         530 :         : OStorePageObject (rxPage)
     222         530 :     {}
     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           0 :     OStorePageNameBlock (void)
     325           0 :         : m_aGuard(), m_aKey(), m_nAttrib (0)
     326             :     {
     327           0 :         memset (m_pData, 0, sizeof(m_pData));
     328           0 :     }
     329             : 
     330             :     /** guard (external representation).
     331             :     */
     332           0 :     void guard()
     333             :     {
     334           0 :         sal_uInt32 nCRC32 = 0;
     335           0 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     336           0 :         nCRC32 = rtl_crc32 (nCRC32, &m_aKey, theSize - sizeof(G));
     337           0 :         m_aGuard.m_nCRC32 = store::htonl(nCRC32);
     338           0 :     }
     339             : 
     340             :     /** verify (external representation).
     341             :     */
     342       39404 :     storeError verify() const
     343             :     {
     344       39404 :         sal_uInt32 nCRC32 = 0;
     345       39404 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     346       39404 :         nCRC32 = rtl_crc32 (nCRC32, &m_aKey, theSize - sizeof(G));
     347       39404 :         if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
     348           0 :             return store_E_InvalidChecksum;
     349             :         else
     350       39404 :             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       31074 :         LinkDescriptor (void)
     382             :             : m_nIndex0 ((sal_uInt16)(~0)),
     383             :               m_nIndex1 ((sal_uInt16)(~0)),
     384             :               m_nIndex2 ((sal_uInt16)(~0)),
     385       31074 :               m_nIndex3 ((sal_uInt16)(~0))
     386       31074 :         {}
     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           0 :         void initialize (void)
     403             :         {
     404           0 :           memset(m_pDirect, STORE_PAGE_NULL, sizeof(m_pDirect));
     405           0 :           memset(m_pSingle, STORE_PAGE_NULL, sizeof(m_pSingle));
     406           0 :           memset(m_pDouble, STORE_PAGE_NULL, sizeof(m_pDouble));
     407           0 :           memset(m_pTriple, STORE_PAGE_NULL, sizeof(m_pTriple));
     408           0 :         }
     409             : 
     410             :         /** Construction.
     411             :         */
     412           0 :         LinkTable (void)
     413             :         {
     414           0 :           initialize();
     415           0 :         }
     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           0 :     OStoreDirectoryDataBlock (void)
     440           0 :         : m_aGuard(), m_aTable(), m_nDataLen (0)
     441           0 :     {}
     442             : 
     443             :     /** guard (external representation).
     444             :     */
     445           0 :     void guard()
     446             :     {
     447           0 :         sal_uInt32 nCRC32 = 0;
     448           0 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     449           0 :         nCRC32 = rtl_crc32 (nCRC32, &m_aTable, theSize - sizeof(G));
     450           0 :         m_aGuard.m_nCRC32 = store::htonl(nCRC32);
     451           0 :     }
     452             : 
     453             :     /** verify (external representation).
     454             :     */
     455       39404 :     storeError verify() const
     456             :     {
     457       39404 :         sal_uInt32 nCRC32 = 0;
     458       39404 :         nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
     459       39404 :         nCRC32 = rtl_crc32 (nCRC32, &m_aTable, theSize - sizeof(G));
     460       39404 :         if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
     461           0 :             return store_E_InvalidChecksum;
     462             :         else
     463       39404 :             return store_E_None;
     464             :     }
     465             : 
     466             :     /** direct.
     467             :     */
     468       61618 :     static sal_uInt16 directCount (void)
     469             :     {
     470       61618 :         return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_DIRECT));
     471             :     }
     472       30544 :     sal_uInt32 directLink (sal_uInt16 nIndex) const
     473             :     {
     474       30544 :         if (nIndex < directCount())
     475       30544 :             return store::ntohl(m_aTable.m_pDirect[nIndex]);
     476             :         else
     477           0 :             return STORE_PAGE_NULL;
     478             :     }
     479           0 :     void directLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     480             :     {
     481           0 :         if (nIndex < directCount())
     482           0 :             m_aTable.m_pDirect[nIndex] = store::htonl(nAddr);
     483           0 :     }
     484             : 
     485             :     /** single.
     486             :     */
     487        1060 :     static sal_uInt16 singleCount (void)
     488             :     {
     489        1060 :         return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_SINGLE));
     490             :     }
     491         530 :     sal_uInt32 singleLink (sal_uInt16 nIndex) const
     492             :     {
     493         530 :         if (nIndex < singleCount())
     494         530 :             return store::ntohl(m_aTable.m_pSingle[nIndex]);
     495             :         else
     496           0 :             return STORE_PAGE_NULL;
     497             :     }
     498           0 :     void singleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     499             :     {
     500           0 :         if (nIndex < singleCount())
     501           0 :             m_aTable.m_pSingle[nIndex] = store::htonl(nAddr);
     502           0 :     }
     503             : 
     504             :     /** double.
     505             :     */
     506           0 :     static sal_uInt16 doubleCount (void)
     507             :     {
     508           0 :         return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_DOUBLE));
     509             :     }
     510           0 :     sal_uInt32 doubleLink (sal_uInt16 nIndex) const
     511             :     {
     512           0 :         if (nIndex < doubleCount())
     513           0 :             return store::ntohl(m_aTable.m_pDouble[nIndex]);
     514             :         else
     515           0 :             return STORE_PAGE_NULL;
     516             :     }
     517           0 :     void doubleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     518             :     {
     519           0 :         if (nIndex < doubleCount())
     520           0 :             m_aTable.m_pDouble[nIndex] = store::htonl(nAddr);
     521           0 :     }
     522             : 
     523             :     /** triple.
     524             :     */
     525           0 :     static sal_uInt16 tripleCount (void)
     526             :     {
     527           0 :         return ((sal_uInt16)(STORE_LIMIT_DATAPAGE_TRIPLE));
     528             :     }
     529           0 :     sal_uInt32 tripleLink (sal_uInt16 nIndex) const
     530             :     {
     531           0 :         if (nIndex < tripleCount())
     532           0 :             return store::ntohl(m_aTable.m_pTriple[nIndex]);
     533             :         else
     534           0 :             return STORE_PAGE_NULL;
     535             :     }
     536           0 :     void tripleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     537             :     {
     538           0 :         if (nIndex < tripleCount())
     539           0 :             m_aTable.m_pTriple[nIndex] = store::htonl(nAddr);
     540           0 :     }
     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      231832 :     sal_uInt16 capacity() const
     578             :     {
     579      231832 :         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           0 :     explicit OStoreDirectoryPageData (sal_uInt16 nPageSize)
     605           0 :         : base (nPageSize), m_aNameBlock(), m_aDataBlock()
     606             :     {
     607           0 :         base::m_aGuard.m_nMagic = store::htonl(self::theTypeId);
     608           0 :         base::m_aDescr.m_nUsed  = store::htons(self::thePageSize);
     609           0 :         memset (m_pData, 0, capacity());
     610           0 :     }
     611             : 
     612             :     /** guard (external representation).
     613             :     */
     614           0 :     void guard()
     615             :     {
     616           0 :         m_aNameBlock.guard();
     617           0 :         m_aDataBlock.guard();
     618           0 :     }
     619             : 
     620             :     /** verify (external representation).
     621             :     */
     622       39404 :     storeError verify() const
     623             :     {
     624       39404 :         storeError eErrCode = m_aNameBlock.verify();
     625       39404 :         if (eErrCode == store_E_None)
     626       39404 :             eErrCode = m_aDataBlock.verify();
     627       39404 :         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      115916 :         ChunkDescriptor (sal_uInt32 nPosition, sal_uInt16 nCapacity)
     643             :         {
     644      115916 :             m_nPage   = nPosition / nCapacity;
     645      115916 :             m_nOffset = (sal_uInt16)((nPosition % nCapacity) & 0xffff);
     646      115916 :             m_nLength = nCapacity - m_nOffset;
     647      115916 :         }
     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      115916 :     ChunkScope scope (sal_uInt32 nPosition) const
     667             :     {
     668      115916 :         sal_uInt32 nCapacity = capacity();
     669      115916 :         if (nPosition < nCapacity)
     670       84842 :             return SCOPE_INTERNAL;
     671             :         else
     672       31074 :             return SCOPE_EXTERNAL;
     673             :     }
     674             : };
     675             : 
     676             : /*========================================================================
     677             :  *
     678             :  * OStoreDirectoryPageObject.
     679             :  *
     680             :  *======================================================================*/
     681      193603 : 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      193603 :     explicit OStoreDirectoryPageObject (PageHolder const & rxPage = PageHolder())
     693      193603 :         : OStorePageObject (rxPage)
     694      193603 :     {}
     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      172116 :     sal_uInt32 attrib (void) const
     704             :     {
     705      172116 :         return store::ntohl(PAGE().m_aNameBlock.m_nAttrib);
     706             :     }
     707           0 :     void attrib (sal_uInt32 nAttrib)
     708             :     {
     709           0 :         PAGE().m_aNameBlock.m_nAttrib = store::htonl(nAttrib);
     710           0 :         touch();
     711           0 :     }
     712             : 
     713             :     /** key.
     714             :     */
     715           0 :     OStorePageKey key (void) const
     716             :     {
     717           0 :         return PAGE().m_aNameBlock.m_aKey;
     718             :     }
     719           0 :     void key (OStorePageKey const & rKey)
     720             :     {
     721           0 :         PAGE().m_aNameBlock.m_aKey = rKey;
     722           0 :         touch();
     723           0 :     }
     724             : 
     725             :     /** path.
     726             :     */
     727       20295 :     sal_uInt32 path (void) const
     728             :     {
     729       20295 :         page const & rPage = PAGE();
     730       20295 :         const sal_Char * pszName = rPage.m_aNameBlock.m_pData;
     731       20295 :         sal_uInt32       nPath   = store::ntohl(rPage.m_aNameBlock.m_aKey.m_nHigh);
     732       20295 :         return rtl_crc32 (nPath, pszName, rtl_str_getLength(pszName));
     733             :     }
     734             : 
     735             :     sal_Size getName (sal_Char * pBuffer, sal_Size nBufsize) const
     736             :     {
     737             :         sal_Char const * pszName = PAGE().m_aNameBlock.m_pData;
     738             :         sal_Size nLength = rtl_str_getLength(pszName);
     739             :         memcpy (pBuffer, pszName, nLength < nBufsize ? nLength : nBufsize);
     740             :         return nLength;
     741             :     }
     742             : 
     743             :     /** dataLength.
     744             :     */
     745       89122 :     sal_uInt32 dataLength (void) const
     746             :     {
     747       89122 :         return store::ntohl(PAGE().m_aDataBlock.m_nDataLen);
     748             :     }
     749           0 :     void dataLength (sal_uInt32 nLength)
     750             :     {
     751           0 :         PAGE().m_aDataBlock.m_nDataLen = store::htonl(nLength);
     752           0 :         touch();
     753           0 :     }
     754             : 
     755             :     /** direct.
     756             :     */
     757       30544 :     sal_uInt32 directLink (sal_uInt16 nIndex) const
     758             :     {
     759       30544 :         return PAGE().m_aDataBlock.directLink (nIndex);
     760             :     }
     761           0 :     void directLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     762             :     {
     763           0 :         PAGE().m_aDataBlock.directLink (nIndex, nAddr);
     764           0 :         touch();
     765           0 :     }
     766             : 
     767             :     /** single indirect.
     768             :     */
     769         530 :     sal_uInt32 singleLink (sal_uInt16 nIndex) const
     770             :     {
     771         530 :         return PAGE().m_aDataBlock.singleLink (nIndex);
     772             :     }
     773           0 :     void singleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     774             :     {
     775           0 :         PAGE().m_aDataBlock.singleLink (nIndex, nAddr);
     776           0 :         touch();
     777           0 :     }
     778             : 
     779             :     /** double indirect.
     780             :     */
     781           0 :     sal_uInt32 doubleLink (sal_uInt16 nIndex) const
     782             :     {
     783           0 :         return PAGE().m_aDataBlock.doubleLink (nIndex);
     784             :     }
     785           0 :     void doubleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     786             :     {
     787           0 :         PAGE().m_aDataBlock.doubleLink (nIndex, nAddr);
     788           0 :         touch();
     789           0 :     }
     790             : 
     791             :     /** triple indirect.
     792             :     */
     793           0 :     sal_uInt32 tripleLink (sal_uInt16 nIndex) const
     794             :     {
     795           0 :         return PAGE().m_aDataBlock.tripleLink (nIndex);
     796             :     }
     797           0 :     void tripleLink (sal_uInt16 nIndex, sal_uInt32 nAddr)
     798             :     {
     799           0 :         PAGE().m_aDataBlock.tripleLink (nIndex, nAddr);
     800           0 :         touch();
     801           0 :     }
     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           0 :     page & PAGE()
     827             :     {
     828           0 :         page * pImpl = static_cast<page*>(m_xPage.get());
     829             :         OSL_PRECOND(pImpl != 0, "OStoreDirectoryPageObject::PAGE(): Null pointer");
     830           0 :         return (*pImpl);
     831             :     }
     832      343681 :     page const & PAGE() const
     833             :     {
     834      343681 :         page const * pImpl = static_cast<page const *>(m_xPage.get());
     835             :         OSL_PRECOND(pImpl != 0, "OStoreDirectoryPageObject::PAGE(): Null pointer");
     836      343681 :         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: */

Generated by: LCOV version 1.10