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"
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
{
24 nsDiskCacheBlockFile()
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
);
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
,
49 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
);
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
);
62 uint32_t * mBitMap
; // XXX future: array of bit map blocks
64 uint32_t mBitMapWords
;
69 #endif // _nsDiskCacheBlockFile_h_