mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Reformat
This commit is contained in:
@@ -5,6 +5,7 @@ set(CMAKE_C_STANDARD 99)
|
||||
add_compile_definitions(__STDC_FORMAT_MACROS=1)
|
||||
|
||||
add_library(dicformat SHARED include/dicformat/consts.h include/dicformat/enums.h include/dic.h include/dicformat.h
|
||||
include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h src/close.c include/dicformat/errors.h src/read.c src/crc64.c src/cst.c src/ecc_cd.c src/helpers.c)
|
||||
include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h
|
||||
src/close.c include/dicformat/errors.h src/read.c src/crc64.c src/cst.c src/ecc_cd.c src/helpers.c)
|
||||
|
||||
include_directories(include include/dicformat)
|
||||
157
include/dic.h
157
include/dic.h
@@ -112,8 +112,8 @@ typedef enum
|
||||
PD650 = 32,
|
||||
/** 120mm, Write-Once, 1281856 sectors, 512 bytes/sector, PD650, ECMA-240, ISO 15485 */
|
||||
PD650_WORM = 33, /**
|
||||
* CD-i Ready, contains a track before the first TOC track, in mode 2, and all TOC tracks are Audio. Subchannel
|
||||
* marks track as audio pause.
|
||||
* CD-i Ready, contains a track before the first TOC track, in mode 2, and all TOC tracks are
|
||||
* Audio. Subchannel marks track as audio pause.
|
||||
*/
|
||||
CDIREADY = 34,
|
||||
FMTOWNS = 35,
|
||||
@@ -334,8 +334,8 @@ typedef enum
|
||||
* bytes/sector, falsified to DOS as 19 spt, 512 bps
|
||||
*/
|
||||
XDF_525 = 203, /**
|
||||
* 3.5", DS, HD, 80 tracks, 4 spt, 8192 + 2048 + 1024 + 512 bytes/sector, MFM track 0 = 19 sectors, 512
|
||||
* bytes/sector, falsified to DOS as 23 spt, 512 bps
|
||||
* 3.5", DS, HD, 80 tracks, 4 spt, 8192 + 2048 + 1024 + 512 bytes/sector, MFM track 0 = 19
|
||||
* sectors, 512 bytes/sector, falsified to DOS as 23 spt, 512 bps
|
||||
*/
|
||||
XDF_35 = 204,
|
||||
// IBM/Microsoft PC standard floppy formats, types 190 to 209
|
||||
@@ -353,16 +353,16 @@ typedef enum
|
||||
IBM43FD_128 = 214,
|
||||
/** 8", DS, SD, 74 tracks, 26 spt, 256 bytes/sector, FM, track 0 = 26 sectors, 128 bytes/sector */
|
||||
IBM43FD_256 = 215, /**
|
||||
* 8", DS, DD, 74 tracks, 26 spt, 256 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 74 tracks, 26 spt, 256 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
IBM53FD_256 = 216, /**
|
||||
* 8", DS, DD, 74 tracks, 15 spt, 512 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 74 tracks, 15 spt, 512 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
IBM53FD_512 = 217, /**
|
||||
* 8", DS, DD, 74 tracks, 8 spt, 1024 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 74 tracks, 8 spt, 1024 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
IBM53FD_1024 = 218,
|
||||
// IBM standard floppy formats, types 210 to 219
|
||||
@@ -460,12 +460,12 @@ typedef enum
|
||||
* 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_99_8 = 270, /**
|
||||
* 5,25", DS, DD, 77 tracks, 15 spt, 512 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128 bytes/sector, track
|
||||
* 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
* 5,25", DS, DD, 77 tracks, 15 spt, 512 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_99_15 = 271, /**
|
||||
* 5,25", DS, DD, 77 tracks, 26 spt, 256 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128 bytes/sector, track
|
||||
* 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
* 5,25", DS, DD, 77 tracks, 26 spt, 256 bytes/sector, MFM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_99_26 = 272,
|
||||
/** 3,5", DS, DD, 80 tracks, 9 spt, 512 bytes/sector, MFM */
|
||||
@@ -480,24 +480,24 @@ typedef enum
|
||||
ECMA_59 = 274,
|
||||
/** 5,25", SS, DD, 35 tracks, 9 spt, 256 bytes/sector, FM, track 0 side 0 = 16 sectors, 128 bytes/sector */
|
||||
ECMA_66 = 275, /**
|
||||
* 8", DS, DD, 77 tracks, 8 spt, 1024 bytes/sector, FM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 77 tracks, 8 spt, 1024 bytes/sector, FM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_69_8 = 276, /**
|
||||
* 8", DS, DD, 77 tracks, 15 spt, 512 bytes/sector, FM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 77 tracks, 15 spt, 512 bytes/sector, FM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_69_15 = 277, /**
|
||||
* 8", DS, DD, 77 tracks, 26 spt, 256 bytes/sector, FM, track 0 side 0 = 26 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 26 sectors, 256 bytes/sector
|
||||
* 8", DS, DD, 77 tracks, 26 spt, 256 bytes/sector, FM, track 0 side 0 = 26 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 26 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_69_26 = 278, /**
|
||||
* 5,25", DS, DD, 40 tracks, 16 spt, 256 bytes/sector, FM, track 0 side 0 = 16 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 16 sectors, 256 bytes/sector
|
||||
* 5,25", DS, DD, 40 tracks, 16 spt, 256 bytes/sector, FM, track 0 side 0 = 16 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 16 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_70 = 279, /**
|
||||
* 5,25", DS, DD, 80 tracks, 16 spt, 256 bytes/sector, FM, track 0 side 0 = 16 sectors, 128 bytes/sector, track 0
|
||||
* side 1 = 16 sectors, 256 bytes/sector
|
||||
* 5,25", DS, DD, 80 tracks, 16 spt, 256 bytes/sector, FM, track 0 side 0 = 16 sectors, 128
|
||||
* bytes/sector, track 0 side 1 = 16 sectors, 256 bytes/sector
|
||||
*/
|
||||
ECMA_78 = 280,
|
||||
/** 5,25", DS, DD, 80 tracks, 9 spt, 512 bytes/sector, FM */
|
||||
@@ -888,108 +888,108 @@ typedef enum
|
||||
* 204890112 bytes
|
||||
*/
|
||||
RA60 = 700, /**
|
||||
* 546 cylinders, 14 tracks/cylinder, 31 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 121325568 bytes
|
||||
* 546 cylinders, 14 tracks/cylinder, 31 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 121325568 bytes
|
||||
*/
|
||||
RA80 = 701, /**
|
||||
* 1248 cylinders, 14 tracks/cylinder, 51 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 456228864 bytes
|
||||
* 1248 cylinders, 14 tracks/cylinder, 51 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 456228864 bytes
|
||||
*/
|
||||
RA81 = 702, /**
|
||||
* 302 cylinders, 4 tracks/cylinder, 42 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 25976832
|
||||
* bytes
|
||||
* 302 cylinders, 4 tracks/cylinder, 42 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 25976832 bytes
|
||||
*/
|
||||
RC25 = 703, /**
|
||||
* 615 cylinders, 4 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 21411840
|
||||
* bytes
|
||||
* 615 cylinders, 4 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 21411840 bytes
|
||||
*/
|
||||
RD31 = 704, /**
|
||||
* 820 cylinders, 6 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 42823680
|
||||
* bytes
|
||||
* 820 cylinders, 6 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 42823680 bytes
|
||||
*/
|
||||
RD32 = 705, /**
|
||||
* 306 cylinders, 4 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 10653696
|
||||
* bytes
|
||||
* 306 cylinders, 4 tracks/cylinder, 17 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 10653696 bytes
|
||||
*/
|
||||
RD51 = 706, /**
|
||||
* 480 cylinders, 7 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 30965760
|
||||
* bytes
|
||||
* 480 cylinders, 7 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 30965760 bytes
|
||||
*/
|
||||
RD52 = 707, /**
|
||||
* 1024 cylinders, 7 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 75497472 bytes
|
||||
* 1024 cylinders, 7 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 75497472 bytes
|
||||
*/
|
||||
RD53 = 708, /**
|
||||
* 1225 cylinders, 8 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 159936000 bytes
|
||||
* 1225 cylinders, 8 tracks/cylinder, 18 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 159936000 bytes
|
||||
*/
|
||||
RD54 = 709, /**
|
||||
* 411 cylinders, 3 tracks/cylinder, 22 sectors/track, 256 words/sector, 16 bits/word, 512 bytes/sector, 13888512
|
||||
* bytes
|
||||
* 411 cylinders, 3 tracks/cylinder, 22 sectors/track, 256 words/sector, 16 bits/word, 512
|
||||
* bytes/sector, 13888512 bytes
|
||||
*/
|
||||
RK06 = 710, /**
|
||||
* 411 cylinders, 3 tracks/cylinder, 20 sectors/track, 256 words/sector, 18 bits/word, 576 bytes/sector, 14204160
|
||||
* bytes
|
||||
* 411 cylinders, 3 tracks/cylinder, 20 sectors/track, 256 words/sector, 18 bits/word, 576
|
||||
* bytes/sector, 14204160 bytes
|
||||
*/
|
||||
RK06_18 = 711, /**
|
||||
* 815 cylinders, 3 tracks/cylinder, 22 sectors/track, 256 words/sector, 16 bits/word, 512 bytes/sector, 27540480
|
||||
* bytes
|
||||
* 815 cylinders, 3 tracks/cylinder, 22 sectors/track, 256 words/sector, 16 bits/word, 512
|
||||
* bytes/sector, 27540480 bytes
|
||||
*/
|
||||
RK07 = 712, /**
|
||||
* 815 cylinders, 3 tracks/cylinder, 20 sectors/track, 256 words/sector, 18 bits/word, 576 bytes/sector, 28166400
|
||||
* bytes
|
||||
* 815 cylinders, 3 tracks/cylinder, 20 sectors/track, 256 words/sector, 18 bits/word, 576
|
||||
* bytes/sector, 28166400 bytes
|
||||
*/
|
||||
RK07_18 = 713, /**
|
||||
* 823 cylinders, 5 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 67420160
|
||||
* bytes
|
||||
* 823 cylinders, 5 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 67420160 bytes
|
||||
*/
|
||||
RM02 = 714, /**
|
||||
* 823 cylinders, 5 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector, 67420160
|
||||
* bytes
|
||||
* 823 cylinders, 5 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 67420160 bytes
|
||||
*/
|
||||
RM03 = 715, /**
|
||||
* 823 cylinders, 19 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 256196608 bytes
|
||||
* 823 cylinders, 19 tracks/cylinder, 32 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 256196608 bytes
|
||||
*/
|
||||
RM05 = 716, /**
|
||||
* 203 cylinders, 10 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 22865920 bytes
|
||||
* 203 cylinders, 10 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 22865920 bytes
|
||||
*/
|
||||
RP02 = 717, /**
|
||||
* 203 cylinders, 10 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576 bytes/sector,
|
||||
* 23385600 bytes
|
||||
* 203 cylinders, 10 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576
|
||||
* bytes/sector, 23385600 bytes
|
||||
*/
|
||||
RP02_18 = 718, /**
|
||||
* 400 cylinders, 10 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 45056000 bytes
|
||||
* 400 cylinders, 10 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 45056000 bytes
|
||||
*/
|
||||
RP03 = 719, /**
|
||||
* 400 cylinders, 10 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576 bytes/sector,
|
||||
* 46080000 bytes
|
||||
* 400 cylinders, 10 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576
|
||||
* bytes/sector, 46080000 bytes
|
||||
*/
|
||||
RP03_18 = 720, /**
|
||||
* 411 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 87960576 bytes
|
||||
* 411 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 87960576 bytes
|
||||
*/
|
||||
RP04 = 721, /**
|
||||
* 411 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576 bytes/sector,
|
||||
* 89959680 bytes
|
||||
* 411 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576
|
||||
* bytes/sector, 89959680 bytes
|
||||
*/
|
||||
RP04_18 = 722, /**
|
||||
* 411 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 87960576 bytes
|
||||
* 411 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 87960576 bytes
|
||||
*/
|
||||
RP05 = 723, /**
|
||||
* 411 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576 bytes/sector,
|
||||
* 89959680 bytes
|
||||
* 411 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576
|
||||
* bytes/sector, 89959680 bytes
|
||||
*/
|
||||
RP05_18 = 724, /**
|
||||
* 815 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512 bytes/sector,
|
||||
* 174423040 bytes
|
||||
* 815 cylinders, 19 tracks/cylinder, 22 sectors/track, 128 words/sector, 32 bits/word, 512
|
||||
* bytes/sector, 174423040 bytes
|
||||
*/
|
||||
RP06 = 725, /**
|
||||
* 815 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576 bytes/sector,
|
||||
* 178387200 bytes
|
||||
* 815 cylinders, 19 tracks/cylinder, 20 sectors/track, 128 words/sector, 36 bits/word, 576
|
||||
* bytes/sector, 178387200 bytes
|
||||
*/
|
||||
RP06_18 = 726,
|
||||
// DEC hard disks, types 700 to 729
|
||||
@@ -1167,8 +1167,8 @@ typedef enum
|
||||
MMC_OCR = 56, /* MultiMediaCard Extended CSD */
|
||||
MMC_ExtendedCSD = 57, /* Xbox Security Sector */
|
||||
Xbox_SecuritySector = 58, /*
|
||||
* On floppy disks, data in last cylinder usually in a different format that contains duplication or
|
||||
* manufacturing information
|
||||
* On floppy disks, data in last cylinder usually in a different format that contains
|
||||
* duplication or manufacturing information
|
||||
*/
|
||||
Floppy_LeadOut = 59, /* DVD Disc Control Blocks */
|
||||
DCB = 60, /* Compact Disc First Track Pregap */
|
||||
@@ -1182,7 +1182,6 @@ typedef enum
|
||||
CD_LeadIn = 68
|
||||
} MediaTagType;
|
||||
|
||||
|
||||
#endif // LIBDICFORMAT_DIC_H
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
@@ -36,11 +36,11 @@
|
||||
#define LIBDICFORMAT_MAJOR_VERSION 1
|
||||
#define LIBDICFORMAT_MINOR_VERSION 0
|
||||
|
||||
#include "dicformat/errors.h"
|
||||
#include "dicformat/consts.h"
|
||||
#include "dicformat/enums.h"
|
||||
#include "dicformat/decls.h"
|
||||
#include "dicformat/structs.h"
|
||||
#include "dicformat/context.h"
|
||||
#include "dicformat/decls.h"
|
||||
#include "dicformat/enums.h"
|
||||
#include "dicformat/errors.h"
|
||||
#include "dicformat/structs.h"
|
||||
|
||||
#endif // LIBDICFORMAT_DICFORMAT_H
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
/** Magic identidier = "DICMFMT". */
|
||||
#define DIC_MAGIC 0x544D52464D434944
|
||||
/** Image format version. A change in this number indicates an incompatible change to the format that prevents older implementations from reading it correctly, if at all. */
|
||||
/** Image format version. A change in this number indicates an incompatible change to the format that prevents older
|
||||
* implementations from reading it correctly, if at all. */
|
||||
#define DICF_VERSION 1
|
||||
/** Maximum read cache size, 256MiB. */
|
||||
#define MAX_CACHE_SIZE 256 * 1024 * 1024
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
#ifndef LIBDICFORMAT_CONTEXT_H
|
||||
#define LIBDICFORMAT_CONTEXT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct dicformatContext
|
||||
{
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
#ifndef LIBDICFORMAT_DECLS_H
|
||||
#define LIBDICFORMAT_DECLS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int identify(const char *filename);
|
||||
|
||||
|
||||
@@ -211,7 +211,11 @@ typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Invalid = 0, Md5 = 1, Sha1 = 2, Sha256 = 3, SpamSum = 4
|
||||
Invalid = 0,
|
||||
Md5 = 1,
|
||||
Sha1 = 2,
|
||||
Sha256 = 3,
|
||||
SpamSum = 4
|
||||
} ChecksumAlgorithm;
|
||||
|
||||
typedef enum
|
||||
|
||||
@@ -37,11 +37,12 @@
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <dic.h>
|
||||
#include "enums.h"
|
||||
|
||||
#include <dic.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**Header, at start of file */
|
||||
typedef struct DicHeader
|
||||
{
|
||||
|
||||
12
src/close.c
12
src/close.c
@@ -30,10 +30,10 @@
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dicformat.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int close(void *context)
|
||||
@@ -54,8 +54,7 @@ int close(void *context)
|
||||
}
|
||||
|
||||
// This may do nothing if imageStream is NULL, but as the behaviour is undefined, better sure than sorry
|
||||
if(ctx->imageStream != NULL)
|
||||
fclose(ctx->imageStream);
|
||||
if(ctx->imageStream != NULL) fclose(ctx->imageStream);
|
||||
|
||||
free(ctx->sectorPrefix);
|
||||
free(ctx->sectorPrefixCorrected);
|
||||
@@ -82,10 +81,7 @@ int close(void *context)
|
||||
free(ctx->mediaTagsHead);
|
||||
}
|
||||
|
||||
if(!ctx->inMemoryDdt)
|
||||
{
|
||||
munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize);
|
||||
}
|
||||
if(!ctx->inMemoryDdt) { munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize); }
|
||||
|
||||
free(ctx->sectorPrefixDdt);
|
||||
free(ctx->sectorSuffixDdt);
|
||||
|
||||
22
src/crc64.c
22
src/crc64.c
@@ -30,10 +30,10 @@
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <dicformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
void *crc64_init(uint64_t polynomial, uint64_t seed)
|
||||
{
|
||||
@@ -41,8 +41,7 @@ void *crc64_init(uint64_t polynomial, uint64_t seed)
|
||||
|
||||
ctx = malloc(sizeof(Crc64Context));
|
||||
|
||||
if(ctx == NULL)
|
||||
return NULL;
|
||||
if(ctx == NULL) return NULL;
|
||||
|
||||
memset(ctx, 1, sizeof(Crc64Context));
|
||||
|
||||
@@ -64,18 +63,13 @@ void *crc64_init(uint64_t polynomial, uint64_t seed)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void *crc64_init_ecma(void)
|
||||
{
|
||||
return crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED);
|
||||
}
|
||||
|
||||
void *crc64_init_ecma(void) { return crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED); }
|
||||
|
||||
void crc64_update(void *context, const uint8_t *data, size_t len)
|
||||
{
|
||||
Crc64Context *ctx = context;
|
||||
|
||||
for(size_t i = 0; i < len; i++)
|
||||
ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)];
|
||||
for(size_t i = 0; i < len; i++) ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)];
|
||||
}
|
||||
|
||||
uint64_t crc64_final(void *context)
|
||||
@@ -102,8 +96,7 @@ uint64_t crc64_data(const uint8_t *data, size_t len, uint64_t polynomial, uint64
|
||||
table[i] = entry;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < len; i++)
|
||||
hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)];
|
||||
for(size_t i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)];
|
||||
|
||||
return hashInt ^ seed;
|
||||
}
|
||||
@@ -112,4 +105,3 @@ uint64_t crc64_data_ecma(const uint8_t *data, size_t len)
|
||||
{
|
||||
return crc64_data(data, len, CRC64_ECMA_POLY, CRC64_ECMA_SEED);
|
||||
}
|
||||
|
||||
|
||||
10
src/cst.c
10
src/cst.c
@@ -30,9 +30,9 @@
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <dicformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int32_t cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
|
||||
@@ -46,8 +46,7 @@ int32_t cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t le
|
||||
size_t vStart;
|
||||
size_t wStart;
|
||||
|
||||
if(interleaved == NULL || sequential == NULL)
|
||||
return DICF_ERROR_BUFFER_TOO_SMALL;
|
||||
if(interleaved == NULL || sequential == NULL) return DICF_ERROR_BUFFER_TOO_SMALL;
|
||||
|
||||
p = malloc(length / 8);
|
||||
q = malloc(length / 8);
|
||||
@@ -180,8 +179,7 @@ int32_t cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t
|
||||
size_t vStart;
|
||||
size_t wStart;
|
||||
|
||||
if(interleaved == NULL || sequential == NULL)
|
||||
return DICF_ERROR_BUFFER_TOO_SMALL;
|
||||
if(interleaved == NULL || sequential == NULL) return DICF_ERROR_BUFFER_TOO_SMALL;
|
||||
|
||||
p = malloc(length / 8);
|
||||
q = malloc(length / 8);
|
||||
|
||||
115
src/ecc_cd.c
115
src/ecc_cd.c
@@ -31,11 +31,11 @@
|
||||
// ECC algorithm from ECM(c) 2002-2011 Neill Corlett
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <dicformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
void *ecc_cd_init()
|
||||
{
|
||||
@@ -44,8 +44,7 @@ void *ecc_cd_init()
|
||||
|
||||
context = (CdEccContext *)malloc(sizeof(CdEccContext));
|
||||
|
||||
if(context == NULL)
|
||||
return NULL;
|
||||
if(context == NULL) return NULL;
|
||||
|
||||
context->eccFTable = (uint8_t *)malloc(sizeof(uint8_t) * 256);
|
||||
|
||||
@@ -79,8 +78,7 @@ void *ecc_cd_init()
|
||||
j = (uint32_t)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
|
||||
context->eccFTable[i] = (uint8_t)j;
|
||||
context->eccBTable[i ^ j] = (uint8_t)i;
|
||||
for(j = 0; j < 8; j++)
|
||||
edc = (edc >> 1) ^ ((edc & 1) > 0 ? 0xD8018001 : 0);
|
||||
for(j = 0; j < 8; j++) edc = (edc >> 1) ^ ((edc & 1) > 0 ? 0xD8018001 : 0);
|
||||
context->edcTable[i] = edc;
|
||||
}
|
||||
|
||||
@@ -95,39 +93,29 @@ bool ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
|
||||
uint32_t storedEdc, edc, calculatedEdc;
|
||||
int size, pos;
|
||||
|
||||
if(context == NULL || sector == NULL)
|
||||
return false;
|
||||
if(context == NULL || sector == NULL) return false;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return false;
|
||||
if(!ctx->initedEdc) return false;
|
||||
|
||||
if(sector[0x814] != 0x00 ||
|
||||
// reserved (8 bytes)
|
||||
sector[0x815] != 0x00 ||
|
||||
sector[0x816] != 0x00 ||
|
||||
sector[0x817] != 0x00 ||
|
||||
sector[0x818] != 0x00 ||
|
||||
sector[0x819] != 0x00 ||
|
||||
sector[0x81A] != 0x00 ||
|
||||
sector[0x81B] != 0x00)
|
||||
sector[0x815] != 0x00 || sector[0x816] != 0x00 || sector[0x817] != 0x00 || sector[0x818] != 0x00 ||
|
||||
sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00)
|
||||
return false;
|
||||
|
||||
bool correctEccP = ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
|
||||
if(!correctEccP)
|
||||
return false;
|
||||
if(!correctEccP) return false;
|
||||
|
||||
bool correctEccQ = ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
|
||||
if(!correctEccQ)
|
||||
return false;
|
||||
if(!correctEccQ) return false;
|
||||
|
||||
storedEdc = sector[0x810]; // TODO: Check casting
|
||||
edc = 0;
|
||||
size = 0x810;
|
||||
pos = 0;
|
||||
for(; size > 0; size--)
|
||||
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
|
||||
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
|
||||
calculatedEdc = edc;
|
||||
|
||||
return calculatedEdc == storedEdc;
|
||||
@@ -140,32 +128,25 @@ bool ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
|
||||
int size, pos;
|
||||
uint8_t zeroaddress[4];
|
||||
|
||||
if(context == NULL || sector == NULL)
|
||||
return false;
|
||||
if(context == NULL || sector == NULL) return false;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return false;
|
||||
if(!ctx->initedEdc) return false;
|
||||
|
||||
memset(&zeroaddress, 4, sizeof(uint8_t));
|
||||
|
||||
bool correctEccP = ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C);
|
||||
if(!correctEccP)
|
||||
return false;
|
||||
if(!correctEccP) return false;
|
||||
|
||||
bool
|
||||
correctEccQ =
|
||||
ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
|
||||
if(!correctEccQ)
|
||||
return false;
|
||||
bool correctEccQ = ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
|
||||
if(!correctEccQ) return false;
|
||||
|
||||
storedEdc = sector[0x818]; // TODO: Check cast
|
||||
edc = 0;
|
||||
size = 0x808;
|
||||
pos = 0x10;
|
||||
for(; size > 0; size--)
|
||||
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
|
||||
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
|
||||
calculatedEdc = edc;
|
||||
|
||||
return calculatedEdc == storedEdc;
|
||||
@@ -187,13 +168,11 @@ bool ecc_cd_check(void *context,
|
||||
uint32_t size, major, idx, minor;
|
||||
uint8_t eccA, eccB, temp;
|
||||
|
||||
if(context == NULL || address == NULL || data == NULL || ecc == NULL)
|
||||
return false;
|
||||
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return false;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return false;
|
||||
if(!ctx->initedEdc) return false;
|
||||
|
||||
size = majorCount * minorCount;
|
||||
for(major = 0; major < majorCount; major++)
|
||||
@@ -205,16 +184,14 @@ bool ecc_cd_check(void *context,
|
||||
{
|
||||
temp = idx < 4 ? address[idx + addressOffset] : data[idx + dataOffset - 4];
|
||||
idx += minorInc;
|
||||
if(idx >= size)
|
||||
idx -= size;
|
||||
if(idx >= size) idx -= size;
|
||||
eccA ^= temp;
|
||||
eccB ^= temp;
|
||||
eccA = ctx->eccFTable[eccA];
|
||||
}
|
||||
|
||||
eccA = ctx->eccBTable[ctx->eccFTable[eccA] ^ eccB];
|
||||
if(ecc[major + eccOffset] != eccA || ecc[major + majorCount + eccOffset] != (eccA ^ eccB))
|
||||
return false;
|
||||
if(ecc[major + eccOffset] != eccA || ecc[major + majorCount + eccOffset] != (eccA ^ eccB)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -236,13 +213,11 @@ void ecc_cd_write(void *context,
|
||||
uint32_t size, major, idx, minor;
|
||||
uint8_t eccA, eccB, temp;
|
||||
|
||||
if(context == NULL || address == NULL || data == NULL || ecc == NULL)
|
||||
return;
|
||||
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return;
|
||||
if(!ctx->initedEdc) return;
|
||||
|
||||
size = majorCount * minorCount;
|
||||
for(major = 0; major < majorCount; major++)
|
||||
@@ -255,8 +230,7 @@ void ecc_cd_write(void *context,
|
||||
{
|
||||
temp = idx < 4 ? address[idx + addressOffset] : data[idx + dataOffset - 4];
|
||||
idx += minorInc;
|
||||
if(idx >= size)
|
||||
idx -= size;
|
||||
if(idx >= size) idx -= size;
|
||||
eccA ^= temp;
|
||||
eccB ^= temp;
|
||||
eccA = ctx->eccFTable[eccA];
|
||||
@@ -287,14 +261,13 @@ void cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame
|
||||
*frame = (uint8_t)((pos + 150) % 75);
|
||||
}
|
||||
|
||||
|
||||
void ecc_cd_reconstruct_prefix(uint8_t *sector, // must point to a full 2352-byte sector
|
||||
uint8_t type, int64_t lba)
|
||||
uint8_t type,
|
||||
int64_t lba)
|
||||
{
|
||||
uint8_t minute, second, frame;
|
||||
|
||||
if(sector == NULL)
|
||||
return;
|
||||
if(sector == NULL) return;
|
||||
|
||||
//
|
||||
// Sync
|
||||
@@ -345,7 +318,8 @@ void ecc_cd_reconstruct_prefix(uint8_t *sector, // must point to a full 2352-byt
|
||||
}
|
||||
}
|
||||
|
||||
void ecc_cd_reconstruct(void *context, uint8_t *sector, // must point to a full 2352-byte sector
|
||||
void ecc_cd_reconstruct(void * context,
|
||||
uint8_t *sector, // must point to a full 2352-byte sector
|
||||
uint8_t type)
|
||||
{
|
||||
uint32_t computedEdc;
|
||||
@@ -353,26 +327,27 @@ void ecc_cd_reconstruct(void *context, uint8_t *sector, // must point to a full
|
||||
|
||||
CdEccContext *ctx;
|
||||
|
||||
if(context == NULL || sector == NULL)
|
||||
return;
|
||||
if(context == NULL || sector == NULL) return;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return;
|
||||
if(!ctx->initedEdc) return;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
//
|
||||
// Compute EDC
|
||||
//
|
||||
case CdMode1:computedEdc = edc_cd_compute(context, 0, sector, 0x810, 0);
|
||||
case CdMode1:
|
||||
computedEdc = edc_cd_compute(context, 0, sector, 0x810, 0);
|
||||
memcpy(sector + 0x810, &computedEdc, 4);
|
||||
break;
|
||||
case CdMode2Form1:computedEdc = edc_cd_compute(context, 0, sector, 0x808, 0x10);
|
||||
case CdMode2Form1:
|
||||
computedEdc = edc_cd_compute(context, 0, sector, 0x808, 0x10);
|
||||
memcpy(sector + 0x818, &computedEdc, 4);
|
||||
break;
|
||||
case CdMode2Form2:computedEdc = edc_cd_compute(context, 0, sector, 0x91C, 0x10);
|
||||
case CdMode2Form2:
|
||||
computedEdc = edc_cd_compute(context, 0, sector, 0x91C, 0x10);
|
||||
memcpy(sector + 0x92C, &computedEdc, 4);
|
||||
break;
|
||||
default: return;
|
||||
@@ -399,8 +374,7 @@ void ecc_cd_reconstruct(void *context, uint8_t *sector, // must point to a full
|
||||
sector[0x81B] = 0x00;
|
||||
ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C);
|
||||
break;
|
||||
case CdMode2Form1:ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C);
|
||||
break;
|
||||
case CdMode2Form1: ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
@@ -413,16 +387,13 @@ uint32_t edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int siz
|
||||
{
|
||||
CdEccContext *ctx;
|
||||
|
||||
if(context == NULL || src == NULL)
|
||||
return 0;
|
||||
if(context == NULL || src == NULL) return 0;
|
||||
|
||||
ctx = (CdEccContext *)context;
|
||||
|
||||
if(!ctx->initedEdc)
|
||||
return 0;
|
||||
if(!ctx->initedEdc) return 0;
|
||||
|
||||
for(; size > 0; size--)
|
||||
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ src[pos++]) & 0xFF];
|
||||
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ src[pos++]) & 0xFF];
|
||||
|
||||
return edc;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <dicformat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <dicformat.h>
|
||||
|
||||
//! Identifies a file as dicformat, using path
|
||||
/*!
|
||||
@@ -47,8 +47,7 @@ int identify(const char *filename)
|
||||
|
||||
stream = fopen(filename, "rb");
|
||||
|
||||
if(stream == NULL)
|
||||
return errno;
|
||||
if(stream == NULL) return errno;
|
||||
|
||||
int ret = identifyStream(stream);
|
||||
|
||||
@@ -72,11 +71,9 @@ int identifyStream(FILE *imageStream)
|
||||
|
||||
size_t ret = fread(&header, sizeof(DicHeader), 1, imageStream);
|
||||
|
||||
if(ret < sizeof(DicHeader))
|
||||
return 0;
|
||||
if(ret < sizeof(DicHeader)) return 0;
|
||||
|
||||
if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= DICF_VERSION)
|
||||
return 100;
|
||||
if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= DICF_VERSION) return 100;
|
||||
|
||||
return 0;
|
||||
}
|
||||
183
src/open.c
183
src/open.c
@@ -30,11 +30,11 @@
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dicformat.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -54,8 +54,7 @@ void *open(const char *filepath)
|
||||
ctx = (dicformatContext *)malloc(sizeof(dicformatContext));
|
||||
memset(ctx, 0, sizeof(dicformatContext));
|
||||
|
||||
if(ctx == NULL)
|
||||
return NULL;
|
||||
if(ctx == NULL) return NULL;
|
||||
|
||||
ctx->imageStream = fopen(filepath, "rb");
|
||||
|
||||
@@ -159,7 +158,8 @@ void *open(const char *filepath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fprintf(stderr, "libdicformat: Index at %"PRIu64" contains %d entries", ctx->header.indexOffset, idxHeader.entries);
|
||||
fprintf(
|
||||
stderr, "libdicformat: Index at %" PRIu64 " contains %d entries", ctx->header.indexOffset, idxHeader.entries);
|
||||
|
||||
idxEntries = (IndexEntry *)malloc(sizeof(IndexEntry) * idxHeader.entries);
|
||||
|
||||
@@ -186,7 +186,8 @@ void *open(const char *filepath)
|
||||
|
||||
for(int i = 0; i < idxHeader.entries; i++)
|
||||
{
|
||||
fprintf(stderr, "libdicformat: Block type %4.4s with data type %4.4s is indexed to be at %"PRIu64"",
|
||||
fprintf(stderr,
|
||||
"libdicformat: Block type %4.4s with data type %4.4s is indexed to be at %" PRIu64 "",
|
||||
(char *)&idxEntries[i].blockType,
|
||||
(char *)&idxEntries[i].dataType,
|
||||
idxEntries[i].offset);
|
||||
@@ -215,8 +216,7 @@ void *open(const char *filepath)
|
||||
{
|
||||
case DataBlock:
|
||||
// NOP block, skip
|
||||
if(idxEntries[i].dataType == NoData)
|
||||
break;
|
||||
if(idxEntries[i].dataType == NoData) break;
|
||||
|
||||
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
|
||||
|
||||
@@ -249,14 +249,16 @@ void *open(const char *filepath)
|
||||
if(blockHeader.type != idxEntries[i].dataType)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"libdicformat: Expected block with data type %4.4s at position %"PRIu64" but found data type %4.4s",
|
||||
"libdicformat: Expected block with data type %4.4s at position %" PRIu64
|
||||
" but found data type %4.4s",
|
||||
(char *)&idxEntries[i].blockType,
|
||||
idxEntries[i].offset,
|
||||
(char *)&blockHeader.type);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "libdicformat: Found data block with type %4.4s at position %"PRIu64"",
|
||||
fprintf(stderr,
|
||||
"libdicformat: Found data block with type %4.4s at position %" PRIu64 "",
|
||||
(char *)&idxEntries[i].blockType,
|
||||
idxEntries[i].offset);
|
||||
|
||||
@@ -290,7 +292,8 @@ void *open(const char *filepath)
|
||||
if(crc64 != blockHeader.crc64)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
|
||||
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
|
||||
", continuing...",
|
||||
crc64,
|
||||
blockHeader.crc64);
|
||||
break;
|
||||
@@ -303,10 +306,7 @@ void *open(const char *filepath)
|
||||
{
|
||||
case CdSectorPrefix:
|
||||
case CdSectorPrefixCorrected:
|
||||
if(idxEntries[i].dataType == CdSectorPrefixCorrected)
|
||||
{
|
||||
ctx->sectorPrefixCorrected = data;
|
||||
}
|
||||
if(idxEntries[i].dataType == CdSectorPrefixCorrected) { ctx->sectorPrefixCorrected = data; }
|
||||
else
|
||||
ctx->sectorPrefix = data;
|
||||
|
||||
@@ -327,16 +327,17 @@ void *open(const char *filepath)
|
||||
ctx->readableSectorTags[CdSectorEccQ] = true;
|
||||
ctx->readableSectorTags[CdSectorEdc] = true;
|
||||
break;
|
||||
case CdSectorSubchannel:ctx->sectorSubchannel = data;
|
||||
case CdSectorSubchannel:
|
||||
ctx->sectorSubchannel = data;
|
||||
ctx->readableSectorTags[CdSectorSubchannel] = true;
|
||||
break;
|
||||
case AppleProfileTag:
|
||||
case AppleSonyTag:
|
||||
case PriamDataTowerTag:ctx->sectorSubchannel = data;
|
||||
case PriamDataTowerTag:
|
||||
ctx->sectorSubchannel = data;
|
||||
ctx->readableSectorTags[AppleSectorTag] = true;
|
||||
break;
|
||||
case CompactDiscMode2Subheader:ctx->mode2Subheaders = data;
|
||||
break;
|
||||
case CompactDiscMode2Subheader: ctx->mode2Subheaders = data; break;
|
||||
default:
|
||||
if(ctx->mediaTagsHead != NULL)
|
||||
{
|
||||
@@ -359,8 +360,7 @@ void *open(const char *filepath)
|
||||
|
||||
// If we mediaTag is NULL means we have arrived the end of the list without finding a duplicate
|
||||
// or the list was empty
|
||||
if(mediaTag != NULL)
|
||||
break;
|
||||
if(mediaTag != NULL) break;
|
||||
|
||||
mediaTag = (dataLinkedList *)malloc(sizeof(dataLinkedList));
|
||||
|
||||
@@ -375,10 +375,7 @@ void *open(const char *filepath)
|
||||
mediaTag->data = data;
|
||||
mediaTag->length = blockHeader.length;
|
||||
|
||||
if(ctx->mediaTagsHead == NULL)
|
||||
{
|
||||
ctx->mediaTagsHead = mediaTag;
|
||||
}
|
||||
if(ctx->mediaTagsHead == NULL) { ctx->mediaTagsHead = mediaTag; }
|
||||
else
|
||||
{
|
||||
mediaTag->previous = ctx->mediaTagsTail;
|
||||
@@ -391,7 +388,8 @@ void *open(const char *filepath)
|
||||
}
|
||||
|
||||
break;
|
||||
case DeDuplicationTable:readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
|
||||
case DeDuplicationTable:
|
||||
readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DdtHeader))
|
||||
{
|
||||
@@ -412,9 +410,9 @@ void *open(const char *filepath)
|
||||
// Check for DDT compression
|
||||
switch(ddtHeader.compression)
|
||||
{
|
||||
case None:ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
|
||||
ctx->userDataDdt =
|
||||
mmap(NULL,
|
||||
case None:
|
||||
ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
|
||||
ctx->userDataDdt = mmap(NULL,
|
||||
ctx->mappedMemoryDdtSize,
|
||||
PROT_READ,
|
||||
MAP_SHARED,
|
||||
@@ -436,7 +434,6 @@ void *open(const char *filepath)
|
||||
blockHeader.compression);
|
||||
foundUserDataDdt = false;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if(idxEntries[i].dataType == CdSectorPrefixCorrected ||
|
||||
@@ -444,7 +441,8 @@ void *open(const char *filepath)
|
||||
{
|
||||
switch(ddtHeader.compression)
|
||||
{
|
||||
case None:cdDdt = (uint32_t *)malloc(ddtHeader.entries * sizeof(uint32_t));
|
||||
case None:
|
||||
cdDdt = (uint32_t *)malloc(ddtHeader.entries * sizeof(uint32_t));
|
||||
|
||||
if(mediaTag == NULL)
|
||||
{
|
||||
@@ -478,7 +476,8 @@ void *open(const char *filepath)
|
||||
}
|
||||
break;
|
||||
// Logical geometry block. It doesn't have a CRC coz, well, it's not so important
|
||||
case GeometryBlock:readBytes = fread(&ctx->geometryBlock, sizeof(GeometryBlockHeader), 1, ctx->imageStream);
|
||||
case GeometryBlock:
|
||||
readBytes = fread(&ctx->geometryBlock, sizeof(GeometryBlockHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(GeometryBlockHeader))
|
||||
{
|
||||
@@ -504,11 +503,8 @@ void *open(const char *filepath)
|
||||
|
||||
break;
|
||||
// Metadata block
|
||||
case MetadataBlock: readBytes =
|
||||
fread(&ctx->metadataBlockHeader,
|
||||
sizeof(MetadataBlockHeader),
|
||||
1,
|
||||
ctx->imageStream);
|
||||
case MetadataBlock:
|
||||
readBytes = fread(&ctx->metadataBlockHeader, sizeof(MetadataBlockHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(MetadataBlockHeader))
|
||||
{
|
||||
@@ -597,7 +593,8 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->metadataBlockHeader.mediaManufacturerLength > 0 &&
|
||||
ctx->metadataBlockHeader.mediaManufacturerOffset +
|
||||
ctx->metadataBlockHeader.mediaManufacturerLength <= ctx->metadataBlockHeader.blockSize)
|
||||
ctx->metadataBlockHeader.mediaManufacturerLength <=
|
||||
ctx->metadataBlockHeader.blockSize)
|
||||
{
|
||||
ctx->imageInfo.MediaManufacturer =
|
||||
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaManufacturerLength);
|
||||
@@ -624,7 +621,8 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->metadataBlockHeader.mediaSerialNumberLength > 0 &&
|
||||
ctx->metadataBlockHeader.mediaSerialNumberOffset +
|
||||
ctx->metadataBlockHeader.mediaSerialNumberLength <= ctx->metadataBlockHeader.blockSize)
|
||||
ctx->metadataBlockHeader.mediaSerialNumberLength <=
|
||||
ctx->metadataBlockHeader.blockSize)
|
||||
{
|
||||
ctx->imageInfo.MediaSerialNumber =
|
||||
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaSerialNumberLength);
|
||||
@@ -664,7 +662,8 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->metadataBlockHeader.driveManufacturerLength > 0 &&
|
||||
ctx->metadataBlockHeader.driveManufacturerOffset +
|
||||
ctx->metadataBlockHeader.driveManufacturerLength <= ctx->metadataBlockHeader.blockSize)
|
||||
ctx->metadataBlockHeader.driveManufacturerLength <=
|
||||
ctx->metadataBlockHeader.blockSize)
|
||||
{
|
||||
ctx->imageInfo.DriveManufacturer =
|
||||
(uint8_t *)malloc(ctx->metadataBlockHeader.driveManufacturerLength);
|
||||
@@ -691,7 +690,8 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->metadataBlockHeader.driveSerialNumberLength > 0 &&
|
||||
ctx->metadataBlockHeader.driveSerialNumberOffset +
|
||||
ctx->metadataBlockHeader.driveSerialNumberLength <= ctx->metadataBlockHeader.blockSize)
|
||||
ctx->metadataBlockHeader.driveSerialNumberLength <=
|
||||
ctx->metadataBlockHeader.blockSize)
|
||||
{
|
||||
ctx->imageInfo.DriveSerialNumber =
|
||||
(uint8_t *)malloc(ctx->metadataBlockHeader.driveSerialNumberLength);
|
||||
@@ -705,7 +705,8 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->metadataBlockHeader.driveManufacturerLength > 0 &&
|
||||
ctx->metadataBlockHeader.driveFirmwareRevisionOffset +
|
||||
ctx->metadataBlockHeader.driveManufacturerLength <= ctx->metadataBlockHeader.blockSize)
|
||||
ctx->metadataBlockHeader.driveManufacturerLength <=
|
||||
ctx->metadataBlockHeader.blockSize)
|
||||
{
|
||||
ctx->imageInfo.DriveFirmwareRevision =
|
||||
(uint8_t *)malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength);
|
||||
@@ -718,7 +719,8 @@ void *open(const char *filepath)
|
||||
}
|
||||
|
||||
break;
|
||||
case TracksBlock: readBytes = fread(&ctx->tracksHeader, sizeof(TracksHeader), 1, ctx->imageStream);
|
||||
case TracksBlock:
|
||||
readBytes = fread(&ctx->tracksHeader, sizeof(TracksHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(TracksHeader))
|
||||
{
|
||||
@@ -756,12 +758,12 @@ void *open(const char *filepath)
|
||||
}
|
||||
|
||||
crc64 =
|
||||
crc64_data_ecma((const uint8_t *)ctx->trackEntries,
|
||||
ctx->tracksHeader.entries * sizeof(TrackEntry));
|
||||
crc64_data_ecma((const uint8_t *)ctx->trackEntries, ctx->tracksHeader.entries * sizeof(TrackEntry));
|
||||
if(crc64 != ctx->tracksHeader.crc64)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
|
||||
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
|
||||
", continuing...",
|
||||
crc64,
|
||||
ctx->tracksHeader.crc64);
|
||||
break;
|
||||
@@ -788,25 +790,23 @@ void *open(const char *filepath)
|
||||
{
|
||||
ctx->dataTracks = (TrackEntry *)malloc(sizeof(TrackEntry) * temp8u);
|
||||
|
||||
if(ctx->dataTracks == NULL)
|
||||
break;
|
||||
if(ctx->dataTracks == NULL) break;
|
||||
|
||||
ctx->numberOfDataTracks = temp8u;
|
||||
|
||||
for(i = 0, temp8u = 0; i < ctx->tracksHeader.entries; i++)
|
||||
{
|
||||
if(ctx->trackEntries[i].sequence > 99)
|
||||
continue;
|
||||
if(ctx->trackEntries[i].sequence > 99) continue;
|
||||
|
||||
memcpy(&ctx->dataTracks[ctx->trackEntries[i].sequence],
|
||||
&ctx->trackEntries[i],
|
||||
sizeof(TrackEntry));
|
||||
memcpy(
|
||||
&ctx->dataTracks[ctx->trackEntries[i].sequence], &ctx->trackEntries[i], sizeof(TrackEntry));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
// CICM XML metadata block
|
||||
case CicmBlock:readBytes = fread(&ctx->cicmBlockHeader, sizeof(CicmMetadataBlock), 1, ctx->imageStream);
|
||||
case CicmBlock:
|
||||
readBytes = fread(&ctx->cicmBlockHeader, sizeof(CicmMetadataBlock), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(CicmMetadataBlock))
|
||||
{
|
||||
@@ -847,11 +847,8 @@ void *open(const char *filepath)
|
||||
fprintf(stderr, "libdicformat: Found CICM XML metadata block %" PRIu64 ".", idxEntries[i].offset);
|
||||
break;
|
||||
// Dump hardware block
|
||||
case DumpHardwareBlock: readBytes =
|
||||
fread(&ctx->dumpHardwareHeader,
|
||||
sizeof(DumpHardwareHeader),
|
||||
1,
|
||||
ctx->imageStream);
|
||||
case DumpHardwareBlock:
|
||||
readBytes = fread(&ctx->dumpHardwareHeader, sizeof(DumpHardwareHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareHeader))
|
||||
{
|
||||
@@ -880,7 +877,8 @@ void *open(const char *filepath)
|
||||
{
|
||||
free(data);
|
||||
fprintf(stderr,
|
||||
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
|
||||
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
|
||||
", continuing...",
|
||||
crc64,
|
||||
ctx->dumpHardwareHeader.crc64);
|
||||
break;
|
||||
@@ -891,9 +889,8 @@ void *open(const char *filepath)
|
||||
fseek(ctx->imageStream, -readBytes, SEEK_CUR);
|
||||
}
|
||||
|
||||
ctx->dumpHardwareEntriesWithData =
|
||||
(DumpHardwareEntriesWithData *)malloc(sizeof(DumpHardwareEntriesWithData) *
|
||||
ctx->dumpHardwareHeader.entries);
|
||||
ctx->dumpHardwareEntriesWithData = (DumpHardwareEntriesWithData *)malloc(
|
||||
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData == NULL)
|
||||
{
|
||||
@@ -908,11 +905,8 @@ void *open(const char *filepath)
|
||||
|
||||
for(uint16_t e = 0; e < ctx->dumpHardwareHeader.entries; e++)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].entry,
|
||||
sizeof(DumpHardwareEntry),
|
||||
1,
|
||||
ctx->imageStream);
|
||||
readBytes = fread(
|
||||
&ctx->dumpHardwareEntriesWithData[e].entry, sizeof(DumpHardwareEntry), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareEntry))
|
||||
{
|
||||
@@ -928,8 +922,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].manufacturer,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].manufacturer,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -939,7 +932,8 @@ void *open(const char *filepath)
|
||||
free(ctx->dumpHardwareEntriesWithData[e].manufacturer);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0;
|
||||
fprintf(stderr,
|
||||
"libdicformat: Could not read dump hardware block entry manufacturer, continuing...");
|
||||
"libdicformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -951,8 +945,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].model != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].model,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].model,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.modelLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -974,8 +967,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].revision != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].revision,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].revision,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -984,7 +976,8 @@ void *open(const char *filepath)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].revision);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0;
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"libdicformat: Could not read dump hardware block entry revision, continuing...");
|
||||
}
|
||||
}
|
||||
@@ -997,8 +990,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].firmware,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].firmware,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -1007,7 +999,8 @@ void *open(const char *filepath)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].firmware);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0;
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"libdicformat: Could not read dump hardware block entry firmware, continuing...");
|
||||
}
|
||||
}
|
||||
@@ -1020,8 +1013,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].serial != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].serial,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].serial,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.serialLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -1043,8 +1035,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].softwareName,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareName,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -1054,7 +1045,8 @@ void *open(const char *filepath)
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareName);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength = 0;
|
||||
fprintf(stderr,
|
||||
"libdicformat: Could not read dump hardware block entry software name, continuing...");
|
||||
"libdicformat: Could not read dump hardware block entry software name, "
|
||||
"continuing...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1066,8 +1058,7 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].softwareVersion,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareVersion,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -1077,7 +1068,8 @@ void *open(const char *filepath)
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareVersion);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength = 0;
|
||||
fprintf(stderr,
|
||||
"libdicformat: Could not read dump hardware block entry software version, continuing...");
|
||||
"libdicformat: Could not read dump hardware block entry software version, "
|
||||
"continuing...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1085,13 +1077,11 @@ void *open(const char *filepath)
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry
|
||||
.softwareOperatingSystemLength);
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL)
|
||||
{
|
||||
readBytes =
|
||||
fread(&ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem,
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength,
|
||||
1,
|
||||
ctx->imageStream);
|
||||
@@ -1101,7 +1091,8 @@ void *open(const char *filepath)
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0;
|
||||
fprintf(stderr,
|
||||
"libdicformat: Could not read dump hardware block entry manufacturer, continuing...");
|
||||
"libdicformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1111,13 +1102,13 @@ void *open(const char *filepath)
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].extents == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"libdicformat: Could not allocate memory for dump hardware block extents, continuing...");
|
||||
continue;
|
||||
}
|
||||
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].extents,
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents,
|
||||
sizeof(DumpExtent),
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.extents,
|
||||
ctx->imageStream);
|
||||
@@ -1156,7 +1147,7 @@ void *open(const char *filepath)
|
||||
ctx->imageInfo.LastModificationTime = ctx->header.lastWrittenTime;
|
||||
ctx->imageInfo.XmlMediaType = GetXmlMediaType(ctx->header.mediaType);
|
||||
|
||||
if(ctx->geometryBlock.identifier != GeometryBlock/* && ctx->imageInfo.XmlMediaType == XmlMediaType.BlockMedia*/)
|
||||
if(ctx->geometryBlock.identifier != GeometryBlock && ctx->imageInfo.XmlMediaType == BlockMedia)
|
||||
{
|
||||
ctx->imageInfo.Cylinders = (uint32_t)(ctx->imageInfo.Sectors / 16 / 63);
|
||||
ctx->imageInfo.Heads = 16;
|
||||
|
||||
78
src/read.c
78
src/read.c
@@ -39,14 +39,12 @@ int32_t read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *leng
|
||||
dicformatContext *ctx;
|
||||
dataLinkedList * item;
|
||||
|
||||
if(context == NULL)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
ctx = context;
|
||||
|
||||
// Not a libdicformat context
|
||||
if(ctx->magic != DIC_MAGIC)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
item = ctx->mediaTagsHead;
|
||||
|
||||
@@ -82,17 +80,14 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
|
||||
uint8_t * block;
|
||||
size_t readBytes;
|
||||
|
||||
if(context == NULL)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
ctx = context;
|
||||
|
||||
// Not a libdicformat context
|
||||
if(ctx->magic != DIC_MAGIC)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
if(sectorAddress > ctx->imageInfo.Sectors - 1)
|
||||
return DICF_ERROR_SECTOR_OUT_OF_BOUNDS;
|
||||
if(sectorAddress > ctx->imageInfo.Sectors - 1) return DICF_ERROR_SECTOR_OUT_OF_BOUNDS;
|
||||
|
||||
ddtEntry = ctx->userDataDdt[sectorAddress];
|
||||
offsetMask = (uint32_t)((1 << ctx->shift) - 1);
|
||||
@@ -114,8 +109,7 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
|
||||
fseek(ctx->imageStream, blockOffset, SEEK_SET);
|
||||
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(BlockHeader))
|
||||
return DICF_ERROR_CANNOT_READ_HEADER;
|
||||
if(readBytes != sizeof(BlockHeader)) return DICF_ERROR_CANNOT_READ_HEADER;
|
||||
|
||||
if(data == NULL || *length < blockHeader.sectorSize)
|
||||
{
|
||||
@@ -126,9 +120,9 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
|
||||
// Decompress block
|
||||
switch(blockHeader.compression)
|
||||
{
|
||||
case None:block = (uint8_t *)malloc(blockHeader.length);
|
||||
if(block == NULL)
|
||||
return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
case None:
|
||||
block = (uint8_t *)malloc(blockHeader.length);
|
||||
if(block == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
||||
readBytes = fread(block, blockHeader.length, 1, ctx->imageStream);
|
||||
|
||||
@@ -159,24 +153,19 @@ int32_t read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress,
|
||||
dicformatContext *ctx;
|
||||
int i;
|
||||
|
||||
if(context == NULL)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
ctx = context;
|
||||
|
||||
// Not a libdicformat context
|
||||
if(ctx->magic != DIC_MAGIC)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
if(ctx->imageInfo.XmlMediaType != OpticalDisc)
|
||||
return DICF_ERROR_INCORRECT_MEDIA_TYPE;
|
||||
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 read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length); }
|
||||
}
|
||||
|
||||
return DICF_ERROR_TRACK_NOT_FOUND;
|
||||
@@ -193,14 +182,12 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
int i;
|
||||
bool trkFound;
|
||||
|
||||
if(context == NULL)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
ctx = context;
|
||||
|
||||
// Not a libdicformat context
|
||||
if(ctx->magic != DIC_MAGIC)
|
||||
return DICF_ERROR_NOT_DICFORMAT;
|
||||
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
|
||||
|
||||
switch(ctx->imageInfo.XmlMediaType)
|
||||
{
|
||||
@@ -219,13 +206,11 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
|
||||
bareData = (uint8_t *)malloc(bareLength);
|
||||
|
||||
if(bareData == NULL)
|
||||
return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
if(bareData == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
||||
res = read_sector(context, sectorAddress, bareData, &bareLength);
|
||||
|
||||
if(res < DICF_STATUS_OK)
|
||||
return res;
|
||||
if(res < DICF_STATUS_OK) return res;
|
||||
|
||||
trkFound = false;
|
||||
|
||||
@@ -239,15 +224,14 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
}
|
||||
}
|
||||
|
||||
if(!trkFound)
|
||||
return DICF_ERROR_TRACK_NOT_FOUND;
|
||||
if(!trkFound) return DICF_ERROR_TRACK_NOT_FOUND;
|
||||
|
||||
switch(trk.type)
|
||||
{
|
||||
case Audio:
|
||||
case Data:memcpy(bareData, data, bareLength);
|
||||
return res;
|
||||
case CdMode1:memcpy(bareData, data + 16, 2048);
|
||||
case Data: memcpy(bareData, data, bareLength); return res;
|
||||
case CdMode1:
|
||||
memcpy(bareData, data + 16, 2048);
|
||||
|
||||
if(ctx->sectorPrefix != NULL)
|
||||
memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
|
||||
@@ -279,7 +263,6 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
{
|
||||
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
|
||||
{
|
||||
|
||||
ecc_cd_reconstruct(ctx->eccCdContext, data, trk.type);
|
||||
res = DICF_STATUS_OK;
|
||||
}
|
||||
@@ -363,20 +346,16 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
case AppleSonyDS:
|
||||
case AppleWidget:
|
||||
case PriamDataTower:
|
||||
if(ctx->sectorSubchannel == NULL)
|
||||
return read_sector(context, sectorAddress, data, length);
|
||||
if(ctx->sectorSubchannel == NULL) return read_sector(context, sectorAddress, data, length);
|
||||
|
||||
switch(ctx->imageInfo.MediaType)
|
||||
{
|
||||
case AppleFileWare:
|
||||
case AppleProfile:
|
||||
case AppleWidget:tagLength = 20;
|
||||
break;
|
||||
case AppleWidget: tagLength = 20; break;
|
||||
case AppleSonySS:
|
||||
case AppleSonyDS:tagLength = 12;
|
||||
break;
|
||||
case PriamDataTower:tagLength = 24;
|
||||
break;
|
||||
case AppleSonyDS: tagLength = 12; break;
|
||||
case PriamDataTower: tagLength = 24; break;
|
||||
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
|
||||
}
|
||||
|
||||
@@ -390,13 +369,11 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
|
||||
bareData = malloc(bareLength);
|
||||
|
||||
if(bareData == NULL)
|
||||
return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
if(bareData == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
||||
res = read_sector(context, sectorAddress, bareData, &bareLength);
|
||||
|
||||
if(bareLength != 512)
|
||||
return res;
|
||||
if(bareLength != 512) return res;
|
||||
|
||||
memcpy(data, ctx->sectorSubchannel + sectorAddress * tagLength, tagLength);
|
||||
memcpy(data, bareData, 512);
|
||||
@@ -405,7 +382,6 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
|
||||
|
||||
return res;
|
||||
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
|
||||
|
||||
}
|
||||
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user