mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
f252f9248a
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 BitKeeper/etc/ignore: added libmysqld/ha_ndbcluster_cond.cc --- added debian/defs.mk debian/control client/completion_hash.cc: Remove not needed casts client/my_readline.h: Remove some old types client/mysql.cc: Simplify types client/mysql_upgrade.c: Remove some old types Update call to dirname_part client/mysqladmin.cc: Remove some old types client/mysqlbinlog.cc: Remove some old types Change some buffers to be uchar to avoid casts client/mysqlcheck.c: Remove some old types client/mysqldump.c: Remove some old types Remove some not needed casts Change some string lengths to size_t client/mysqlimport.c: Remove some old types client/mysqlshow.c: Remove some old types client/mysqlslap.c: Remove some old types Remove some not needed casts client/mysqltest.c: Removed some old types Removed some not needed casts Updated hash-get-key function arguments Updated parameters to dirname_part() client/readline.cc: Removed some old types Removed some not needed casts Changed some string lengths to use size_t client/sql_string.cc: Removed some old types dbug/dbug.c: Removed some old types Changed some string lengths to use size_t Changed some prototypes to avoid casts extra/comp_err.c: Removed some old types extra/innochecksum.c: Removed some old types extra/my_print_defaults.c: Removed some old types extra/mysql_waitpid.c: Removed some old types extra/perror.c: Removed some old types extra/replace.c: Removed some old types Updated parameters to dirname_part() extra/resolve_stack_dump.c: Removed some old types extra/resolveip.c: Removed some old types include/config-win.h: Removed some old types include/decimal.h: Changed binary strings to be uchar* instead of char* include/ft_global.h: Removed some old types include/hash.h: Removed some old types include/heap.h: Removed some old types Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable include/keycache.h: Removed some old types include/m_ctype.h: Removed some old types Changed some string lengths to use size_t Changed character length functions to return uint unsigned char -> uchar include/m_string.h: Removed some old types Changed some string lengths to use size_t include/my_alloc.h: Changed some string lengths to use size_t include/my_base.h: Removed some old types include/my_dbug.h: Removed some old types Changed some string lengths to use size_t Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage include/my_getopt.h: Removed some old types include/my_global.h: Removed old types: my_size_t -> size_t byte -> uchar gptr -> uchar * include/my_list.h: Removed some old types include/my_nosys.h: Removed some old types include/my_pthread.h: Removed some old types include/my_sys.h: Removed some old types Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read() Changed some string lengths to use size_t my_malloc() / my_free() now uses void * Updated parameters to dirname_part() & my_uncompress() include/my_tree.h: Removed some old types include/my_trie.h: Removed some old types include/my_user.h: Changed some string lengths to use size_t include/my_vle.h: Removed some old types include/my_xml.h: Removed some old types Changed some string lengths to use size_t include/myisam.h: Removed some old types include/myisammrg.h: Removed some old types include/mysql.h: Removed some old types Changed byte streams to use uchar* instead of char* include/mysql_com.h: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts include/queues.h: Removed some old types include/sql_common.h: Removed some old types include/sslopt-longopts.h: Removed some old types include/violite.h: Removed some old types Changed some string lengths to use size_t libmysql/client_settings.h: Removed some old types libmysql/libmysql.c: Removed some old types libmysql/manager.c: Removed some old types libmysqld/emb_qcache.cc: Removed some old types libmysqld/emb_qcache.h: Removed some old types libmysqld/lib_sql.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts true -> TRUE, false -> FALSE mysys/array.c: Removed some old types mysys/charset.c: Changed some string lengths to use size_t mysys/checksum.c: Include zlib to get definition for crc32 Removed some old types mysys/default.c: Removed some old types Changed some string lengths to use size_t mysys/default_modify.c: Changed some string lengths to use size_t Removed some not needed casts mysys/hash.c: Removed some old types Changed some string lengths to use size_t Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function. hash_element now takes 'ulong' as the index type (cleanup) mysys/list.c: Removed some old types mysys/mf_cache.c: Changed some string lengths to use size_t mysys/mf_dirname.c: Removed some old types Changed some string lengths to use size_t Added argument to dirname_part() to avoid calculation of length for 'to' mysys/mf_fn_ext.c: Removed some old types Updated parameters to dirname_part() mysys/mf_format.c: Removed some old types Changed some string lengths to use size_t mysys/mf_getdate.c: Removed some old types mysys/mf_iocache.c: Removed some old types Changed some string lengths to use size_t Changed calculation of 'max_length' to be done the same way in all functions mysys/mf_iocache2.c: Removed some old types Changed some string lengths to use size_t Clean up comments Removed not needed indentation mysys/mf_keycache.c: Removed some old types mysys/mf_keycaches.c: Removed some old types mysys/mf_loadpath.c: Removed some old types mysys/mf_pack.c: Removed some old types Changed some string lengths to use size_t Removed some not needed casts Removed very old VMS code Updated parameters to dirname_part() Use result of dirnam_part() to remove call to strcat() mysys/mf_path.c: Removed some old types mysys/mf_radix.c: Removed some old types mysys/mf_same.c: Removed some old types mysys/mf_sort.c: Removed some old types mysys/mf_soundex.c: Removed some old types mysys/mf_strip.c: Removed some old types mysys/mf_tempdir.c: Removed some old types mysys/mf_unixpath.c: Removed some old types mysys/mf_wfile.c: Removed some old types mysys/mulalloc.c: Removed some old types mysys/my_alloc.c: Removed some old types Changed some string lengths to use size_t Use void* as type for allocated memory area Removed some not needed casts Changed argument 'Size' to 'length' according coding guidelines mysys/my_chsize.c: Changed some buffers to be uchar* to avoid casts mysys/my_compress.c: More comments Removed some old types Changed string lengths to use size_t Changed arguments to my_uncompress() to make them easier to understand Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) Changed type of 'pack_data' argument to packfrm() to avoid casts. mysys/my_conio.c: Changed some string lengths to use size_t mysys/my_create.c: Removed some old types mysys/my_div.c: Removed some old types mysys/my_error.c: Removed some old types mysys/my_fopen.c: Removed some old types mysys/my_fstream.c: Removed some old types Changed some string lengths to use size_t writen -> written mysys/my_getopt.c: Removed some old types mysys/my_getwd.c: Removed some old types More comments mysys/my_init.c: Removed some old types mysys/my_largepage.c: Removed some old types Changed some string lengths to use size_t mysys/my_lib.c: Removed some old types mysys/my_lockmem.c: Removed some old types mysys/my_malloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/my_memmem.c: Indentation cleanup mysys/my_once.c: Removed some old types Changed malloc(), free() and related functions to use void * mysys/my_open.c: Removed some old types mysys/my_pread.c: Removed some old types Changed all functions to use size_t Added comment for how my_pread() / my_pwrite() are supposed to work. 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. (If we ever would really need this, it should be enabled only with a flag argument) mysys/my_quick.c: Removed some old types Changed all functions to use size_t mysys/my_read.c: Removed some old types Changed all functions to use size_t mysys/my_realloc.c: Removed some old types Use void* as type for allocated memory area Changed all functions to use size_t mysys/my_static.c: Removed some old types mysys/my_static.h: Removed some old types mysys/my_vle.c: Removed some old types mysys/my_wincond.c: Removed some old types mysys/my_windac.c: Removed some old types mysys/my_write.c: Removed some old types Changed all functions to use size_t mysys/ptr_cmp.c: Removed some old types Changed all functions to use size_t mysys/queues.c: Removed some old types mysys/safemalloc.c: Removed some old types Changed malloc(), free() and related functions to use void * Changed all functions to use size_t mysys/string.c: Removed some old types Changed all functions to use size_t mysys/testhash.c: Removed some old types mysys/thr_alarm.c: Removed some old types mysys/thr_lock.c: Removed some old types mysys/tree.c: Removed some old types mysys/trie.c: Removed some old types mysys/typelib.c: Removed some old types plugin/daemon_example/daemon_example.cc: Removed some old types regex/reginit.c: Removed some old types server-tools/instance-manager/buffer.cc: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/buffer.h: Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/commands.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_map.cc: Removed some old types Changed some string lengths to use size_t Changed buffer to be of type uchar* server-tools/instance-manager/instance_options.cc: Changed buffer to be of type uchar* Replaced alloc_root + strcpy() with strdup_root() server-tools/instance-manager/mysql_connection.cc: Changed buffer to be of type uchar* server-tools/instance-manager/options.cc: Removed some old types server-tools/instance-manager/parse.cc: Changed some string lengths to use size_t server-tools/instance-manager/parse.h: Removed some old types Changed some string lengths to use size_t server-tools/instance-manager/protocol.cc: Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t server-tools/instance-manager/protocol.h: Changed some string lengths to use size_t server-tools/instance-manager/user_map.cc: Removed some old types Changed some string lengths to use size_t sql/derror.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/discover.cc: Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts sql/event_data_objects.cc: Removed some old types Added missing casts for alloc() and sprintf() sql/event_db_repository.cc: Changed some buffers to be uchar* to avoid casts Added missing casts for sprintf() sql/event_queue.cc: Removed some old types sql/field.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/field.h: Removed some old types Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes). Changed some string lengths to use size_t Removed some not needed casts Changed val_xxx(xxx, new_ptr) to take const pointers sql/field_conv.cc: Removed some old types Added casts required because memory area pointers are now uchar* sql/filesort.cc: Initalize variable that was used unitialized in error conditions sql/gen_lex_hash.cc: Removed some old types Changed memory buffers to be uchar* Changed some string lengths to use size_t Removed a lot of casts Safety fix in Field_blob::val_decimal() to not access zero pointer sql/gstream.h: Added required cast sql/ha_ndbcluster.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Added required casts Removed some not needed casts sql/ha_ndbcluster.h: Removed some old types sql/ha_ndbcluster_binlog.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake() Changed some string lengths to use size_t Added missing casts for alloc() and sprintf() sql/ha_ndbcluster_binlog.h: Removed some old types sql/ha_ndbcluster_cond.cc: Removed some old types Removed some not needed casts sql/ha_ndbcluster_cond.h: Removed some old types sql/ha_partition.cc: Removed some old types Changed prototype for change_partition() to avoid casts sql/ha_partition.h: Removed some old types sql/handler.cc: Removed some old types Changed some string lengths to use size_t sql/handler.h: Removed some old types Changed some string lengths to use size_t Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts sql/hash_filo.h: Removed some old types Changed all functions to use size_t sql/hostname.cc: Removed some old types sql/item.cc: Removed some old types Changed some string lengths to use size_t Use strmake() instead of memdup() to create a null terminated string. Updated calls to new Field() sql/item.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.cc: Removed some old types Changed some buffers to be uchar* to avoid casts sql/item_cmpfunc.h: Removed some old types sql/item_create.cc: Removed some old types sql/item_func.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added test for failing alloc() in init_result_field() Remove old confusing comment Fixed compiler warning sql/item_func.h: Removed some old types sql/item_row.cc: Removed some old types sql/item_row.h: Removed some old types sql/item_strfunc.cc: Include zlib (needed becasue we call crc32) Removed some old types sql/item_strfunc.h: Removed some old types Changed some types to match new function prototypes sql/item_subselect.cc: Removed some old types sql/item_subselect.h: Removed some old types sql/item_sum.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/item_sum.h: Removed some old types sql/item_timefunc.cc: Removed some old types Changed some string lengths to use size_t sql/item_timefunc.h: Removed some old types sql/item_xmlfunc.cc: Changed some string lengths to use size_t sql/item_xmlfunc.h: Removed some old types sql/key.cc: Removed some old types Removed some not needed casts sql/lock.cc: Removed some old types Added some cast to my_multi_malloc() arguments for safety sql/log.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Changed usage of pwrite() to not assume it holds the cursor position for the file Made usage of my_read() safer sql/log_event.cc: Removed some old types Added checking of return value of malloc() in pack_info() Changed some buffers to be uchar* to avoid casts Removed some 'const' to avoid casts Added missing casts for alloc() and sprintf() Added required casts Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety sql/log_event.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/log_event_old.cc: Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/log_event_old.h: Changed some buffers to be uchar* to avoid casts sql/mf_iocache.cc: Removed some old types sql/my_decimal.cc: Changed memory area to use uchar* sql/my_decimal.h: Changed memory area to use uchar* sql/mysql_priv.h: Removed some old types Changed malloc(), free() and related functions to use void * Changed some string lengths to use size_t Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow Changed some buffers to be uchar* to avoid casts sql/mysqld.cc: Removed some old types sql/net_serv.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Ensure that vio_read()/vio_write() return values are stored in a size_t variable Removed some not needed casts sql/opt_range.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/opt_range.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/opt_sum.cc: Removed some old types Removed some not needed casts sql/parse_file.cc: Removed some old types Changed some string lengths to use size_t Changed alloc_root + memcpy + set end 0 -> strmake_root() sql/parse_file.h: Removed some old types sql/partition_info.cc: Removed some old types Added missing casts for alloc() Changed some buffers to be uchar* to avoid casts sql/partition_info.h: Changed some buffers to be uchar* to avoid casts sql/protocol.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/protocol.h: Removed some old types Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/records.cc: Removed some old types sql/repl_failsafe.cc: Removed some old types Changed some string lengths to use size_t Added required casts sql/rpl_filter.cc: Removed some old types Updated hash-get-key function arguments Changed some string lengths to use size_t sql/rpl_filter.h: Changed some string lengths to use size_t sql/rpl_injector.h: Removed some old types sql/rpl_record.cc: Removed some old types Removed some not needed casts Changed some buffers to be uchar* to avoid casts sql/rpl_record.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/rpl_record_old.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/rpl_record_old.h: Removed some old types Changed some buffers to be uchar* to avoid cast sql/rpl_rli.cc: Removed some old types sql/rpl_tblmap.cc: Removed some old types sql/rpl_tblmap.h: Removed some old types sql/rpl_utility.cc: Removed some old types sql/rpl_utility.h: Removed some old types Changed type of 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 sql/set_var.cc: Removed some old types Updated parameters to dirname_part() sql/set_var.h: Removed some old types sql/slave.cc: Removed some old types Changed some string lengths to use size_t sql/slave.h: Removed some old types sql/sp.cc: Removed some old types Added missing casts for printf() sql/sp.h: Removed some old types Updated hash-get-key function arguments sql/sp_cache.cc: Removed some old types Added missing casts for printf() Updated hash-get-key function arguments sql/sp_head.cc: Removed some old types Added missing casts for alloc() and printf() Added required casts Updated hash-get-key function arguments sql/sp_head.h: Removed some old types sql/sp_pcontext.cc: Removed some old types sql/sp_pcontext.h: Removed some old types sql/sql_acl.cc: Removed some old types Changed some string lengths to use size_t Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added required casts sql/sql_analyse.cc: Changed some buffers to be uchar* to avoid casts sql/sql_analyse.h: Changed some buffers to be uchar* to avoid casts sql/sql_array.h: Removed some old types sql/sql_base.cc: Removed some old types Updated hash-get-key function arguments sql/sql_binlog.cc: Removed some old types Added missing casts for printf() sql/sql_cache.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts Changed some string lengths to use size_t sql/sql_cache.h: Removed some old types Removed reference to not existing function cache_key() Updated hash-get-key function arguments sql/sql_class.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() Updated hash-get-key function arguments Moved THD::max_row_length() to table.cc (as it's not depending on THD) Removed some not needed casts sql/sql_class.h: Removed some old types Changed malloc(), free() and related functions to use void * Removed some not needed casts Changed some string lengths to use size_t Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD sql/sql_connect.cc: Removed some old types Added required casts sql/sql_db.cc: Removed some old types Removed some not needed casts Added some cast to my_multi_malloc() arguments for safety Added missing casts for alloc() sql/sql_delete.cc: Removed some old types sql/sql_handler.cc: Removed some old types Updated hash-get-key function arguments Added some cast to my_multi_malloc() arguments for safety sql/sql_help.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_insert.cc: Removed some old types Added missing casts for alloc() and printf() sql/sql_lex.cc: Removed some old types sql/sql_lex.h: Removed some old types Removed some not needed casts sql/sql_list.h: Removed some old types Removed some not needed casts sql/sql_load.cc: Removed some old types Removed compiler warning sql/sql_manager.cc: Removed some old types sql/sql_map.cc: Removed some old types sql/sql_map.h: Removed some old types sql/sql_olap.cc: Removed some old types sql/sql_parse.cc: Removed some old types Trivial move of code lines to make things more readable Changed some string lengths to use size_t Added missing casts for alloc() sql/sql_partition.cc: Removed some old types Removed compiler warnings about not used functions Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_partition.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_plugin.cc: Removed some old types Added missing casts for alloc() Updated hash-get-key function arguments sql/sql_prepare.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Added missing casts for alloc() and printf() sql-common/client.c: Removed some old types Changed some memory areas to use uchar* sql-common/my_user.c: Changed some string lengths to use size_t sql-common/pack.c: Changed some buffers to be uchar* to avoid casts sql/sql_repl.cc: Added required casts Changed some buffers to be uchar* to avoid casts Changed some string lengths to use size_t sql/sql_select.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some old types sql/sql_select.h: Removed some old types Changed some buffers to be uchar* to avoid casts sql/sql_servers.cc: Removed some old types Updated hash-get-key function arguments sql/sql_show.cc: Removed some old types Added missing casts for alloc() Removed some not needed casts sql/sql_string.cc: Removed some old types Added required casts sql/sql_table.cc: Removed some old types Removed compiler warning about not used variable Changed some buffers to be uchar* to avoid casts Removed some not needed casts sql/sql_test.cc: Removed some old types sql/sql_trigger.cc: Removed some old types Added missing casts for alloc() sql/sql_udf.cc: Removed some old types Updated hash-get-key function arguments sql/sql_union.cc: Removed some old types sql/sql_update.cc: Removed some old types Removed some not needed casts sql/sql_view.cc: Removed some old types sql/sql_yacc.yy: Removed some old types Changed some string lengths to use size_t Added missing casts for alloc() sql/stacktrace.c: Removed some old types sql/stacktrace.h: Removed some old types sql/structs.h: Removed some old types sql/table.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts Removed setting of LEX_STRING() arguments in declaration Added required casts More function comments Moved max_row_length() here from sql_class.cc/sql_class.h sql/table.h: Removed some old types Changed some string lengths to use size_t sql/thr_malloc.cc: Use void* as type for allocated memory area Changed all functions to use size_t sql/tzfile.h: Changed some buffers to be uchar* to avoid casts sql/tztime.cc: Changed some buffers to be uchar* to avoid casts Updated hash-get-key function arguments Added missing casts for alloc() Removed some not needed casts sql/uniques.cc: Removed some old types Removed some not needed casts sql/unireg.cc: Removed some old types Changed some buffers to be uchar* to avoid casts Removed some not needed casts Added missing casts for alloc() storage/archive/archive_reader.c: Removed some old types storage/archive/azio.c: Removed some old types Removed some not needed casts storage/archive/ha_archive.cc: Removed some old types Changed type for 'frmblob' in archive_discover() to match handler Updated hash-get-key function arguments Removed some not needed casts storage/archive/ha_archive.h: Removed some old types storage/blackhole/ha_blackhole.cc: Removed some old types storage/blackhole/ha_blackhole.h: Removed some old types storage/csv/ha_tina.cc: Removed some old types Updated hash-get-key function arguments Changed some buffers to be uchar* to avoid casts storage/csv/ha_tina.h: Removed some old types Removed some not needed casts storage/csv/transparent_file.cc: Removed some old types Changed type of 'bytes_read' to be able to detect read errors Fixed indentation storage/csv/transparent_file.h: Removed some old types storage/example/ha_example.cc: Removed some old types Updated hash-get-key function arguments storage/example/ha_example.h: Removed some old types storage/federated/ha_federated.cc: Removed some old types Updated hash-get-key function arguments Removed some not needed casts storage/federated/ha_federated.h: Removed some old types storage/heap/_check.c: Changed some buffers to be uchar* to avoid casts storage/heap/_rectest.c: Removed some old types storage/heap/ha_heap.cc: Removed some old types storage/heap/ha_heap.h: Removed some old types storage/heap/heapdef.h: Removed some old types storage/heap/hp_block.c: Removed some old types Changed some string lengths to use size_t storage/heap/hp_clear.c: Removed some old types storage/heap/hp_close.c: Removed some old types storage/heap/hp_create.c: Removed some old types storage/heap/hp_delete.c: Removed some old types storage/heap/hp_hash.c: Removed some old types storage/heap/hp_info.c: Removed some old types storage/heap/hp_open.c: Removed some old types storage/heap/hp_rfirst.c: Removed some old types storage/heap/hp_rkey.c: Removed some old types storage/heap/hp_rlast.c: Removed some old types storage/heap/hp_rnext.c: Removed some old types storage/heap/hp_rprev.c: Removed some old types storage/heap/hp_rrnd.c: Removed some old types storage/heap/hp_rsame.c: Removed some old types storage/heap/hp_scan.c: Removed some old types storage/heap/hp_test1.c: Removed some old types storage/heap/hp_test2.c: Removed some old types storage/heap/hp_update.c: Removed some old types storage/heap/hp_write.c: Removed some old types Changed some string lengths to use size_t storage/innobase/handler/ha_innodb.cc: Removed some old types Updated hash-get-key function arguments Added missing casts for alloc() and printf() Removed some not needed casts storage/innobase/handler/ha_innodb.h: Removed some old types storage/myisam/ft_boolean_search.c: Removed some old types storage/myisam/ft_nlq_search.c: Removed some old types storage/myisam/ft_parser.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ft_static.c: Removed some old types storage/myisam/ft_stopwords.c: Removed some old types storage/myisam/ft_update.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/ftdefs.h: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/fulltext.h: Removed some old types storage/myisam/ha_myisam.cc: Removed some old types storage/myisam/ha_myisam.h: Removed some old types storage/myisam/mi_cache.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_check.c: Removed some old types storage/myisam/mi_checksum.c: Removed some old types storage/myisam/mi_close.c: Removed some old types storage/myisam/mi_create.c: Removed some old types storage/myisam/mi_delete.c: Removed some old types storage/myisam/mi_delete_all.c: Removed some old types storage/myisam/mi_dynrec.c: Removed some old types storage/myisam/mi_extra.c: Removed some old types storage/myisam/mi_key.c: Removed some old types storage/myisam/mi_locking.c: Removed some old types storage/myisam/mi_log.c: Removed some old types storage/myisam/mi_open.c: Removed some old types Removed some not needed casts Check argument of my_write()/my_pwrite() in functions returning int Added casting of string lengths to size_t storage/myisam/mi_packrec.c: Removed some old types Changed some buffers to be uchar* to avoid casts storage/myisam/mi_page.c: Removed some old types storage/myisam/mi_preload.c: Removed some old types storage/myisam/mi_range.c: Removed some old types storage/myisam/mi_rfirst.c: Removed some old types storage/myisam/mi_rkey.c: Removed some old types storage/myisam/mi_rlast.c: Removed some old types storage/myisam/mi_rnext.c: Removed some old types storage/myisam/mi_rnext_same.c: Removed some old types storage/myisam/mi_rprev.c: Removed some old types storage/myisam/mi_rrnd.c: Removed some old types storage/myisam/mi_rsame.c: Removed some old types storage/myisam/mi_rsamepos.c: Removed some old types storage/myisam/mi_scan.c: Removed some old types storage/myisam/mi_search.c: Removed some old types storage/myisam/mi_static.c: Removed some old types storage/myisam/mi_statrec.c: Removed some old types storage/myisam/mi_test1.c: Removed some old types storage/myisam/mi_test2.c: Removed some old types storage/myisam/mi_test3.c: Removed some old types storage/myisam/mi_unique.c: Removed some old types storage/myisam/mi_update.c: Removed some old types storage/myisam/mi_write.c: Removed some old types storage/myisam/myisam_ftdump.c: Removed some old types storage/myisam/myisamchk.c: Removed some old types storage/myisam/myisamdef.h: Removed some old types storage/myisam/myisamlog.c: Removed some old types Indentation fix storage/myisam/myisampack.c: Removed some old types storage/myisam/rt_index.c: Removed some old types storage/myisam/rt_split.c: Removed some old types storage/myisam/sort.c: Removed some old types storage/myisam/sp_defs.h: Removed some old types storage/myisam/sp_key.c: Removed some old types storage/myisammrg/ha_myisammrg.cc: Removed some old types storage/myisammrg/ha_myisammrg.h: Removed some old types storage/myisammrg/myrg_close.c: Removed some old types storage/myisammrg/myrg_def.h: Removed some old types storage/myisammrg/myrg_delete.c: Removed some old types storage/myisammrg/myrg_open.c: Removed some old types Updated parameters to dirname_part() storage/myisammrg/myrg_queue.c: Removed some old types storage/myisammrg/myrg_rfirst.c: Removed some old types storage/myisammrg/myrg_rkey.c: Removed some old types storage/myisammrg/myrg_rlast.c: Removed some old types storage/myisammrg/myrg_rnext.c: Removed some old types storage/myisammrg/myrg_rnext_same.c: Removed some old types storage/myisammrg/myrg_rprev.c: Removed some old types storage/myisammrg/myrg_rrnd.c: Removed some old types storage/myisammrg/myrg_rsame.c: Removed some old types storage/myisammrg/myrg_update.c: Removed some old types storage/myisammrg/myrg_write.c: Removed some old types storage/ndb/include/util/ndb_opts.h: Removed some old types storage/ndb/src/cw/cpcd/main.cpp: Removed some old types storage/ndb/src/kernel/vm/Configuration.cpp: Removed some old types storage/ndb/src/mgmclient/main.cpp: Removed some old types storage/ndb/src/mgmsrv/InitConfigFileParser.cpp: Removed some old types Removed old disabled code storage/ndb/src/mgmsrv/main.cpp: Removed some old types storage/ndb/src/ndbapi/NdbBlob.cpp: Removed some old types storage/ndb/src/ndbapi/NdbOperationDefine.cpp: Removed not used variable storage/ndb/src/ndbapi/NdbOperationInt.cpp: Added required casts storage/ndb/src/ndbapi/NdbScanOperation.cpp: Added required casts storage/ndb/tools/delete_all.cpp: Removed some old types storage/ndb/tools/desc.cpp: Removed some old types storage/ndb/tools/drop_index.cpp: Removed some old types storage/ndb/tools/drop_tab.cpp: Removed some old types storage/ndb/tools/listTables.cpp: Removed some old types storage/ndb/tools/ndb_config.cpp: Removed some old types storage/ndb/tools/restore/consumer_restore.cpp: Changed some buffers to be uchar* to avoid casts with new defintion of packfrm() storage/ndb/tools/restore/restore_main.cpp: Removed some old types storage/ndb/tools/select_all.cpp: Removed some old types storage/ndb/tools/select_count.cpp: Removed some old types storage/ndb/tools/waiter.cpp: Removed some old types strings/bchange.c: Changed function to use uchar * and size_t strings/bcmp.c: Changed function to use uchar * and size_t strings/bmove512.c: Changed function to use uchar * and size_t strings/bmove_upp.c: Changed function to use uchar * and size_t strings/ctype-big5.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-bin.c: Changed functions to use size_t strings/ctype-cp932.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-czech.c: Fixed indentation Changed functions to use size_t strings/ctype-euc_kr.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-eucjpms.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-gb2312.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-gbk.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-latin1.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-mb.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-simple.c: Changed functions to use size_t Simpler loops for caseup/casedown unsigned int -> uint unsigned char -> uchar strings/ctype-sjis.c: Changed functions to use size_t Changed character length functions to return uint strings/ctype-tis620.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-uca.c: Changed functions to use size_t unsigned char -> uchar strings/ctype-ucs2.c: Moved inclusion of stdarg.h to other includes usigned char -> uchar Changed functions to use size_t Changed character length functions to return uint strings/ctype-ujis.c: Changed functions to use size_t Changed character length functions to return uint unsigned char -> uchar strings/ctype-utf8.c: Changed functions to use size_t unsigned char -> uchar Indentation fixes strings/ctype-win1250ch.c: Indentation fixes Changed functions to use size_t strings/ctype.c: Changed functions to use size_t strings/decimal.c: Changed type for memory argument to uchar * strings/do_ctype.c: Indentation fixes strings/my_strtoll10.c: unsigned char -> uchar strings/my_vsnprintf.c: Changed functions to use size_t strings/r_strinstr.c: Removed some old types Changed functions to use size_t strings/str_test.c: Removed some old types strings/strappend.c: Changed functions to use size_t strings/strcont.c: Removed some old types strings/strfill.c: Removed some old types strings/strinstr.c: Changed functions to use size_t strings/strlen.c: Changed functions to use size_t strings/strmake.c: Changed functions to use size_t strings/strnlen.c: Changed functions to use size_t strings/strnmov.c: Changed functions to use size_t strings/strto.c: unsigned char -> uchar strings/strtod.c: Changed functions to use size_t strings/strxnmov.c: Changed functions to use size_t strings/xml.c: Changed functions to use size_t Indentation fixes tests/mysql_client_test.c: Removed some old types tests/thread_test.c: Removed some old types vio/test-ssl.c: Removed some old types vio/test-sslclient.c: Removed some old types vio/test-sslserver.c: Removed some old types vio/vio.c: Removed some old types vio/vio_priv.h: Removed some old types Changed vio_read()/vio_write() to work with size_t vio/viosocket.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viossl.c: Changed vio_read()/vio_write() to work with size_t Indentation fixes vio/viosslfactories.c: Removed some old types vio/viotest-ssl.c: Removed some old types win/README: More explanations
1936 lines
53 KiB
C
1936 lines
53 KiB
C
/* Copyright (C) 2000-2006 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/*
|
|
Functions to handle space-packed-records and blobs
|
|
|
|
A row may be stored in one or more linked blocks.
|
|
The block size is between MI_MIN_BLOCK_LENGTH and MI_MAX_BLOCK_LENGTH.
|
|
Each block is aligned on MI_DYN_ALIGN_SIZE.
|
|
The reson for the max block size is to not have too many different types
|
|
of blocks. For the differnet block types, look at _mi_get_block_info()
|
|
*/
|
|
|
|
#include "myisamdef.h"
|
|
|
|
/* Enough for comparing if number is zero */
|
|
static char zero_string[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
static int write_dynamic_record(MI_INFO *info,const uchar *record,
|
|
ulong reclength);
|
|
static int _mi_find_writepos(MI_INFO *info,ulong reclength,my_off_t *filepos,
|
|
ulong *length);
|
|
static int update_dynamic_record(MI_INFO *info,my_off_t filepos,uchar *record,
|
|
ulong reclength);
|
|
static int delete_dynamic_record(MI_INFO *info,my_off_t filepos,
|
|
uint second_read);
|
|
static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
|
|
uint length);
|
|
|
|
#ifdef THREAD
|
|
/* Play it safe; We have a small stack when using threads */
|
|
#undef my_alloca
|
|
#undef my_afree
|
|
#define my_alloca(A) my_malloc((A),MYF(0))
|
|
#define my_afree(A) my_free((A),MYF(0))
|
|
#endif
|
|
|
|
/* Interface function from MI_INFO */
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
/*
|
|
Create mmaped area for MyISAM handler
|
|
|
|
SYNOPSIS
|
|
mi_dynmap_file()
|
|
info MyISAM handler
|
|
|
|
RETURN
|
|
0 ok
|
|
1 error.
|
|
*/
|
|
|
|
my_bool mi_dynmap_file(MI_INFO *info, my_off_t size)
|
|
{
|
|
DBUG_ENTER("mi_dynmap_file");
|
|
if (size > (my_off_t) (~((size_t) 0)) - MEMMAP_EXTRA_MARGIN)
|
|
{
|
|
DBUG_PRINT("warning", ("File is too large for mmap"));
|
|
DBUG_RETURN(1);
|
|
}
|
|
/*
|
|
I wonder if it is good to use MAP_NORESERVE. From the Linux man page:
|
|
MAP_NORESERVE
|
|
Do not reserve swap space for this mapping. When swap space is
|
|
reserved, one has the guarantee that it is possible to modify the
|
|
mapping. When swap space is not reserved one might get SIGSEGV
|
|
upon a write if no physical memory is available.
|
|
*/
|
|
info->s->file_map= (uchar*)
|
|
my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN),
|
|
info->s->mode==O_RDONLY ? PROT_READ :
|
|
PROT_READ | PROT_WRITE,
|
|
MAP_SHARED | MAP_NORESERVE,
|
|
info->dfile, 0L);
|
|
if (info->s->file_map == (uchar*) MAP_FAILED)
|
|
{
|
|
info->s->file_map= NULL;
|
|
DBUG_RETURN(1);
|
|
}
|
|
#if defined(HAVE_MADVISE)
|
|
madvise(info->s->file_map, size, MADV_RANDOM);
|
|
#endif
|
|
info->s->mmaped_length= size;
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
Resize mmaped area for MyISAM handler
|
|
|
|
SYNOPSIS
|
|
mi_remap_file()
|
|
info MyISAM handler
|
|
|
|
RETURN
|
|
*/
|
|
|
|
void mi_remap_file(MI_INFO *info, my_off_t size)
|
|
{
|
|
if (info->s->file_map)
|
|
{
|
|
VOID(my_munmap(info->s->file_map,
|
|
(size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN));
|
|
mi_dynmap_file(info, size);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
|
|
/*
|
|
Read bytes from MySAM handler, using mmap or pread
|
|
|
|
SYNOPSIS
|
|
mi_mmap_pread()
|
|
info MyISAM handler
|
|
Buffer Input buffer
|
|
Count Count of bytes for read
|
|
offset Start position
|
|
MyFlags
|
|
|
|
RETURN
|
|
0 ok
|
|
*/
|
|
|
|
uint mi_mmap_pread(MI_INFO *info, uchar *Buffer,
|
|
uint Count, my_off_t offset, myf MyFlags)
|
|
{
|
|
DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile));
|
|
if (info->s->concurrent_insert)
|
|
rw_rdlock(&info->s->mmap_lock);
|
|
|
|
/*
|
|
The following test may fail in the following cases:
|
|
- We failed to remap a memory area (fragmented memory?)
|
|
- This thread has done some writes, but not yet extended the
|
|
memory mapped area.
|
|
*/
|
|
|
|
if (info->s->mmaped_length >= offset + Count)
|
|
{
|
|
memcpy(Buffer, info->s->file_map + offset, Count);
|
|
if (info->s->concurrent_insert)
|
|
rw_unlock(&info->s->mmap_lock);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
if (info->s->concurrent_insert)
|
|
rw_unlock(&info->s->mmap_lock);
|
|
return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
|
|
}
|
|
}
|
|
|
|
|
|
/* wrapper for my_pread in case if mmap isn't used */
|
|
|
|
uint mi_nommap_pread(MI_INFO *info, uchar *Buffer,
|
|
uint Count, my_off_t offset, myf MyFlags)
|
|
{
|
|
return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
|
|
}
|
|
|
|
|
|
/*
|
|
Write bytes to MySAM handler, using mmap or pwrite
|
|
|
|
SYNOPSIS
|
|
mi_mmap_pwrite()
|
|
info MyISAM handler
|
|
Buffer Output buffer
|
|
Count Count of bytes for write
|
|
offset Start position
|
|
MyFlags
|
|
|
|
RETURN
|
|
0 ok
|
|
!=0 error. In this case return error from pwrite
|
|
*/
|
|
|
|
uint mi_mmap_pwrite(MI_INFO *info, uchar *Buffer,
|
|
uint Count, my_off_t offset, myf MyFlags)
|
|
{
|
|
DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile));
|
|
if (info->s->concurrent_insert)
|
|
rw_rdlock(&info->s->mmap_lock);
|
|
|
|
/*
|
|
The following test may fail in the following cases:
|
|
- We failed to remap a memory area (fragmented memory?)
|
|
- This thread has done some writes, but not yet extended the
|
|
memory mapped area.
|
|
*/
|
|
|
|
if (info->s->mmaped_length >= offset + Count)
|
|
{
|
|
memcpy(info->s->file_map + offset, Buffer, Count);
|
|
if (info->s->concurrent_insert)
|
|
rw_unlock(&info->s->mmap_lock);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
info->s->nonmmaped_inserts++;
|
|
if (info->s->concurrent_insert)
|
|
rw_unlock(&info->s->mmap_lock);
|
|
return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/* wrapper for my_pwrite in case if mmap isn't used */
|
|
|
|
uint mi_nommap_pwrite(MI_INFO *info, uchar *Buffer,
|
|
uint Count, my_off_t offset, myf MyFlags)
|
|
{
|
|
return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
|
|
}
|
|
|
|
|
|
int _mi_write_dynamic_record(MI_INFO *info, const uchar *record)
|
|
{
|
|
ulong reclength=_mi_rec_pack(info,info->rec_buff,record);
|
|
return (write_dynamic_record(info,info->rec_buff,reclength));
|
|
}
|
|
|
|
int _mi_update_dynamic_record(MI_INFO *info, my_off_t pos, const uchar *record)
|
|
{
|
|
uint length=_mi_rec_pack(info,info->rec_buff,record);
|
|
return (update_dynamic_record(info,pos,info->rec_buff,length));
|
|
}
|
|
|
|
int _mi_write_blob_record(MI_INFO *info, const uchar *record)
|
|
{
|
|
uchar *rec_buff;
|
|
int error;
|
|
ulong reclength,reclength2,extra;
|
|
|
|
extra= (ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
|
|
MI_DYN_DELETE_BLOCK_HEADER+1);
|
|
reclength= (info->s->base.pack_reclength +
|
|
_my_calc_total_blob_length(info,record)+ extra);
|
|
#ifdef NOT_USED /* We now support big rows */
|
|
if (reclength > MI_DYN_MAX_ROW_LENGTH)
|
|
{
|
|
my_errno=HA_ERR_TO_BIG_ROW;
|
|
return -1;
|
|
}
|
|
#endif
|
|
if (!(rec_buff=(uchar*) my_alloca(reclength)))
|
|
{
|
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
|
return(-1);
|
|
}
|
|
reclength2= _mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
|
|
record);
|
|
DBUG_PRINT("info",("reclength: %lu reclength2: %lu",
|
|
reclength, reclength2));
|
|
DBUG_ASSERT(reclength2 <= reclength);
|
|
error=write_dynamic_record(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
|
|
reclength2);
|
|
my_afree(rec_buff);
|
|
return(error);
|
|
}
|
|
|
|
|
|
int _mi_update_blob_record(MI_INFO *info, my_off_t pos, const uchar *record)
|
|
{
|
|
uchar *rec_buff;
|
|
int error;
|
|
ulong reclength,extra;
|
|
|
|
extra= (ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+
|
|
MI_DYN_DELETE_BLOCK_HEADER);
|
|
reclength= (info->s->base.pack_reclength+
|
|
_my_calc_total_blob_length(info,record)+ extra);
|
|
#ifdef NOT_USED /* We now support big rows */
|
|
if (reclength > MI_DYN_MAX_ROW_LENGTH)
|
|
{
|
|
my_errno=HA_ERR_TO_BIG_ROW;
|
|
return -1;
|
|
}
|
|
#endif
|
|
if (!(rec_buff=(uchar*) my_alloca(reclength)))
|
|
{
|
|
my_errno= HA_ERR_OUT_OF_MEM; /* purecov: inspected */
|
|
return(-1);
|
|
}
|
|
reclength=_mi_rec_pack(info,rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
|
|
record);
|
|
error=update_dynamic_record(info,pos,
|
|
rec_buff+ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER),
|
|
reclength);
|
|
my_afree(rec_buff);
|
|
return(error);
|
|
}
|
|
|
|
|
|
int _mi_delete_dynamic_record(MI_INFO *info)
|
|
{
|
|
return delete_dynamic_record(info,info->lastpos,0);
|
|
}
|
|
|
|
|
|
/* Write record to data-file */
|
|
|
|
static int write_dynamic_record(MI_INFO *info, const uchar *record,
|
|
ulong reclength)
|
|
{
|
|
int flag;
|
|
ulong length;
|
|
my_off_t filepos;
|
|
DBUG_ENTER("write_dynamic_record");
|
|
|
|
flag=0;
|
|
do
|
|
{
|
|
if (_mi_find_writepos(info,reclength,&filepos,&length))
|
|
goto err;
|
|
if (_mi_write_part_record(info,filepos,length,
|
|
(info->append_insert_at_end ?
|
|
HA_OFFSET_ERROR : info->s->state.dellink),
|
|
(uchar**) &record,&reclength,&flag))
|
|
goto err;
|
|
} while (reclength);
|
|
|
|
DBUG_RETURN(0);
|
|
err:
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
|
|
/* Get a block for data ; The given data-area must be used !! */
|
|
|
|
static int _mi_find_writepos(MI_INFO *info,
|
|
ulong reclength, /* record length */
|
|
my_off_t *filepos, /* Return file pos */
|
|
ulong *length) /* length of block at filepos */
|
|
{
|
|
MI_BLOCK_INFO block_info;
|
|
ulong tmp;
|
|
DBUG_ENTER("_mi_find_writepos");
|
|
|
|
if (info->s->state.dellink != HA_OFFSET_ERROR &&
|
|
!info->append_insert_at_end)
|
|
{
|
|
/* Deleted blocks exists; Get last used block */
|
|
*filepos=info->s->state.dellink;
|
|
block_info.second_read=0;
|
|
info->rec_cache.seek_not_done=1;
|
|
if (!(_mi_get_block_info(&block_info,info->dfile,info->s->state.dellink) &
|
|
BLOCK_DELETED))
|
|
{
|
|
DBUG_PRINT("error",("Delete link crashed"));
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
DBUG_RETURN(-1);
|
|
}
|
|
info->s->state.dellink=block_info.next_filepos;
|
|
info->state->del--;
|
|
info->state->empty-= block_info.block_len;
|
|
*length= block_info.block_len;
|
|
}
|
|
else
|
|
{
|
|
/* No deleted blocks; Allocate a new block */
|
|
*filepos=info->state->data_file_length;
|
|
if ((tmp=reclength+3 + test(reclength >= (65520-3))) <
|
|
info->s->base.min_block_length)
|
|
tmp= info->s->base.min_block_length;
|
|
else
|
|
tmp= ((tmp+MI_DYN_ALIGN_SIZE-1) &
|
|
(~ (ulong) (MI_DYN_ALIGN_SIZE-1)));
|
|
if (info->state->data_file_length >
|
|
(info->s->base.max_data_file_length - tmp))
|
|
{
|
|
my_errno=HA_ERR_RECORD_FILE_FULL;
|
|
DBUG_RETURN(-1);
|
|
}
|
|
if (tmp > MI_MAX_BLOCK_LENGTH)
|
|
tmp=MI_MAX_BLOCK_LENGTH;
|
|
*length= tmp;
|
|
info->state->data_file_length+= tmp;
|
|
info->s->state.split++;
|
|
info->update|=HA_STATE_WRITE_AT_END;
|
|
}
|
|
DBUG_RETURN(0);
|
|
} /* _mi_find_writepos */
|
|
|
|
|
|
|
|
/*
|
|
Unlink a deleted block from the deleted list.
|
|
This block will be combined with the preceding or next block to form
|
|
a big block.
|
|
*/
|
|
|
|
static bool unlink_deleted_block(MI_INFO *info, MI_BLOCK_INFO *block_info)
|
|
{
|
|
DBUG_ENTER("unlink_deleted_block");
|
|
if (block_info->filepos == info->s->state.dellink)
|
|
{
|
|
/* First deleted block; We can just use this ! */
|
|
info->s->state.dellink=block_info->next_filepos;
|
|
}
|
|
else
|
|
{
|
|
MI_BLOCK_INFO tmp;
|
|
tmp.second_read=0;
|
|
/* Unlink block from the previous block */
|
|
if (!(_mi_get_block_info(&tmp,info->dfile,block_info->prev_filepos)
|
|
& BLOCK_DELETED))
|
|
DBUG_RETURN(1); /* Something is wrong */
|
|
mi_sizestore(tmp.header+4,block_info->next_filepos);
|
|
if (info->s->file_write(info,(char*) tmp.header+4,8,
|
|
block_info->prev_filepos+4, MYF(MY_NABP)))
|
|
DBUG_RETURN(1);
|
|
/* Unlink block from next block */
|
|
if (block_info->next_filepos != HA_OFFSET_ERROR)
|
|
{
|
|
if (!(_mi_get_block_info(&tmp,info->dfile,block_info->next_filepos)
|
|
& BLOCK_DELETED))
|
|
DBUG_RETURN(1); /* Something is wrong */
|
|
mi_sizestore(tmp.header+12,block_info->prev_filepos);
|
|
if (info->s->file_write(info,(char*) tmp.header+12,8,
|
|
block_info->next_filepos+12,
|
|
MYF(MY_NABP)))
|
|
DBUG_RETURN(1);
|
|
}
|
|
}
|
|
/* We now have one less deleted block */
|
|
info->state->del--;
|
|
info->state->empty-= block_info->block_len;
|
|
info->s->state.split--;
|
|
|
|
/*
|
|
If this was a block that we where accessing through table scan
|
|
(mi_rrnd() or mi_scan(), then ensure that we skip over this block
|
|
when doing next mi_rrnd() or mi_scan().
|
|
*/
|
|
if (info->nextpos == block_info->filepos)
|
|
info->nextpos+=block_info->block_len;
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/*
|
|
Add a backward link to delete block
|
|
|
|
SYNOPSIS
|
|
update_backward_delete_link()
|
|
info MyISAM handler
|
|
delete_block Position to delete block to update.
|
|
If this is 'HA_OFFSET_ERROR', nothing will be done
|
|
filepos Position to block that 'delete_block' should point to
|
|
|
|
RETURN
|
|
0 ok
|
|
1 error. In this case my_error is set.
|
|
*/
|
|
|
|
static int update_backward_delete_link(MI_INFO *info, my_off_t delete_block,
|
|
my_off_t filepos)
|
|
{
|
|
MI_BLOCK_INFO block_info;
|
|
DBUG_ENTER("update_backward_delete_link");
|
|
|
|
if (delete_block != HA_OFFSET_ERROR)
|
|
{
|
|
block_info.second_read=0;
|
|
if (_mi_get_block_info(&block_info,info->dfile,delete_block)
|
|
& BLOCK_DELETED)
|
|
{
|
|
char buff[8];
|
|
mi_sizestore(buff,filepos);
|
|
if (info->s->file_write(info,buff, 8, delete_block+12, MYF(MY_NABP)))
|
|
DBUG_RETURN(1); /* Error on write */
|
|
}
|
|
else
|
|
{
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
DBUG_RETURN(1); /* Wrong delete link */
|
|
}
|
|
}
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
/* Delete datarecord from database */
|
|
/* info->rec_cache.seek_not_done is updated in cmp_record */
|
|
|
|
static int delete_dynamic_record(MI_INFO *info, my_off_t filepos,
|
|
uint second_read)
|
|
{
|
|
uint length,b_type;
|
|
MI_BLOCK_INFO block_info,del_block;
|
|
int error;
|
|
my_bool remove_next_block;
|
|
DBUG_ENTER("delete_dynamic_record");
|
|
|
|
/* First add a link from the last block to the new one */
|
|
error= update_backward_delete_link(info, info->s->state.dellink, filepos);
|
|
|
|
block_info.second_read=second_read;
|
|
do
|
|
{
|
|
/* Remove block at 'filepos' */
|
|
if ((b_type=_mi_get_block_info(&block_info,info->dfile,filepos))
|
|
& (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR |
|
|
BLOCK_FATAL_ERROR) ||
|
|
(length=(uint) (block_info.filepos-filepos) +block_info.block_len) <
|
|
MI_MIN_BLOCK_LENGTH)
|
|
{
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
DBUG_RETURN(1);
|
|
}
|
|
/* Check if next block is a delete block */
|
|
del_block.second_read=0;
|
|
remove_next_block=0;
|
|
if (_mi_get_block_info(&del_block,info->dfile,filepos+length) &
|
|
BLOCK_DELETED && del_block.block_len+length < MI_DYN_MAX_BLOCK_LENGTH)
|
|
{
|
|
/* We can't remove this yet as this block may be the head block */
|
|
remove_next_block=1;
|
|
length+=del_block.block_len;
|
|
}
|
|
|
|
block_info.header[0]=0;
|
|
mi_int3store(block_info.header+1,length);
|
|
mi_sizestore(block_info.header+4,info->s->state.dellink);
|
|
if (b_type & BLOCK_LAST)
|
|
bfill(block_info.header+12,8,255);
|
|
else
|
|
mi_sizestore(block_info.header+12,block_info.next_filepos);
|
|
if (info->s->file_write(info,(uchar*) block_info.header,20,filepos,
|
|
MYF(MY_NABP)))
|
|
DBUG_RETURN(1);
|
|
info->s->state.dellink = filepos;
|
|
info->state->del++;
|
|
info->state->empty+=length;
|
|
filepos=block_info.next_filepos;
|
|
|
|
/* Now it's safe to unlink the deleted block directly after this one */
|
|
if (remove_next_block && unlink_deleted_block(info,&del_block))
|
|
error=1;
|
|
} while (!(b_type & BLOCK_LAST));
|
|
|
|
DBUG_RETURN(error);
|
|
}
|
|
|
|
|
|
/* Write a block to datafile */
|
|
|
|
int _mi_write_part_record(MI_INFO *info,
|
|
my_off_t filepos, /* points at empty block */
|
|
ulong length, /* length of block */
|
|
my_off_t next_filepos,/* Next empty block */
|
|
uchar **record, /* pointer to record ptr */
|
|
ulong *reclength, /* length of *record */
|
|
int *flag) /* *flag == 0 if header */
|
|
{
|
|
ulong head_length,res_length,extra_length,long_block,del_length;
|
|
uchar *pos,*record_end;
|
|
my_off_t next_delete_block;
|
|
uchar temp[MI_SPLIT_LENGTH+MI_DYN_DELETE_BLOCK_HEADER];
|
|
DBUG_ENTER("_mi_write_part_record");
|
|
|
|
next_delete_block=HA_OFFSET_ERROR;
|
|
|
|
res_length=extra_length=0;
|
|
if (length > *reclength + MI_SPLIT_LENGTH)
|
|
{ /* Splitt big block */
|
|
res_length=MY_ALIGN(length- *reclength - MI_EXTEND_BLOCK_LENGTH,
|
|
MI_DYN_ALIGN_SIZE);
|
|
length-= res_length; /* Use this for first part */
|
|
}
|
|
long_block= (length < 65520L && *reclength < 65520L) ? 0 : 1;
|
|
if (length == *reclength+ 3 + long_block)
|
|
{
|
|
/* Block is exactly of the right length */
|
|
temp[0]=(uchar) (1+ *flag)+(uchar) long_block; /* Flag is 0 or 6 */
|
|
if (long_block)
|
|
{
|
|
mi_int3store(temp+1,*reclength);
|
|
head_length=4;
|
|
}
|
|
else
|
|
{
|
|
mi_int2store(temp+1,*reclength);
|
|
head_length=3;
|
|
}
|
|
}
|
|
else if (length-long_block < *reclength+4)
|
|
{ /* To short block */
|
|
if (next_filepos == HA_OFFSET_ERROR)
|
|
next_filepos= (info->s->state.dellink != HA_OFFSET_ERROR &&
|
|
!info->append_insert_at_end ?
|
|
info->s->state.dellink : info->state->data_file_length);
|
|
if (*flag == 0) /* First block */
|
|
{
|
|
if (*reclength > MI_MAX_BLOCK_LENGTH)
|
|
{
|
|
head_length= 16;
|
|
temp[0]=13;
|
|
mi_int4store(temp+1,*reclength);
|
|
mi_int3store(temp+5,length-head_length);
|
|
mi_sizestore((uchar*) temp+8,next_filepos);
|
|
}
|
|
else
|
|
{
|
|
head_length=5+8+long_block*2;
|
|
temp[0]=5+(uchar) long_block;
|
|
if (long_block)
|
|
{
|
|
mi_int3store(temp+1,*reclength);
|
|
mi_int3store(temp+4,length-head_length);
|
|
mi_sizestore((uchar*) temp+7,next_filepos);
|
|
}
|
|
else
|
|
{
|
|
mi_int2store(temp+1,*reclength);
|
|
mi_int2store(temp+3,length-head_length);
|
|
mi_sizestore((uchar*) temp+5,next_filepos);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
head_length=3+8+long_block;
|
|
temp[0]=11+(uchar) long_block;
|
|
if (long_block)
|
|
{
|
|
mi_int3store(temp+1,length-head_length);
|
|
mi_sizestore((uchar*) temp+4,next_filepos);
|
|
}
|
|
else
|
|
{
|
|
mi_int2store(temp+1,length-head_length);
|
|
mi_sizestore((uchar*) temp+3,next_filepos);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{ /* Block with empty info last */
|
|
head_length=4+long_block;
|
|
extra_length= length- *reclength-head_length;
|
|
temp[0]= (uchar) (3+ *flag)+(uchar) long_block; /* 3,4 or 9,10 */
|
|
if (long_block)
|
|
{
|
|
mi_int3store(temp+1,*reclength);
|
|
temp[4]= (uchar) (extra_length);
|
|
}
|
|
else
|
|
{
|
|
mi_int2store(temp+1,*reclength);
|
|
temp[3]= (uchar) (extra_length);
|
|
}
|
|
length= *reclength+head_length; /* Write only what is needed */
|
|
}
|
|
DBUG_DUMP("header",(uchar*) temp,head_length);
|
|
|
|
/* Make a long block for one write */
|
|
record_end= *record+length-head_length;
|
|
del_length=(res_length ? MI_DYN_DELETE_BLOCK_HEADER : 0);
|
|
bmove((uchar*) (*record-head_length),(uchar*) temp,head_length);
|
|
memcpy(temp,record_end,(size_t) (extra_length+del_length));
|
|
bzero((uchar*) record_end,extra_length);
|
|
|
|
if (res_length)
|
|
{
|
|
/* Check first if we can join this block with the next one */
|
|
MI_BLOCK_INFO del_block;
|
|
my_off_t next_block=filepos+length+extra_length+res_length;
|
|
|
|
del_block.second_read=0;
|
|
if (next_block < info->state->data_file_length &&
|
|
info->s->state.dellink != HA_OFFSET_ERROR)
|
|
{
|
|
if ((_mi_get_block_info(&del_block,info->dfile,next_block)
|
|
& BLOCK_DELETED) &&
|
|
res_length + del_block.block_len < MI_DYN_MAX_BLOCK_LENGTH)
|
|
{
|
|
if (unlink_deleted_block(info,&del_block))
|
|
goto err;
|
|
res_length+=del_block.block_len;
|
|
}
|
|
}
|
|
|
|
/* Create a delete link of the last part of the block */
|
|
pos=record_end+extra_length;
|
|
pos[0]= '\0';
|
|
mi_int3store(pos+1,res_length);
|
|
mi_sizestore(pos+4,info->s->state.dellink);
|
|
bfill(pos+12,8,255); /* End link */
|
|
next_delete_block=info->s->state.dellink;
|
|
info->s->state.dellink= filepos+length+extra_length;
|
|
info->state->del++;
|
|
info->state->empty+=res_length;
|
|
info->s->state.split++;
|
|
}
|
|
if (info->opt_flag & WRITE_CACHE_USED &&
|
|
info->update & HA_STATE_WRITE_AT_END)
|
|
{
|
|
if (info->update & HA_STATE_EXTEND_BLOCK)
|
|
{
|
|
info->update&= ~HA_STATE_EXTEND_BLOCK;
|
|
if (my_block_write(&info->rec_cache,(uchar*) *record-head_length,
|
|
length+extra_length+del_length,filepos))
|
|
goto err;
|
|
}
|
|
else if (my_b_write(&info->rec_cache,(uchar*) *record-head_length,
|
|
length+extra_length+del_length))
|
|
goto err;
|
|
}
|
|
else
|
|
{
|
|
info->rec_cache.seek_not_done=1;
|
|
if (info->s->file_write(info,(uchar*) *record-head_length,length+extra_length+
|
|
del_length,filepos,info->s->write_flag))
|
|
goto err;
|
|
}
|
|
memcpy(record_end,temp,(size_t) (extra_length+del_length));
|
|
*record=record_end;
|
|
*reclength-=(length-head_length);
|
|
*flag=6;
|
|
|
|
if (del_length)
|
|
{
|
|
/* link the next delete block to this */
|
|
if (update_backward_delete_link(info, next_delete_block,
|
|
info->s->state.dellink))
|
|
goto err;
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
err:
|
|
DBUG_PRINT("exit",("errno: %d",my_errno));
|
|
DBUG_RETURN(1);
|
|
} /*_mi_write_part_record */
|
|
|
|
|
|
/* update record from datafile */
|
|
|
|
static int update_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *record,
|
|
ulong reclength)
|
|
{
|
|
int flag;
|
|
uint error;
|
|
ulong length;
|
|
MI_BLOCK_INFO block_info;
|
|
DBUG_ENTER("update_dynamic_record");
|
|
|
|
flag=block_info.second_read=0;
|
|
while (reclength > 0)
|
|
{
|
|
if (filepos != info->s->state.dellink)
|
|
{
|
|
block_info.next_filepos= HA_OFFSET_ERROR;
|
|
if ((error=_mi_get_block_info(&block_info,info->dfile,filepos))
|
|
& (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR |
|
|
BLOCK_FATAL_ERROR))
|
|
{
|
|
DBUG_PRINT("error",("Got wrong block info"));
|
|
if (!(error & BLOCK_FATAL_ERROR))
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
goto err;
|
|
}
|
|
length=(ulong) (block_info.filepos-filepos) + block_info.block_len;
|
|
if (length < reclength)
|
|
{
|
|
uint tmp=MY_ALIGN(reclength - length + 3 +
|
|
test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
|
|
/* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
|
|
tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
|
|
/* Check if we can extend this block */
|
|
if (block_info.filepos + block_info.block_len ==
|
|
info->state->data_file_length &&
|
|
info->state->data_file_length <
|
|
info->s->base.max_data_file_length-tmp)
|
|
{
|
|
/* extend file */
|
|
DBUG_PRINT("info",("Extending file with %d bytes",tmp));
|
|
if (info->nextpos == info->state->data_file_length)
|
|
info->nextpos+= tmp;
|
|
info->state->data_file_length+= tmp;
|
|
info->update|= HA_STATE_WRITE_AT_END | HA_STATE_EXTEND_BLOCK;
|
|
length+=tmp;
|
|
}
|
|
else if (length < MI_MAX_BLOCK_LENGTH - MI_MIN_BLOCK_LENGTH)
|
|
{
|
|
/*
|
|
Check if next block is a deleted block
|
|
Above we have MI_MIN_BLOCK_LENGTH to avoid the problem where
|
|
the next block is so small it can't be splited which could
|
|
casue problems
|
|
*/
|
|
|
|
MI_BLOCK_INFO del_block;
|
|
del_block.second_read=0;
|
|
if (_mi_get_block_info(&del_block,info->dfile,
|
|
block_info.filepos + block_info.block_len) &
|
|
BLOCK_DELETED)
|
|
{
|
|
/* Use; Unlink it and extend the current block */
|
|
DBUG_PRINT("info",("Extending current block"));
|
|
if (unlink_deleted_block(info,&del_block))
|
|
goto err;
|
|
if ((length+=del_block.block_len) > MI_MAX_BLOCK_LENGTH)
|
|
{
|
|
/*
|
|
New block was too big, link overflow part back to
|
|
delete list
|
|
*/
|
|
my_off_t next_pos;
|
|
ulong rest_length= length-MI_MAX_BLOCK_LENGTH;
|
|
set_if_bigger(rest_length, MI_MIN_BLOCK_LENGTH);
|
|
next_pos= del_block.filepos+ del_block.block_len - rest_length;
|
|
|
|
if (update_backward_delete_link(info, info->s->state.dellink,
|
|
next_pos))
|
|
DBUG_RETURN(1);
|
|
|
|
/* create delete link for data that didn't fit into the page */
|
|
del_block.header[0]=0;
|
|
mi_int3store(del_block.header+1, rest_length);
|
|
mi_sizestore(del_block.header+4,info->s->state.dellink);
|
|
bfill(del_block.header+12,8,255);
|
|
if (info->s->file_write(info,(uchar*) del_block.header,20, next_pos,
|
|
MYF(MY_NABP)))
|
|
DBUG_RETURN(1);
|
|
info->s->state.dellink= next_pos;
|
|
info->s->state.split++;
|
|
info->state->del++;
|
|
info->state->empty+= rest_length;
|
|
length-= rest_length;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_mi_find_writepos(info,reclength,&filepos,&length))
|
|
goto err;
|
|
}
|
|
if (_mi_write_part_record(info,filepos,length,block_info.next_filepos,
|
|
&record,&reclength,&flag))
|
|
goto err;
|
|
if ((filepos=block_info.next_filepos) == HA_OFFSET_ERROR)
|
|
{
|
|
/* Start writing data on deleted blocks */
|
|
filepos=info->s->state.dellink;
|
|
}
|
|
}
|
|
|
|
if (block_info.next_filepos != HA_OFFSET_ERROR)
|
|
if (delete_dynamic_record(info,block_info.next_filepos,1))
|
|
goto err;
|
|
DBUG_RETURN(0);
|
|
err:
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
|
|
/* Pack a record. Return new reclength */
|
|
|
|
uint _mi_rec_pack(MI_INFO *info, register uchar *to,
|
|
register const uchar *from)
|
|
{
|
|
uint length,new_length,flag,bit,i;
|
|
uchar *pos,*end,*startpos,*packpos;
|
|
enum en_fieldtype type;
|
|
reg3 MI_COLUMNDEF *rec;
|
|
MI_BLOB *blob;
|
|
DBUG_ENTER("_mi_rec_pack");
|
|
|
|
flag=0 ; bit=1;
|
|
startpos=packpos=to; to+= info->s->base.pack_bits; blob=info->blobs;
|
|
rec=info->s->rec;
|
|
|
|
for (i=info->s->base.fields ; i-- > 0; from+= length,rec++)
|
|
{
|
|
length=(uint) rec->length;
|
|
if ((type = (enum en_fieldtype) rec->type) != FIELD_NORMAL)
|
|
{
|
|
if (type == FIELD_BLOB)
|
|
{
|
|
if (!blob->length)
|
|
flag|=bit;
|
|
else
|
|
{
|
|
char *temp_pos;
|
|
size_t tmp_length=length-mi_portable_sizeof_char_ptr;
|
|
memcpy((uchar*) to,from,tmp_length);
|
|
memcpy_fixed(&temp_pos,from+tmp_length,sizeof(char*));
|
|
memcpy(to+tmp_length,temp_pos,(size_t) blob->length);
|
|
to+=tmp_length+blob->length;
|
|
}
|
|
blob++;
|
|
}
|
|
else if (type == FIELD_SKIP_ZERO)
|
|
{
|
|
if (memcmp((uchar*) from,zero_string,length) == 0)
|
|
flag|=bit;
|
|
else
|
|
{
|
|
memcpy((uchar*) to,from,(size_t) length); to+=length;
|
|
}
|
|
}
|
|
else if (type == FIELD_SKIP_ENDSPACE ||
|
|
type == FIELD_SKIP_PRESPACE)
|
|
{
|
|
pos= (uchar*) from; end= (uchar*) from + length;
|
|
if (type == FIELD_SKIP_ENDSPACE)
|
|
{ /* Pack trailing spaces */
|
|
while (end > from && *(end-1) == ' ')
|
|
end--;
|
|
}
|
|
else
|
|
{ /* Pack pref-spaces */
|
|
while (pos < end && *pos == ' ')
|
|
pos++;
|
|
}
|
|
new_length=(uint) (end-pos);
|
|
if (new_length +1 + test(rec->length > 255 && new_length > 127)
|
|
< length)
|
|
{
|
|
if (rec->length > 255 && new_length > 127)
|
|
{
|
|
to[0]=(char) ((new_length & 127)+128);
|
|
to[1]=(char) (new_length >> 7);
|
|
to+=2;
|
|
}
|
|
else
|
|
*to++= (char) new_length;
|
|
memcpy((uchar*) to,pos,(size_t) new_length); to+=new_length;
|
|
flag|=bit;
|
|
}
|
|
else
|
|
{
|
|
memcpy(to,from,(size_t) length); to+=length;
|
|
}
|
|
}
|
|
else if (type == FIELD_VARCHAR)
|
|
{
|
|
uint pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
|
|
uint tmp_length;
|
|
if (pack_length == 1)
|
|
{
|
|
tmp_length= (uint) *(uchar*) from;
|
|
*to++= *from;
|
|
}
|
|
else
|
|
{
|
|
tmp_length= uint2korr(from);
|
|
store_key_length_inc(to,tmp_length);
|
|
}
|
|
memcpy(to, from+pack_length,tmp_length);
|
|
to+= tmp_length;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
memcpy(to,from,(size_t) length); to+=length;
|
|
continue; /* Normal field */
|
|
}
|
|
if ((bit= bit << 1) >= 256)
|
|
{
|
|
*packpos++ = (char) (uchar) flag;
|
|
bit=1; flag=0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
memcpy(to,from,(size_t) length); to+=length;
|
|
}
|
|
}
|
|
if (bit != 1)
|
|
*packpos= (char) (uchar) flag;
|
|
if (info->s->calc_checksum)
|
|
*to++=(char) info->checksum;
|
|
DBUG_PRINT("exit",("packed length: %d",(int) (to-startpos)));
|
|
DBUG_RETURN((uint) (to-startpos));
|
|
} /* _mi_rec_pack */
|
|
|
|
|
|
|
|
/*
|
|
Check if a record was correctly packed. Used only by myisamchk
|
|
Returns 0 if record is ok.
|
|
*/
|
|
|
|
my_bool _mi_rec_check(MI_INFO *info,const uchar *record, uchar *rec_buff,
|
|
ulong packed_length, my_bool with_checksum)
|
|
{
|
|
uint length,new_length,flag,bit,i;
|
|
uchar *pos,*end,*packpos,*to;
|
|
enum en_fieldtype type;
|
|
reg3 MI_COLUMNDEF *rec;
|
|
DBUG_ENTER("_mi_rec_check");
|
|
|
|
packpos=rec_buff; to= rec_buff+info->s->base.pack_bits;
|
|
rec=info->s->rec;
|
|
flag= *packpos; bit=1;
|
|
|
|
for (i=info->s->base.fields ; i-- > 0; record+= length, rec++)
|
|
{
|
|
length=(uint) rec->length;
|
|
if ((type = (enum en_fieldtype) rec->type) != FIELD_NORMAL)
|
|
{
|
|
if (type == FIELD_BLOB)
|
|
{
|
|
uint blob_length=
|
|
_mi_calc_blob_length(length-mi_portable_sizeof_char_ptr,record);
|
|
if (!blob_length && !(flag & bit))
|
|
goto err;
|
|
if (blob_length)
|
|
to+=length - mi_portable_sizeof_char_ptr+ blob_length;
|
|
}
|
|
else if (type == FIELD_SKIP_ZERO)
|
|
{
|
|
if (memcmp((uchar*) record,zero_string,length) == 0)
|
|
{
|
|
if (!(flag & bit))
|
|
goto err;
|
|
}
|
|
else
|
|
to+=length;
|
|
}
|
|
else if (type == FIELD_SKIP_ENDSPACE ||
|
|
type == FIELD_SKIP_PRESPACE)
|
|
{
|
|
pos= (uchar*) record; end= (uchar*) record + length;
|
|
if (type == FIELD_SKIP_ENDSPACE)
|
|
{ /* Pack trailing spaces */
|
|
while (end > record && *(end-1) == ' ')
|
|
end--;
|
|
}
|
|
else
|
|
{ /* Pack pre-spaces */
|
|
while (pos < end && *pos == ' ')
|
|
pos++;
|
|
}
|
|
new_length=(uint) (end-pos);
|
|
if (new_length +1 + test(rec->length > 255 && new_length > 127)
|
|
< length)
|
|
{
|
|
if (!(flag & bit))
|
|
goto err;
|
|
if (rec->length > 255 && new_length > 127)
|
|
{
|
|
if (to[0] != (char) ((new_length & 127)+128) ||
|
|
to[1] != (char) (new_length >> 7))
|
|
goto err;
|
|
to+=2;
|
|
}
|
|
else if (*to++ != (char) new_length)
|
|
goto err;
|
|
to+=new_length;
|
|
}
|
|
else
|
|
to+=length;
|
|
}
|
|
else if (type == FIELD_VARCHAR)
|
|
{
|
|
uint pack_length= HA_VARCHAR_PACKLENGTH(rec->length -1);
|
|
uint tmp_length;
|
|
if (pack_length == 1)
|
|
{
|
|
tmp_length= (uint) *(uchar*) record;
|
|
to+= 1+ tmp_length;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
tmp_length= uint2korr(record);
|
|
to+= get_pack_length(tmp_length)+tmp_length;
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
to+=length;
|
|
continue; /* Normal field */
|
|
}
|
|
if ((bit= bit << 1) >= 256)
|
|
{
|
|
flag= *++packpos;
|
|
bit=1;
|
|
}
|
|
}
|
|
else
|
|
to+= length;
|
|
}
|
|
if (packed_length != (uint) (to - rec_buff) + test(info->s->calc_checksum) ||
|
|
(bit != 1 && (flag & ~(bit - 1))))
|
|
goto err;
|
|
if (with_checksum && ((uchar) info->checksum != (uchar) *to))
|
|
{
|
|
DBUG_PRINT("error",("wrong checksum for row"));
|
|
goto err;
|
|
}
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
|
|
|
|
/* Unpacks a record */
|
|
/* Returns -1 and my_errno =HA_ERR_RECORD_DELETED if reclength isn't */
|
|
/* right. Returns reclength (>0) if ok */
|
|
|
|
ulong _mi_rec_unpack(register MI_INFO *info, register uchar *to, uchar *from,
|
|
ulong found_length)
|
|
{
|
|
uint flag,bit,length,rec_length,min_pack_length;
|
|
enum en_fieldtype type;
|
|
uchar *from_end,*to_end,*packpos;
|
|
reg3 MI_COLUMNDEF *rec,*end_field;
|
|
DBUG_ENTER("_mi_rec_unpack");
|
|
|
|
to_end=to + info->s->base.reclength;
|
|
from_end=from+found_length;
|
|
flag= (uchar) *from; bit=1; packpos=from;
|
|
if (found_length < info->s->base.min_pack_length)
|
|
goto err;
|
|
from+= info->s->base.pack_bits;
|
|
min_pack_length=info->s->base.min_pack_length - info->s->base.pack_bits;
|
|
|
|
for (rec=info->s->rec , end_field=rec+info->s->base.fields ;
|
|
rec < end_field ; to+= rec_length, rec++)
|
|
{
|
|
rec_length=rec->length;
|
|
if ((type = (enum en_fieldtype) rec->type) != FIELD_NORMAL &&
|
|
(type != FIELD_CHECK))
|
|
{
|
|
if (type == FIELD_VARCHAR)
|
|
{
|
|
uint pack_length= HA_VARCHAR_PACKLENGTH(rec_length-1);
|
|
if (pack_length == 1)
|
|
{
|
|
length= (uint) *(uchar*) from;
|
|
if (length > rec_length-1)
|
|
goto err;
|
|
*to= *from++;
|
|
}
|
|
else
|
|
{
|
|
get_key_length(length, from);
|
|
if (length > rec_length-2)
|
|
goto err;
|
|
int2store(to,length);
|
|
}
|
|
if (from+length > from_end)
|
|
goto err;
|
|
memcpy(to+pack_length, from, length);
|
|
from+= length;
|
|
min_pack_length--;
|
|
continue;
|
|
}
|
|
if (flag & bit)
|
|
{
|
|
if (type == FIELD_BLOB || type == FIELD_SKIP_ZERO)
|
|
bzero((uchar*) to,rec_length);
|
|
else if (type == FIELD_SKIP_ENDSPACE ||
|
|
type == FIELD_SKIP_PRESPACE)
|
|
{
|
|
if (rec->length > 255 && *from & 128)
|
|
{
|
|
if (from + 1 >= from_end)
|
|
goto err;
|
|
length= (*from & 127)+ ((uint) (uchar) *(from+1) << 7); from+=2;
|
|
}
|
|
else
|
|
{
|
|
if (from == from_end)
|
|
goto err;
|
|
length= (uchar) *from++;
|
|
}
|
|
min_pack_length--;
|
|
if (length >= rec_length ||
|
|
min_pack_length + length > (uint) (from_end - from))
|
|
goto err;
|
|
if (type == FIELD_SKIP_ENDSPACE)
|
|
{
|
|
memcpy(to,(uchar*) from,(size_t) length);
|
|
bfill((uchar*) to+length,rec_length-length,' ');
|
|
}
|
|
else
|
|
{
|
|
bfill((uchar*) to,rec_length-length,' ');
|
|
memcpy(to+rec_length-length,(uchar*) from,(size_t) length);
|
|
}
|
|
from+=length;
|
|
}
|
|
}
|
|
else if (type == FIELD_BLOB)
|
|
{
|
|
uint size_length=rec_length- mi_portable_sizeof_char_ptr;
|
|
ulong blob_length=_mi_calc_blob_length(size_length,from);
|
|
ulong from_left= (ulong) (from_end - from);
|
|
if (from_left < size_length ||
|
|
from_left - size_length < blob_length ||
|
|
from_left - size_length - blob_length < min_pack_length)
|
|
goto err;
|
|
memcpy((uchar*) to,(uchar*) from,(size_t) size_length);
|
|
from+=size_length;
|
|
memcpy_fixed((uchar*) to+size_length,(uchar*) &from,sizeof(char*));
|
|
from+=blob_length;
|
|
}
|
|
else
|
|
{
|
|
if (type == FIELD_SKIP_ENDSPACE || type == FIELD_SKIP_PRESPACE)
|
|
min_pack_length--;
|
|
if (min_pack_length + rec_length > (uint) (from_end - from))
|
|
goto err;
|
|
memcpy(to,(uchar*) from,(size_t) rec_length); from+=rec_length;
|
|
}
|
|
if ((bit= bit << 1) >= 256)
|
|
{
|
|
flag= (uchar) *++packpos; bit=1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (min_pack_length > (uint) (from_end - from))
|
|
goto err;
|
|
min_pack_length-=rec_length;
|
|
memcpy(to, (uchar*) from, (size_t) rec_length);
|
|
from+=rec_length;
|
|
}
|
|
}
|
|
if (info->s->calc_checksum)
|
|
from++;
|
|
if (to == to_end && from == from_end && (bit == 1 || !(flag & ~(bit-1))))
|
|
DBUG_RETURN(found_length);
|
|
|
|
err:
|
|
my_errno= HA_ERR_WRONG_IN_RECORD;
|
|
DBUG_PRINT("error",("to_end: 0x%lx -> 0x%lx from_end: 0x%lx -> 0x%lx",
|
|
(long) to, (long) to_end, (long) from, (long) from_end));
|
|
DBUG_DUMP("from",(uchar*) info->rec_buff,info->s->base.min_pack_length);
|
|
DBUG_RETURN(MY_FILE_ERROR);
|
|
} /* _mi_rec_unpack */
|
|
|
|
|
|
/* Calc length of blob. Update info in blobs->length */
|
|
|
|
ulong _my_calc_total_blob_length(MI_INFO *info, const uchar *record)
|
|
{
|
|
ulong length;
|
|
MI_BLOB *blob,*end;
|
|
|
|
for (length=0, blob= info->blobs, end=blob+info->s->base.blobs ;
|
|
blob != end;
|
|
blob++)
|
|
{
|
|
blob->length=_mi_calc_blob_length(blob->pack_length,record + blob->offset);
|
|
length+=blob->length;
|
|
}
|
|
return length;
|
|
}
|
|
|
|
|
|
ulong _mi_calc_blob_length(uint length, const uchar *pos)
|
|
{
|
|
switch (length) {
|
|
case 1:
|
|
return (uint) (uchar) *pos;
|
|
case 2:
|
|
return (uint) uint2korr(pos);
|
|
case 3:
|
|
return uint3korr(pos);
|
|
case 4:
|
|
return uint4korr(pos);
|
|
default:
|
|
break;
|
|
}
|
|
return 0; /* Impossible */
|
|
}
|
|
|
|
|
|
void _my_store_blob_length(uchar *pos,uint pack_length,uint length)
|
|
{
|
|
switch (pack_length) {
|
|
case 1:
|
|
*pos= (uchar) length;
|
|
break;
|
|
case 2:
|
|
int2store(pos,length);
|
|
break;
|
|
case 3:
|
|
int3store(pos,length);
|
|
break;
|
|
case 4:
|
|
int4store(pos,length);
|
|
default:
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
/*
|
|
Read record from datafile.
|
|
|
|
SYNOPSIS
|
|
_mi_read_dynamic_record()
|
|
info MI_INFO pointer to table.
|
|
filepos From where to read the record.
|
|
buf Destination for record.
|
|
|
|
NOTE
|
|
|
|
If a write buffer is active, it needs to be flushed if its contents
|
|
intersects with the record to read. We always check if the position
|
|
of the first byte of the write buffer is lower than the position
|
|
past the last byte to read. In theory this is also true if the write
|
|
buffer is completely below the read segment. That is, if there is no
|
|
intersection. But this case is unusual. We flush anyway. Only if the
|
|
first byte in the write buffer is above the last byte to read, we do
|
|
not flush.
|
|
|
|
A dynamic record may need several reads. So this check must be done
|
|
before every read. Reading a dynamic record starts with reading the
|
|
block header. If the record does not fit into the free space of the
|
|
header, the block may be longer than the header. In this case a
|
|
second read is necessary. These one or two reads repeat for every
|
|
part of the record.
|
|
|
|
RETURN
|
|
0 OK
|
|
-1 Error
|
|
*/
|
|
|
|
int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, uchar *buf)
|
|
{
|
|
int block_of_record;
|
|
uint b_type,left_length;
|
|
uchar *to;
|
|
MI_BLOCK_INFO block_info;
|
|
File file;
|
|
DBUG_ENTER("mi_read_dynamic_record");
|
|
|
|
if (filepos != HA_OFFSET_ERROR)
|
|
{
|
|
LINT_INIT(to);
|
|
LINT_INIT(left_length);
|
|
file=info->dfile;
|
|
block_of_record= 0; /* First block of record is numbered as zero. */
|
|
block_info.second_read= 0;
|
|
do
|
|
{
|
|
/* A corrupted table can have wrong pointers. (Bug# 19835) */
|
|
if (filepos == HA_OFFSET_ERROR)
|
|
goto panic;
|
|
if (info->opt_flag & WRITE_CACHE_USED &&
|
|
info->rec_cache.pos_in_file < filepos + MI_BLOCK_INFO_HEADER_LENGTH &&
|
|
flush_io_cache(&info->rec_cache))
|
|
goto err;
|
|
info->rec_cache.seek_not_done=1;
|
|
if ((b_type= _mi_get_block_info(&block_info, file, filepos))
|
|
& (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR |
|
|
BLOCK_FATAL_ERROR))
|
|
{
|
|
if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
|
|
my_errno=HA_ERR_RECORD_DELETED;
|
|
goto err;
|
|
}
|
|
if (block_of_record++ == 0) /* First block */
|
|
{
|
|
if (block_info.rec_len > (uint) info->s->base.max_pack_length)
|
|
goto panic;
|
|
if (info->s->base.blobs)
|
|
{
|
|
if (!(to=mi_alloc_rec_buff(info, block_info.rec_len,
|
|
&info->rec_buff)))
|
|
goto err;
|
|
}
|
|
else
|
|
to= info->rec_buff;
|
|
left_length=block_info.rec_len;
|
|
}
|
|
if (left_length < block_info.data_len || ! block_info.data_len)
|
|
goto panic; /* Wrong linked record */
|
|
/* copy information that is already read */
|
|
{
|
|
uint offset= (uint) (block_info.filepos - filepos);
|
|
uint prefetch_len= (sizeof(block_info.header) - offset);
|
|
filepos+= sizeof(block_info.header);
|
|
|
|
if (prefetch_len > block_info.data_len)
|
|
prefetch_len= block_info.data_len;
|
|
if (prefetch_len)
|
|
{
|
|
memcpy((uchar*) to, block_info.header + offset, prefetch_len);
|
|
block_info.data_len-= prefetch_len;
|
|
left_length-= prefetch_len;
|
|
to+= prefetch_len;
|
|
}
|
|
}
|
|
/* read rest of record from file */
|
|
if (block_info.data_len)
|
|
{
|
|
if (info->opt_flag & WRITE_CACHE_USED &&
|
|
info->rec_cache.pos_in_file < filepos + block_info.data_len &&
|
|
flush_io_cache(&info->rec_cache))
|
|
goto err;
|
|
/*
|
|
What a pity that this method is not called 'file_pread' and that
|
|
there is no equivalent without seeking. We are at the right
|
|
position already. :(
|
|
*/
|
|
if (info->s->file_read(info, (uchar*) to, block_info.data_len,
|
|
filepos, MYF(MY_NABP)))
|
|
goto panic;
|
|
left_length-=block_info.data_len;
|
|
to+=block_info.data_len;
|
|
}
|
|
filepos= block_info.next_filepos;
|
|
} while (left_length);
|
|
|
|
info->update|= HA_STATE_AKTIV; /* We have a aktive record */
|
|
fast_mi_writeinfo(info);
|
|
DBUG_RETURN(_mi_rec_unpack(info,buf,info->rec_buff,block_info.rec_len) !=
|
|
MY_FILE_ERROR ? 0 : -1);
|
|
}
|
|
fast_mi_writeinfo(info);
|
|
DBUG_RETURN(-1); /* Wrong data to read */
|
|
|
|
panic:
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
err:
|
|
VOID(_mi_writeinfo(info,0));
|
|
DBUG_RETURN(-1);
|
|
}
|
|
|
|
/* compare unique constraint between stored rows */
|
|
|
|
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
|
|
const uchar *record, my_off_t pos)
|
|
{
|
|
uchar *rec_buff,*old_record;
|
|
int error;
|
|
DBUG_ENTER("_mi_cmp_dynamic_unique");
|
|
|
|
if (!(old_record=my_alloca(info->s->base.reclength)))
|
|
DBUG_RETURN(1);
|
|
|
|
/* Don't let the compare destroy blobs that may be in use */
|
|
rec_buff=info->rec_buff;
|
|
if (info->s->base.blobs)
|
|
info->rec_buff=0;
|
|
error=_mi_read_dynamic_record(info,pos,old_record);
|
|
if (!error)
|
|
error=mi_unique_comp(def, record, old_record, def->null_are_equal);
|
|
if (info->s->base.blobs)
|
|
{
|
|
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
|
|
info->rec_buff=rec_buff;
|
|
}
|
|
my_afree(old_record);
|
|
DBUG_RETURN(error);
|
|
}
|
|
|
|
|
|
/* Compare of record one disk with packed record in memory */
|
|
|
|
int _mi_cmp_dynamic_record(register MI_INFO *info, register const uchar *record)
|
|
{
|
|
uint flag,reclength,b_type;
|
|
my_off_t filepos;
|
|
uchar *buffer;
|
|
MI_BLOCK_INFO block_info;
|
|
DBUG_ENTER("_mi_cmp_dynamic_record");
|
|
|
|
/* We are going to do changes; dont let anybody disturb */
|
|
dont_break(); /* Dont allow SIGHUP or SIGINT */
|
|
|
|
if (info->opt_flag & WRITE_CACHE_USED)
|
|
{
|
|
info->update&= ~(HA_STATE_WRITE_AT_END | HA_STATE_EXTEND_BLOCK);
|
|
if (flush_io_cache(&info->rec_cache))
|
|
DBUG_RETURN(-1);
|
|
}
|
|
info->rec_cache.seek_not_done=1;
|
|
|
|
/* If nobody have touched the database we don't have to test rec */
|
|
|
|
buffer=info->rec_buff;
|
|
if ((info->opt_flag & READ_CHECK_USED))
|
|
{ /* If check isn't disabled */
|
|
if (info->s->base.blobs)
|
|
{
|
|
if (!(buffer=(uchar*) my_alloca(info->s->base.pack_reclength+
|
|
_my_calc_total_blob_length(info,record))))
|
|
DBUG_RETURN(-1);
|
|
}
|
|
reclength=_mi_rec_pack(info,buffer,record);
|
|
record= buffer;
|
|
|
|
filepos=info->lastpos;
|
|
flag=block_info.second_read=0;
|
|
block_info.next_filepos=filepos;
|
|
while (reclength > 0)
|
|
{
|
|
if ((b_type=_mi_get_block_info(&block_info,info->dfile,
|
|
block_info.next_filepos))
|
|
& (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR |
|
|
BLOCK_FATAL_ERROR))
|
|
{
|
|
if (b_type & (BLOCK_SYNC_ERROR | BLOCK_DELETED))
|
|
my_errno=HA_ERR_RECORD_CHANGED;
|
|
goto err;
|
|
}
|
|
if (flag == 0) /* First block */
|
|
{
|
|
flag=1;
|
|
if (reclength != block_info.rec_len)
|
|
{
|
|
my_errno=HA_ERR_RECORD_CHANGED;
|
|
goto err;
|
|
}
|
|
} else if (reclength < block_info.data_len)
|
|
{
|
|
my_errno=HA_ERR_WRONG_IN_RECORD;
|
|
goto err;
|
|
}
|
|
reclength-=block_info.data_len;
|
|
if (_mi_cmp_buffer(info->dfile,record,block_info.filepos,
|
|
block_info.data_len))
|
|
{
|
|
my_errno=HA_ERR_RECORD_CHANGED;
|
|
goto err;
|
|
}
|
|
flag=1;
|
|
record+=block_info.data_len;
|
|
}
|
|
}
|
|
my_errno=0;
|
|
err:
|
|
if (buffer != info->rec_buff)
|
|
my_afree((uchar*) buffer);
|
|
DBUG_RETURN(my_errno);
|
|
}
|
|
|
|
|
|
/* Compare file to buffert */
|
|
|
|
static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
|
|
uint length)
|
|
{
|
|
uint next_length;
|
|
char temp_buff[IO_SIZE*2];
|
|
DBUG_ENTER("_mi_cmp_buffer");
|
|
|
|
next_length= IO_SIZE*2 - (uint) (filepos & (IO_SIZE-1));
|
|
|
|
while (length > IO_SIZE*2)
|
|
{
|
|
if (my_pread(file,temp_buff,next_length,filepos, MYF(MY_NABP)) ||
|
|
memcmp((uchar*) buff,temp_buff,next_length))
|
|
goto err;
|
|
filepos+=next_length;
|
|
buff+=next_length;
|
|
length-= next_length;
|
|
next_length=IO_SIZE*2;
|
|
}
|
|
if (my_pread(file,temp_buff,length,filepos,MYF(MY_NABP)))
|
|
goto err;
|
|
DBUG_RETURN(memcmp((uchar*) buff,temp_buff,length));
|
|
err:
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
|
|
/*
|
|
Read record from datafile.
|
|
|
|
SYNOPSIS
|
|
_mi_read_rnd_dynamic_record()
|
|
info MI_INFO pointer to table.
|
|
buf Destination for record.
|
|
filepos From where to read the record.
|
|
skip_deleted_blocks If to repeat reading until a non-deleted
|
|
record is found.
|
|
|
|
NOTE
|
|
|
|
If a write buffer is active, it needs to be flushed if its contents
|
|
intersects with the record to read. We always check if the position
|
|
of the first byte of the write buffer is lower than the position
|
|
past the last byte to read. In theory this is also true if the write
|
|
buffer is completely below the read segment. That is, if there is no
|
|
intersection. But this case is unusual. We flush anyway. Only if the
|
|
first byte in the write buffer is above the last byte to read, we do
|
|
not flush.
|
|
|
|
A dynamic record may need several reads. So this check must be done
|
|
before every read. Reading a dynamic record starts with reading the
|
|
block header. If the record does not fit into the free space of the
|
|
header, the block may be longer than the header. In this case a
|
|
second read is necessary. These one or two reads repeat for every
|
|
part of the record.
|
|
|
|
RETURN
|
|
0 OK
|
|
!= 0 Error
|
|
*/
|
|
|
|
int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf,
|
|
register my_off_t filepos,
|
|
my_bool skip_deleted_blocks)
|
|
{
|
|
int block_of_record, info_read, save_errno;
|
|
uint left_len,b_type;
|
|
uchar *to;
|
|
MI_BLOCK_INFO block_info;
|
|
MYISAM_SHARE *share=info->s;
|
|
DBUG_ENTER("_mi_read_rnd_dynamic_record");
|
|
|
|
info_read=0;
|
|
LINT_INIT(to);
|
|
|
|
if (info->lock_type == F_UNLCK)
|
|
{
|
|
#ifndef UNSAFE_LOCKING
|
|
if (share->tot_locks == 0)
|
|
{
|
|
if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF,
|
|
MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
|
|
DBUG_RETURN(my_errno);
|
|
}
|
|
#else
|
|
info->tmp_lock_type=F_RDLCK;
|
|
#endif
|
|
}
|
|
else
|
|
info_read=1; /* memory-keyinfoblock is ok */
|
|
|
|
block_of_record= 0; /* First block of record is numbered as zero. */
|
|
block_info.second_read= 0;
|
|
left_len=1;
|
|
do
|
|
{
|
|
if (filepos >= info->state->data_file_length)
|
|
{
|
|
if (!info_read)
|
|
{ /* Check if changed */
|
|
info_read=1;
|
|
info->rec_cache.seek_not_done=1;
|
|
if (mi_state_info_read_dsk(share->kfile,&share->state,1))
|
|
goto panic;
|
|
}
|
|
if (filepos >= info->state->data_file_length)
|
|
{
|
|
my_errno= HA_ERR_END_OF_FILE;
|
|
goto err;
|
|
}
|
|
}
|
|
if (info->opt_flag & READ_CACHE_USED)
|
|
{
|
|
if (_mi_read_cache(&info->rec_cache,(uchar*) block_info.header,filepos,
|
|
sizeof(block_info.header),
|
|
(!block_of_record && skip_deleted_blocks ?
|
|
READING_NEXT : 0) | READING_HEADER))
|
|
goto panic;
|
|
b_type=_mi_get_block_info(&block_info,-1,filepos);
|
|
}
|
|
else
|
|
{
|
|
if (info->opt_flag & WRITE_CACHE_USED &&
|
|
info->rec_cache.pos_in_file < filepos + MI_BLOCK_INFO_HEADER_LENGTH &&
|
|
flush_io_cache(&info->rec_cache))
|
|
DBUG_RETURN(my_errno);
|
|
info->rec_cache.seek_not_done=1;
|
|
b_type=_mi_get_block_info(&block_info,info->dfile,filepos);
|
|
}
|
|
|
|
if (b_type & (BLOCK_DELETED | BLOCK_ERROR | BLOCK_SYNC_ERROR |
|
|
BLOCK_FATAL_ERROR))
|
|
{
|
|
if ((b_type & (BLOCK_DELETED | BLOCK_SYNC_ERROR))
|
|
&& skip_deleted_blocks)
|
|
{
|
|
filepos=block_info.filepos+block_info.block_len;
|
|
block_info.second_read=0;
|
|
continue; /* Search after next_record */
|
|
}
|
|
if (b_type & (BLOCK_DELETED | BLOCK_SYNC_ERROR))
|
|
{
|
|
my_errno=HA_ERR_RECORD_DELETED;
|
|
info->lastpos=block_info.filepos;
|
|
info->nextpos=block_info.filepos+block_info.block_len;
|
|
}
|
|
goto err;
|
|
}
|
|
if (block_of_record == 0) /* First block */
|
|
{
|
|
if (block_info.rec_len > (uint) share->base.max_pack_length)
|
|
goto panic;
|
|
info->lastpos=filepos;
|
|
if (share->base.blobs)
|
|
{
|
|
if (!(to= mi_alloc_rec_buff(info, block_info.rec_len,
|
|
&info->rec_buff)))
|
|
goto err;
|
|
}
|
|
else
|
|
to= info->rec_buff;
|
|
left_len=block_info.rec_len;
|
|
}
|
|
if (left_len < block_info.data_len)
|
|
goto panic; /* Wrong linked record */
|
|
|
|
/* copy information that is already read */
|
|
{
|
|
uint offset=(uint) (block_info.filepos - filepos);
|
|
uint tmp_length= (sizeof(block_info.header) - offset);
|
|
filepos=block_info.filepos;
|
|
|
|
if (tmp_length > block_info.data_len)
|
|
tmp_length= block_info.data_len;
|
|
if (tmp_length)
|
|
{
|
|
memcpy((uchar*) to, block_info.header+offset,tmp_length);
|
|
block_info.data_len-=tmp_length;
|
|
left_len-=tmp_length;
|
|
to+=tmp_length;
|
|
filepos+=tmp_length;
|
|
}
|
|
}
|
|
/* read rest of record from file */
|
|
if (block_info.data_len)
|
|
{
|
|
if (info->opt_flag & READ_CACHE_USED)
|
|
{
|
|
if (_mi_read_cache(&info->rec_cache,(uchar*) to,filepos,
|
|
block_info.data_len,
|
|
(!block_of_record && skip_deleted_blocks) ?
|
|
READING_NEXT : 0))
|
|
goto panic;
|
|
}
|
|
else
|
|
{
|
|
if (info->opt_flag & WRITE_CACHE_USED &&
|
|
info->rec_cache.pos_in_file <
|
|
block_info.filepos + block_info.data_len &&
|
|
flush_io_cache(&info->rec_cache))
|
|
goto err;
|
|
/* VOID(my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0))); */
|
|
if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP)))
|
|
{
|
|
if (my_errno == -1)
|
|
my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */
|
|
goto err;
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
Increment block-of-record counter. If it was the first block,
|
|
remember the position behind the block for the next call.
|
|
*/
|
|
if (block_of_record++ == 0)
|
|
{
|
|
info->nextpos= block_info.filepos + block_info.block_len;
|
|
skip_deleted_blocks= 0;
|
|
}
|
|
left_len-=block_info.data_len;
|
|
to+=block_info.data_len;
|
|
filepos=block_info.next_filepos;
|
|
} while (left_len);
|
|
|
|
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
|
|
fast_mi_writeinfo(info);
|
|
if (_mi_rec_unpack(info,buf,info->rec_buff,block_info.rec_len) !=
|
|
MY_FILE_ERROR)
|
|
DBUG_RETURN(0);
|
|
DBUG_RETURN(my_errno); /* Wrong record */
|
|
|
|
panic:
|
|
my_errno=HA_ERR_WRONG_IN_RECORD; /* Something is fatal wrong */
|
|
err:
|
|
save_errno=my_errno;
|
|
VOID(_mi_writeinfo(info,0));
|
|
DBUG_RETURN(my_errno=save_errno);
|
|
}
|
|
|
|
|
|
/* Read and process header from a dynamic-record-file */
|
|
|
|
uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos)
|
|
{
|
|
uint return_val=0;
|
|
uchar *header=info->header;
|
|
|
|
if (file >= 0)
|
|
{
|
|
/*
|
|
We do not use my_pread() here because we want to have the file
|
|
pointer set to the end of the header after this function.
|
|
my_pread() may leave the file pointer untouched.
|
|
*/
|
|
VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
|
|
if (my_read(file,(char*) header,sizeof(info->header),MYF(0)) !=
|
|
sizeof(info->header))
|
|
goto err;
|
|
}
|
|
DBUG_DUMP("header",(uchar*) header,MI_BLOCK_INFO_HEADER_LENGTH);
|
|
if (info->second_read)
|
|
{
|
|
if (info->header[0] <= 6 || info->header[0] == 13)
|
|
return_val=BLOCK_SYNC_ERROR;
|
|
}
|
|
else
|
|
{
|
|
if (info->header[0] > 6 && info->header[0] != 13)
|
|
return_val=BLOCK_SYNC_ERROR;
|
|
}
|
|
info->next_filepos= HA_OFFSET_ERROR; /* Dummy if no next block */
|
|
|
|
switch (info->header[0]) {
|
|
case 0:
|
|
if ((info->block_len=(uint) mi_uint3korr(header+1)) <
|
|
MI_MIN_BLOCK_LENGTH ||
|
|
(info->block_len & (MI_DYN_ALIGN_SIZE -1)))
|
|
goto err;
|
|
info->filepos=filepos;
|
|
info->next_filepos=mi_sizekorr(header+4);
|
|
info->prev_filepos=mi_sizekorr(header+12);
|
|
#if SIZEOF_OFF_T == 4
|
|
if ((mi_uint4korr(header+4) != 0 &&
|
|
(mi_uint4korr(header+4) != (ulong) ~0 ||
|
|
info->next_filepos != (ulong) ~0)) ||
|
|
(mi_uint4korr(header+12) != 0 &&
|
|
(mi_uint4korr(header+12) != (ulong) ~0 ||
|
|
info->prev_filepos != (ulong) ~0)))
|
|
goto err;
|
|
#endif
|
|
return return_val | BLOCK_DELETED; /* Deleted block */
|
|
|
|
case 1:
|
|
info->rec_len=info->data_len=info->block_len=mi_uint2korr(header+1);
|
|
info->filepos=filepos+3;
|
|
return return_val | BLOCK_FIRST | BLOCK_LAST;
|
|
case 2:
|
|
info->rec_len=info->data_len=info->block_len=mi_uint3korr(header+1);
|
|
info->filepos=filepos+4;
|
|
return return_val | BLOCK_FIRST | BLOCK_LAST;
|
|
|
|
case 13:
|
|
info->rec_len=mi_uint4korr(header+1);
|
|
info->block_len=info->data_len=mi_uint3korr(header+5);
|
|
info->next_filepos=mi_sizekorr(header+8);
|
|
info->second_read=1;
|
|
info->filepos=filepos+16;
|
|
return return_val | BLOCK_FIRST;
|
|
|
|
case 3:
|
|
info->rec_len=info->data_len=mi_uint2korr(header+1);
|
|
info->block_len=info->rec_len+ (uint) header[3];
|
|
info->filepos=filepos+4;
|
|
return return_val | BLOCK_FIRST | BLOCK_LAST;
|
|
case 4:
|
|
info->rec_len=info->data_len=mi_uint3korr(header+1);
|
|
info->block_len=info->rec_len+ (uint) header[4];
|
|
info->filepos=filepos+5;
|
|
return return_val | BLOCK_FIRST | BLOCK_LAST;
|
|
|
|
case 5:
|
|
info->rec_len=mi_uint2korr(header+1);
|
|
info->block_len=info->data_len=mi_uint2korr(header+3);
|
|
info->next_filepos=mi_sizekorr(header+5);
|
|
info->second_read=1;
|
|
info->filepos=filepos+13;
|
|
return return_val | BLOCK_FIRST;
|
|
case 6:
|
|
info->rec_len=mi_uint3korr(header+1);
|
|
info->block_len=info->data_len=mi_uint3korr(header+4);
|
|
info->next_filepos=mi_sizekorr(header+7);
|
|
info->second_read=1;
|
|
info->filepos=filepos+15;
|
|
return return_val | BLOCK_FIRST;
|
|
|
|
/* The following blocks are identical to 1-6 without rec_len */
|
|
case 7:
|
|
info->data_len=info->block_len=mi_uint2korr(header+1);
|
|
info->filepos=filepos+3;
|
|
return return_val | BLOCK_LAST;
|
|
case 8:
|
|
info->data_len=info->block_len=mi_uint3korr(header+1);
|
|
info->filepos=filepos+4;
|
|
return return_val | BLOCK_LAST;
|
|
|
|
case 9:
|
|
info->data_len=mi_uint2korr(header+1);
|
|
info->block_len=info->data_len+ (uint) header[3];
|
|
info->filepos=filepos+4;
|
|
return return_val | BLOCK_LAST;
|
|
case 10:
|
|
info->data_len=mi_uint3korr(header+1);
|
|
info->block_len=info->data_len+ (uint) header[4];
|
|
info->filepos=filepos+5;
|
|
return return_val | BLOCK_LAST;
|
|
|
|
case 11:
|
|
info->data_len=info->block_len=mi_uint2korr(header+1);
|
|
info->next_filepos=mi_sizekorr(header+3);
|
|
info->second_read=1;
|
|
info->filepos=filepos+11;
|
|
return return_val;
|
|
case 12:
|
|
info->data_len=info->block_len=mi_uint3korr(header+1);
|
|
info->next_filepos=mi_sizekorr(header+4);
|
|
info->second_read=1;
|
|
info->filepos=filepos+12;
|
|
return return_val;
|
|
}
|
|
|
|
err:
|
|
my_errno=HA_ERR_WRONG_IN_RECORD; /* Garbage */
|
|
return BLOCK_ERROR;
|
|
}
|