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