~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 08:00:16 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713080016-8qtjv9ypt42azzr6
CRC32() as UDF

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 "myisamdef.h"
19
 
#include "myisam.h"
 
18
#include <my_global.h>
20
19
 
21
 
#include <mystrings/m_ctype.h>
22
 
#include <mysys/my_getopt.h>
23
 
#include <mysys/my_bit.h>
24
 
#include <mystrings/m_string.h>
25
 
#include <stdio.h>
 
20
#include <m_ctype.h>
26
21
#include <stdarg.h>
 
22
#include <my_getopt.h>
 
23
#include <my_bit.h>
 
24
#include <myisam.h>
 
25
#include <m_string.h>
27
26
#ifdef HAVE_SYS_VADVICE_H
28
27
#include <sys/vadvise.h>
29
28
#endif
30
29
#ifdef HAVE_SYS_MMAN_H
31
30
#include <sys/mman.h>
32
31
#endif
33
 
#include <drizzled/util/test.h>
34
 
 
35
 
 
36
 
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
37
 
 
38
 
static uint32_t decode_bits;
 
32
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
 
33
 
 
34
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
 
35
#define my_raid_delete(A,B,C) my_delete(A,B)
 
36
 
 
37
#include "myisamdef.h"
 
38
 
 
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;
 
47
static MY_TMPDIR myisamchk_tmpdir;
46
48
 
47
49
static const char *type_names[]=
48
50
{ "impossible","char","binary", "short", "long", "float",
49
51
  "double","number","unsigned short",
50
 
  "unsigned long","int64_t","uint64_t","int24",
 
52
  "unsigned long","longlong","ulonglong","int24",
51
53
  "uint24","int8","varchar", "varbin","?",
52
54
  "?"};
53
55
 
70
72
static int myisamchk(MI_CHECK *param, char *filename);
71
73
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
72
74
static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
73
 
                           char * name, uint32_t sort_key,
74
 
                           bool write_info, bool update_index);
 
75
                           char * name, uint sort_key,
 
76
                           my_bool write_info, my_bool update_index);
75
77
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
76
78
                             MI_KEYDEF *keyinfo,
77
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
78
 
                             File new_file, bool update_index);
79
 
extern "C"
80
 
bool get_one_option(int optid, const struct my_option *, char *argument);
 
79
                             my_off_t page,uchar *buff,uint sortkey,
 
80
                             File new_file, my_bool update_index);
81
81
 
82
82
MI_CHECK check_param;
83
83
 
100
100
    int new_error=myisamchk(&check_param, *(argv++));
101
101
    if ((check_param.testflag & T_REP_ANY) != T_REP)
102
102
      check_param.testflag&= ~T_REP;
103
 
    fflush(stdout);
104
 
    fflush(stderr);
 
103
    VOID(fflush(stdout));
 
104
    VOID(fflush(stderr));
105
105
    if ((check_param.error_printed | check_param.warning_printed) &&
106
106
        (check_param.testflag & T_FORCE_CREATE) &&
107
107
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
108
108
                                   T_SORT_INDEX))))
109
109
    {
110
 
      uint32_t old_testflag=check_param.testflag;
 
110
      uint old_testflag=check_param.testflag;
111
111
      if (!(check_param.testflag & T_REP))
112
112
        check_param.testflag|= T_REP_BY_SORT;
113
113
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
114
114
      error|=myisamchk(&check_param, argv[-1]);
115
115
      check_param.testflag= old_testflag;
116
 
      fflush(stdout);
117
 
      fflush(stderr);
 
116
      VOID(fflush(stdout));
 
117
      VOID(fflush(stderr));
118
118
    }
119
119
    else
120
120
      error|=new_error;
121
121
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
122
122
    {
123
123
      puts("\n---------\n");
124
 
      fflush(stdout);
 
124
      VOID(fflush(stdout));
125
125
    }
126
126
  }
127
127
  if (check_param.total_files > 1)
132
132
    printf("\nTotal of all %d MyISAM-files:\nData records: %9s   Deleted blocks: %9s\n",check_param.total_files,llstr(check_param.total_records,buff),
133
133
           llstr(check_param.total_deleted,buff2));
134
134
  }
135
 
 
136
 
  pthread_mutex_destroy(&THR_LOCK_myisam);
137
 
 
138
135
  free_defaults(default_argv);
 
136
  free_tmpdir(&myisamchk_tmpdir);
139
137
  my_end(check_param.testflag & T_INFO ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
140
 
  return error;
 
138
  exit(error);
 
139
#ifndef _lint
 
140
  return 0;                             /* No compiler warning */
 
141
#endif
141
142
} /* main */
142
143
 
