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