Bumping manifests a=b2g-bump
[gecko.git] / netwerk / cache / nsDiskCacheBlockFile.h
blob058cc7fcca97227adf0880333d34d31b29d1e322
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set sw=4 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _nsDiskCacheBlockFile_h_
8 #define _nsDiskCacheBlockFile_h_
10 #include "mozilla/MemoryReporting.h"
11 #include "nsIFile.h"
12 #include "nsDiskCache.h"
14 /******************************************************************************
15 * nsDiskCacheBlockFile
17 * The structure of a cache block file is a 4096 bytes bit map, followed by
18 * some number of blocks of mBlockSize. The creator of a
19 * nsDiskCacheBlockFile object must provide the block size for a given file.
21 *****************************************************************************/
22 class nsDiskCacheBlockFile {
23 public:
24 nsDiskCacheBlockFile()
25 : mFD(nullptr)
26 , mBitMap(nullptr)
27 , mBlockSize(0)
28 , mBitMapWords(0)
29 , mFileSize(0)
30 , mBitMapDirty(false)
32 ~nsDiskCacheBlockFile() { (void) Close(true); }
34 nsresult Open( nsIFile * blockFile, uint32_t blockSize,
35 uint32_t bitMapSize, nsDiskCache::CorruptCacheInfo * corruptInfo);
36 nsresult Close(bool flush);
39 * Trim
40 * Truncates the block file to the end of the last allocated block.
42 nsresult Trim() { return nsDiskCache::Truncate(mFD, CalcBlockFileSize()); }
43 nsresult DeallocateBlocks( int32_t startBlock, int32_t numBlocks);
44 nsresult WriteBlocks( void * buffer, uint32_t size, int32_t numBlocks,
45 int32_t * startBlock);
46 nsresult ReadBlocks( void * buffer, int32_t startBlock, int32_t numBlocks,
47 int32_t * bytesRead);
49 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
51 private:
52 nsresult FlushBitMap();
53 int32_t AllocateBlocks( int32_t numBlocks);
54 nsresult VerifyAllocation( int32_t startBlock, int32_t numBLocks);
55 uint32_t CalcBlockFileSize();
56 bool Write(int32_t offset, const void *buf, int32_t amount);
58 /**
59 * Data members
61 PRFileDesc * mFD;
62 uint32_t * mBitMap; // XXX future: array of bit map blocks
63 uint32_t mBlockSize;
64 uint32_t mBitMapWords;
65 int32_t mFileSize;
66 bool mBitMapDirty;
69 #endif // _nsDiskCacheBlockFile_h_