143
144
enum options_mc {
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
 
163
  {"block-search", 'b',
 
164
   "No help available.",
 
165
   0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
157
166
  {"backup", 'B',
158
167
   "Make a backup of the .MYD file as 'filename-time.BAK'.",
159
168
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
169
  {"character-sets-dir", OPT_CHARSETS_DIR,
 
170
   "Directory where character sets are.",
 
171
   (char**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
160
172
  {"check", 'c',
161
173
   "Check table for errors.",
162
174
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
166
178
  {"correct-checksum", OPT_CORRECT_CHECKSUM,
167
179
   "Correct checksum information for table.",
168
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
169
186
  {"description", 'd',
170
187
   "Prints some information about table.",
171
188
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
201
218
   "Skip rows bigger than this if myisamchk can't allocate memory to hold it",
202
219
   (char**) &check_param.max_record_length,
203
220
   (char**) &check_param.max_record_length,
204
 
   0, GET_ULL, REQUIRED_ARG, INT64_MAX, 0, INT64_MAX, 0, 0, 0},
 
221
   0, GET_ULL, REQUIRED_ARG, LONGLONG_MAX, 0, LONGLONG_MAX, 0, 0, 0},
205
222
  {"medium-check", 'm',
206
223
   "Faster than extend-check, but only finds 99.99% of all errors. Should be good enough for most cases.",
207
224
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
270
287
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
271
288
  { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
272
289
    (char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
273
 
    GET_UINT64, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
274
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
 
290
    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
 
291
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
275
292
  { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
276
293
    (char**) &opt_key_cache_block_size,
277
294
    (char**) &opt_key_cache_block_size, 0,
283
300
    MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
284
301
  { "read_buffer_size", OPT_READ_BUFFER_SIZE, "",
285
302
    (char**) &check_param.read_buffer_length,
286
 
    (char**) &check_param.read_buffer_length, 0, GET_SIZE, REQUIRED_ARG,
 
303
    (char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
287
304
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
288
 
    SIZE_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
305
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
289
306
  { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
290
307
    (char**) &check_param.write_buffer_length,
291
 
    (char**) &check_param.write_buffer_length, 0, GET_SIZE, REQUIRED_ARG,
 
308
    (char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
292
309
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
293
 
    SIZE_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
310
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
294
311
  { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
295
312
    (char**) &check_param.sort_buffer_length,
296
 
    (char**) &check_param.sort_buffer_length, 0, GET_SIZE, REQUIRED_ARG,
 
313
    (char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
297
314
    (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
298
 
    SIZE_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
315
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
299
316
  { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
300
317
    (char**) &check_param.sort_key_blocks,
301
 
    (char**) &check_param.sort_key_blocks, 0, GET_SIZE, REQUIRED_ARG,
 
318
    (char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
302
319
    BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
303
320
  { "decode_bits", OPT_DECODE_BITS, "", (char**) &decode_bits,
304
321
    (char**) &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
312
329
};
313
330
 
314
331
 
 
332
#include <help_start.h>
 
333
 
315
334
static void print_version(void)
316
335
{
317
336
  printf("%s  Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
318
337
         MACHINE_TYPE);
 
338
  NETWARE_SET_SCREEN_MODE(1);
319
339
}
320
340
 
321
341
 
328
348
  puts("Used without options all tables on the command will be checked for errors");
329
349
  printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short);
330
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
331
355
  printf("\
332
356
  -?, --help          Display this help and exit.\n\
333
357
  -O, --set-variable var=option.\n\
336
360
                      directly with '--variable-name=value'.\n\
337
361
  -t, --tmpdir=path   Path for temporary files. Multiple paths can be\n\
338
362
                      specified, separated by ");
339
 
#if defined( __WIN__)
 
363
#if defined( __WIN__) || defined(__NETWARE__)
340
364
   printf("semicolon (;)");
341
365
#else
342
366
   printf("colon (:)");
424
448
  -R, --sort-records=#\n\
425
449
                      Sort records according to an index.  This makes your\n\
426
450
                      data much more localized and may speed up things\n\
427
 
                      (It may be VERY slow to do a sort the first time!).\n");
 
451
                      (It may be VERY slow to do a sort the first time!).\n\
 
452
  -b,  --block-search=#\n\
 
453
                       Find a record, a block at given offset belongs to.");
428
454
 
429
 
  print_defaults("drizzle", load_default_groups);
 
455
  print_defaults("my", load_default_groups);
430
456
  my_print_variables(my_long_options);
431
457
}
432
458
 
 
459
#include <help_end.h>
 
460
 
433
461
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
434
 
                                           "nulls_ignored", NULL};
 
462
                                           "nulls_ignored", NullS};
435
463
TYPELIB myisam_stats_method_typelib= {
436
464
  array_elements(myisam_stats_method_names) - 1, "",
437
465
  myisam_stats_method_names, NULL};
438
466
 
439
467
         /* Read options */
440
468
 
441
 
bool get_one_option(int optid, const struct my_option *, char *argument)
 
469
static my_bool
 
470
get_one_option(int optid,
 
471
               const struct my_option *opt __attribute__((unused)),
 
472
               char *argument)
442
473
{
443
474
  switch (optid) {
 
475
#ifdef __NETWARE__
 
476
  case OPT_AUTO_CLOSE:
 
477
    setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
 
478
    break;
 
479
#endif
444
480
  case 'a':
445
481
    if (argument == disabled_my_option)
446
482
      check_param.testflag&= ~T_STATISTICS;
532
568
      check_param.testflag|= T_FAST;
533
569
    break;
534
570
  case 'k':
535
 
    check_param.keys_in_use= (uint64_t) strtoll(argument, NULL, 10);
 
571
    check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10);
536
572
    break;
537
573
  case 'm':
538
574
    if (argument == disabled_my_option)
556
592
    if (argument != disabled_my_option)
557
593
    {
558
594
      check_param.testflag|= T_REP;
559
 
      my_disable_async_io= true;                /* More safety */
 
595
      my_disable_async_io= 1;           /* More safety */
560
596
    }
561
597
    break;
562
598
  case 'n':
628
664
    else
629
665
      check_param.testflag|= T_UPDATE_STATE;
630
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;
631
677
  case 'V':
632
678
    print_version();
633
679
    exit(0);
648
694
      exit(1);
649
695
    }
650
696
    switch (method-1) {
651
 
    case 0:
 
697
    case 0: 
652
698
      method_conv= MI_STATS_METHOD_NULLS_EQUAL;
653
699
      break;
654
700
    case 1:
658
704
      method_conv= MI_STATS_METHOD_IGNORE_NULLS;
659
705
      break;
660
706
    default: assert(0);                         /* Impossible */
661
 
      fprintf(stderr, "Invalid value of stats_method: %s.\n", argument);
662
 
      exit(1);
663
707
    }
664
708
    check_param.stats_method= method_conv;
665
709
    break;
684
728
{
685
729
  int ho_error;
686
730
 
687
 
  load_defaults("drizzle", load_default_groups, argc, argv);
 
731
  load_defaults("my", load_default_groups, argc, argv);
688
732
  default_argv= *argv;
689
733
  if (isatty(fileno(stdout)))
690
734
    check_param.testflag|=T_WRITE_LOOP;
706
750
  if ((check_param.testflag & T_UNPACK) &&
707
751
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
708
752
  {
709
 
    fprintf(stderr,
710
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
711
 
            my_progname_short);
 
753
    VOID(fprintf(stderr,
 
754
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
755
                 my_progname_short));
712
756
    exit(1);
713
757
  }
714
758
  if ((check_param.testflag & T_READONLY) &&
716
760
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
717
761
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
718
762
  {
719
 
    fprintf(stderr,
720
 
            "%s: Can't use --readonly when repairing or sorting\n",
721
 
            my_progname_short);
 
763
    VOID(fprintf(stderr,
 
764
                 "%s: Can't use --readonly when repairing or sorting\n",
 
765
                 my_progname_short));
722
766
    exit(1);
723
767
  }
724
768
 
 
769
  if (init_tmpdir(&myisamchk_tmpdir, opt_tmpdir))
 
770
    exit(1);
 
771
 
 
772
  check_param.tmpdir=&myisamchk_tmpdir;
725
773
  check_param.key_cache_block_size= opt_key_cache_block_size;
726
774
 
727
775
  if (set_collation_name)
728
 
    if (!(set_collation= get_charset_by_name(set_collation_name)))
 
776
    if (!(set_collation= get_charset_by_name(set_collation_name,
 
777
                                             MYF(MY_WME))))
729
778
      exit(1);
730
779
 
731
780
  myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size);
739
788
{
740
789
  int error,lock_type,recreate;
741
790
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
742
 
  uint32_t raid_chunks;
 
791
  uint raid_chunks;
743
792
  MI_INFO *info;
744
793
  File datafile;
745
794
  char llbuff[22],llbuff2[22];
746
 
  bool state_updated=0;
 
795
  my_bool state_updated=0;
747
796
  MYISAM_SHARE *share;
 
797
  DBUG_ENTER("myisamchk");
748
798
 
749
799
  param->out_flag=error=param->warning_printed=param->error_printed=
750
800
    recreate=0;
794
844
                  my_errno,filename);
795
845
      break;
796
846
    }
797
 
    return(1);
 
847
    DBUG_RETURN(1);
798
848
  }
799
849
  share=info->s;
800
850
  share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
809
859
  */
810
860
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
811
861
  {
812
 
    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;
813
863
 
814
864
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
815
865
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
841
891
      {
842
892
        mi_check_print_error(param,"%d when closing MyISAM-table '%s'",
843
893
                             my_errno,filename);
844
 
        return(1);
 
894
        DBUG_RETURN(1);
845
895
      }
846
 
      return(0);
 
896
      DBUG_RETURN(0);
847
897
    }
848
898
  }
849
899
  if ((param->testflag & (T_REP_ANY | T_STATISTICS |
866
916
      param->language= set_collation->number;
867
917
    if (recreate_table(param, &info,filename))
868
918
    {
869
 
      fprintf(stderr,
870
 
              "MyISAM-table '%s' is not fixed because of errors\n",
871
 
              filename);
 
919
      VOID(fprintf(stderr,
 
920
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
921
              filename));
872
922
      return(-1);
873
923
    }
874
924
    recreate=1;
919
969
    {
920
970
      if (param->testflag & T_REP_ANY)
921
971
      {
922
 
        uint64_t tmp=share->state.key_map;
 
972
        ulonglong tmp=share->state.key_map;
923
973
        mi_copy_keys_active(share->state.key_map, share->base.keys,
924
974
                            param->keys_in_use);
925
975
        if (tmp != share->state.key_map)
959
1009
      }
960
1010
      if (!error && param->testflag & T_SORT_RECORDS)
961
1011
      {
962
 
        uint32_t key;
 
1012
        uint key;
963
1013
        /*
964
1014
          We can't update the index in mi_sort_records if we have a
965
1015
          prefix compressed or fulltext index
966
1016
        */
967
 
        bool update_index=1;
 
1017
        my_bool update_index=1;
968
1018
        for (key=0 ; key < share->base.keys; key++)
969
 
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
 
1019
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
970
1020
            update_index=0;
971
1021
 
972
1022
        error=mi_sort_records(param,info,filename,param->opt_sort_key,
973
1023
                           /* what is the following parameter for ? */
974
 
                              (bool) !(param->testflag & T_REP),
 
1024
                              (my_bool) !(param->testflag & T_REP),
975
1025
                              update_index);
976
1026
        datafile=info->dfile;   /* This is now locked */
977
1027
        if (!error && !update_index)
1017
1067
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1018
1068
      {
1019
1069
        if (param->testflag & (T_EXTEND | T_MEDIUM))
1020
 
          init_key_cache(dflt_key_cache,opt_key_cache_block_size,
1021
 
                         (size_t)param->use_buffers, 0, 0);
1022
 
        init_io_cache(&param->read_cache,datafile,
1023
 
                      (uint) param->read_buffer_length,
1024
 
                      READ_CACHE,
1025
 
                      (param->start_check_pos ?
1026
 
                       param->start_check_pos :
1027
 
                       share->pack.header_length),
1028
 
                      1,
1029
 
                      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)));
1030
1080
        lock_memory(param);
1031
1081
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1032
1082
                                 HA_OPTION_COMPRESS_RECORD)) ||
1033
1083
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1034
1084
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1035
1085
        error|=flush_blocks(param, share->key_cache, share->kfile);
1036
 
        end_io_cache(&param->read_cache);
 
1086
        VOID(end_io_cache(&param->read_cache));
1037
1087
      }
1038
1088
      if (!error)
1039
1089
      {
1054
1104
  if ((param->testflag & T_AUTO_INC) ||
1055
1105
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1056
1106
    update_auto_increment_key(param, info,
1057
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1107
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1058
1108
 
1059
1109
  if (!(param->testflag & T_DESCRIPT))
1060
1110
  {
1066
1116
                                (state_updated ? UPDATE_STAT : 0) |
1067
1117
                                ((param->testflag & T_SORT_RECORDS) ?
1068
1118
                                 UPDATE_SORT : 0)));
 
1119
    VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename));
1069
1120
    info->update&= ~HA_STATE_CHANGED;
1070
1121
  }
1071
1122
  mi_lock_database(info, F_UNLCK);
1073
1124
  if (mi_close(info))
1074
1125
  {
1075
1126
    mi_check_print_error(param,"%d when closing MyISAM-table '%s'",my_errno,filename);
1076
 
    return(1);
 
1127
    DBUG_RETURN(1);
1077
1128
  }
1078
1129
  if (error == 0)
1079
1130
  {
1086
1137
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1087
1138
                               MYF(0));
1088
1139
  }
1089
 
  fflush(stdout); fflush(stderr);
 
1140
  VOID(fflush(stdout)); VOID(fflush(stderr));
1090
1141
  if (param->error_printed)
1091
1142
  {
1092
1143
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1093
1144
    {
1094
 
      fprintf(stderr,
1095
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1096
 
              filename);
 
1145
      VOID(fprintf(stderr,
 
1146
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1147
                   filename));
1097
1148
      if (param->testflag & T_REP_ANY)
1098
 
        fprintf(stderr,
1099
 
                "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"));
1100
1151
    }
1101
1152
    else if (!(param->error_printed & 2) &&
1102
1153
             !(param->testflag & T_FORCE_CREATE))
1103
 
      fprintf(stderr,
1104
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1105
 
              filename);
 
1154
      VOID(fprintf(stderr,
 
1155
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1156
              filename));
1106
1157
  }
1107
1158
  else if (param->warning_printed &&
1108
1159
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1109
1160
                          T_FORCE_CREATE)))
1110
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1111
 
            filename);
1112
 
  fflush(stderr);
1113
 
  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);
1114
1165
} /* myisamchk */
1115
1166
 
1116
1167
 
1118
1169
 
1119
1170
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1120
1171
{
1121
 
  uint32_t key,keyseg_nr,field,start;
 
1172
  uint key,keyseg_nr,field,start;
1122
1173
  register MI_KEYDEF *keyinfo;
1123
1174
  register HA_KEYSEG *keyseg;
1124
1175
  register const char *text;
1126
1177
  enum en_fieldtype type;
1127
1178
  MYISAM_SHARE *share=info->s;
1128
1179
  char llbuff[22],llbuff2[22];
 
1180
  DBUG_ENTER("describe");
1129
1181
 
1130
1182
  printf("\nMyISAM file:         %s\n",name);
1131
1183
  fputs("Record format:       ",stdout);
1136
1188
  else
1137
1189
    puts("Fixed length");
1138
1190
  printf("Character set:       %s (%d)\n",
1139
 
  get_charset_name(share->state.header.language),
1140
 
  share->state.header.language);
 
1191
         get_charset_name(share->state.header.language),
 
1192
         share->state.header.language);
1141
1193
 
1142
1194
  if (param->testflag & T_VERBOSE)
1143
1195
  {
1155
1207
    }
1156
1208
    pos=buff;
1157
1209
    if (share->state.changed & STATE_CRASHED)
1158
 
      strcpy(buff,"crashed");
 
1210
      strmov(buff,"crashed");
1159
1211
    else
1160
1212
    {
1161
1213
      if (share->state.open_count)
1162
 
        pos= strcpy(pos,"open,")+5;
 
1214
        pos=strmov(pos,"open,");
1163
1215
      if (share->state.changed & STATE_CHANGED)
1164
 
        pos= strcpy(pos,"changed,")+8;
 
1216
        pos=strmov(pos,"changed,");
1165
1217
      else
1166
 
        pos= strcpy(pos,"checked,")+8;
 
1218
        pos=strmov(pos,"checked,");
1167
1219
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1168
 
        pos= strcpy(pos,"analyzed,")+9;
 
1220
        pos=strmov(pos,"analyzed,");
1169
1221
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1170
 
        pos= strcpy(pos,"optimized keys,")+15;
 
1222
        pos=strmov(pos,"optimized keys,");
1171
1223
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1172
 
        pos= strcpy(pos,"sorted index pages,")+19;
 
1224
        pos=strmov(pos,"sorted index pages,");
1173
1225
      pos[-1]=0;                                /* Remove extra ',' */
1174
 
    }
 
1226
    }      
1175
1227
    printf("Status:              %s\n",buff);
1176
1228
    if (share->base.auto_key)
1177
1229
    {
1179
1231
             share->base.auto_key,
1180
1232
             llstr(share->state.auto_increment,llbuff));
1181
1233
    }
 
1234
    if (share->base.raid_type)
 
1235
    {
 
1236
      printf("RAID:                Type:  %u   Chunks: %u  Chunksize: %lu\n",
 
1237
             share->base.raid_type,
 
1238
             share->base.raid_chunks,
 
1239
             share->base.raid_chunksize);
 
1240
    }
1182
1241
    if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
1183
1242
      printf("Checksum:  %23s\n",llstr(info->state->checksum,llbuff));
1184
1243
;
1187
1246
 
1188
1247
  }
1189
1248
  printf("Data records:        %13s  Deleted blocks:     %13s\n",
1190
 
  llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
 
1249
         llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
1191
1250
  if (param->testflag & T_SILENT)
1192
 
    return;                             /* This is enough */
 
1251
    DBUG_VOID_RETURN;                           /* This is enough */
1193
1252
 
1194
1253
  if (param->testflag & T_VERBOSE)
1195
1254
  {
1197
1256
    printf("Init-relocation:     %13s\n",llstr(share->base.reloc,llbuff));
1198
1257
#endif
1199
1258
    printf("Datafile parts:      %13s  Deleted data:       %13s\n",
1200
 
    llstr(share->state.split,llbuff),
1201
 
    llstr(info->state->empty,llbuff2));
 
1259
           llstr(share->state.split,llbuff),
 
1260
           llstr(info->state->empty,llbuff2));
1202
1261
    printf("Datafile pointer (bytes):%9d  Keyfile pointer (bytes):%9d\n",
1203
 
    share->rec_reflength,share->base.key_reflength);
 
1262
           share->rec_reflength,share->base.key_reflength);
1204
1263
    printf("Datafile length:     %13s  Keyfile length:     %13s\n",
1205
 
    llstr(info->state->data_file_length,llbuff),
1206
 
    llstr(info->state->key_file_length,llbuff2));
 
1264
           llstr(info->state->data_file_length,llbuff),
 
1265
           llstr(info->state->key_file_length,llbuff2));
1207
1266
 
1208
1267
    if (info->s->base.reloc == 1L && info->s->base.records == 1L)
1209
1268
      puts("This is a one-record table");
1210
1269
    else
1211
1270
    {
1212
1271
      if (share->base.max_data_file_length != HA_OFFSET_ERROR ||
1213
 
          share->base.max_key_file_length != HA_OFFSET_ERROR)
1214
 
        printf("Max datafile length: %13s  Max keyfile length: %13s\n",
1215
 
                     llstr(share->base.max_data_file_length-1,llbuff),
1216
 
                     llstr(share->base.max_key_file_length-1,llbuff2));
 
1272
          share->base.max_key_file_length != HA_OFFSET_ERROR)
 
1273
        printf("Max datafile length: %13s  Max keyfile length: %13s\n",
 
1274
               llstr(share->base.max_data_file_length-1,llbuff),
 
1275
               llstr(share->base.max_key_file_length-1,llbuff2));
1217
1276
    }
1218
1277
  }
1219
1278
 
1220
1279
  printf("Recordlength:        %13d\n",(int) share->base.pack_reclength);
1221
1280
  if (! mi_is_all_keys_active(share->state.key_map, share->base.keys))
1222
1281
  {
1223
 
    int64_t2str(share->state.key_map,buff,2);
 
1282
    longlong2str(share->state.key_map,buff,2);
1224
1283
    printf("Using only keys '%s' of %d possibly keys\n",
1225
 
    buff, share->base.keys);
 
1284
           buff, share->base.keys);
1226
1285
  }
1227
1286
  puts("\ntable description:");
1228
1287
  printf("Key Start Len Index   Type");
1229
1288
  if (param->testflag & T_VERBOSE)
1230
1289
    printf("                     Rec/key         Root  Blocksize");
1231
 
