OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // file plus a collection of external files. | 6 // file plus a collection of external files. |
7 // | 7 // |
8 // Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a | 8 // Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a |
9 // separate file named f_xxx where x is a hexadecimal number. Shorter data will | 9 // separate file named f_xxx where x is a hexadecimal number. Shorter data will |
10 // be stored as a series of blocks on a block-file. In any case, CacheAddr | 10 // be stored as a series of blocks on a block-file. In any case, CacheAddr |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // | 45 // |
46 // In order to prevent dirty data to be used as valid (after a crash), every | 46 // In order to prevent dirty data to be used as valid (after a crash), every |
47 // cache entry has a dirty identifier. Each running instance of the cache keeps | 47 // cache entry has a dirty identifier. Each running instance of the cache keeps |
48 // a separate identifier (maintained on the "this_id" header field) that is used | 48 // a separate identifier (maintained on the "this_id" header field) that is used |
49 // to mark every entry that is created or modified. When the entry is closed, | 49 // to mark every entry that is created or modified. When the entry is closed, |
50 // and all the data can be trusted, the dirty flag is cleared from the entry. | 50 // and all the data can be trusted, the dirty flag is cleared from the entry. |
51 // When the cache encounters an entry whose identifier is different than the one | 51 // When the cache encounters an entry whose identifier is different than the one |
52 // being currently used, it means that the entry was not properly closed on a | 52 // being currently used, it means that the entry was not properly closed on a |
53 // previous run, so it is discarded. | 53 // previous run, so it is discarded. |
54 | 54 |
55 #ifndef NET_DISK_CACHE_DISK_FORMAT_H__ | 55 #ifndef NET_DISK_CACHE_DISK_FORMAT_H_ |
56 #define NET_DISK_CACHE_DISK_FORMAT_H__ | 56 #define NET_DISK_CACHE_DISK_FORMAT_H_ |
57 | 57 |
58 #include "base/basictypes.h" | 58 #include "base/basictypes.h" |
59 | 59 |
60 namespace disk_cache { | 60 namespace disk_cache { |
61 | 61 |
62 typedef uint32 CacheAddr; | 62 typedef uint32 CacheAddr; |
63 | 63 |
64 const int kIndexTablesize = 0x10000; | 64 const int kIndexTablesize = 0x10000; |
65 const uint32 kIndexMagic = 0xC103CAC3; | 65 const uint32 kIndexMagic = 0xC103CAC3; |
66 const uint32 kCurrentVersion = 0x20000; // Version 2.0. | 66 const uint32 kCurrentVersion = 0x20000; // Version 2.0. |
67 | 67 |
68 struct LruData { | 68 struct LruData { |
| 69 int32 pad1[3]; |
| 70 int32 sizes[5]; |
69 CacheAddr heads[5]; | 71 CacheAddr heads[5]; |
70 CacheAddr tails[5]; | 72 CacheAddr tails[5]; |
71 CacheAddr transaction; // In-flight operation target. | 73 CacheAddr transaction; // In-flight operation target. |
72 int32 operation; // Actual in-flight operation. | 74 int32 operation; // Actual in-flight operation. |
73 int32 operation_list; // In-flight operation list. | 75 int32 operation_list; // In-flight operation list. |
74 int32 pad[7]; | 76 int32 pad2[7]; |
75 }; | 77 }; |
76 | 78 |
77 // Header for the master index file. | 79 // Header for the master index file. |
78 struct IndexHeader { | 80 struct IndexHeader { |
79 uint32 magic; | 81 uint32 magic; |
80 uint32 version; | 82 uint32 version; |
81 int32 num_entries; // Number of entries currently stored. | 83 int32 num_entries; // Number of entries currently stored. |
82 int32 num_bytes; // Total size of the stored data. | 84 int32 num_bytes; // Total size of the stored data. |
83 int32 last_file; // Last external file created. | 85 int32 last_file; // Last external file created. |
84 int32 this_id; // Id for all entries being changed (dirty flag). | 86 int32 this_id; // Id for all entries being changed (dirty flag). |
85 CacheAddr stats; // Storage for usage data. | 87 CacheAddr stats; // Storage for usage data. |
86 int32 table_len; // Actual size of the table (0 == kIndexTablesize). | 88 int32 table_len; // Actual size of the table (0 == kIndexTablesize). |
87 int32 crash; // Signals a previous crash. | 89 int32 crash; // Signals a previous crash. |
88 int32 experiment; // Id of an ongoing test. | 90 int32 experiment; // Id of an ongoing test. |
89 int32 pad[62]; | 91 int32 pad[54]; |
90 LruData lru; // Eviction control data. | 92 LruData lru; // Eviction control data. |
91 IndexHeader() { | 93 IndexHeader() { |
92 memset(this, 0, sizeof(*this)); | 94 memset(this, 0, sizeof(*this)); |
93 magic = kIndexMagic; | 95 magic = kIndexMagic; |
94 version = kCurrentVersion; | 96 version = kCurrentVersion; |
95 }; | 97 }; |
96 }; | 98 }; |
97 | 99 |
98 // The structure of the whole index file. | 100 // The structure of the whole index file. |
99 struct Index { | 101 struct Index { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 memset(this, 0, sizeof(BlockFileHeader)); | 183 memset(this, 0, sizeof(BlockFileHeader)); |
182 magic = kBlockMagic; | 184 magic = kBlockMagic; |
183 version = kCurrentVersion; | 185 version = kCurrentVersion; |
184 }; | 186 }; |
185 }; | 187 }; |
186 | 188 |
187 COMPILE_ASSERT(sizeof(BlockFileHeader) == kBlockHeaderSize, bad_header); | 189 COMPILE_ASSERT(sizeof(BlockFileHeader) == kBlockHeaderSize, bad_header); |
188 | 190 |
189 } // namespace disk_cache | 191 } // namespace disk_cache |
190 | 192 |
191 #endif // NET_DISK_CACHE_DISK_FORMAT_H__ | 193 #endif // NET_DISK_CACHE_DISK_FORMAT_H_ |
192 | 194 |
OLD | NEW |