~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_open.c

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

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>
20
24
 
21
25
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
26
 
29
27
#define disk_pos_assert(pos, end_pos) \
30
28
if (pos > end_pos)             \
96
94
    share_buff.key_cache= multi_key_cache_search((unsigned char*) name_buff,
97
95
                                                 strlen(name_buff));
98
96
 
99
 
    if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0)
 
97
    if ((kfile=my_open(name_buff,(open_mode=O_RDWR),MYF(0))) < 0)
100
98
    {
101
99
      if ((errno != EROFS && errno != EACCES) ||
102
100
          mode != O_RDONLY ||
103
 
          (kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0)
 
101
          (kfile=my_open(name_buff,(open_mode=O_RDONLY),MYF(0))) < 0)
104
102
        goto err;
105
103
    }
106
104
    share->mode=open_mode;
136
134
    /* Don't call realpath() if the name can't be a link */
137
135
    if (!strcmp(name_buff, org_name) ||
138
136
        my_readlink(index_name, org_name, MYF(0)) == -1)
139
 
      (void) my_stpcpy(index_name, org_name);
 
137
      (void) strcpy(index_name, org_name);
140
138
    *strrchr(org_name, '.')= '\0';
141
139
    (void) fn_format(data_name,org_name,"",MI_NAME_DEXT,
142
140
                     MY_APPEND_EXT|MY_UNPACK_FILENAME|MY_RESOLVE_SYMLINKS);
151
149
    end_pos=disk_cache+info_length;
152
150
    errpos=2;
153
151
 
154
 
    my_seek(kfile,0L,MY_SEEK_SET,MYF(0));
 
152
    lseek(kfile,0,SEEK_SET);
155
153
    errpos=3;
156
154
    if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP)))
157
155
    {
205
203
      mi_safe_mul(MI_MIN_KEY_BLOCK_LENGTH,
206
204
                  ((uint64_t) 1 << (share->base.key_reflength*8))-1);
207
205
#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);
 
206
    set_if_smaller(max_data_file_length, INT32_MAX);
 
207
    set_if_smaller(max_key_file_length, INT32_MAX);
210
208
#endif
211
209
    if (share->base.raid_type)
212
210
    {
239
237
                         &share->state.key_root,keys*sizeof(my_off_t),
240
238
                         &share->state.key_del,
241
239
                         (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),
 
240
                         &share->key_root_lock,sizeof(pthread_rwlock_t)*keys,
 
241
                         &share->mmap_lock,sizeof(pthread_rwlock_t),
244
242
                         NULL))
245
243
      goto err;
246
244
    errpos=4;
251
249
           sizeof(my_off_t)*keys);
252
250
    memcpy(share->state.key_del, key_del,
253
251
           sizeof(my_off_t) * share->state.header.max_block_size_index);
254
 
    my_stpcpy(share->unique_file_name, name_buff);
 
252
    strcpy(share->unique_file_name, name_buff);
255
253
    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);
 
254
    strcpy(share->index_file_name,  index_name);
 
255
    strcpy(share->data_file_name,   data_name);
258
256
 
259
257
    share->blocksize=cmin(IO_SIZE,myisam_block_size);
