X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/aaa9a007ee4af6b40d2eefef15bccc51f92e17d9..d1cfb7971a17f744717953a0466ee2efbd53f442:/src/btree.cpp?ds=inline 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);