~jaypipes/drizzle/subscriber-plugin

« back to all changes in this revision

Viewing changes to extra/innochecksum.c

  • Committer: Brian Aker
  • Date: 2008-07-05 19:32:59 UTC
  • mfrom: (53.2.28 codestyle)
  • Revision ID: brian@tangent.org-20080705193259-opqzfb0oprfcg8dm
Merge from Monty's tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <sys/types.h>
36
36
#include <sys/stat.h>
37
37
#include <unistd.h>
 
38
#include <stdint.h>
38
39
 
39
40
/* all of these ripped from InnoDB code from MySQL 4.0.22 */
40
41
#define UT_HASH_RANDOM_MASK     1463735687
50
51
/* command line argument to do page checks (that's it) */
51
52
/* another argument to specify page ranges... seek to right spot and go from there */
52
53
 
53
 
typedef unsigned long int ulint;
 
54
typedef uint32_t ulint;
54
55
typedef unsigned char uchar;
55
56
 
56
57
/* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */
57
 
ulint mach_read_from_4(uchar *b)
 
58
static ulint mach_read_from_4(uchar *b)
58
59
{
59
60
  return( ((ulint)(b[0]) << 24)
60
61
          + ((ulint)(b[1]) << 16)
63
64
          );
64
65
}
65
66
 
66
 
ulint
 
67
static ulint
67
68
ut_fold_ulint_pair(
68
69
/*===============*/
69
70
            /* out: folded value */
74
75
                        ^ UT_HASH_RANDOM_MASK) + n2);
75
76
}
76
77
 
77
 
ulint
 
78
static ulint
78
79
ut_fold_binary(
79
80
/*===========*/
80
81
            /* out: folded value */
94
95
    return(fold);
95
96
}
96
97
 
97
 
ulint
 
98
static ulint
98
99
buf_calc_page_new_checksum(
99
100
/*=======================*/
100
101
               /* out: checksum */
119
120
    return(checksum);
120
121
}
121
122
 
122
 
ulint
 
123
static ulint
123
124
buf_calc_page_old_checksum(
124
125
/*=======================*/
125
126
               /* out: checksum */
219
220
  pages= size / UNIV_PAGE_SIZE;
220
221
  if (just_count)
221
222
  {
222
 
    printf("%lu\n", pages);
 
223
    printf("%u\n", pages);
223
224
    return 0;
224
225
  }
225
226
  else if (verbose)
226
227
  {
227
 
    printf("file %s= %llu bytes (%lu pages)...\n", argv[1], size, pages);
228
 
    printf("checking pages in range %lu to %lu\n", start_page, use_end_page ? end_page : (pages - 1));
 
228
    printf("file %s= %llu bytes (%u pages)...\n", argv[1], size, pages);
 
229
    printf("checking pages in range %u to %u\n", start_page, use_end_page ? end_page : (pages - 1));
229
230
  }
230
231
 
231
232
  /* open the file for reading */
275
276
    logseq= mach_read_from_4(p + FIL_PAGE_LSN + 4);
276
277
    logseqfield= mach_read_from_4(p + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM + 4);
277
278
    if (debug)
278
 
      printf("page %lu: log sequence number: first = %lu; second = %lu\n", ct, logseq, logseqfield);
 
279
      printf("page %u: log sequence number: first = %u; second = %u\n", ct, logseq, logseqfield);
279
280
    if (logseq != logseqfield)
280
281
    {
281
 
      fprintf(stderr, "page %lu invalid (fails log sequence number check)\n", ct);
 
282
      fprintf(stderr, "page %u invalid (fails log sequence number check)\n", ct);
282
283
      return 1;
283
284
    }
284
285
 
286
287
    oldcsum= buf_calc_page_old_checksum(p);
287
288
    oldcsumfield= mach_read_from_4(p + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM);
288
289
    if (debug)
289
 
      printf("page %lu: old style: calculated = %lu; recorded = %lu\n", ct, oldcsum, oldcsumfield);
 
290
      printf("page %u: old style: calculated = %u; recorded = %u\n", ct, oldcsum, oldcsumfield);
290
291
    if (oldcsumfield != mach_read_from_4(p + FIL_PAGE_LSN) && oldcsumfield != oldcsum)
291
292
    {
292
 
      fprintf(stderr, "page %lu invalid (fails old style checksum)\n", ct);
 
293
      fprintf(stderr, "page %u invalid (fails old style checksum)\n", ct);
293
294
      return 1;
294
295
    }
295
296
 
297
298
    csum= buf_calc_page_new_checksum(p);
298
299
    csumfield= mach_read_from_4(p + FIL_PAGE_SPACE_OR_CHKSUM);
299
300
    if (debug)
300
 
      printf("page %lu: new style: calculated = %lu; recorded = %lu\n", ct, csum, csumfield);
 
301
      printf("page %u: new style: calculated = %u; recorded = %u\n", ct, csum, csumfield);
301
302
    if (csumfield != 0 && csum != csumfield)
302
303
    {
303
 
      fprintf(stderr, "page %lu invalid (fails new style checksum)\n", ct);
 
304
      fprintf(stderr, "page %u invalid (fails new style checksum)\n", ct);
304
305
      return 1;
305
306
    }
306
307
 
318
319
        if (!lastt) lastt= now;
319
320
        if (now - lastt >= 1)
320
321
        {
321
 
          printf("page %lu okay: %.3f%% done\n", (ct - 1), (float) ct / pages * 100);
 
322
          printf("page %u okay: %.3f%% done\n", (ct - 1), (float) ct / pages * 100);
322
323
          lastt= now;
323
324
        }
324
325
      }