~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to extra/innochecksum.c

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

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