Implement read_track_sector().

This commit is contained in:
2019-03-23 23:31:04 +00:00
parent 6ed23b6616
commit 3be40f84fe
4 changed files with 64 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
// The Disc Image Chef // The Disc Image Chef
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// //
// Filename : decsl.h // Filename : decls.h
// Author(s) : Natalia Portillo <claunia@claunia.com> // Author(s) : Natalia Portillo <claunia@claunia.com>
// //
// Component : libdicformat. // Component : libdicformat.
@@ -111,4 +111,6 @@ void ecc_cd_reconstruct(void *context, uint8_t *sector, uint8_t type);
uint32_t edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int size, int pos); uint32_t edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int size, int pos);
int32_t read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress, uint32_t *length, uint8_t track);
#endif //LIBDICFORMAT_DECLS_H #endif //LIBDICFORMAT_DECLS_H

View File

@@ -1,4 +1,3 @@
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#ifndef LIBDICFORMAT_ENUMS_H #ifndef LIBDICFORMAT_ENUMS_H
@@ -183,21 +182,21 @@ typedef enum
typedef enum typedef enum
{ {
/** Block containing data */ /** Block containing data */
DataBlock = 0x4B4C4244, DataBlock = 0x4B4C4244,
/** Block containing a deduplication table */ /** Block containing a deduplication table */
DeDuplicationTable = 0X2A544444, DeDuplicationTable = 0X2A544444,
/** Block containing the index */ /** Block containing the index */
IndexBlock = 0X58444E49, IndexBlock = 0X58444E49,
/** Block containing logical geometry */ /** Block containing logical geometry */
GeometryBlock = 0x4D4F4547, GeometryBlock = 0x4D4F4547,
/** Block containing metadata */ /** Block containing metadata */
MetadataBlock = 0x4154454D, MetadataBlock = 0x4154454D,
/** Block containing optical disc tracks */ /** Block containing optical disc tracks */
TracksBlock = 0x534B5254, TracksBlock = 0x534B5254,
/** Block containing CICM XML metadata */ /** Block containing CICM XML metadata */
CicmBlock = 0x4D434943, CicmBlock = 0x4D434943,
/** Block containing contents checksums */ /** Block containing contents checksums */
ChecksumBlock = 0x4D534B43, ChecksumBlock = 0x4D534B43,
/** TODO: Block containing data position measurements */ /** TODO: Block containing data position measurements */
DataPositionMeasurementBlock = 0x2A4D5044, DataPositionMeasurementBlock = 0x2A4D5044,
/** TODO: Block containing a snapshot index */ /** TODO: Block containing a snapshot index */
@@ -241,6 +240,27 @@ typedef enum
DICF_STATUS_INVALID_CONTEXT = -1, DICF_STATUS_INVALID_CONTEXT = -1,
} DicformatStatus; } DicformatStatus;
/**
* Enumeration of media types defined in CICM metadata
*/
typedef enum
{
/**
* Purely optical discs
*/
OpticalDisc = 0, /**
* Media that is physically block-based or abstracted like that
*/
BlockMedia = 1, /**
* Media that can be accessed by-byte or by-bit, like chips
*/
LinearMedia = 2, /**
* Media that can only store data when it is modulated to audio
*/
AudioMedia = 3
} XmlMediaType;
#endif //LIBDICFORMAT_ENUMS_H #endif //LIBDICFORMAT_ENUMS_H
#pragma clang diagnostic pop #pragma clang diagnostic pop

View File

@@ -16,6 +16,8 @@
#define DICF_ERROR_NOT_ENOUGH_MEMORY -9 #define DICF_ERROR_NOT_ENOUGH_MEMORY -9
#define DICF_ERROR_BUFFER_TOO_SMALL -10 #define DICF_ERROR_BUFFER_TOO_SMALL -10
#define DICF_ERROR_MEDIA_TAG_NOT_PRESENT -11 #define DICF_ERROR_MEDIA_TAG_NOT_PRESENT -11
#define DICF_ERROR_INCORRECT_MEDIA_TYPE -12
#define DICF_ERROR_TRACK_NOT_FOUND -13
#define DICF_STATUS_OK 0 #define DICF_STATUS_OK 0
#define DICF_STATUS_SECTOR_NEVER_WRITTEN 1 #define DICF_STATUS_SECTOR_NEVER_WRITTEN 1

View File

@@ -154,4 +154,33 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
*length = blockHeader.sectorSize; *length = blockHeader.sectorSize;
free(block); free(block);
return DICF_STATUS_OK; return DICF_STATUS_OK;
} }
int32_t read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress, uint32_t *length, uint8_t track)
{
dicformatContext *ctx;
int i;
if(context == NULL)
return DICF_ERROR_NOT_DICFORMAT;
ctx = context;
// TODO: Cast this field without casting the whole structure, as this can buffer overflow
// Not a libdicformat context
if(ctx->magic != DIC_MAGIC)
return DICF_ERROR_NOT_DICFORMAT;
if(ctx->imageInfo.XmlMediaType != OpticalDisc)
return DICF_ERROR_INCORRECT_MEDIA_TYPE;
for(i = 0; i < ctx->numberOfDataTracks; i++)
{
if(ctx->dataTracks[i].sequence == track)
{
return read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length);
}
}
return DICF_ERROR_TRACK_NOT_FOUND;
}