~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/*
17
  Functions for read record cacheing with myisam
18
  Used for reading dynamic/compressed records from datafile.
19
20
  Can fetch data directly from file (outside cache),
21
  if reading a small chunk straight before the cached part (with possible
22
  overlap).
23
24
  Can be explicitly asked not to use cache (by not setting READING_NEXT in
25
  flag) - useful for occasional out-of-cache reads, when the next read is
26
  expected to hit the cache again.
27
28
  Allows "partial read" errors in the record header (when READING_HEADER flag
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
29
  is set) - unread part is zero'ed
1 by brian
clean slate
30
31
  Note: out-of-cache reads are enabled for shared IO_CACHE's too,
32
  as these reads will be cached by OS cache (and my_pread is always atomic)
33
*/
34
35
36
#include "myisamdef.h"
37
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
38
#include <algorithm>
39
40
using namespace std;
41
42
482 by Brian Aker
Remove uint.
43
int _mi_read_cache(IO_CACHE *info, unsigned char *buff, my_off_t pos, uint32_t length,
1 by brian
clean slate
44
		   int flag)
45
{
482 by Brian Aker
Remove uint.
46
  uint32_t read_length,in_buff_length;
1 by brian
clean slate
47
  my_off_t offset;
481 by Brian Aker
Remove all of uchar.
48
  unsigned char *in_buff_pos;
1 by brian
clean slate
49
50
  if (pos < info->pos_in_file)
51
  {
52
    read_length=length;
53
    if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos))
54
      read_length=(uint) (info->pos_in_file-pos);
55
    info->seek_not_done=1;
56
    if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
57
      return(1);
1 by brian
clean slate
58
    if (!(length-=read_length))
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
59
      return(0);
1 by brian
clean slate
60
    pos+=read_length;
61
    buff+=read_length;
62
  }
63
  if (pos >= info->pos_in_file &&
64
      (offset= (my_off_t) (pos - info->pos_in_file)) <
65
      (my_off_t) (info->read_end - info->request_pos))
66
  {
67
    in_buff_pos=info->request_pos+(uint) offset;
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
68
    in_buff_length= min(length, (uint32_t) (info->read_end-in_buff_pos));
1 by brian
clean slate
69
    memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
70
    if (!(length-=in_buff_length))
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
71
      return(0);
1 by brian
clean slate
72
    pos+=in_buff_length;
73
    buff+=in_buff_length;
74
  }
75
  else
76
    in_buff_length=0;
77
  if (flag & READING_NEXT)
78
  {
79
    if (pos != (info->pos_in_file +
80
		(uint) (info->read_end - info->request_pos)))
81
    {
82
      info->pos_in_file=pos;				/* Force start here */
83
      info->read_pos=info->read_end=info->request_pos;	/* Everything used */
84
      info->seek_not_done=1;
85
    }
86
    else
87
      info->read_pos=info->read_end;			/* All block used */
88
    if (!(*info->read_function)(info,buff,length))
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
89
      return(0);
1 by brian
clean slate
90
    read_length=info->error;
91
  }
92
  else
93
  {
94
    info->seek_not_done=1;
95
    if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
96
      return(0);
1 by brian
clean slate
97
  }
98
  if (!(flag & READING_HEADER) || (int) read_length == -1 ||
99
      read_length+in_buff_length < 3)
100
  {
101
    if (!my_errno || my_errno == -1)
102
      my_errno=HA_ERR_WRONG_IN_RECORD;
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
103
    return(1);
1 by brian
clean slate
104
  }
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
105
  memset(buff+read_length, 0,
106
         MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);
51.1.90 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
107
  return(0);
1 by brian
clean slate
108
} /* _mi_read_cache */