~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_dynrec.c

  • Committer: Brian Aker
  • Date: 2009-01-07 09:27:07 UTC
  • Revision ID: brian@tangent.org-20090107092707-bn67qpdllfcyh3j9
Removing dead field translator code.

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
23
23
  of blocks.  For the differnet block types, look at _mi_get_block_info()
24
24
*/
25
25
 
26
 
#include "myisam_priv.h"
 
26
#include "myisamdef.h"
27
27
 
28
28
#ifdef HAVE_SYS_TYPES
29
29
#include <sys/types.h>
32
32
#include <sys/mman.h>
33
33
#endif
34
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;
42
35
 
43
36
/* Enough for comparing if number is zero */
44
37
static char zero_string[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
45
38
 
46
39
static int write_dynamic_record(MI_INFO *info,const unsigned char *record,
47
40
                                ulong reclength);
48
 
static int _mi_find_writepos(MI_INFO *info,ulong reclength,internal::my_off_t *filepos,
 
41
static int _mi_find_writepos(MI_INFO *info,ulong reclength,my_off_t *filepos,
49
42
                             ulong *length);
50
 
static int update_dynamic_record(MI_INFO *info,internal::my_off_t filepos,unsigned char *record,
 
43
static int update_dynamic_record(MI_INFO *info,my_off_t filepos,unsigned char *record,
51
44
                                 ulong reclength);
52
 
static int delete_dynamic_record(MI_INFO *info,internal::my_off_t filepos,
 
45
static int delete_dynamic_record(MI_INFO *info,my_off_t filepos,
53
46
                                 uint32_t second_read);
54
 
static int _mi_cmp_buffer(int file, const unsigned char *buff, internal::my_off_t filepos,
 
47
static int _mi_cmp_buffer(File file, const unsigned char *buff, my_off_t filepos,
55
48
                          uint32_t length);
56
49
 
57
50
        /* Interface function from MI_INFO */
58
51
 
 
52
#ifdef HAVE_MMAP
59
53
 
60
54
/*
61
55
  Create mmaped area for MyISAM handler
69
63
    1  error.
70
64
*/
71
65
 
72
 
bool mi_dynmap_file(MI_INFO *info, internal::my_off_t size)
 
66
bool mi_dynmap_file(MI_INFO *info, my_off_t size)
73
67
{
74
 
  if (size > (internal::my_off_t) (~((size_t) 0)) - MEMMAP_EXTRA_MARGIN)
 
68
  if (size > (my_off_t) (~((size_t) 0)) - MEMMAP_EXTRA_MARGIN)
75
69
  {
76
70
    return(1);
77
71
  }
84
78
      upon a write if no physical memory is available.
85
79
  */
86
80
  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);
 
81
                  my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN),
 
82
                          info->s->mode==O_RDONLY ? PROT_READ :
 
83
                          PROT_READ | PROT_WRITE,
 
84
                          MAP_SHARED | MAP_NORESERVE,
 
85
                          info->dfile, 0L);
92
86
  if (info->s->file_map == (unsigned char*) MAP_FAILED)
93
87
  {
94
88
    info->s->file_map= NULL;
95
89
    return(1);
96
90
  }
97
91
/* per krow we should look at removing the following code */
98
 
#if !defined(TARGET_OS_SOLARIS)
 
92
#if defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
99
93
  madvise((char*) info->s->file_map, size, MADV_RANDOM);
100
94
#endif
101
95
  info->s->mmaped_length= size;
113
107
  RETURN
114
108
*/
115
109
 
116
 
void mi_remap_file(MI_INFO *info, internal::my_off_t size)
 
110
void mi_remap_file(MI_INFO *info, my_off_t size)
117
111
{
118
112
  if (info->s->file_map)
119
113
  {
120
 
    munmap((char*) info->s->file_map,
121
 
           (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN);
 
114
    my_munmap((char*) info->s->file_map,
 
115
              (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN);
122
116
    mi_dynmap_file(info, size);
123
117
  }
124
118
}
 
119
#endif
125
120
 
126
121
 
127
122
/*
140
135
*/
141
136
 
142
137
size_t mi_mmap_pread(MI_INFO *info, unsigned char *Buffer,
143
 
                    size_t Count, internal::my_off_t offset, myf MyFlags)
 
138
                    size_t Count, my_off_t offset, myf MyFlags)
144
139
{
 
140
  if (info->s->concurrent_insert)
 
141
    pthread_rwlock_rdlock(&info->s->mmap_lock);
 
142
 
145
143
  /*
146
144
    The following test may fail in the following cases:
147
145
    - We failed to remap a memory area (fragmented memory?)
152
150
  if (info->s->mmaped_length >= offset + Count)
153
151
  {
154
152
    memcpy(Buffer, info->s->file_map + offset, Count);
 
153
    if (info->s->concurrent_insert)
 
154
      pthread_rwlock_unlock(&info->s->mmap_lock);
155
155
    return 0;
156
156
  }
157
157
  else
158
158
  {
 
159
    if (info->s->concurrent_insert)
 
160
      pthread_rwlock_unlock(&info->s->mmap_lock);
159
161
    return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
160
162
  }
161
163
}
164
166
        /* wrapper for my_pread in case if mmap isn't used */
165
167
 
166
168
size_t mi_nommap_pread(MI_INFO *info, unsigned char *Buffer,
167
 
                       size_t Count, internal::my_off_t offset, myf MyFlags)
 
169
                       size_t Count, my_off_t offset, myf MyFlags)
168
170
{
169
171
  return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
170
172
}
187
189
*/
188
190
 
189
191
size_t mi_mmap_pwrite(MI_INFO *info, const unsigned char *Buffer,
190
 
                      size_t Count, internal::my_off_t offset, myf MyFlags)
 
192
                      size_t Count, my_off_t offset, myf MyFlags)
191
193
{
 
194
  if (info->s->concurrent_insert)
 
195
    pthread_rwlock_rdlock(&info->s->mmap_lock);
192
196
 
193
197
  /*
194
198
    The following test may fail in the following cases:
200
204
  if (info->s->mmaped_length >= offset + Count)
201
205
  {
202
206
    memcpy(info->s->file_map + offset, Buffer, Count);
 
207
    if (info->s->concurrent_insert)
 
208
      pthread_rwlock_unlock(&info->s->mmap_lock);
203
209
    return 0;
204
210
  }
205
211
  else
206
212
  {
207
213
    info->s->nonmmaped_inserts++;
 
214
    if (info->s->concurrent_insert)
 
215
      pthread_rwlock_unlock(&info->s->mmap_lock);
208
216
    return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
209
217
  }
210
218
 
214
222
        /* wrapper for my_pwrite in case if mmap isn't used */
215
223
 
216
224
size_t mi_nommap_pwrite(MI_INFO *info, const unsigned char *Buffer,
217
 
                      size_t Count, internal::my_off_t offset, myf MyFlags)
 
225
                      size_t Count, my_off_t offset, myf MyFlags)
218
226
{
219
227
  return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
220
228
}
226
234
  return (write_dynamic_record(info,info->rec_buff,reclength));
227
235
}
228
236
 
229
 
int _mi_update_dynamic_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
 
237
int _mi_update_dynamic_record(MI_INFO *info, my_off_t pos, const unsigned char *record)
230
238
{
231
239
  uint32_t length=_mi_rec_pack(info,info->rec_buff,record);
232
240
  return (update_dynamic_record(info,pos,info->rec_buff,length));
245
253
#ifdef NOT_USED                                 /* We now support big rows */
246
254
  if (reclength > MI_DYN_MAX_ROW_LENGTH)
247
255
  {
248
 
    errno=HA_ERR_TO_BIG_ROW;
 
256
    my_errno=HA_ERR_TO_BIG_ROW;
249
257
    return -1;
250
258
  }
251
259
#endif
252
260
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
253
261
  {
254
 
    errno= HA_ERR_OUT_OF_MEM;
 
262
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
255
263
    return(-1);
256
264
  }
257
265
  reclength2= _mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
264
272
}
265
273
 
266
274
 
267
 
int _mi_update_blob_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
 
275
int _mi_update_blob_record(MI_INFO *info, my_off_t pos, const unsigned char *record)
268
276
{
269
277
  unsigned char *rec_buff;
270
278
  int error;
277
285
#ifdef NOT_USED                                 /* We now support big rows */
278
286
  if (reclength > MI_DYN_MAX_ROW_LENGTH)
279
287
  {
280
 
    errno=HA_ERR_TO_BIG_ROW;
 
288
    my_errno=HA_ERR_TO_BIG_ROW;
281
289
    return -1;
282
290
  }
283
291
#endif
284
292
  if (!(rec_buff=(unsigned char*) malloc(reclength)))
285
293
  {
286
 
    errno= HA_ERR_OUT_OF_MEM;
 
294
    my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
287
295
    return(-1);
288
296
  }
289
297
  reclength=_mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
309
317
{
310
318
  int flag;
311
319
  ulong length;
312
 
  internal::my_off_t filepos;
 
320
  my_off_t filepos;
313
321
 
314
322
  flag=0;
315
323
 
330
338
        info->state->empty - info->state->del * MI_MAX_DYN_BLOCK_HEADER <
331
339
        reclength + MI_MAX_DYN_BLOCK_HEADER)
332
340
    {
333
 
      errno=HA_ERR_RECORD_FILE_FULL;
 
341
      my_errno=HA_ERR_RECORD_FILE_FULL;
334
342
      return(1);
335
343
    }
336
344
  }
356
364
 
357
365
static int _mi_find_writepos(MI_INFO *info,
358
366
                             ulong reclength, /* record length */
359
 
                             internal::my_off_t *filepos, /* Return file pos */
 
367
                             my_off_t *filepos, /* Return file pos */
360
368
                             ulong *length)   /* length of block at filepos */
361
369
{
362
370
  MI_BLOCK_INFO block_info;
372
380
    if (!(_mi_get_block_info(&block_info,info->dfile,info->s->state.dellink) &
373
381
           BLOCK_DELETED))
374
382
    {
375
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
383
      my_errno=HA_ERR_WRONG_IN_RECORD;
376
384
      return(-1);
377
385
    }
378
386
    info->s->state.dellink=block_info.next_filepos;
393
401
    if (info->state->data_file_length >
394
402
        (info->s->base.max_data_file_length - tmp))
395
403
    {
396
 
      errno=HA_ERR_RECORD_FILE_FULL;
 
404
      my_errno=HA_ERR_RECORD_FILE_FULL;
397
405
      return(-1);
398
406
    }
399
407
    if (tmp > MI_MAX_BLOCK_LENGTH)
477
485
    1  error.  In this case my_error is set.
478
486
*/
479
487
 
480
 
static int update_backward_delete_link(MI_INFO *info, internal::my_off_t delete_block,
481
 
                                       internal::my_off_t filepos)
 
488
static int update_backward_delete_link(MI_INFO *info, my_off_t delete_block,
 
489
                                       my_off_t filepos)
482
490
{
483
491
  MI_BLOCK_INFO block_info;
484
492
 
495
503
    }
496
504
    else
497
505
    {
498
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
506
      my_errno=HA_ERR_WRONG_IN_RECORD;
499
507
      return(1);                                /* Wrong delete link */
500
508
    }
501
509
  }
505
513
        /* Delete datarecord from database */
506
514
        /* info->rec_cache.seek_not_done is updated in cmp_record */
507
515
 
508
 
static int delete_dynamic_record(MI_INFO *info, internal::my_off_t filepos,
 
516
static int delete_dynamic_record(MI_INFO *info, my_off_t filepos,
509
517
                                 uint32_t second_read)
510
518
{
511
519
  uint32_t length,b_type;
526
534
        (length=(uint) (block_info.filepos-filepos) +block_info.block_len) <
527
535
        MI_MIN_BLOCK_LENGTH)
528
536
    {
529
 
      errno=HA_ERR_WRONG_IN_RECORD;
 
537
      my_errno=HA_ERR_WRONG_IN_RECORD;
530
538
      return(1);
531
539
    }
532
540
    /* Check if next block is a delete block */
567
575
        /* Write a block to datafile */
568
576
 
569
577
int _mi_write_part_record(MI_INFO *info,
570
 
                          internal::my_off_t filepos,   /* points at empty block */
 
578
                          my_off_t filepos,     /* points at empty block */
571
579
                          ulong length,         /* length of block */
572
 
                          internal::my_off_t next_filepos,/* Next empty block */
 
580
                          my_off_t next_filepos,/* Next empty block */
573
581
                          unsigned char **record,       /* pointer to record ptr */
574
582
                          ulong *reclength,     /* length of *record */
575
583
                          int *flag)            /* *flag == 0 if header */
576
584
{
577
585
  ulong head_length,res_length,extra_length,long_block,del_length;
578
586
  unsigned char *pos,*record_end;
579
 
  internal::my_off_t  next_delete_block;
 
587
  my_off_t  next_delete_block;
580
588
  unsigned char temp[MI_SPLIT_LENGTH+MI_DYN_DELETE_BLOCK_HEADER];
581
589
 
582
590
  next_delete_block=HA_OFFSET_ERROR;
683
691
  {
684
692
    /* Check first if we can join this block with the next one */
685
693
    MI_BLOCK_INFO del_block;
686
 
    internal::my_off_t next_block=filepos+length+extra_length+res_length;
 
694
    my_off_t next_block=filepos+length+extra_length+res_length;
687
695
 
688
696
    del_block.second_read=0;
689
697
    if (next_block < info->state->data_file_length &&
753
761
 
754
762
        /* update record from datafile */
755
763
 
756
 
static int update_dynamic_record(MI_INFO *info, internal::my_off_t filepos, unsigned char *record,
 
764
static int update_dynamic_record(MI_INFO *info, my_off_t filepos, unsigned char *record,
757
765
                                 ulong reclength)
758
766
{
759
767
  int flag;
786
794
        & (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR | BLOCK_FATAL_ERROR))
787
795
    {
788
796
      if (!(error & BLOCK_FATAL_ERROR))
789
 
        errno=HA_ERR_WRONG_IN_RECORD;
 
797
        my_errno=HA_ERR_WRONG_IN_RECORD;
790
798
      goto err;
791
799
    }
792
800
 
799
807
          info->state->empty - info->state->del * MI_MAX_DYN_BLOCK_HEADER <
800
808
          reclength - block_info.rec_len + MI_MAX_DYN_BLOCK_HEADER)
801
809
      {
802
 
        errno=HA_ERR_RECORD_FILE_FULL;
 
810
        my_errno=HA_ERR_RECORD_FILE_FULL;
803
811
        goto err;
804
812
      }
805
813
    }
816
824
             BLOCK_FATAL_ERROR))
817
825
      {
818
826
        if (!(error & BLOCK_FATAL_ERROR))
819
 
          errno=HA_ERR_WRONG_IN_RECORD;
 
827
          my_errno=HA_ERR_WRONG_IN_RECORD;
820
828
        goto err;
821
829
      }
822
830
      length=(ulong) (block_info.filepos-filepos) + block_info.block_len;
825
833
        uint32_t tmp=MY_ALIGN(reclength - length + 3 +
826
834
                          test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
827
835
        /* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
828
 
        tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
 
836
        tmp= cmin(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
829
837
        /* Check if we can extend this block */
830
838
        if (block_info.filepos + block_info.block_len ==
831
839
            info->state->data_file_length &&
863
871
                New block was too big, link overflow part back to
864
872
                delete list
865
873
              */
866
 
              internal::my_off_t next_pos;
 
874
              my_off_t next_pos;
867
875
              ulong rest_length= length-MI_MAX_BLOCK_LENGTH;
868
 
              set_if_bigger(rest_length, (ulong)MI_MIN_BLOCK_LENGTH);
 
876
              set_if_bigger(rest_length, MI_MIN_BLOCK_LENGTH);
869
877
              next_pos= del_block.filepos+ del_block.block_len - rest_length;
870
878
 
871
879
              if (update_backward_delete_link(info, info->s->state.dellink,
997
1005
      }
998
1006
      else if (type == FIELD_VARCHAR)
999
1007
      {
1000
 
        uint32_t pack_length= ha_varchar_packlength(rec->length -1);
 
1008
        uint32_t pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
1001
1009
        uint32_t tmp_length;
1002
1010
        if (pack_length == 1)
1003
1011
        {
1103
1111
            goto err;
1104
1112
          if (rec->length > 255 && new_length > 127)
1105
1113
          {
 
1114
            /* purecov: begin inspected */
1106
1115
            if (to[0] != (unsigned char) ((new_length & 127) + 128) ||
1107
1116
                to[1] != (unsigned char) (new_length >> 7))
1108
1117
              goto err;
1109
1118
            to+=2;
 
1119
            /* purecov: end */
1110
1120
          }
1111
1121
          else if (*to++ != (unsigned char) new_length)
1112
1122
            goto err;
1117
1127
      }
1118
1128
      else if (type == FIELD_VARCHAR)
1119
1129
      {
1120
 
        uint32_t pack_length= ha_varchar_packlength(rec->length -1);
 
1130
        uint32_t pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
1121
1131
        uint32_t tmp_length;
1122
1132
        if (pack_length == 1)
1123
1133
        {
1162
1172
 
1163
1173
 
1164
1174
        /* Unpacks a record */
1165
 
        /* Returns -1 and errno =HA_ERR_RECORD_DELETED if reclength isn't */
 
1175
        /* Returns -1 and my_errno =HA_ERR_RECORD_DELETED if reclength isn't */
1166
1176
        /* right. Returns reclength (>0) if ok */
1167
1177
 
1168
1178
ulong _mi_rec_unpack(register MI_INFO *info, register unsigned char *to, unsigned char *from,
1190
1200
    {
1191
1201
      if (type == FIELD_VARCHAR)
1192
1202
      {
1193
 
        uint32_t pack_length= ha_varchar_packlength(rec_length-1);
 
1203
        uint32_t pack_length= HA_VARCHAR_PACKLENGTH(rec_length-1);
1194
1204
        if (pack_length == 1)
1195
1205
        {
1196
1206
          length= (uint) *(unsigned char*) from;
1291
1301
    return(found_length);
1292
1302
 
1293
1303
err:
1294
 
  errno= HA_ERR_WRONG_IN_RECORD;
 
1304
  my_errno= HA_ERR_WRONG_IN_RECORD;
1295
1305
  return(MY_FILE_ERROR);
1296
1306
} /* _mi_rec_unpack */
1297
1307
 
1385
1395
    -1          Error
1386
1396
*/
1387
1397
 
1388
 
int _mi_read_dynamic_record(MI_INFO *info, internal::my_off_t filepos, unsigned char *buf)
 
1398
int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, unsigned char *buf)
1389
1399
{
1390
1400
  int block_of_record;
1391
1401
  uint32_t b_type, left_length= 0;
1392
1402
  unsigned char *to= NULL;
1393
1403
  MI_BLOCK_INFO block_info;
1394
 
  int file;
 
1404
  File file;
1395
1405
 
1396
1406
  if (filepos != HA_OFFSET_ERROR)
1397
1407
  {
1413
1423
             BLOCK_FATAL_ERROR))
1414
1424
      {
1415
1425
        if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
1416
 
          errno=HA_ERR_RECORD_DELETED;
 
1426
          my_errno=HA_ERR_RECORD_DELETED;
1417
1427
        goto err;
1418
1428
      }
1419
1429
      if (block_of_record++ == 0)                       /* First block */
1478
1488
  return(-1);                   /* Wrong data to read */
1479
1489
 
1480
1490
panic:
1481
 
  errno=HA_ERR_WRONG_IN_RECORD;
 
1491
  my_errno=HA_ERR_WRONG_IN_RECORD;
1482
1492
err:
1483
1493
  _mi_writeinfo(info,0);
1484
1494
  return(-1);
1487
1497
        /* compare unique constraint between stored rows */
1488
1498
 
1489
1499
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
1490
 
                           const unsigned char *record, internal::my_off_t pos)
 
1500
                           const unsigned char *record, my_off_t pos)
1491
1501
{
1492
1502
  unsigned char *rec_buff,*old_record;
1493
1503
  int error;
1494
1504
 
1495
 
  if (!(old_record=(unsigned char *)malloc(info->s->base.reclength)))
 
1505
  if (!(old_record=malloc(info->s->base.reclength)))
1496
1506
    return(1);
1497
1507
 
1498
1508
  /* Don't let the compare destroy blobs that may be in use */
1519
1529
int _mi_cmp_dynamic_record(register MI_INFO *info, register const unsigned char *record)
1520
1530
{
1521
1531
  uint32_t flag,reclength,b_type;
1522
 
  internal::my_off_t filepos;
 
1532
  my_off_t filepos;
1523
1533
  unsigned char *buffer;
1524
1534
  MI_BLOCK_INFO block_info;
1525
1535
 
1556
1566
             BLOCK_FATAL_ERROR))
1557
1567
      {
1558
1568
        if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
1559
 
          errno=HA_ERR_RECORD_CHANGED;
 
1569
          my_errno=HA_ERR_RECORD_CHANGED;
1560
1570
        goto err;
1561
1571
      }
1562
1572
      if (flag == 0)                            /* First block */
1564
1574
        flag=1;
1565
1575
        if (reclength != block_info.rec_len)
1566
1576
        {
1567
 
          errno=HA_ERR_RECORD_CHANGED;
 
1577
          my_errno=HA_ERR_RECORD_CHANGED;
1568
1578
          goto err;
1569
1579
        }
1570
1580
      } else if (reclength < block_info.data_len)
1571
1581
      {
1572
 
        errno=HA_ERR_WRONG_IN_RECORD;
 
1582
        my_errno=HA_ERR_WRONG_IN_RECORD;
1573
1583
        goto err;
1574
1584
      }
1575
1585
      reclength-=block_info.data_len;
1576
1586
      if (_mi_cmp_buffer(info->dfile,record,block_info.filepos,
1577
1587
                         block_info.data_len))
1578
1588
      {
1579
 
        errno=HA_ERR_RECORD_CHANGED;
 
1589
        my_errno=HA_ERR_RECORD_CHANGED;
1580
1590
        goto err;
1581
1591
      }
1582
1592
      flag=1;
1583
1593
      record+=block_info.data_len;
1584
1594
    }
1585
1595
  }
1586
 
  errno=0;
 
1596
  my_errno=0;
1587
1597
err:
1588
1598
  if (buffer != info->rec_buff)
1589
1599
    free((unsigned char*) buffer);
1590
 
  return(errno);
 
1600
  return(my_errno);
1591
1601
}
1592
1602
 
1593
1603
 
1594
1604
        /* Compare file to buffert */
1595
1605
 
1596
 
static int _mi_cmp_buffer(int file, const unsigned char *buff, internal::my_off_t filepos,
 
1606
static int _mi_cmp_buffer(File file, const unsigned char *buff, my_off_t filepos,
1597
1607
                          uint32_t length)
1598
1608
{
1599
1609
  uint32_t next_length;
1654
1664
*/
1655
1665
 
1656
1666
int _mi_read_rnd_dynamic_record(MI_INFO *info, unsigned char *buf,
1657
 
                                register internal::my_off_t filepos,
 
1667
                                register my_off_t filepos,
1658
1668
                                bool skip_deleted_blocks)
1659
1669
{
1660
1670
  int block_of_record, info_read, save_errno;
1688
1698
      }
1689
1699
      if (filepos >= info->state->data_file_length)
1690
1700
      {
1691
 
        errno= HA_ERR_END_OF_FILE;
 
1701
        my_errno= HA_ERR_END_OF_FILE;
1692
1702
        goto err;
1693
1703
      }
1694
1704
    }
1706
1716
      if (info->opt_flag & WRITE_CACHE_USED &&
1707
1717
          info->rec_cache.pos_in_file < filepos + MI_BLOCK_INFO_HEADER_LENGTH &&
1708
1718
          flush_io_cache(&info->rec_cache))
1709
 
        return(errno);
 
1719
        return(my_errno);
1710
1720
      info->rec_cache.seek_not_done=1;
1711
1721
      b_type=_mi_get_block_info(&block_info,info->dfile,filepos);
1712
1722
    }
1723
1733
      }
1724
1734
      if (b_type & (BLOCK_DELETED | BLOCK_SYNC_ERROR))
1725
1735
      {
1726
 
        errno=HA_ERR_RECORD_DELETED;
 
1736
        my_errno=HA_ERR_RECORD_DELETED;
1727
1737
        info->lastpos=block_info.filepos;
1728
1738
        info->nextpos=block_info.filepos+block_info.block_len;
1729
1739
      }
1783
1793
            flush_io_cache(&info->rec_cache))
1784
1794
          goto err;
1785
1795
        /* lseek(info->dfile,filepos,SEEK_SET); */
1786
 
        if (internal::my_read(info->dfile,(unsigned char*) to,block_info.data_len,MYF(MY_NABP)))
 
1796
        if (my_read(info->dfile,(unsigned char*) to,block_info.data_len,MYF(MY_NABP)))
1787
1797
        {
1788
 
          if (errno == -1)
1789
 
            errno= HA_ERR_WRONG_IN_RECORD;      /* Unexpected end of file */
 
1798
          if (my_errno == -1)
 
1799
            my_errno= HA_ERR_WRONG_IN_RECORD;   /* Unexpected end of file */
1790
1800
          goto err;
1791
1801
        }
1792
1802
      }
1810
1820
  if (_mi_rec_unpack(info,buf,info->rec_buff,block_info.rec_len) !=
1811
1821
      MY_FILE_ERROR)
1812
1822
    return(0);
1813
 
  return(errno);                        /* Wrong record */
 
1823
  return(my_errno);                     /* Wrong record */
1814
1824
 
1815
1825
panic:
1816
 
  errno=HA_ERR_WRONG_IN_RECORD;         /* Something is fatal wrong */
 
1826
  my_errno=HA_ERR_WRONG_IN_RECORD;              /* Something is fatal wrong */
1817
1827
err:
1818
 
  save_errno=errno;
 
1828
  save_errno=my_errno;
1819
1829
  _mi_writeinfo(info,0);
1820
 
  return(errno=save_errno);
 
1830
  return(my_errno=save_errno);
1821
1831
}
1822
1832
 
1823
1833
 
1824
1834
        /* Read and process header from a dynamic-record-file */
1825
1835
 
1826
 
uint32_t _mi_get_block_info(MI_BLOCK_INFO *info, int file, internal::my_off_t filepos)
 
1836
uint32_t _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos)
1827
1837
{
1828
1838
  uint32_t return_val=0;
1829
1839
  unsigned char *header=info->header;
1836
1846
      my_pread() may leave the file pointer untouched.
1837
1847
    */
1838
1848
    lseek(file,filepos,SEEK_SET);
1839
 
    if (internal::my_read(file, header, sizeof(info->header),MYF(0)) !=
 
1849
    if (my_read(file, header, sizeof(info->header),MYF(0)) !=
1840
1850
        sizeof(info->header))
1841
1851
      goto err;
1842
1852
  }
1951
1961
  }
1952
1962
 
1953
1963
err:
1954
 
  errno=HA_ERR_WRONG_IN_RECORD;  /* Garbage */
 
1964
  my_errno=HA_ERR_WRONG_IN_RECORD;       /* Garbage */
1955
1965
  return BLOCK_ERROR;
1956
1966
}