/src/mozilla-central/netwerk/cache/nsDiskCacheBlockFile.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef _nsDiskCacheBlockFile_h_ |
8 | | #define _nsDiskCacheBlockFile_h_ |
9 | | |
10 | | #include "mozilla/MemoryReporting.h" |
11 | | #include "nsIFile.h" |
12 | | #include "nsDiskCache.h" |
13 | | |
14 | | /****************************************************************************** |
15 | | * nsDiskCacheBlockFile |
16 | | * |
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. |
20 | | * |
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) |
31 | 0 | {} |
32 | 0 | ~nsDiskCacheBlockFile() { (void) Close(true); } |
33 | | |
34 | | nsresult Open( nsIFile * blockFile, uint32_t blockSize, |
35 | | uint32_t bitMapSize, nsDiskCache::CorruptCacheInfo * corruptInfo); |
36 | | nsresult Close(bool flush); |
37 | | |
38 | | /* |
39 | | * Trim |
40 | | * Truncates the block file to the end of the last allocated block. |
41 | | */ |
42 | 0 | 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); |
48 | | |
49 | | size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf); |
50 | | |
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); |
57 | | |
58 | | /** |
59 | | * Data members |
60 | | */ |
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; |
67 | | }; |
68 | | |
69 | | #endif // _nsDiskCacheBlockFile_h_ |