libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
identify.c
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <errno.h>
20#include <stdio.h>
21
22#include <aaruformat.h>
23
84int aaruf_identify(const char *filename)
85{
86 if(filename == NULL) return EINVAL;
87
88 FILE *stream = NULL;
89
90 stream = fopen(filename, "rb");
91
92 if(stream == NULL) return errno;
93
94 const int ret = aaruf_identify_stream(stream);
95
96 fclose(stream);
97
98 return ret;
99}
100
163int aaruf_identify_stream(FILE *image_stream)
164{
165 if(image_stream == NULL) return 0;
166
167 if(fseek(image_stream, 0, SEEK_SET) != 0) return 0;
168
169 AaruHeader header;
170
171 const size_t ret = fread(&header, sizeof(AaruHeader), 1, image_stream);
172
173 if(ret != 1) return 0;
174
175 if((header.identifier == DIC_MAGIC || header.identifier == AARU_MAGIC) && header.imageMajorVersion <= AARUF_VERSION)
176 return 100;
177
178 return 0;
179}
#define DIC_MAGIC
Magic identifier for legacy DiscImageChef container (ASCII "DICMFRMT").
Definition consts.h:61
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
Definition consts.h:64
#define AARUF_VERSION
Current image format major version (incompatible changes bump this).
Definition consts.h:68
int aaruf_identify_stream(FILE *image_stream)
Identifies a file as an AaruFormat image using an open stream.
Definition identify.c:163
int aaruf_identify(const char *filename)
Identifies a file as an AaruFormat image using a file path.
Definition identify.c:84
Version 1 container header placed at offset 0 for legacy / initial format.
Definition header.h:77
uint8_t imageMajorVersion
Container format major version (incompatible changes when incremented).
Definition header.h:80
uint64_t identifier
File magic (AARU_MAGIC).
Definition header.h:78