Loading...
Searching...
No Matches
identify.c
Go to the documentation of this file.
/*
* This file is part of the Aaru Data Preservation Suite.
* Copyright (c) 2019-2026 Natalia Portillo.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <stdio.h>
#include <aaruformat.h>
AARU_EXPORT int AARU_CALL aaruf_identify(const char *filename)
{
if(filename == NULL) return EINVAL;
FILE *stream = NULL;
stream = fopen(filename, "rb");
if(stream == NULL) return errno;
const int ret = aaruf_identify_stream(stream);
fclose(stream);
return ret;
}
AARU_EXPORT int AARU_CALL aaruf_identify_stream(FILE *image_stream)
{
if(image_stream == NULL) return 0;
if(fseek(image_stream, 0, SEEK_SET) != 0) return 0;
AaruHeader header;
const size_t ret = fread(&header, sizeof(AaruHeader), 1, image_stream);
if(ret != 1) return 0;
if((header.identifier == DIC_MAGIC || header.identifier == AARU_MAGIC) && header.imageMajorVersion <= AARUF_VERSION)
return 100;
return 0;
}
aaruformat.h
DIC_MAGIC
#define DIC_MAGIC
Magic identifier for legacy DiscImageChef container (ASCII "DICMFRMT").
Definition consts.h:61
AARU_MAGIC
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
Definition consts.h:64
AARUF_VERSION
#define AARUF_VERSION
Current image format major version (incompatible changes bump this).
Definition consts.h:68
AARU_CALL
#define AARU_CALL
Definition decls.h:46
AARU_EXPORT
#define AARU_EXPORT
Definition decls.h:55
aaruf_identify_stream
int aaruf_identify_stream(FILE *image_stream)
Identifies a file as an AaruFormat image using an open stream.
Definition identify.c:163
aaruf_identify
int aaruf_identify(const char *filename)
Identifies a file as an AaruFormat image using a file path.
Definition identify.c:84
AaruHeader
Version 1 container header placed at offset 0 for legacy / initial format.
Definition header.h:77
AaruHeader::imageMajorVersion
uint8_t imageMajorVersion
Container format major version (incompatible changes when incremented).
Definition header.h:80
AaruHeader::identifier
uint64_t identifier
File magic (AARU_MAGIC).
Definition header.h:78