<commit_before>#include "common/structs.h"
#include "common/common.h"
#include <fstream>
#include <iostream>
#include <map>
#include <set>

using namespace cheesebase;

DskBlockHdr get_hdr(Addr addr, std::ifstream& fs) {
  fs.seekg(addr, std::ios_base::beg);
  DskBlockHdr hdr;
  fs.read((char*)&hdr, sizeof(hdr));
  return hdr;
}
bool check_free(std::set<Addr>& free, Addr first, BlockType type, int level, std::ifstream& fs) {

  auto next = first;
  while (next != 0) {
    if (next % (k_page_size / level) != 0) {
      std::cout << "Corrupted: invalid block in free list of PageAlloc!\n";
      return false;
    }
    auto hdr = get_hdr(next, fs);
    if (hdr.type() != type) {
      std::cout << "Corrupted: invalid block in free list of level " << level
                << " allocator.\n";
      return false;
    }
    free.insert(next);
    next = hdr.next();
  }
  return true;
}

int main(int argc, char* argv[]) {
  if (argc < 2) return 1;

  std::ifstream fs;
  fs.open(argv[1], std::fstream::in | std::fstream::binary);

  DskDatabaseHdr db_hdr;
  fs.read((char*)&db_hdr, sizeof(db_hdr));

  fs.seekg(0, std::ios_base::end);
  auto end = fs.tellg();
  if (db_hdr.end_of_file != end) {
    std::cout << "Corrupted: file size != end of file marker!\n";
    return 1;
  }

  std::set<Addr> free;
  if (!check_free(free, db_hdr.free_alloc_pg, BlockType::pg, 1, fs))<commit_msg>adjust filesize check in viewer<commit_after>#include "common/structs.h"
#include "common/common.h"
#include <fstream>
#include <iostream>
#include <map>
#include <set>

using namespace cheesebase;

DskBlockHdr get_hdr(Addr addr, std::ifstream& fs) {
  fs.seekg(addr, std::ios_base::beg);
  DskBlockHdr hdr;
  fs.read((char*)&hdr, sizeof(hdr));
  return hdr;
}
bool check_free(std::set<Addr>& free, Addr first, BlockType type, int level, std::ifstream& fs) {

  auto next = first;
  while (next != 0) {
    if (next % (k_page_size / level) != 0) {
      std::cout << "Corrupted: invalid block in free list of PageAlloc!\n";
      return false;
    }
    auto hdr = get_hdr(next, fs);
    if (hdr.type() != type) {
      std::cout << "Corrupted: invalid block in free list of level " << level
                << " allocator.\n";
      return false;
    }
    free.insert(next);
    next = hdr.next();
  }
  return true;
}

int main(int argc, char* argv[]) {
  if (argc < 2) return 1;

  std::ifstream fs;
  fs.open(argv[1], std::fstream::in | std::fstream::binary);

  DskDatabaseHdr db_hdr;
  fs.read((char*)&db_hdr, sizeof(db_hdr));

  fs.seekg(0, std::ios_base::end);
  auto end = fs.tellg();
  if (db_hdr.end_of_file > end) {
    std::cout << "Corrupted: file size < end of file marker!\n";
    return 1;
  }

  std::set<Addr> free;
  if (!check_free(free, db_hdr.free_alloc_pg, BlockType::pg, 1, fs))
{'fraction_non_alphanumeric': 0.167621776504298, 'fraction_numerical': 0.0057306590257879654, 'mean_word_length': 3.5414634146341464, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3674213', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1049, 'n_words': 265}