~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Describe, check and repair of MyISAM tables */
17
17
 
18
 
#include <drizzled/global.h>
 
18
#include <my_global.h>
19
19
 
20
 
#include <mystrings/m_ctype.h>
 
20
#include <m_ctype.h>
21
21
#include <stdarg.h>
22
 
#include <mysys/my_getopt.h>
23
 
#include <mysys/my_bit.h>
 
22
#include <my_getopt.h>
 
23
#include <my_bit.h>
24
24
#include <myisam.h>
25
 
#include <mystrings/m_string.h>
 
25
#include <m_string.h>
26
26
#ifdef HAVE_SYS_VADVICE_H
27
27
#include <sys/vadvise.h>
28
28
#endif
29
29
#ifdef HAVE_SYS_MMAN_H
30
30
#include <sys/mman.h>
31
31
#endif
 
32
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
32
33
 
33
34
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
34
35
#define my_raid_delete(A,B,C) my_delete(A,B)
35
36
 
36
37
#include "myisamdef.h"
37
38
 
38
 
static uint32_t decode_bits;
 
39
static uint decode_bits;
39
40
static char **default_argv;
40
41
static const char *load_default_groups[]= { "myisamchk", 0 };
41
42
static const char *set_collation_name, *opt_tmpdir;
42
 
static const CHARSET_INFO *set_collation;
 
43
static CHARSET_INFO *set_collation;
43
44
static long opt_myisam_block_size;
44
45
static long opt_key_cache_block_size;
45
46
static const char *my_progname_short;
48
49
static const char *type_names[]=
49
50
{ "impossible","char","binary", "short", "long", "float",
50
51
  "double","number","unsigned short",
51
 
  "unsigned long","int64_t","uint64_t","int24",
 
52
  "unsigned long","longlong","ulonglong","int24",
52
53
  "uint24","int8","varchar", "varbin","?",
53
54
  "?"};
54
55
 
71
72
static int myisamchk(MI_CHECK *param, char *filename);
72
73
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
73
74
static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
74
 
                           char * name, uint32_t sort_key,
75
 
                           bool write_info, bool update_index);
 
75
                           char * name, uint sort_key,
 
76
                           my_bool write_info, my_bool update_index);
76
77
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
77
78
                             MI_KEYDEF *keyinfo,
78
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
79
 
                             File new_file, bool update_index);
 
79
                             my_off_t page,uchar *buff,uint sortkey,
 
80
                             File new_file, my_bool update_index);
80
81
 
81
82
MI_CHECK check_param;
82
83
 
99
100
    int new_error=myisamchk(&check_param, *(argv++));
100
101
    if ((check_param.testflag & T_REP_ANY) != T_REP)
101
102
      check_param.testflag&= ~T_REP;
102
 
    fflush(stdout);
103
 
    fflush(stderr);
 
103
    VOID(fflush(stdout));
 
104
    VOID(fflush(stderr));
104
105
    if ((check_param.error_printed | check_param.warning_printed) &&
105
106
        (check_param.testflag & T_FORCE_CREATE) &&
106
107
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
107
108
                                   T_SORT_INDEX))))
108
109
    {
109
 
      uint32_t old_testflag=check_param.testflag;
 
110
      uint old_testflag=check_param.testflag;
110
111
      if (!(check_param.testflag & T_REP))
111
112
        check_param.testflag|= T_REP_BY_SORT;
112
113
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
113
114
      error|=myisamchk(&check_param, argv[-1]);
114
115
      check_param.testflag= old_testflag;
115
 
      fflush(stdout);
116
 
      fflush(stderr);
 
116
      VOID(fflush(stdout));
 
117
      VOID(fflush(stderr));
117
118
    }
118
119
    else
119
120
      error|=new_error;
120
121
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
121
122
    {
122
123
      puts("\n---------\n");
123
 
      fflush(stdout);
 
124
      VOID(fflush(stdout));
124
125
    }
125
126
  }
126
127
  if (check_param.total_files > 1)
145
146
  OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE,
146
147
  OPT_KEY_CACHE_BLOCK_SIZE, OPT_MYISAM_BLOCK_SIZE,
147
148
  OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE,
148
 
  OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS,
 
149
  OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN,
 
150
  OPT_FT_MAX_WORD_LEN, OPT_FT_STOPWORD_FILE,
149
151
  OPT_MAX_RECORD_LENGTH, OPT_AUTO_CLOSE, OPT_STATS_METHOD
150
152
};
151
153
 
