OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The cache is stored on disk as a collection of block-files, plus an index | 5 // The cache is stored on disk as a collection of block-files, plus an index |
6 // plus a collection of external files. | 6 // plus a collection of external files. |
7 // | 7 // |
8 // Any data blob bigger than kMaxBlockSize (disk_cache/addr.h) will be stored in | 8 // Any data blob bigger than kMaxBlockSize (disk_cache/addr.h) will be stored in |
9 // a separate file named f_xxx where x is a hexadecimal number. Shorter data | 9 // a separate file named f_xxx where x is a hexadecimal number. Shorter data |
10 // will be stored as a series of blocks on a block-file. In any case, CacheAddr | 10 // will be stored as a series of blocks on a block-file. In any case, CacheAddr |
(...skipping 27 matching lines...) Expand all Loading... |
38 // time) when the process dies in the middle of an update. There are dedicated | 38 // time) when the process dies in the middle of an update. There are dedicated |
39 // backup files for cache bitmaps, used to detect entries out of date. | 39 // backup files for cache bitmaps, used to detect entries out of date. |
40 // | 40 // |
41 // Although cache files are to be consumed on the same machine that creates | 41 // Although cache files are to be consumed on the same machine that creates |
42 // them, if files are to be moved accross machines, little endian storage is | 42 // them, if files are to be moved accross machines, little endian storage is |
43 // assumed. | 43 // assumed. |
44 | 44 |
45 #ifndef NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ | 45 #ifndef NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ |
46 #define NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ | 46 #define NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ |
47 | 47 |
48 #include "base/basictypes.h" | 48 #include <stdint.h> |
| 49 |
49 #include "net/disk_cache/blockfile/disk_format_base.h" | 50 #include "net/disk_cache/blockfile/disk_format_base.h" |
50 | 51 |
51 namespace disk_cache { | 52 namespace disk_cache { |
52 | 53 |
53 const int kBaseTableLen = 0x400; | 54 const int kBaseTableLen = 0x400; |
54 const uint32 kIndexMagicV3 = 0xC103CAC3; | 55 const uint32_t kIndexMagicV3 = 0xC103CAC3; |
55 const uint32 kVersion3 = 0x30000; // Version 3.0. | 56 const uint32_t kVersion3 = 0x30000; // Version 3.0. |
56 | 57 |
57 // Flags for a given cache. | 58 // Flags for a given cache. |
58 enum CacheFlags { | 59 enum CacheFlags { |
59 SMALL_CACHE = 1 << 0, // See IndexCell. | 60 SMALL_CACHE = 1 << 0, // See IndexCell. |
60 CACHE_EVICTION_2 = 1 << 1, // Keep multiple lists for eviction. | 61 CACHE_EVICTION_2 = 1 << 1, // Keep multiple lists for eviction. |
61 CACHE_EVICTED = 1 << 2 // Already evicted at least one entry. | 62 CACHE_EVICTED = 1 << 2 // Already evicted at least one entry. |
62 }; | 63 }; |
63 | 64 |
64 // Header for the master index file. | 65 // Header for the master index file. |
65 struct IndexHeaderV3 { | 66 struct IndexHeaderV3 { |
66 uint32 magic; | 67 uint32_t magic; |
67 uint32 version; | 68 uint32_t version; |
68 int32 num_entries; // Number of entries currently stored. | 69 int32_t num_entries; // Number of entries currently stored. |
69 int32 num_bytes; // Total size of the stored data. | 70 int32_t num_bytes; // Total size of the stored data. |
70 int32 last_file; // Last external file created. | 71 int32_t last_file; // Last external file created. |
71 int32 reserved1; | 72 int32_t reserved1; |
72 CacheAddr stats; // Storage for usage data. | 73 CacheAddr stats; // Storage for usage data. |
73 int32 table_len; // Actual size of the table. | 74 int32_t table_len; // Actual size of the table. |
74 int32 crash; // Signals a previous crash. | 75 int32_t crash; // Signals a previous crash. |
75 int32 experiment; // Id of an ongoing test. | 76 int32_t experiment; // Id of an ongoing test. |
76 int32 max_bytes; // Total maximum size of the stored data. | 77 int32_t max_bytes; // Total maximum size of the stored data. |
77 uint32 flags; | 78 uint32_t flags; |
78 int32 used_cells; | 79 int32_t used_cells; |
79 int32 max_bucket; | 80 int32_t max_bucket; |
80 uint64 create_time; // Creation time for this set of files. | 81 uint64_t create_time; // Creation time for this set of files. |
81 uint64 base_time; // Current base for timestamps. | 82 uint64_t base_time; // Current base for timestamps. |
82 uint64 old_time; // Previous time used for timestamps. | 83 uint64_t old_time; // Previous time used for timestamps. |
83 int32 max_block_file; | 84 int32_t max_block_file; |
84 int32 num_no_use_entries; | 85 int32_t num_no_use_entries; |
85 int32 num_low_use_entries; | 86 int32_t num_low_use_entries; |
86 int32 num_high_use_entries; | 87 int32_t num_high_use_entries; |
87 int32 reserved; | 88 int32_t reserved; |
88 int32 num_evicted_entries; | 89 int32_t num_evicted_entries; |
89 int32 pad[6]; | 90 int32_t pad[6]; |
90 }; | 91 }; |
91 | 92 |
92 const int kBaseBitmapBytes = 3968; | 93 const int kBaseBitmapBytes = 3968; |
93 // The IndexBitmap is directly saved to a file named index. The file grows in | 94 // The IndexBitmap is directly saved to a file named index. The file grows in |
94 // page increments (4096 bytes), but all bits don't have to be in use at any | 95 // page increments (4096 bytes), but all bits don't have to be in use at any |
95 // given time. The required file size can be computed from header.table_len. | 96 // given time. The required file size can be computed from header.table_len. |
96 struct IndexBitmap { | 97 struct IndexBitmap { |
97 IndexHeaderV3 header; | 98 IndexHeaderV3 header; |
98 uint32 bitmap[kBaseBitmapBytes / 4]; // First page of the bitmap. | 99 uint32_t bitmap[kBaseBitmapBytes / 4]; // First page of the bitmap. |
99 }; | 100 }; |
100 static_assert(sizeof(IndexBitmap) == 4096, "bad IndexHeader"); | 101 static_assert(sizeof(IndexBitmap) == 4096, "bad IndexHeader"); |
101 | 102 |
102 // Possible states for a given entry. | 103 // Possible states for a given entry. |
103 enum EntryState { | 104 enum EntryState { |
104 ENTRY_FREE = 0, // Available slot. | 105 ENTRY_FREE = 0, // Available slot. |
105 ENTRY_NEW, // The entry is being created. | 106 ENTRY_NEW, // The entry is being created. |
106 ENTRY_OPEN, // The entry is being accessed. | 107 ENTRY_OPEN, // The entry is being accessed. |
107 ENTRY_MODIFIED, // The entry is being modified. | 108 ENTRY_MODIFIED, // The entry is being modified. |
108 ENTRY_DELETED, // The entry is being deleted. | 109 ENTRY_DELETED, // The entry is being deleted. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // | 174 // |
174 // For example, a small table may store something like 0x1234 as the location | 175 // For example, a small table may store something like 0x1234 as the location |
175 // field. That means it stores the entry number 0x1234. If that record belongs | 176 // field. That means it stores the entry number 0x1234. If that record belongs |
176 // to a deleted entry, the regular cache address may look something like | 177 // to a deleted entry, the regular cache address may look something like |
177 // BLOCK_EVICTED + 1 block + file number 6 + entry number 0x1234 | 178 // BLOCK_EVICTED + 1 block + file number 6 + entry number 0x1234 |
178 // so Addr = 0xf0061234 | 179 // so Addr = 0xf0061234 |
179 // | 180 // |
180 // If that same Addr is stored on a large table, the location field would be | 181 // If that same Addr is stored on a large table, the location field would be |
181 // 0x61234 | 182 // 0x61234 |
182 | 183 |
183 uint64 first_part; | 184 uint64_t first_part; |
184 uint8 last_part; | 185 uint8_t last_part; |
185 }; | 186 }; |
186 static_assert(sizeof(IndexCell) == 9, "bad IndexCell"); | 187 static_assert(sizeof(IndexCell) == 9, "bad IndexCell"); |
187 | 188 |
188 const int kCellsPerBucket = 4; | 189 const int kCellsPerBucket = 4; |
189 struct IndexBucket { | 190 struct IndexBucket { |
190 IndexCell cells[kCellsPerBucket]; | 191 IndexCell cells[kCellsPerBucket]; |
191 int32 next; | 192 int32_t next; |
192 uint32 hash; // The high order byte is reserved (should be zero). | 193 uint32_t hash; // The high order byte is reserved (should be zero). |
193 }; | 194 }; |
194 static_assert(sizeof(IndexBucket) == 44, "bad IndexBucket"); | 195 static_assert(sizeof(IndexBucket) == 44, "bad IndexBucket"); |
195 const int kBytesPerCell = 44 / kCellsPerBucket; | 196 const int kBytesPerCell = 44 / kCellsPerBucket; |
196 | 197 |
197 // The main cache index. Backed by a file named index_tb1. | 198 // The main cache index. Backed by a file named index_tb1. |
198 // The extra table (index_tb2) has a similar format, but different size. | 199 // The extra table (index_tb2) has a similar format, but different size. |
199 struct Index { | 200 struct Index { |
200 // Default size. Actual size controlled by header.table_len. | 201 // Default size. Actual size controlled by header.table_len. |
201 IndexBucket table[kBaseTableLen / kCellsPerBucket]; | 202 IndexBucket table[kBaseTableLen / kCellsPerBucket]; |
202 }; | 203 }; |
203 #pragma pack(pop) | 204 #pragma pack(pop) |
204 | 205 |
205 // Flags that can be applied to an entry. | 206 // Flags that can be applied to an entry. |
206 enum EntryFlags { | 207 enum EntryFlags { |
207 PARENT_ENTRY = 1, // This entry has children (sparse) entries. | 208 PARENT_ENTRY = 1, // This entry has children (sparse) entries. |
208 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data. | 209 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data. |
209 }; | 210 }; |
210 | 211 |
211 struct EntryRecord { | 212 struct EntryRecord { |
212 uint32 hash; | 213 uint32_t hash; |
213 uint32 pad1; | 214 uint32_t pad1; |
214 uint8 reuse_count; | 215 uint8_t reuse_count; |
215 uint8 refetch_count; | 216 uint8_t refetch_count; |
216 int8 state; // Current EntryState. | 217 int8_t state; // Current EntryState. |
217 uint8 flags; // Any combination of EntryFlags. | 218 uint8_t flags; // Any combination of EntryFlags. |
218 int32 key_len; | 219 int32_t key_len; |
219 int32 data_size[4]; // We can store up to 4 data streams for each | 220 int32_t data_size[4]; // We can store up to 4 data streams for each |
220 CacheAddr data_addr[4]; // entry. | 221 CacheAddr data_addr[4]; // entry. |
221 uint32 data_hash[4]; | 222 uint32_t data_hash[4]; |
222 uint64 creation_time; | 223 uint64_t creation_time; |
223 uint64 last_modified_time; | 224 uint64_t last_modified_time; |
224 uint64 last_access_time; | 225 uint64_t last_access_time; |
225 int32 pad[3]; | 226 int32_t pad[3]; |
226 uint32 self_hash; | 227 uint32_t self_hash; |
227 }; | 228 }; |
228 static_assert(sizeof(EntryRecord) == 104, "bad EntryRecord"); | 229 static_assert(sizeof(EntryRecord) == 104, "bad EntryRecord"); |
229 | 230 |
230 struct ShortEntryRecord { | 231 struct ShortEntryRecord { |
231 uint32 hash; | 232 uint32_t hash; |
232 uint32 pad1; | 233 uint32_t pad1; |
233 uint8 reuse_count; | 234 uint8_t reuse_count; |
234 uint8 refetch_count; | 235 uint8_t refetch_count; |
235 int8 state; // Current EntryState. | 236 int8_t state; // Current EntryState. |
236 uint8 flags; | 237 uint8_t flags; |
237 int32 key_len; | 238 int32_t key_len; |
238 uint64 last_access_time; | 239 uint64_t last_access_time; |
239 uint32 long_hash[5]; | 240 uint32_t long_hash[5]; |
240 uint32 self_hash; | 241 uint32_t self_hash; |
241 }; | 242 }; |
242 static_assert(sizeof(ShortEntryRecord) == 48, "bad ShortEntryRecord"); | 243 static_assert(sizeof(ShortEntryRecord) == 48, "bad ShortEntryRecord"); |
243 | 244 |
244 } // namespace disk_cache | 245 } // namespace disk_cache |
245 | 246 |
246 #endif // NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ | 247 #endif // NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_V3_H_ |
OLD | NEW |