void gdbWriteFreeBlockList(GDatabase *db, GdbFreeBlock *blocks, uint32_t count) { uint32_t listSize; uint8_t *buffer; uint32_t i, counter = 0; offset_t __offset; if (db == NULL || blocks == NULL) { return; } /* Get the total size of the list. */ listSize = sizeof(uint32_t) + count * (sizeof(uint16_t) + sizeof(offset_t)); /* Allocate the buffer for the block list. */ MEM_CHECK(buffer = (uint8_t *)SAFE_MALLOC(listSize, LOC_DB_0006)); gdbPut32(buffer, &counter, count); for (i = 0; i < count; i++) { gdbPut16(buffer, &counter, blocks[i].size); gdbPutOffset(buffer, &counter, blocks[i].offset); } rawFileSeek(db->idxRawFile, DB_FREE_BLOCK_LIST_OFFSET, SEEK_SET); __offset = DB_FREE_BLOCK_LIST_OFFSET; rawFileWrite(db->idxRawFile, __offset, buffer, listSize, 1, LOC_DB_0007); SAFE_FREE(buffer, LOC_DB_0008); }
void gdbWriteHeader(GDatabase *db) { uint8_t version[2]; uint8_t type; offset_t offset; if (db == NULL || db->idxRawFile == NULL) { return; } version[0] = DB_MAJOR_VER; version[1] = DB_MINOR_VER; type = db->type; rawFileSeek(db->idxRawFile, 0, SEEK_SET); offset = 0; /* Write the magic string. */ rawFilePuts(db->idxRawFile, offset, DB_MAGIC); offset += strlen(DB_MAGIC); rawFileWrite(db->idxRawFile, offset, version, sizeof(uint8_t), 2, LOC_DB_0011); offset += (sizeof(uint8_t) * 2); rawFileWrite(db->idxRawFile, offset, &type, sizeof(uint8_t), 1, LOC_DB_0012); offset += sizeof(uint8_t); if (DB_HEADER_BLOCK_SIZE > DB_HEADER_DATA_SIZE) { gdbPad(db->idxRawFile, offset, DB_HEADER_BLOCK_SIZE - DB_HEADER_DATA_SIZE); } }