36 #include "myisamdef.h"
38 int _mi_read_cache(
IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
41 uint read_length,in_buff_length;
44 DBUG_ENTER(
"_mi_read_cache");
46 if (pos < info->pos_in_file)
49 if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos))
50 read_length=(uint) (info->pos_in_file-pos);
51 info->seek_not_done=1;
54 if (!(length-=read_length))
59 if (pos >= info->pos_in_file &&
60 (offset= (my_off_t) (pos - info->pos_in_file)) <
61 (my_off_t) (info->read_end - info->request_pos))
63 in_buff_pos=info->request_pos+(uint) offset;
64 in_buff_length= MY_MIN(length, (
size_t) (info->read_end-in_buff_pos));
65 memcpy(buff,info->request_pos+(uint) offset,(
size_t) in_buff_length);
66 if (!(length-=in_buff_length))
73 if (flag & READING_NEXT)
75 if (pos != (info->pos_in_file +
76 (uint) (info->read_end - info->request_pos)))
78 info->pos_in_file=pos;
79 info->read_pos=info->read_end=info->request_pos;
80 info->seek_not_done=1;
83 info->read_pos=info->read_end;
84 if (!(*info->read_function)(info,buff,length))
86 read_length=info->error;
90 info->seek_not_done=1;
95 if (!(flag & READING_HEADER) || (
int) read_length == -1 ||
96 read_length+in_buff_length < 3)
99 (
"Error %d reading next-multi-part block (Got %d bytes)",
100 my_errno, (
int) read_length));
101 if (!my_errno || my_errno == -1)
102 my_errno=HA_ERR_WRONG_IN_RECORD;
105 memset(buff+read_length, 0,
106 MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);