libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
close.c File Reference

Resource cleanup and public aaruf_close() entry point for libaaruformat. More...

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <aaruformat.h>
#include "erasure_internal.h"
#include "internal.h"
#include "log.h"

Go to the source code of this file.

Functions

static void aaruf_set_close_error (const int error_code)
int aaruf_close (void *context)
 Close an Aaru image context, flushing pending data structures and releasing resources.

Detailed Description

Resource cleanup and public aaruf_close() entry point for libaaruformat.

Performs orderly teardown of dynamically allocated resources when closing an Aaru image context, regardless of read or write mode. For write-mode contexts the writer finalization hook (aaruf_finalize_write(), defined in close_write.c) is invoked via a function pointer before cleanup begins.

See also
close_write.c

Definition in file close.c.

Function Documentation

◆ aaruf_close()

int aaruf_close ( void * context)

Close an Aaru image context, flushing pending data structures and releasing resources.

Public API entry point used to finalize an image being written or simply dispose of a context opened for reading. For write-mode contexts the finalize_write function pointer (set during aaruf_create() or resume-mode aaruf_open()) is invoked to flush all pending blocks, DDTs, and the global index before cleanup proceeds.

Afterwards (or for read-mode contexts) all dynamically allocated buffers, arrays, hash tables and mapping structures are freed/unmapped. Media tags are removed from their hash table.

Error Handling:

  • Returns -1 with errno = EINVAL if the provided pointer is NULL or not a valid context.
  • If the writer finalization hook returns an error status, that error value is propagated directly.
Parameters
contextOpaque pointer returned by earlier open/create calls (must be an aaruformatContext).
Returns
0 on success; -1 or negative libaaruformat error code on failure.
Return values
0All pending data flushed (if writing) and resources released successfully.
-1Invalid context pointer (errno = EINVAL).
<negativelibaaruformat code> Propagated from the writer finalization hook.
Note
On success the context memory itself is freed; the caller must not reuse the pointer.

Definition at line 80 of file close.c.

References AARU_CALL, AARU_EXPORT, AARU_MAGIC, aaruf_ecc_cd_free(), aaruf_set_close_error(), AARUF_STATUS_OK, aaruformat_context::block_cache, aaruformat_context::block_header_cache, aaruformat_context::cached_secondary_ddt2, aaruformat_context::checksums, aaruformat_context::cicm_block, mediaTagEntry::data, aaruformat_context::data_tracks, aaruformat_context::dump_hardware_entries_with_data, aaruformat_context::dump_hardware_header, ec_free(), aaruformat_context::ecc_cd_context, DumpHardwareHeader::entries, DumpHardwareEntriesWithData::extents, FATAL, aaruformat_context::finalize_write, DumpHardwareEntriesWithData::firmware, free_cache(), aaruformat_context::imageStream, aaruformat_context::in_memory_ddt, aaruformat_context::index_entries, aaruformat_context::magic, DumpHardwareEntriesWithData::manufacturer, aaruformat_context::mapped_memory_ddt_size, aaruformat_context::mediaTags, aaruformat_context::metadata_block, aaruformat_context::mode2_subheaders, DumpHardwareEntriesWithData::model, aaruformat_context::ngcw_junk_entries, aaruformat_context::ngcw_junk_entry_count, aaruformat_context::ngcw_junk_initialized, aaruformat_context::ngcw_junk_seed_size, aaruformat_context::ps3_disc_key, aaruformat_context::ps3_encryption_initialized, aaruformat_context::ps3_plaintext_region_count, aaruformat_context::ps3_plaintext_regions, aaruformat_context::readableSectorTags, DumpHardwareEntriesWithData::revision, aaruformat_context::sector_cpr_mai, aaruformat_context::sector_edc, aaruformat_context::sector_id, aaruformat_context::sector_ied, aaruformat_context::sector_prefix, aaruformat_context::sector_prefix_corrected, aaruformat_context::sector_prefix_ddt, aaruformat_context::sector_prefix_ddt2, aaruformat_context::sector_subchannel, aaruformat_context::sector_suffix, aaruformat_context::sector_suffix_corrected, aaruformat_context::sector_suffix_ddt, aaruformat_context::sector_suffix_ddt2, DumpHardwareEntriesWithData::serial, DumpHardwareEntriesWithData::softwareName, DumpHardwareEntriesWithData::softwareOperatingSystem, DumpHardwareEntriesWithData::softwareVersion, Checksums::spamsum, TRACE, aaruformat_context::track_entries, aaruformat_context::user_data_ddt, aaruformat_context::user_data_ddt2, aaruformat_context::wii_cache_valid, aaruformat_context::wii_encrypted_group_cache, aaruformat_context::wii_encryption_initialized, aaruformat_context::wii_partition_region_count, aaruformat_context::wii_partition_regions, aaruformat_context::wiiu_cache_valid, aaruformat_context::wiiu_disc_key, aaruformat_context::wiiu_encrypted_block_cache, aaruformat_context::wiiu_encryption_initialized, aaruformat_context::wiiu_partition_region_count, and aaruformat_context::wiiu_partition_regions.

Referenced by aaruf_open().

◆ aaruf_set_close_error()

void aaruf_set_close_error ( const int error_code)
inlinestatic

Definition at line 49 of file close.c.

Referenced by aaruf_close().