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