From ee619d18f5d688c5ea2f630a80a3560de36a99ed Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Sun, 2 Oct 2005 19:08:00 +0000 Subject: [PATCH] Hago que el header ocupe todo el primer bloque. --- src/btree.cpp | 12 +++++++++--- src/btree.h | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/btree.cpp b/src/btree.cpp index ae98139..a063bef 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -45,7 +45,8 @@ void BTree::WriteFileHeader () 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); } @@ -402,9 +403,14 @@ void BTree::WriteNodoHeader (uchar *node, BTreeNodeHeader *header) 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; @@ -501,7 +507,7 @@ uchar *BTree::NewBlock (uint &num) 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); diff --git a/src/btree.h b/src/btree.h index afcec63..e67c7cf 100644 --- a/src/btree.h +++ b/src/btree.h @@ -55,7 +55,11 @@ /* alias para codear menos :) */ -/** Encabezado del archivo BTree */ +/** Encabezado del archivo BTree + * + * Esta estructura es para comodidad de manejo, aunque en disco + * ocupe block_size de tamaño. + */ struct BTreeFileHeader { uint block_size; }; -- 2.43.0