  putchar('\n');
 
1290
  VOID(putchar('\n'));
1232
1291
 
1233
1292
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1234
1293
       key < share->base.keys;
1236
1295
  {
1237
1296
    keyseg=keyinfo->seg;
1238
1297
    if (keyinfo->flag & HA_NOSAME) text="unique ";
 
1298
    else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
1239
1299
    else text="multip.";
1240
1300
 
1241
1301
    pos=buff;
1242
1302
    if (keyseg->flag & HA_REVERSE_SORT)
1243
1303
      *pos++ = '-';
1244
 
    pos= strcpy(pos,type_names[keyseg->type]);
1245
 
    pos+= strlen(type_names[keyseg->type]);
 
1304
    pos=strmov(pos,type_names[keyseg->type]);
1246
1305
    *pos++ = ' ';
1247
1306
    *pos=0;
1248
1307
    if (keyinfo->flag & HA_PACK_KEY)
1249
 
      pos= strcpy(pos,prefix_packed_txt) + strlen(prefix_packed_txt);
 
1308
      pos=strmov(pos,prefix_packed_txt);
1250
1309
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1251
 
      pos= strcpy(pos,bin_packed_txt) + strlen(bin_packed_txt);
 
1310
      pos=strmov(pos,bin_packed_txt);
1252
1311
    if (keyseg->flag & HA_SPACE_PACK)
1253
 
      pos= strcpy(pos,diff_txt) + strlen(diff_txt);
 
1312
      pos=strmov(pos,diff_txt);
1254
1313
    if (keyseg->flag & HA_BLOB_PART)
1255
 
      pos= strcpy(pos,blob_txt) + strlen(blob_txt);
 
1314
      pos=strmov(pos,blob_txt);
1256
1315
    if (keyseg->flag & HA_NULL_PART)
1257
 
      pos= strcpy(pos,null_txt) + strlen(null_txt);
 
1316
      pos=strmov(pos,null_txt);
1258
1317
    *pos=0;
1259
1318
 
1260
1319
    printf("%-4d%-6ld%-3d %-8s%-21s",
1261
 
           key+1,(long) keyseg->start+1,keyseg->length,text,buff);
 
1320
           key+1,(long) keyseg->start+1,keyseg->length,text,buff);
1262
1321
    if (share->state.key_root[key] != HA_OFFSET_ERROR)
1263
1322
      llstr(share->state.key_root[key],buff);
1264
1323
    else
1265
1324
      buff[0]=0;
1266
1325
    if (param->testflag & T_VERBOSE)
1267
1326
      printf("%11lu %12s %10d",
1268
 
    share->state.rec_per_key_part[keyseg_nr++],
1269
 
    buff,keyinfo->block_length);
1270
 
