summaryrefslogtreecommitdiffstats
path: root/netwerk/cache/nsDiskCacheBlockFile.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/cache/nsDiskCacheBlockFile.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/cache/nsDiskCacheBlockFile.h')
-rw-r--r--netwerk/cache/nsDiskCacheBlockFile.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/netwerk/cache/nsDiskCacheBlockFile.h b/netwerk/cache/nsDiskCacheBlockFile.h
new file mode 100644
index 000000000..058cc7fcc
--- /dev/null
+++ b/netwerk/cache/nsDiskCacheBlockFile.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set sw=4 ts=8 et tw=80 : */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef _nsDiskCacheBlockFile_h_
+#define _nsDiskCacheBlockFile_h_
+
+#include "mozilla/MemoryReporting.h"
+#include "nsIFile.h"
+#include "nsDiskCache.h"
+
+/******************************************************************************
+ * nsDiskCacheBlockFile
+ *
+ * The structure of a cache block file is a 4096 bytes bit map, followed by
+ * some number of blocks of mBlockSize. The creator of a
+ * nsDiskCacheBlockFile object must provide the block size for a given file.
+ *
+ *****************************************************************************/
+class nsDiskCacheBlockFile {
+public:
+ nsDiskCacheBlockFile()
+ : mFD(nullptr)
+ , mBitMap(nullptr)
+ , mBlockSize(0)
+ , mBitMapWords(0)
+ , mFileSize(0)
+ , mBitMapDirty(false)
+ {}
+ ~nsDiskCacheBlockFile() { (void) Close(true); }
+
+ nsresult Open( nsIFile * blockFile, uint32_t blockSize,
+ uint32_t bitMapSize, nsDiskCache::CorruptCacheInfo * corruptInfo);
+ nsresult Close(bool flush);
+
+ /*
+ * Trim
+ * Truncates the block file to the end of the last allocated block.
+ */
+ nsresult Trim() { return nsDiskCache::Truncate(mFD, CalcBlockFileSize()); }
+ nsresult DeallocateBlocks( int32_t startBlock, int32_t numBlocks);
+ nsresult WriteBlocks( void * buffer, uint32_t size, int32_t numBlocks,
+ int32_t * startBlock);
+ nsresult ReadBlocks( void * buffer, int32_t startBlock, int32_t numBlocks,
+ int32_t * bytesRead);
+
+ size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
+
+private:
+ nsresult FlushBitMap();
+ int32_t AllocateBlocks( int32_t numBlocks);
+ nsresult VerifyAllocation( int32_t startBlock, int32_t numBLocks);
+ uint32_t CalcBlockFileSize();
+ bool Write(int32_t offset, const void *buf, int32_t amount);
+
+/**
+ * Data members
+ */
+ PRFileDesc * mFD;
+ uint32_t * mBitMap; // XXX future: array of bit map blocks
+ uint32_t mBlockSize;
+ uint32_t mBitMapWords;
+ int32_t mFileSize;
+ bool mBitMapDirty;
+};
+
+#endif // _nsDiskCacheBlockFile_h_