~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_open.cc

Removing global errbuff and cleaning up two remaining instances that referenced it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "myisamdef.h"
19
19
#include <mystrings/m_ctype.h>
 
20
#include <mystrings/m_string.h>
 
21
#include <drizzled/util/test.h>
 
22
 
 
23
#include <string.h>
 
24
 
 
25
using namespace std;
20
26
 
21
27
static void setup_key_functions(MI_KEYDEF *keyinfo);
22
 
#define get_next_element(to,pos,size) \
23
 
  do {                                \
24
 
    memcpy(to, pos, size);            \
25
 
    pos+=size;                        \
26
 
  } while (0)
27
 
 
28
28
 
29
29
#define disk_pos_assert(pos, end_pos) \
30
30
if (pos > end_pos)             \
41
41
 
42
42
MI_INFO *test_if_reopen(char *filename)
43
43
{
44
 
  LIST *pos;
45
 
 
46
 
  for (pos=myisam_open_list ; pos ; pos=pos->next)
 
44
  list<MI_INFO *>::iterator it= myisam_open_list.begin();
 
45
  while (it != myisam_open_list.end())
47
46
  {
48
 
    MI_INFO *info=(MI_INFO*) pos->data;
 
47
    MI_INFO *info= *it;
49
48
    MYISAM_SHARE *share=info->s;
50
49
    if (!strcmp(share->unique_file_name,filename) && share->last_version)
51
50
      return info;
 
51
    ++it;
52
52
  }
53
53
  return 0;
54
54
}
96
96
    share_buff.key_cache= multi_key_cache_search((unsigned char*) name_buff,
97
97
                                                 strlen(name_buff));
98
98
 
99
 
    if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0)
 
99
    if ((kfile=my_open(name_buff,(open_mode=O_RDWR),MYF(0))) < 0)
100
100
    {
101
101
      if ((errno != EROFS && errno != EACCES) ||
102
102
          mode != O_RDONLY ||
103
 
          (kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0)
 
103
          (kfile=my_open(name_buff,(open_mode=O_RDONLY),MYF(0))) < 0)
104
104
        goto err;
105
105
    }
106
106
    share->mode=open_mode;
136
136
    /* Don't call realpath() if the name can't be a link */
137
137
    if (!strcmp(name_buff, org_name) ||
138
138
        my_readlink(index_name, org_name, MYF(0)) == -1)
139
 
      (void) my_stpcpy(index_name, org_name);
 
139
      (void) strcpy(index_name, org_name);
140
140
    *strrchr(org_name, '.')= '\0';
141
141
    (void) fn_format(data_name,org_name,"",MI_NAME_DEXT,
142
142
                     MY_APPEND_EXT|MY_UNPACK_FILENAME|MY_RESOLVE_SYMLINKS);
151
151
    end_pos=disk_cache+info_length;
152
152
    errpos=2;
153
153
 
154
 
    my_seek(kfile,0L,MY_SEEK_SET,MYF(0));
 
154
    lseek(kfile,0,SEEK_SET);
155
155
    errpos=3;
156
156
    if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP)))
157
157
    {
205
205
      mi_safe_mul(MI_MIN_KEY_BLOCK_LENGTH,
206
206
                  ((uint64_t) 1 << (share->base.key_reflength*8))-1);
207
207
#if SIZEOF_OFF_T == 4
208
 
    set_if_smaller(max_data_file_length, INT_MAX32);
209
 
    set_if_smaller(max_key_file_length, INT_MAX32);
 
208
    set_if_smaller(max_data_file_length, INT32_MAX);
 
209
    set_if_smaller(max_key_file_length, INT32_MAX);
210
210
#endif
211
211
    if (share->base.raid_type)
212
212
    {
239
239
                         &share->state.key_root,keys*sizeof(my_off_t),
240
240
                         &share->state.key_del,
241
241
                         (share->state.header.max_block_size_index*sizeof(my_off_t)),
242
 
                         &share->key_root_lock,sizeof(rw_lock_t)*keys,
243
 
                         &share->mmap_lock,sizeof(rw_lock_t),
 
242
                         &share->key_root_lock,sizeof(pthread_rwlock_t)*keys,
 
243
                         &share->mmap_lock,sizeof(pthread_rwlock_t),
244
244
                         NULL))
