~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_dynrec.c

  • Committer: Monty
  • Date: 2008-10-02 05:41:33 UTC
  • mfrom: (398.1.10 codestyle)
  • Revision ID: mordred@scylla.inaugust.com-20081002054133-tyxv5bmqpazfaqqi
Merged up to 408 of stdint-includes-fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
17
  Functions to handle space-packed-records and blobs
18
 
 
 
18
 
19
19
  A row may be stored in one or more linked blocks.
20
20
  The block size is between MI_MIN_BLOCK_LENGTH and MI_MAX_BLOCK_LENGTH.
21
21
  Each block is aligned on MI_DYN_ALIGN_SIZE.
23
23
  of blocks.  For the differnet block types, look at _mi_get_block_info()
24
24
*/
25
25
 
26
 
#include "myisam_priv.h"
27
 
 
28
 
#ifdef HAVE_SYS_TYPES
29
 
#include <sys/types.h>
30
 
#endif
31
 
#ifdef HAVE_SYS_MMAN_H
32
 
#include <sys/mman.h>
33
 
#endif
34
 
#include <drizzled/util/test.h>
35
 
#include <drizzled/error.h>
36
 
 
37
 
#include <cassert>
38
 
#include <algorithm>
39
 
 
40
 
using namespace drizzled;
41
 
using namespace std;
 
26
#include "myisamdef.h"
42
27
 
