2019-03-17 19:07:57 +00:00
|
|
|
// /***************************************************************************
|
2020-03-01 19:50:12 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2019-03-17 19:07:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : identify.c
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Disk image plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Identifies DiscImageChef format disk images.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:47:47 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2019-03-17 19:07:57 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2020-03-01 19:51:13 +00:00
|
|
|
#include <aaruformat.h>
|
2019-03-17 19:07:57 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2020-03-01 19:49:43 +00:00
|
|
|
//! Identifies a file as aaruformat, using path
|
2019-03-17 19:07:57 +00:00
|
|
|
/*!
|
|
|
|
|
*
|
|
|
|
|
* @param filename path to the file to identify
|
|
|
|
|
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
|
|
|
|
|
* If negative, error value
|
|
|
|
|
*/
|
2019-08-03 01:58:19 +01:00
|
|
|
int identify(const char* filename)
|
2019-03-17 19:07:57 +00:00
|
|
|
{
|
2019-08-03 01:58:19 +01:00
|
|
|
FILE* stream;
|
2019-03-17 19:07:57 +00:00
|
|
|
|
|
|
|
|
stream = fopen(filename, "rb");
|
|
|
|
|
|
2019-03-31 20:52:06 +01:00
|
|
|
if(stream == NULL) return errno;
|
2019-03-17 19:07:57 +00:00
|
|
|
|
|
|
|
|
int ret = identifyStream(stream);
|
|
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-01 19:49:43 +00:00
|
|
|
//! Identifies a file as aaruformat, using an already existing stream
|
2019-03-17 19:07:57 +00:00
|
|
|
/*!
|
|
|
|
|
*
|
|
|
|
|
* @param imageStream stream of the file to identify
|
|
|
|
|
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
|
|
|
|
|
* If negative, error value
|
|
|
|
|
*/
|
2019-08-03 01:58:19 +01:00
|
|
|
int identifyStream(FILE* imageStream)
|
2019-03-17 19:07:57 +00:00
|
|
|
{
|
|
|
|
|
fseek(imageStream, 0, SEEK_SET);
|
|
|
|
|
|
2020-03-01 19:55:22 +00:00
|
|
|
AaruHeader header;
|
2019-03-17 19:07:57 +00:00
|
|
|
|
2020-03-01 19:55:22 +00:00
|
|
|
size_t ret = fread(&header, sizeof(AaruHeader), 1, imageStream);
|
2019-03-17 19:07:57 +00:00
|
|
|
|
2020-03-01 19:55:22 +00:00
|
|
|
if(ret < sizeof(AaruHeader)) return 0;
|
2019-03-17 19:07:57 +00:00
|
|
|
|
2020-03-01 19:53:05 +00:00
|
|
|
if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= AARUF_VERSION) return 100;
|
2019-03-17 19:07:57 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|