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
@@ -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

@@ -155,3 +155,32 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
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;
}