Skip to content

Commit

Permalink
updated files so they will compile with linux by changing types, aka …
Browse files Browse the repository at this point in the history
…u_char to unsigned char
  • Loading branch information
sparkletron committed Oct 15, 2016
1 parent eaa7a08 commit e731010
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 91 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.objs
/ExampleFiles/
files
Debug
pages
scrap.txt
test.xml
*.depend
*.layout
*.exe
*.exe
mkpsxiso
107 changes: 53 additions & 54 deletions cd.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
// Sector size in bytes (do not change)
#define CD_SECTOR_SIZE 2352


// CD and ISO 9660 reader namespace
namespace cd {

/// Structure for a mode 2 form 1 sector (used in regular files)
typedef struct {
u_char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00)
u_char addr[3]; /// Sector address (see below for encoding details)
u_char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors)
u_char subHead[8]; /// Sub-header (00 00 08 00 00 00 08 00 for Form 1 data sectors)
u_char data[2048]; /// Data (form 1)
u_char edc[4]; /// Error-detection code (CRC32 of data area)
u_char ecc[276]; /// Error-correction code (uses Reed-Solomon ECC algorithm)
unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00)
unsigned char addr[3]; /// Sector address (see below for encoding details)
unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors)
unsigned char subHead[8]; /// Sub-header (00 00 08 00 00 00 08 00 for Form 1 data sectors)
unsigned char data[2048]; /// Data (form 1)
unsigned char edc[4]; /// Error-detection code (CRC32 of data area)
unsigned char ecc[276]; /// Error-correction code (uses Reed-Solomon ECC algorithm)
} SECTOR_M2F1;