    putchar('\n');
 
1327
             share->state.rec_per_key_part[keyseg_nr++],
 
1328
             buff,keyinfo->block_length);
 
1329
    VOID(putchar('\n'));
1271
1330
    while ((++keyseg)->type != HA_KEYTYPE_END)
1272
1331
    {
1273
1332
      pos=buff;
1274
1333
      if (keyseg->flag & HA_REVERSE_SORT)
1275
 
        *pos++ = '-';
1276
 
      pos= strcpy(pos,type_names[keyseg->type]);
1277
 
      pos+= strlen(type_names[keyseg->type]);
 
1334
        *pos++ = '-';
 
1335
      pos=strmov(pos,type_names[keyseg->type]);
1278
1336
      *pos++= ' ';
1279
1337
      if (keyseg->flag & HA_SPACE_PACK)
1280
 
        pos= strcpy(pos,diff_txt) + strlen(diff_txt);
 
1338
        pos=strmov(pos,diff_txt);
1281
1339
      if (keyseg->flag & HA_BLOB_PART)
1282
 
        pos= strcpy(pos,blob_txt) + strlen(blob_txt);
 
1340
        pos=strmov(pos,blob_txt);
1283
1341
      if (keyseg->flag & HA_NULL_PART)
1284
 
        pos= strcpy(pos,null_txt) + strlen(null_txt);
 
1342
        pos=strmov(pos,null_txt);
1285
1343
      *pos=0;
1286
1344
      printf("    %-6ld%-3d         %-21s",
1287
1345
             (long) keyseg->start+1,keyseg->length,buff);
1288
1346
      if (param->testflag & T_VERBOSE)
1289
 
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1290
 
      putchar('\n');
 
1347
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
 
1348
      VOID(putchar('\n'));
1291
1349
    }
