~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to extra/innochecksum.c

  • Committer: Monty Taylor
  • Date: 2008-10-05 01:41:06 UTC
  • Revision ID: monty@inaugust.com-20081005014106-bulqe4kp7i6ipts1
Moved qsort declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <sys/stat.h>
39
39
#include <unistd.h>
40
40
#include <stdint.h>
41
 
#include <inttypes.h>
42
41
 
43
42
/* all of these ripped from InnoDB code from MySQL 4.0.22 */
44
43
#define UT_HASH_RANDOM_MASK     1463735687
54
53
/* command line argument to do page checks (that's it) */
55
54
/* another argument to specify page ranges... seek to right spot and go from there */
56
55
 
 
56
typedef uint32_t ulint;
 
57
typedef unsigned char uchar;
 
58
 
57
59
/* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */
58
 
static uint32_t mach_read_from_4(unsigned char *b)
 
60
static ulint mach_read_from_4(uchar *b)
59
61
{
60
 
  return( ((uint32_t)(b[0]) << 24)
61
 
          + ((uint32_t)(b[1]) << 16)
62
 
          + ((uint32_t)(b[2]) << 8)
63
 
          + (uint32_t)(b[3])
 
62
  return( ((ulint)(b[0]) << 24)
 
63
          + ((ulint)(b[1]) << 16)
 
64
          + ((ulint)(b[2]) << 8)
 
65
          + (ulint)(b[3])
64
66
          );
65
67
}
66
68
 
67
 
static uint32_t
68
 
ut_fold_uint32_t_pair(
 
69
static ulint
 
70
ut_fold_ulint_pair(
69
71
/*===============*/
70
72
            /* out: folded value */
71
 
    uint32_t   n1, /* in: uint32_t */
72
 
    uint32_t   n2) /* in: uint32_t */
 
73
    ulint   n1, /* in: ulint */
 
74
    ulint   n2) /* in: ulint */
73
75
{
74
76
    return(((((n1 ^ n2 ^ UT_HASH_RANDOM_MASK2) << 8) + n1)
75
77
                        ^ UT_HASH_RANDOM_MASK) + n2);
76
78
}
77
79
 
78
 
static uint32_t
 
80
static ulint
79
81
ut_fold_binary(
80
82
/*===========*/
81
83
            /* out: folded value */
82
 
    unsigned char*   str,    /* in: string of bytes */
83
 
    uint32_t   len)    /* in: length */
 
84
    uchar*   str,    /* in: string of bytes */
 
85
    ulint   len)    /* in: length */
84
86
{
85
 
    uint32_t   i;
86
 
    uint32_t   fold= 0;
 
87
    ulint   i;
 
88
    ulint   fold= 0;
87
89
 
88
90
    for (i= 0; i < len; i++)
89
91
    {
90
 
      fold= ut_fold_uint32_t_pair(fold, (uint32_t)(*str));
 
92
      fold= ut_fold_ulint_pair(fold, (ulint)(*str));
91
93
 
92
94
      str++;
93
95
    }
95
97
    return(fold);
96
98
}
97
99
 
98
 
static uint32_t
 
100
static ulint
99
101
buf_calc_page_new_checksum(
100
102
/*=======================*/
101
103
               /* out: checksum */
102
 
    unsigned char*    page) /* in: buffer page */
 
104
    uchar*    page) /* in: buffer page */
103
105
{
104
 
    uint32_t checksum;
 
106
    ulint checksum;
105
107
 
106
108
    /* Since the fields FIL_PAGE_FILE_FLUSH_LSN and ..._ARCH_LOG_NO
107
109
    are written outside the buffer pool to the first pages of data
120
122
    return(checksum);
121
123
}
122
124
 
123
 
static uint32_t
 
125
static ulint
124
126
buf_calc_page_old_checksum(
125
127
/*=======================*/
126
128
               /* out: checksum */
127
 
    unsigned char*    page) /* in: buffer page */
 
129
    uchar*    page) /* in: buffer page */
128
130
{
129
 
    uint32_t checksum;
 
131
    ulint checksum;
130
132
 
131
133
    checksum= ut_fold_binary(page, FIL_PAGE_FILE_FLUSH_LSN);
132
134
 
139
141
int main(int argc, char **argv)
140
142
{
141
143
  FILE *f;                     /* our input file */
142
 
  unsigned char *p;                     /* storage of pages read */
 
144
  uchar *p;                     /* storage of pages read */
143
145
  int bytes;                   /* bytes read count */
144
 
  uint32_t ct;                    /* current page number (0 based) */
 
146
  ulint ct;                    /* current page number (0 based) */
145
147
  int now;                     /* current time */
146
148
  int lastt;                   /* last time */
147
 
  uint32_t oldcsum, oldcsumfield, csum, csumfield, logseq, logseqfield; /* uint32_ts for checksum storage */
 
149
  ulint oldcsum, oldcsumfield, csum, csumfield, logseq, logseqfield; /* ulints for checksum storage */
148
150
  struct stat st;              /* for stat, if you couldn't guess */
149
 
  uint64_t size; /* size of file (has to be 64 bits) */
150
 
  uint32_t pages;                 /* number of pages in file */
151
 
  uint32_t start_page= 0, end_page= 0, use_end_page= 0; /* for starting and ending at certain pages */
 
151
  unsigned long long int size; /* size of file (has to be 64 bits) */
 
152
  ulint pages;                 /* number of pages in file */
 
153
  ulint start_page= 0, end_page= 0, use_end_page= 0; /* for starting and ending at certain pages */
152
154
  off_t offset= 0;
153
155
  int just_count= 0;          /* if true, just print page count */
154
156
  int verbose= 0;
225
227
  }
226
228
  else if (verbose)
227
229
  {
228
 
    printf("file %s= %"PRIu64" bytes (%u pages)...\n", argv[1], size, pages);
 
230
    printf("file %s= %llu bytes (%u pages)...\n", argv[1], size, pages);
229
231
    printf("checking pages in range %u to %u\n", start_page, use_end_page ? end_page : (pages - 1));
230
232
  }
231
233
 
257
259
  }
258
260
 
259
261
  /* allocate buffer for reading (so we don't realloc every time) */
260
 
  p= (unsigned char *)malloc(UNIV_PAGE_SIZE);
 
262
  p= (uchar *)malloc(UNIV_PAGE_SIZE);
261
263
 
262
264
  /* main checksumming loop */
263
265
  ct= start_page;