FreeBSD/contrib/subversion/subversion/libsvn_fs_x/verify.c
/* Verify that for all phys-to-log index entries for revisions START to
 * START + COUNT-1 in FS there is a consistent entry in the log-to-phys
 * index.  If given, invoke CANCEL_FUNC with CANCEL_BATON at regular
 * intervals. Use SCRATCH_POOL for temporary allocations.
 *
 * Please note that we can only check on pack / rev file granularity and
 * must only be called for a single rev / pack file.
 */


Please note that we can only check on pack / rev file granularity and
must only be called for a single rev / pack file.
Please note that we can only check on pack / rev file granularity and must only be called for a single rev / pack file .
static svn_error_t *
compare_p2l_to_l2p_index(svn_fs_t *fs,
                         svn_revnum_t start,
                         svn_revnum_t count,
                         svn_cancel_func_t cancel_func,
                         void *cancel_baton,
                         apr_pool_t *scratch_pool)
{
  svn_fs_x__data_t *ffd = fs->fsap_data;
  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
  apr_pool_t *iterpool2 = svn_pool_create(scratch_pool);
  apr_off_t max_offset;
  apr_off_t offset = 0;
  svn_fs_x__revision_file_t *rev_file;
  SVN_ERR(svn_fs_x__open_pack_or_rev_file(&rev_file, fs, start, scratch_pool,
                                          iterpool));
  SVN_ERR(svn_fs_x__p2l_get_max_offset(&max_offset, fs, rev_file, start,
                                       scratch_pool));
  for (offset = 0; offset < max_offset; )
    {
      apr_array_header_t *entries;
      svn_fs_x__p2l_entry_t *last_entry;
      int i;
      svn_pool_clear(iterpool);
      SVN_ERR(svn_fs_x__p2l_index_lookup(&entries, fs, rev_file, start,
                                         offset, ffd->p2l_page_size,
                                         iterpool, iterpool));
      if (entries->nelts == 0)
        return svn_error_createf(SVN_ERR_FS_INDEX_CORRUPTION,
                                 NULL,
                                 _("p2l does not cover offset %s"
                                   " for revision %ld"),
                                  apr_off_t_toa(scratch_pool, offset), start);
      last_entry
        = &APR_ARRAY_IDX(entries, entries->nelts-1, svn_fs_x__p2l_entry_t);
      offset = last_entry->offset + last_entry->size;
      for (i = 0; i < entries->nelts; ++i)
        {
          apr_uint32_t k;
          svn_fs_x__p2l_entry_t *entry
            = &APR_ARRAY_IDX(entries, i, svn_fs_x__p2l_entry_t);
          for (k = 0; k < entry->item_count; ++k)
            {
              apr_off_t l2p_offset;
              apr_uint32_t sub_item;
              svn_fs_x__id_t *p2l_item = &entry->items[k];
              svn_revnum_t revision
                = svn_fs_x__get_revnum(p2l_item->change_set);
              svn_pool_clear(iterpool2);
              SVN_ERR(svn_fs_x__item_offset(&l2p_offset, &sub_item, fs,
                                            rev_file, p2l_item, iterpool2));
              if (sub_item != k || l2p_offset != entry->offset)
                return svn_error_createf(SVN_ERR_FS_INDEX_INCONSISTENT,
                                         NULL,
                                         _("l2p index entry PHYS o%s:s%ld "
                                           "does not match p2l index value "
                                           "LOG r%ld:i%ld for PHYS o%s:s%ld"),
                                         apr_off_t_toa(scratch_pool,
                                                       l2p_offset),
                                         (long)sub_item,
                                         revision,
                                         (long)p2l_item->number,
                                         apr_off_t_toa(scratch_pool,
                                                       entry->offset),
                                         (long)k);
            }
        }
      if (cancel_func)
        SVN_ERR(cancel_func(cancel_baton));
    }
  svn_pool_destroy(iterpool2);
  svn_pool_destroy(iterpool);
  SVN_ERR(svn_fs_x__close_revision_file(rev_file));
  return SVN_NO_ERROR;
}
static svn_error_t * compare_p2l_to_l2p_index ( svn_fs_t * fs , svn_revnum_t start , svn_revnum_t count , svn_cancel_func_t cancel_func , void * cancel_baton , apr_pool_t * scratch_pool ) { svn_fs_x__data_t * ffd = fs -> fsap_data ; apr_pool_t * iterpool = svn_pool_create ( scratch_pool ) ; apr_pool_t * iterpool2 = svn_pool_create ( scratch_pool ) ; apr_off_t max_offset ; apr_off_t offset = 0 ; svn_fs_x__revision_file_t * rev_file ; SVN_ERR ( svn_fs_x__open_pack_or_rev_file ( & rev_file , fs , start , scratch_pool , iterpool ) ) ; SVN_ERR ( svn_fs_x__p2l_get_max_offset ( & max_offset , fs , rev_file , start , scratch_pool ) ) ; for ( offset = 0 ; offset < max_offset ; ) { apr_array_header_t * entries ; svn_fs_x__p2l_entry_t * last_entry ; int i ; svn_pool_clear ( iterpool ) ; SVN_ERR ( svn_fs_x__p2l_index_lookup ( & entries , fs , rev_file , start , offset , ffd -> p2l_page_size , iterpool , iterpool ) ) ; if ( entries -> nelts == 0 ) return svn_error_createf ( SVN_ERR_FS_INDEX_CORRUPTION , NULL , _ ( " " " " ) , apr_off_t_toa ( scratch_pool , offset ) , start ) ; last_entry = & APR_ARRAY_IDX ( entries , entries -> nelts - 1 , svn_fs_x__p2l_entry_t ) ; offset = last_entry -> offset + last_entry -> size ; for ( i = 0 ; i < entries -> nelts ; ++ i ) { apr_uint32_t k ; svn_fs_x__p2l_entry_t * entry = & APR_ARRAY_IDX ( entries , i , svn_fs_x__p2l_entry_t ) ; for ( k = 0 ; k < entry -> item_count ; ++ k ) { apr_off_t l2p_offset ; apr_uint32_t sub_item ; svn_fs_x__id_t * p2l_item = & entry -> items [ k ] ; svn_revnum_t revision = svn_fs_x__get_revnum ( p2l_item -> change_set ) ; svn_pool_clear ( iterpool2 ) ; SVN_ERR ( svn_fs_x__item_offset ( & l2p_offset , & sub_item , fs , rev_file , p2l_item , iterpool2 ) ) ; if ( sub_item != k || l2p_offset != entry -> offset ) return svn_error_createf ( SVN_ERR_FS_INDEX_INCONSISTENT , NULL , _ ( " " " " " " ) , apr_off_t_toa ( scratch_pool , l2p_offset ) , ( long ) sub_item , revision , ( long ) p2l_item -> number , apr_off_t_toa ( scratch_pool , entry -> offset ) , ( long ) k ) ; } } if ( cancel_func ) SVN_ERR ( cancel_func ( cancel_baton ) ) ; } svn_pool_destroy ( iterpool2 ) ; svn_pool_destroy ( iterpool ) ; SVN_ERR ( svn_fs_x__close_revision_file ( rev_file ) ) ; return SVN_NO_ERROR ; }
Verify that for all phys-to-log index entries for revisions START to
 START + COUNT-1 in FS there is a consistent entry in the log-to-phys
 index.
Verify that for all phys - to - log index entries for revisions START to START + COUNT - 1 in FS there is a consistent entry in the log - to - phys index .
/* common file access structure */ /* get the size of the rev / pack file as covered by the P2L index */ /* for all offsets in the file, get the P2L index entries and check
     them against the L2P index */ /* get all entries for the current block */ /* process all entries (and later continue with the next block) */ /* check all sub-items for consist entries in the L2P index */