1292
1350
    keyseg++;
1293
1351
  }
1296
1354
    MI_UNIQUEDEF *uniqueinfo;
1297
1355
    puts("\nUnique  Key  Start  Len  Nullpos  Nullbit  Type");
1298
1356
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1299
 
         key < share->state.header.uniques; key++, uniqueinfo++)
 
1357
         key < share->state.header.uniques; key++, uniqueinfo++)
1300
1358
    {
1301
 
      bool new_row=0;
 
1359
      my_bool new_row=0;
1302
1360
      char null_bit[8],null_pos[8];
1303
1361
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1304
1362
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1305
1363
      {
1306
 
        if (new_row)
1307
 
          fputs("             ",stdout);
1308
 
        null_bit[0]=null_pos[0]=0;
1309
 
        if (keyseg->null_bit)
1310
 
        {
1311
 
          sprintf(null_bit,"%d",keyseg->null_bit);
1312
 
          sprintf(null_pos,"%ld",(long) keyseg->null_pos+1);
1313
 
        }
1314
 
        printf("%-7ld%-5d%-9s%-10s%-30s\n",
1315
 
               (long) keyseg->start+1,keyseg->length,
1316
 
               null_pos,null_bit,
1317
 
               type_names[keyseg->type]);
1318
 
        new_row=1;
 
1364
        if (new_row)
 
1365
          fputs("             ",stdout);
 
1366
        null_bit[0]=null_pos[0]=0;
 
1367
        if (keyseg->null_bit)
 
1368
        {
 
1369
          sprintf(null_bit,"%d",keyseg->null_bit);
 
1370
          sprintf(null_pos,"%ld",(long) keyseg->null_pos+1);
 
1371
        }
 
1372
        printf("%-7ld%-5d%-9s%-10s%-30s\n",
 
1373
               (long) keyseg->start+1,keyseg->length,
 
1374
               null_pos,null_bit,
 
1375
               type_names[keyseg->type]);
 
1376
        new_row=1;
1319
1377
      }
1320
1378
    }
