2012-04-08 01:25:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2001-04-17 07:54:48 +04:00
|
|
|
|
|
|
|
#ifndef _nsDiskCacheBlockFile_h_
|
|
|
|
#define _nsDiskCacheBlockFile_h_
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2012-07-21 03:47:52 +04:00
|
|
|
#include "nsDiskCache.h"
|
2001-04-17 07:54:48 +04:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* 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()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mFD(nullptr)
|
|
|
|
, mBitMap(nullptr)
|
2010-09-30 03:41:03 +04:00
|
|
|
, mBlockSize(0)
|
2011-01-18 17:12:10 +03:00
|
|
|
, mBitMapWords(0)
|
2010-09-24 16:20:23 +04:00
|
|
|
, mFileSize(0)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mBitMapDirty(false)
|
2001-04-17 07:54:48 +04:00
|
|
|
{}
|
2011-10-17 18:59:28 +04:00
|
|
|
~nsDiskCacheBlockFile() { (void) Close(true); }
|
2001-04-17 07:54:48 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult Open( nsIFile * blockFile, uint32_t blockSize,
|
|
|
|
uint32_t bitMapSize, nsDiskCache::CorruptCacheInfo * corruptInfo);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult Close(bool flush);
|
2012-07-21 03:47:52 +04:00
|
|
|
|
2005-10-08 05:20:36 +04:00
|
|
|
/*
|
|
|
|
* Trim
|
|
|
|
* Truncates the block file to the end of the last allocated block.
|
|
|
|
*/
|
|
|
|
nsresult Trim() { return nsDiskCache::Truncate(mFD, CalcBlockFileSize()); }
|
2012-08-22 19:56:38 +04:00
|
|
|
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);
|
2012-11-05 22:22:33 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-11-05 22:22:33 +04:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
private:
|
|
|
|
nsresult FlushBitMap();
|
2012-08-22 19:56:38 +04:00
|
|
|
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);
|
2001-04-17 07:54:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data members
|
|
|
|
*/
|
2001-05-19 03:24:09 +04:00
|
|
|
PRFileDesc * mFD;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t * mBitMap; // XXX future: array of bit map blocks
|
|
|
|
uint32_t mBlockSize;
|
|
|
|
uint32_t mBitMapWords;
|
|
|
|
int32_t mFileSize;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mBitMapDirty;
|
2001-04-17 07:54:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsDiskCacheBlockFile_h_
|