/** Regular data files are usually stored in this sector format as it has ECC error correction which
Expand All @@ -48,10 +47,10 @@ namespace cd {

/// Structure for a mode 2 form 2 sector (used in STR/XA files)
typedef struct {
u_char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00)
u_char addr[3]; /// Sector address (a 24-bit big-endian integer. starts at 200, 201 an onwards)
u_char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors)
u_char data[2336]; /// 8 bytes Subheader, 2324 bytes Data (form 2), and 4 bytes ECC
unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00)
unsigned char addr[3]; /// Sector address (a 24-bit big-endian integer. starts at 200, 201 an onwards)
unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors)
unsigned char data[2336]; /// 8 bytes Subheader, 2324 bytes Data (form 2), and 4 bytes ECC
} SECTOR_M2F2;

// Set struct alignment to 1 because the ISO file system is not very memory alignment friendly which will
Expand All @@ -60,65 +59,65 @@ namespace cd {

/// Structure of a double-endian unsigned short word
typedef struct {
u_short lsb; /// LSB format 16-bit word
u_short msb; /// MSB format 16-bit word
unsigned short lsb; /// LSB format 16-bit word
unsigned short msb; /// MSB format 16-bit word
} ISO_USHORT_PAIR;

/// Structure of a double-endian unsigned int word
typedef struct {
u_int lsb; /// LSB format 32-bit word
u_int msb; /// MSB format 32-bit word
unsigned int lsb; /// LSB format 32-bit word
unsigned int msb; /// MSB format 32-bit word
} ISO_UINT_PAIR;

/// ISO descriptor header structure
typedef struct {
u_char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator)
unsigned char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator)
char id[5]; /// Volume descriptor ID (always CD001)
u_short version; /// Volume descriptor version (always 0x01)
unsigned short version; /// Volume descriptor version (always 0x01)
} ISO_DESCRIPTOR_HEADER;

/// Structure of a date stamp for ISO_DIR_ENTRY structure
typedef struct {
u_char year; /// number of years since 1900
u_char month; /// month, where 1=January, 2=February, etc.
u_char day; /// day of month, in the range from 1 to 31
u_char hour; /// hour, in the range from 0 to 23
u_char minute; /// minute, in the range from 0 to 59
u_char second; /// Second, in the range from 0 to 59
u_char GMToffs; /// Greenwich Mean Time offset
unsigned char year; /// number of years since 1900
unsigned char month; /// month, where 1=January, 2=February, etc.
unsigned char day; /// day of month, in the range from 1 to 31
unsigned char hour; /// hour, in the range from 0 to 23
unsigned char minute; /// minute, in the range from 0 to 59
unsigned char second; /// Second, in the range from 0 to 59
unsigned char GMToffs; /// Greenwich Mean Time offset
} ISO_DATESTAMP;

/// Structure of an ISO path table entry (specifically for the cd::IsoReader class)
typedef struct {
u_char nameLength; /// Name length (or 1 for the root directory)
u_char extLength; /// Number of sectors in extended attribute record
u_int dirOffs; /// Number of the first sector in the directory, as a double word
unsigned char nameLength; /// Name length (or 1 for the root directory)
unsigned char extLength; /// Number of sectors in extended attribute record
unsigned int dirOffs; /// Number of the first sector in the directory, as a double word
short dirLevel; /// Index of the directory record's parent directory
char* name; /// Name (0 for the root directory)
/// If nameLength is odd numbered, a padding byte will be present after the identifier text.
} ISO_PATHTABLE_ENTRY;

typedef struct {
// Directory entry length (variable, use for parsing through entries)
u_char entryLength;
unsigned char entryLength;
// Extended entry data length (always 0)
u_char extLength;
unsigned char extLength;
// Points to the LBA of the file/directory entry
ISO_UINT_PAIR entryOffs;
// Size of the file/directory entry
ISO_UINT_PAIR entrySize;
// Date & time stamp of entry
ISO_DATESTAMP entryDate;
// File flags (0x02 for directories, 0x00 for files)
u_char flags;
unsigned char flags;
// Unit size (usually 0 even with Form 2 files such as STR/XA)
u_char fileUnitSize;
unsigned char fileUnitSize;
// Interleave gap size (usually 0 even with Form 2 files such as STR/XA)
u_char interleaveGapSize;
unsigned char interleaveGapSize;
// Volume sequence number (always 1)
ISO_USHORT_PAIR volSeqNum;
// Identifier (file/directory name) length in bytes
u_char identifierLen;
unsigned char identifierLen;
// Pointer to identifier (placed here for convenience)
// If identifierLen is even numbered, a padding byte will be present after the identifier text.
char* identifier;
Expand All @@ -127,24 +126,24 @@ namespace cd {

// XA attribute struct (located right after the identifier string)
typedef struct {
u_int pad; // Nothing but null bytes
u_short type; // XA attribute (0x8800 for directories, 0x800 for regular files, 0x0 for XA Form 2 files)
unsigned int pad; // Nothing but null bytes
unsigned short type; // XA attribute (0x8800 for directories, 0x800 for regular files, 0x0 for XA Form 2 files)
char id[2]; // Always XA
u_char pad2[6]; // Nothing but null bytes
unsigned char pad2[6]; // Nothing but null bytes
} ISO_XA_ATTRIB;

typedef struct {
u_char entryLength; // Always 34 bytes
u_char extLength; // Always 0
unsigned char entryLength; // Always 34 bytes
unsigned char extLength; // Always 0
ISO_UINT_PAIR entryOffs; // Should point to LBA 22
ISO_UINT_PAIR entrySize; // Size of entry extent
ISO_DATESTAMP entryDate; // Record date and time
u_char flags; // File flags
u_char fileUnitSize;
u_char interleaveGapSize;
unsigned char flags; // File flags
unsigned char fileUnitSize;
unsigned char interleaveGapSize;
ISO_USHORT_PAIR volSeqNum;
u_char identifierLen; // 0x01
u_char identifier; // 0x01
unsigned char identifierLen; // 0x01
unsigned char identifier; // 0x01
} ISO_ROOTDIR_HEADER;

// ISO descriptor structure
Expand All @@ -157,11 +156,11 @@ namespace cd {
// Volume ID (or label, can be blank or anything)
char volumeID[32];
// Unused null bytes
u_char pad2[8];
unsigned char pad2[8];
// Size of volume in sector units
ISO_UINT_PAIR volumeSize;
// Unused null bytes
u_char pad3[32];
unsigned char pad3[32];
// Number of discs in this volume set (always 1 for single volume)
ISO_USHORT_PAIR volumeSetSize;
// Number of this disc in volume set (always 1 for single volume)
Expand All @@ -171,13 +170,13 @@ namespace cd {
// Path table size in bytes (applies to all the path tables)
ISO_UINT_PAIR pathTableSize;
// LBA to Type-L path table
u_int pathTable1Offs;
unsigned int pathTable1Offs;
// LBA to optional Type-L path table (usually a copy of the primary path table)
u_int pathTable2Offs;
unsigned int pathTable2Offs;
// LBA to Type-L path table but with MSB format values
u_int pathTable1MSBoffs;
unsigned int pathTable1MSBoffs;
// LBA to optional Type-L path table but with MSB format values (usually a copy of the main path table)
u_int pathTable2MSBoffs;
unsigned int pathTable2MSBoffs;
// Directory entry for the root directory (similar to a directory entry)
ISO_ROOTDIR_HEADER rootDirRecord;
// Volume set identifier (can be blank or anything)
Expand All @@ -203,13 +202,13 @@ namespace cd {
// Volume effective date (in text format YYYYMMDDHHMMSSMMGG)
char volumeEffeciveDate[17];
// File structure version (always 1)
u_char fileStructVersion;
unsigned char fileStructVersion;
// Padding
u_char dummy0;
unsigned char dummy0;
// Application specific data (says CD-XA001 at [141], the rest are null bytes)
u_char appData[512];
unsigned char appData[512];
// Padding
u_char pad4[653];
unsigned char pad4[653];

} ISO_DESCRIPTOR;

Expand Down
13 changes: 7 additions & 6 deletions cdwriter.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include <unistd.h>
#include <string.h>
#include "cdwriter.h"
#include "edcecc.h"


void cd::SwapBytes(void *var, int size) {

u_char temp[size];
unsigned char temp[size];

memcpy(temp, var, size);
for(short i=0; i<size; i++) {
((u_char*)var)[i] = temp[(size-1)-i];
((unsigned char*)var)[i] = temp[(size-1)-i];
}

}

void cd::SetPair16(cd::ISO_USHORT_PAIR* pair, u_short val) {
void cd::SetPair16(cd::ISO_USHORT_PAIR* pair, unsigned short val) {

pair->lsb = val;
pair->msb = val;
Expand All @@ -23,7 +24,7 @@ void cd::SetPair16(cd::ISO_USHORT_PAIR* pair, u_short val) {

}

void cd::SetPair32(cd::ISO_UINT_PAIR* pair, u_int val) {
void cd::SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val) {

pair->lsb = val;
pair->msb = val;
Expand Down Expand Up @@ -81,7 +82,7 @@ void cd::IsoWriter::PrepSector(int edcEccMode) {
edcEccGen.ComputeEdcBlock(cd::IsoWriter::sectorM2F1->subHead, 0x808, cd::IsoWriter::sectorM2F1->edc);

// Encode ECC data
u_char tempAddr[4];
unsigned char tempAddr[4];

for(int i=0; i<4; i++) {

Expand Down Expand Up @@ -330,7 +331,7 @@ int cd::IsoWriter::CurrentSector() {

}

void cd::IsoWriter::SetSubheader(u_char* data) {
void cd::IsoWriter::SetSubheader(unsigned char* data) {

memcpy(cd::IsoWriter::subHeadBuff, data, 8);

Expand Down
10 changes: 5 additions & 5 deletions cdwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace cd {
class IsoWriter {

FILE* filePtr;
u_char subHeadBuff[12];
u_char sectorBuff[CD_SECTOR_SIZE];
unsigned char subHeadBuff[12];
unsigned char sectorBuff[CD_SECTOR_SIZE];
SECTOR_M2F1* sectorM2F1;
SECTOR_M2F2* sectorM2F2;

Expand Down Expand Up @@ -42,7 +42,7 @@ class IsoWriter {

int CurrentSector();

void SetSubheader(u_char* data);
void SetSubheader(unsigned char* data);

size_t WriteBytes(void* data, size_t bytes, int edcEccEncode);
size_t WriteBytesXA(void* data, size_t bytes, int edcEccEncode);
Expand All @@ -53,8 +53,8 @@ class IsoWriter {
};

void SwapBytes(void *var, int size);
void SetPair16(cd::ISO_USHORT_PAIR* pair, u_short val);
void SetPair32(cd::ISO_UINT_PAIR* pair, u_int val);
void SetPair16(cd::ISO_USHORT_PAIR* pair, unsigned short val);
void SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val);

};

Expand Down
22 changes: 11 additions & 11 deletions edcecc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

EDCECC::EDCECC() {

u_int i,j,edc;
unsigned int i,j,edc;

for(i=0; i<256; i++) {

Expand All @@ -25,7 +25,7 @@ EDCECC::EDCECC() {

}

u_int EDCECC::ComputeEdcBlockPartial(u_int edc, const u_char *src, int len) {
unsigned int EDCECC::ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len) {

while(len--)
edc = (edc>>8)^EDCECC::edc_lut[(edc^(*src++))&0xFF];
Expand All @@ -34,9 +34,9 @@ u_int EDCECC::ComputeEdcBlockPartial(u_int edc, const u_char *src, int len) {

}

void EDCECC::ComputeEdcBlock(const u_char *src, int len, u_char *dest) {
void EDCECC::ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest) {

u_int edc = EDCECC::ComputeEdcBlockPartial(0, src, len);
unsigned int edc = EDCECC::ComputeEdcBlockPartial(0, src, len);

dest[0] = (edc>>0)&0xFF;
dest[1] = (edc>>8)&0xFF;
Expand All @@ -45,20 +45,20 @@ void EDCECC::ComputeEdcBlock(const u_char *src, int len, u_char *dest) {

}

void EDCECC::ComputeEccBlock(u_char *src, u_int major_count, u_int minor_count, u_int major_mult, u_int minor_inc, u_char *dest) {
void EDCECC::ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest) {

u_int len = major_count*minor_count;
u_int major,minor;
unsigned int len = major_count*minor_count;
unsigned int major,minor;

for(major = 0; major < major_count; major++) {

u_int index = (major >> 1) * major_mult + (major & 1);
u_char ecc_a = 0;
u_char ecc_b = 0;
unsigned int index = (major >> 1) * major_mult + (major & 1);
unsigned char ecc_a = 0;
unsigned char ecc_b = 0;

for(minor = 0; minor < minor_count; minor++) {

u_char temp = src[index];
unsigned char temp = src[index];

index += minor_inc;

Expand Down
12 changes: 6 additions & 6 deletions edcecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
class EDCECC {

// Tables for EDC and ECC calculation
u_char ecc_f_lut[256];
u_char ecc_b_lut[256];
u_int edc_lut[256];
unsigned char ecc_f_lut[256];
unsigned char ecc_b_lut[256];
unsigned int edc_lut[256];

public:

// Initializer
EDCECC();

// Computes the EDC of *src and returns the result
u_int ComputeEdcBlockPartial(u_int edc, const u_char *src, int len);
unsigned int ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len);

// Computes the EDC of *src and stores the result to an unsigned char array *dest
void ComputeEdcBlock(const u_char *src, int len, u_char *dest);
void ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest);

// Computes the ECC data of *src and stores the result to an unsigned char array *dest
void ComputeEccBlock(u_char *src, u_int major_count, u_int minor_count, u_int major_mult, u_int minor_inc, u_char *dest);
void ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest);

};

Expand Down
Loading

0 comments on commit e731010

Please sign in to comment.