cache.c
//Should only be called for active blocks (just added the access queue)
Should only be called for active blocks (just added the access queue)
Should only be called for active blocks ( just added the access queue )
bool addBlockMapping(activity_table_t* hostTable, block_list_node_t* toAdd) {
    if(!hostTable) {
        fprintf(stderr, "The hosting activity table has no been properly initialized.\n");
        return false;
    }
    if(!toAdd || (toAdd->block->id == BLOCK_IS_FREE)) {
        fprintf(stderr, "You must fully initialize and assign a block to a block node before creating a mapping for it.\n");
        return false;
    }
    block_mapping_node_t* newNode = initializeMappingNode(toAdd);
    if(!newNode) {
        return false; 
    }
    uint32_t targetSector = lookupMapping(toAdd->block->id);
    block_mapping_node_t* sentinel = hostTable->ActiveBlockMap[targetSector];
    if(!sentinel) {
        hostTable->ActiveBlockMap[targetSector] = newNode;
        return true;
    }
    else{
        while(sentinel) {
            if( !(sentinel->next) ) {
                sentinel->next = newNode;
                return true;
            }
            sentinel = sentinel->next;
        }
    }
    return false;
}
bool addBlockMapping ( activity_table_t * hostTable , block_list_node_t * toAdd ) { if ( ! hostTable ) { fprintf ( stderr , " \n " ) ; return false ; } if ( ! toAdd || ( toAdd -> block -> id == BLOCK_IS_FREE ) ) { fprintf ( stderr , " \n " ) ; return false ; } block_mapping_node_t * newNode = initializeMappingNode ( toAdd ) ; if ( ! newNode ) { return false ; } uint32_t targetSector = lookupMapping ( toAdd -> block -> id ) ; block_mapping_node_t * sentinel = hostTable -> ActiveBlockMap [ targetSector ] ; if ( ! sentinel ) { hostTable -> ActiveBlockMap [ targetSector ] = newNode ; return true ; } else { while ( sentinel ) { if ( ! ( sentinel -> next ) ) { sentinel -> next = newNode ; return true ; } sentinel = sentinel -> next ; } } return false ; }
Should only be called for active blocks (just added the access queue)
Should only be called for active blocks ( just added the access queue )
//initializer outputs an err msg already //Adding to a list / sector