2022-05-28 12:57:21 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Aaru Data Preservation Suite.
|
2025-08-01 21:19:45 +01:00
|
|
|
* Copyright (c) 2019-2025 Natalia Portillo.
|
2022-05-28 12:57:21 +01:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
2019-03-17 20:39:40 +00:00
|
|
|
|
|
|
|
|
#include <errno.h>
|
2019-03-31 20:52:06 +01:00
|
|
|
#include <stdio.h>
|
2022-10-03 18:15:13 +01:00
|
|
|
#include <stdlib.h>
|
2022-06-21 21:08:19 +01:00
|
|
|
|
|
|
|
|
#ifdef __linux__
|
2019-03-17 23:19:13 +00:00
|
|
|
#include <sys/mman.h>
|
2022-06-21 21:08:19 +01:00
|
|
|
#endif
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2022-05-28 12:10:04 +01:00
|
|
|
#include <aaruformat.h>
|
|
|
|
|
|
2024-04-30 15:51:32 +01:00
|
|
|
int aaruf_close(void *context)
|
2019-03-17 20:39:40 +00:00
|
|
|
{
|
2025-08-01 15:34:36 +01:00
|
|
|
int i = 0;
|
|
|
|
|
mediaTagEntry *mediaTag = NULL;
|
|
|
|
|
mediaTagEntry *tmpMediaTag = NULL;
|
2019-08-03 02:11:36 +01:00
|
|
|
|
2019-03-17 20:39:40 +00:00
|
|
|
if(context == NULL)
|
|
|
|
|
{
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 15:51:32 +01:00
|
|
|
aaruformatContext *ctx = context;
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2020-03-01 19:51:13 +00:00
|
|
|
// Not a libaaruformat context
|
2020-03-01 19:58:09 +00:00
|
|
|
if(ctx->magic != AARU_MAGIC)
|
2019-03-17 20:39:40 +00:00
|
|
|
{
|
|
|
|
|
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
|
2022-10-03 19:31:39 +01:00
|
|
|
if(ctx->imageStream != NULL)
|
|
|
|
|
{
|
|
|
|
|
fclose(ctx->imageStream);
|
|
|
|
|
ctx->imageStream = NULL;
|
|
|
|
|
}
|
2019-03-17 20:39:40 +00:00
|
|
|
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorPrefix);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorPrefix = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorPrefixCorrected);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorPrefixCorrected = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorSuffix);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorSuffix = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorSuffixCorrected);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorSuffixCorrected = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->sectorSubchannel);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorSubchannel = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
free(ctx->mode2Subheaders);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->mode2Subheaders = NULL;
|
2019-03-17 22:41:04 +00:00
|
|
|
|
2022-10-04 20:32:26 +01:00
|
|
|
if(ctx->mediaTags != NULL)
|
2019-03-17 23:01:54 +00:00
|
|
|
{
|
2022-10-04 20:32:26 +01:00
|
|
|
HASH_ITER(hh, ctx->mediaTags, mediaTag, tmpMediaTag)
|
2019-03-17 23:01:54 +00:00
|
|
|
{
|
2022-10-04 20:32:26 +01:00
|
|
|
HASH_DEL(ctx->mediaTags, mediaTag);
|
2019-03-17 23:01:54 +00:00
|
|
|
free(mediaTag->data);
|
2022-10-04 20:32:26 +01:00
|
|
|
free(mediaTag);
|
2019-03-17 23:01:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 15:51:32 +01:00
|
|
|
#ifdef __linux__ // TODO: Implement
|
2022-10-03 19:31:39 +01:00
|
|
|
if(!ctx->inMemoryDdt)
|
|
|
|
|
{
|
|
|
|
|
munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize);
|
|
|
|
|
ctx->userDataDdt = NULL;
|
|
|
|
|
}
|
2022-06-21 21:08:19 +01:00
|
|
|
#endif
|
2019-03-17 23:25:45 +00:00
|
|
|
|
|
|
|
|
free(ctx->sectorPrefixDdt);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorPrefixDdt = NULL;
|
2019-03-17 23:25:45 +00:00
|
|
|
free(ctx->sectorSuffixDdt);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->sectorSuffixDdt = NULL;
|
2019-03-17 23:25:45 +00:00
|
|
|
|
2019-03-17 23:41:07 +00:00
|
|
|
free(ctx->metadataBlock);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->metadataBlock = NULL;
|
2019-03-18 00:10:24 +00:00
|
|
|
free(ctx->trackEntries);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->trackEntries = NULL;
|
2019-03-18 22:06:10 +00:00
|
|
|
free(ctx->cicmBlock);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->cicmBlock = NULL;
|
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);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].extents = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].manufacturer);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].manufacturer = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].model);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].model = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].revision);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].revision = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].firmware);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].firmware = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].serial);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].serial = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareName);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].softwareName = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareVersion);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].softwareVersion = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
free(ctx->dumpHardwareEntriesWithData[i].softwareOperatingSystem);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData[i].softwareOperatingSystem = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
}
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->dumpHardwareEntriesWithData = NULL;
|
2019-03-20 00:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-31 14:56:03 +01:00
|
|
|
free(ctx->readableSectorTags);
|
2022-10-03 19:31:39 +01:00
|
|
|
ctx->readableSectorTags = NULL;
|
|
|
|
|
|
2022-10-03 19:32:25 +01:00
|
|
|
free(ctx->eccCdContext);
|
|
|
|
|
ctx->eccCdContext = NULL;
|
|
|
|
|
|
2022-10-04 19:44:34 +01:00
|
|
|
free(ctx->checksums.spamsum);
|
|
|
|
|
ctx->checksums.spamsum = NULL;
|
|
|
|
|
|
2022-10-03 19:31:39 +01:00
|
|
|
// TODO: Free caches
|
2019-03-31 14:56:03 +01:00
|
|
|
|
2019-03-17 20:39:40 +00:00
|
|
|
free(context);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|