Skip to content

Commit

Permalink
Fix bug in deleteRelCatEntry(#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vikram18rock authored Nov 4, 2023
1 parent a45e368 commit d06b6e6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions block_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d06b6e6

Please sign in to comment.