1321
1379
  }
1325
1383
    printf("\nField Start Length Nullpos Nullbit Type");
1326
1384
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1327
1385
      printf("                         Huff tree  Bits");
1328
 
    putchar('\n');
 
1386
    VOID(putchar('\n'));
1329
1387
    start=1;
1330
1388
    for (field=0 ; field < share->base.fields ; field++)
1331
1389
    {
1332
1390
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1333
 
        type=share->rec[field].base_type;
 
1391
        type=share->rec[field].base_type;
1334
1392
      else
1335
 
        type=(enum en_fieldtype) share->rec[field].type;
1336
 
      end= strcpy(buff, field_pack[type]);
1337
 
      end+= strlen(field_pack[type]);
 
1393
        type=(enum en_fieldtype) share->rec[field].type;
 
1394
      end=strmov(buff,field_pack[type]);
1338
1395
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1339
1396
      {
1340
 
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1341
 
          end= strcpy(end,", not_always")+12;
1342
 
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1343
 
          end= strcpy(end,", no empty")+10;
1344
 
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1345
 
        {
1346
 
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1347
 
          end= strchr(end, '\0');
1348
 
        }
 
1397
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
 
1398
          end=strmov(end,", not_always");
 
1399
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
 
1400
          end=strmov(end,", no empty");
 
1401
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
 
1402
        {
 
1403
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
 
1404
          end=strend(end);
 
1405
        }
1349
1406
      }
1350
1407
      if (buff[0] == ',')
1351
 
        strcpy(buff,buff+2);
 
1408
        strmov(buff,buff+2);
1352
1409
      int10_to_str((long) share->rec[field].length,length,10);
1353
1410
      null_bit[0]=null_pos[0]=0;
1354
1411
      if (share->rec[field].null_bit)
1355
1412
      {
1356
 
        sprintf(null_bit,"%d",share->rec[field].null_bit);
1357
 
        sprintf(null_pos,"%d",share->rec[field].null_pos+1);
 
1413
        sprintf(null_bit,"%d",share->rec[field].null_bit);
 
1414
        sprintf(null_pos,"%d",share->rec[field].null_pos+1);
1358
1415
      }
1359
1416
      printf("%-6d%-6d%-7s%-8s%-8s%-35s",field+1,start,length,
1360
1417
             null_pos, null_bit, buff);
1365
1422
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1366
1423
                 share->rec[field].huff_tree->quick_table_bits);
1367
1424
      }
1368
 
      putchar('\n');
 
1425
      VOID(putchar('\n'));
1369
1426
      start+=share->rec[field].length;
1370
1427
    }
1371
1428
  }
1372
 
  return;
 
1429
  DBUG_VOID_RETURN;
1373
1430
} /* describe */
1374
1431
 
1375
1432
 
1377
1434
 
1378
1435
static int mi_sort_records(MI_CHECK *param,
1379
1436
                           register MI_INFO *info, char * name,
1380
 
                           uint32_t sort_key,
1381
 
                           bool write_info,
1382
 
                           bool update_index)
 
1437
                           uint sort_key,
 
1438
                           my_bool write_info,
 
1439
                           my_bool update_index)
