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 // For a general description of the files used by the cache see file_format.h. | 5 // For a general description of the files used by the cache see file_format.h. |
6 // | 6 // |
7 // A block file is a file designed to store blocks of data of a given size. It | 7 // A block file is a file designed to store blocks of data of a given size. It |
8 // is able to store data that spans from one to four consecutive "blocks", and | 8 // is able to store data that spans from one to four consecutive "blocks", and |
9 // it grows as needed to store up to approximately 65000 blocks. It has a fixed | 9 // it grows as needed to store up to approximately 65000 blocks. It has a fixed |
10 // size header used for book keeping such as tracking free of blocks on the | 10 // size header used for book keeping such as tracking free of blocks on the |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace disk_cache { | 26 namespace disk_cache { |
27 | 27 |
28 typedef uint32 CacheAddr; | 28 typedef uint32 CacheAddr; |
29 | 29 |
30 const uint32 kBlockVersion2 = 0x20000; // Version 2.0. | 30 const uint32 kBlockVersion2 = 0x20000; // Version 2.0. |
31 const uint32 kBlockCurrentVersion = 0x30000; // Version 3.0. | 31 const uint32 kBlockCurrentVersion = 0x30000; // Version 3.0. |
32 | 32 |
33 const uint32 kBlockMagic = 0xC104CAC3; | 33 const uint32 kBlockMagic = 0xC104CAC3; |
34 const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries | 34 const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries |
35 const int kMaxBlocks = (kBlockHeaderSize - 80) * 8; | 35 const int kMaxBlocks = (kBlockHeaderSize - 80) * 8; |
| 36 const int kNumExtraBlocks = 1024; |
36 | 37 |
37 // Bitmap to track used blocks on a block-file. | 38 // Bitmap to track used blocks on a block-file. |
38 typedef uint32 AllocBitmap[kMaxBlocks / 32]; | 39 typedef uint32 AllocBitmap[kMaxBlocks / 32]; |
39 | 40 |
40 // A block-file is the file used to store information in blocks (could be | 41 // A block-file is the file used to store information in blocks (could be |
41 // EntryStore blocks, RankingsNode blocks or user-data blocks). | 42 // EntryStore blocks, RankingsNode blocks or user-data blocks). |
42 // We store entries that can expand for up to 4 consecutive blocks, and keep | 43 // We store entries that can expand for up to 4 consecutive blocks, and keep |
43 // counters of the number of blocks available for each type of entry. For | 44 // counters of the number of blocks available for each type of entry. For |
44 // instance, an entry of 3 blocks is an entry of type 3. We also keep track of | 45 // instance, an entry of 3 blocks is an entry of type 3. We also keep track of |
45 // where did we find the last entry of that type (to avoid searching the bitmap | 46 // where did we find the last entry of that type (to avoid searching the bitmap |
46 // from the beginning every time). | 47 // from the beginning every time). |
| 48 // |
| 49 // The only difference between versions 2 and 3 is that the latter stores the |
| 50 // header and allocation file in a dedicated file, and the data in another file, |
| 51 // instead of using a single file for both things (as does version 2). |
47 // This Structure is the header of a block-file: | 52 // This Structure is the header of a block-file: |
48 struct BlockFileHeader { | 53 struct NET_EXPORT_PRIVATE BlockFileHeader { |
49 uint32 magic; | 54 uint32 magic; |
50 uint32 version; | 55 uint32 version; |
51 int16 this_file; // Index of this file. | 56 int16 this_file; // Index of this file. |
52 int16 next_file; // Next file when this one is full. | 57 int16 next_file; // Next file when this one is full. |
53 int32 entry_size; // Size of the blocks of this file. | 58 int32 entry_size; // Size of the blocks of this file. |
54 int32 num_entries; // Number of stored entries. | 59 int32 num_entries; // Number of stored entries. |
55 int32 max_entries; // Current maximum number of entries. | 60 int32 max_entries; // Current maximum number of entries. |
56 int32 empty[4]; // Counters of empty entries for each type. | 61 int32 empty[4]; // Counters of empty entries for each type. |
57 int32 hints[4]; // Last used position for each entry type. | 62 int32 hints[4]; // Last used position for each entry type. |
58 volatile int32 updating; // Keep track of updates to the header. | 63 volatile int32 updating; // Keep track of updates to the header. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 }; | 127 }; |
123 | 128 |
124 // The number of blocks stored by a child entry. | 129 // The number of blocks stored by a child entry. |
125 const int kNumSparseBits = 1024; | 130 const int kNumSparseBits = 1024; |
126 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, | 131 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, |
127 Invalid_SparseData_bitmap); | 132 Invalid_SparseData_bitmap); |
128 | 133 |
129 } // namespace disk_cache | 134 } // namespace disk_cache |
130 | 135 |
131 #endif // NET_DISK_CACHE_DISK_FORMAT_BASE_H_ | 136 #endif // NET_DISK_CACHE_DISK_FORMAT_BASE_H_ |
OLD | NEW |