You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1774 lines
59 KiB

23 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 years ago
26 years ago
23 years ago
24 years ago
24 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
21 years ago
21 years ago
21 years ago
26 years ago
26 years ago
26 years ago
21 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
24 years ago
20 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
26 years ago
Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found per-file comments: client/mysql.cc Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysql_upgrade.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqladmin.cc Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqlcheck.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqldump.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqlimport.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqlshow.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found client/mysqlslap.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found mysql-test/t/mysql.test Bug#47216 programs should quit if the file specified by --defaults-file option isn't found test added sql/mysqld.cc Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found storage/myisam/myisamchk.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found storage/myisam/myisampack.c Bug#47216 programs should quit if the file specified by --defaults-file option isn't found added code to exit a tool if the forced config file wasn't found
16 years ago
26 years ago
26 years ago
26 years ago
24 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
24 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
24 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. test_if_data_home_dir fixed to look into real path. Checks added to mi_open for symlinks into data home directory. per-file messages: include/my_sys.h Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. my_is_symlink interface added include/myisam.h Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. myisam_test_invalid_symlink interface added myisam/mi_check.c Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. mi_open_datafile calls modified myisam/mi_open.c Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. code added to mi_open to check for symlinks into data home directory. mi_open_datafile now accepts 'original' file path to check if it's an allowed symlink. myisam/mi_static.c Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. myisam_test_invlaid_symlink defined myisam/myisamchk.c Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. mi_open_datafile call modified myisam/myisamdef.h Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. mi_open_datafile interface modified - 'real_path' parameter added mysql-test/r/symlink.test Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. error codes corrected as some patch now rejected pointing inside datahome mysql-test/r/symlink.result Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. error messages corrected in the result mysys/my_symlink.c Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. my_is_symlink() implementsd my_realpath() now returns the 'realpath' even if a file isn't a symlink sql/mysql_priv.h Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. test_if_data_home_dir interface sql/mysqld.cc Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. myisam_test_invalid_symlik set with the 'test_if_data_home_dir' sql/sql_parse.cc Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY. error messages corrected test_if_data_home_dir code fixed
17 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives.
16 years ago
26 years ago
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives.
16 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
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
19 years ago
26 years ago
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
19 years ago
26 years ago
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
19 years ago
26 years ago
22 years ago
21 years ago
22 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (C) 2000-2003 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /* Describe, check and repair of MyISAM tables */
  13. #include "fulltext.h"
  14. #include <m_ctype.h>
  15. #include <stdarg.h>
  16. #include <my_getopt.h>
  17. #include <my_bit.h>
  18. #ifdef HAVE_SYS_VADVICE_H
  19. #include <sys/vadvise.h>
  20. #endif
  21. #ifdef HAVE_SYS_MMAN_H
  22. #include <sys/mman.h>
  23. #endif
  24. static uint decode_bits;
  25. static char **default_argv;
  26. static const char *load_default_groups[]= { "myisamchk", 0 };
  27. static const char *set_collation_name, *opt_tmpdir;
  28. static CHARSET_INFO *set_collation;
  29. static long opt_myisam_block_size;
  30. static long opt_key_cache_block_size;
  31. static const char *my_progname_short;
  32. static int stopwords_inited= 0;
  33. static MY_TMPDIR myisamchk_tmpdir;
  34. static const char *type_names[]=
  35. { "impossible","char","binary", "short", "long", "float",
  36. "double","number","unsigned short",
  37. "unsigned long","longlong","ulonglong","int24",
  38. "uint24","int8","varchar", "varbin","?",
  39. "?"};
  40. static const char *prefix_packed_txt="packed ",
  41. *bin_packed_txt="prefix ",
  42. *diff_txt="stripped ",
  43. *null_txt="NULL",
  44. *blob_txt="BLOB ";
  45. static const char *field_pack[]=
  46. {"","no endspace", "no prespace",
  47. "no zeros", "blob", "constant", "table-lockup",
  48. "always zero","varchar","unique-hash","?","?"};
  49. static const char *myisam_stats_method_str="nulls_unequal";
  50. static void get_options(int *argc,char * * *argv);
  51. static void print_version(void);
  52. static void usage(void);
  53. static int myisamchk(MI_CHECK *param, char *filename);
  54. static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
  55. static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
  56. char * name, uint sort_key,
  57. my_bool write_info, my_bool update_index);
  58. static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
  59. MI_KEYDEF *keyinfo,
  60. my_off_t page,uchar *buff,uint sortkey,
  61. File new_file, my_bool update_index);
  62. MI_CHECK check_param;
  63. /* Main program */
  64. int main(int argc, char **argv)
  65. {
  66. int error;
  67. MY_INIT(argv[0]);
  68. my_progname_short= my_progname+dirname_length(my_progname);
  69. myisamchk_init(&check_param);
  70. check_param.opt_lock_memory=1; /* Lock memory if possible */
  71. check_param.using_global_keycache = 0;
  72. get_options(&argc,(char***) &argv);
  73. myisam_quick_table_bits=decode_bits;
  74. error=0;
  75. while (--argc >= 0)
  76. {
  77. int new_error=myisamchk(&check_param, *(argv++));
  78. if ((check_param.testflag & T_REP_ANY) != T_REP)
  79. check_param.testflag&= ~T_REP;
  80. (void) fflush(stdout);
  81. (void) fflush(stderr);
  82. if ((check_param.error_printed | check_param.warning_printed) &&
  83. (check_param.testflag & T_FORCE_CREATE) &&
  84. (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
  85. T_SORT_INDEX))))
  86. {
  87. uint old_testflag=check_param.testflag;
  88. if (!(check_param.testflag & T_REP))
  89. check_param.testflag|= T_REP_BY_SORT;
  90. check_param.testflag&= ~T_EXTEND; /* Don't needed */
  91. error|=myisamchk(&check_param, argv[-1]);
  92. check_param.testflag= old_testflag;
  93. (void) fflush(stdout);
  94. (void) fflush(stderr);
  95. }
  96. else
  97. error|=new_error;
  98. if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
  99. {
  100. puts("\n---------\n");
  101. (void) fflush(stdout);
  102. }
  103. }
  104. if (check_param.total_files > 1)
  105. { /* Only if descript */
  106. char buff[22],buff2[22];
  107. if (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO)
  108. puts("\n---------\n");
  109. printf("\nTotal of all %d MyISAM-files:\nData records: %9s Deleted blocks: %9s\n",check_param.total_files,llstr(check_param.total_records,buff),
  110. llstr(check_param.total_deleted,buff2));
  111. }
  112. free_defaults(default_argv);
  113. free_tmpdir(&myisamchk_tmpdir);
  114. ft_free_stopwords();
  115. my_end(check_param.testflag & T_INFO ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
  116. exit(error);
  117. #ifndef _lint
  118. return 0; /* No compiler warning */
  119. #endif
  120. } /* main */
  121. enum options_mc {
  122. OPT_CHARSETS_DIR=256, OPT_SET_COLLATION,OPT_START_CHECK_POS,
  123. OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE,
  124. OPT_KEY_CACHE_BLOCK_SIZE, OPT_MYISAM_BLOCK_SIZE,
  125. OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE,
  126. OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN,
  127. OPT_FT_MAX_WORD_LEN, OPT_FT_STOPWORD_FILE,
  128. OPT_MAX_RECORD_LENGTH, OPT_STATS_METHOD
  129. };
  130. static struct my_option my_long_options[] =
  131. {
  132. {"analyze", 'a',
  133. "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.",
  134. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  135. {"block-search", 'b',
  136. "No help available.",
  137. 0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  138. {"backup", 'B',
  139. "Make a backup of the .MYD file as 'filename-time.BAK'.",
  140. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  141. {"character-sets-dir", OPT_CHARSETS_DIR,
  142. "Directory where character sets are.",
  143. &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  144. {"check", 'c',
  145. "Check table for errors.",
  146. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  147. {"check-only-changed", 'C',
  148. "Check only tables that have changed since last check. It also applies to other requested actions (e.g. --analyze will be ignored if the table is already analyzed).",
  149. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  150. {"correct-checksum", OPT_CORRECT_CHECKSUM,
  151. "Correct checksum information for table.",
  152. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  153. #ifndef DBUG_OFF
  154. {"debug", '#',
  155. "Output debug log. Often this is 'd:t:o,filename'.",
  156. 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
  157. #endif
  158. {"description", 'd',
  159. "Prints some information about table.",
  160. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  161. {"data-file-length", 'D',
  162. "Max length of data file (when recreating data-file when it's full).",
  163. &check_param.max_data_file_length,
  164. &check_param.max_data_file_length,
  165. 0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  166. {"extend-check", 'e',
  167. "If used when checking a table, ensure that the table is 100 percent consistent, which will take a long time. If used when repairing a table, try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option with repair if you are not totally desperate.",
  168. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  169. {"fast", 'F',
  170. "Check only tables that haven't been closed properly. It also applies to other requested actions (e.g. --analyze will be ignored if the table is already analyzed).",
  171. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  172. {"force", 'f',
  173. "Restart with -r if there are any errors in the table. States will be updated as with --update-state.",
  174. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  175. {"HELP", 'H',
  176. "Display this help and exit.",
  177. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  178. {"help", '?',
  179. "Display this help and exit.",
  180. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  181. {"information", 'i',
  182. "Print statistics information about table that is checked.",
  183. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  184. {"keys-used", 'k',
  185. "Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts.",
  186. &check_param.keys_in_use,
  187. &check_param.keys_in_use,
  188. 0, GET_ULL, REQUIRED_ARG, -1, 0, 0, 0, 0, 0},
  189. {"max-record-length", OPT_MAX_RECORD_LENGTH,
  190. "Skip rows bigger than this if myisamchk can't allocate memory to hold it",
  191. &check_param.max_record_length,
  192. &check_param.max_record_length,
  193. 0, GET_ULL, REQUIRED_ARG, LONGLONG_MAX, 0, LONGLONG_MAX, 0, 0, 0},
  194. {"medium-check", 'm',
  195. "Faster than extend-check, but only finds 99.99% of all errors. Should be good enough for most cases.",
  196. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  197. {"quick", 'q', "Faster repair by not modifying the data file.",
  198. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  199. {"read-only", 'T',
  200. "Don't mark table as checked.",
  201. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  202. {"recover", 'r',
  203. "Can fix almost anything except unique keys that aren't unique.",
  204. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  205. {"parallel-recover", 'p',
  206. "Same as '-r' but creates all the keys in parallel.",
  207. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  208. {"safe-recover", 'o',
  209. "Uses old recovery method; Slower than '-r' but can handle a couple of cases where '-r' reports that it can't fix the data file.",
  210. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  211. {"sort-recover", 'n',
  212. "Force recovering with sorting even if the temporary file was very big.",
  213. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  214. #ifdef DEBUG
  215. {"start-check-pos", OPT_START_CHECK_POS,
  216. "No help available.",
  217. 0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  218. #endif
  219. {"set-auto-increment", 'A',
  220. "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
  221. &check_param.auto_increment_value,
  222. &check_param.auto_increment_value,
  223. 0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
  224. {"set-collation", OPT_SET_COLLATION,
  225. "Change the collation used by the index",
  226. &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  227. {"silent", 's',
  228. "Only print errors. One can use two -s to make myisamchk very silent.",
  229. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  230. {"sort-index", 'S',
  231. "Sort index blocks. This speeds up 'read-next' in applications.",
  232. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  233. {"sort-records", 'R',
  234. "Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)",
  235. &check_param.opt_sort_key,
  236. &check_param.opt_sort_key,
  237. 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  238. {"tmpdir", 't',
  239. "Path for temporary files.",
  240. &opt_tmpdir,
  241. 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  242. {"update-state", 'U',
  243. "Mark tables as crashed if any errors were found.",
  244. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  245. {"unpack", 'u',
  246. "Unpack file packed with myisampack.",
  247. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  248. {"verbose", 'v',
  249. "Print more information. This can be used with --description and --check. Use many -v for more verbosity!",
  250. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  251. {"version", 'V',
  252. "Print version and exit.",
  253. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  254. {"wait", 'w',
  255. "Wait if table is locked.",
  256. 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  257. { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
  258. &check_param.use_buffers, &check_param.use_buffers, 0,
  259. GET_ULL, REQUIRED_ARG, USE_BUFFER_INIT, MALLOC_OVERHEAD,
  260. SIZE_T_MAX, MALLOC_OVERHEAD, IO_SIZE, 0},
  261. { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE, "",
  262. &opt_key_cache_block_size,
  263. &opt_key_cache_block_size, 0,
  264. GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
  265. MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
  266. { "myisam_block_size", OPT_MYISAM_BLOCK_SIZE, "",
  267. &opt_myisam_block_size, &opt_myisam_block_size, 0,
  268. GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
  269. MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
  270. { "read_buffer_size", OPT_READ_BUFFER_SIZE, "",
  271. &check_param.read_buffer_length,
  272. &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
  273. (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
  274. INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0},
  275. { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
  276. &check_param.write_buffer_length,
  277. &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
  278. (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
  279. INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0},
  280. { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
  281. &check_param.sort_buffer_length,
  282. &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
  283. (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
  284. ULONG_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
  285. { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
  286. &check_param.sort_key_blocks,
  287. &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
  288. BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
  289. { "decode_bits", OPT_DECODE_BITS, "", &decode_bits,
  290. &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
  291. { "ft_min_word_len", OPT_FT_MIN_WORD_LEN, "", &ft_min_word_len,
  292. &ft_min_word_len, 0, GET_ULONG, REQUIRED_ARG, 4, 1, HA_FT_MAXCHARLEN,
  293. 0, 1, 0},
  294. { "ft_max_word_len", OPT_FT_MAX_WORD_LEN, "", &ft_max_word_len,
  295. &ft_max_word_len, 0, GET_ULONG, REQUIRED_ARG, HA_FT_MAXCHARLEN, 10,
  296. HA_FT_MAXCHARLEN, 0, 1, 0},
  297. { "ft_stopword_file", OPT_FT_STOPWORD_FILE,
  298. "Use stopwords from this file instead of built-in list.",
  299. &ft_stopword_file, &ft_stopword_file, 0, GET_STR,
  300. REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  301. {"stats_method", OPT_STATS_METHOD,
  302. "Specifies how index statistics collection code should treat NULLs. "
  303. "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
  304. "\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
  305. &myisam_stats_method_str, &myisam_stats_method_str, 0,
  306. GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  307. { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
  308. };
  309. static void print_version(void)
  310. {
  311. printf("%s Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
  312. MACHINE_TYPE);
  313. }
  314. static void usage(void)
  315. {
  316. print_version();
  317. puts("By Monty, for your professional use");
  318. puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n");
  319. puts("Description, check and repair of MyISAM tables.");
  320. puts("Used without options all tables on the command will be checked for errors");
  321. printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short);
  322. printf("\nGlobal options:\n");
  323. #ifndef DBUG_OFF
  324. printf("\
  325. -#, --debug=... Output debug log. Often this is 'd:t:o,filename'.\n");
  326. #endif
  327. printf("\
  328. -H, --HELP Display this help and exit.\n\
  329. -?, --help Display this help and exit.\n\
  330. -t, --tmpdir=path Path for temporary files. Multiple paths can be\n\
  331. specified, separated by ");
  332. #if defined( __WIN__)
  333. printf("semicolon (;)");
  334. #else
  335. printf("colon (:)");
  336. #endif
  337. printf(", they will be used\n\
  338. in a round-robin fashion.\n\
  339. -s, --silent Only print errors. One can use two -s to make\n\
  340. myisamchk very silent.\n\
  341. -v, --verbose Print more information. This can be used with\n\
  342. --description and --check. Use many -v for more verbosity.\n\
  343. -V, --version Print version and exit.\n\
  344. -w, --wait Wait if table is locked.\n\n");
  345. #ifdef DEBUG
  346. puts(" --start-check-pos=# Start reading file at given offset.\n");
  347. #endif
  348. puts("Check options (check is the default action for myisamchk):\n\
  349. -c, --check Check table for errors.\n\
  350. -e, --extend-check Check the table VERY throughly. Only use this in\n\
  351. extreme cases as myisamchk should normally be able to\n\
  352. find out if the table is ok even without this switch.\n\
  353. -F, --fast Check only tables that haven't been closed properly.\n\
  354. -C, --check-only-changed\n\
  355. Check only tables that have changed since last check.\n\
  356. -f, --force Restart with '-r' if there are any errors in the table.\n\
  357. States will be updated as with '--update-state'.\n\
  358. -i, --information Print statistics information about table that is checked.\n\
  359. -m, --medium-check Faster than extend-check, but only finds 99.99% of\n\
  360. all errors. Should be good enough for most cases.\n\
  361. -U --update-state Mark tables as crashed if you find any errors.\n\
  362. -T, --read-only Don't mark table as checked.\n");
  363. puts("Repair options (When using '-r' or '-o'):\n\
  364. -B, --backup Make a backup of the .MYD file as 'filename-time.BAK'.\n\
  365. --correct-checksum Correct checksum information for table.\n\
  366. -D, --data-file-length=# Max length of data file (when recreating data\n\
  367. file when it's full).\n\
  368. -e, --extend-check Try to recover every possible row from the data file\n\
  369. Normally this will also find a lot of garbage rows;\n\
  370. Don't use this option if you are not totally desperate.\n\
  371. -f, --force Overwrite old temporary files.\n\
  372. -k, --keys-used=# Tell MyISAM to update only some specific keys. # is a\n\
  373. bit mask of which keys to use. This can be used to\n\
  374. get faster inserts.\n\
  375. --max-record-length=#\n\
  376. Skip rows bigger than this if myisamchk can't allocate\n\
  377. memory to hold it.\n\
  378. -r, --recover Can fix almost anything except unique keys that aren't\n\
  379. unique.\n\
  380. -n, --sort-recover Forces recovering with sorting even if the temporary\n\
  381. file would be very big.\n\
  382. -p, --parallel-recover\n\
  383. Uses the same technique as '-r' and '-n', but creates\n\
  384. all the keys in parallel, in different threads.\n\
  385. -o, --safe-recover Uses old recovery method; Slower than '-r' but can\n\
  386. handle a couple of cases where '-r' reports that it\n\
  387. can't fix the data file.\n\
  388. --character-sets-dir=...\n\
  389. Directory where character sets are.\n\
  390. --set-collation=name\n\
  391. Change the collation used by the index.\n\
  392. -q, --quick Faster repair by not modifying the data file.\n\
  393. One can give a second '-q' to force myisamchk to\n\
  394. modify the original datafile in case of duplicate keys.\n\
  395. NOTE: Tables where the data file is currupted can't be\n\
  396. fixed with this option.\n\
  397. -u, --unpack Unpack file packed with myisampack.\n\
  398. ");
  399. puts("Other actions:\n\
  400. -a, --analyze Analyze distribution of keys. Will make some joins in\n\
  401. MySQL faster. You can check the calculated distribution\n\
  402. by using '--description --verbose table_name'.\n\
  403. --stats_method=name Specifies how index statistics collection code should\n\
  404. treat NULLs. Possible values of name are \"nulls_unequal\"\n\
  405. (default for 4.1/5.0), \"nulls_equal\" (emulate 4.0), and \n\
  406. \"nulls_ignored\".\n\
  407. -d, --description Prints some information about table.\n\
  408. -A, --set-auto-increment[=value]\n\
  409. Force auto_increment to start at this or higher value\n\
  410. If no value is given, then sets the next auto_increment\n\
  411. value to the highest used value for the auto key + 1.\n\
  412. -S, --sort-index Sort index blocks. This speeds up 'read-next' in\n\
  413. applications.\n\
  414. -R, --sort-records=#\n\
  415. Sort records according to an index. This makes your\n\
  416. data much more localized and may speed up things\n\
  417. (It may be VERY slow to do a sort the first time!).\n\
  418. -b, --block-search=#\n\
  419. Find a record, a block at given offset belongs to.");
  420. print_defaults("my", load_default_groups);
  421. my_print_variables(my_long_options);
  422. }
  423. const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
  424. "nulls_ignored", NullS};
  425. TYPELIB myisam_stats_method_typelib= {
  426. array_elements(myisam_stats_method_names) - 1, "",
  427. myisam_stats_method_names, NULL};
  428. /* Read options */
  429. static my_bool
  430. get_one_option(int optid,
  431. const struct my_option *opt __attribute__((unused)),
  432. char *argument)
  433. {
  434. switch (optid) {
  435. case 'a':
  436. if (argument == disabled_my_option)
  437. check_param.testflag&= ~T_STATISTICS;
  438. else
  439. check_param.testflag|= T_STATISTICS;
  440. break;
  441. case 'A':
  442. if (argument)
  443. check_param.auto_increment_value= strtoull(argument, NULL, 0);
  444. else
  445. check_param.auto_increment_value= 0; /* Set to max used value */
  446. check_param.testflag|= T_AUTO_INC;
  447. break;
  448. case 'b':
  449. check_param.search_after_block= strtoul(argument, NULL, 10);
  450. break;
  451. case 'B':
  452. if (argument == disabled_my_option)
  453. check_param.testflag&= ~T_BACKUP_DATA;
  454. else
  455. check_param.testflag|= T_BACKUP_DATA;
  456. break;
  457. case 'c':
  458. if (argument == disabled_my_option)
  459. check_param.testflag&= ~T_CHECK;
  460. else
  461. check_param.testflag|= T_CHECK;
  462. break;
  463. case 'C':
  464. if (argument == disabled_my_option)
  465. check_param.testflag&= ~(T_CHECK | T_CHECK_ONLY_CHANGED);
  466. else
  467. check_param.testflag|= T_CHECK | T_CHECK_ONLY_CHANGED;
  468. break;
  469. case 'D':
  470. check_param.max_data_file_length=strtoll(argument, NULL, 10);
  471. break;
  472. case 's': /* silent */
  473. if (argument == disabled_my_option)
  474. check_param.testflag&= ~(T_SILENT | T_VERY_SILENT);
  475. else
  476. {
  477. if (check_param.testflag & T_SILENT)
  478. check_param.testflag|= T_VERY_SILENT;
  479. check_param.testflag|= T_SILENT;
  480. check_param.testflag&= ~T_WRITE_LOOP;
  481. }
  482. break;
  483. case 'w':
  484. if (argument == disabled_my_option)
  485. check_param.testflag&= ~T_WAIT_FOREVER;
  486. else
  487. check_param.testflag|= T_WAIT_FOREVER;
  488. break;
  489. case 'd': /* description if isam-file */
  490. if (argument == disabled_my_option)
  491. check_param.testflag&= ~T_DESCRIPT;
  492. else
  493. check_param.testflag|= T_DESCRIPT;
  494. break;
  495. case 'e': /* extend check */
  496. if (argument == disabled_my_option)
  497. check_param.testflag&= ~T_EXTEND;
  498. else
  499. check_param.testflag|= T_EXTEND;
  500. break;
  501. case 'i':
  502. if (argument == disabled_my_option)
  503. check_param.testflag&= ~T_INFO;
  504. else
  505. check_param.testflag|= T_INFO;
  506. break;
  507. case 'f':
  508. if (argument == disabled_my_option)
  509. {
  510. check_param.tmpfile_createflag= O_RDWR | O_TRUNC | O_EXCL;
  511. check_param.testflag&= ~(T_FORCE_CREATE | T_UPDATE_STATE);
  512. }
  513. else
  514. {
  515. check_param.tmpfile_createflag= O_RDWR | O_TRUNC;
  516. check_param.testflag|= T_FORCE_CREATE | T_UPDATE_STATE;
  517. }
  518. break;
  519. case 'F':
  520. if (argument == disabled_my_option)
  521. check_param.testflag&= ~T_FAST;
  522. else
  523. check_param.testflag|= T_FAST;
  524. break;
  525. case 'k':
  526. check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10);
  527. break;
  528. case 'm':
  529. if (argument == disabled_my_option)
  530. check_param.testflag&= ~T_MEDIUM;
  531. else
  532. check_param.testflag|= T_MEDIUM; /* Medium check */
  533. break;
  534. case 'r': /* Repair table */
  535. check_param.testflag&= ~T_REP_ANY;
  536. if (argument != disabled_my_option)
  537. check_param.testflag|= T_REP_BY_SORT;
  538. break;
  539. case 'p':
  540. check_param.testflag&= ~T_REP_ANY;
  541. if (argument != disabled_my_option)
  542. check_param.testflag|= T_REP_PARALLEL;
  543. break;
  544. case 'o':
  545. check_param.testflag&= ~T_REP_ANY;
  546. check_param.force_sort= 0;
  547. if (argument != disabled_my_option)
  548. {
  549. check_param.testflag|= T_REP;
  550. my_disable_async_io= 1; /* More safety */
  551. }
  552. break;
  553. case 'n':
  554. check_param.testflag&= ~T_REP_ANY;
  555. if (argument == disabled_my_option)
  556. check_param.force_sort= 0;
  557. else
  558. {
  559. check_param.testflag|= T_REP_BY_SORT;
  560. check_param.force_sort= 1;
  561. }
  562. break;
  563. case 'q':
  564. if (argument == disabled_my_option)
  565. check_param.testflag&= ~(T_QUICK | T_FORCE_UNIQUENESS);
  566. else
  567. check_param.testflag|=
  568. (check_param.testflag & T_QUICK) ? T_FORCE_UNIQUENESS : T_QUICK;
  569. break;
  570. case 'u':
  571. if (argument == disabled_my_option)
  572. check_param.testflag&= ~(T_UNPACK | T_REP_BY_SORT);
  573. else
  574. check_param.testflag|= T_UNPACK | T_REP_BY_SORT;
  575. break;
  576. case 'v': /* Verbose */
  577. if (argument == disabled_my_option)
  578. {
  579. check_param.testflag&= ~T_VERBOSE;
  580. check_param.verbose=0;
  581. }
  582. else
  583. {
  584. check_param.testflag|= T_VERBOSE;
  585. check_param.verbose++;
  586. }
  587. break;
  588. case 'R': /* Sort records */
  589. if (argument == disabled_my_option)
  590. check_param.testflag&= ~T_SORT_RECORDS;
  591. else
  592. {
  593. check_param.testflag|= T_SORT_RECORDS;
  594. check_param.opt_sort_key= (uint) atoi(argument) - 1;
  595. if (check_param.opt_sort_key >= MI_MAX_KEY)
  596. {
  597. fprintf(stderr,
  598. "The value of the sort key is bigger than max key: %d.\n",
  599. MI_MAX_KEY);
  600. exit(1);
  601. }
  602. }
  603. break;
  604. case 'S': /* Sort index */
  605. if (argument == disabled_my_option)
  606. check_param.testflag&= ~T_SORT_INDEX;
  607. else
  608. check_param.testflag|= T_SORT_INDEX;
  609. break;
  610. case 'T':
  611. if (argument == disabled_my_option)
  612. check_param.testflag&= ~T_READONLY;
  613. else
  614. check_param.testflag|= T_READONLY;
  615. break;
  616. case 'U':
  617. if (argument == disabled_my_option)
  618. check_param.testflag&= ~T_UPDATE_STATE;
  619. else
  620. check_param.testflag|= T_UPDATE_STATE;
  621. break;
  622. case '#':
  623. if (argument == disabled_my_option)
  624. {
  625. DBUG_POP();
  626. }
  627. else
  628. {
  629. DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace");
  630. }
  631. break;
  632. case 'V':
  633. print_version();
  634. exit(0);
  635. case OPT_CORRECT_CHECKSUM:
  636. if (argument == disabled_my_option)
  637. check_param.testflag&= ~T_CALC_CHECKSUM;
  638. else
  639. check_param.testflag|= T_CALC_CHECKSUM;
  640. break;
  641. case OPT_STATS_METHOD:
  642. {
  643. int method;
  644. enum_mi_stats_method UNINIT_VAR(method_conv);
  645. myisam_stats_method_str= argument;
  646. if ((method=find_type(argument, &myisam_stats_method_typelib, 2)) <= 0)
  647. {
  648. fprintf(stderr, "Invalid value of stats_method: %s.\n", argument);
  649. exit(1);
  650. }
  651. switch (method-1) {
  652. case 0:
  653. method_conv= MI_STATS_METHOD_NULLS_EQUAL;
  654. break;
  655. case 1:
  656. method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
  657. break;
  658. case 2:
  659. method_conv= MI_STATS_METHOD_IGNORE_NULLS;
  660. break;
  661. default: assert(0); /* Impossible */
  662. }
  663. check_param.stats_method= method_conv;
  664. break;
  665. }
  666. #ifdef DEBUG /* Only useful if debugging */
  667. case OPT_START_CHECK_POS:
  668. check_param.start_check_pos= strtoull(argument, NULL, 0);
  669. break;
  670. #endif
  671. case 'H':
  672. my_print_help(my_long_options);
  673. exit(0);
  674. case '?':
  675. usage();
  676. exit(0);
  677. }
  678. return 0;
  679. }
  680. static void get_options(register int *argc,register char ***argv)
  681. {
  682. int ho_error;
  683. if (load_defaults("my", load_default_groups, argc, argv))
  684. exit(1);
  685. default_argv= *argv;
  686. if (isatty(fileno(stdout)))
  687. check_param.testflag|=T_WRITE_LOOP;
  688. if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
  689. exit(ho_error);
  690. /* If using repair, then update checksum if one uses --update-state */
  691. if ((check_param.testflag & T_UPDATE_STATE) &&
  692. (check_param.testflag & T_REP_ANY))
  693. check_param.testflag|= T_CALC_CHECKSUM;
  694. if (*argc == 0)
  695. {
  696. usage();
  697. exit(-1);
  698. }
  699. if ((check_param.testflag & T_UNPACK) &&
  700. (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
  701. {
  702. (void) fprintf(stderr,
  703. "%s: --unpack can't be used with --quick or --sort-records\n",
  704. my_progname_short);
  705. exit(1);
  706. }
  707. if ((check_param.testflag & T_READONLY) &&
  708. (check_param.testflag &
  709. (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
  710. T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
  711. {
  712. (void) fprintf(stderr,
  713. "%s: Can't use --readonly when repairing or sorting\n",
  714. my_progname_short);
  715. exit(1);
  716. }
  717. if (init_tmpdir(&myisamchk_tmpdir, opt_tmpdir))
  718. exit(1);
  719. check_param.tmpdir=&myisamchk_tmpdir;
  720. check_param.key_cache_block_size= opt_key_cache_block_size;
  721. if (set_collation_name)
  722. if (!(set_collation= get_charset_by_name(set_collation_name,
  723. MYF(MY_WME))))
  724. exit(1);
  725. myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size);
  726. return;
  727. } /* get options */
  728. /* Check table */
  729. static int myisamchk(MI_CHECK *param, char * filename)
  730. {
  731. int error,lock_type,recreate;
  732. int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
  733. MI_INFO *info;
  734. File datafile;
  735. char llbuff[22],llbuff2[22];
  736. my_bool state_updated=0;
  737. MYISAM_SHARE *share;
  738. DBUG_ENTER("myisamchk");
  739. param->out_flag=error=param->warning_printed=param->error_printed=
  740. recreate=0;
  741. datafile=0;
  742. param->isam_file_name=filename; /* For error messages */
  743. if (!(info=mi_open(filename,
  744. (param->testflag & (T_DESCRIPT | T_READONLY)) ?
  745. O_RDONLY : O_RDWR,
  746. HA_OPEN_FOR_REPAIR |
  747. ((param->testflag & T_WAIT_FOREVER) ?
  748. HA_OPEN_WAIT_IF_LOCKED :
  749. (param->testflag & T_DESCRIPT) ?
  750. HA_OPEN_IGNORE_IF_LOCKED : HA_OPEN_ABORT_IF_LOCKED))))
  751. {
  752. /* Avoid twice printing of isam file name */
  753. param->error_printed=1;
  754. switch (my_errno) {
  755. case HA_ERR_CRASHED:
  756. mi_check_print_error(param,"'%s' doesn't have a correct index definition. You need to recreate it before you can do a repair",filename);
  757. break;
  758. case HA_ERR_NOT_A_TABLE:
  759. mi_check_print_error(param,"'%s' is not a MyISAM-table",filename);
  760. break;
  761. case HA_ERR_CRASHED_ON_USAGE:
  762. mi_check_print_error(param,"'%s' is marked as crashed",filename);
  763. break;
  764. case HA_ERR_CRASHED_ON_REPAIR:
  765. mi_check_print_error(param,"'%s' is marked as crashed after last repair",filename);
  766. break;
  767. case HA_ERR_OLD_FILE:
  768. mi_check_print_error(param,"'%s' is an old type of MyISAM-table", filename);
  769. break;
  770. case HA_ERR_END_OF_FILE:
  771. mi_check_print_error(param,"Couldn't read complete header from '%s'", filename);
  772. break;
  773. case EAGAIN:
  774. mi_check_print_error(param,"'%s' is locked. Use -w to wait until unlocked",filename);
  775. break;
  776. case ENOENT:
  777. mi_check_print_error(param,"File '%s' doesn't exist",filename);
  778. break;
  779. case EACCES:
  780. mi_check_print_error(param,"You don't have permission to use '%s'",filename);
  781. break;
  782. default:
  783. mi_check_print_error(param,"%d when opening MyISAM-table '%s'",
  784. my_errno,filename);
  785. break;
  786. }
  787. DBUG_RETURN(1);
  788. }
  789. share=info->s;
  790. share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
  791. share->tot_locks-= share->r_locks;
  792. share->r_locks=0;
  793. /*
  794. Skip the checking of the file if:
  795. We are using --fast and the table is closed properly
  796. We are using --check-only-changed-tables and the table hasn't changed
  797. */
  798. if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
  799. {
  800. my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
  801. if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
  802. ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
  803. STATE_CRASHED_ON_REPAIR) ||
  804. !(param->testflag & T_CHECK_ONLY_CHANGED))))
  805. need_to_check=1;
  806. if (info->s->base.keys && info->state->records)
  807. {
  808. if ((param->testflag & T_STATISTICS) &&
  809. (share->state.changed & STATE_NOT_ANALYZED))
  810. need_to_check=1;
  811. if ((param->testflag & T_SORT_INDEX) &&
  812. (share->state.changed & STATE_NOT_SORTED_PAGES))
  813. need_to_check=1;
  814. if ((param->testflag & T_REP_BY_SORT) &&
  815. (share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
  816. need_to_check=1;
  817. }
  818. if ((param->testflag & T_CHECK_ONLY_CHANGED) &&
  819. (share->state.changed & (STATE_CHANGED | STATE_CRASHED |
  820. STATE_CRASHED_ON_REPAIR)))
  821. need_to_check=1;
  822. if (!need_to_check)
  823. {
  824. if (!(param->testflag & T_SILENT) || param->testflag & T_INFO)
  825. printf("MyISAM file: %s is already checked\n",filename);
  826. if (mi_close(info))
  827. {
  828. mi_check_print_error(param,"%d when closing MyISAM-table '%s'",
  829. my_errno,filename);
  830. DBUG_RETURN(1);
  831. }
  832. DBUG_RETURN(0);
  833. }
  834. }
  835. if ((param->testflag & (T_REP_ANY | T_STATISTICS |
  836. T_SORT_RECORDS | T_SORT_INDEX)) &&
  837. (((param->testflag & T_UNPACK) &&
  838. share->data_file_type == COMPRESSED_RECORD) ||
  839. mi_uint2korr(share->state.header.state_info_length) !=
  840. MI_STATE_INFO_SIZE ||
  841. mi_uint2korr(share->state.header.base_info_length) !=
  842. MI_BASE_INFO_SIZE ||
  843. mi_is_any_intersect_keys_active(param->keys_in_use, share->base.keys,
  844. ~share->state.key_map) ||
  845. test_if_almost_full(info) ||
  846. info->s->state.header.file_version[3] != myisam_file_magic[3] ||
  847. (set_collation &&
  848. set_collation->number != share->state.header.language) ||
  849. myisam_block_size != MI_KEY_BLOCK_LENGTH))
  850. {
  851. if (set_collation)
  852. param->language= set_collation->number;
  853. if (recreate_table(param, &info,filename))
  854. {
  855. (void) fprintf(stderr,
  856. "MyISAM-table '%s' is not fixed because of errors\n",
  857. filename);
  858. return(-1);
  859. }
  860. recreate=1;
  861. if (!(param->testflag & T_REP_ANY))
  862. {
  863. param->testflag|=T_REP_BY_SORT; /* if only STATISTICS */
  864. if (!(param->testflag & T_SILENT))
  865. printf("- '%s' has old table-format. Recreating index\n",filename);
  866. rep_quick|=T_QUICK;
  867. }
  868. share=info->s;
  869. share->tot_locks-= share->r_locks;
  870. share->r_locks=0;
  871. }
  872. if (param->testflag & T_DESCRIPT)
  873. {
  874. param->total_files++;
  875. param->total_records+=info->state->records;
  876. param->total_deleted+=info->state->del;
  877. descript(param, info, filename);
  878. }
  879. else
  880. {
  881. if (!stopwords_inited++)
  882. ft_init_stopwords();
  883. if (!(param->testflag & T_READONLY))
  884. lock_type = F_WRLCK; /* table is changed */
  885. else
  886. lock_type= F_RDLCK;
  887. if (info->lock_type == F_RDLCK)
  888. info->lock_type=F_UNLCK; /* Read only table */
  889. if (_mi_readinfo(info,lock_type,0))
  890. {
  891. mi_check_print_error(param,"Can't lock indexfile of '%s', error: %d",
  892. filename,my_errno);
  893. param->error_printed=0;
  894. goto end2;
  895. }
  896. /*
  897. _mi_readinfo() has locked the table.
  898. We mark the table as locked (without doing file locks) to be able to
  899. use functions that only works on locked tables (like row caching).
  900. */
  901. mi_lock_database(info, F_EXTRA_LCK);
  902. datafile=info->dfile;
  903. if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
  904. {
  905. if (param->testflag & T_REP_ANY)
  906. {
  907. ulonglong tmp=share->state.key_map;
  908. mi_copy_keys_active(share->state.key_map, share->base.keys,
  909. param->keys_in_use);
  910. if (tmp != share->state.key_map)
  911. info->update|=HA_STATE_CHANGED;
  912. }
  913. if (rep_quick && chk_del(param, info, param->testflag & ~T_VERBOSE))
  914. {
  915. if (param->testflag & T_FORCE_CREATE)
  916. {
  917. rep_quick=0;
  918. mi_check_print_info(param,"Creating new data file\n");
  919. }
  920. else
  921. {
  922. error=1;
  923. mi_check_print_error(param,
  924. "Quick-recover aborted; Run recovery without switch 'q'");
  925. }
  926. }
  927. if (!error)
  928. {
  929. if ((param->testflag & (T_REP_BY_SORT | T_REP_PARALLEL)) &&
  930. (mi_is_any_key_active(share->state.key_map) ||
  931. (rep_quick && !param->keys_in_use && !recreate)) &&
  932. mi_test_if_sort_rep(info, info->state->records,
  933. info->s->state.key_map,
  934. param->force_sort))
  935. {
  936. if (param->testflag & T_REP_BY_SORT)
  937. error=mi_repair_by_sort(param,info,filename,rep_quick);
  938. else
  939. error=mi_repair_parallel(param,info,filename,rep_quick);
  940. state_updated=1;
  941. }
  942. else if (param->testflag & T_REP_ANY)
  943. error=mi_repair(param, info,filename,rep_quick);
  944. }
  945. if (!error && param->testflag & T_SORT_RECORDS)
  946. {
  947. /*
  948. The data file is nowadays reopened in the repair code so we should
  949. soon remove the following reopen-code
  950. */
  951. #ifndef TO_BE_REMOVED
  952. if (param->out_flag & O_NEW_DATA)
  953. { /* Change temp file to org file */
  954. (void) my_close(info->dfile,MYF(MY_WME)); /* Close new file */
  955. error|=change_to_newfile(filename, MI_NAME_DEXT, DATA_TMP_EXT, MYF(0));
  956. if (mi_open_datafile(info,info->s, NULL, -1))
  957. error=1;
  958. param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
  959. param->read_cache.file=info->dfile;
  960. }
  961. #endif
  962. if (! error)
  963. {
  964. uint key;
  965. /*
  966. We can't update the index in mi_sort_records if we have a
  967. prefix compressed or fulltext index
  968. */
  969. my_bool update_index=1;
  970. for (key=0 ; key < share->base.keys; key++)
  971. if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
  972. update_index=0;
  973. error=mi_sort_records(param,info,filename,param->opt_sort_key,
  974. /* what is the following parameter for ? */
  975. (my_bool) !(param->testflag & T_REP),
  976. update_index);
  977. datafile=info->dfile; /* This is now locked */
  978. if (!error && !update_index)
  979. {
  980. if (param->verbose)
  981. puts("Table had a compressed index; We must now recreate the index");
  982. error=mi_repair_by_sort(param,info,filename,1);
  983. }
  984. }
  985. }
  986. if (!error && param->testflag & T_SORT_INDEX)
  987. error=mi_sort_index(param,info,filename);
  988. if (!error)
  989. share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
  990. STATE_CRASHED_ON_REPAIR);
  991. else
  992. mi_mark_crashed(info);
  993. }
  994. else if ((param->testflag & T_CHECK) || !(param->testflag & T_AUTO_INC))
  995. {
  996. if (!(param->testflag & T_SILENT) || param->testflag & T_INFO)
  997. printf("Checking MyISAM file: %s\n",filename);
  998. if (!(param->testflag & T_SILENT))
  999. printf("Data records: %7s Deleted blocks: %7s\n",
  1000. llstr(info->state->records,llbuff),
  1001. llstr(info->state->del,llbuff2));
  1002. error =chk_status(param,info);
  1003. mi_intersect_keys_active(share->state.key_map, param->keys_in_use);
  1004. error =chk_size(param,info);
  1005. if (!error || !(param->testflag & (T_FAST | T_FORCE_CREATE)))
  1006. error|=chk_del(param, info,param->testflag);
  1007. if ((!error || (!(param->testflag & (T_FAST | T_FORCE_CREATE)) &&
  1008. !param->start_check_pos)))
  1009. {
  1010. error|=chk_key(param, info);
  1011. if (!error && (param->testflag & (T_STATISTICS | T_AUTO_INC)))
  1012. error=update_state_info(param, info,
  1013. ((param->testflag & T_STATISTICS) ?
  1014. UPDATE_STAT : 0) |
  1015. ((param->testflag & T_AUTO_INC) ?
  1016. UPDATE_AUTO_INC : 0));
  1017. }
  1018. if ((!rep_quick && !error) ||
  1019. !(param->testflag & (T_FAST | T_FORCE_CREATE)))
  1020. {
  1021. if (param->testflag & (T_EXTEND | T_MEDIUM))
  1022. (void) init_key_cache(dflt_key_cache,opt_key_cache_block_size,
  1023. param->use_buffers, 0, 0);
  1024. (void) init_io_cache(&param->read_cache,datafile,
  1025. (uint) param->read_buffer_length,
  1026. READ_CACHE,
  1027. (param->start_check_pos ?
  1028. param->start_check_pos :
  1029. share->pack.header_length),
  1030. 1,
  1031. MYF(MY_WME));
  1032. lock_memory(param);
  1033. if ((info->s->options & (HA_OPTION_PACK_RECORD |
  1034. HA_OPTION_COMPRESS_RECORD)) ||
  1035. (param->testflag & (T_EXTEND | T_MEDIUM)))
  1036. error|=chk_data_link(param, info, param->testflag & T_EXTEND);
  1037. error|=flush_blocks(param, share->key_cache, share->kfile);
  1038. (void) end_io_cache(&param->read_cache);
  1039. }
  1040. if (!error)
  1041. {
  1042. if ((share->state.changed & STATE_CHANGED) &&
  1043. (param->testflag & T_UPDATE_STATE))
  1044. info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
  1045. share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
  1046. STATE_CRASHED_ON_REPAIR);
  1047. }
  1048. else if (!mi_is_crashed(info) &&
  1049. (param->testflag & T_UPDATE_STATE))
  1050. { /* Mark crashed */
  1051. mi_mark_crashed(info);
  1052. info->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
  1053. }
  1054. }
  1055. }
  1056. if ((param->testflag & T_AUTO_INC) ||
  1057. ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
  1058. update_auto_increment_key(param, info,
  1059. (my_bool) !test(param->testflag & T_AUTO_INC));
  1060. if (!(param->testflag & T_DESCRIPT))
  1061. {
  1062. if (info->update & HA_STATE_CHANGED && ! (param->testflag & T_READONLY))
  1063. error|=update_state_info(param, info,
  1064. UPDATE_OPEN_COUNT |
  1065. (((param->testflag & T_REP_ANY) ?
  1066. UPDATE_TIME : 0) |
  1067. (state_updated ? UPDATE_STAT : 0) |
  1068. ((param->testflag & T_SORT_RECORDS) ?
  1069. UPDATE_SORT : 0)));
  1070. (void) lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename);
  1071. info->update&= ~HA_STATE_CHANGED;
  1072. }
  1073. mi_lock_database(info, F_UNLCK);
  1074. end2:
  1075. if (mi_close(info))
  1076. {
  1077. mi_check_print_error(param,"%d when closing MyISAM-table '%s'",my_errno,filename);
  1078. DBUG_RETURN(1);
  1079. }
  1080. if (error == 0)
  1081. {
  1082. if (param->out_flag & O_NEW_DATA)
  1083. error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT,
  1084. ((param->testflag & T_BACKUP_DATA) ?
  1085. MYF(MY_REDEL_MAKE_BACKUP) : MYF(0)));
  1086. if (param->out_flag & O_NEW_INDEX)
  1087. error|=change_to_newfile(filename, MI_NAME_IEXT, INDEX_TMP_EXT, MYF(0));
  1088. }
  1089. (void) fflush(stdout); (void) fflush(stderr);
  1090. if (param->error_printed)
  1091. {
  1092. if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
  1093. {
  1094. (void) fprintf(stderr,
  1095. "MyISAM-table '%s' is not fixed because of errors\n",
  1096. filename);
  1097. if (param->testflag & T_REP_ANY)
  1098. (void) fprintf(stderr,
  1099. "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
  1100. }
  1101. else if (!(param->error_printed & 2) &&
  1102. !(param->testflag & T_FORCE_CREATE))
  1103. (void) fprintf(stderr,
  1104. "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
  1105. filename);
  1106. }
  1107. else if (param->warning_printed &&
  1108. ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
  1109. T_FORCE_CREATE)))
  1110. (void) fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
  1111. filename);
  1112. (void) fflush(stderr);
  1113. DBUG_RETURN(error);
  1114. } /* myisamchk */
  1115. /* Write info about table */
  1116. static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
  1117. {
  1118. uint key,keyseg_nr,field,start;
  1119. reg3 MI_KEYDEF *keyinfo;
  1120. reg2 HA_KEYSEG *keyseg;
  1121. reg4 const char *text;
  1122. char buff[160],length[10],*pos,*end;
  1123. enum en_fieldtype type;
  1124. MYISAM_SHARE *share=info->s;
  1125. char llbuff[22],llbuff2[22];
  1126. DBUG_ENTER("describe");
  1127. printf("\nMyISAM file: %s\n",name);
  1128. fputs("Record format: ",stdout);
  1129. if (share->options & HA_OPTION_COMPRESS_RECORD)
  1130. puts("Compressed");
  1131. else if (share->options & HA_OPTION_PACK_RECORD)
  1132. puts("Packed");
  1133. else
  1134. puts("Fixed length");
  1135. printf("Character set: %s (%d)\n",
  1136. get_charset_name(share->state.header.language),
  1137. share->state.header.language);
  1138. if (param->testflag & T_VERBOSE)
  1139. {
  1140. printf("File-version: %d\n",
  1141. (int) share->state.header.file_version[3]);
  1142. if (share->state.create_time)
  1143. {
  1144. get_date(buff,1,share->state.create_time);
  1145. printf("Creation time: %s\n",buff);
  1146. }
  1147. if (share->state.check_time)
  1148. {
  1149. get_date(buff,1,share->state.check_time);
  1150. printf("Recover time: %s\n",buff);
  1151. }
  1152. pos=buff;
  1153. if (share->state.changed & STATE_CRASHED)
  1154. strmov(buff,"crashed");
  1155. else
  1156. {
  1157. if (share->state.open_count)
  1158. pos=strmov(pos,"open,");
  1159. if (share->state.changed & STATE_CHANGED)
  1160. pos=strmov(pos,"changed,");
  1161. else
  1162. pos=strmov(pos,"checked,");
  1163. if (!(share->state.changed & STATE_NOT_ANALYZED))
  1164. pos=strmov(pos,"analyzed,");
  1165. if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
  1166. pos=strmov(pos,"optimized keys,");
  1167. if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
  1168. pos=strmov(pos,"sorted index pages,");
  1169. pos[-1]=0; /* Remove extra ',' */
  1170. }
  1171. printf("Status: %s\n",buff);
  1172. if (share->base.auto_key)
  1173. {
  1174. printf("Auto increment key: %13d Last value: %13s\n",
  1175. share->base.auto_key,
  1176. llstr(share->state.auto_increment,llbuff));
  1177. }
  1178. if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
  1179. printf("Checksum: %23s\n",llstr(info->state->checksum,llbuff));
  1180. if (share->options & HA_OPTION_DELAY_KEY_WRITE)
  1181. printf("Keys are only flushed at close\n");
  1182. }
  1183. printf("Data records: %13s Deleted blocks: %13s\n",
  1184. llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
  1185. if (param->testflag & T_SILENT)
  1186. DBUG_VOID_RETURN; /* This is enough */
  1187. if (param->testflag & T_VERBOSE)
  1188. {
  1189. #ifdef USE_RELOC
  1190. printf("Init-relocation: %13s\n",llstr(share->base.reloc,llbuff));
  1191. #endif
  1192. printf("Datafile parts: %13s Deleted data: %13s\n",
  1193. llstr(share->state.split,llbuff),
  1194. llstr(info->state->empty,llbuff2));
  1195. printf("Datafile pointer (bytes):%9d Keyfile pointer (bytes):%9d\n",
  1196. share->rec_reflength,share->base.key_reflength);
  1197. printf("Datafile length: %13s Keyfile length: %13s\n",
  1198. llstr(info->state->data_file_length,llbuff),
  1199. llstr(info->state->key_file_length,llbuff2));
  1200. if (info->s->base.reloc == 1L && info->s->base.records == 1L)
  1201. puts("This is a one-record table");
  1202. else
  1203. {
  1204. if (share->base.max_data_file_length != HA_OFFSET_ERROR ||
  1205. share->base.max_key_file_length != HA_OFFSET_ERROR)
  1206. printf("Max datafile length: %13s Max keyfile length: %13s\n",
  1207. llstr(share->base.max_data_file_length-1,llbuff),
  1208. ullstr(share->base.max_key_file_length - 1, llbuff2));
  1209. }
  1210. }
  1211. printf("Recordlength: %13d\n",(int) share->base.pack_reclength);
  1212. if (! mi_is_all_keys_active(share->state.key_map, share->base.keys))
  1213. {
  1214. longlong2str(share->state.key_map,buff,2);
  1215. printf("Using only keys '%s' of %d possibly keys\n",
  1216. buff, share->base.keys);
  1217. }
  1218. puts("\ntable description:");
  1219. printf("Key Start Len Index Type");
  1220. if (param->testflag & T_VERBOSE)
  1221. printf(" Rec/key Root Blocksize");
  1222. (void) putchar('\n');
  1223. for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
  1224. key < share->base.keys;
  1225. key++,keyinfo++)
  1226. {
  1227. keyseg=keyinfo->seg;
  1228. if (keyinfo->flag & HA_NOSAME) text="unique ";
  1229. else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
  1230. else text="multip.";
  1231. pos=buff;
  1232. if (keyseg->flag & HA_REVERSE_SORT)
  1233. *pos++ = '-';
  1234. pos=strmov(pos,type_names[keyseg->type]);
  1235. *pos++ = ' ';
  1236. *pos=0;
  1237. if (keyinfo->flag & HA_PACK_KEY)
  1238. pos=strmov(pos,prefix_packed_txt);
  1239. if (keyinfo->flag & HA_BINARY_PACK_KEY)
  1240. pos=strmov(pos,bin_packed_txt);
  1241. if (keyseg->flag & HA_SPACE_PACK)
  1242. pos=strmov(pos,diff_txt);
  1243. if (keyseg->flag & HA_BLOB_PART)
  1244. pos=strmov(pos,blob_txt);
  1245. if (keyseg->flag & HA_NULL_PART)
  1246. pos=strmov(pos,null_txt);
  1247. *pos=0;
  1248. printf("%-4d%-6ld%-3d %-8s%-21s",
  1249. key+1,(long) keyseg->start+1,keyseg->length,text,buff);
  1250. if (share->state.key_root[key] != HA_OFFSET_ERROR)
  1251. llstr(share->state.key_root[key],buff);
  1252. else
  1253. buff[0]=0;
  1254. if (param->testflag & T_VERBOSE)
  1255. printf("%11lu %12s %10d",
  1256. share->state.rec_per_key_part[keyseg_nr++],
  1257. buff,keyinfo->block_length);
  1258. (void) putchar('\n');
  1259. while ((++keyseg)->type != HA_KEYTYPE_END)
  1260. {
  1261. pos=buff;
  1262. if (keyseg->flag & HA_REVERSE_SORT)
  1263. *pos++ = '-';
  1264. pos=strmov(pos,type_names[keyseg->type]);
  1265. *pos++= ' ';
  1266. if (keyseg->flag & HA_SPACE_PACK)
  1267. pos=strmov(pos,diff_txt);
  1268. if (keyseg->flag & HA_BLOB_PART)
  1269. pos=strmov(pos,blob_txt);
  1270. if (keyseg->flag & HA_NULL_PART)
  1271. pos=strmov(pos,null_txt);
  1272. *pos=0;
  1273. printf(" %-6ld%-3d %-21s",
  1274. (long) keyseg->start+1,keyseg->length,buff);
  1275. if (param->testflag & T_VERBOSE)
  1276. printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
  1277. (void) putchar('\n');
  1278. }
  1279. keyseg++;
  1280. }
  1281. if (share->state.header.uniques)
  1282. {
  1283. MI_UNIQUEDEF *uniqueinfo;
  1284. puts("\nUnique Key Start Len Nullpos Nullbit Type");
  1285. for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
  1286. key < share->state.header.uniques; key++, uniqueinfo++)
  1287. {
  1288. my_bool new_row=0;
  1289. char null_bit[8],null_pos[8];
  1290. printf("%-8d%-5d",key+1,uniqueinfo->key+1);
  1291. for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
  1292. {
  1293. if (new_row)
  1294. fputs(" ",stdout);
  1295. null_bit[0]=null_pos[0]=0;
  1296. if (keyseg->null_bit)
  1297. {
  1298. sprintf(null_bit,"%d",keyseg->null_bit);
  1299. sprintf(null_pos,"%ld",(long) keyseg->null_pos+1);
  1300. }
  1301. printf("%-7ld%-5d%-9s%-10s%-30s\n",
  1302. (long) keyseg->start+1,keyseg->length,
  1303. null_pos,null_bit,
  1304. type_names[keyseg->type]);
  1305. new_row=1;
  1306. }
  1307. }
  1308. }
  1309. if (param->verbose > 1)
  1310. {
  1311. char null_bit[8],null_pos[8];
  1312. printf("\nField Start Length Nullpos Nullbit Type");
  1313. if (share->options & HA_OPTION_COMPRESS_RECORD)
  1314. printf(" Huff tree Bits");
  1315. (void) putchar('\n');
  1316. start=1;
  1317. for (field=0 ; field < share->base.fields ; field++)
  1318. {
  1319. if (share->options & HA_OPTION_COMPRESS_RECORD)
  1320. type=share->rec[field].base_type;
  1321. else
  1322. type=(enum en_fieldtype) share->rec[field].type;
  1323. end=strmov(buff,field_pack[type]);
  1324. if (share->options & HA_OPTION_COMPRESS_RECORD)
  1325. {
  1326. if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
  1327. end=strmov(end,", not_always");
  1328. if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
  1329. end=strmov(end,", no empty");
  1330. if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
  1331. {
  1332. sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
  1333. end=strend(end);
  1334. }
  1335. }
  1336. if (buff[0] == ',')
  1337. strmov(buff,buff+2);
  1338. int10_to_str((long) share->rec[field].length,length,10);
  1339. null_bit[0]=null_pos[0]=0;
  1340. if (share->rec[field].null_bit)
  1341. {
  1342. sprintf(null_bit,"%d",share->rec[field].null_bit);
  1343. sprintf(null_pos,"%d",share->rec[field].null_pos+1);
  1344. }
  1345. printf("%-6d%-6d%-7s%-8s%-8s%-35s",field+1,start,length,
  1346. null_pos, null_bit, buff);
  1347. if (share->options & HA_OPTION_COMPRESS_RECORD)
  1348. {
  1349. if (share->rec[field].huff_tree)
  1350. printf("%3d %2d",
  1351. (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
  1352. share->rec[field].huff_tree->quick_table_bits);
  1353. }
  1354. (void) putchar('\n');
  1355. start+=share->rec[field].length;
  1356. }
  1357. }
  1358. DBUG_VOID_RETURN;
  1359. } /* describe */
  1360. /* Sort records according to one key */
  1361. static int mi_sort_records(MI_CHECK *param,
  1362. register MI_INFO *info, char * name,
  1363. uint sort_key,
  1364. my_bool write_info,
  1365. my_bool update_index)
  1366. {
  1367. int got_error;
  1368. uint key;
  1369. MI_KEYDEF *keyinfo;
  1370. File new_file;
  1371. uchar *temp_buff;
  1372. ha_rows old_record_count;
  1373. MYISAM_SHARE *share=info->s;
  1374. char llbuff[22],llbuff2[22];
  1375. SORT_INFO sort_info;
  1376. MI_SORT_PARAM sort_param;
  1377. DBUG_ENTER("sort_records");
  1378. bzero((char*)&sort_info,sizeof(sort_info));
  1379. bzero((char*)&sort_param,sizeof(sort_param));
  1380. sort_param.sort_info=&sort_info;
  1381. sort_info.param=param;
  1382. keyinfo= &share->keyinfo[sort_key];
  1383. got_error=1;
  1384. temp_buff=0;
  1385. new_file= -1;
  1386. if (! mi_is_key_active(share->state.key_map, sort_key))
  1387. {
  1388. mi_check_print_warning(param,
  1389. "Can't sort table '%s' on key %d; No such key",
  1390. name,sort_key+1);
  1391. param->error_printed=0;
  1392. DBUG_RETURN(0); /* Nothing to do */
  1393. }
  1394. if (keyinfo->flag & HA_FULLTEXT)
  1395. {
  1396. mi_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
  1397. name,sort_key+1);
  1398. param->error_printed=0;
  1399. DBUG_RETURN(0); /* Nothing to do */
  1400. }
  1401. if (share->data_file_type == COMPRESSED_RECORD)
  1402. {
  1403. mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
  1404. param->error_printed=0;
  1405. DBUG_RETURN(0); /* Nothing to do */
  1406. }
  1407. if (!(param->testflag & T_SILENT))
  1408. {
  1409. printf("- Sorting records for MyISAM-table '%s'\n",name);
  1410. if (write_info)
  1411. printf("Data records: %9s Deleted: %9s\n",
  1412. llstr(info->state->records,llbuff),
  1413. llstr(info->state->del,llbuff2));
  1414. }
  1415. if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
  1416. DBUG_RETURN(0); /* Nothing to do */
  1417. init_key_cache(dflt_key_cache, opt_key_cache_block_size,
  1418. (size_t) param->use_buffers, 0, 0);
  1419. if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length,
  1420. WRITE_CACHE,share->pack.header_length,1,
  1421. MYF(MY_WME | MY_WAIT_IF_FULL)))
  1422. goto err;
  1423. info->opt_flag|=WRITE_CACHE_USED;
  1424. if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
  1425. {
  1426. mi_check_print_error(param,"Not enough memory for key block");
  1427. goto err;
  1428. }
  1429. if (!mi_alloc_rec_buff(info, -1, &sort_param.record))
  1430. {
  1431. mi_check_print_error(param,"Not enough memory for record");
  1432. goto err;
  1433. }
  1434. fn_format(param->temp_filename,name,"", MI_NAME_DEXT,2+4+32);
  1435. new_file= my_create(fn_format(param->temp_filename,
  1436. param->temp_filename, "",
  1437. DATA_TMP_EXT, 2+4),
  1438. 0, param->tmpfile_createflag,
  1439. MYF(0));
  1440. if (new_file < 0)
  1441. {
  1442. mi_check_print_error(param,"Can't create new tempfile: '%s'",
  1443. param->temp_filename);
  1444. goto err;
  1445. }
  1446. if (share->pack.header_length)
  1447. if (filecopy(param,new_file,info->dfile,0L,share->pack.header_length,
  1448. "datafile-header"))
  1449. goto err;
  1450. info->rec_cache.file=new_file; /* Use this file for cacheing*/
  1451. lock_memory(param);
  1452. for (key=0 ; key < share->base.keys ; key++)
  1453. share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
  1454. if (my_pread(share->kfile,(uchar*) temp_buff,
  1455. (uint) keyinfo->block_length,
  1456. share->state.key_root[sort_key],
  1457. MYF(MY_NABP+MY_WME)))
  1458. {
  1459. mi_check_print_error(param,"Can't read indexpage from filepos: %s",
  1460. (ulong) share->state.key_root[sort_key]);
  1461. goto err;
  1462. }
  1463. /* Setup param for sort_write_record */
  1464. sort_info.info=info;
  1465. sort_info.new_data_file_type=share->data_file_type;
  1466. sort_param.fix_datafile=1;
  1467. sort_param.master=1;
  1468. sort_param.filepos=share->pack.header_length;
  1469. old_record_count=info->state->records;
  1470. info->state->records=0;
  1471. if (sort_info.new_data_file_type != COMPRESSED_RECORD)
  1472. info->state->checksum=0;
  1473. if (sort_record_index(&sort_param,info,keyinfo,share->state.key_root[sort_key],
  1474. temp_buff, sort_key,new_file,update_index) ||
  1475. write_data_suffix(&sort_info,1) ||
  1476. flush_io_cache(&info->rec_cache))
  1477. goto err;
  1478. if (info->state->records != old_record_count)
  1479. {
  1480. mi_check_print_error(param,"found %s of %s records",
  1481. llstr(info->state->records,llbuff),
  1482. llstr(old_record_count,llbuff2));
  1483. goto err;
  1484. }
  1485. (void) my_close(info->dfile,MYF(MY_WME));
  1486. param->out_flag|=O_NEW_DATA; /* Data in new file */
  1487. info->dfile=new_file; /* Use new datafile */
  1488. info->state->del=0;
  1489. info->state->empty=0;
  1490. share->state.dellink= HA_OFFSET_ERROR;
  1491. info->state->data_file_length=sort_param.filepos;
  1492. share->state.split=info->state->records; /* Only hole records */
  1493. share->state.version=(ulong) time((time_t*) 0);
  1494. info->update= (short) (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
  1495. if (param->testflag & T_WRITE_LOOP)
  1496. {
  1497. (void) fputs(" \r",stdout); (void) fflush(stdout);
  1498. }
  1499. got_error=0;
  1500. err:
  1501. if (got_error && new_file >= 0)
  1502. {
  1503. (void) end_io_cache(&info->rec_cache);
  1504. (void) my_close(new_file,MYF(MY_WME));
  1505. (void) my_delete(param->temp_filename, MYF(MY_WME));
  1506. }
  1507. if (temp_buff)
  1508. {
  1509. my_afree((uchar*) temp_buff);
  1510. }
  1511. my_free(mi_get_rec_buff_ptr(info, sort_param.record));
  1512. info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
  1513. (void) end_io_cache(&info->rec_cache);
  1514. my_free(sort_info.buff);
  1515. sort_info.buff=0;
  1516. share->state.sortkey=sort_key;
  1517. DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) |
  1518. got_error);
  1519. } /* sort_records */
  1520. /* Sort records recursive using one index */
  1521. static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
  1522. MI_KEYDEF *keyinfo,
  1523. my_off_t page, uchar *buff, uint sort_key,
  1524. File new_file,my_bool update_index)
  1525. {
  1526. uint nod_flag,used_length,key_length;
  1527. uchar *temp_buff,*keypos,*endpos;
  1528. my_off_t next_page,rec_pos;
  1529. uchar lastkey[MI_MAX_KEY_BUFF];
  1530. char llbuff[22];
  1531. SORT_INFO *sort_info= sort_param->sort_info;
  1532. MI_CHECK *param=sort_info->param;
  1533. DBUG_ENTER("sort_record_index");
  1534. nod_flag=mi_test_if_nod(buff);
  1535. temp_buff=0;
  1536. if (nod_flag)
  1537. {
  1538. if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
  1539. {
  1540. mi_check_print_error(param,"Not Enough memory");
  1541. DBUG_RETURN(-1);
  1542. }
  1543. }
  1544. used_length=mi_getint(buff);
  1545. keypos=buff+2+nod_flag;
  1546. endpos=buff+used_length;
  1547. for ( ;; )
  1548. {
  1549. if (nod_flag)
  1550. {
  1551. next_page=_mi_kpos(nod_flag,keypos);
  1552. if (my_pread(info->s->kfile,(uchar*) temp_buff,
  1553. (uint) keyinfo->block_length, next_page,
  1554. MYF(MY_NABP+MY_WME)))
  1555. {
  1556. mi_check_print_error(param,"Can't read keys from filepos: %s",
  1557. llstr(next_page,llbuff));
  1558. goto err;
  1559. }
  1560. if (sort_record_index(sort_param, info,keyinfo,next_page,temp_buff,sort_key,
  1561. new_file, update_index))
  1562. goto err;
  1563. }
  1564. if (keypos >= endpos ||
  1565. (key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,lastkey))
  1566. == 0)
  1567. break;
  1568. rec_pos= _mi_dpos(info,0,lastkey+key_length);
  1569. if ((*info->s->read_rnd)(info,sort_param->record,rec_pos,0))
  1570. {
  1571. mi_check_print_error(param,"%d when reading datafile",my_errno);
  1572. goto err;
  1573. }
  1574. if (rec_pos != sort_param->filepos && update_index)
  1575. {
  1576. _mi_dpointer(info,keypos-nod_flag-info->s->rec_reflength,
  1577. sort_param->filepos);
  1578. if (movepoint(info,sort_param->record,rec_pos,sort_param->filepos,
  1579. sort_key))
  1580. {
  1581. mi_check_print_error(param,"%d when updating key-pointers",my_errno);
  1582. goto err;
  1583. }
  1584. }
  1585. if (sort_write_record(sort_param))
  1586. goto err;
  1587. }
  1588. /* Clear end of block to get better compression if the table is backuped */
  1589. bzero((uchar*) buff+used_length,keyinfo->block_length-used_length);
  1590. if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
  1591. page,param->myf_rw))
  1592. {
  1593. mi_check_print_error(param,"%d when updating keyblock",my_errno);
  1594. goto err;
  1595. }
  1596. if (temp_buff)
  1597. my_afree((uchar*) temp_buff);
  1598. DBUG_RETURN(0);
  1599. err:
  1600. if (temp_buff)
  1601. my_afree((uchar*) temp_buff);
  1602. DBUG_RETURN(1);
  1603. } /* sort_record_index */
  1604. /*
  1605. Check if myisamchk was killed by a signal
  1606. This is overloaded by other programs that want to be able to abort
  1607. sorting
  1608. */
  1609. static int not_killed= 0;
  1610. volatile int *killed_ptr(MI_CHECK *param __attribute__((unused)))
  1611. {
  1612. return &not_killed; /* always NULL */
  1613. }
  1614. /* print warnings and errors */
  1615. /* VARARGS */
  1616. void mi_check_print_info(MI_CHECK *param __attribute__((unused)),
  1617. const char *fmt,...)
  1618. {
  1619. va_list args;
  1620. va_start(args,fmt);
  1621. (void) vfprintf(stdout, fmt, args);
  1622. (void) fputc('\n',stdout);
  1623. va_end(args);
  1624. }
  1625. /* VARARGS */
  1626. void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
  1627. {
  1628. va_list args;
  1629. DBUG_ENTER("mi_check_print_warning");
  1630. fflush(stdout);
  1631. if (!param->warning_printed && !param->error_printed)
  1632. {
  1633. if (param->testflag & T_SILENT)
  1634. fprintf(stderr,"%s: MyISAM file %s\n",my_progname_short,
  1635. param->isam_file_name);
  1636. param->out_flag|= O_DATA_LOST;
  1637. }
  1638. param->warning_printed=1;
  1639. va_start(args,fmt);
  1640. fprintf(stderr,"%s: warning: ",my_progname_short);
  1641. (void) vfprintf(stderr, fmt, args);
  1642. (void) fputc('\n',stderr);
  1643. fflush(stderr);
  1644. va_end(args);
  1645. DBUG_VOID_RETURN;
  1646. }
  1647. /* VARARGS */
  1648. void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
  1649. {
  1650. va_list args;
  1651. DBUG_ENTER("mi_check_print_error");
  1652. DBUG_PRINT("enter",("format: %s",fmt));
  1653. fflush(stdout);
  1654. if (!param->warning_printed && !param->error_printed)
  1655. {
  1656. if (param->testflag & T_SILENT)
  1657. fprintf(stderr,"%s: MyISAM file %s\n",my_progname_short,param->isam_file_name);
  1658. param->out_flag|= O_DATA_LOST;
  1659. }
  1660. param->error_printed|=1;
  1661. va_start(args,fmt);
  1662. fprintf(stderr,"%s: error: ",my_progname_short);
  1663. (void) vfprintf(stderr, fmt, args);
  1664. (void) fputc('\n',stderr);
  1665. fflush(stderr);
  1666. va_end(args);
  1667. DBUG_VOID_RETURN;
  1668. }
  1669. #include "mi_extrafunc.h"