1383
1440
{
1384
1441
  int got_error;
1385
 
  uint32_t key;
 
1442
  uint key;
1386
1443
  MI_KEYDEF *keyinfo;
1387
1444
  File new_file;
1388
 
  unsigned char *temp_buff;
 
1445
  uchar *temp_buff;
1389
1446
  ha_rows old_record_count;
1390
1447
  MYISAM_SHARE *share=info->s;
1391
1448
  char llbuff[22],llbuff2[22];
1392
1449
  SORT_INFO sort_info;
1393
1450
  MI_SORT_PARAM sort_param;
 
1451
  DBUG_ENTER("sort_records");
1394
1452
 
1395
 
  memset(&sort_info, 0, sizeof(sort_info));
1396
 
  memset(&sort_param, 0, sizeof(sort_param));
 
1453
  bzero((char*)&sort_info,sizeof(sort_info));
 
1454
  bzero((char*)&sort_param,sizeof(sort_param));
1397
1455
  sort_param.sort_info=&sort_info;
1398
1456
  sort_info.param=param;
1399
1457
  keyinfo= &share->keyinfo[sort_key];
1407
1465
                           "Can't sort table '%s' on key %d;  No such key",
1408
1466
                name,sort_key+1);
1409
1467
    param->error_printed=0;
1410
 
    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 */
1411
1476
  }
1412
1477
  if (share->data_file_type == COMPRESSED_RECORD)
1413
1478
  {
1414
1479
    mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
1415
1480
    param->error_printed=0;
1416
 
    return(0);                          /* Nothing to do */
 
1481
    DBUG_RETURN(0);                             /* Nothing to do */
1417
1482
  }
1418
1483
  if (!(param->testflag & T_SILENT))
1419
1484
  {
1424
1489
             llstr(info->state->del,llbuff2));
1425
1490
  }
1426
1491
  if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
1427
 
    return(0);                          /* Nothing to do */
 
1492
    DBUG_RETURN(0);                             /* Nothing to do */
1428
1493
 
1429
 
  init_key_cache(dflt_key_cache, opt_key_cache_block_size, 
1430
 
                 (size_t)param->use_buffers,
 
1494
  init_key_cache(dflt_key_cache, opt_key_cache_block_size, param->use_buffers,
1431
1495
                 0, 0);
1432
1496
  if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length,
1433
1497
                   WRITE_CACHE,share->pack.header_length,1,
1435
1499
    goto err;
1436
1500
  info->opt_flag|=WRITE_CACHE_USED;
1437
1501
 
1438
 
  if (!(temp_buff=(unsigned char*) malloc(keyinfo->block_length)))
 
1502
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1439
1503
  {
1440
1504
    mi_check_print_error(param,"Not enough memory for key block");
1441
1505
    goto err;
1442
1506
  }
1443
1507
 
1444
 
  if (!mi_alloc_rec_buff(info, (ulong)-1, &sort_param.record))
 
1508
  if (!mi_alloc_rec_buff(info, -1, &sort_param.record))
1445
1509
  {
1446
1510
    mi_check_print_error(param,"Not enough memory for record");
1447
1511
    goto err;
1448
1512
  }
1449
1513
  fn_format(param->temp_filename,name,"", MI_NAME_DEXT,2+4+32);
1450
 
  new_file=my_create(fn_format(param->temp_filename,
1451
 
                               param->temp_filename,"",
1452
 
                               DATA_TMP_EXT,2+4),
1453
 
                     0,param->tmpfile_createflag,
1454
 
                     MYF(0));
 
1514
  new_file=my_raid_create(fn_format(param->temp_filename,
 
1515
                                    param->temp_filename,"",
 
1516
                                    DATA_TMP_EXT,2+4),
 
1517
                          0,param->tmpfile_createflag,
 
1518
                          share->base.raid_type,
 
1519
                          share->base.raid_chunks,
 
1520
                          share->base.raid_chunksize,
 
1521
                          MYF(0));
1455
1522
  if (new_file < 0)
1456
1523
  {
1457
1524
    mi_check_print_error(param,"Can't create new tempfile: '%s'",
1468
1535
  for (key=0 ; key < share->base.keys ; key++)
1469
1536
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1470
1537
 
1471
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1538
  if (my_pread(share->kfile,(uchar*) temp_buff,
1472
1539
               (uint) keyinfo->block_length,
1473
1540
               share->state.key_root[sort_key],
1474
1541
               MYF(MY_NABP+MY_WME)))
1503
1570
    goto err;
1504
1571
  }
1505
1572
 
1506
 
  my_close(info->dfile,MYF(MY_WME));
 
1573
  VOID(my_close(info->dfile,MYF(MY_WME)));
1507
1574
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1508
1575
  info->dfile=new_file;                         /* Use new datafile */
1509
1576
  info->state->del=0;
1517
1584
 
1518
1585
  if (param->testflag & T_WRITE_LOOP)
1519
1586
  {
1520
 
    fputs("          \r",stdout); fflush(stdout);
 
1587
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1521
1588
  }
1522
1589
  got_error=0;
1523
1590
 
1524
1591
err:
1525
1592
  if (got_error && new_file >= 0)
1526
1593
  {
1527
 
    end_io_cache(&info->rec_cache);
 
1594
    VOID(end_io_cache(&info->rec_cache));
1528
1595
    (void) my_close(new_file,MYF(MY_WME));
1529
 
    (void) my_delete(param->temp_filename, MYF(MY_WME));
 
1596
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
 
1597
                          MYF(MY_WME));
1530
1598
  }
1531
1599
  if (temp_buff)
1532
1600
  {
1533
 
    free((unsigned char*) temp_buff);
 
1601
    my_afree((uchar*) temp_buff);
1534
1602
  }
1535
 
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1536
 
  if (rec_buff_ptr != NULL)
1537
 
    free(rec_buff_ptr);
1538
 
 
 
1603
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1604
          MYF(MY_ALLOW_ZERO_PTR));
1539
1605
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1540
 
  end_io_cache(&info->rec_cache);
