From d06b6e609c482b9c45dce75a43003e8bbad4ccd9 Mon Sep 17 00:00:00 2001 From: Aadarsh Date: Sat, 4 Nov 2023 16:00:55 +0530 Subject: [PATCH] Fix bug in deleteRelCatEntry(#1) * Bug in deleteRelCatEntry modified: block_access.cpp * - Typo in previous commit corrected to `relcat_rec[1]` - The slot map update should be done after the getRecord to avoid error messages --- block_access.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block_access.cpp b/block_access.cpp index f959993..8ae1daf 100644 --- a/block_access.cpp +++ b/block_access.cpp @@ -936,19 +936,22 @@ int deleteRelCatEntry(recId relcat_recid, Attribute relcat_rec[6]) { relcat_header.numEntries = relcat_header.numEntries - 1; setHeader(&relcat_header, 4); unsigned char relcat_slotmap[20]; - getSlotmap(relcat_slotmap, 4); - relcat_slotmap[relcat_recid.slot] = SLOT_UNOCCUPIED; - setSlotmap(relcat_slotmap, 20, relcat_recid.block); - + getRecord(relcat_rec, 4, 0); relcat_rec[2].nval = relcat_rec[2].nval - 1; setRecord(relcat_rec, 4, 0); + getRecord(relcat_rec, 4, relcat_recid.slot); int no_of_attrs = relcat_rec[1].nval; + getRecord(relcat_rec, 4, 1); relcat_rec[2].nval = relcat_rec[2].nval - no_of_attrs; setRecord(relcat_rec, 4, 1); + getSlotmap(relcat_slotmap, 4); + relcat_slotmap[relcat_recid.slot] = SLOT_UNOCCUPIED; + setSlotmap(relcat_slotmap, 20, relcat_recid.block); + FILE *disk = fopen(&DISK_PATH[0], "rb+"); fseek(disk, (relcat_recid.block) * BLOCK_SIZE + HEADER_SIZE + SLOTMAP_SIZE_RELCAT_ATTRCAT + relcat_recid.slot * NO_OF_ATTRS_RELCAT_ATTRCAT * ATTR_SIZE, SEEK_SET);