43
28
/* Enough for comparing if number is zero */
44
29
static char zero_string[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
45
30
 
46
 
static int write_dynamic_record(MI_INFO *info,const unsigned char *record,
 
31
static int write_dynamic_record(MI_INFO *info,const uchar *record,
47
32
                                ulong reclength);
48
 
static int _mi_find_writepos(MI_INFO *info,ulong reclength,internal::my_off_t *filepos,
 
33
static int _mi_find_writepos(MI_INFO *info,ulong reclength,my_off_t *filepos,
49
34
                             ulong *length);
50
 
static int update_dynamic_record(MI_INFO *info,internal::my_off_t filepos,unsigned char *record,
 
35
static int update_dynamic_record(MI_INFO *info,my_off_t filepos,uchar *record,
51
36
                                 ulong reclength);
52
 
static int delete_dynamic_record(MI_INFO *info,internal::my_off_t filepos,
53
 
                                 uint32_t second_read);
54
 
static int _mi_cmp_buffer(int file, const unsigned char *buff, internal::my_off_t filepos,
55
 
                          uint32_t length);
 
37
static int delete_dynamic_record(MI_INFO *info,my_off_t filepos,
 
38
                                 uint second_read);
 
39
static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
 
40
                          uint length);
 
41
 
 
42
/* Play it safe; We have a small stack when using threads */
 
43
#undef my_alloca
 
44
#undef my_afree
 
45
#define my_alloca(A) my_malloc((A),MYF(0))
 
46
#define my_afree(A) my_free((A),MYF(0))
56
47
 
57
48
        /* Interface function from MI_INFO */
58
49
 
 
50
#ifdef HAVE_MMAP
59
51
 
60
52
/*
61
53
  Create mmaped area for MyISAM handler
69
61
    1  error.
70
62
*/
71
63
 
72
 
bool mi_dynmap_file(MI_INFO *info, internal::my_off_t size)
 
64
bool mi_dynmap_file(MI_INFO *info, my_off_t size)
73
65
{
74
 
  if (size > (internal::my_off_t) (~((size_t) 0)) - MEMMAP_EXTRA_MARGIN)
 
66
  if (size > (my_off_t) (~((size_t) 0)) - MEMMAP_EXTRA_MARGIN)
75
67
  {
76
68
    return(1);
77
69
  }
83
75
      mapping. When swap space is not reserved one might get SIGSEGV
84
76
      upon a write if no physical memory is available.
85
77
  */
86
 
  info->s->file_map= (unsigned char*)
87
 
                  mmap(NULL, (size_t)(size + MEMMAP_EXTRA_MARGIN),
88
 
                       info->s->mode==O_RDONLY ? PROT_READ :
89
 
                       PROT_READ | PROT_WRITE,
90
 
                       MAP_SHARED | MAP_NORESERVE,
91
 
                       info->dfile, 0L);
92
 
  if (info->s->file_map == (unsigned char*) MAP_FAILED)
 
78
  info->s->file_map= (uchar*)
 
79
                  my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN),
 
80
                          info->s->mode==O_RDONLY ? PROT_READ :
 
81
                          PROT_READ | PROT_WRITE,
 
82
                          MAP_SHARED | MAP_NORESERVE,
 
83
                          info->dfile, 0L);
 
84
  if (info->s->file_map == (uchar*) MAP_FAILED)
93
85
  {
94
86
    info->s->file_map= NULL;
95
87
    return(1);
96
88
  }
97
 
/* per krow we should look at removing the following code */
98
 
#if !defined(TARGET_OS_SOLARIS)
 
89
#if defined(HAVE_MADVISE)
99
90
  madvise((char*) info->s->file_map, size, MADV_RANDOM);
100
91
#endif
101
92
  info->s->mmaped_length= size;
113
104
  RETURN
114
105
*/
115
106
 
116
 
void mi_remap_file(MI_INFO *info, internal::my_off_t size)
 
107
void mi_remap_file(MI_INFO *info, my_off_t size)
117
108
{
118
109
  if (info->s->file_map)
119
110
  {
120
 
    munmap((char*) info->s->file_map,
121
 
           (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN);
 
111
    my_munmap((char*) info->s->file_map,
 
112
              (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN);
122
113
    mi_dynmap_file(info, size);
123
114
  }
124
115
}
 
116
#endif
125
117
 
126
118
 
127
119
/*
133
125
    Buffer              Input buffer
134
126
    Count               Count of bytes for read
135
127
    offset              Start position
136
 
    MyFlags
 
128
    MyFlags             
137
129
 
138
130
  RETURN
139
131
    0  ok
140
132
*/
141
133
 
142
 
size_t mi_mmap_pread(MI_INFO *info, unsigned char *Buffer,
143
 
                    size_t Count, internal::my_off_t offset, myf MyFlags)
 
134
size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
 
135
                    size_t Count, my_off_t offset, myf MyFlags)
144
136
{
 
137
  if (info->s->concurrent_insert)
 
138
    rw_rdlock(&info->s->mmap_lock);
 
139
 
145
140
  /*
146
141
    The following test may fail in the following cases:
147
142
    - We failed to remap a memory area (fragmented memory?)
152
147
  if (info->s->mmaped_length >= offset + Count)
153
148
  {
154
149
    memcpy(Buffer, info->s->file_map + offset, Count);
 
150
    if (info->s->concurrent_insert)
 
151
      rw_unlock(&info->s->mmap_lock);
155
152
    return 0;
156
153
  }
157
154
  else
158
155
  {
 
156
    if (info->s->concurrent_insert)
 
157
      rw_unlock(&info->s->mmap_lock);
159
158
    return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
160
159
  }
161
160
}
163
162
 
164
163
        /* wrapper for my_pread in case if mmap isn't used */
165
164
 
166
 
size_t mi_nommap_pread(MI_INFO *info, unsigned char *Buffer,
167
 
                       size_t Count, internal::my_off_t offset, myf MyFlags)
 
165
size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer,
 
166
                       size_t Count, my_off_t offset, myf MyFlags)
168
167
{
169
168
  return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
170
169
}
179
178
    Buffer              Output buffer
180
179
    Count               Count of bytes for write
181
180
    offset              Start position
182
 
    MyFlags
 
181
    MyFlags             
183
182
 
184
183
  RETURN
185
184
    0  ok
186
185
    !=0  error.  In this case return error from pwrite
187
186
*/
188
187
 
189
 
size_t mi_mmap_pwrite(MI_INFO *info, const unsigned char *Buffer,
190
 
                      size_t Count, internal::my_off_t offset, myf MyFlags)
 
188
size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
 
189
                      size_t Count, my_off_t offset, myf MyFlags)
191
190
{
 
191
  if (info->s->concurrent_insert)
 
192
    rw_rdlock(&info->s->mmap_lock);
192
193
 
193
194
  /*
194
195
    The following test may fail in the following cases:
199
200
 
200
201
  if (info->s->mmaped_length >= offset + Count)
201
202
  {
202
 
    memcpy(info->s->file_map + offset, Buffer, Count);
 
203
    memcpy(info->s->file_map + offset, Buffer, Count); 
 
204
    if (info->s->concurrent_insert)
 
205
      rw_unlock(&info->s->mmap_lock);
203
206
    return 0;
204
207
  }
205
208
  else
206
209
  {
207
210
    info->s->nonmmaped_inserts++;
 
211
    if (info->s->concurrent_insert)
 
212
      rw_unlock(&info->s->mmap_lock);
208
213
    return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
209
214
  }
210
215
 
213
218
 
214
219
        /* wrapper for my_pwrite in case if mmap isn't used */
215
220
 
216
 
size_t mi_nommap_pwrite(MI_INFO *info, const unsigned char *Buffer,
217
 
                      size_t Count, internal::my_off_t offset, myf MyFlags)
 
221
size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer,
 
222
                      size_t Count, my_off_t offset, myf MyFlags)
218
223
{
219
224
  return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
220
225
}
221
226
 
222
227
 
223
 
int _mi_write_dynamic_record(MI_INFO *info, const unsigned char *record)
 
228
int _mi_write_dynamic_record(MI_INFO *info, const uchar *record)
224
229
{
225
230
  ulong reclength=_mi_rec_pack(info,info->rec_buff,record);
226
231
  return (write_dynamic_record(info,info->rec_buff,reclength));
227
232
}
228
233
 
229
 
int _mi_update_dynamic_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
 
234
int _mi_update_dynamic_record(MI_INFO *info, my_off_t pos, const uchar *record)
230
235
{
231
 
  uint32_t length=_mi_rec_pack(info,info->rec_buff,record);
 
236
  uint length=_mi_rec_pack(info,info->rec_buff,record);
232
237
  return (update_dynamic_record(info,pos,info->rec_buff,length));
233
238
}
234
239
 
235
 
int _mi_write_blob_record(MI_INFO *info, const unsigned char *record)
 
240
int _mi_write_blob_record(MI_INFO *info, const uchar *record)
236
241
{
237
 
  unsigned char *rec_buff;
 
242
  uchar *rec_buff;
238
243
  int error;
239
244
  ulong reclength,reclength2,extra;
240
245
 
245
250
#ifdef NOT_USED                                 /* We now support big rows */
246
251
  if (reclength > MI_DYN_MAX_ROW_LENGTH)
247
252
  {
248
 
    errno=HA_ERR_TO_BIG_ROW;
 
253
    my_errno=HA_ERR_TO_BIG_ROW;
249
254
    return -1;
250
255
  }
251
256
#endif
252
 
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
 
257
  if (!(rec_buff=(uchar*) my_alloca(reclength)))
253
258
  {
254
 
    errno= HA_ERR_OUT_OF_MEM;
 
259
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
255
260
    return(-1);
256
261
  }
257
262
  reclength2= _mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
259
264
  assert(reclength2 <= reclength);
260
265
  error=write_dynamic_record(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
261
266
                             reclength2);
262
 
  free(rec_buff);
 
267
  my_afree(rec_buff);
263
268
  return(error);
264
269
}
265
270
 
266
271
 
267
 
int _mi_update_blob_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
 
272
int _mi_update_blob_record(MI_INFO *info, my_off_t pos, const uchar *record)
268
273
{
269
 
  unsigned char *rec_buff;
 
274
  uchar *rec_buff;
270
275
  int error;
271
276
  ulong reclength,extra;
272
277
 
277
282
#ifdef NOT_USED                                 /* We now support big rows */
278
283
  if (reclength > MI_DYN_MAX_ROW_LENGTH)
279
284
  {
280
 
    errno=HA_ERR_TO_BIG_ROW;
 
285
    my_errno=HA_ERR_TO_BIG_ROW;
281
286
    return -1;
282
287
  }
283
288
#endif
284
 
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
 
289
  if (!(rec_buff=(uchar*) my_alloca(reclength)))
285
290
  {
286
 
    errno= HA_ERR_OUT_OF_MEM;
 
291
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
287
292
    return(-1);
288
293
  }
289
294
  reclength=_mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
291
296
  error=update_dynamic_record(info,pos,
292
297
                              rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
293
298
                              reclength);
294
 
  free(rec_buff);
 
299
  my_afree(rec_buff);
295
300
  return(error);
296
301
}
297
302
 
304
309
 
305
310
        /* Write record to data-file */
306
311
 
307
 
static int write_dynamic_record(MI_INFO *info, const unsigned char *record,
 
312
static int write_dynamic_record(MI_INFO *info, const uchar *record,
308
313
                                ulong reclength)
309
314
{
310
315
  int flag;
311
316
  ulong length;
312
 
  internal::my_off_t filepos;
 
317
  my_off_t filepos;
313
318
 
314
319
  flag=0;
315
320
 
330
335
        info->state->empty - info->state->del * MI_MAX_DYN_BLOCK_HEADER <
331
336
        reclength + MI_MAX_DYN_BLOCK_HEADER)
332
337
    {
333
 
      errno=HA_ERR_RECORD_FILE_FULL;
 
338
      my_errno=HA_ERR_RECORD_FILE_FULL;
334
339
      return(1);
335
340
    }
336
341
  }
342
347
    if (_mi_write_part_record(info,filepos,length,
343
348
                              (info->append_insert_at_end ?
344
349
                               HA_OFFSET_ERROR : info->s->state.dellink),
345
 
                              (unsigned char**) &record,&reclength,&flag))
 
350
                              (uchar**) &record,&reclength,&flag))
