Lines Matching refs:header
34 void FixAllocationCounters(disk_cache::BlockFileHeader* header);
39 bool CreateMapBlock(int target, int size, disk_cache::BlockFileHeader* header,
50 int current = header->hints[target - 1];
51 for (int i = 0; i < header->max_entries / 32; i++, current++) {
52 if (current == header->max_entries / 32)
54 uint32 map_block = header->allocation_map[current];
60 disk_cache::FileLock lock(header);
65 header->allocation_map[current] |= to_add;
67 header->hints[target - 1] = current;
68 header->empty[target - 1]--;
69 DCHECK(header->empty[target - 1] >= 0);
70 header->num_entries++;
72 header->empty[target - size - 1]++;
82 FixAllocationCounters(header);
87 // relevant counters on the header.
88 void DeleteMapBlock(int index, int size, disk_cache::BlockFileHeader* header) {
95 uint8* byte_map = reinterpret_cast<uint8*>(header->allocation_map);
108 disk_cache::FileLock lock(header);
116 header->empty[bits_at_end - 1]--;
117 header->empty[new_type - 1]++;
118 DCHECK(header->empty[bits_at_end - 1] >= 0);
120 header->num_entries--;
121 DCHECK(header->num_entries >= 0);
128 bool UsedMapBlock(int index, int size, disk_cache::BlockFileHeader* header) {
134 uint8* byte_map = reinterpret_cast<uint8*>(header->allocation_map);
147 void FixAllocationCounters(disk_cache::BlockFileHeader* header) {
149 header->hints[i] = 0;
150 header->empty[i] = 0;
153 for (int i = 0; i < header->max_entries / 32; i++) {
154 uint32 map_block = header->allocation_map[i];
159 header->empty[type -1]++;
166 bool NeedToGrowBlockFile(const disk_cache::BlockFileHeader* header,
171 empty_blocks += header->empty[i] * (i + 1);
172 if (i >= block_count - 1 && header->empty[i])
176 if (header->next_file && (empty_blocks < disk_cache::kMaxBlocks / 10)) {
254 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
258 if (header->empty[i - 1]) {
266 if (!CreateMapBlock(target_size, block_count, header, &index))
269 Addr address(block_type, block_count, header->this_file, index);
296 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
297 DeleteMapBlock(address.start_block(), address.num_blocks(), header);
299 if (!header->num_entries) {
301 FileType type = Addr::RequiredFileType(header->entry_size);
302 if (Addr::BlockSizeForFileType(RANKINGS) == header->entry_size)
351 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
352 bool rv = UsedMapBlock(address.start_block(), address.num_blocks(), header);
381 BlockFileHeader header;
382 header.entry_size = Addr::BlockSizeForFileType(file_type);
383 header.this_file = static_cast<int16>(index);
386 return file->Write(&header, sizeof(header), 0);
410 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
411 if (kBlockMagic != header->magic || kCurrentVersion != header->version) {
416 if (header->updating) {
423 header->max_entries * header->entry_size + kBlockHeaderSize) {
440 bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) {
441 if (kMaxBlocks == header->max_entries)
444 DCHECK(!header->empty[3]);
445 int new_size = header->max_entries + 1024;
449 int new_size_bytes = new_size * header->entry_size + sizeof(*header);
451 FileLock lock(header);
453 // Most likely we are trying to truncate the file, so the header is wrong.
454 if (header->updating < 10 && !FixBlockFileHeader(file)) {
457 header->updating = 100;
460 return (header->max_entries >= new_size);
463 header->empty[3] = (new_size - header->max_entries) / 4; // 4 blocks entries
464 header->max_entries = new_size;
472 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
475 while (NeedToGrowBlockFile(header, block_count)) {
476 if (kMaxBlocks == header->max_entries) {
480 header = reinterpret_cast<BlockFileHeader*>(file->buffer());
484 if (!GrowBlockFile(file, header))
493 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
494 int new_file = header->next_file;
498 FileType type = Addr::RequiredFileType(header->entry_size);
499 if (header->entry_size == Addr::BlockSizeForFileType(RANKINGS))
506 FileLock lock(header);
507 header->next_file = new_file;
527 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
529 while (header->next_file) {
531 Addr address(BLOCK_256, 1, header->next_file, 0);
539 DCHECK_EQ(next_header->entry_size, header->entry_size);
541 int file_index = header->next_file;
542 header->next_file = next_header->next_file;
560 header = next_header;
566 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
568 if (file_size < static_cast<int>(sizeof(*header)))
571 int expected = header->entry_size * header->max_entries + sizeof(*header);
573 int max_expected = header->entry_size * kMaxBlocks + sizeof(*header);
574 if (file_size < expected || header->empty[3] || file_size > max_expected) {
580 int num_entries = (file_size - sizeof(*header)) / header->entry_size;
581 header->max_entries = num_entries;
584 FixAllocationCounters(header);
585 header->updating = 0;
601 BlockFileHeader* header =
604 max_blocks += header->max_entries;
605 int used = header->max_entries;
607 used -= header->empty[i] * (i + 1);
612 if (!header->next_file)
614 index = header->next_file;