245
245
      goto err;
246
246
    errpos=4;
251
251
           sizeof(my_off_t)*keys);
252
252
    memcpy(share->state.key_del, key_del,
253
253
           sizeof(my_off_t) * share->state.header.max_block_size_index);
254
 
    my_stpcpy(share->unique_file_name, name_buff);
 
254
    strcpy(share->unique_file_name, name_buff);
255
255
    share->unique_name_length= strlen(name_buff);
256
 
    my_stpcpy(share->index_file_name,  index_name);
257
 
    my_stpcpy(share->data_file_name,   data_name);
 
256
    strcpy(share->index_file_name,  index_name);
 
257
    strcpy(share->data_file_name,   data_name);
258
258
 
259
259
    share->blocksize=cmin(IO_SIZE,myisam_block_size);
260
260
    {
265
265
        disk_pos=mi_keydef_read(disk_pos, &share->keyinfo[i]);
266
266
        disk_pos_assert(disk_pos + share->keyinfo[i].keysegs * HA_KEYSEG_SIZE,
267
267
                        end_pos);
268
 
        set_if_smaller(share->blocksize,share->keyinfo[i].block_length);
 
268
        set_if_smaller(share->blocksize,(uint)share->keyinfo[i].block_length);
269
269
        share->keyinfo[i].seg=pos;
270
270
        for (j=0 ; j < share->keyinfo[i].keysegs; j++,pos++)
271
271
        {
283
283
          {
284
284
            if (!pos->language)
285
285
              pos->charset=default_charset_info;
286
 
            else if (!(pos->charset= get_charset(pos->language, MYF(MY_WME))))
 
286
            else if (!(pos->charset= get_charset(pos->language)))
287
287
            {
288
288
              my_errno=HA_ERR_UNKNOWN_CHARSET;
289
289
              goto err;
315
315
          {
316
316
            if (!pos->language)
317
317
              pos->charset=default_charset_info;
318
 
            else if (!(pos->charset= get_charset(pos->language, MYF(MY_WME))))
 
318
            else if (!(pos->charset= get_charset(pos->language)))
319
319
            {
320
320
              my_errno=HA_ERR_UNKNOWN_CHARSET;
321
321
              goto err;
386
386
    thr_lock_init(&share->lock);
387
387
    pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST);
388
388
    for (i=0; i<keys; i++)
389
 
      my_rwlock_init(&share->key_root_lock[i], NULL);
390
 
    my_rwlock_init(&share->mmap_lock, NULL);
 
389
      pthread_rwlock_init(&share->key_root_lock[i], NULL);
 
390
    pthread_rwlock_init(&share->mmap_lock, NULL);
391
391
    if (!thr_lock_inited)
392
392
    {
393
393
      /* Probably a single threaded program; Don't use concurrent inserts */
449
449
  if (!have_rtree)
450
450
    info.rtree_recursion_state= NULL;
451
451
 
452
 
  my_stpcpy(info.filename,name);
 
452
  strcpy(info.filename,name);
453
453
  memcpy(info.blobs,share->blobs,sizeof(MI_BLOB)*share->base.blobs);
454
454
  info.lastkey2=info.lastkey+share->base.max_key_length;
455
455
 
505
505
 
506
506
  *m_info=info;
507
507
  thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);
508
 
  m_info->open_list.data=(void*) m_info;
509
 
  myisam_open_list=list_add(myisam_open_list,&m_info->open_list);
 
508
  myisam_open_list.push_front(m_info);
510
509
 
511
510
  pthread_mutex_unlock(&THR_LOCK_myisam);
512
511
  return(m_info);
546
545
} /* mi_open */
547
546
 
548
547
 
549
 
unsigned char *mi_alloc_rec_buff(MI_INFO *info, ulong length, unsigned char **buf)
 
548
unsigned char *mi_alloc_rec_buff(MI_INFO *info, size_t length, unsigned char **buf)
550
549
{
551
550
  uint32_t extra;
552
551
  uint32_t old_length= 0;
573
572
            MI_REC_BUFF_OFFSET : 0);
574
573
    if (extra && newptr)
575
574
      newptr-= MI_REC_BUFF_OFFSET;
576
 
    if (!(newptr=(unsigned char*) my_realloc((unsigned char*)newptr, length+extra+8,
577
 
                                     MYF(MY_ALLOW_ZERO_PTR))))
 
575
    void *tmpnewptr= NULL;
 
576
    if (!(tmpnewptr= realloc(newptr, length+extra+8))) 
578
577
      return newptr;
 
578
    newptr= (unsigned char *)tmpnewptr;
579
579
    *((uint32_t *) newptr)= (uint32_t) length;
580
580
    *buf= newptr+(extra ?  MI_REC_BUFF_OFFSET : 0);
581
581
  }
860
860
  mi_int2store(ptr,base->max_key_length);               ptr +=2;
861
861
  mi_int2store(ptr,base->extra_alloc_bytes);            ptr +=2;
862
862
  *ptr++= base->extra_alloc_procent;
863
 
  *ptr++= base->raid_type;
864
 
  mi_int2store(ptr,base->raid_chunks);                  ptr +=2;
865
 
  mi_int4store(ptr,base->raid_chunksize);               ptr +=4;
 
863
  /* old raid info  slots */
 
864
  *ptr++= 0;
 
865
  mi_int2store(ptr,UINT16_C(0));                        ptr +=2;
 
866
  mi_int4store(ptr,UINT32_C(0));                        ptr +=4;
 
867
 
866
868
  memset(ptr, 0, 6);                                    ptr +=6; /* extra */
867
869
  return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
868
870
}
894
896
  base->max_key_length = mi_uint2korr(ptr);             ptr +=2;
895
897
  base->extra_alloc_bytes = mi_uint2korr(ptr);          ptr +=2;
896
898
  base->extra_alloc_procent = *ptr++;
897
 
  base->raid_type= *ptr++;
898
 
  base->raid_chunks= mi_uint2korr(ptr);                 ptr +=2;
899
 
  base->raid_chunksize= mi_uint4korr(ptr);              ptr +=4;
900
 
  /* TO BE REMOVED: Fix for old RAID files */
901
 
  if (base->raid_type == 0)
902
 
  {
903
 
    base->raid_chunks=0;
904
 
    base->raid_chunksize=0;
905
 
  }
 
899
 
 
900
  /* advance past raid_type (1) raid_chunks (2) and raid_chunksize (4) */
 
901
  ptr+= 7;
906
902
 
907
903
  ptr+=6;
908
904
  return ptr;
965
961
  pos= keyseg->null_bit ? keyseg->null_pos : keyseg->bit_pos;
966
962
  mi_int4store(ptr, pos);
967
963
  ptr+=4;
968
 
  
 
964
 
969
965
  return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
970
966
}
971
967
 
1043
1039
}
1044
1040
 
1045
1041
/**************************************************************************
1046
 
Open data file with or without RAID
 
1042
Open data file
1047
1043
We can't use dup() here as the data file descriptors need to have different
1048
1044
active seek-positions.
1049
1045
 
1051
1047
exist a dup()-like call that would give us two different file descriptors.
1052
1048
*************************************************************************/
1053
1049
 
1054
 
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share,
1055
 
                     File file_to_dup __attribute__((unused)))
 
1050
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup)
1056
1051
{
1057
 
    info->dfile=my_open(share->data_file_name, share->mode | O_SHARE,
1058
 
                        MYF(MY_WME));
 
1052
  (void)file_to_dup; 
 
1053
  info->dfile=my_open(share->data_file_name, share->mode,
 
1054
                      MYF(MY_WME));
1059
1055
  return info->dfile >= 0 ? 0 : 1;
1060
1056
}
1061
1057
 
1062
1058
 
1063
1059
int mi_open_keyfile(MYISAM_SHARE *share)
1064
1060
{
1065
 
  if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE,
 
1061
  if ((share->kfile=my_open(share->unique_file_name, share->mode,
1066
1062
                            MYF(MY_WME))) < 0)
1067
1063
    return 1;
1068
1064
  return 0;