346
351
      goto err;
347
352
  } while (reclength);
348
353
 
356
361
 
357
362
static int _mi_find_writepos(MI_INFO *info,
358
363
                             ulong reclength, /* record length */
359
 
                             internal::my_off_t *filepos, /* Return file pos */
 
364
                             my_off_t *filepos, /* Return file pos */
360
365
                             ulong *length)   /* length of block at filepos */
361
366
{
362
367
  MI_BLOCK_INFO block_info;
372
377
    if (!(_mi_get_block_info(&block_info,info->dfile,info->s->state.dellink) &
373
378
           BLOCK_DELETED))
374
379
    {
375
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
380
      my_errno=HA_ERR_WRONG_IN_RECORD;
376
381
      return(-1);
377
382
    }
378
383
    info->s->state.dellink=block_info.next_filepos;
393
398
    if (info->state->data_file_length >
394
399
        (info->s->base.max_data_file_length - tmp))
395
400
    {
396
 
      errno=HA_ERR_RECORD_FILE_FULL;
 
401
      my_errno=HA_ERR_RECORD_FILE_FULL;
397
402
      return(-1);
398
403
    }
399
404
    if (tmp > MI_MAX_BLOCK_LENGTH)
477
482
    1  error.  In this case my_error is set.
478
483
*/
479
484
 
480
 
static int update_backward_delete_link(MI_INFO *info, internal::my_off_t delete_block,
481
 
                                       internal::my_off_t filepos)
 
485
static int update_backward_delete_link(MI_INFO *info, my_off_t delete_block,
 
486
                                       my_off_t filepos)
482
487
{
483
488
  MI_BLOCK_INFO block_info;
484
489
 
488
493
    if (_mi_get_block_info(&block_info,info->dfile,delete_block)
489
494
        & BLOCK_DELETED)
490
495
    {
491
 
      unsigned char buff[8];
 
496
      uchar buff[8];
492
497
      mi_sizestore(buff,filepos);
493
498
      if (info->s->file_write(info,buff, 8, delete_block+12, MYF(MY_NABP)))
494
499
        return(1);                              /* Error on write */
495
500
    }
496
501
    else
497
502
    {
498
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
503
      my_errno=HA_ERR_WRONG_IN_RECORD;
499
504
      return(1);                                /* Wrong delete link */
500
505
    }
501
506
  }
505
510
        /* Delete datarecord from database */
506
511
        /* info->rec_cache.seek_not_done is updated in cmp_record */
507
512
 
508
 
static int delete_dynamic_record(MI_INFO *info, internal::my_off_t filepos,
509
 
                                 uint32_t second_read)
 
513
static int delete_dynamic_record(MI_INFO *info, my_off_t filepos,
 
514
                                 uint second_read)
510
515
{
511
 
  uint32_t length,b_type;
 
516
  uint length,b_type;
512
517
  MI_BLOCK_INFO block_info,del_block;
513
518
  int error;
514
519
  bool remove_next_block;
526
531
        (length=(uint) (block_info.filepos-filepos) +block_info.block_len) <
527
532
        MI_MIN_BLOCK_LENGTH)
528
533
    {
529
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
534
      my_errno=HA_ERR_WRONG_IN_RECORD;
530
535
      return(1);
531
536
    }
532
537
    /* Check if next block is a delete block */
547
552
      memset(block_info.header+12, 255, 8);
548
553
    else
549
554
      mi_sizestore(block_info.header+12,block_info.next_filepos);
550
 
    if (info->s->file_write(info,(unsigned char*) block_info.header,20,filepos,
 
555
    if (info->s->file_write(info,(uchar*) block_info.header,20,filepos,
551
556
                  MYF(MY_NABP)))
552
557
      return(1);
553
558
    info->s->state.dellink = filepos;
567
572
        /* Write a block to datafile */
568
573
 
569
574
int _mi_write_part_record(MI_INFO *info,
570
 
                          internal::my_off_t filepos,   /* points at empty block */
 
575
                          my_off_t filepos,     /* points at empty block */
571
576
                          ulong length,         /* length of block */
572
 
                          internal::my_off_t next_filepos,/* Next empty block */
573
 
                          unsigned char **record,       /* pointer to record ptr */
 
577
                          my_off_t next_filepos,/* Next empty block */
 
578
                          uchar **record,       /* pointer to record ptr */
574
579
                          ulong *reclength,     /* length of *record */
575
580
                          int *flag)            /* *flag == 0 if header */
576
581
{
577
582
  ulong head_length,res_length,extra_length,long_block,del_length;
578
 
  unsigned char *pos,*record_end;
579
 
  internal::my_off_t  next_delete_block;
580
 
  unsigned char temp[MI_SPLIT_LENGTH+MI_DYN_DELETE_BLOCK_HEADER];
 
583
  uchar *pos,*record_end;
 
584
  my_off_t  next_delete_block;
 
585
  uchar temp[MI_SPLIT_LENGTH+MI_DYN_DELETE_BLOCK_HEADER];
581
586
 
582
587
  next_delete_block=HA_OFFSET_ERROR;
583
588
 
592
597
  if (length == *reclength+ 3 + long_block)
593
598
  {
594
599
    /* Block is exactly of the right length */
595
 
    temp[0]=(unsigned char) (1+ *flag)+(unsigned char) long_block;      /* Flag is 0 or 6 */
 
600
    temp[0]=(uchar) (1+ *flag)+(uchar) long_block;      /* Flag is 0 or 6 */
596
601
    if (long_block)
597
602
    {
598
603
      mi_int3store(temp+1,*reclength);
618
623
        temp[0]=13;
619
624
        mi_int4store(temp+1,*reclength);
620
625
        mi_int3store(temp+5,length-head_length);
621
 
        mi_sizestore((unsigned char*) temp+8,next_filepos);
 
626
        mi_sizestore((uchar*) temp+8,next_filepos);
622
627
      }
623
628
      else
624
629
      {
625
630
        head_length=5+8+long_block*2;
626
 
        temp[0]=5+(unsigned char) long_block;
 
631
        temp[0]=5+(uchar) long_block;
627
632
        if (long_block)
628
633
        {
629
634
          mi_int3store(temp+1,*reclength);
630
635
          mi_int3store(temp+4,length-head_length);
631
 
          mi_sizestore((unsigned char*) temp+7,next_filepos);
 
636
          mi_sizestore((uchar*) temp+7,next_filepos);
632
637
        }
633
638
        else
634
639
        {
635
640
          mi_int2store(temp+1,*reclength);
636
641
          mi_int2store(temp+3,length-head_length);
637
 
          mi_sizestore((unsigned char*) temp+5,next_filepos);
 
642
          mi_sizestore((uchar*) temp+5,next_filepos);
638
643
        }
639
644
      }
640
645
    }
641
646
    else
642
647
    {
643
648
      head_length=3+8+long_block;
644
 
      temp[0]=11+(unsigned char) long_block;
 
649
      temp[0]=11+(uchar) long_block;
645
650
      if (long_block)
646
651
      {
647
652
        mi_int3store(temp+1,length-head_length);
648
 
        mi_sizestore((unsigned char*) temp+4,next_filepos);
 
653
        mi_sizestore((uchar*) temp+4,next_filepos);
649
654
      }
650
655
      else
651
656
      {
652
657
        mi_int2store(temp+1,length-head_length);
653
 
        mi_sizestore((unsigned char*) temp+3,next_filepos);
 
658
        mi_sizestore((uchar*) temp+3,next_filepos);
654
659
      }
655
660
    }
656
661
  }
658
663
  {                                     /* Block with empty info last */
659
664
    head_length=4+long_block;
660
665
    extra_length= length- *reclength-head_length;
661
 
    temp[0]= (unsigned char) (3+ *flag)+(unsigned char) long_block; /* 3,4 or 9,10 */
 
666
    temp[0]= (uchar) (3+ *flag)+(uchar) long_block; /* 3,4 or 9,10 */
662
667
    if (long_block)
663
668
    {
664
669
      mi_int3store(temp+1,*reclength);
665
 
      temp[4]= (unsigned char) (extra_length);
 
670
      temp[4]= (uchar) (extra_length);
666
671
    }
667
672
    else
668
673
    {
669
674
      mi_int2store(temp+1,*reclength);
670
 
      temp[3]= (unsigned char) (extra_length);
 
675
      temp[3]= (uchar) (extra_length);
671
676
    }
672
677
    length=       *reclength+head_length;       /* Write only what is needed */
673
678
  }
675
680
        /* Make a long block for one write */
676
681
  record_end= *record+length-head_length;
677
682
  del_length=(res_length ? MI_DYN_DELETE_BLOCK_HEADER : 0);
678
 
  memmove(*record - head_length, temp, head_length);
 
683
  memcpy(*record - head_length, temp, head_length);
679
684
  memcpy(temp,record_end,(size_t) (extra_length+del_length));
680
685
  memset(record_end, 0, extra_length);
681
686
 
683
688
  {
684
689
    /* Check first if we can join this block with the next one */
685
690
    MI_BLOCK_INFO del_block;
686
 
    internal::my_off_t next_block=filepos+length+extra_length+res_length;
 
691
    my_off_t next_block=filepos+length+extra_length+res_length;
687
692
 
688
693
    del_block.second_read=0;
689
694
    if (next_block < info->state->data_file_length &&
717
722
    if (info->update & HA_STATE_EXTEND_BLOCK)
718
723
    {
719
724
      info->update&= ~HA_STATE_EXTEND_BLOCK;
720
 
      if (my_block_write(&info->rec_cache,(unsigned char*) *record-head_length,
 
725
      if (my_block_write(&info->rec_cache,(uchar*) *record-head_length,
721
726
                         length+extra_length+del_length,filepos))
722
727
      goto err;
723
728
    }
724
 
    else if (my_b_write(&info->rec_cache,(unsigned char*) *record-head_length,
 
729
    else if (my_b_write(&info->rec_cache,(uchar*) *record-head_length,
725
730
                        length+extra_length+del_length))
726
731
      goto err;
727
732
  }
728
733
  else
729
734
  {
730
735
    info->rec_cache.seek_not_done=1;
731
 
    if (info->s->file_write(info,(unsigned char*) *record-head_length,length+extra_length+
 
736
    if (info->s->file_write(info,(uchar*) *record-head_length,length+extra_length+
732
737
                  del_length,filepos,info->s->write_flag))
733
738
      goto err;
734
739
  }
753
758
 
754
759
        /* update record from datafile */
755
760
 
756
 
static int update_dynamic_record(MI_INFO *info, internal::my_off_t filepos, unsigned char *record,
 
761
static int update_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *record,
757
762
                                 ulong reclength)
758
763
{
759
764
  int flag;
760
 
  uint32_t error;
 
765
  uint error;
761
766
  ulong length;
762
767
  MI_BLOCK_INFO block_info;
763
768
 
786
791
        & (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR | BLOCK_FATAL_ERROR))
787
792
    {
788
793
      if (!(error & BLOCK_FATAL_ERROR))
789
 
        errno=HA_ERR_WRONG_IN_RECORD;
 
794
        my_errno=HA_ERR_WRONG_IN_RECORD;
790
795
      goto err;
791
796
    }
792
797
 
799
804
          info->state->empty - info->state->del * MI_MAX_DYN_BLOCK_HEADER <
800
805
          reclength - block_info.rec_len + MI_MAX_DYN_BLOCK_HEADER)
801
806
      {
802
 
        errno=HA_ERR_RECORD_FILE_FULL;
 
807
        my_errno=HA_ERR_RECORD_FILE_FULL;
803
808
        goto err;
804
809
      }
805
810
    }
816
821
             BLOCK_FATAL_ERROR))
817
822
      {
818
823
        if (!(error & BLOCK_FATAL_ERROR))
819
 
          errno=HA_ERR_WRONG_IN_RECORD;
 
824
          my_errno=HA_ERR_WRONG_IN_RECORD;
820
825
        goto err;
821
826
      }
822
827
      length=(ulong) (block_info.filepos-filepos) + block_info.block_len;
823
828
      if (length < reclength)
824
829
      {
825
 
        uint32_t tmp=MY_ALIGN(reclength - length + 3 +
 
830
        uint tmp=MY_ALIGN(reclength - length + 3 +
826
831
                          test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
827
832
        /* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
828
 
        tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
 
833
        tmp= cmin(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
829
834
        /* Check if we can extend this block */
830
835
        if (block_info.filepos + block_info.block_len ==
831
836
            info->state->data_file_length &&
863
868
                New block was too big, link overflow part back to
864
869
                delete list
865
870
              */
866
 
              internal::my_off_t next_pos;
 
871
              my_off_t next_pos;
867
872
              ulong rest_length= length-MI_MAX_BLOCK_LENGTH;
868
 
              set_if_bigger(rest_length, (ulong)MI_MIN_BLOCK_LENGTH);
 
873
              set_if_bigger(rest_length, MI_MIN_BLOCK_LENGTH);
869
874
              next_pos= del_block.filepos+ del_block.block_len - rest_length;
870
875
 
871
876
              if (update_backward_delete_link(info, info->s->state.dellink,
877
882
              mi_int3store(del_block.header+1, rest_length);
878
883
              mi_sizestore(del_block.header+4,info->s->state.dellink);
879
884
              memset(del_block.header+12, 255, 8);
880
 
              if (info->s->file_write(info,(unsigned char*) del_block.header,20, next_pos,
 
885
              if (info->s->file_write(info,(uchar*) del_block.header,20, next_pos,
881
886
                            MYF(MY_NABP)))
882
887
                return(1);
883
888
              info->s->state.dellink= next_pos;
916
921
 
917
922
        /* Pack a record. Return new reclength */
918
923
 
919
 
uint32_t _mi_rec_pack(MI_INFO *info, register unsigned char *to,
920
 
                  register const unsigned char *from)
 
924
uint _mi_rec_pack(MI_INFO *info, register uchar *to,
 
925
                  register const uchar *from)
921
926
{
922
927
  uint          length,new_length,flag,bit,i;
923
 
  unsigned char         *pos,*end,*startpos,*packpos;
 
928
  uchar         *pos,*end,*startpos,*packpos;
924
929
  enum en_fieldtype type;
925
930
  register MI_COLUMNDEF *rec;
926
931
  MI_BLOB       *blob;
962
967
      else if (type == FIELD_SKIP_ENDSPACE ||
963
968
               type == FIELD_SKIP_PRESPACE)
964
969
      {
965
 
        pos= (unsigned char*) from; end= (unsigned char*) from + length;
 
970
        pos= (uchar*) from; end= (uchar*) from + length;
966
971
        if (type == FIELD_SKIP_ENDSPACE)
967
972
        {                                       /* Pack trailing spaces */
968
973
          while (end > from && *(end-1) == ' ')
979
984
        {
980
985
          if (rec->length > 255 && new_length > 127)
981
986
          {
982
 
            to[0]= (unsigned char) ((new_length & 127) + 128);
983
 
            to[1]= (unsigned char) (new_length >> 7);
 
987
            to[0]= (uchar) ((new_length & 127) + 128);
 
988
            to[1]= (uchar) (new_length >> 7);
984
989
            to+=2;
985
990
          }
986
991
          else
987
 
            *to++= (unsigned char) new_length;
 
992
            *to++= (uchar) new_length;
988
993
          memcpy(to, pos, new_length);
989
994
          to+=new_length;
990
995
          flag|=bit;
997
1002
      }
998
1003
      else if (type == FIELD_VARCHAR)
999
1004
      {
1000
 
        uint32_t pack_length= ha_varchar_packlength(rec->length -1);
1001
 
        uint32_t tmp_length;
 
1005
        uint pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
 
1006
        uint tmp_length;
1002
1007
        if (pack_length == 1)
1003
1008
        {
1004
 
          tmp_length= (uint) *(unsigned char*) from;
 
1009
          tmp_length= (uint) *(uchar*) from;
1005
1010
          *to++= *from;
1006
1011
        }
1007
1012
        else
1021
1026
      }
1022
1027
      if ((bit= bit << 1) >= 256)
1023
1028
      {
1024
 
        *packpos++= (unsigned char) flag;
 
1029
        *packpos++= (uchar) flag;
1025
1030
        bit=1; flag=0;
1026
1031
      }
1027
1032
    }
1032
1037
    }
1033
1038
  }
1034
1039
  if (bit != 1)
1035
 
    *packpos= (unsigned char) flag;
 
1040
    *packpos= (uchar) flag;
1036
1041
  if (info->s->calc_checksum)
1037
 
    *to++= (unsigned char) info->checksum;
 
1042
    *to++= (uchar) info->checksum;
1038
1043
  return((uint) (to-startpos));
1039
1044
} /* _mi_rec_pack */
1040
1045
 
1045
1050
  Returns 0 if record is ok.
1046
1051
*/
1047
1052
 
1048
 
bool _mi_rec_check(MI_INFO *info,const unsigned char *record, unsigned char *rec_buff,
 
1053
bool _mi_rec_check(MI_INFO *info,const uchar *record, uchar *rec_buff,
1049
1054
                      ulong packed_length, bool with_checksum)
1050
1055
{
1051
1056
  uint          length,new_length,flag,bit,i;
1052
 
  unsigned char         *pos,*end,*packpos,*to;
 
1057
  uchar         *pos,*end,*packpos,*to;
1053
1058
  enum en_fieldtype type;
1054
1059
  register MI_COLUMNDEF *rec;
1055
1060
 
1064
1069
    {
1065
1070
      if (type == FIELD_BLOB)
1066
1071
      {
1067
 
        uint32_t blob_length=
 
1072
        uint blob_length=
1068
1073
          _mi_calc_blob_length(length-portable_sizeof_char_ptr,record);
1069
1074
        if (!blob_length && !(flag & bit))
1070
1075
          goto err;
1084
1089
      else if (type == FIELD_SKIP_ENDSPACE ||
1085
1090
               type == FIELD_SKIP_PRESPACE)
1086
1091
      {
1087
 
        pos= (unsigned char*) record; end= (unsigned char*) record + length;
 
1092
        pos= (uchar*) record; end= (uchar*) record + length;
1088
1093
        if (type == FIELD_SKIP_ENDSPACE)
1089
1094
        {                                       /* Pack trailing spaces */
1090
1095
          while (end > record && *(end-1) == ' ')
1103
1108
            goto err;
1104
1109
          if (rec->length > 255 && new_length > 127)
1105
1110
          {
1106
 
            if (to[0] != (unsigned char) ((new_length & 127) + 128) ||
1107
 
                to[1] != (unsigned char) (new_length >> 7))
 
1111
            /* purecov: begin inspected */
 
1112
            if (to[0] != (uchar) ((new_length & 127) + 128) ||
 
1113
                to[1] != (uchar) (new_length >> 7))
1108
1114
              goto err;
1109
1115
            to+=2;
 
1116
            /* purecov: end */
1110
1117
          }
1111
 
          else if (*to++ != (unsigned char) new_length)
 
1118
          else if (*to++ != (uchar) new_length)
1112
1119
            goto err;
1113
1120
          to+=new_length;
1114
1121
        }
1117
1124
      }
1118
1125
      else if (type == FIELD_VARCHAR)
1119
1126
      {
1120
 
        uint32_t pack_length= ha_varchar_packlength(rec->length -1);
1121
 
        uint32_t tmp_length;
 
1127
        uint pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
 
1128
        uint tmp_length;
1122
1129
        if (pack_length == 1)
1123
1130
        {
1124
 
          tmp_length= (uint) *(unsigned char*) record;
 
1131
          tmp_length= (uint) *(uchar*) record;
1125
1132
          to+= 1+ tmp_length;
1126
1133
          continue;
1127
1134
        }
1149
1156
  if (packed_length != (uint) (to - rec_buff) + test(info->s->calc_checksum) ||
1150
1157
      (bit != 1 && (flag & ~(bit - 1))))
1151
1158
    goto err;
1152
 
  if (with_checksum && ((unsigned char) info->checksum != (unsigned char) *to))
 
1159
  if (with_checksum && ((uchar) info->checksum != (uchar) *to))
1153
1160
  {
1154
1161
    goto err;
1155
1162
  }
1162
1169
 
1163
1170
 
1164
1171
        /* Unpacks a record */
1165
 
        /* Returns -1 and errno =HA_ERR_RECORD_DELETED if reclength isn't */
 
1172
        /* Returns -1 and my_errno =HA_ERR_RECORD_DELETED if reclength isn't */
1166
1173
        /* right. Returns reclength (>0) if ok */
1167
1174
 
1168
 
ulong _mi_rec_unpack(register MI_INFO *info, register unsigned char *to, unsigned char *from,
 
1175
ulong _mi_rec_unpack(register MI_INFO *info, register uchar *to, uchar *from,
1169
1176
                     ulong found_length)
1170
1177
{
1171
 
  uint32_t flag,bit,length,rec_length,min_pack_length;
 
1178
  uint flag,bit,length,rec_length,min_pack_length;
1172
1179
  enum en_fieldtype type;
1173
 
  unsigned char *from_end,*to_end,*packpos;
 
1180
  uchar *from_end,*to_end,*packpos;
1174
1181
  register MI_COLUMNDEF *rec,*end_field;
1175
1182
 
1176
1183
  to_end=to + info->s->base.reclength;
1177
1184
  from_end=from+found_length;
1178
 
  flag= (unsigned char) *from; bit=1; packpos=from;
 
1185
  flag= (uchar) *from; bit=1; packpos=from;
1179
1186
  if (found_length < info->s->base.min_pack_length)
1180
1187
    goto err;
1181
1188
  from+= info->s->base.pack_bits;
1190
1197
    {
1191
1198
      if (type == FIELD_VARCHAR)
1192
1199
      {
1193
 
        uint32_t pack_length= ha_varchar_packlength(rec_length-1);
 
1200
        uint pack_length= HA_VARCHAR_PACKLENGTH(rec_length-1);
1194
1201
        if (pack_length == 1)
1195
1202
        {
1196
 
          length= (uint) *(unsigned char*) from;
 
1203
          length= (uint) *(uchar*) from;
1197
1204
          if (length > rec_length-1)
1198
1205
            goto err;
1199
1206
          *to= *from++;
1223
1230
          {
1224
1231
            if (from + 1 >= from_end)
1225
1232
              goto err;
1226
 
            length= (*from & 127)+ ((uint) (unsigned char) *(from+1) << 7); from+=2;
 
1233
            length= (*from & 127)+ ((uint) (uchar) *(from+1) << 7); from+=2;
1227
1234
          }
1228
1235
          else
1229
1236
          {
1230
1237
            if (from == from_end)
1231
1238
              goto err;
1232
 
            length= (unsigned char) *from++;
 
1239
            length= (uchar) *from++;
1233
1240
          }
1234
1241
          min_pack_length--;
1235
1242
          if (length >= rec_length ||
1250
1257
      }
1251
1258
      else if (type == FIELD_BLOB)
1252
1259
      {
1253
 
        uint32_t size_length=rec_length- portable_sizeof_char_ptr;
 
1260
        uint size_length=rec_length- portable_sizeof_char_ptr;
1254
1261
        ulong blob_length=_mi_calc_blob_length(size_length,from);
1255
1262
        ulong from_left= (ulong) (from_end - from);
1256
1263
        if (from_left < size_length ||
1273
1280
      }
1274
1281
      if ((bit= bit << 1) >= 256)
1275
1282
      {
1276
 
        flag= (unsigned char) *++packpos; bit=1;
 
1283
        flag= (uchar) *++packpos; bit=1;
1277
1284
      }
1278
1285
    }
1279
1286
    else
1291
1298
    return(found_length);
1292
1299
 
1293
1300
err:
1294
 
  errno= HA_ERR_WRONG_IN_RECORD;
 
1301
  my_errno= HA_ERR_WRONG_IN_RECORD;
1295
1302
  return(MY_FILE_ERROR);
1296
1303
} /* _mi_rec_unpack */
1297
1304
 
1298
1305
 
1299
1306
        /* Calc length of blob. Update info in blobs->length */
1300
1307
 
1301
 
ulong _my_calc_total_blob_length(MI_INFO *info, const unsigned char *record)
 
1308
ulong _my_calc_total_blob_length(MI_INFO *info, const uchar *record)
1302
1309
{
1303
1310
  ulong length;
1304
1311
  MI_BLOB *blob,*end;
1314
1321
}
1315
1322
 
1316
1323
 
1317
 
ulong _mi_calc_blob_length(uint32_t length, const unsigned char *pos)
 
1324
ulong _mi_calc_blob_length(uint length, const uchar *pos)
1318
1325
{
1319
1326
  switch (length) {
1320
1327
  case 1:
1321
 
    return (uint) (unsigned char) *pos;
 
1328
    return (uint) (uchar) *pos;
1322
1329
  case 2:
1323
1330
    return (uint) uint2korr(pos);
1324
1331
  case 3:
1332
1339
}
1333
1340
 
1334
1341
 
1335
 
void _my_store_blob_length(unsigned char *pos,uint32_t pack_length,uint32_t length)
 
1342
void _my_store_blob_length(uchar *pos,uint pack_length,uint length)
1336
1343
{
1337
1344
  switch (pack_length) {
1338
1345
  case 1:
1339
 
    *pos= (unsigned char) length;
 
1346
    *pos= (uchar) length;
1340
1347
    break;
1341
1348
  case 2:
1342
1349
    int2store(pos,length);
1385
1392
    -1          Error
1386
1393
*/
1387
1394
 
1388
 
int _mi_read_dynamic_record(MI_INFO *info, internal::my_off_t filepos, unsigned char *buf)
 
1395
int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *buf)
1389
1396
{
1390
1397
  int block_of_record;
1391
 
  uint32_t b_type, left_length= 0;
1392
 
  unsigned char *to= NULL;
 
1398
  uint b_type, left_length= 0;
 
1399
  uchar *to= NULL;
1393
1400
  MI_BLOCK_INFO block_info;
1394
 
  int file;
 
1401
  File file;
1395
1402
 
1396
1403
  if (filepos != HA_OFFSET_ERROR)
1397
1404
  {
1413
1420
             BLOCK_FATAL_ERROR))
1414
1421
      {
1415
1422
        if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
1416
 
          errno=HA_ERR_RECORD_DELETED;
 
1423
          my_errno=HA_ERR_RECORD_DELETED;
1417
1424
        goto err;
1418
1425
      }
1419
1426
      if (block_of_record++ == 0)                       /* First block */
1434
1441
        goto panic;                     /* Wrong linked record */
1435
1442
      /* copy information that is already read */
1436
1443
      {
1437
 
        uint32_t offset= (uint) (block_info.filepos - filepos);
1438
 
        uint32_t prefetch_len= (sizeof(block_info.header) - offset);
 
1444
        uint offset= (uint) (block_info.filepos - filepos);
 
1445
        uint prefetch_len= (sizeof(block_info.header) - offset);
1439
1446
        filepos+= sizeof(block_info.header);
1440
1447
 
1441
1448
        if (prefetch_len > block_info.data_len)
1460
1467
          there is no equivalent without seeking. We are at the right
1461
1468
          position already. :(
1462
1469
        */
1463
 
        if (info->s->file_read(info, (unsigned char*) to, block_info.data_len,
 
1470
        if (info->s->file_read(info, (uchar*) to, block_info.data_len,
1464
1471
                               filepos, MYF(MY_NABP)))
1465
1472
          goto panic;
1466
1473
        left_length-=block_info.data_len;
1478
1485
  return(-1);                   /* Wrong data to read */
1479
1486
 
1480
1487
panic:
1481
 
  errno=HA_ERR_WRONG_IN_RECORD;
 
1488
  my_errno=HA_ERR_WRONG_IN_RECORD;
1482
1489
err:
1483
1490
  _mi_writeinfo(info,0);
1484
1491
  return(-1);
1487
1494
        /* compare unique constraint between stored rows */
1488
1495
 
1489
1496
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
1490
 
                           const unsigned char *record, internal::my_off_t pos)
 
1497
                           const uchar *record, my_off_t pos)
1491
1498
{
1492
 
  unsigned char *rec_buff,*old_record;
 
1499
  uchar *rec_buff,*old_record;
1493
1500
  int error;
1494
1501
 
1495
 
  if (!(old_record=(unsigned char *)malloc(info->s->base.reclength)))
 
1502
  if (!(old_record=my_alloca(info->s->base.reclength)))
1496
1503
    return(1);
1497
1504
 
1498
1505
  /* Don't let the compare destroy blobs that may be in use */
1504
1511
    error=mi_unique_comp(def, record, old_record, def->null_are_equal);
1505
1512
  if (info->s->base.blobs)
1506
1513
  {
1507
 
    void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
1508
 
    if (rec_buff_ptr != NULL)
1509
 
      free(rec_buff_ptr);
 
1514
    my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
1510
1515
    info->rec_buff=rec_buff;
1511
1516
  }
1512
 
  free(old_record);
 
1517
  my_afree(old_record);
1513
1518
  return(error);
1514
1519
}
1515
1520
 
1516
1521
 
1517
1522
        /* Compare of record one disk with packed record in memory */
1518
1523
 
1519
 
int _mi_cmp_dynamic_record(register MI_INFO *info, register const unsigned char *record)
 
1524
int _mi_cmp_dynamic_record(register MI_INFO *info, register const uchar *record)
1520
1525
{
1521
 
  uint32_t flag,reclength,b_type;
1522
 
  internal::my_off_t filepos;
1523
 
  unsigned char *buffer;
 
1526
  uint flag,reclength,b_type;
 
1527
  my_off_t filepos;
 
1528
  uchar *buffer;
1524
1529
  MI_BLOCK_INFO block_info;
1525
1530
 
1526
1531
  if (info->opt_flag & WRITE_CACHE_USED)
1538
1543
  {                                             /* If check isn't disabled  */
1539
1544
    if (info->s->base.blobs)
1540
1545
    {
1541
 
      if (!(buffer=(unsigned char*) malloc(info->s->base.pack_reclength+
 
1546
      if (!(buffer=(uchar*) my_alloca(info->s->base.pack_reclength+
1542
1547
                                     _my_calc_total_blob_length(info,record))))
1543
1548
        return(-1);
1544
1549
    }
1556
1561
             BLOCK_FATAL_ERROR))
1557
1562
      {
1558
1563
        if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
1559
 
          errno=HA_ERR_RECORD_CHANGED;
 
1564
          my_errno=HA_ERR_RECORD_CHANGED;
1560
1565
        goto err;
1561
1566
      }
1562
1567
      if (flag == 0)                            /* First block */
1564
1569
        flag=1;
1565
1570
        if (reclength != block_info.rec_len)
1566
1571
        {
1567
 
          errno=HA_ERR_RECORD_CHANGED;
 
1572
          my_errno=HA_ERR_RECORD_CHANGED;
1568
1573
          goto err;
1569
1574
        }
1570
1575
      } else if (reclength < block_info.data_len)
1571
1576
      {
1572
 
        errno=HA_ERR_WRONG_IN_RECORD;
 
1577
        my_errno=HA_ERR_WRONG_IN_RECORD;
1573
1578
        goto err;
1574
1579
      }
1575
1580
      reclength-=block_info.data_len;
1576
1581
      if (_mi_cmp_buffer(info->dfile,record,block_info.filepos,
1577
1582
                         block_info.data_len))
1578
1583
      {
1579
 
        errno=HA_ERR_RECORD_CHANGED;
 
1584
        my_errno=HA_ERR_RECORD_CHANGED;
1580
1585
        goto err;
1581
1586
      }
1582
1587
      flag=1;
1583
1588
      record+=block_info.data_len;
1584
1589
    }
1585
1590
  }
1586
 
  errno=0;
 
1591
  my_errno=0;
1587
1592
err:
1588
1593
  if (buffer != info->rec_buff)
1589
 
    free((unsigned char*) buffer);
1590
 
  return(errno);
 
1594
    my_afree((uchar*) buffer);
 
1595
  return(my_errno);
1591
1596
}
1592
1597
 
1593
1598
 
1594
1599
        /* Compare file to buffert */
1595
1600
 
1596
 
static int _mi_cmp_buffer(int file, const unsigned char *buff, internal::my_off_t filepos,
1597
 
                          uint32_t length)
 
1601
static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
 
1602
                          uint length)
1598
1603
{
1599
 
  uint32_t next_length;
1600
 
  unsigned char temp_buff[IO_SIZE*2];
 
1604
  uint next_length;
 
1605
  uchar temp_buff[IO_SIZE*2];
1601
1606
 
1602
1607
  next_length= IO_SIZE*2 - (uint) (filepos & (IO_SIZE-1));
1603
1608
 
1653
1658
    != 0        Error
1654
1659
*/
1655
1660
 
1656
 
int _mi_read_rnd_dynamic_record(MI_INFO *info, unsigned char *buf,
1657
 
                                register internal::my_off_t filepos,
 
1661
int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf,
 
1662
                                register my_off_t filepos,
1658
1663
                                bool skip_deleted_blocks)
1659
1664
{
1660
1665
  int block_of_record, info_read, save_errno;
1661
 
  uint32_t left_len,b_type;
1662
 
  unsigned char *to= NULL;
 
1666
  uint left_len,b_type;
 
1667
  uchar *to= NULL;
1663
1668
  MI_BLOCK_INFO block_info;
1664
1669
  MYISAM_SHARE *share=info->s;
1665
1670
 
1688
1693
      }
1689
1694
      if (filepos >= info->state->data_file_length)
1690
1695
      {
1691
 
        errno= HA_ERR_END_OF_FILE;
 
1696
        my_errno= HA_ERR_END_OF_FILE;
1692
1697
        goto err;
1693
1698
      }
1694
1699
    }
1695
1700
    if (info->opt_flag & READ_CACHE_USED)
1696
1701
    {
1697
 
      if (_mi_read_cache(&info->rec_cache,(unsigned char*) block_info.header,filepos,
 
1702
      if (_mi_read_cache(&info->rec_cache,(uchar*) block_info.header,filepos,
1698
1703
                         sizeof(block_info.header),
1699
1704
                         (!block_of_record && skip_deleted_blocks ?
1700
1705
                          READING_NEXT : 0) | READING_HEADER))
1706
1711
      if (info->opt_flag & WRITE_CACHE_USED &&
1707
1712
          info->rec_cache.pos_in_file < filepos + MI_BLOCK_INFO_HEADER_LENGTH &&
1708
1713
          flush_io_cache(&info->rec_cache))
1709
 
        return(errno);
 
1714
        return(my_errno);
1710
1715
      info->rec_cache.seek_not_done=1;
1711
1716
      b_type=_mi_get_block_info(&block_info,info->dfile,filepos);
1712
1717
    }
1723
1728
      }
1724
1729
      if (b_type & (BLOCK_DELETED | BLOCK_SYNC_ERROR))
1725
1730
      {
1726
 
        errno=HA_ERR_RECORD_DELETED;
 
1731
        my_errno=HA_ERR_RECORD_DELETED;
1727
1732
        info->lastpos=block_info.filepos;
1728
1733
        info->nextpos=block_info.filepos+block_info.block_len;
1729
1734
      }
1749
1754
 
1750
1755
    /* copy information that is already read */
1751
1756
    {
1752
 
      uint32_t offset=(uint) (block_info.filepos - filepos);
1753
 
      uint32_t tmp_length= (sizeof(block_info.header) - offset);
 
1757
      uint offset=(uint) (block_info.filepos - filepos);
 
1758
      uint tmp_length= (sizeof(block_info.header) - offset);
1754
1759
      filepos=block_info.filepos;
1755
1760
 
1756
1761
      if (tmp_length > block_info.data_len)
1769
1774
    {
1770
1775
      if (info->opt_flag & READ_CACHE_USED)
1771
1776
      {
1772
 
        if (_mi_read_cache(&info->rec_cache,(unsigned char*) to,filepos,
 
1777
        if (_mi_read_cache(&info->rec_cache,(uchar*) to,filepos,
1773
1778
                           block_info.data_len,
1774
1779
                           (!block_of_record && skip_deleted_blocks) ?
1775
1780
                           READING_NEXT : 0))
1782
1787
            block_info.filepos + block_info.data_len &&
1783
1788
            flush_io_cache(&info->rec_cache))
1784
1789
          goto err;
1785
 
        /* lseek(info->dfile,filepos,SEEK_SET); */
1786
 
        if (internal::my_read(info->dfile,(unsigned char*) to,block_info.data_len,MYF(MY_NABP)))
 
1790
        /* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */
 
1791
        if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP)))
1787
1792
        {
1788
 
          if (errno == -1)
1789
 
            errno= HA_ERR_WRONG_IN_RECORD;      /* Unexpected end of file */
 
1793
          if (my_errno == -1)
 
1794
            my_errno= HA_ERR_WRONG_IN_RECORD;   /* Unexpected end of file */
1790
1795
          goto err;
1791
1796
        }
1792
1797
      }
1810
1815
  if (_mi_rec_unpack(info,buf,info->rec_buff,block_info.rec_len) !=
1811
1816
      MY_FILE_ERROR)
1812
1817
    return(0);
1813
 
  return(errno);                        /* Wrong record */
 
1818
  return(my_errno);                     /* Wrong record */
1814
1819
 
1815
1820
panic:
1816
 
  errno=HA_ERR_WRONG_IN_RECORD;         /* Something is fatal wrong */
 
1821
  my_errno=HA_ERR_WRONG_IN_RECORD;              /* Something is fatal wrong */
1817
1822
err:
1818
 
  save_errno=errno;
 
1823
  save_errno=my_errno;
1819
1824
  _mi_writeinfo(info,0);
1820
 
  return(errno=save_errno);
 
1825
  return(my_errno=save_errno);
1821
1826
}
1822
1827
 
1823
1828
 
1824
1829
        /* Read and process header from a dynamic-record-file */
1825
1830
 
1826
 
uint32_t _mi_get_block_info(MI_BLOCK_INFO *info, int file, internal::my_off_t filepos)
 
1831
uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos)
1827
1832
{
1828
 
  uint32_t return_val=0;
1829
 
  unsigned char *header=info->header;
 
1833
  uint return_val=0;
 
1834
  uchar *header=info->header;
1830
1835
 
1831
1836
  if (file >= 0)
1832
1837
  {
1835
1840
      pointer set to the end of the header after this function.
1836
1841
      my_pread() may leave the file pointer untouched.
1837
1842
    */
1838
 
    lseek(file,filepos,SEEK_SET);
1839
 
    if (internal::my_read(file, header, sizeof(info->header),MYF(0)) !=
 
1843
    my_seek(file,filepos,MY_SEEK_SET,MYF(0));
 
1844
    if (my_read(file, header, sizeof(info->header),MYF(0)) !=
1840
1845
        sizeof(info->header))
1841
1846
      goto err;
1842
1847
  }
1951
1956
  }
1952
1957
 
1953
1958
err:
1954
 
  errno=HA_ERR_WRONG_IN_RECORD;  /* Garbage */
 
1959
  my_errno=HA_ERR_WRONG_IN_RECORD;       /* Garbage */
1955
1960
  return BLOCK_ERROR;
1956
1961
}