00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "myisam_priv.h"
00037
00038 #include <algorithm>
00039
00040 using namespace std;
00041 using namespace drizzled;
00042
00043
00044 int _mi_read_cache(internal::IO_CACHE *info, unsigned char *buff, internal::my_off_t pos, uint32_t length,
00045 int flag)
00046 {
00047 uint32_t read_length,in_buff_length;
00048 internal::my_off_t offset;
00049 unsigned char *in_buff_pos;
00050
00051 if (pos < info->pos_in_file)
00052 {
00053 read_length=length;
00054 if ((internal::my_off_t) read_length > (internal::my_off_t) (info->pos_in_file-pos))
00055 read_length=(uint) (info->pos_in_file-pos);
00056 info->seek_not_done=1;
00057 if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
00058 return(1);
00059 if (!(length-=read_length))
00060 return(0);
00061 pos+=read_length;
00062 buff+=read_length;
00063 }
00064 if (pos >= info->pos_in_file &&
00065 (offset= (internal::my_off_t) (pos - info->pos_in_file)) <
00066 (internal::my_off_t) (info->read_end - info->request_pos))
00067 {
00068 in_buff_pos=info->request_pos+(uint) offset;
00069 in_buff_length= min(length, (uint32_t) (info->read_end-in_buff_pos));
00070 memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
00071 if (!(length-=in_buff_length))
00072 return(0);
00073 pos+=in_buff_length;
00074 buff+=in_buff_length;
00075 }
00076 else
00077 in_buff_length=0;
00078 if (flag & READING_NEXT)
00079 {
00080 if (pos != (info->pos_in_file +
00081 (uint) (info->read_end - info->request_pos)))
00082 {
00083 info->pos_in_file=pos;
00084 info->read_pos=info->read_end=info->request_pos;
00085 info->seek_not_done=1;
00086 }
00087 else
00088 info->read_pos=info->read_end;
00089 if (!(*info->read_function)(info,buff,length))
00090 return(0);
00091 read_length=info->error;
00092 }
00093 else
00094 {
00095 info->seek_not_done=1;
00096 if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
00097 return(0);
00098 }
00099 if (!(flag & READING_HEADER) || (int) read_length == -1 ||
00100 read_length+in_buff_length < 3)
00101 {
00102 if (!errno || errno == -1)
00103 errno=HA_ERR_WRONG_IN_RECORD;
00104 return(1);
00105 }
00106 memset(buff+read_length, 0,
00107 MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);
00108 return(0);
00109 }