154
156
  {"analyze", 'a',
155
157
   "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.",
156
158
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
159
#ifdef __NETWARE__
 
160
  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
 
161
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
162
#endif
157
163
  {"block-search", 'b',
158
164
   "No help available.",
159
165
   0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
162
168
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
163
169
  {"character-sets-dir", OPT_CHARSETS_DIR,
164
170
   "Directory where character sets are.",
165
 
   (char**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
171
   (uchar**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
166
172
  {"check", 'c',
167
173
   "Check table for errors.",
168
174
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
172
178
  {"correct-checksum", OPT_CORRECT_CHECKSUM,
173
179
   "Correct checksum information for table.",
174
180
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
181
#ifndef DBUG_OFF
 
182
  {"debug", '#',
 
183
   "Output debug log. Often this is 'd:t:o,filename'.",
 
184
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
185
#endif
175
186
  {"description", 'd',
176
187
   "Prints some information about table.",
177
188
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
178
189
  {"data-file-length", 'D',
179
190
   "Max length of data file (when recreating data-file when it's full).",
180
 
   (char**) &check_param.max_data_file_length,
181
 
   (char**) &check_param.max_data_file_length,
 
191
   (uchar**) &check_param.max_data_file_length,
 
192
   (uchar**) &check_param.max_data_file_length,
182
193
   0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
183
194
  {"extend-check", 'e',
184
195
   "If used when checking a table, ensure that the table is 100 percent consistent, which will take a long time. If used when repairing a table, try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option with repair if you are not totally desperate.",
200
211
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
201
212
  {"keys-used", 'k',
202
213
   "Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts.",
203
 
   (char**) &check_param.keys_in_use,
204
 
   (char**) &check_param.keys_in_use,
 
214
   (uchar**) &check_param.keys_in_use,
 
215
   (uchar**) &check_param.keys_in_use,
205
216
   0, GET_ULL, REQUIRED_ARG, -1, 0, 0, 0, 0, 0},
206
217
  {"max-record-length", OPT_MAX_RECORD_LENGTH,
207
218
   "Skip rows bigger than this if myisamchk can't allocate memory to hold it",
208
 
   (char**) &check_param.max_record_length,
209
 
   (char**) &check_param.max_record_length,
210
 
   0, GET_ULL, REQUIRED_ARG, INT64_MAX, 0, INT64_MAX, 0, 0, 0},
 
219
   (uchar**) &check_param.max_record_length,
 
220
   (uchar**) &check_param.max_record_length,
 
221
   0, GET_ULL, REQUIRED_ARG, LONGLONG_MAX, 0, LONGLONG_MAX, 0, 0, 0},
211
222
  {"medium-check", 'm',
212
223
   "Faster than extend-check, but only finds 99.99% of all errors. Should be good enough for most cases.",
213
224
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
235
246
#endif
236
247
  {"set-auto-increment", 'A',
237
248
   "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
238
 
   (char**) &check_param.auto_increment_value,
239
 
   (char**) &check_param.auto_increment_value,
 
249
   (uchar**) &check_param.auto_increment_value,
 
250
   (uchar**) &check_param.auto_increment_value,
240
251
   0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
241
252
  {"set-collation", OPT_SET_COLLATION,
242
253
   "Change the collation used by the index",
243
 
   (char**) &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
254
   (uchar**) &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
244
255
  {"set-variable", 'O',
245
256
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
246
257
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
252
263
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
253
264
  {"sort-records", 'R',
254
265
   "Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)",
255
 
   (char**) &check_param.opt_sort_key,
256
 
   (char**) &check_param.opt_sort_key,
 
266
   (uchar**) &check_param.opt_sort_key,
 
267
   (uchar**) &check_param.opt_sort_key,
257
268
   0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
258
269
  {"tmpdir", 't',
259
270
   "Path for temporary files.",
260
 
   (char**) &opt_tmpdir,
 
271
   (uchar**) &opt_tmpdir,
261
272
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
262
273
  {"update-state", 'U',
263
274
   "Mark tables as crashed if any errors were found.",
275
286
   "Wait if table is locked.",
276
287
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
277
288
  { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
278
 
    (char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
 
289
    (uchar**) &check_param.use_buffers, (uchar**) &check_param.use_buffers, 0,
279
290
    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
280
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
 
291
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
281
292
  { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
282
 
    (char**) &opt_key_cache_block_size,
283
 
    (char**) &opt_key_cache_block_size, 0,
 
293
    (uchar**) &opt_key_cache_block_size,
 
294
    (uchar**) &opt_key_cache_block_size, 0,
284
295
    GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
285
296
    MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
286
297
  { "myisam_block_size", OPT_MYISAM_BLOCK_SIZE,  "",
287
 
    (char**) &opt_myisam_block_size, (char**) &opt_myisam_block_size, 0,
 
298
    (uchar**) &opt_myisam_block_size, (uchar**) &opt_myisam_block_size, 0,
288
299
    GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
289
300
    MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
290
301
  { "read_buffer_size", OPT_READ_BUFFER_SIZE, "",
291
 
    (char**) &check_param.read_buffer_length,
292
 
    (char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
 
302
    (uchar**) &check_param.read_buffer_length,
 
303
    (uchar**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
293
304
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
294
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
305
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
295
306
  { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
296
 
    (char**) &check_param.write_buffer_length,
297
 
    (char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
 
307
    (uchar**) &check_param.write_buffer_length,
 
308
    (uchar**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
298
309
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
299
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
310
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
300
311
  { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
301
 
    (char**) &check_param.sort_buffer_length,
302
 
    (char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
 
312
    (uchar**) &check_param.sort_buffer_length,
 
313
    (uchar**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
303
314
    (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
304
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
315
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
305
316
  { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
306
 
    (char**) &check_param.sort_key_blocks,
307
 
    (char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
 
317
    (uchar**) &check_param.sort_key_blocks,
 
318
    (uchar**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
308
319
    BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
309
 
  { "decode_bits", OPT_DECODE_BITS, "", (char**) &decode_bits,
310
 
    (char**) &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
 
320
  { "decode_bits", OPT_DECODE_BITS, "", (uchar**) &decode_bits,
 
321
    (uchar**) &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
311
322
  {"stats_method", OPT_STATS_METHOD,
312
323
   "Specifies how index statistics collection code should treat NULLs. "
313
324
   "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
314
325
   "\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
315
 
   (char**) &myisam_stats_method_str, (char**) &myisam_stats_method_str, 0,
 
326
   (uchar**) &myisam_stats_method_str, (uchar**) &myisam_stats_method_str, 0,
316
327
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
317
328
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
318
329
};
319
330
 
320
331
 
 
332
#include <help_start.h>
 
333
 
321
334
static void print_version(void)
322
335
{
323
336
  printf("%s  Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
324
337
         MACHINE_TYPE);
 
338
  NETWARE_SET_SCREEN_MODE(1);
325
339
}
326
340
 
327
341
 
334
348
  puts("Used without options all tables on the command will be checked for errors");
335
349
  printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short);
336
350
  printf("\nGlobal options:\n");
 
351
#ifndef DBUG_OFF
 
352
  printf("\
 
353
  -#, --debug=...     Output debug log. Often this is 'd:t:o,filename'.\n");
 
354
#endif
337
355
  printf("\
338
356
  -?, --help          Display this help and exit.\n\
339
357
  -O, --set-variable var=option.\n\
342
360
                      directly with '--variable-name=value'.\n\
343
361
  -t, --tmpdir=path   Path for temporary files. Multiple paths can be\n\
344
362
                      specified, separated by ");
345
 
#if defined( __WIN__)
 
363
#if defined( __WIN__) || defined(__NETWARE__)
346
364
   printf("semicolon (;)");
347
365
#else
348
366
   printf("colon (:)");
438
456
  my_print_variables(my_long_options);
439
457
}
440
458
 
 
459
#include <help_end.h>
 
460
 
441
461
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
442
 
                                           "nulls_ignored", NULL};
 
462
                                           "nulls_ignored", NullS};
443
463
TYPELIB myisam_stats_method_typelib= {
444
464
  array_elements(myisam_stats_method_names) - 1, "",
445
465
  myisam_stats_method_names, NULL};
446
466
 
447
467
         /* Read options */
448
468
 
449
 
static bool
 
469
static my_bool
450
470
get_one_option(int optid,
451
471
               const struct my_option *opt __attribute__((unused)),
452
472
               char *argument)
453
473
{
454
474
  switch (optid) {
 
475
#ifdef __NETWARE__
 
476
  case OPT_AUTO_CLOSE:
 
477
    setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
 
478
    break;
 
479
#endif
455
480
  case 'a':
456
481
    if (argument == disabled_my_option)
457
482
      check_param.testflag&= ~T_STATISTICS;
543
568
      check_param.testflag|= T_FAST;
544
569
    break;
545
570
  case 'k':
546
 
    check_param.keys_in_use= (uint64_t) strtoll(argument, NULL, 10);
 
571
    check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10);
547
572
    break;
548
573
  case 'm':
549
574
    if (argument == disabled_my_option)
639
664
    else
640
665
      check_param.testflag|= T_UPDATE_STATE;
641
666
    break;
 
667
  case '#':
 
668
    if (argument == disabled_my_option)
 
669
    {
 
670
      DBUG_POP();
 
671
    }
 
672
    else
 
673
    {
 
674
      DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace");
 
675
    }
 
676
    break;
642
677
  case 'V':
643
678
    print_version();
644
679
    exit(0);
715
750
  if ((check_param.testflag & T_UNPACK) &&
716
751
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
717
752
  {
718
 
    fprintf(stderr,
719
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
720
 
            my_progname_short);
 
753
    VOID(fprintf(stderr,
 
754
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
755
                 my_progname_short));
721
756
    exit(1);
722
757
  }
723
758
  if ((check_param.testflag & T_READONLY) &&
725
760
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
726
761
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
727
762
  {
728
 
    fprintf(stderr,
729
 
            "%s: Can't use --readonly when repairing or sorting\n",
730
 
            my_progname_short);
 
763
    VOID(fprintf(stderr,
 
764
                 "%s: Can't use --readonly when repairing or sorting\n",
 
765
                 my_progname_short));
731
766
    exit(1);
732
767
  }
733
768
 
753
788
{
754
789
  int error,lock_type,recreate;
755
790
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
756
 
  uint32_t raid_chunks;
 
791
  uint raid_chunks;
757
792
  MI_INFO *info;
758
793
  File datafile;
759
794
  char llbuff[22],llbuff2[22];
760
 
  bool state_updated=0;
 
795
  my_bool state_updated=0;
761
796
  MYISAM_SHARE *share;
 
797
  DBUG_ENTER("myisamchk");
762
798
 
763
799
  param->out_flag=error=param->warning_printed=param->error_printed=
764
800
    recreate=0;
808
844
                  my_errno,filename);
809
845
      break;
810
846
    }
811
 
    return(1);
 
847
    DBUG_RETURN(1);
812
848
  }
813
849
  share=info->s;
814
850
  share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
823
859
  */
824
860
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
825
861
  {
826
 
    bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
 
862
    my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
827
863
 
828
864
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
829
865
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
855
891
      {
856
892
        mi_check_print_error(param,"%d when closing MyISAM-table '%s'",
857
893
                             my_errno,filename);
858
 
        return(1);
 
894
        DBUG_RETURN(1);
859
895
      }
860
 
      return(0);
 
896
      DBUG_RETURN(0);
861
897
    }
862
898
  }
863
899
  if ((param->testflag & (T_REP_ANY | T_STATISTICS |
880
916
      param->language= set_collation->number;
881
917
    if (recreate_table(param, &info,filename))
882
918
    {
883
 
      fprintf(stderr,
884
 
              "MyISAM-table '%s' is not fixed because of errors\n",
885
 
              filename);
 
919
      VOID(fprintf(stderr,
 
920
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
921
              filename));
886
922
      return(-1);
887
923
    }
888
924
    recreate=1;
933
969
    {
934
970
      if (param->testflag & T_REP_ANY)
935
971
      {
936
 
        uint64_t tmp=share->state.key_map;
 
972
        ulonglong tmp=share->state.key_map;
937
973
        mi_copy_keys_active(share->state.key_map, share->base.keys,
938
974
                            param->keys_in_use);
939
975
        if (tmp != share->state.key_map)
973
1009
      }
974
1010
      if (!error && param->testflag & T_SORT_RECORDS)
975
1011
      {
976
 
        uint32_t key;
 
1012
        uint key;
977
1013
        /*
978
1014
          We can't update the index in mi_sort_records if we have a
979
1015
          prefix compressed or fulltext index
980
1016
        */
981
 
        bool update_index=1;
 
1017
        my_bool update_index=1;
982
1018
        for (key=0 ; key < share->base.keys; key++)
983
 
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
 
1019
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
984
1020
            update_index=0;
985
1021
 
986
1022
        error=mi_sort_records(param,info,filename,param->opt_sort_key,
987
1023
                           /* what is the following parameter for ? */
988
 
                              (bool) !(param->testflag & T_REP),
 
1024
                              (my_bool) !(param->testflag & T_REP),
989
1025
                              update_index);
990
1026
        datafile=info->dfile;   /* This is now locked */
991
1027
        if (!error && !update_index)
1031
1067
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1032
1068
      {
1033
1069
        if (param->testflag & (T_EXTEND | T_MEDIUM))
1034
 
          init_key_cache(dflt_key_cache,opt_key_cache_block_size,
1035
 
                         param->use_buffers, 0, 0);
1036
 
        init_io_cache(&param->read_cache,datafile,
1037
 
                      (uint) param->read_buffer_length,
1038
 
                      READ_CACHE,
1039
 
                      (param->start_check_pos ?
1040
 
                       param->start_check_pos :
1041
 
                       share->pack.header_length),
1042
 
                      1,
1043
 
                      MYF(MY_WME));
 
1070
          VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
 
1071
                              param->use_buffers, 0, 0));
 
1072
        VOID(init_io_cache(&param->read_cache,datafile,
 
1073
                           (uint) param->read_buffer_length,
 
1074
                           READ_CACHE,
 
1075
                           (param->start_check_pos ?
 
1076
                            param->start_check_pos :
 
1077
                            share->pack.header_length),
 
1078
                           1,
 
1079
                           MYF(MY_WME)));
1044
1080
        lock_memory(param);
1045
1081
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1046
1082
                                 HA_OPTION_COMPRESS_RECORD)) ||
1047
1083
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1048
1084
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1049
1085
        error|=flush_blocks(param, share->key_cache, share->kfile);
1050
 
        end_io_cache(&param->read_cache);
 
1086
        VOID(end_io_cache(&param->read_cache));
1051
1087
      }
1052
1088
      if (!error)
1053
1089
      {
1068
1104
  if ((param->testflag & T_AUTO_INC) ||
1069
1105
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1070
1106
    update_auto_increment_key(param, info,
1071
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1107
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1072
1108
 
1073
1109
  if (!(param->testflag & T_DESCRIPT))
1074
1110
  {
1080
1116
                                (state_updated ? UPDATE_STAT : 0) |
1081
1117
                                ((param->testflag & T_SORT_RECORDS) ?
1082
1118
                                 UPDATE_SORT : 0)));
 
1119
    VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename));
1083
1120
    info->update&= ~HA_STATE_CHANGED;
1084
1121
  }
1085
1122
  mi_lock_database(info, F_UNLCK);
1087
1124
  if (mi_close(info))
1088
1125
  {
1089
1126
    mi_check_print_error(param,"%d when closing MyISAM-table '%s'",my_errno,filename);
1090
 
    return(1);
 
1127
    DBUG_RETURN(1);
1091
1128
  }
1092
1129
  if (error == 0)
1093
1130
  {
1100
1137
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1101
1138
                               MYF(0));
1102
1139
  }
1103
 
  fflush(stdout); fflush(stderr);
 
1140
  VOID(fflush(stdout)); VOID(fflush(stderr));
1104
1141
  if (param->error_printed)
1105
1142
  {
1106
1143
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1107
1144
    {
1108
 
      fprintf(stderr,
1109
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1110
 
              filename);
 
1145
      VOID(fprintf(stderr,
 
1146
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1147
                   filename));
1111
1148
      if (param->testflag & T_REP_ANY)
1112
 
        fprintf(stderr,
1113
 
                "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
 
1149
        VOID(fprintf(stderr,
 
1150
                     "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
1114
1151
    }
1115
1152
    else if (!(param->error_printed & 2) &&
1116
1153
             !(param->testflag & T_FORCE_CREATE))
1117
 
      fprintf(stderr,
1118
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1119
 
              filename);
 
1154
      VOID(fprintf(stderr,
 
1155
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1156
              filename));
1120
1157
  }
1121
1158
  else if (param->warning_printed &&
1122
1159
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1123
1160
                          T_FORCE_CREATE)))
1124
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1125
 
            filename);
1126
 
  fflush(stderr);
1127
 
  return(error);
 
1161
    VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
 
1162
                 filename));
 
1163
  VOID(fflush(stderr));
 
1164
  DBUG_RETURN(error);
1128
1165
} /* myisamchk */
1129
1166
 
1130
1167
 
1132
1169
 
1133
1170
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1134
1171
{
1135
 
  uint32_t key,keyseg_nr,field,start;
 
1172
  uint key,keyseg_nr,field,start;
1136
1173
  register MI_KEYDEF *keyinfo;
1137
1174
  register HA_KEYSEG *keyseg;
1138
1175
  register const char *text;
1140
1177
  enum en_fieldtype type;
1141
1178
  MYISAM_SHARE *share=info->s;
1142
1179
  char llbuff[22],llbuff2[22];
 
1180
  DBUG_ENTER("describe");
1143
1181
 
1144
1182
  printf("\nMyISAM file:         %s\n",name);
1145
1183
  fputs("Record format:       ",stdout);
1169
1207
    }
1170
1208
    pos=buff;
1171
1209
    if (share->state.changed & STATE_CRASHED)
1172
 
      my_stpcpy(buff,"crashed");
 
1210
      strmov(buff,"crashed");
1173
1211
    else
1174
1212
    {
1175
1213
      if (share->state.open_count)
1176
 
        pos=my_stpcpy(pos,"open,");
 
1214
        pos=strmov(pos,"open,");
1177
1215
      if (share->state.changed & STATE_CHANGED)
1178
 
        pos=my_stpcpy(pos,"changed,");
 
1216
        pos=strmov(pos,"changed,");
1179
1217
      else
1180
 
        pos=my_stpcpy(pos,"checked,");
 
1218
        pos=strmov(pos,"checked,");
1181
1219
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1182
 
        pos=my_stpcpy(pos,"analyzed,");
 
1220
        pos=strmov(pos,"analyzed,");
1183
1221
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1184
 
        pos=my_stpcpy(pos,"optimized keys,");
 
1222
        pos=strmov(pos,"optimized keys,");
1185
1223
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1186
 
        pos=my_stpcpy(pos,"sorted index pages,");
 
1224
        pos=strmov(pos,"sorted index pages,");
1187
1225
      pos[-1]=0;                                /* Remove extra ',' */
1188
1226
    }      
1189
1227
    printf("Status:              %s\n",buff);
1210
1248
  printf("Data records:        %13s  Deleted blocks:     %13s\n",
1211
1249
         llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
1212
1250
  if (param->testflag & T_SILENT)
1213
 
    return;                             /* This is enough */
 
1251
    DBUG_VOID_RETURN;                           /* This is enough */
1214
1252
 
1215
1253
  if (param->testflag & T_VERBOSE)
1216
1254
  {
1241
1279
  printf("Recordlength:        %13d\n",(int) share->base.pack_reclength);
1242
1280
  if (! mi_is_all_keys_active(share->state.key_map, share->base.keys))
1243
1281
  {
1244
 
    int64_t2str(share->state.key_map,buff,2);
 
1282
    longlong2str(share->state.key_map,buff,2);
1245
1283
    printf("Using only keys '%s' of %d possibly keys\n",
1246
1284
           buff, share->base.keys);
1247
1285
  }
1249
1287
  printf("Key Start Len Index   Type");
1250
1288
  if (param->testflag & T_VERBOSE)
1251
1289
    printf("                     Rec/key         Root  Blocksize");
1252
 
  putchar('\n');
 
1290
  VOID(putchar('\n'));
1253
1291
 
1254
1292
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1255
1293
       key < share->base.keys;
1257
1295
  {
1258
1296
    keyseg=keyinfo->seg;
1259
1297
    if (keyinfo->flag & HA_NOSAME) text="unique ";
 
1298
    else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
1260
1299
    else text="multip.";
1261
1300
 
1262
1301
    pos=buff;
1263
1302
    if (keyseg->flag & HA_REVERSE_SORT)
1264
1303
      *pos++ = '-';
1265
 
    pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1304
    pos=strmov(pos,type_names[keyseg->type]);
1266
1305
    *pos++ = ' ';
1267
1306
    *pos=0;
1268
1307
    if (keyinfo->flag & HA_PACK_KEY)
1269
 
      pos=my_stpcpy(pos,prefix_packed_txt);
 
1308
      pos=strmov(pos,prefix_packed_txt);
1270
1309
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1271
 
      pos=my_stpcpy(pos,bin_packed_txt);
 
1310
      pos=strmov(pos,bin_packed_txt);
1272
1311
    if (keyseg->flag & HA_SPACE_PACK)
1273
 
      pos=my_stpcpy(pos,diff_txt);
 
1312
      pos=strmov(pos,diff_txt);
1274
1313
    if (keyseg->flag & HA_BLOB_PART)
1275
 
      pos=my_stpcpy(pos,blob_txt);
 
1314
      pos=strmov(pos,blob_txt);
1276
1315
    if (keyseg->flag & HA_NULL_PART)
1277
 
      pos=my_stpcpy(pos,null_txt);
 
1316
      pos=strmov(pos,null_txt);
1278
1317
    *pos=0;
1279
1318
 
1280
1319
    printf("%-4d%-6ld%-3d %-8s%-21s",
1287
1326
      printf("%11lu %12s %10d",
1288
1327
             share->state.rec_per_key_part[keyseg_nr++],
1289
1328
             buff,keyinfo->block_length);
1290
 
    putchar('\n');
 
1329
    VOID(putchar('\n'));
1291
1330
    while ((++keyseg)->type != HA_KEYTYPE_END)
1292
1331
    {
1293
1332
      pos=buff;
1294
1333
      if (keyseg->flag & HA_REVERSE_SORT)
1295
1334
        *pos++ = '-';
1296
 
      pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1335
      pos=strmov(pos,type_names[keyseg->type]);
1297
1336
      *pos++= ' ';
1298
1337
      if (keyseg->flag & HA_SPACE_PACK)
1299
 
        pos=my_stpcpy(pos,diff_txt);
 
1338
        pos=strmov(pos,diff_txt);
1300
1339
      if (keyseg->flag & HA_BLOB_PART)
1301
 
        pos=my_stpcpy(pos,blob_txt);
 
1340
        pos=strmov(pos,blob_txt);
1302
1341
      if (keyseg->flag & HA_NULL_PART)
1303
 
        pos=my_stpcpy(pos,null_txt);
 
1342
        pos=strmov(pos,null_txt);
1304
1343
      *pos=0;
1305
1344
      printf("    %-6ld%-3d         %-21s",
1306
1345
             (long) keyseg->start+1,keyseg->length,buff);
1307
1346
      if (param->testflag & T_VERBOSE)
1308
1347
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1309
 
      putchar('\n');
 
1348
      VOID(putchar('\n'));
1310
1349
    }
1311
1350
    keyseg++;
1312
1351
  }
1317
1356
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1318
1357
         key < share->state.header.uniques; key++, uniqueinfo++)
1319
1358
    {
1320
 
      bool new_row=0;
 
1359
      my_bool new_row=0;
1321
1360
      char null_bit[8],null_pos[8];
1322
1361
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1323
1362
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1344
1383
    printf("\nField Start Length Nullpos Nullbit Type");
1345
1384
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1346
1385
      printf("                         Huff tree  Bits");
1347
 
    putchar('\n');
 
1386
    VOID(putchar('\n'));
1348
1387
    start=1;
1349
1388
    for (field=0 ; field < share->base.fields ; field++)
1350
1389
    {
1352
1391
        type=share->rec[field].base_type;
1353
1392
      else
1354
1393
        type=(enum en_fieldtype) share->rec[field].type;
1355
 
      end=my_stpcpy(buff,field_pack[type]);
 
1394
      end=strmov(buff,field_pack[type]);
1356
1395
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1357
1396
      {
1358
1397
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1359
 
          end=my_stpcpy(end,", not_always");
 
1398
          end=strmov(end,", not_always");
1360
1399
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1361
 
          end=my_stpcpy(end,", no empty");
 
1400
          end=strmov(end,", no empty");
1362
1401
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1363
1402
        {
1364
1403
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1365
 
          end= strchr(end, '\0');
 
1404
          end=strend(end);
1366
1405
        }
1367
1406
      }
1368
1407
      if (buff[0] == ',')
1369
 
        my_stpcpy(buff,buff+2);
 
1408
        strmov(buff,buff+2);
1370
1409
      int10_to_str((long) share->rec[field].length,length,10);
1371
1410
      null_bit[0]=null_pos[0]=0;
1372
1411
      if (share->rec[field].null_bit)
1383
1422
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1384
1423
                 share->rec[field].huff_tree->quick_table_bits);
1385
1424
      }
1386
 
      putchar('\n');
 
1425
      VOID(putchar('\n'));
1387
1426
      start+=share->rec[field].length;
1388
1427
    }
1389
1428
  }
1390
 
  return;
 
1429
  DBUG_VOID_RETURN;
1391
1430
} /* describe */
1392
1431
 
1393
1432
 
1395
1434
 
1396
1435
static int mi_sort_records(MI_CHECK *param,
1397
1436
                           register MI_INFO *info, char * name,
1398
 
                           uint32_t sort_key,
1399
 
                           bool write_info,
1400
 
                           bool update_index)
 
1437
                           uint sort_key,
 
1438
                           my_bool write_info,
 
1439
                           my_bool update_index)
1401
1440
{
1402
1441
  int got_error;
1403
 
  uint32_t key;
 
1442
  uint key;
1404
1443
  MI_KEYDEF *keyinfo;
1405
1444
  File new_file;
1406
 
  unsigned char *temp_buff;
 
1445
  uchar *temp_buff;
1407
1446
  ha_rows old_record_count;
1408
1447
  MYISAM_SHARE *share=info->s;
1409
1448
  char llbuff[22],llbuff2[22];
1410
1449
  SORT_INFO sort_info;
1411
1450
  MI_SORT_PARAM sort_param;
 
1451
  DBUG_ENTER("sort_records");
1412
1452
 
1413
 
  memset(&sort_info, 0, sizeof(sort_info));
1414
 
  memset(&sort_param, 0, sizeof(sort_param));
 
1453
  bzero((char*)&sort_info,sizeof(sort_info));
 
1454
  bzero((char*)&sort_param,sizeof(sort_param));
1415
1455
  sort_param.sort_info=&sort_info;
1416
1456
  sort_info.param=param;
1417
1457
  keyinfo= &share->keyinfo[sort_key];
1425
1465
                           "Can't sort table '%s' on key %d;  No such key",
1426
1466
                name,sort_key+1);
1427
1467
    param->error_printed=0;
1428
 
    return(0);                          /* Nothing to do */
 
1468
    DBUG_RETURN(0);                             /* Nothing to do */
 
1469
  }
 
1470
  if (keyinfo->flag & HA_FULLTEXT)
 
1471
  {
 
1472
    mi_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
 
1473
                           name,sort_key+1);
 
1474
    param->error_printed=0;
 
1475
    DBUG_RETURN(0);                             /* Nothing to do */
1429
1476
  }
1430
1477
  if (share->data_file_type == COMPRESSED_RECORD)
1431
1478
  {
1432
1479
    mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
1433
1480
    param->error_printed=0;
1434
 
    return(0);                          /* Nothing to do */
 
1481
    DBUG_RETURN(0);                             /* Nothing to do */
1435
1482
  }
1436
1483
  if (!(param->testflag & T_SILENT))
1437
1484
  {
1442
1489
             llstr(info->state->del,llbuff2));
1443
1490
  }
1444
1491
  if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
1445
 
    return(0);                          /* Nothing to do */
 
1492
    DBUG_RETURN(0);                             /* Nothing to do */
1446
1493
 
1447
1494
  init_key_cache(dflt_key_cache, opt_key_cache_block_size, param->use_buffers,
1448
1495
                 0, 0);
1452
1499
    goto err;
1453
1500
  info->opt_flag|=WRITE_CACHE_USED;
1454
1501
 
1455
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1502
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1456
1503
  {
1457
1504
    mi_check_print_error(param,"Not enough memory for key block");
1458
1505
    goto err;
1488
1535
  for (key=0 ; key < share->base.keys ; key++)
1489
1536
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1490
1537
 
1491
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1538
  if (my_pread(share->kfile,(uchar*) temp_buff,
1492
1539
               (uint) keyinfo->block_length,
1493
1540
               share->state.key_root[sort_key],
1494
1541
               MYF(MY_NABP+MY_WME)))
1523
1570
    goto err;
1524
1571
  }
1525
1572
 
1526
 
  my_close(info->dfile,MYF(MY_WME));
 
1573
  VOID(my_close(info->dfile,MYF(MY_WME)));
1527
1574
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1528
1575
  info->dfile=new_file;                         /* Use new datafile */
1529
1576
  info->state->del=0;
1537
1584
 
1538
1585
  if (param->testflag & T_WRITE_LOOP)
1539
1586
  {
1540
 
    fputs("          \r",stdout); fflush(stdout);
 
1587
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1541
1588
  }
1542
1589
  got_error=0;
1543
1590
 
1544
1591
err:
1545
1592
  if (got_error && new_file >= 0)
1546
1593
  {
1547
 
    end_io_cache(&info->rec_cache);
 
1594
    VOID(end_io_cache(&info->rec_cache));
1548
1595
    (void) my_close(new_file,MYF(MY_WME));
1549
1596
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
1550
1597
                          MYF(MY_WME));
1551
1598
  }
1552
1599
  if (temp_buff)
1553
1600
  {
1554
 
    my_afree((unsigned char*) temp_buff);
 
1601
    my_afree((uchar*) temp_buff);
1555
1602
  }
1556
 
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1557
 
  if (rec_buff_ptr != NULL)
1558
 
    free(rec_buff_ptr);
1559
 
 
 
1603
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1604
          MYF(MY_ALLOW_ZERO_PTR));
1560
1605
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1561
 
  end_io_cache(&info->rec_cache);
1562
 
  free(sort_info.buff);
 
1606
  VOID(end_io_cache(&info->rec_cache));
 
1607
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1563
1608
  sort_info.buff=0;
1564
1609
  share->state.sortkey=sort_key;
1565
 
  return(flush_blocks(param, share->key_cache, share->kfile) |
 
1610
  DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) |
1566
1611
              got_error);
1567
1612
} /* sort_records */
1568
1613
 
1571
1616
 
1572
1617
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1573
1618
                             MI_KEYDEF *keyinfo,
1574
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1575
 
                             File new_file,bool update_index)
 
1619
                             my_off_t page, uchar *buff, uint sort_key,
 
1620
                             File new_file,my_bool update_index)
1576
1621
{
1577
1622
  uint  nod_flag,used_length,key_length;
1578
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1623
  uchar *temp_buff,*keypos,*endpos;
1579
1624
  my_off_t next_page,rec_pos;
1580
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1625
  uchar lastkey[MI_MAX_KEY_BUFF];
1581
1626
  char llbuff[22];
1582
1627
  SORT_INFO *sort_info= sort_param->sort_info;
1583
1628
  MI_CHECK *param=sort_info->param;
 
1629
  DBUG_ENTER("sort_record_index");
1584
1630
 
1585
1631
  nod_flag=mi_test_if_nod(buff);
1586
1632
  temp_buff=0;
1587
1633
 
1588
1634
  if (nod_flag)
1589
1635
  {
1590
 
    if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1636
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1591
1637
    {
1592
1638
      mi_check_print_error(param,"Not Enough memory");
1593
 
      return(-1);
 
1639
      DBUG_RETURN(-1);
1594
1640
    }
1595
1641
  }
1596
1642
  used_length=mi_getint(buff);
1601
1647
    if (nod_flag)
1602
1648
    {
1603
1649
      next_page=_mi_kpos(nod_flag,keypos);
1604
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1650
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1605
1651
                  (uint) keyinfo->block_length, next_page,
1606
1652
                   MYF(MY_NABP+MY_WME)))
1607
1653
      {
1639
1685
      goto err;
1640
1686
  }
1641
1687
  /* Clear end of block to get better compression if the table is backuped */
1642
 
  memset(buff+used_length, 0, keyinfo->block_length-used_length);
1643
 
  if (my_pwrite(info->s->kfile,(unsigned char*) buff,(uint) keyinfo->block_length,
 
1688
  bzero((uchar*) buff+used_length,keyinfo->block_length-used_length);
 
1689
  if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
1644
1690
                page,param->myf_rw))
1645
1691
  {
1646
1692
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1647
1693
    goto err;
1648
1694
  }
1649
1695
  if (temp_buff)
1650
 
    my_afree((unsigned char*) temp_buff);
1651
 
  return(0);
 
1696
    my_afree((uchar*) temp_buff);
 
1697
  DBUG_RETURN(0);
1652
1698
err:
1653
1699
  if (temp_buff)
1654
 
    my_afree((unsigned char*) temp_buff);
1655
 
  return(1);
 
1700
    my_afree((uchar*) temp_buff);
 
1701
  DBUG_RETURN(1);
1656
1702
} /* sort_record_index */
1657
1703
 
1658
1704
 
1679
1725
  va_list args;
1680
1726
 
1681
1727
  va_start(args,fmt);
1682
 
  vfprintf(stdout, fmt, args);
1683
 
  fputc('\n',stdout);
 
1728
  VOID(vfprintf(stdout, fmt, args));
 
1729
  VOID(fputc('\n',stdout));
1684
1730
  va_end(args);
1685
1731
}
1686
1732
 
1689
1735
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
1690
1736
{
1691
1737
  va_list args;
 
1738
  DBUG_ENTER("mi_check_print_warning");
1692
1739
 
1693
1740
  fflush(stdout);
1694
1741
  if (!param->warning_printed && !param->error_printed)
1701
1748
  param->warning_printed=1;
1702
1749
  va_start(args,fmt);
1703
1750
  fprintf(stderr,"%s: warning: ",my_progname_short);
1704
 
  vfprintf(stderr, fmt, args);
1705
 
  fputc('\n',stderr);
 
1751
  VOID(vfprintf(stderr, fmt, args));
 
1752
  VOID(fputc('\n',stderr));
1706
1753
  fflush(stderr);
1707
1754
  va_end(args);
1708
 
  return;
 
1755
  DBUG_VOID_RETURN;
1709
1756
}
1710
1757
 
1711
1758
/* VARARGS */
1713
1760
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
1714
1761
{
1715
1762
  va_list args;
 
1763
  DBUG_ENTER("mi_check_print_error");
 
1764
  DBUG_PRINT("enter",("format: %s",fmt));
1716
1765
 
1717
1766
  fflush(stdout);
1718
1767
  if (!param->warning_printed && !param->error_printed)
1724
1773
  param->error_printed|=1;
1725
1774
  va_start(args,fmt);
1726
1775
  fprintf(stderr,"%s: error: ",my_progname_short);
1727
 
  vfprintf(stderr, fmt, args);
1728
 
  fputc('\n',stderr);
 
1776
  VOID(vfprintf(stderr, fmt, args));
 
1777
  VOID(fputc('\n',stderr));
1729
1778
  fflush(stderr);
1730
1779
  va_end(args);
1731
 
  return;
 
1780
  DBUG_VOID_RETURN;
1732
1781
}
1733
1782