/* dvdisaster: Additional error correction for optical media.1* Copyright (C) 2004-2007 Carsten Gnoerlich.2* Project home page: http://www.dvdisaster.com3* Email: [email protected] -or- [email protected]4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,18* or direct your browser at http://www.gnu.org.19*/2021#ifndef DVDISASTER_H22#define DVDISASTER_H2324/* "Dare to be gorgeous and unique.25* But don't ever be cryptic or otherwise unfathomable.26* Make it unforgettably great."27*28* From "A Final Note on Style",29* Amiga Intuition Reference Manual, 1986, p. 23130*/3132/***33*** I'm too lazy to mess with #include dependencies.34*** Everything #includeable is rolled up herein...35*/3637#include "octoshock.h"38#include <ctype.h>39#include <errno.h>40#include <fcntl.h>41#include <math.h>42#include <sys/types.h>43#include <sys/stat.h>44#include <stdarg.h>45#include <stddef.h>46#include <stdio.h>47#include <stdlib.h>48#include <string.h>4950/***51*** dvdisaster.c52***/5354void PrepareDeadSector(void);5556void CreateEcc(void);57void FixEcc(void);58void Verify(void);5960uint32 EDCCrc32(const unsigned char*, int);6162/***63*** galois.c64***65* This is currently the hardcoded GF(2**8).66* int32 gives abundant space for the GF.67* Squeezing it down to uint8 won't probably gain much,68* so we implement this defensively here.69*70* Note that some performance critical stuff needs to71* be #included from galois-inlines.h72*/7374/* Galois field parameters for 8bit symbol Reed-Solomon code */7576#define GF_SYMBOLSIZE 877#define GF_FIELDSIZE (1<<GF_SYMBOLSIZE)78#define GF_FIELDMAX (GF_FIELDSIZE-1)79#define GF_ALPHA0 GF_FIELDMAX8081/* Lookup tables for Galois field arithmetic */8283typedef struct _GaloisTables84{ int32 gfGenerator; /* GF generator polynomial */85int32 *indexOf; /* log */86int32 *alphaTo; /* inverse log */87int32 *encAlphaTo; /* inverse log optimized for encoder */88} GaloisTables;8990/* Lookup and working tables for the ReedSolomon codecs */9192typedef struct _ReedSolomonTables93{ GaloisTables *gfTables;/* from above */94int32 *gpoly; /* RS code generator polynomial */95int32 fcr; /* first consecutive root of RS generator polynomial */96int32 primElem; /* primitive field element */97int32 nroots; /* degree of RS generator polynomial */98int32 ndata; /* data bytes per ecc block */99} ReedSolomonTables;100101GaloisTables* CreateGaloisTables(int32);102void FreeGaloisTables(GaloisTables*);103104ReedSolomonTables *CreateReedSolomonTables(GaloisTables*, int32, int32, int);105void FreeReedSolomonTables(ReedSolomonTables*);106107/***108*** l-ec.c109***/110111#define N_P_VECTORS 86 /* 43 16bit p vectors */112#define P_VECTOR_SIZE 26 /* using RS(26,24) ECC */113114#define N_Q_VECTORS 52 /* 26 16bit q vectors */115#define Q_VECTOR_SIZE 45 /* using RS(45,43) ECC */116117#define P_PADDING 229 /* padding values for */118#define Q_PADDING 210 /* shortened RS code */119120int PToByteIndex(int, int);121int QToByteIndex(int, int);122void ByteIndexToP(int, int*, int*);123void ByteIndexToQ(int, int*, int*);124125void GetPVector(unsigned char*, unsigned char*, int);126void SetPVector(unsigned char*, unsigned char*, int);127void FillPVector(unsigned char*, unsigned char, int);128void AndPVector(unsigned char*, unsigned char, int);129void OrPVector(unsigned char*, unsigned char, int);130131void GetQVector(unsigned char*, unsigned char*, int);132void SetQVector(unsigned char*, unsigned char*, int);133void FillQVector(unsigned char*, unsigned char, int);134void AndQVector(unsigned char*, unsigned char, int);135void OrQVector(unsigned char*, unsigned char, int);136137int DecodePQ(ReedSolomonTables*, unsigned char*, int, int*, int);138139int CountC2Errors(unsigned char*);140141/***142*** misc.c143***/144145char* sgettext(char*);146char* sgettext_utf8(char*);147148int64 uchar_to_int64(unsigned char*);149void int64_to_uchar(unsigned char*, int64);150151void CalcSectors(int64, int64*, int*);152153/***154*** recover-raw.c155***/156157#define CD_RAW_SECTOR_SIZE 2352158#define CD_RAW_C2_SECTOR_SIZE (2352+294) /* main channel plus C2 vector */159160int CheckEDC(const unsigned char*, bool);161int CheckMSF(unsigned char*, int);162163164int ValidateRawSector(unsigned char *frame, bool xaMode);165bool Init_LEC_Correct(void);166void Kill_LEC_Correct(void);167168169#endif /* DVDISASTER_H */170171172