1
/* Copyright (C) 2000-2004, 2006 MySQL AB
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
/* Read and write key blocks */
18
#include "myisam_priv.h"
20
using namespace drizzled;
22
/* Fetch a key-page in memory */
24
unsigned char *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo,
25
internal::my_off_t page, int level,
26
unsigned char *buff, int return_buffer)
31
tmp=(unsigned char*) key_cache_read(info->s->getKeyCache(),
32
info->s->kfile, page, level, (unsigned char*) buff,
33
(uint) keyinfo->block_length,
34
(uint) keyinfo->block_length,
36
if (tmp == info->buff)
40
info->last_keypage=HA_OFFSET_ERROR;
41
mi_print_error(info->s, HA_ERR_CRASHED);
45
info->last_keypage=page;
46
page_size=mi_getint(tmp);
47
if (page_size < 4 || page_size > keyinfo->block_length)
49
info->last_keypage = HA_OFFSET_ERROR;
50
mi_print_error(info->s, HA_ERR_CRASHED);
51
errno = HA_ERR_CRASHED;
55
} /* _mi_fetch_keypage */
58
/* Write a key-page on disk */
60
int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo,
61
internal::my_off_t page, int level, unsigned char *buff)
63
register uint32_t length;
65
#ifndef FAST /* Safety check */
66
if (page < info->s->base.keystart ||
67
page+keyinfo->block_length > info->state->key_file_length ||
68
(page & (MI_MIN_KEY_BLOCK_LENGTH-1)))
75
if ((length=keyinfo->block_length) > IO_SIZE*2 &&
76
info->state->key_file_length != page+length)
77
length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1));
80
length=mi_getint(buff);
81
memset(buff+length, 0, keyinfo->block_length-length);
82
length=keyinfo->block_length;
85
return((key_cache_write(info->s->getKeyCache(),
86
info->s->kfile,page, level, (unsigned char*) buff,length,
87
(uint) keyinfo->block_length,
88
(int) ((info->lock_type != F_UNLCK) ||
89
info->s->delay_key_write))));
90
} /* mi_write_keypage */
93
/* Remove page from disk */
95
int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, internal::my_off_t pos,
98
internal::my_off_t old_link;
99
unsigned char buff[8];
101
old_link= info->s->state.key_del[keyinfo->block_size_index];
102
info->s->state.key_del[keyinfo->block_size_index]= pos;
103
mi_sizestore(buff,old_link);
104
info->s->state.changed|= STATE_NOT_SORTED_PAGES;
105
return(key_cache_write(info->s->getKeyCache(),
106
info->s->kfile, pos , level, buff,
108
(uint) keyinfo->block_length,
109
(int) (info->lock_type != F_UNLCK)));
113
/* Make new page on disk */
115
internal::my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level)
117
internal::my_off_t pos;
118
unsigned char buff[8];
120
if ((pos= info->s->state.key_del[keyinfo->block_size_index]) ==
123
if (info->state->key_file_length >=
124
info->s->base.max_key_file_length - keyinfo->block_length)
126
errno=HA_ERR_INDEX_FILE_FULL;
127
return(HA_OFFSET_ERROR);
129
pos=info->state->key_file_length;
130
info->state->key_file_length+= keyinfo->block_length;
134
if (!key_cache_read(info->s->getKeyCache(),
135
info->s->kfile, pos, level,
138
(uint) keyinfo->block_length,0))
139
pos= HA_OFFSET_ERROR;
141
info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff);
143
info->s->state.changed|= STATE_NOT_SORTED_PAGES;