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
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* Read and write key blocks */
|
|
17 |
||
18 |
#include "myisamdef.h" |
|
19 |
||
20 |
/* Fetch a key-page in memory */
|
|
21 |
||
481
by Brian Aker
Remove all of uchar. |
22 |
unsigned char *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo, |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
23 |
my_off_t page, int level, |
481
by Brian Aker
Remove all of uchar. |
24 |
unsigned char *buff, int return_buffer) |
1
by brian
clean slate |
25 |
{
|
481
by Brian Aker
Remove all of uchar. |
26 |
unsigned char *tmp; |
482
by Brian Aker
Remove uint. |
27 |
uint32_t page_size; |
1
by brian
clean slate |
28 |
|
481
by Brian Aker
Remove all of uchar. |
29 |
tmp=(unsigned char*) key_cache_read(info->s->key_cache, |
30 |
info->s->kfile, page, level, (unsigned char*) buff, |
|
1
by brian
clean slate |
31 |
(uint) keyinfo->block_length, |
32 |
(uint) keyinfo->block_length, |
|
33 |
return_buffer); |
|
34 |
if (tmp == info->buff) |
|
35 |
info->buff_used=1; |
|
36 |
else if (!tmp) |
|
37 |
{
|
|
38 |
info->last_keypage=HA_OFFSET_ERROR; |
|
39 |
mi_print_error(info->s, HA_ERR_CRASHED); |
|
40 |
my_errno=HA_ERR_CRASHED; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
41 |
return(0); |
1
by brian
clean slate |
42 |
}
|
43 |
info->last_keypage=page; |
|
44 |
page_size=mi_getint(tmp); |
|
45 |
if (page_size < 4 || page_size > keyinfo->block_length) |
|
46 |
{
|
|
47 |
info->last_keypage = HA_OFFSET_ERROR; |
|
48 |
mi_print_error(info->s, HA_ERR_CRASHED); |
|
49 |
my_errno = HA_ERR_CRASHED; |
|
50 |
tmp = 0; |
|
51 |
}
|
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
52 |
return(tmp); |
1
by brian
clean slate |
53 |
} /* _mi_fetch_keypage */ |
54 |
||
55 |
||
56 |
/* Write a key-page on disk */
|
|
57 |
||
58 |
int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, |
|
481
by Brian Aker
Remove all of uchar. |
59 |
my_off_t page, int level, unsigned char *buff) |
1
by brian
clean slate |
60 |
{
|
482
by Brian Aker
Remove uint. |
61 |
register uint32_t length; |
1
by brian
clean slate |
62 |
|
63 |
#ifndef FAST /* Safety check */ |
|
64 |
if (page < info->s->base.keystart || |
|
65 |
page+keyinfo->block_length > info->state->key_file_length || |
|
66 |
(page & (MI_MIN_KEY_BLOCK_LENGTH-1))) |
|
67 |
{
|
|
68 |
my_errno=EINVAL; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
69 |
return((-1)); |
1
by brian
clean slate |
70 |
}
|
71 |
#endif
|
|
72 |
||
73 |
if ((length=keyinfo->block_length) > IO_SIZE*2 && |
|
74 |
info->state->key_file_length != page+length) |
|
75 |
length= ((mi_getint(buff)+IO_SIZE-1) & (uint) ~(IO_SIZE-1)); |
|
76 |
#ifdef HAVE_purify
|
|
77 |
{
|
|
78 |
length=mi_getint(buff); |
|
212.6.12
by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove(). |
79 |
memset(buff+length, 0, keyinfo->block_length-length); |
1
by brian
clean slate |
80 |
length=keyinfo->block_length; |
81 |
}
|
|
82 |
#endif
|
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
83 |
return((key_cache_write(info->s->key_cache, |
481
by Brian Aker
Remove all of uchar. |
84 |
info->s->kfile,page, level, (unsigned char*) buff,length, |
1
by brian
clean slate |
85 |
(uint) keyinfo->block_length, |
86 |
(int) ((info->lock_type != F_UNLCK) || |
|
87 |
info->s->delay_key_write)))); |
|
88 |
} /* mi_write_keypage */ |
|
89 |
||
90 |
||
91 |
/* Remove page from disk */
|
|
92 |
||
93 |
int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos, |
|
94 |
int level) |
|
95 |
{
|
|
96 |
my_off_t old_link; |
|
481
by Brian Aker
Remove all of uchar. |
97 |
unsigned char buff[8]; |
1
by brian
clean slate |
98 |
|
99 |
old_link= info->s->state.key_del[keyinfo->block_size_index]; |
|
100 |
info->s->state.key_del[keyinfo->block_size_index]= pos; |
|
101 |
mi_sizestore(buff,old_link); |
|
102 |
info->s->state.changed|= STATE_NOT_SORTED_PAGES; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
103 |
return(key_cache_write(info->s->key_cache, |
1
by brian
clean slate |
104 |
info->s->kfile, pos , level, buff, |
105 |
sizeof(buff), |
|
106 |
(uint) keyinfo->block_length, |
|
107 |
(int) (info->lock_type != F_UNLCK))); |
|
108 |
} /* _mi_dispose */ |
|
109 |
||
110 |
||
111 |
/* Make new page on disk */
|
|
112 |
||
113 |
my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level) |
|
114 |
{
|
|
115 |
my_off_t pos; |
|
481
by Brian Aker
Remove all of uchar. |
116 |
unsigned char buff[8]; |
1
by brian
clean slate |
117 |
|
118 |
if ((pos= info->s->state.key_del[keyinfo->block_size_index]) == |
|
119 |
HA_OFFSET_ERROR) |
|
120 |
{
|
|
121 |
if (info->state->key_file_length >= |
|
122 |
info->s->base.max_key_file_length - keyinfo->block_length) |
|
123 |
{
|
|
124 |
my_errno=HA_ERR_INDEX_FILE_FULL; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
125 |
return(HA_OFFSET_ERROR); |
1
by brian
clean slate |
126 |
}
|
127 |
pos=info->state->key_file_length; |
|
128 |
info->state->key_file_length+= keyinfo->block_length; |
|
129 |
}
|
|
130 |
else
|
|
131 |
{
|
|
132 |
if (!key_cache_read(info->s->key_cache, |
|
133 |
info->s->kfile, pos, level, |
|
134 |
buff, |
|
135 |
(uint) sizeof(buff), |
|
136 |
(uint) keyinfo->block_length,0)) |
|
137 |
pos= HA_OFFSET_ERROR; |
|
138 |
else
|
|
139 |
info->s->state.key_del[keyinfo->block_size_index]= mi_sizekorr(buff); |
|
140 |
}
|
|
141 |
info->s->state.changed|= STATE_NOT_SORTED_PAGES; |
|
51.1.105
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
142 |
return(pos); |
1
by brian
clean slate |
143 |
} /* _mi_new */ |