/* * API */ void close_DEHT_files(DEHT * deht) { if (deht == NULL) { return; } write_DEHT_pointers_table(deht); if (deht->hashTableOfPointersImageInMemory != NULL) { free(deht->hashTableOfPointersImageInMemory); deht->hashTableOfPointersImageInMemory = NULL; } if (deht->hashPointersForLastBlockImageInMemory != NULL) { free(deht->hashPointersForLastBlockImageInMemory); deht->hashPointersForLastBlockImageInMemory = NULL; } if (deht->anLastBlockSize != NULL) { free(deht->anLastBlockSize); deht->anLastBlockSize = NULL; } /* no point in checking return value of fclose -- this function is void * anyway and is not meant to report errors back */ if (deht->keyFP != NULL) { fclose(deht->keyFP); deht->keyFP = NULL; } if (deht->dataFP != NULL) { fclose(deht->dataFP); deht->dataFP = NULL; } /* since we malloc()'ed the deht, it's time for us to free() it */ free(deht); }
void lock_DEHT_files(DEHT *ht) { TRACE_FUNC_ENTRY(); /* If present, serialize pointer table to disk. Errors are ignored - we try to do as much as we can in spite of error in the name of robustness */ (void) write_DEHT_pointers_table(ht); /* If present, serialize user data to disk. Errors are ignored - we try to do as much as we can in spite of error in the name of robustness */ (void) DEHT_writeUserBytes(ht); DEHT_freeResources(ht, FALSE); }
int calc_DEHT_last_block_per_bucket(DEHT *ht) { int ret = DEHT_STATUS_FAIL; size_t rawTableSize = 0; ulong_t bucketIndex = 0; int pointerTableLoadRes = 0; TRACE_FUNC_ENTRY(); CHECK(NULL != ht); if (NULL != ht->hashPointersForLastBlockImageInMemory) { return DEHT_STATUS_NOT_NEEDED; } /* We will be scanning the entire bucket table. It would be wise to use the first block cache for this step */ pointerTableLoadRes = read_DEHT_pointers_table(ht); /* alloc cache */ rawTableSize = ht->header.numEntriesInHashTable * sizeof(DEHT_DISK_PTR); ht->hashPointersForLastBlockImageInMemory = malloc(rawTableSize); CHECK_MSG("malloc", (NULL != ht->hashPointersForLastBlockImageInMemory)); for (bucketIndex = 0; bucketIndex < ht->header.numEntriesInHashTable; ++bucketIndex) { CHECK(DEHT_findLastBlockForBucketDumb(ht, bucketIndex, ht->hashPointersForLastBlockImageInMemory + bucketIndex)); } ret = DEHT_STATUS_SUCCESS; goto LBL_CLEANUP; LBL_ERROR: /* free on error */ FREE(ht->hashPointersForLastBlockImageInMemory); ret = DEHT_STATUS_FAIL; TRACE_FUNC_ERROR(); LBL_CLEANUP: /* If the first block pointer table wasn't loaded before us, we should unload it (errors are silenced) */ if (DEHT_STATUS_SUCCESS == pointerTableLoadRes) { (void) write_DEHT_pointers_table(ht); } TRACE_FUNC_EXIT(); return ret; }