void BTree::WriteBlock (uchar *block, uint num)
{
- fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET);
+ num++;
+ fseek (fp, num*header.block_size, SEEK_SET);
fwrite (block, 1, header.block_size, fp);
}
uchar *BTree::ReadBlock (uint num)
{
+ /* Como el bloque 0 se usa para el header, el Nodo "num"
+ * está en el bloque "num+1"
+ */
+ num++;
+
uchar *out = new uchar[header.block_size];
- fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET);
+ fseek (fp, num*header.block_size, SEEK_SET);
fread (out, 1, header.block_size, fp);
return out;
fseek (fp, 0, SEEK_END);
filelen = ftell (fp);
- num = (filelen - sizeof (BTreeFileHeader))/header.block_size;
+ num = filelen/header.block_size - 1;
node = new uchar[header.block_size];
ReadNodoHeader (node, &nh);