// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // The cache is stored on disk as a collection of block-files, plus an index // file plus a collection of external files. // // Any data blob bigger than kMaxBlockSize (disk_cache/addr.h) will be stored in // a separate file named f_xxx where x is a hexadecimal number. Shorter data // will be stored as a series of blocks on a block-file. In any case, CacheAddr // represents the address of the data inside the cache. // // The index file is just a simple hash table that maps a particular entry to // a CacheAddr value. Linking for a given hash bucket is handled internally // by the cache entry. // // The last element of the cache is the block-file. A block file is a file // designed to store blocks of data of a given size. For more details see // disk_cache/disk_format_base.h // // A new cache is initialized with four block files (named data_0 through // data_3), each one dedicated to store blocks of a given size. The number at // the end of the file name is the block file number (in decimal). // // There are two "special" types of blocks: an entry and a rankings node. An // entry keeps track of all the information related to the same cache entry, // such as the key, hash value, data pointers etc. A rankings node keeps track // of the information that is updated frequently for a given entry, such as its // location on the LRU lists, last access time etc. // // The files that store internal information for the cache (blocks and index) // are at least partially memory mapped. They have a location that is signaled // every time the internal structures are modified, so it is possible to detect // (most of the time) when the process dies in the middle of an update. // // In order to prevent dirty data to be used as valid (after a crash), every // cache entry has a dirty identifier. Each running instance of the cache keeps // a separate identifier (maintained on the "this_id" header field) that is used // to mark every entry that is created or modified. When the entry is closed, // and all the data can be trusted, the dirty flag is cleared from the entry. // When the cache encounters an entry whose identifier is different than the one // being currently used, it means that the entry was not properly closed on a // previous run, so it is discarded. #ifndef NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_ #define NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_ #include <stddef.h> #include <stdint.h> #include <string.h> #include "net/base/net_export.h" #include "net/disk_cache/blockfile/disk_format_base.h" namespace disk_cache { const int kIndexTablesize = …; const uint32_t kIndexMagic = …; const uint32_t kVersion2_0 = …; const uint32_t kVersion2_1 = …; const uint32_t kVersion3_0 = …; const uint32_t kCurrentVersion = …; struct LruData { … }; // Header for the master index file. struct NET_EXPORT_PRIVATE IndexHeader { … }; // The structure of the whole index file. struct Index { … }; // Main structure for an entry on the backing storage. If the key is longer than // what can be stored on this structure, it will be extended on consecutive // blocks (adding 256 bytes each time), up to 4 blocks (1024 - 32 - 1 chars). // After that point, the whole key will be stored as a data block or external // file. struct EntryStore { … }; static_assert …; const int kMaxInternalKeyLength = …; // Possible states for a given entry. enum EntryState { … }; // Flags that can be applied to an entry. enum EntryFlags { … }; #pragma pack(push, 4) // Rankings information for a given entry. struct RankingsNode { … }; #pragma pack(pop) static_assert …; } // namespace disk_cache #endif // NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_