36 #include "myisam_priv.h"
41 using namespace drizzled;
44 int _mi_read_cache(
internal::io_cache_st *info,
unsigned char *buff, internal::my_off_t pos, uint32_t length,
47 uint32_t read_length,in_buff_length;
48 internal::my_off_t offset;
49 unsigned char *in_buff_pos;
51 if (pos < info->pos_in_file)
54 if ((internal::my_off_t) read_length > (internal::my_off_t) (info->pos_in_file-pos))
55 read_length=(uint) (info->pos_in_file-pos);
56 info->seek_not_done=1;
57 if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
59 if (!(length-=read_length))
64 if (pos >= info->pos_in_file &&
65 (offset= (internal::my_off_t) (pos - info->pos_in_file)) <
66 (internal::my_off_t) (info->read_end - info->request_pos))
68 in_buff_pos=info->request_pos+(uint) offset;
69 in_buff_length= min(length, (uint32_t) (info->read_end-in_buff_pos));
70 memcpy(buff,info->request_pos+(uint) offset,(
size_t) in_buff_length);
71 if (!(length-=in_buff_length))
78 if (flag & READING_NEXT)
80 if (pos != (info->pos_in_file +
81 (uint) (info->read_end - info->request_pos)))
83 info->pos_in_file=pos;
84 info->read_pos=info->read_end=info->request_pos;
85 info->seek_not_done=1;
88 info->read_pos=info->read_end;
89 if (!(*info->read_function)(info,buff,length))
91 read_length=info->error;
95 info->seek_not_done=1;
96 if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
99 if (!(flag & READING_HEADER) || (
int) read_length == -1 ||
100 read_length+in_buff_length < 3)
102 if (!errno || errno == -1)
103 errno=HA_ERR_WRONG_IN_RECORD;
106 memset(buff+read_length, 0,
107 MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);