Read uncompressed user data deduplication table.

This commit is contained in:
2019-03-17 23:19:13 +00:00
parent 3d070e8fc2
commit d54284db4c
3 changed files with 58 additions and 4 deletions

View File

@@ -50,6 +50,10 @@ typedef struct dicformatContext
unsigned char *sectorSuffixCorrected;
unsigned char *sectorSubchannel;
unsigned char *mode2Subheaders;
byte shift;
bool inMemoryDdt;
uint64_t *userDataDdt;
size_t mappedMemoryDdtSize;
} dicformatContext;
typedef struct dataLinkedList

View File

@@ -34,6 +34,7 @@
#include <dicformat.h>
#include <malloc.h>
#include <errno.h>
#include <sys/mman.h>
int close(void *context)
{
@@ -82,6 +83,10 @@ int close(void *context)
free(ctx->mediaTagsHead);
}
if(!ctx->inMemoryDdt)
{
munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize);
}
free(context);
return 0;

View File

@@ -37,6 +37,7 @@
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include <sys/mman.h>
// TODO: Check CRC64 on structures
// TODO: ImageInfo
@@ -178,6 +179,9 @@ void *open(const char *filepath)
continue;
}
BlockHeader blockHeader;
DdtHeader ddtHeader;
switch(idxEntries[i].blockType)
{
case DataBlock:
@@ -185,8 +189,6 @@ void *open(const char *filepath)
if(idxEntries[i].dataType == NoData)
break;
BlockHeader blockHeader;
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
if(readBytes != sizeof(BlockHeader))
@@ -376,8 +378,51 @@ void *open(const char *filepath)
}
break;
case DeDuplicationTable:
// TODO
case DeDuplicationTable:readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
if(readBytes != sizeof(DdtHeader))
{
fprintf(stderr, "libdicformat: Could not read block header at %"PRIu64"", idxEntries[i].offset);
break;
}
foundUserDataDdt = true;
if(idxEntries[i].dataType == UserData)
{
ctx->shift = ddtHeader.shift;
// Check for DDT compression
switch(ddtHeader.compression)
{
case None:ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
ctx->userDataDdt =
mmap(NULL,
ctx->mappedMemoryDdtSize,
PROT_READ,
MAP_SHARED,
fileno(ctx->imageStream),
idxEntries[i].offset + sizeof(ddtHeader));
if(ctx->userDataDdt == MAP_FAILED)
{
foundUserDataDdt = false;
fprintf(stderr, "libdicformat: Could not read map deduplication table.");
break;
}
ctx->inMemoryDdt = false;
break;
default:
fprintf(stderr,
"libdicformat: Found unknown compression type %d, continuing...",
blockHeader.compression);
foundUserDataDdt = false;
break;
}
}
break;
case GeometryBlock:
// TODO