63
63
using namespace std;
66
static int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count);
67
static int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count);
68
static int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count);
69
static int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count);
65
72
#define lock_append_buffer(info) \
66
73
pthread_mutex_lock(&(info)->append_buffer_lock)
67
74
#define unlock_append_buffer(info) \
427
434
1 Error: can't read requested characters
430
int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
437
static int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
432
439
size_t length,diff_length,left_length, max_length;
433
440
my_off_t pos_in_file;
887
894
1 Error: can't read requested characters
890
int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count)
897
extern "C" int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count)
892
899
my_off_t pos_in_file;
893
900
size_t length, diff_length, left_length;
1055
1062
1 Failed to read
1058
int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
1065
extern "C" int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
1060
1067
size_t length, diff_length, left_length, save_count, max_length;
1061
1068
my_off_t pos_in_file;
1405
1412
-1 On error; my_errno contains error code.
1408
int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1415
extern "C" int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1410
1417
size_t rest_length,length;
1472
Append a block to the write buffer.
1473
This is done with the buffer locked to ensure that we don't read from
1474
the write buffer before we are ready with it.
1477
int my_b_append(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1479
size_t rest_length,length;
1482
Assert that we cannot come here with a shared cache. If we do one
1483
day, we might need to add a call to copy_to_read_buffer().
1485
assert(!info->share);
1487
lock_append_buffer(info);
1488
rest_length= (size_t) (info->write_end - info->write_pos);
1489
if (Count <= rest_length)
1491
memcpy(info->write_pos, Buffer, rest_length);
1492
Buffer+=rest_length;
1494
info->write_pos+=rest_length;
1495
if (my_b_flush_io_cache(info,0))
1497
unlock_append_buffer(info);
1500
if (Count >= IO_SIZE)
1501
{ /* Fill first intern buffer */
1502
length=Count & (size_t) ~(IO_SIZE-1);
1503
if (my_write(info->file,Buffer, length, info->myflags | MY_NABP))
1505
unlock_append_buffer(info);
1506
return info->error= -1;
1510
info->end_of_file+=length;
1514
memcpy(info->write_pos,Buffer,(size_t) Count);
1515
info->write_pos+=Count;
1516
unlock_append_buffer(info);
1521
int my_b_safe_write(IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1524
Sasha: We are not writing this with the ? operator to avoid hitting
1525
a possible compiler bug. At least gcc 2.95 cannot deal with
1526
several layers of ternary operators that evaluated comma(,) operator
1527
expressions inside - I do have a test case if somebody wants it
1529
if (info->type == SEQ_READ_APPEND)
1530
return my_b_append(info, Buffer, Count);
1531
return my_b_write(info, Buffer, Count);
1536
1478
Write a block to disk where part of the data may be inside the record
1537
1479
buffer. As all write calls to the data goes through the cache,