2019-03-17 20:39:40 +00:00
|
|
|
// /***************************************************************************
|
2020-03-01 19:50:12 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2019-03-17 20:39:40 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : close.c
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2020-03-01 19:51:13 +00:00
|
|
|
// Component : libaaruformat.
|
2019-03-17 20:39:40 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2020-03-01 19:55:50 +00:00
|
|
|
// Handles closing Aaru format disk images.
|
2019-03-17 20:39:40 +00:00
|
|
|
//
|
|
|
|
|
// --[ 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 20:39:40 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2020-03-01 19:51:13 +00:00
|
|
|
#include <aaruformat.h>
|
2019-03-17 20:39:40 +00:00
|
|
|
#include <errno.h>
|
2019-03-31 20:52:06 +01:00
|
|
|
#include <malloc.h>
|
|
|
|
|
#include <stdio.h>
|
2019-03-17 23:19:13 +00:00
|
|
|
#include <sys/mman.h>
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2019-08-03 01:58:19 +01:00
|
|
|
int close(void* context)
|
2019-03-17 20:39:40 +00:00
|
|
|
{
|
2019-08-03 02:11:36 +01:00
|
|
|
int i;
|
|
|
|
|
|
2019-03-17 20:39:40 +00:00
|
|
|
if(context == NULL)
|
|
|
|
|
{
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-01 19:51:13 +00:00
|
|
|
aaruformatContext* ctx = context;
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2020-03-01 19:51:13 +00:00
|
|
|
// Not a libaaruformat context
|
2019-03-17 20:39:40 +00:00
|
|
|
if(ctx->magic != DIC_MAGIC)
|
|
|
|
|
{
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-17 22:41:04 +00:00
|
|
|
// This may do nothing if imageStream is NULL, but as the behaviour is undefined, better sure than sorry
|
2019-03-31 20:52:06 +01:00
|
|
|
if(ctx->imageStream != NULL) fclose(ctx->imageStream);
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorPrefix);
|
|
|
|
|
free(ctx->sectorPrefixCorrected);
|
|
|
|
|
free(ctx->sectorSuffix);
|
|
|
|
|
free(ctx->sectorSuffixCorrected);
|
|
|
|
|
free(ctx->sectorSubchannel);
|
|
|
|
|
free(ctx->mode2Subheaders);
|
|
|
|
|
|
2019-03-17 23:01:54 +00:00
|
|
|
if(ctx->mediaTagsTail != NULL)
|
|
|
|
|
{
|
2019-08-03 01:58:19 +01:00
|
|
|
dataLinkedList* mediaTag = ctx->mediaTagsTail;
|
2019-03-17 23:01:54 +00:00
|
|
|
|
|
|
|
|
while(mediaTag->previous != NULL)
|
|
|
|
|
{
|
|
|
|
|
free(mediaTag->data);
|
|
|
|
|
mediaTag = mediaTag->previous;
|
|
|
|
|
free(mediaTag->next);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ctx->mediaTagsHead != NULL)
|
|
|
|
|
{
|
|
|
|
|
free(ctx->mediaTagsHead->data);
|
|
|
|
|
free(ctx->mediaTagsHead);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 20:52:06 +01:00
|
|
|
if(!ctx->inMemoryDdt) { munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize); }
|
2019-03-17 23:25:45 +00:00
|
|
|
|
|
|
|
|
free(ctx->sectorPrefixDdt);
|
|
|
|
|
free(ctx->sectorSuffixDdt);
|
|
|
|
|
|
2019-03-17 23:41:07 +00:00
|
|
|
free(ctx->metadataBlock);
|
2019-03-18 00:10:24 +00:00
|
|
|
free(ctx->trackEntries);
|
2019-03-18 22:06:10 +00:00
|
|
|
free(ctx->cicmBlock);
|
2019-03-17 23:41:07 +00:00
|
|
|
|
2019-03-20 00:23:30 +00:00
|
|
|
if(ctx->dumpHardwareEntriesWithData != NULL)
|
|
|
|
|
{
|
2019-08-03 02:11:36 +01:00
|
|
|
for(i = 0; i < ctx->dumpHardwareHeader.entries; i++)
|
2019-03-20 00:23:30 +00:00
|
|
|
{
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].extents);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].manufacturer);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].model);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].revision);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].firmware);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].serial);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareName);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareVersion);
|
|
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareOperatingSystem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 14:56:03 +01:00
|
|
|
free(ctx->readableSectorTags);
|
|
|
|
|
|
2019-03-17 20:39:40 +00:00
|
|
|
free(context);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|