Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: net/disk_cache/blockfile/disk_format.h

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 (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
38 // a separate identifier (maintained on the "this_id" header field) that is used 38 // a separate identifier (maintained on the "this_id" header field) that is used
39 // to mark every entry that is created or modified. When the entry is closed, 39 // to mark every entry that is created or modified. When the entry is closed,
40 // and all the data can be trusted, the dirty flag is cleared from the entry. 40 // and all the data can be trusted, the dirty flag is cleared from the entry.
41 // When the cache encounters an entry whose identifier is different than the one 41 // When the cache encounters an entry whose identifier is different than the one
42 // being currently used, it means that the entry was not properly closed on a 42 // being currently used, it means that the entry was not properly closed on a
43 // previous run, so it is discarded. 43 // previous run, so it is discarded.
44 44
45 #ifndef NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_ 45 #ifndef NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_
46 #define NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_ 46 #define NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_
47 47
48 #include "base/basictypes.h" 48 #include <stddef.h>
49 #include <stdint.h>
50 #include <string.h>
51
49 #include "net/base/net_export.h" 52 #include "net/base/net_export.h"
50 #include "net/disk_cache/blockfile/disk_format_base.h" 53 #include "net/disk_cache/blockfile/disk_format_base.h"
51 54
52 namespace disk_cache { 55 namespace disk_cache {
53 56
54 const int kIndexTablesize = 0x10000; 57 const int kIndexTablesize = 0x10000;
55 const uint32 kIndexMagic = 0xC103CAC3; 58 const uint32_t kIndexMagic = 0xC103CAC3;
56 const uint32 kCurrentVersion = 0x20000; // Version 2.0. 59 const uint32_t kCurrentVersion = 0x20000; // Version 2.0.
57 60
58 struct LruData { 61 struct LruData {
59 int32 pad1[2]; 62 int32_t pad1[2];
60 int32 filled; // Flag to tell when we filled the cache. 63 int32_t filled; // Flag to tell when we filled the cache.
61 int32 sizes[5]; 64 int32_t sizes[5];
62 CacheAddr heads[5]; 65 CacheAddr heads[5];
63 CacheAddr tails[5]; 66 CacheAddr tails[5];
64 CacheAddr transaction; // In-flight operation target. 67 CacheAddr transaction; // In-flight operation target.
65 int32 operation; // Actual in-flight operation. 68 int32_t operation; // Actual in-flight operation.
66 int32 operation_list; // In-flight operation list. 69 int32_t operation_list; // In-flight operation list.
67 int32 pad2[7]; 70 int32_t pad2[7];
68 }; 71 };
69 72
70 // Header for the master index file. 73 // Header for the master index file.
71 struct NET_EXPORT_PRIVATE IndexHeader { 74 struct NET_EXPORT_PRIVATE IndexHeader {
72 IndexHeader(); 75 IndexHeader();
73 76
74 uint32 magic; 77 uint32_t magic;
75 uint32 version; 78 uint32_t version;
76 int32 num_entries; // Number of entries currently stored. 79 int32_t num_entries; // Number of entries currently stored.
77 int32 num_bytes; // Total size of the stored data. 80 int32_t num_bytes; // Total size of the stored data.
78 int32 last_file; // Last external file created. 81 int32_t last_file; // Last external file created.
79 int32 this_id; // Id for all entries being changed (dirty flag). 82 int32_t this_id; // Id for all entries being changed (dirty flag).
80 CacheAddr stats; // Storage for usage data. 83 CacheAddr stats; // Storage for usage data.
81 int32 table_len; // Actual size of the table (0 == kIndexTablesize). 84 int32_t table_len; // Actual size of the table (0 == kIndexTablesize).
82 int32 crash; // Signals a previous crash. 85 int32_t crash; // Signals a previous crash.
83 int32 experiment; // Id of an ongoing test. 86 int32_t experiment; // Id of an ongoing test.
84 uint64 create_time; // Creation time for this set of files. 87 uint64_t create_time; // Creation time for this set of files.
85 int32 pad[52]; 88 int32_t pad[52];
86 LruData lru; // Eviction control data. 89 LruData lru; // Eviction control data.
87 }; 90 };
88 91
89 // The structure of the whole index file. 92 // The structure of the whole index file.
90 struct Index { 93 struct Index {
91 IndexHeader header; 94 IndexHeader header;
92 CacheAddr table[kIndexTablesize]; // Default size. Actual size controlled 95 CacheAddr table[kIndexTablesize]; // Default size. Actual size controlled
93 // by header.table_len. 96 // by header.table_len.
94 }; 97 };
95 98
96 // Main structure for an entry on the backing storage. If the key is longer than 99 // Main structure for an entry on the backing storage. If the key is longer than
97 // what can be stored on this structure, it will be extended on consecutive 100 // what can be stored on this structure, it will be extended on consecutive
98 // blocks (adding 256 bytes each time), up to 4 blocks (1024 - 32 - 1 chars). 101 // blocks (adding 256 bytes each time), up to 4 blocks (1024 - 32 - 1 chars).
99 // After that point, the whole key will be stored as a data block or external 102 // After that point, the whole key will be stored as a data block or external
100 // file. 103 // file.
101 struct EntryStore { 104 struct EntryStore {
102 uint32 hash; // Full hash of the key. 105 uint32_t hash; // Full hash of the key.
103 CacheAddr next; // Next entry with the same hash or bucket. 106 CacheAddr next; // Next entry with the same hash or bucket.
104 CacheAddr rankings_node; // Rankings node for this entry. 107 CacheAddr rankings_node; // Rankings node for this entry.
105 int32 reuse_count; // How often is this entry used. 108 int32_t reuse_count; // How often is this entry used.
106 int32 refetch_count; // How often is this fetched from the net. 109 int32_t refetch_count; // How often is this fetched from the net.
107 int32 state; // Current state. 110 int32_t state; // Current state.
108 uint64 creation_time; 111 uint64_t creation_time;
109 int32 key_len; 112 int32_t key_len;
110 CacheAddr long_key; // Optional address of a long key. 113 CacheAddr long_key; // Optional address of a long key.
111 int32 data_size[4]; // We can store up to 4 data streams for each 114 int32_t data_size[4]; // We can store up to 4 data streams for each
112 CacheAddr data_addr[4]; // entry. 115 CacheAddr data_addr[4]; // entry.
113 uint32 flags; // Any combination of EntryFlags. 116 uint32_t flags; // Any combination of EntryFlags.
114 int32 pad[4]; 117 int32_t pad[4];
115 uint32 self_hash; // The hash of EntryStore up to this point. 118 uint32_t self_hash; // The hash of EntryStore up to this point.
116 char key[256 - 24 * 4]; // null terminated 119 char key[256 - 24 * 4]; // null terminated
117 }; 120 };
118 121
119 static_assert(sizeof(EntryStore) == 256, "bad EntryStore"); 122 static_assert(sizeof(EntryStore) == 256, "bad EntryStore");
120 const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) - 123 const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) -
121 offsetof(EntryStore, key) - 1; 124 offsetof(EntryStore, key) - 1;
122 125
123 // Possible states for a given entry. 126 // Possible states for a given entry.
124 enum EntryState { 127 enum EntryState {
125 ENTRY_NORMAL = 0, 128 ENTRY_NORMAL = 0,
126 ENTRY_EVICTED, // The entry was recently evicted from the cache. 129 ENTRY_EVICTED, // The entry was recently evicted from the cache.
127 ENTRY_DOOMED // The entry was doomed. 130 ENTRY_DOOMED // The entry was doomed.
128 }; 131 };
129 132
130 // Flags that can be applied to an entry. 133 // Flags that can be applied to an entry.
131 enum EntryFlags { 134 enum EntryFlags {
132 PARENT_ENTRY = 1, // This entry has children (sparse) entries. 135 PARENT_ENTRY = 1, // This entry has children (sparse) entries.
133 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data. 136 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data.
134 }; 137 };
135 138
136 #pragma pack(push, 4) 139 #pragma pack(push, 4)
137 // Rankings information for a given entry. 140 // Rankings information for a given entry.
138 struct RankingsNode { 141 struct RankingsNode {
139 uint64 last_used; // LRU info. 142 uint64_t last_used; // LRU info.
140 uint64 last_modified; // LRU info. 143 uint64_t last_modified; // LRU info.
141 CacheAddr next; // LRU list. 144 CacheAddr next; // LRU list.
142 CacheAddr prev; // LRU list. 145 CacheAddr prev; // LRU list.
143 CacheAddr contents; // Address of the EntryStore. 146 CacheAddr contents; // Address of the EntryStore.
144 int32 dirty; // The entry is being modifyied. 147 int32_t dirty; // The entry is being modifyied.
145 uint32 self_hash; // RankingsNode's hash. 148 uint32_t self_hash; // RankingsNode's hash.
146 }; 149 };
147 #pragma pack(pop) 150 #pragma pack(pop)
148 151
149 static_assert(sizeof(RankingsNode) == 36, "bad RankingsNode"); 152 static_assert(sizeof(RankingsNode) == 36, "bad RankingsNode");
150 153
151 } // namespace disk_cache 154 } // namespace disk_cache
152 155
153 #endif // NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_ 156 #endif // NET_DISK_CACHE_BLOCKFILE_DISK_FORMAT_H_
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/disk_cache_perftest.cc ('k') | net/disk_cache/blockfile/disk_format_v3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698