mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Read uncompressed user data deduplication table.
This commit is contained in:
@@ -50,6 +50,10 @@ typedef struct dicformatContext
|
|||||||
unsigned char *sectorSuffixCorrected;
|
unsigned char *sectorSuffixCorrected;
|
||||||
unsigned char *sectorSubchannel;
|
unsigned char *sectorSubchannel;
|
||||||
unsigned char *mode2Subheaders;
|
unsigned char *mode2Subheaders;
|
||||||
|
byte shift;
|
||||||
|
bool inMemoryDdt;
|
||||||
|
uint64_t *userDataDdt;
|
||||||
|
size_t mappedMemoryDdtSize;
|
||||||
} dicformatContext;
|
} dicformatContext;
|
||||||
|
|
||||||
typedef struct dataLinkedList
|
typedef struct dataLinkedList
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <dicformat.h>
|
#include <dicformat.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
int close(void *context)
|
int close(void *context)
|
||||||
{
|
{
|
||||||
@@ -82,6 +83,10 @@ int close(void *context)
|
|||||||
free(ctx->mediaTagsHead);
|
free(ctx->mediaTagsHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!ctx->inMemoryDdt)
|
||||||
|
{
|
||||||
|
munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize);
|
||||||
|
}
|
||||||
free(context);
|
free(context);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
53
src/open.c
53
src/open.c
@@ -37,6 +37,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
// TODO: Check CRC64 on structures
|
// TODO: Check CRC64 on structures
|
||||||
// TODO: ImageInfo
|
// TODO: ImageInfo
|
||||||
@@ -178,6 +179,9 @@ void *open(const char *filepath)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlockHeader blockHeader;
|
||||||
|
DdtHeader ddtHeader;
|
||||||
|
|
||||||
switch(idxEntries[i].blockType)
|
switch(idxEntries[i].blockType)
|
||||||
{
|
{
|
||||||
case DataBlock:
|
case DataBlock:
|
||||||
@@ -185,8 +189,6 @@ void *open(const char *filepath)
|
|||||||
if(idxEntries[i].dataType == NoData)
|
if(idxEntries[i].dataType == NoData)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
BlockHeader blockHeader;
|
|
||||||
|
|
||||||
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
|
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
|
||||||
|
|
||||||
if(readBytes != sizeof(BlockHeader))
|
if(readBytes != sizeof(BlockHeader))
|
||||||
@@ -376,8 +378,51 @@ void *open(const char *filepath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DeDuplicationTable:
|
case DeDuplicationTable:readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
|
||||||
// TODO
|
|
||||||
|
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;
|
break;
|
||||||
case GeometryBlock:
|
case GeometryBlock:
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user