~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2004, 2006 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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Read and write key blocks */
17
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
18
#include "myisam_priv.h"
1 by brian
clean slate
19
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
20
using namespace drizzled;
21
1 by brian
clean slate
22
	/* Fetch a key-page in memory */
23
2409.2.4 by Olaf van der Spek
Remove keycache
24
unsigned char *_mi_fetch_keypage(MI_INFO *info, MI_KEYDEF *keyinfo,
25
			 internal::my_off_t page, int, unsigned char *buff, int)
1 by brian
clean slate
26
{
2409.2.4 by Olaf van der Spek
Remove keycache
27
  if (not pread(info->s->kfile, buff, keyinfo->block_length, page))
1 by brian
clean slate
28
  {
29
    info->last_keypage=HA_OFFSET_ERROR;
30
    mi_print_error(info->s, HA_ERR_CRASHED);
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
31
    errno=HA_ERR_CRASHED;
51.1.105 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
32
    return(0);
1 by brian
clean slate
33
  }
2409.2.4 by Olaf van der Spek
Remove keycache
34
  unsigned char* tmp= buff;
35
  if (tmp == info->buff)
36
    info->buff_used=1;
1 by brian
clean slate
37
  info->last_keypage=page;
2409.2.4 by Olaf van der Spek
Remove keycache
38
  uint32_t page_size=mi_getint(tmp);
1 by brian
clean slate
39
  if (page_size < 4 || page_size > keyinfo->block_length)
40
  {
41
    info->last_keypage = HA_OFFSET_ERROR;
42
    mi_print_error(info->s, HA_ERR_CRASHED);
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
43
    errno = HA_ERR_CRASHED;
1 by brian
clean slate
44
    tmp = 0;
45
  }
51.1.105 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
46
  return(tmp);
1 by brian
clean slate
47
} /* _mi_fetch_keypage */
48
49
50
	/* Write a key-page on disk */
51
2409.2.4 by Olaf van der Spek
Remove keycache
52
int _mi_write_keypage(MI_INFO *info, MI_KEYDEF *keyinfo,
53
		      internal::my_off_t page, int, unsigned char *buff)
1 by brian
clean slate
54
{
2409.2.4 by Olaf van der Spek
Remove keycache
55
  uint32_t length;
1 by brian
clean slate
56
57
#ifndef FAST					/* Safety check */
58
  if (page < info->s->base.keystart ||
59
      page+keyinfo->block_length > info->state->key_file_length ||
60
      (page & (MI_MIN_KEY_BLOCK_LENGTH-1)))
61
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
62
    errno=EINVAL;
51.1.105 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
63
    return((-1));
1 by brian
clean slate
64
  }
65
#endif
66
67
  if ((length=keyinfo->block_length) > IO_SIZE*2 &&
68
      info->state->key_file_length != page+length)
69
    length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1));
1859.2.14 by Brian Aker
Add support for --with-valgrind
70
#ifdef HAVE_VALGRIND
1 by brian
clean slate
71
  {
72
    length=mi_getint(buff);
212.6.12 by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove().
73
    memset(buff+length, 0, keyinfo->block_length-length);
1 by brian
clean slate
74
    length=keyinfo->block_length;
75
  }
76
#endif
2409.2.4 by Olaf van der Spek
Remove keycache
77
  return not pwrite(info->s->kfile, buff, length, page);
1 by brian
clean slate
78
} /* mi_write_keypage */
79
80
81
	/* Remove page from disk */
82
2409.2.4 by Olaf van der Spek
Remove keycache
83
int _mi_dispose(MI_INFO *info, MI_KEYDEF *keyinfo, internal::my_off_t pos, int)
1 by brian
clean slate
84
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
85
  internal::my_off_t old_link;
481 by Brian Aker
Remove all of uchar.
86
  unsigned char buff[8];
1 by brian
clean slate
87
88
  old_link= info->s->state.key_del[keyinfo->block_size_index];
89
  info->s->state.key_del[keyinfo->block_size_index]= pos;
90
  mi_sizestore(buff,old_link);
91
  info->s->state.changed|= STATE_NOT_SORTED_PAGES;
2409.2.4 by Olaf van der Spek
Remove keycache
92
  return not pwrite(info->s->kfile, buff, sizeof(buff), pos);
1 by brian
clean slate
93
} /* _mi_dispose */
94
95
96
	/* Make new page on disk */
97
2409.2.4 by Olaf van der Spek
Remove keycache
98
internal::my_off_t _mi_new(MI_INFO *info, MI_KEYDEF *keyinfo, int)
1 by brian
clean slate
99
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
100
  internal::my_off_t pos;
481 by Brian Aker
Remove all of uchar.
101
  unsigned char buff[8];
1 by brian
clean slate
102
103
  if ((pos= info->s->state.key_del[keyinfo->block_size_index]) ==
104
      HA_OFFSET_ERROR)
105
  {
106
    if (info->state->key_file_length >=
107
	info->s->base.max_key_file_length - keyinfo->block_length)
108
    {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
109
      errno=HA_ERR_INDEX_FILE_FULL;
51.1.105 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
110
      return(HA_OFFSET_ERROR);
1 by brian
clean slate
111
    }
112
    pos=info->state->key_file_length;
113
    info->state->key_file_length+= keyinfo->block_length;
114
  }
2409.2.4 by Olaf van der Spek
Remove keycache
115
  else if (pread(info->s->kfile, buff, sizeof(buff), pos))
116
    info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff);
1 by brian
clean slate
117
  else
2409.2.4 by Olaf van der Spek
Remove keycache
118
    pos= HA_OFFSET_ERROR;
1 by brian
clean slate
119
  info->s->state.changed|= STATE_NOT_SORTED_PAGES;
51.1.105 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
120
  return(pos);
1 by brian
clean slate
121
} /* _mi_new */