18 #include "myisamdef.h"
21 int _mi_write_static_record(
MI_INFO *info,
const uchar *
record)
24 if (info->s->state.dellink != HA_OFFSET_ERROR &&
25 !info->append_insert_at_end)
27 my_off_t filepos=info->s->state.dellink;
28 info->rec_cache.seek_not_done=1;
29 if (info->s->file_read(info, &temp[0],info->s->base.rec_reflength,
30 info->s->state.dellink+1,
33 info->s->state.dellink= _mi_rec_pos(info->s,temp);
35 info->state->empty-=info->s->base.pack_reclength;
36 if (info->s->file_write(info, record, info->s->base.reclength,
43 if (info->state->data_file_length > info->s->base.max_data_file_length-
44 info->s->base.pack_reclength)
46 my_errno=HA_ERR_RECORD_FILE_FULL;
49 if (info->opt_flag & WRITE_CACHE_USED)
51 if (my_b_write(&info->rec_cache, record,
52 info->s->base.reclength))
54 if (info->s->base.pack_reclength != info->s->base.reclength)
56 uint length=info->s->base.pack_reclength - info->s->base.reclength;
57 memset(temp, 0, length);
58 if (my_b_write(&info->rec_cache, temp,length))
64 info->rec_cache.seek_not_done=1;
65 if (info->s->file_write(info, record, info->s->base.reclength,
66 info->state->data_file_length,
69 if (info->s->base.pack_reclength != info->s->base.reclength)
71 uint length=info->s->base.pack_reclength - info->s->base.reclength;
72 memset(temp, 0, length);
73 if (info->s->file_write(info, temp,length,
74 info->state->data_file_length+
75 info->s->base.reclength,
80 info->state->data_file_length+=info->s->base.pack_reclength;
81 info->s->state.split++;
88 int _mi_update_static_record(
MI_INFO *info, my_off_t pos,
const uchar *record)
90 info->rec_cache.seek_not_done=1;
91 return (info->s->file_write(info,
92 record, info->s->base.reclength,
98 int _mi_delete_static_record(
MI_INFO *info)
103 info->state->empty+=info->s->base.pack_reclength;
105 _mi_dpointer(info,temp+1,info->s->state.dellink);
106 info->s->state.dellink = info->lastpos;
107 info->rec_cache.seek_not_done=1;
108 return (info->s->file_write(info,(uchar*) temp, 1+info->s->rec_reflength,
109 info->lastpos, MYF(MY_NABP)) != 0);
113 int _mi_cmp_static_record(
register MI_INFO *info,
register const uchar *old)
115 DBUG_ENTER(
"_mi_cmp_static_record");
117 if (info->opt_flag & WRITE_CACHE_USED)
119 if (flush_io_cache(&info->rec_cache))
123 info->rec_cache.seek_not_done=1;
126 if ((info->opt_flag & READ_CHECK_USED))
128 info->rec_cache.seek_not_done=1;
129 if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
133 if (memcmp(info->rec_buff, old,
134 (uint) info->s->base.reclength))
136 DBUG_DUMP(
"read",old,info->s->base.reclength);
137 DBUG_DUMP(
"disk",info->rec_buff,info->s->base.reclength);
138 my_errno=HA_ERR_RECORD_CHANGED;
147 const uchar *record, my_off_t pos)
149 DBUG_ENTER(
"_mi_cmp_static_unique");
151 info->rec_cache.seek_not_done=1;
152 if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
155 DBUG_RETURN(mi_unique_comp(def, record, info->rec_buff,
156 def->null_are_equal));
165 int _mi_read_static_record(
register MI_INFO *info,
register my_off_t pos,
166 register uchar *record)
170 if (pos != HA_OFFSET_ERROR)
172 if (info->opt_flag & WRITE_CACHE_USED &&
173 info->rec_cache.pos_in_file <= pos &&
174 flush_io_cache(&info->rec_cache))
176 info->rec_cache.seek_not_done=1;
178 error=info->s->file_read(info, record, info->s->base.reclength,
179 pos,MYF(MY_NABP)) != 0;
180 fast_mi_writeinfo(info);
185 my_errno=HA_ERR_RECORD_DELETED;
188 info->update|= HA_STATE_AKTIV;
193 fast_mi_writeinfo(info);
199 int _mi_read_rnd_static_record(
MI_INFO *info, uchar *
buf,
200 register my_off_t filepos,
201 my_bool skip_deleted_blocks)
203 int locked,error,cache_read;
206 DBUG_ENTER(
"_mi_read_rnd_static_record");
210 if (info->opt_flag & WRITE_CACHE_USED &&
211 (info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) &&
212 flush_io_cache(&info->rec_cache))
213 DBUG_RETURN(my_errno);
214 if (info->opt_flag & READ_CACHE_USED)
216 if (filepos == my_b_tell(&info->rec_cache) &&
217 (skip_deleted_blocks || !filepos))
220 cache_length=(uint) (info->rec_cache.read_end - info->rec_cache.read_pos);
223 info->rec_cache.seek_not_done=1;
226 if (info->lock_type == F_UNLCK)
228 if (filepos >= info->state->data_file_length)
230 if (_mi_readinfo(info,F_RDLCK,0))
231 DBUG_RETURN(my_errno);
236 #ifndef UNSAFE_LOCKING
237 if ((! cache_read || share->base.reclength > cache_length) &&
238 share->tot_locks == 0)
240 if (my_lock(share->kfile,F_RDLCK,0L,F_TO_EOF,
241 MYF(MY_SEEK_NOT_DONE) | info->lock_wait))
242 DBUG_RETURN(my_errno);
246 info->tmp_lock_type=F_RDLCK;
250 if (filepos >= info->state->data_file_length)
252 DBUG_PRINT(
"test",(
"filepos: %ld (%ld) records: %ld del: %ld",
253 (
long) filepos/share->base.reclength, (
long) filepos,
254 (
long) info->state->records, (
long) info->state->del));
255 fast_mi_writeinfo(info);
256 DBUG_RETURN(my_errno=HA_ERR_END_OF_FILE);
258 info->lastpos= filepos;
259 info->nextpos= filepos+share->base.pack_reclength;
263 if ((error=_mi_read_static_record(info,filepos,buf)))
266 error=my_errno=HA_ERR_RECORD_DELETED;
279 error=my_b_read(&info->rec_cache,(uchar*) buf,share->base.reclength);
280 if (info->s->base.pack_reclength != info->s->base.reclength && !error)
283 error=my_b_read(&info->rec_cache,(uchar*) tmp,
284 info->s->base.pack_reclength - info->s->base.reclength);
287 (void) _mi_writeinfo(info,0);
292 DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
295 info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
299 if (info->rec_cache.error != -1 || my_errno == 0)
305 if (info->rec_cache.error == 0)
306 my_errno= HA_ERR_END_OF_FILE;
308 my_errno= HA_ERR_WRONG_IN_RECORD;
310 DBUG_RETURN(my_errno);