hashfile/src/hash_file.c
HT_ErrorCode HT_OpenIndex(const char *fileName, int *indexDesc){
    CALL_BF(BF_OpenFile(fileName, indexDesc));

    if(*indexDesc >= MAX_OPEN_FILES){
    	printf("Error: too many opened files.\n");
	return HT_ERROR;
    }

    char *data;
    BF_Block *block;
    BF_Block_Init(&block);

    CALL_BF(BF_GetBlock(*indexDesc, 0, block));
    data = BF_Block_GetData(block);
     
    if (*data != '*'){
            return HT_ERROR;
    }
    memcpy(&table[*indexDesc], data+sizeof(char), sizeof(int));
    CALL_BF(BF_UnpinBlock(block));
    BF_Block_Destroy(&block);
    return HT_OK;
}
/**
 * Opening a file requires validation that the file is indeed a hashfile.
 * The only thing that is needed is a check for the '*' identifier at the start.
 */
Opening a file requires validation that the file is indeed a hashfile.
The only thing that is needed is a check for the '*' identifier at the start.
Opening a file requires validation that the file is indeed a hashfile . The only thing that is needed is a check for the ' * ' identifier at the start .
HT_ErrorCode HT_OpenIndex(const char *fileName, int *indexDesc){
    CALL_BF(BF_OpenFile(fileName, indexDesc));
    if(*indexDesc >= MAX_OPEN_FILES){
    	printf("Error: too many opened files.\n");
	return HT_ERROR;
    }
    char *data;
    BF_Block *block;
    BF_Block_Init(&block);
    CALL_BF(BF_GetBlock(*indexDesc, 0, block));
    data = BF_Block_GetData(block);
    if (*data != '*'){
            return HT_ERROR;
    }
    memcpy(&table[*indexDesc], data+sizeof(char), sizeof(int));
    CALL_BF(BF_UnpinBlock(block));
    BF_Block_Destroy(&block);
    return HT_OK;
}
HT_ErrorCode HT_OpenIndex ( const char * fileName , int * indexDesc ) { CALL_BF ( BF_OpenFile ( fileName , indexDesc ) ) ; if ( * indexDesc >= MAX_OPEN_FILES ) { printf ( " \n " ) ; return HT_ERROR ; } char * data ; BF_Block * block ; BF_Block_Init ( & block ) ; CALL_BF ( BF_GetBlock ( * indexDesc , 0 , block ) ) ; data = BF_Block_GetData ( block ) ; if ( * data != ' ' ) { return HT_ERROR ; } memcpy ( & table [ * indexDesc ] , data + sizeof ( char ) , sizeof ( int ) ) ; CALL_BF ( BF_UnpinBlock ( block ) ) ; BF_Block_Destroy ( & block ) ; return HT_OK ; }
Opening a file requires validation that the file is indeed a hashfile.
Opening a file requires validation that the file is indeed a hashfile .