1
/* Copyright (C) 2008 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include "SectorBuffer.h"
19
#include "SectorCache.h"
24
SectorBuffer::SectorBuffer()
30
SectorBuffer::~SectorBuffer(void)
34
void SectorBuffer::readPage(Bdb* bdb)
36
int pageSize = cache->pageSize;
38
int offset = (bdb->pageNumber % cache->pagesPerSector) * pageSize;
39
ASSERT(offset < activeLength);
41
Page *page = (Page *)(buffer + offset);
44
Validate page checksum.
45
Do it only once and after that reset the checksum field. It is necessary
46
because later the checksum in header might be incorrect (when page is read,
47
modified and written back to buffer�but not yet to disk).Also, the same page
48
might be read multiple times and we want to avoid the checksum calculation
51
if(page->checksum != NO_CHECKSUM_MAGIC)
53
dbb->validateChecksum(page, pageSize, ((int64)bdb->pageNumber) * pageSize);
54
page->checksum = NO_CHECKSUM_MAGIC;
56
memcpy(bdb->buffer, page, pageSize);
59
void SectorBuffer::readSector()
61
uint64 offset = (uint64)sectorNumber * (uint64)cache->pagesPerSector * (uint64)cache->pageSize;
62
activeLength = dbb->pread(offset, SECTOR_BUFFER_SIZE, buffer);
65
void SectorBuffer::setSector(Dbb* db, int sector)
68
sectorNumber = sector;
71
void SectorBuffer::writePage(Bdb* bdb)
73
int offset = (bdb->pageNumber % cache->pagesPerSector) * cache->pageSize;
74
memcpy(buffer + offset, bdb->buffer, cache->pageSize);
75
offset += cache->pageSize;
76
activeLength = MAX(activeLength, offset);