1541
 
  free(sort_info.buff);
 
1606
  VOID(end_io_cache(&info->rec_cache));
 
1607
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1542
1608
  sort_info.buff=0;
1543
1609
  share->state.sortkey=sort_key;
1544
 
  return(flush_blocks(param, share->key_cache, share->kfile) |
 
1610
  DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) |
1545
1611
              got_error);
1546
1612
} /* sort_records */
1547
1613
 
1550
1616
 
1551
1617
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1552
1618
                             MI_KEYDEF *keyinfo,
1553
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1554
 
                             File new_file,bool update_index)
 
1619
                             my_off_t page, uchar *buff, uint sort_key,
 
1620
                             File new_file,my_bool update_index)
1555
1621
{
1556
1622
  uint  nod_flag,used_length,key_length;
1557
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1623
  uchar *temp_buff,*keypos,*endpos;
1558
1624
  my_off_t next_page,rec_pos;
1559
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1625
  uchar lastkey[MI_MAX_KEY_BUFF];
1560
1626
  char llbuff[22];
1561
1627
  SORT_INFO *sort_info= sort_param->sort_info;
1562
1628
  MI_CHECK *param=sort_info->param;
 
1629
  DBUG_ENTER("sort_record_index");
1563
1630
 
1564
1631
  nod_flag=mi_test_if_nod(buff);
1565
1632
  temp_buff=0;
1566
1633
 
1567
1634
  if (nod_flag)
1568
1635
  {
1569
 
    if (!(temp_buff=(unsigned char*) malloc(keyinfo->block_length)))
 
1636
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1570
1637
    {
1571
1638
      mi_check_print_error(param,"Not Enough memory");
1572
 
      return(-1);
 
1639
      DBUG_RETURN(-1);
1573
1640
    }
1574
1641
  }
1575
1642
  used_length=mi_getint(buff);
1580
1647
    if (nod_flag)
1581
1648
    {
1582
1649
      next_page=_mi_kpos(nod_flag,keypos);
1583
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1650
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1584
1651
                  (uint) keyinfo->block_length, next_page,
1585
1652
                   MYF(MY_NABP+MY_WME)))
1586
1653
      {
1618
1685
      goto err;
1619
1686
  }
1620
1687
  /* Clear end of block to get better compression if the table is backuped */
1621
 
  memset(buff+used_length, 0, keyinfo->block_length-used_length);
1622
 
  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,
1623
1690
                page,param->myf_rw))
1624
1691
  {
1625
1692
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1626
1693
    goto err;
1627
1694
  }
1628
1695
  if (temp_buff)
1629
 
    free((unsigned char*) temp_buff);
1630
 
  return(0);
 
1696
    my_afree((uchar*) temp_buff);
 
1697
  DBUG_RETURN(0);
1631
1698
err:
1632
1699
  if (temp_buff)
1633
 
    free((unsigned char*) temp_buff);
1634
 
  return(1);
 
1700
    my_afree((uchar*) temp_buff);
 
1701
  DBUG_RETURN(1);
1635
1702
} /* sort_record_index */
1636
1703
 
1637
1704
 
1644
1711
 
1645
1712
static int not_killed= 0;
1646
1713
 
1647
 
volatile int *killed_ptr(MI_CHECK *)
 
1714
volatile int *killed_ptr(MI_CHECK *param __attribute__((unused)))
1648
1715
{
1649
1716
  return &not_killed;                   /* always NULL */
1650
1717
}
1652
1719
        /* print warnings and errors */
1653
1720
        /* VARARGS */
1654
1721
 
1655
 
void mi_check_print_info(MI_CHECK *,
 
1722
void mi_check_print_info(MI_CHECK *param __attribute__((unused)),
1656
1723
                         const char *fmt,...)
1657
1724
{
1658
1725
  va_list args;
1659
1726
 
1660
1727
  va_start(args,fmt);
1661
 
  vfprintf(stdout, fmt, args);
1662
 
  fputc('\n',stdout);
 
1728
  VOID(vfprintf(stdout, fmt, args));
 
1729
  VOID(fputc('\n',stdout));
1663
1730
  va_end(args);
1664
1731
}
1665
1732
 
1668
1735
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
1669
1736
{
1670
1737
  va_list args;
 
1738
  DBUG_ENTER("mi_check_print_warning");
1671
1739
 
1672
1740
  fflush(stdout);
1673
1741
  if (!param->warning_printed && !param->error_printed)
1680
1748
  param->warning_printed=1;
1681
1749
  va_start(args,fmt);
1682
1750
  fprintf(stderr,"%s: warning: ",my_progname_short);
1683
 
  vfprintf(stderr, fmt, args);
1684
 
  fputc('\n',stderr);
 
1751
  VOID(vfprintf(stderr, fmt, args));
 
1752
  VOID(fputc('\n',stderr));
1685
1753
  fflush(stderr);
1686
1754
  va_end(args);
1687
 
  return;
 
1755
  DBUG_VOID_RETURN;
1688
1756
}
1689
1757
 
1690
1758
/* VARARGS */
1692
1760
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
1693
1761
{
1694
1762
  va_list args;
 
1763
  DBUG_ENTER("mi_check_print_error");
 
1764
  DBUG_PRINT("enter",("format: %s",fmt));
1695
1765
 
1696
1766
  fflush(stdout);
1697
1767
  if (!param->warning_printed && !param->error_printed)
1703
1773
  param->error_printed|=1;
1704
1774
  va_start(args,fmt);
1705
1775
  fprintf(stderr,"%s: error: ",my_progname_short);
1706
 
  vfprintf(stderr, fmt, args);
1707
 
  fputc('\n',stderr);
 
1776
  VOID(vfprintf(stderr, fmt, args));
 
1777
  VOID(fputc('\n',stderr));
1708
1778
  fflush(stderr);
1709
1779
  va_end(args);
1710
 
  return;
 
1780
  DBUG_VOID_RETURN;
1711
1781
}
1712
1782