netwerk/cache/nsDiskCacheBlockFile.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache/nsDiskCacheBlockFile.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim: set sw=4 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef _nsDiskCacheBlockFile_h_
    1.11 +#define _nsDiskCacheBlockFile_h_
    1.12 +
    1.13 +#include "mozilla/MemoryReporting.h"
    1.14 +#include "nsIFile.h"
    1.15 +#include "nsDiskCache.h"
    1.16 +
    1.17 +/******************************************************************************
    1.18 + *  nsDiskCacheBlockFile
    1.19 + *
    1.20 + *  The structure of a cache block file is a 4096 bytes bit map, followed by
    1.21 + *  some number of blocks of mBlockSize.  The creator of a
    1.22 + *  nsDiskCacheBlockFile object must provide the block size for a given file.
    1.23 + *
    1.24 + *****************************************************************************/
    1.25 +class nsDiskCacheBlockFile {
    1.26 +public:
    1.27 +    nsDiskCacheBlockFile()
    1.28 +           : mFD(nullptr)
    1.29 +           , mBitMap(nullptr)
    1.30 +           , mBlockSize(0)
    1.31 +           , mBitMapWords(0)
    1.32 +           , mFileSize(0)
    1.33 +           , mBitMapDirty(false)
    1.34 +            {}
    1.35 +    ~nsDiskCacheBlockFile() { (void) Close(true); }
    1.36 +    
    1.37 +    nsresult  Open( nsIFile *  blockFile, uint32_t  blockSize,
    1.38 +                    uint32_t  bitMapSize, nsDiskCache::CorruptCacheInfo *  corruptInfo);
    1.39 +    nsresult  Close(bool flush);
    1.40 +
    1.41 +    /*
    1.42 +     * Trim
    1.43 +     * Truncates the block file to the end of the last allocated block.
    1.44 +     */
    1.45 +    nsresult  Trim() { return nsDiskCache::Truncate(mFD, CalcBlockFileSize()); }
    1.46 +    nsresult  DeallocateBlocks( int32_t  startBlock, int32_t  numBlocks);
    1.47 +    nsresult  WriteBlocks( void * buffer, uint32_t size, int32_t  numBlocks, 
    1.48 +                           int32_t * startBlock);
    1.49 +    nsresult  ReadBlocks( void * buffer, int32_t  startBlock, int32_t  numBlocks, 
    1.50 +                          int32_t * bytesRead);
    1.51 +
    1.52 +    size_t   SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
    1.53 +
    1.54 +private:
    1.55 +    nsresult  FlushBitMap();
    1.56 +    int32_t   AllocateBlocks( int32_t  numBlocks);
    1.57 +    nsresult  VerifyAllocation( int32_t startBlock, int32_t numBLocks);
    1.58 +    uint32_t  CalcBlockFileSize();
    1.59 +    bool   Write(int32_t offset, const void *buf, int32_t amount);
    1.60 +
    1.61 +/**
    1.62 + *  Data members
    1.63 + */
    1.64 +    PRFileDesc *                mFD;
    1.65 +    uint32_t *                  mBitMap;      // XXX future: array of bit map blocks
    1.66 +    uint32_t                    mBlockSize;
    1.67 +    uint32_t                    mBitMapWords;
    1.68 +    int32_t                     mFileSize;
    1.69 +    bool                        mBitMapDirty;
    1.70 +};
    1.71 +
    1.72 +#endif // _nsDiskCacheBlockFile_h_

mercurial