NITCbase / nitcbase.github.io

The entire documentation on implementing the NITCbase project.
https://nitcbase.github.io/
MIT License
10 stars 6 forks source link

BlockBuffer::getFreeBlock Error Handling, Constructor 1 Issue, DISK_FULL issue #33

Closed jessiyajoy closed 1 year ago

jessiyajoy commented 2 years ago
gokulsreekumar commented 2 years ago
SaintNerevar commented 2 years ago

The second point in

  • Block type is already set when setting the header using setHeader(). There is no need to call setBlockType again.
  • setHeader() also calls getBufferPtr() which in turn calls getBlock() which calls getFreeBuffer() (everytime since the block number corresponds to an unallocated block) which makes calling getFreeBuffer() in getFreeBlock() unnecessary.

is probably confusing.

The idea is that getFreeBlock() sets the header of the newly allocated (not yet buffered) block. This results in a call to getFreeBuffer() everytime. That's why calling getFreeBuffer() in getFreeBlock() is unnecessary

gokulsreekumar commented 2 years ago
jessiyajoy commented 2 years ago
// Constructor 1
BlockBuffer::BlockBuffer(char blockType) {
    // allocate a block on the disc and a buffer in memory to hold the new block of given type using getFreeBlock function.
    int newBlockNum;

    switch (blockType) {
        case 'R':
            newBlockNum = getFreeBlock(REC);
            break;
        case 'I':
            newBlockNum = getFreeBlock(IND_INTERNAL);
            break;
        case 'L':
            newBlockNum = getFreeBlock(IND_LEAF);
            break;
        default:
            newBlockNum = FAILURE;
    }

    // set the blockNum field of the object to that of the allocated block number.
    // TODO: what happens if disk full..note down
    this->blockNum = newBlockNum;
}
gokulsreekumar commented 2 years ago

Done

clifordjoshy commented 1 year ago

verified that the caller handles E_DISKFULL wherever the constructor is in use.