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 // 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #pragma once | 57 #pragma once |
58 | 58 |
59 #include "base/basictypes.h" | 59 #include "base/basictypes.h" |
60 #include "net/base/net_api.h" | 60 #include "net/base/net_export.h" |
61 | 61 |
62 namespace disk_cache { | 62 namespace disk_cache { |
63 | 63 |
64 typedef uint32 CacheAddr; | 64 typedef uint32 CacheAddr; |
65 | 65 |
66 const int kIndexTablesize = 0x10000; | 66 const int kIndexTablesize = 0x10000; |
67 const uint32 kIndexMagic = 0xC103CAC3; | 67 const uint32 kIndexMagic = 0xC103CAC3; |
68 const uint32 kCurrentVersion = 0x20000; // Version 2.0. | 68 const uint32 kCurrentVersion = 0x20000; // Version 2.0. |
69 | 69 |
70 struct LruData { | 70 struct LruData { |
71 int32 pad1[2]; | 71 int32 pad1[2]; |
72 int32 filled; // Flag to tell when we filled the cache. | 72 int32 filled; // Flag to tell when we filled the cache. |
73 int32 sizes[5]; | 73 int32 sizes[5]; |
74 CacheAddr heads[5]; | 74 CacheAddr heads[5]; |
75 CacheAddr tails[5]; | 75 CacheAddr tails[5]; |
76 CacheAddr transaction; // In-flight operation target. | 76 CacheAddr transaction; // In-flight operation target. |
77 int32 operation; // Actual in-flight operation. | 77 int32 operation; // Actual in-flight operation. |
78 int32 operation_list; // In-flight operation list. | 78 int32 operation_list; // In-flight operation list. |
79 int32 pad2[7]; | 79 int32 pad2[7]; |
80 }; | 80 }; |
81 | 81 |
82 // Header for the master index file. | 82 // Header for the master index file. |
83 struct NET_TEST IndexHeader { | 83 struct NET_EXPORT_PRIVATE IndexHeader { |
84 IndexHeader(); | 84 IndexHeader(); |
85 | 85 |
86 uint32 magic; | 86 uint32 magic; |
87 uint32 version; | 87 uint32 version; |
88 int32 num_entries; // Number of entries currently stored. | 88 int32 num_entries; // Number of entries currently stored. |
89 int32 num_bytes; // Total size of the stored data. | 89 int32 num_bytes; // Total size of the stored data. |
90 int32 last_file; // Last external file created. | 90 int32 last_file; // Last external file created. |
91 int32 this_id; // Id for all entries being changed (dirty flag). | 91 int32 this_id; // Id for all entries being changed (dirty flag). |
92 CacheAddr stats; // Storage for usage data. | 92 CacheAddr stats; // Storage for usage data. |
93 int32 table_len; // Actual size of the table (0 == kIndexTablesize). | 93 int32 table_len; // Actual size of the table (0 == kIndexTablesize). |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 typedef uint32 AllocBitmap[kMaxBlocks / 32]; | 167 typedef uint32 AllocBitmap[kMaxBlocks / 32]; |
168 | 168 |
169 // A block-file is the file used to store information in blocks (could be | 169 // A block-file is the file used to store information in blocks (could be |
170 // EntryStore blocks, RankingsNode blocks or user-data blocks). | 170 // EntryStore blocks, RankingsNode blocks or user-data blocks). |
171 // We store entries that can expand for up to 4 consecutive blocks, and keep | 171 // We store entries that can expand for up to 4 consecutive blocks, and keep |
172 // counters of the number of blocks available for each type of entry. For | 172 // counters of the number of blocks available for each type of entry. For |
173 // instance, an entry of 3 blocks is an entry of type 3. We also keep track of | 173 // instance, an entry of 3 blocks is an entry of type 3. We also keep track of |
174 // where did we find the last entry of that type (to avoid searching the bitmap | 174 // where did we find the last entry of that type (to avoid searching the bitmap |
175 // from the beginning every time). | 175 // from the beginning every time). |
176 // This Structure is the header of a block-file: | 176 // This Structure is the header of a block-file: |
177 struct NET_TEST BlockFileHeader { | 177 struct NET_EXPORT_PRIVATE BlockFileHeader { |
178 BlockFileHeader(); | 178 BlockFileHeader(); |
179 | 179 |
180 uint32 magic; | 180 uint32 magic; |
181 uint32 version; | 181 uint32 version; |
182 int16 this_file; // Index of this file. | 182 int16 this_file; // Index of this file. |
183 int16 next_file; // Next file when this one is full. | 183 int16 next_file; // Next file when this one is full. |
184 int32 entry_size; // Size of the blocks of this file. | 184 int32 entry_size; // Size of the blocks of this file. |
185 int32 num_entries; // Number of stored entries. | 185 int32 num_entries; // Number of stored entries. |
186 int32 max_entries; // Current maximum number of entries. | 186 int32 max_entries; // Current maximum number of entries. |
187 int32 empty[4]; // Counters of empty entries for each type. | 187 int32 empty[4]; // Counters of empty entries for each type. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 }; | 253 }; |
254 | 254 |
255 // The number of blocks stored by a child entry. | 255 // The number of blocks stored by a child entry. |
256 const int kNumSparseBits = 1024; | 256 const int kNumSparseBits = 1024; |
257 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, | 257 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, |
258 Invalid_SparseData_bitmap); | 258 Invalid_SparseData_bitmap); |
259 | 259 |
260 } // namespace disk_cache | 260 } // namespace disk_cache |
261 | 261 |
262 #endif // NET_DISK_CACHE_DISK_FORMAT_H_ | 262 #endif // NET_DISK_CACHE_DISK_FORMAT_H_ |
OLD | NEW |