From 629401939d56b47a82d13a245641be04aa97194a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 1 Mar 2020 19:58:09 +0000 Subject: [PATCH] Add new magic number. --- include/aaruformat/consts.h | 4 +++- src/close.c | 2 +- src/identify.c | 3 ++- src/open.c | 4 ++-- src/read.c | 8 ++++---- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/aaruformat/consts.h b/include/aaruformat/consts.h index dc3cd64..3b24580 100644 --- a/include/aaruformat/consts.h +++ b/include/aaruformat/consts.h @@ -35,8 +35,10 @@ #ifndef LIBAARUFORMAT_CONSTS_H #define LIBAARUFORMAT_CONSTS_H -/** Magic identidier = "DICMFMT". */ +/** Magic identidier = "DICMFRMT". */ #define DIC_MAGIC 0x544D52464D434944 +/** Magic identidier = "AARUFRMT". */ +#define AARU_MAGIC 0x544D524655524141 /** Image format version. A change in this number indicates an incompatible change to the format that prevents older * implementations from reading it correctly, if at all. */ #define AARUF_VERSION 1 diff --git a/src/close.c b/src/close.c index 1d3347e..014b885 100644 --- a/src/close.c +++ b/src/close.c @@ -49,7 +49,7 @@ int close(void* context) aaruformatContext* ctx = context; // Not a libaaruformat context - if(ctx->magic != DIC_MAGIC) + if(ctx->magic != AARU_MAGIC) { errno = EINVAL; return -1; diff --git a/src/identify.c b/src/identify.c index b0cefdd..f42fe04 100644 --- a/src/identify.c +++ b/src/identify.c @@ -73,7 +73,8 @@ int identifyStream(FILE* imageStream) if(ret < sizeof(AaruHeader)) return 0; - if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= AARUF_VERSION) return 100; + if((header.identifier == DIC_MAGIC || header.identifier == AARU_MAGIC) && header.imageMajorVersion <= AARUF_VERSION) + return 100; return 0; } \ No newline at end of file diff --git a/src/open.c b/src/open.c index af2af89..7bdb1b9 100644 --- a/src/open.c +++ b/src/open.c @@ -80,7 +80,7 @@ void* open(const char* filepath) return NULL; } - if(ctx->header.identifier != DIC_MAGIC) + if(ctx->header.identifier != DIC_MAGIC && ctx->header.identifier != AARU_MAGIC) { free(ctx); errno = AARUF_ERROR_NOT_AARUFORMAT; @@ -1172,7 +1172,7 @@ void* open(const char* filepath) // Initialize ECC for Compact Disc ctx->eccCdContext = (CdEccContext*)ecc_cd_init(); - ctx->magic = DIC_MAGIC; + ctx->magic = AARU_MAGIC; ctx->libraryMajorVersion = LIBAARUFORMAT_MAJOR_VERSION; ctx->libraryMinorVersion = LIBAARUFORMAT_MINOR_VERSION; diff --git a/src/read.c b/src/read.c index e4ff9f0..d53d7f3 100644 --- a/src/read.c +++ b/src/read.c @@ -44,7 +44,7 @@ int32_t read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* leng ctx = context; // Not a libaaruformat context - if(ctx->magic != DIC_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; + if(ctx->magic != AARU_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; item = ctx->mediaTagsHead; @@ -85,7 +85,7 @@ int32_t read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32 ctx = context; // Not a libaaruformat context - if(ctx->magic != DIC_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; + if(ctx->magic != AARU_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; if(sectorAddress > ctx->imageInfo.Sectors - 1) return AARUF_ERROR_SECTOR_OUT_OF_BOUNDS; @@ -158,7 +158,7 @@ int32_t read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, ctx = context; // Not a libaaruformat context - if(ctx->magic != DIC_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; + if(ctx->magic != AARU_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; if(ctx->imageInfo.XmlMediaType != OpticalDisc) return AARUF_ERROR_INCORRECT_MEDIA_TYPE; @@ -187,7 +187,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u ctx = context; // Not a libaaruformat context - if(ctx->magic != DIC_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; + if(ctx->magic != AARU_MAGIC) return AARUF_ERROR_NOT_AARUFORMAT; switch(ctx->imageInfo.XmlMediaType) {