| 322 | */ |
| 323 | |
| 324 | my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, |
| 325 | my_off_t seek_offset, |
| 326 | pbool use_async_io __attribute__((unused)), |
| 327 | pbool clear_cache) |
| 328 | { |
| 329 | DBUG_ENTER("reinit_io_cache"); |
| 330 | DBUG_PRINT("enter",("cache: 0x%lx type: %d seek_offset: %lu clear_cache: %d", |
| 331 | (ulong) info, type, (ulong) seek_offset, |
| 332 | (int) clear_cache)); |
| 333 | |
| 334 | /* One can't do reinit with the following types */ |
| 335 | DBUG_ASSERT(type != READ_NET && info->type != READ_NET && |
| 336 | type != WRITE_NET && info->type != WRITE_NET && |
| 337 | type != SEQ_READ_APPEND && info->type != SEQ_READ_APPEND); |
| 338 | |
| 339 | /* If the whole file is in memory, avoid flushing to disk */ |
| 340 | if (! clear_cache && |
| 341 | seek_offset >= info->pos_in_file && |
| 342 | seek_offset <= my_b_tell(info)) |
| 343 | { |
| 344 | /* Reuse current buffer without flushing it to disk */ |
| 345 | uchar *pos; |
| 346 | if (info->type == WRITE_CACHE && type == READ_CACHE) |
| 347 | { |
| 348 | info->read_end=info->write_pos; |
| 349 | info->end_of_file=my_b_tell(info); |
| 350 | /* |
| 351 | Trigger a new seek only if we have a valid |
| 352 | file handle. |
| 353 | */ |
| 354 | info->seek_not_done= (info->file != -1); |
| 355 | } |
| 356 | else if (type == WRITE_CACHE) |
| 357 | { |
| 358 | if (info->type == READ_CACHE) |
| 359 | { |
| 360 | info->write_end=info->write_buffer+info->buffer_length; |
| 361 | info->seek_not_done=1; |
| 362 | } |
| 363 | info->end_of_file = ~(my_off_t) 0; |
| 364 | } |
| 365 | pos=info->request_pos+(seek_offset-info->pos_in_file); |
| 366 | if (type == WRITE_CACHE) |
| 367 | info->write_pos=pos; |
| 368 | else |
| 369 | info->read_pos= pos; |
| 370 | #ifdef HAVE_AIOWAIT |
| 371 | my_aiowait(&info->aio_result); /* Wait for outstanding req */ |
| 372 | #endif |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | /* |
| 377 | If we change from WRITE_CACHE to READ_CACHE, assume that everything |
| 378 | after the current positions should be ignored |
| 379 | */ |
| 380 | if (info->type == WRITE_CACHE && type == READ_CACHE) |
| 381 | info->end_of_file=my_b_tell(info); |
no test coverage detected