260
258
    {
265
263
        disk_pos=mi_keydef_read(disk_pos, &share->keyinfo[i]);
266
264
        disk_pos_assert(disk_pos + share->keyinfo[i].keysegs * HA_KEYSEG_SIZE,
267
265
                        end_pos);
268
 
        set_if_smaller(share->blocksize,share->keyinfo[i].block_length);
 
266
        set_if_smaller(share->blocksize,(uint)share->keyinfo[i].block_length);
269
267
        share->keyinfo[i].seg=pos;
270
268
        for (j=0 ; j < share->keyinfo[i].keysegs; j++,pos++)
271
269
        {
283
281
          {
284
282
            if (!pos->language)
285
283
              pos->charset=default_charset_info;
286
 
            else if (!(pos->charset= get_charset(pos->language, MYF(MY_WME))))
 
284
            else if (!(pos->charset= get_charset(pos->language)))
287
285
            {
288
286
              my_errno=HA_ERR_UNKNOWN_CHARSET;
289
287
              goto err;
315
313
          {
316
314
            if (!pos->language)
317
315
              pos->charset=default_charset_info;
318
 
            else if (!(pos->charset= get_charset(pos->language, MYF(MY_WME))))
 
316
            else if (!(pos->charset= get_charset(pos->language)))
319
317
            {
320
318
              my_errno=HA_ERR_UNKNOWN_CHARSET;
321
319
              goto err;
386
384
    thr_lock_init(&share->lock);
387
385
    pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST);
388
386
    for (i=0; i<keys; i++)
389
 
      my_rwlock_init(&share->key_root_lock[i], NULL);
390
 
    my_rwlock_init(&share->mmap_lock, NULL);
 
387
      pthread_rwlock_init(&share->key_root_lock[i], NULL);
 
388
    pthread_rwlock_init(&share->mmap_lock, NULL);
391
389
    if (!thr_lock_inited)
392
390
    {
393
391
      /* Probably a single threaded program; Don't use concurrent inserts */
449
447
  if (!have_rtree)
450
448
    info.rtree_recursion_state= NULL;
451
449
 
452
 
  my_stpcpy(info.filename,name);
 
450
  strcpy(info.filename,name);
453
451
  memcpy(info.blobs,share->blobs,sizeof(MI_BLOB)*share->base.blobs);
454
452
  info.lastkey2=info.lastkey+share->base.max_key_length;
455
453
 
546
544
} /* mi_open */
547
545
 
548
546
 
549
 
unsigned char *mi_alloc_rec_buff(MI_INFO *info, ulong length, unsigned char **buf)
 
547
unsigned char *mi_alloc_rec_buff(MI_INFO *info, size_t length, unsigned char **buf)
550
548
{
551
549
  uint32_t extra;
552
550
  uint32_t old_length= 0;
573
571
            MI_REC_BUFF_OFFSET : 0);
574
572
    if (extra && newptr)
575
573
      newptr-= MI_REC_BUFF_OFFSET;
576
 
    if (!(newptr=(unsigned char*) my_realloc((unsigned char*)newptr, length+extra+8,
577
 
                                     MYF(MY_ALLOW_ZERO_PTR))))
 
574
    void *tmpnewptr= NULL;
 
575
    if (!(tmpnewptr= realloc(newptr, length+extra+8))) 
578
576
      return newptr;
 
577
    newptr= tmpnewptr;
579
578
    *((uint32_t *) newptr)= (uint32_t) length;
580
579
    *buf= newptr+(extra ?  MI_REC_BUFF_OFFSET : 0);
581
580
  }
860
859
  mi_int2store(ptr,base->max_key_length);               ptr +=2;
861
860
  mi_int2store(ptr,base->extra_alloc_bytes);            ptr +=2;
862
861
  *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;
 
862
  /* old raid info  slots */
 
863
  *ptr++= 0;
 
864
  mi_int2store(ptr,UINT16_C(0));                        ptr +=2;
 
865
  mi_int4store(ptr,UINT32_C(0));                        ptr +=4;
 
866
 
866
867
  memset(ptr, 0, 6);                                    ptr +=6; /* extra */
867
868
  return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
868
869
}
894
895
  base->max_key_length = mi_uint2korr(ptr);             ptr +=2;
895
896
  base->extra_alloc_bytes = mi_uint2korr(ptr);          ptr +=2;
896
897
  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
 
  }
 
898
 
 
899
  /* advance past raid_type (1) raid_chunks (2) and raid_chunksize (4) */
 
900
  ptr+= 7;
906
901
 
907
902
  ptr+=6;
908
903
  return ptr;
965
960
  pos= keyseg->null_bit ? keyseg->null_pos : keyseg->bit_pos;
966
961
  mi_int4store(ptr, pos);
967
962
  ptr+=4;
968
 
  
 
963
 
969
964
  return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
970
965
}
971
966
 
1043
1038
}
1044
1039
 
1045
1040
/**************************************************************************
1046
 
Open data file with or without RAID
 
1041
Open data file
1047
1042
We can't use dup() here as the data file descriptors need to have different
1048
1043
active seek-positions.
1049
1044
 
1051
1046
exist a dup()-like call that would give us two different file descriptors.
1052
1047
*************************************************************************/
1053
1048
 
1054
 
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share,
1055
 
                     File file_to_dup __attribute__((unused)))
 
1049
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup)
1056
1050
{
1057
 
    info->dfile=my_open(share->data_file_name, share->mode | O_SHARE,
1058
 
                        MYF(MY_WME));
 
1051
  (void)file_to_dup; 
 
1052
  info->dfile=my_open(share->data_file_name, share->mode,
 
1053
                      MYF(MY_WME));
1059
1054
  return info->dfile >= 0 ? 0 : 1;
1060
1055
}
1061
1056
 
1062
1057
 
1063
1058
int mi_open_keyfile(MYISAM_SHARE *share)
1064
1059
{
1065
 
  if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE,
 
1060
  if ((share->kfile=my_open(share->unique_file_name, share->mode,
1066
1061
                            MYF(MY_WME))) < 0)
1067
1062
    return 1;
1068
1063
  return 0;