~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Andy Lester
  • Date: 2008-08-09 05:13:22 UTC
  • mto: (266.1.29 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 287.
  • Revision ID: andy@petdance.com-20080809051322-dzas70no2mv6c9i5
removed incorrect comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <mysys/queues.h>
21
21
#include <mysys/my_bit.h>
22
22
 
23
 
#include <drizzled/util/test.h>
24
23
 
25
24
/*
26
25
  Old options is used when recreating database, from myisamchk
27
26
*/
28
27
 
29
 
int mi_create(const char *name,uint32_t keys,MI_KEYDEF *keydefs,
30
 
              uint32_t columns, MI_COLUMNDEF *recinfo,
31
 
              uint32_t uniques, MI_UNIQUEDEF *uniquedefs,
32
 
              MI_CREATE_INFO *ci,uint32_t flags)
 
28
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
 
29
              uint columns, MI_COLUMNDEF *recinfo,
 
30
              uint uniques, MI_UNIQUEDEF *uniquedefs,
 
31
              MI_CREATE_INFO *ci,uint flags)
33
32
{
34
 
  register uint32_t i, j;
 
33
  register uint i, j;
35
34
  File dfile= 0, file= 0;
36
35
  int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
37
36
  myf create_flag;
38
 
  uint32_t fields,length,max_key_length,packed,pointer,real_length_diff,
 
37
  uint fields,length,max_key_length,packed,pointer,real_length_diff,
39
38
       key_length,info_length,key_segs,options,min_key_length_skip,
40
39
       base_pos,long_varchar_count,varchar_length,
41
40
       max_key_block_length,unique_key_parts,fulltext_keys,offset;
42
 
  uint32_t aligned_key_start, block_length;
 
41
  uint aligned_key_start, block_length;
43
42
  ulong reclength, real_reclength,min_pack_length;
44
43
  char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
45
44
  ulong pack_reclength;
170
169
  if (flags & HA_CREATE_TMP_TABLE)
171
170
  {
172
171
    options|= HA_OPTION_TMP_TABLE;
173
 
    create_mode|= O_EXCL;
 
172
    create_mode|= O_EXCL | O_NOFOLLOW;
174
173
  }
175
174
  if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
176
175
  {
355
354
    block_length= (keydef->block_length ? 
356
355
                   my_round_up_to_next_power(keydef->block_length) :
357
356
                   myisam_block_size);
358
 
    block_length= cmax(block_length, MI_MIN_KEY_BLOCK_LENGTH);
359
 
    block_length= cmin(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
357
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
358
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
360
359
 
361
360
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
362
361
                                                 pointer,MI_MAX_KEYPTR_SIZE,
432
431
  share.state.unique=   (ulong) 0;
433
432
  share.state.update_count=(ulong) 0;
434
433
  share.state.version=  (ulong) time((time_t*) 0);
435
 
  share.state.sortkey=  UINT16_MAX;
 
434
  share.state.sortkey=  (ushort) ~0;
436
435
  share.state.auto_increment=ci->auto_increment;
437
436
  share.options=options;
438
437
  share.base.rec_reflength=pointer;
444
443
    got from MYI file header (see also myisampack.c:save_state)
445
444
  */
446
445
  share.base.key_reflength=
447
 
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
 
446
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
448
447
  share.base.keys= share.state.header.keys= keys;
449
448
  share.state.header.uniques= uniques;
450
449
  share.state.header.fulltext_keys= fulltext_keys;
477
476
  share.base.min_block_length=
478
477
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
479
478
     ! share.base.blobs) ?
480
 
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
 
479
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
481
480
    MI_EXTEND_BLOCK_LENGTH;
482
481
  if (! (flags & HA_DONT_TOUCH_DATA))
483
482
    share.state.create_time= (long) time((time_t*) 0);
604
603
  /* Write key and keyseg definitions */
605
604
  for (i=0 ; i < share.base.keys - uniques; i++)
606
605
  {
607
 
    uint32_t sp_segs= 0;
 
606
    uint sp_segs= 0;
608
607
 
609
608
    if (mi_keydef_write(file, &keydefs[i]))
610
609
      goto err;
685
684
  pthread_mutex_unlock(&THR_LOCK_myisam);
686
685
  if (my_close(file,MYF(0)))
687
686
    goto err;
688
 
  free((char*) rec_per_key_part);
 
687
  my_free((char*) rec_per_key_part,MYF(0));
689
688
  return(0);
690
689
 
691
690
err:
693
692
  save_errno=my_errno;
694
693
  switch (errpos) {
695
694
  case 3:
696
 
    my_close(dfile,MYF(0));
 
695
    VOID(my_close(dfile,MYF(0)));
697
696
    /* fall through */
698
697
  case 2:
 
698
    /* QQ: T�nu should add a call to my_raid_delete() here */
699
699
  if (! (flags & HA_DONT_TOUCH_DATA))
700
700
    my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
701
701
                                     MY_UNPACK_FILENAME | MY_APPEND_EXT),
702
702
                           MYF(0));
703
703
    /* fall through */
704
704
  case 1:
705
 
    my_close(file,MYF(0));
 
705
    VOID(my_close(file,MYF(0)));
706
706
    if (! (flags & HA_DONT_TOUCH_DATA))
707
707
      my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
708
708
                                       MY_UNPACK_FILENAME | MY_APPEND_EXT),
709
709
                             MYF(0));
710
710
  }
711
 
  free((char*) rec_per_key_part);
 
711
  my_free((char*) rec_per_key_part, MYF(0));
712
712
  return(my_errno=save_errno);          /* return the fatal errno */
713
713
}
714
714
 
715
715
 
716
 
uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def)
 
716
uint mi_get_pointer_length(uint64_t file_length, uint def)
717
717
{
718
718
  assert(def >= 2 && def <= 7);
719
719
  if (file_length)                              /* If not default */