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

Generated by: LCOV version 1.10