2006-12-31 01:02:27 +01:00
|
|
|
|
/* Copyright (C) 2000-2006 MySQL AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
/* Create a MyISAM table */
|
|
|
|
|
|
2004-11-23 15:03:16 +01:00
|
|
|
|
#include "ftdefs.h"
|
2002-02-20 11:11:21 +01:00
|
|
|
|
#include "sp_defs.h"
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
#if defined(MSDOS) || defined(__WIN__)
|
|
|
|
|
#ifdef __WIN__
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <process.h> /* Prototype for getpid */
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
#include <m_ctype.h>
|
|
|
|
|
|
2006-05-03 14:59:17 +02:00
|
|
|
|
/*
|
|
|
|
|
Old options is used when recreating database, from myisamchk
|
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
|
|
|
|
|
uint columns, MI_COLUMNDEF *recinfo,
|
|
|
|
|
uint uniques, MI_UNIQUEDEF *uniquedefs,
|
|
|
|
|
MI_CREATE_INFO *ci,uint flags)
|
|
|
|
|
{
|
|
|
|
|
register uint i,j;
|
|
|
|
|
File dfile,file;
|
2005-03-03 19:51:29 +01:00
|
|
|
|
int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
|
2001-06-05 02:38:10 +02:00
|
|
|
|
myf create_flag;
|
2004-11-23 15:03:16 +01:00
|
|
|
|
uint fields,length,max_key_length,packed,pointer,real_length_diff,
|
2004-02-02 17:25:39 +01:00
|
|
|
|
key_length,info_length,key_segs,options,min_key_length_skip,
|
2004-12-18 04:19:21 +01:00
|
|
|
|
base_pos,long_varchar_count,varchar_length,
|
2003-01-21 19:24:34 +01:00
|
|
|
|
max_key_block_length,unique_key_parts,fulltext_keys,offset;
|
2006-05-03 14:59:17 +02:00
|
|
|
|
uint aligned_key_start, block_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
ulong reclength, real_reclength,min_pack_length;
|
2001-06-05 02:38:10 +02:00
|
|
|
|
char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
ulong pack_reclength;
|
2004-09-22 14:29:15 +02:00
|
|
|
|
ulonglong tot_length,max_rows, tmp;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
enum en_fieldtype type;
|
|
|
|
|
MYISAM_SHARE share;
|
|
|
|
|
MI_KEYDEF *keydef,tmp_keydef;
|
|
|
|
|
MI_UNIQUEDEF *uniquedef;
|
2002-04-25 12:10:29 +02:00
|
|
|
|
HA_KEYSEG *keyseg,tmp_keyseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
MI_COLUMNDEF *rec;
|
2000-11-28 03:47:47 +01:00
|
|
|
|
ulong *rec_per_key_part;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
my_off_t key_root[MI_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE];
|
|
|
|
|
MI_CREATE_INFO tmp_create_info;
|
|
|
|
|
DBUG_ENTER("mi_create");
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("enter", ("keys: %u columns: %u uniques: %u flags: %u",
|
|
|
|
|
keys, columns, uniques, flags));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
if (!ci)
|
|
|
|
|
{
|
|
|
|
|
bzero((char*) &tmp_create_info,sizeof(tmp_create_info));
|
|
|
|
|
ci=&tmp_create_info;
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-02 19:42:07 +02:00
|
|
|
|
if (keys + uniques > MI_MAX_KEY || columns == 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION);
|
|
|
|
|
}
|
|
|
|
|
LINT_INIT(dfile);
|
|
|
|
|
LINT_INIT(file);
|
|
|
|
|
errpos=0;
|
|
|
|
|
options=0;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
|
bzero((uchar*) &share,sizeof(share));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
if (flags & HA_DONT_TOUCH_DATA)
|
|
|
|
|
{
|
|
|
|
|
if (!(ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD))
|
|
|
|
|
options=ci->old_options &
|
|
|
|
|
(HA_OPTION_COMPRESS_RECORD | HA_OPTION_PACK_RECORD |
|
|
|
|
|
HA_OPTION_READ_ONLY_DATA | HA_OPTION_CHECKSUM |
|
|
|
|
|
HA_OPTION_TMP_TABLE | HA_OPTION_DELAY_KEY_WRITE);
|
|
|
|
|
else
|
|
|
|
|
options=ci->old_options &
|
|
|
|
|
(HA_OPTION_CHECKSUM | HA_OPTION_TMP_TABLE | HA_OPTION_DELAY_KEY_WRITE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ci->reloc_rows > ci->max_rows)
|
2000-11-28 03:47:47 +01:00
|
|
|
|
ci->reloc_rows=ci->max_rows; /* Check if wrong parameter */
|
|
|
|
|
|
|
|
|
|
if (!(rec_per_key_part=
|
|
|
|
|
(ulong*) my_malloc((keys + uniques)*MI_MAX_KEY_SEG*sizeof(long),
|
|
|
|
|
MYF(MY_WME | MY_ZEROFILL))))
|
|
|
|
|
DBUG_RETURN(my_errno);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
/* Start by checking fields and field-types used */
|
|
|
|
|
|
2004-12-18 04:19:21 +01:00
|
|
|
|
reclength=varchar_length=long_varchar_count=packed=
|
2000-07-31 21:29:14 +02:00
|
|
|
|
min_pack_length=pack_reclength=0;
|
|
|
|
|
for (rec=recinfo, fields=0 ;
|
|
|
|
|
fields != columns ;
|
|
|
|
|
rec++,fields++)
|
|
|
|
|
{
|
|
|
|
|
reclength+=rec->length;
|
|
|
|
|
if ((type=(enum en_fieldtype) rec->type) != FIELD_NORMAL &&
|
|
|
|
|
type != FIELD_CHECK)
|
|
|
|
|
{
|
|
|
|
|
packed++;
|
|
|
|
|
if (type == FIELD_BLOB)
|
|
|
|
|
{
|
|
|
|
|
share.base.blobs++;
|
|
|
|
|
if (pack_reclength != INT_MAX32)
|
|
|
|
|
{
|
|
|
|
|
if (rec->length == 4+mi_portable_sizeof_char_ptr)
|
|
|
|
|
pack_reclength= INT_MAX32;
|
|
|
|
|
else
|
|
|
|
|
pack_reclength+=(1 << ((rec->length-mi_portable_sizeof_char_ptr)*8)); /* Max blob length */
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-06 23:13:29 +01:00
|
|
|
|
else if (type == FIELD_SKIP_PRESPACE ||
|
|
|
|
|
type == FIELD_SKIP_ENDSPACE)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
if (pack_reclength != INT_MAX32)
|
|
|
|
|
pack_reclength+= rec->length > 255 ? 2 : 1;
|
|
|
|
|
min_pack_length++;
|
|
|
|
|
}
|
|
|
|
|
else if (type == FIELD_VARCHAR)
|
|
|
|
|
{
|
2004-12-18 04:19:21 +01:00
|
|
|
|
varchar_length+= rec->length-1; /* Used for min_pack_length */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
packed--;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
pack_reclength++;
|
|
|
|
|
min_pack_length++;
|
|
|
|
|
/* We must test for 257 as length includes pack-length */
|
2005-12-23 20:50:28 +01:00
|
|
|
|
if (test(rec->length >= 257))
|
2004-12-18 04:19:21 +01:00
|
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
|
long_varchar_count++;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
pack_reclength+= 2; /* May be packed on 3 bytes */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-06 23:13:29 +01:00
|
|
|
|
else if (type != FIELD_SKIP_ZERO)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
min_pack_length+=rec->length;
|
|
|
|
|
packed--; /* Not a pack record type */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else /* FIELD_NORMAL */
|
|
|
|
|
min_pack_length+=rec->length;
|
|
|
|
|
}
|
|
|
|
|
if ((packed & 7) == 1)
|
|
|
|
|
{ /* Bad packing, try to remove a zero-field */
|
|
|
|
|
while (rec != recinfo)
|
|
|
|
|
{
|
|
|
|
|
rec--;
|
2001-11-06 23:13:29 +01:00
|
|
|
|
if (rec->type == (int) FIELD_SKIP_ZERO && rec->length == 1)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
2007-03-13 15:02:06 +01:00
|
|
|
|
/*
|
|
|
|
|
NOTE1: here we change a field type FIELD_SKIP_ZERO ->
|
|
|
|
|
FIELD_NORMAL
|
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
rec->type=(int) FIELD_NORMAL;
|
|
|
|
|
packed--;
|
|
|
|
|
min_pack_length++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (packed || (flags & HA_PACK_RECORD))
|
|
|
|
|
options|=HA_OPTION_PACK_RECORD; /* Must use packed records */
|
2001-06-26 09:23:50 +02:00
|
|
|
|
/* We can't use checksum with static length rows */
|
|
|
|
|
if (!(options & HA_OPTION_PACK_RECORD))
|
|
|
|
|
options&= ~HA_OPTION_CHECKSUM;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
if (!(options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)))
|
|
|
|
|
min_pack_length+= varchar_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (flags & HA_CREATE_TMP_TABLE)
|
2005-03-03 19:51:29 +01:00
|
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
|
options|= HA_OPTION_TMP_TABLE;
|
2005-03-03 19:51:29 +01:00
|
|
|
|
create_mode|= O_EXCL | O_NOFOLLOW;
|
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
|
|
|
|
|
{
|
|
|
|
|
options|= HA_OPTION_CHECKSUM;
|
|
|
|
|
min_pack_length++;
|
|
|
|
|
}
|
|
|
|
|
if (flags & HA_CREATE_DELAY_KEY_WRITE)
|
|
|
|
|
options|= HA_OPTION_DELAY_KEY_WRITE;
|
2005-12-28 13:05:30 +01:00
|
|
|
|
if (flags & HA_CREATE_RELIES_ON_SQL_LAYER)
|
|
|
|
|
options|= HA_OPTION_RELIES_ON_SQL_LAYER;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
packed=(packed+7)/8;
|
|
|
|
|
if (pack_reclength != INT_MAX32)
|
|
|
|
|
pack_reclength+= reclength+packed +
|
|
|
|
|
test(test_all_bits(options, HA_OPTION_CHECKSUM | HA_PACK_RECORD));
|
|
|
|
|
min_pack_length+=packed;
|
|
|
|
|
|
2005-05-13 11:08:08 +02:00
|
|
|
|
if (!ci->data_file_length && ci->max_rows)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
2005-05-13 11:08:08 +02:00
|
|
|
|
if (pack_reclength == INT_MAX32 ||
|
|
|
|
|
(~(ulonglong) 0)/ci->max_rows < (ulonglong) pack_reclength)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
ci->data_file_length= ~(ulonglong) 0;
|
|
|
|
|
else
|
|
|
|
|
ci->data_file_length=(ulonglong) ci->max_rows*pack_reclength;
|
|
|
|
|
}
|
|
|
|
|
else if (!ci->max_rows)
|
|
|
|
|
ci->max_rows=(ha_rows) (ci->data_file_length/(min_pack_length +
|
|
|
|
|
((options & HA_OPTION_PACK_RECORD) ?
|
|
|
|
|
3 : 0)));
|
|
|
|
|
|
|
|
|
|
if (options & (HA_OPTION_COMPRESS_RECORD | HA_OPTION_PACK_RECORD))
|
2004-05-01 15:41:59 +02:00
|
|
|
|
pointer=mi_get_pointer_length(ci->data_file_length,myisam_data_pointer_size);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
else
|
2004-05-01 15:41:59 +02:00
|
|
|
|
pointer=mi_get_pointer_length(ci->max_rows,myisam_data_pointer_size);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (!(max_rows=(ulonglong) ci->max_rows))
|
|
|
|
|
max_rows= ((((ulonglong) 1 << (pointer*8)) -1) / min_pack_length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real_reclength=reclength;
|
|
|
|
|
if (!(options & (HA_OPTION_COMPRESS_RECORD | HA_OPTION_PACK_RECORD)))
|
|
|
|
|
{
|
|
|
|
|
if (reclength <= pointer)
|
|
|
|
|
reclength=pointer+1; /* reserve place for delete link */
|
|
|
|
|
}
|
|
|
|
|
else
|
2004-12-18 04:19:21 +01:00
|
|
|
|
reclength+= long_varchar_count; /* We need space for varchar! */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
max_key_length=0; tot_length=0 ; key_segs=0;
|
2003-01-21 19:24:34 +01:00
|
|
|
|
fulltext_keys=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
max_key_block_length=0;
|
|
|
|
|
share.state.rec_per_key_part=rec_per_key_part;
|
|
|
|
|
share.state.key_root=key_root;
|
|
|
|
|
share.state.key_del=key_del;
|
|
|
|
|
if (uniques)
|
|
|
|
|
{
|
2001-10-02 04:53:00 +02:00
|
|
|
|
max_key_block_length= myisam_block_size;
|
2003-01-16 19:47:46 +01:00
|
|
|
|
max_key_length= MI_UNIQUE_HASH_LENGTH + pointer;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0, keydef=keydefs ; i < keys ; i++ , keydef++)
|
|
|
|
|
{
|
|
|
|
|
|
2002-02-20 11:11:21 +01:00
|
|
|
|
share.state.key_root[i]= HA_OFFSET_ERROR;
|
2004-11-23 15:03:16 +01:00
|
|
|
|
min_key_length_skip=length=real_length_diff=0;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
key_length=pointer;
|
2002-02-20 11:11:21 +01:00
|
|
|
|
if (keydef->flag & HA_SPATIAL)
|
|
|
|
|
{
|
2004-03-12 15:51:03 +01:00
|
|
|
|
#ifdef HAVE_SPATIAL
|
2002-02-20 11:11:21 +01:00
|
|
|
|
/* BAR TODO to support 3D and more dimensions in the future */
|
2003-01-21 19:24:34 +01:00
|
|
|
|
uint sp_segs=SPDIMS*2;
|
2002-02-20 11:11:21 +01:00
|
|
|
|
keydef->flag=HA_SPATIAL;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
2002-02-20 11:11:21 +01:00
|
|
|
|
if (flags & HA_DONT_TOUCH_DATA)
|
|
|
|
|
{
|
2003-01-21 19:24:34 +01:00
|
|
|
|
/*
|
2002-02-20 11:11:21 +01:00
|
|
|
|
called by myisamchk - i.e. table structure was taken from
|
2003-01-21 19:24:34 +01:00
|
|
|
|
MYI file and SPATIAL key *does have* additional sp_segs keysegs.
|
2005-07-23 17:04:15 +02:00
|
|
|
|
keydef->seg here points right at the GEOMETRY segment,
|
|
|
|
|
so we only need to decrease keydef->keysegs.
|
|
|
|
|
(see recreate_table() in mi_check.c)
|
2002-02-20 11:11:21 +01:00
|
|
|
|
*/
|
2005-07-23 17:04:15 +02:00
|
|
|
|
keydef->keysegs-=sp_segs-1;
|
2002-02-20 11:11:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (j=0, keyseg=keydef->seg ; (int) j < keydef->keysegs ;
|
|
|
|
|
j++, keyseg++)
|
|
|
|
|
{
|
|
|
|
|
if (keyseg->type != HA_KEYTYPE_BINARY &&
|
2004-12-18 04:19:21 +01:00
|
|
|
|
keyseg->type != HA_KEYTYPE_VARBINARY1 &&
|
|
|
|
|
keyseg->type != HA_KEYTYPE_VARBINARY2)
|
2002-02-20 11:11:21 +01:00
|
|
|
|
{
|
|
|
|
|
my_errno=HA_WRONG_CREATE_OPTION;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
keydef->keysegs+=sp_segs;
|
|
|
|
|
key_length+=SPLEN*sp_segs;
|
|
|
|
|
length++; /* At least one length byte */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=SPLEN*2*SPDIMS;
|
2004-03-12 15:51:03 +01:00
|
|
|
|
#else
|
|
|
|
|
my_errno= HA_ERR_UNSUPPORTED;
|
|
|
|
|
goto err;
|
|
|
|
|
#endif /*HAVE_SPATIAL*/
|
2002-02-20 11:11:21 +01:00
|
|
|
|
}
|
2004-12-06 01:00:37 +01:00
|
|
|
|
else if (keydef->flag & HA_FULLTEXT)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
keydef->flag=HA_FULLTEXT | HA_PACK_KEY | HA_VAR_LENGTH_KEY;
|
|
|
|
|
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
|
|
|
|
|
|
|
|
|
|
for (j=0, keyseg=keydef->seg ; (int) j < keydef->keysegs ;
|
|
|
|
|
j++, keyseg++)
|
|
|
|
|
{
|
|
|
|
|
if (keyseg->type != HA_KEYTYPE_TEXT &&
|
2004-12-18 04:19:21 +01:00
|
|
|
|
keyseg->type != HA_KEYTYPE_VARTEXT1 &&
|
|
|
|
|
keyseg->type != HA_KEYTYPE_VARTEXT2)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
my_errno=HA_WRONG_CREATE_OPTION;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2004-12-18 04:19:21 +01:00
|
|
|
|
if (!(keyseg->flag & HA_BLOB_PART) &&
|
|
|
|
|
(keyseg->type == HA_KEYTYPE_VARTEXT1 ||
|
|
|
|
|
keyseg->type == HA_KEYTYPE_VARTEXT2))
|
|
|
|
|
{
|
|
|
|
|
/* Make a flag that this is a VARCHAR */
|
|
|
|
|
keyseg->flag|= HA_VAR_LENGTH_PART;
|
|
|
|
|
/* Store in bit_start number of bytes used to pack the length */
|
|
|
|
|
keyseg->bit_start= ((keyseg->type == HA_KEYTYPE_VARTEXT1)?
|
|
|
|
|
1 : 2);
|
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 19:24:34 +01:00
|
|
|
|
fulltext_keys++;
|
2003-12-04 21:58:28 +01:00
|
|
|
|
key_length+= HA_FT_MAXBYTELEN+HA_FT_WLEN;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
length++; /* At least one length byte */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=HA_FT_MAXBYTELEN;
|
2004-11-23 15:03:16 +01:00
|
|
|
|
real_length_diff=HA_FT_MAXBYTELEN-FT_MAX_WORD_LEN_FOR_SORT;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-01-07 23:04:30 +01:00
|
|
|
|
/* Test if prefix compression */
|
|
|
|
|
if (keydef->flag & HA_PACK_KEY)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
2001-01-07 23:04:30 +01:00
|
|
|
|
/* Can't use space_compression on number keys */
|
|
|
|
|
if ((keydef->seg[0].flag & HA_SPACE_PACK) &&
|
|
|
|
|
keydef->seg[0].type == (int) HA_KEYTYPE_NUM)
|
|
|
|
|
keydef->seg[0].flag&= ~HA_SPACE_PACK;
|
|
|
|
|
|
2003-08-20 15:25:44 +02:00
|
|
|
|
/* Only use HA_PACK_KEY when first segment is a variable length key */
|
2001-01-07 23:04:30 +01:00
|
|
|
|
if (!(keydef->seg[0].flag & (HA_SPACE_PACK | HA_BLOB_PART |
|
2004-12-06 01:00:37 +01:00
|
|
|
|
HA_VAR_LENGTH_PART)))
|
2001-01-07 23:04:30 +01:00
|
|
|
|
{
|
|
|
|
|
/* pack relative to previous key */
|
|
|
|
|
keydef->flag&= ~HA_PACK_KEY;
|
|
|
|
|
keydef->flag|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
keydef->seg[0].flag|=HA_PACK_KEY; /* for easyer intern test */
|
|
|
|
|
keydef->flag|=HA_VAR_LENGTH_KEY;
|
|
|
|
|
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
|
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
2001-01-07 23:04:30 +01:00
|
|
|
|
if (keydef->flag & HA_BINARY_PACK_KEY)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
|
|
|
|
|
|
2003-03-02 01:48:57 +01:00
|
|
|
|
if (keydef->flag & HA_AUTO_KEY && ci->with_auto_increment)
|
2001-01-07 23:04:30 +01:00
|
|
|
|
share.base.auto_key=i+1;
|
|
|
|
|
for (j=0, keyseg=keydef->seg ; j < keydef->keysegs ; j++, keyseg++)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
2001-01-07 23:04:30 +01:00
|
|
|
|
/* numbers are stored with high by first to make compression easier */
|
|
|
|
|
switch (keyseg->type) {
|
|
|
|
|
case HA_KEYTYPE_SHORT_INT:
|
|
|
|
|
case HA_KEYTYPE_LONG_INT:
|
|
|
|
|
case HA_KEYTYPE_FLOAT:
|
|
|
|
|
case HA_KEYTYPE_DOUBLE:
|
|
|
|
|
case HA_KEYTYPE_USHORT_INT:
|
|
|
|
|
case HA_KEYTYPE_ULONG_INT:
|
|
|
|
|
case HA_KEYTYPE_LONGLONG:
|
|
|
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
|
|
|
case HA_KEYTYPE_INT24:
|
|
|
|
|
case HA_KEYTYPE_UINT24:
|
|
|
|
|
case HA_KEYTYPE_INT8:
|
|
|
|
|
keyseg->flag|= HA_SWAP_KEY;
|
2004-12-06 01:00:37 +01:00
|
|
|
|
break;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
case HA_KEYTYPE_VARTEXT1:
|
|
|
|
|
case HA_KEYTYPE_VARTEXT2:
|
|
|
|
|
case HA_KEYTYPE_VARBINARY1:
|
|
|
|
|
case HA_KEYTYPE_VARBINARY2:
|
2004-12-06 01:00:37 +01:00
|
|
|
|
if (!(keyseg->flag & HA_BLOB_PART))
|
2004-12-18 04:19:21 +01:00
|
|
|
|
{
|
|
|
|
|
/* Make a flag that this is a VARCHAR */
|
2004-12-06 01:00:37 +01:00
|
|
|
|
keyseg->flag|= HA_VAR_LENGTH_PART;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
/* Store in bit_start number of bytes used to pack the length */
|
|
|
|
|
keyseg->bit_start= ((keyseg->type == HA_KEYTYPE_VARTEXT1 ||
|
|
|
|
|
keyseg->type == HA_KEYTYPE_VARBINARY1) ?
|
|
|
|
|
1 : 2);
|
|
|
|
|
}
|
2004-12-06 01:00:37 +01:00
|
|
|
|
break;
|
2001-01-07 23:04:30 +01:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
2001-01-07 23:04:30 +01:00
|
|
|
|
if (keyseg->flag & HA_SPACE_PACK)
|
|
|
|
|
{
|
2004-12-06 01:00:37 +01:00
|
|
|
|
DBUG_ASSERT(!(keyseg->flag & HA_VAR_LENGTH_PART));
|
2001-01-07 23:04:30 +01:00
|
|
|
|
keydef->flag |= HA_SPACE_PACK_USED | HA_VAR_LENGTH_KEY;
|
|
|
|
|
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
|
|
|
|
|
length++; /* At least one length byte */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=keyseg->length;
|
2001-01-07 23:04:30 +01:00
|
|
|
|
if (keyseg->length >= 255)
|
|
|
|
|
{ /* prefix may be 3 bytes */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=2;
|
2001-01-07 23:04:30 +01:00
|
|
|
|
length+=2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-06 01:00:37 +01:00
|
|
|
|
if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
|
2001-01-07 23:04:30 +01:00
|
|
|
|
{
|
2004-12-18 04:19:21 +01:00
|
|
|
|
DBUG_ASSERT(!test_all_bits(keyseg->flag,
|
|
|
|
|
(HA_VAR_LENGTH_PART | HA_BLOB_PART)));
|
2001-01-07 23:04:30 +01:00
|
|
|
|
keydef->flag|=HA_VAR_LENGTH_KEY;
|
|
|
|
|
length++; /* At least one length byte */
|
|
|
|
|
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=keyseg->length;
|
2001-01-07 23:04:30 +01:00
|
|
|
|
if (keyseg->length >= 255)
|
|
|
|
|
{ /* prefix may be 3 bytes */
|
2004-02-02 17:25:39 +01:00
|
|
|
|
min_key_length_skip+=2;
|
2001-01-07 23:04:30 +01:00
|
|
|
|
length+=2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
key_length+= keyseg->length;
|
|
|
|
|
if (keyseg->null_bit)
|
|
|
|
|
{
|
|
|
|
|
key_length++;
|
|
|
|
|
options|=HA_OPTION_PACK_KEYS;
|
|
|
|
|
keyseg->flag|=HA_NULL_PART;
|
|
|
|
|
keydef->flag|=HA_VAR_LENGTH_KEY | HA_NULL_PART_KEY;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* if HA_FULLTEXT */
|
|
|
|
|
key_segs+=keydef->keysegs;
|
|
|
|
|
if (keydef->keysegs > MI_MAX_KEY_SEG)
|
|
|
|
|
{
|
|
|
|
|
my_errno=HA_WRONG_CREATE_OPTION;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2004-03-26 13:44:52 +01:00
|
|
|
|
/*
|
|
|
|
|
key_segs may be 0 in the case when we only want to be able to
|
|
|
|
|
add on row into the table. This can happen with some DISTINCT queries
|
|
|
|
|
in MySQL
|
|
|
|
|
*/
|
|
|
|
|
if ((keydef->flag & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME &&
|
|
|
|
|
key_segs)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.state.rec_per_key_part[key_segs-1]=1L;
|
|
|
|
|
length+=key_length;
|
2006-05-03 14:59:17 +02:00
|
|
|
|
/* Get block length for key, if defined by user */
|
|
|
|
|
block_length= (keydef->block_length ?
|
|
|
|
|
my_round_up_to_next_power(keydef->block_length) :
|
|
|
|
|
myisam_block_size);
|
|
|
|
|
block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
|
|
|
|
|
block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
|
|
|
|
|
|
2006-11-30 17:25:05 +01:00
|
|
|
|
keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
|
2006-11-30 21:38:12 +01:00
|
|
|
|
pointer,MI_MAX_KEYPTR_SIZE,
|
|
|
|
|
block_length);
|
2002-09-10 21:40:01 +02:00
|
|
|
|
if (keydef->block_length > MI_MAX_KEY_BLOCK_LENGTH ||
|
2002-10-24 00:14:59 +02:00
|
|
|
|
length >= MI_MAX_KEY_BUFF)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
my_errno=HA_WRONG_CREATE_OPTION;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
set_if_bigger(max_key_block_length,keydef->block_length);
|
|
|
|
|
keydef->keylength= (uint16) key_length;
|
2004-02-02 17:25:39 +01:00
|
|
|
|
keydef->minlength= (uint16) (length-min_key_length_skip);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
keydef->maxlength= (uint16) length;
|
|
|
|
|
|
|
|
|
|
if (length > max_key_length)
|
|
|
|
|
max_key_length= length;
|
|
|
|
|
tot_length+= (max_rows/(ulong) (((uint) keydef->block_length-5)/
|
|
|
|
|
(length*2)))*
|
|
|
|
|
(ulong) keydef->block_length;
|
|
|
|
|
}
|
2001-10-02 04:53:00 +02:00
|
|
|
|
for (i=max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; )
|
2000-07-31 21:29:14 +02:00
|
|
|
|
key_del[i]=HA_OFFSET_ERROR;
|
|
|
|
|
|
|
|
|
|
unique_key_parts=0;
|
|
|
|
|
offset=reclength-uniques*MI_UNIQUE_HASH_LENGTH;
|
|
|
|
|
for (i=0, uniquedef=uniquedefs ; i < uniques ; i++ , uniquedef++)
|
|
|
|
|
{
|
|
|
|
|
uniquedef->key=keys+i;
|
|
|
|
|
unique_key_parts+=uniquedef->keysegs;
|
|
|
|
|
share.state.key_root[keys+i]= HA_OFFSET_ERROR;
|
2002-07-24 21:56:33 +02:00
|
|
|
|
tot_length+= (max_rows/(ulong) (((uint) myisam_block_size-5)/
|
|
|
|
|
((MI_UNIQUE_HASH_LENGTH + pointer)*2)))*
|
|
|
|
|
(ulong) myisam_block_size;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
keys+=uniques; /* Each unique has 1 key */
|
|
|
|
|
key_segs+=uniques; /* Each unique has 1 key seg */
|
|
|
|
|
|
|
|
|
|
base_pos=(MI_STATE_INFO_SIZE + keys * MI_STATE_KEY_SIZE +
|
2001-10-02 04:53:00 +02:00
|
|
|
|
max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH*
|
|
|
|
|
MI_STATE_KEYBLOCK_SIZE+
|
2000-07-31 21:29:14 +02:00
|
|
|
|
key_segs*MI_STATE_KEYSEG_SIZE);
|
|
|
|
|
info_length=base_pos+(uint) (MI_BASE_INFO_SIZE+
|
|
|
|
|
keys * MI_KEYDEF_SIZE+
|
|
|
|
|
uniques * MI_UNIQUEDEF_SIZE +
|
2002-04-25 12:10:29 +02:00
|
|
|
|
(key_segs + unique_key_parts)*HA_KEYSEG_SIZE+
|
2000-07-31 21:29:14 +02:00
|
|
|
|
columns*MI_COLUMNDEF_SIZE);
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("info_length: %u", info_length));
|
|
|
|
|
/* There are only 16 bits for the total header length. */
|
|
|
|
|
if (info_length > 65535)
|
|
|
|
|
{
|
|
|
|
|
my_printf_error(0, "MyISAM table '%s' has too many columns and/or "
|
|
|
|
|
"indexes and/or unique constraints.",
|
|
|
|
|
MYF(0), name + dirname_length(name));
|
|
|
|
|
my_errno= HA_WRONG_CREATE_OPTION;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
|
bmove(share.state.header.file_version,(uchar*) myisam_file_magic,4);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
ci->old_options=options| (ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD ?
|
|
|
|
|
HA_OPTION_COMPRESS_RECORD |
|
|
|
|
|
HA_OPTION_TEMP_COMPRESS_RECORD: 0);
|
|
|
|
|
mi_int2store(share.state.header.options,ci->old_options);
|
|
|
|
|
mi_int2store(share.state.header.header_length,info_length);
|
|
|
|
|
mi_int2store(share.state.header.state_info_length,MI_STATE_INFO_SIZE);
|
|
|
|
|
mi_int2store(share.state.header.base_info_length,MI_BASE_INFO_SIZE);
|
|
|
|
|
mi_int2store(share.state.header.base_pos,base_pos);
|
|
|
|
|
share.state.header.language= (ci->language ?
|
2003-06-03 11:59:17 +02:00
|
|
|
|
ci->language : default_charset_info->number);
|
2006-05-03 14:59:17 +02:00
|
|
|
|
share.state.header.max_block_size_index= max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
share.state.dellink = HA_OFFSET_ERROR;
|
|
|
|
|
share.state.process= (ulong) getpid();
|
|
|
|
|
share.state.unique= (ulong) 0;
|
2000-11-16 02:58:58 +01:00
|
|
|
|
share.state.update_count=(ulong) 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.state.version= (ulong) time((time_t*) 0);
|
|
|
|
|
share.state.sortkey= (ushort) ~0;
|
|
|
|
|
share.state.auto_increment=ci->auto_increment;
|
|
|
|
|
share.options=options;
|
|
|
|
|
share.base.rec_reflength=pointer;
|
2004-09-22 14:29:15 +02:00
|
|
|
|
/* Get estimate for index file length (this may be wrong for FT keys) */
|
|
|
|
|
tmp= (tot_length + max_key_block_length * keys *
|
|
|
|
|
MI_INDEX_BLOCK_MARGIN) / MI_MIN_KEY_BLOCK_LENGTH;
|
|
|
|
|
/*
|
|
|
|
|
use maximum of key_file_length we calculated and key_file_length value we
|
|
|
|
|
got from MYI file header (see also myisampack.c:save_state)
|
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.base.key_reflength=
|
2004-09-22 14:29:15 +02:00
|
|
|
|
mi_get_pointer_length(max(ci->key_file_length,tmp),3);
|
2003-01-21 19:24:34 +01:00
|
|
|
|
share.base.keys= share.state.header.keys= keys;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.state.header.uniques= uniques;
|
2003-01-21 19:24:34 +01:00
|
|
|
|
share.state.header.fulltext_keys= fulltext_keys;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
mi_int2store(share.state.header.key_parts,key_segs);
|
|
|
|
|
mi_int2store(share.state.header.unique_key_parts,unique_key_parts);
|
|
|
|
|
|
2005-07-19 14:13:56 +02:00
|
|
|
|
mi_set_all_keys_active(share.state.key_map, keys);
|
2006-05-03 14:59:17 +02:00
|
|
|
|
aligned_key_start= my_round_up_to_next_power(max_key_block_length ?
|
|
|
|
|
max_key_block_length :
|
|
|
|
|
myisam_block_size);
|
|
|
|
|
|
|
|
|
|
share.base.keystart= share.state.state.key_file_length=
|
|
|
|
|
MY_ALIGN(info_length, aligned_key_start);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.base.max_key_block_length=max_key_block_length;
|
|
|
|
|
share.base.max_key_length=ALIGN_SIZE(max_key_length+4);
|
|
|
|
|
share.base.records=ci->max_rows;
|
|
|
|
|
share.base.reloc= ci->reloc_rows;
|
|
|
|
|
share.base.reclength=real_reclength;
|
2001-06-26 09:23:50 +02:00
|
|
|
|
share.base.pack_reclength=reclength+ test(options & HA_OPTION_CHECKSUM);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.base.max_pack_length=pack_reclength;
|
|
|
|
|
share.base.min_pack_length=min_pack_length;
|
|
|
|
|
share.base.pack_bits=packed;
|
|
|
|
|
share.base.fields=fields;
|
|
|
|
|
share.base.pack_fields=packed;
|
|
|
|
|
#ifdef USE_RAID
|
|
|
|
|
share.base.raid_type=ci->raid_type;
|
|
|
|
|
share.base.raid_chunks=ci->raid_chunks;
|
|
|
|
|
share.base.raid_chunksize=ci->raid_chunksize;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* max_data_file_length and max_key_file_length are recalculated on open */
|
|
|
|
|
if (options & HA_OPTION_TMP_TABLE)
|
|
|
|
|
share.base.max_data_file_length=(my_off_t) ci->data_file_length;
|
|
|
|
|
|
|
|
|
|
share.base.min_block_length=
|
|
|
|
|
(share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
|
|
|
|
|
! share.base.blobs) ?
|
|
|
|
|
max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
|
|
|
|
|
MI_EXTEND_BLOCK_LENGTH;
|
|
|
|
|
if (! (flags & HA_DONT_TOUCH_DATA))
|
|
|
|
|
share.state.create_time= (long) time((time_t*) 0);
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
2005-12-23 20:50:28 +01:00
|
|
|
|
pthread_mutex_lock(&THR_LOCK_myisam);
|
|
|
|
|
|
2007-03-23 10:26:14 +01:00
|
|
|
|
/*
|
|
|
|
|
NOTE: For test_if_reopen() we need a real path name. Hence we need
|
|
|
|
|
MY_RETURN_REAL_PATH for every fn_format(filename, ...).
|
|
|
|
|
*/
|
2001-06-05 02:38:10 +02:00
|
|
|
|
if (ci->index_file_name)
|
|
|
|
|
{
|
2005-12-31 06:01:26 +01:00
|
|
|
|
char *iext= strrchr(ci->index_file_name, '.');
|
|
|
|
|
int have_iext= iext && !strcmp(iext, MI_NAME_IEXT);
|
2006-07-06 02:18:59 +02:00
|
|
|
|
if (options & HA_OPTION_TMP_TABLE)
|
|
|
|
|
{
|
|
|
|
|
char *path;
|
|
|
|
|
/* chop off the table name, tempory tables use generated name */
|
|
|
|
|
if ((path= strrchr(ci->index_file_name, FN_LIBCHAR)))
|
|
|
|
|
*path= '\0';
|
|
|
|
|
fn_format(filename, name, ci->index_file_name, MI_NAME_IEXT,
|
2007-03-23 10:26:14 +01:00
|
|
|
|
MY_REPLACE_DIR | MY_UNPACK_FILENAME |
|
|
|
|
|
MY_RETURN_REAL_PATH | MY_APPEND_EXT);
|
2006-07-06 02:18:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2006-07-26 21:33:25 +02:00
|
|
|
|
{
|
|
|
|
|
fn_format(filename, ci->index_file_name, "", MI_NAME_IEXT,
|
2007-03-23 10:26:14 +01:00
|
|
|
|
MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH |
|
|
|
|
|
(have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT));
|
2006-07-26 21:33:25 +02:00
|
|
|
|
}
|
2005-12-31 06:01:26 +01:00
|
|
|
|
fn_format(linkname, name, "", MI_NAME_IEXT,
|
|
|
|
|
MY_UNPACK_FILENAME|MY_APPEND_EXT);
|
2001-06-05 02:38:10 +02:00
|
|
|
|
linkname_ptr=linkname;
|
|
|
|
|
/*
|
|
|
|
|
Don't create the table if the link or file exists to ensure that one
|
|
|
|
|
doesn't accidently destroy another table.
|
|
|
|
|
*/
|
|
|
|
|
create_flag=0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-07 16:30:13 +01:00
|
|
|
|
char *iext= strrchr(name, '.');
|
|
|
|
|
int have_iext= iext && !strcmp(iext, MI_NAME_IEXT);
|
2005-12-31 06:01:26 +01:00
|
|
|
|
fn_format(filename, name, "", MI_NAME_IEXT,
|
2007-03-23 10:26:14 +01:00
|
|
|
|
MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH |
|
2007-03-07 16:30:13 +01:00
|
|
|
|
(have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT));
|
2001-06-05 02:38:10 +02:00
|
|
|
|
linkname_ptr=0;
|
|
|
|
|
/* Replace the current file */
|
2007-07-11 11:37:47 +02:00
|
|
|
|
create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD;
|
2001-06-05 02:38:10 +02:00
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
2005-03-02 10:35:00 +01:00
|
|
|
|
/*
|
|
|
|
|
If a MRG_MyISAM table is in use, the mapped MyISAM tables are open,
|
|
|
|
|
but no entry is made in the table cache for them.
|
|
|
|
|
A TRUNCATE command checks for the table in the cache only and could
|
|
|
|
|
be fooled to believe, the table is not open.
|
|
|
|
|
Pull the emergency brake in this situation. (Bug #8306)
|
2007-03-23 10:26:14 +01:00
|
|
|
|
|
|
|
|
|
NOTE: The filename is compared against unique_file_name of every
|
|
|
|
|
open table. Hence we need a real path here.
|
2005-03-02 10:35:00 +01:00
|
|
|
|
*/
|
|
|
|
|
if (test_if_reopen(filename))
|
|
|
|
|
{
|
|
|
|
|
my_printf_error(0, "MyISAM table '%s' is in use "
|
|
|
|
|
"(most likely by a MERGE table). Try FLUSH TABLES.",
|
|
|
|
|
MYF(0), name + dirname_length(name));
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-03 19:51:29 +01:00
|
|
|
|
if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
|
2001-06-05 02:38:10 +02:00
|
|
|
|
MYF(MY_WME | create_flag))) < 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
goto err;
|
|
|
|
|
errpos=1;
|
2001-05-31 13:07:17 +02:00
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (!(flags & HA_DONT_TOUCH_DATA))
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_RAID
|
|
|
|
|
if (share.base.raid_type)
|
|
|
|
|
{
|
2005-12-31 06:01:26 +01:00
|
|
|
|
(void) fn_format(filename, name, "", MI_NAME_DEXT,
|
|
|
|
|
MY_UNPACK_FILENAME | MY_APPEND_EXT);
|
2005-03-04 09:30:22 +01:00
|
|
|
|
if ((dfile=my_raid_create(filename, 0, create_mode,
|
2000-07-31 21:29:14 +02:00
|
|
|
|
share.base.raid_type,
|
|
|
|
|
share.base.raid_chunks,
|
|
|
|
|
share.base.raid_chunksize,
|
|
|
|
|
MYF(MY_WME | MY_RAID))) < 0)
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
2001-05-31 13:07:17 +02:00
|
|
|
|
{
|
2001-06-05 02:38:10 +02:00
|
|
|
|
if (ci->data_file_name)
|
|
|
|
|
{
|
2005-12-31 06:01:26 +01:00
|
|
|
|
char *dext= strrchr(ci->data_file_name, '.');
|
|
|
|
|
int have_dext= dext && !strcmp(dext, MI_NAME_DEXT);
|
|
|
|
|
|
2006-07-06 02:18:59 +02:00
|
|
|
|
if (options & HA_OPTION_TMP_TABLE)
|
|
|
|
|
{
|
|
|
|
|
char *path;
|
|
|
|
|
/* chop off the table name, tempory tables use generated name */
|
|
|
|
|
if ((path= strrchr(ci->data_file_name, FN_LIBCHAR)))
|
|
|
|
|
*path= '\0';
|
|
|
|
|
fn_format(filename, name, ci->data_file_name, MI_NAME_DEXT,
|
2006-07-27 12:12:41 +02:00
|
|
|
|
MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_APPEND_EXT);
|
2006-07-06 02:18:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2006-07-26 21:33:25 +02:00
|
|
|
|
{
|
|
|
|
|
fn_format(filename, ci->data_file_name, "", MI_NAME_DEXT,
|
|
|
|
|
MY_UNPACK_FILENAME |
|
|
|
|
|
(have_dext ? MY_REPLACE_EXT : MY_APPEND_EXT));
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-31 06:01:26 +01:00
|
|
|
|
fn_format(linkname, name, "",MI_NAME_DEXT,
|
|
|
|
|
MY_UNPACK_FILENAME | MY_APPEND_EXT);
|
2001-06-05 02:38:10 +02:00
|
|
|
|
linkname_ptr=linkname;
|
|
|
|
|
create_flag=0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-12-31 06:01:26 +01:00
|
|
|
|
fn_format(filename,name,"", MI_NAME_DEXT,
|
|
|
|
|
MY_UNPACK_FILENAME | MY_APPEND_EXT);
|
2001-06-05 02:38:10 +02:00
|
|
|
|
linkname_ptr=0;
|
2007-07-11 11:37:47 +02:00
|
|
|
|
create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD;
|
2001-06-05 02:38:10 +02:00
|
|
|
|
}
|
2003-01-21 19:24:34 +01:00
|
|
|
|
if ((dfile=
|
2005-03-03 19:51:29 +01:00
|
|
|
|
my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
|
2001-06-05 02:38:10 +02:00
|
|
|
|
MYF(MY_WME | create_flag))) < 0)
|
2001-05-31 13:07:17 +02:00
|
|
|
|
goto err;
|
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
errpos=3;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("write state info and base info"));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (mi_state_info_write(file, &share.state, 2) ||
|
|
|
|
|
mi_base_info_write(file, &share.base))
|
|
|
|
|
goto err;
|
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
|
if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE)
|
|
|
|
|
{
|
|
|
|
|
uint pos=(uint) my_tell(file,MYF(0));
|
|
|
|
|
DBUG_PRINT("warning",("base_length: %d != used_length: %d",
|
|
|
|
|
base_pos+ MI_BASE_INFO_SIZE, pos));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Write key and keyseg definitions */
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("write key and keyseg definitions"));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
for (i=0 ; i < share.base.keys - uniques; i++)
|
|
|
|
|
{
|
2002-02-20 11:11:21 +01:00
|
|
|
|
uint sp_segs=(keydefs[i].flag & HA_SPATIAL) ? 2*SPDIMS : 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
|
if (mi_keydef_write(file, &keydefs[i]))
|
|
|
|
|
goto err;
|
2003-01-21 19:24:34 +01:00
|
|
|
|
for (j=0 ; j < keydefs[i].keysegs-sp_segs ; j++)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (mi_keyseg_write(file, &keydefs[i].seg[j]))
|
2002-02-20 11:11:21 +01:00
|
|
|
|
goto err;
|
2004-03-12 15:51:03 +01:00
|
|
|
|
#ifdef HAVE_SPATIAL
|
2002-02-20 11:11:21 +01:00
|
|
|
|
for (j=0 ; j < sp_segs ; j++)
|
|
|
|
|
{
|
2002-04-25 12:10:29 +02:00
|
|
|
|
HA_KEYSEG sseg;
|
2002-02-20 11:11:21 +01:00
|
|
|
|
sseg.type=SPTYPE;
|
2005-01-12 02:38:53 +01:00
|
|
|
|
sseg.language= 7; /* Binary */
|
2002-02-20 11:11:21 +01:00
|
|
|
|
sseg.null_bit=0;
|
|
|
|
|
sseg.bit_start=0;
|
|
|
|
|
sseg.bit_end=0;
|
2005-01-12 02:38:53 +01:00
|
|
|
|
sseg.bit_length= 0;
|
|
|
|
|
sseg.bit_pos= 0;
|
2002-02-20 11:11:21 +01:00
|
|
|
|
sseg.length=SPLEN;
|
|
|
|
|
sseg.null_pos=0;
|
|
|
|
|
sseg.start=j*SPLEN;
|
|
|
|
|
sseg.flag= HA_SWAP_KEY;
|
|
|
|
|
if (mi_keyseg_write(file, &sseg))
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2004-03-12 15:51:03 +01:00
|
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
/* Create extra keys for unique definitions */
|
|
|
|
|
offset=reclength-uniques*MI_UNIQUE_HASH_LENGTH;
|
|
|
|
|
bzero((char*) &tmp_keydef,sizeof(tmp_keydef));
|
|
|
|
|
bzero((char*) &tmp_keyseg,sizeof(tmp_keyseg));
|
|
|
|
|
for (i=0; i < uniques ; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp_keydef.keysegs=1;
|
|
|
|
|
tmp_keydef.flag= HA_UNIQUE_CHECK;
|
2005-06-06 18:34:52 +02:00
|
|
|
|
tmp_keydef.block_length= (uint16)myisam_block_size;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
tmp_keydef.keylength= MI_UNIQUE_HASH_LENGTH + pointer;
|
|
|
|
|
tmp_keydef.minlength=tmp_keydef.maxlength=tmp_keydef.keylength;
|
2002-07-24 21:56:33 +02:00
|
|
|
|
tmp_keyseg.type= MI_UNIQUE_HASH_TYPE;
|
|
|
|
|
tmp_keyseg.length= MI_UNIQUE_HASH_LENGTH;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
tmp_keyseg.start= offset;
|
|
|
|
|
offset+= MI_UNIQUE_HASH_LENGTH;
|
|
|
|
|
if (mi_keydef_write(file,&tmp_keydef) ||
|
|
|
|
|
mi_keyseg_write(file,(&tmp_keyseg)))
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save unique definition */
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("write unique definitions"));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
for (i=0 ; i < share.state.header.uniques ; i++)
|
|
|
|
|
{
|
2004-12-18 04:19:21 +01:00
|
|
|
|
HA_KEYSEG *keyseg_end;
|
|
|
|
|
keyseg= uniquedefs[i].seg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (mi_uniquedef_write(file, &uniquedefs[i]))
|
|
|
|
|
goto err;
|
2004-12-18 04:19:21 +01:00
|
|
|
|
for (keyseg= uniquedefs[i].seg, keyseg_end= keyseg+ uniquedefs[i].keysegs;
|
|
|
|
|
keyseg < keyseg_end;
|
|
|
|
|
keyseg++)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
{
|
2004-12-18 04:19:21 +01:00
|
|
|
|
switch (keyseg->type) {
|
|
|
|
|
case HA_KEYTYPE_VARTEXT1:
|
|
|
|
|
case HA_KEYTYPE_VARTEXT2:
|
|
|
|
|
case HA_KEYTYPE_VARBINARY1:
|
|
|
|
|
case HA_KEYTYPE_VARBINARY2:
|
|
|
|
|
if (!(keyseg->flag & HA_BLOB_PART))
|
|
|
|
|
{
|
|
|
|
|
keyseg->flag|= HA_VAR_LENGTH_PART;
|
|
|
|
|
keyseg->bit_start= ((keyseg->type == HA_KEYTYPE_VARTEXT1 ||
|
|
|
|
|
keyseg->type == HA_KEYTYPE_VARBINARY1) ?
|
|
|
|
|
1 : 2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (mi_keyseg_write(file, keyseg))
|
2000-07-31 21:29:14 +02:00
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("write field definitions"));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
for (i=0 ; i < share.base.fields ; i++)
|
|
|
|
|
if (mi_recinfo_write(file, &recinfo[i]))
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
|
if ((uint) my_tell(file,MYF(0)) != info_length)
|
|
|
|
|
{
|
|
|
|
|
uint pos= (uint) my_tell(file,MYF(0));
|
|
|
|
|
DBUG_PRINT("warning",("info_length: %d != used_length: %d",
|
|
|
|
|
info_length, pos));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Enlarge files */
|
2006-06-27 11:26:41 +02:00
|
|
|
|
DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart));
|
2002-08-08 02:12:02 +02:00
|
|
|
|
if (my_chsize(file,(ulong) share.base.keystart,0,MYF(0)))
|
2000-07-31 21:29:14 +02:00
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
if (! (flags & HA_DONT_TOUCH_DATA))
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_RELOC
|
2002-08-08 02:12:02 +02:00
|
|
|
|
if (my_chsize(dfile,share.base.min_pack_length*ci->reloc_rows,0,MYF(0)))
|
2000-07-31 21:29:14 +02:00
|
|
|
|
goto err;
|
|
|
|
|
#endif
|
|
|
|
|
errpos=2;
|
|
|
|
|
if (my_close(dfile,MYF(0)))
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
errpos=0;
|
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_myisam);
|
|
|
|
|
if (my_close(file,MYF(0)))
|
|
|
|
|
goto err;
|
2000-11-28 03:47:47 +01:00
|
|
|
|
my_free((char*) rec_per_key_part,MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_myisam);
|
|
|
|
|
save_errno=my_errno;
|
|
|
|
|
switch (errpos) {
|
|
|
|
|
case 3:
|
|
|
|
|
VOID(my_close(dfile,MYF(0)));
|
|
|
|
|
/* fall through */
|
|
|
|
|
case 2:
|
|
|
|
|
/* QQ: T<>nu should add a call to my_raid_delete() here */
|
2001-06-05 02:38:10 +02:00
|
|
|
|
if (! (flags & HA_DONT_TOUCH_DATA))
|
2005-12-31 06:01:26 +01:00
|
|
|
|
my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
|
|
|
|
|
MY_UNPACK_FILENAME | MY_APPEND_EXT),
|
2001-06-05 02:38:10 +02:00
|
|
|
|
MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
/* fall through */
|
|
|
|
|
case 1:
|
|
|
|
|
VOID(my_close(file,MYF(0)));
|
|
|
|
|
if (! (flags & HA_DONT_TOUCH_DATA))
|
2005-12-31 06:01:26 +01:00
|
|
|
|
my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
|
|
|
|
|
MY_UNPACK_FILENAME | MY_APPEND_EXT),
|
2001-06-05 02:38:10 +02:00
|
|
|
|
MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
}
|
2000-11-28 03:47:47 +01:00
|
|
|
|
my_free((char*) rec_per_key_part, MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint mi_get_pointer_length(ulonglong file_length, uint def)
|
|
|
|
|
{
|
2005-06-30 16:55:47 +02:00
|
|
|
|
DBUG_ASSERT(def >= 2 && def <= 7);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
if (file_length) /* If not default */
|
|
|
|
|
{
|
2005-06-30 16:55:47 +02:00
|
|
|
|
#ifdef NOT_YET_READY_FOR_8_BYTE_POINTERS
|
2007-01-05 10:26:51 +01:00
|
|
|
|
if (file_length >= ULL(1) << 56)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=8;
|
2007-01-05 10:26:51 +01:00
|
|
|
|
else
|
2005-06-30 16:55:47 +02:00
|
|
|
|
#endif
|
2007-01-05 10:26:51 +01:00
|
|
|
|
if (file_length >= ULL(1) << 48)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=7;
|
2007-01-05 10:26:51 +01:00
|
|
|
|
else if (file_length >= ULL(1) << 40)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=6;
|
2007-01-05 10:26:51 +01:00
|
|
|
|
else if (file_length >= ULL(1) << 32)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=5;
|
2007-01-05 10:26:51 +01:00
|
|
|
|
else if (file_length >= ULL(1) << 24)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=4;
|
2007-01-05 10:26:51 +01:00
|
|
|
|
else if (file_length >= ULL(1) << 16)
|
2000-07-31 21:29:14 +02:00
|
|
|
|
def=3;
|
|
|
|
|
else
|
|
|
|
|
def=2;
|
|
|
|
|
}
|
|
|
|
|
return def;
|
|
|
|
|
}
|