Apply debian patch 02-encryption Apply debian patch 03-dvdrom Apply a modified version of patch 05-help-dialog Apply debian patch 08-fix-gnu-make-detection Apply debian patch 10-use-non-size-specific-icon-and-add-keywords-to-desktop-file Apply debian patch 12-fix-spelling-of-up-to Apply debian patch 13-fix-missing-language-field-in-po-files Apply a modified version of debian patch 14-make-builds-reproducible Apply debian patch 17-fix-all-but-deprecated-api-warnings Apply a modified version of debian patch 18-update-copyright-in-about-dialog Apply debian patch 19-show-text-files-with-abs-path Apply debian patch 22-fix-hurd-i386-ftbfs Apply debian patch 23-add-bdrom-support Apply debian patch 25-fix-man-pages Apply debian patch 27-allow-opening-in-browser-again Apply debian patch 28-pdftex-reproducibility Apply debian patch 29-fix-more-typos Apply debian patch 30-hurd-kfreebsd-ftbfs Apply debian patch 31-improve-hurd-and-kfreebsd-support Apply debian patch 33-honour-LDFLAGS Apply debian patch 34-gcc8-format-security.patch Apply debian patch 35-archived-homepage Apply debian patch 36-fix-parallelism
259 lines
7.1 KiB
C
259 lines
7.1 KiB
C
/* dvdisaster: Additional error correction for optical media.
|
|
* Copyright (C) 2004-2017 Carsten Gnoerlich.
|
|
*
|
|
* Email: carsten@dvdisaster.org -or- cgnoerlich@fsfe.org
|
|
* Project homepage: http://www.dvdisaster.org
|
|
*
|
|
* This file is part of dvdisaster.
|
|
*
|
|
* dvdisaster is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* dvdisaster is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with dvdisaster. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef SCSI_LAYER_H
|
|
#define SCSI_LAYER_H
|
|
|
|
#ifdef SYS_LINUX
|
|
#include <sys/ioctl.h>
|
|
#include <linux/cdrom.h>
|
|
#endif
|
|
|
|
#if defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
|
|
#include <camlib.h>
|
|
#endif
|
|
|
|
/***
|
|
*** Global settings
|
|
***/
|
|
|
|
/* Theretically not needed, but using less causes DMA breakage
|
|
on some chipsets. */
|
|
|
|
#define MIN_TRANSFER_LEN 4
|
|
|
|
/***
|
|
*** Define the Sense data structure.
|
|
***/
|
|
|
|
/*
|
|
* Linux already has one
|
|
*/
|
|
|
|
#if defined(SYS_LINUX)
|
|
|
|
#define MAX_CDB_SIZE CDROM_PACKET_SIZE
|
|
|
|
/* Now globally defined for all OSes here */
|
|
//typedef struct request_sense Sense;
|
|
|
|
#elif defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
|
|
|
|
#define MAX_CDB_SIZE SCSI_MAX_CDBLEN
|
|
|
|
#else /* SYS_UNKNOWN and others. */
|
|
|
|
#define MAX_CDB_SIZE 16 /* longest possible SCSI command */
|
|
|
|
#endif
|
|
|
|
/*
|
|
* The sense struct is named differently on various OSes,
|
|
* Some have subtle differences in the used data types.
|
|
* To avoid typecasting mayhem we simply reproduce the Linux
|
|
* version here and use it on all OS versions.
|
|
*/
|
|
|
|
typedef struct _Sense {
|
|
guint8 error_code : 7;
|
|
guint8 valid : 1;
|
|
guint8 segment_number;
|
|
guint8 sense_key : 4;
|
|
guint8 reserved2 : 1;
|
|
guint8 ili : 1;
|
|
guint8 reserved1 : 2;
|
|
guint8 information[4];
|
|
guint8 add_sense_len;
|
|
guint8 command_info[4];
|
|
guint8 asc;
|
|
guint8 ascq;
|
|
guint8 fruc;
|
|
guint8 sks[3];
|
|
guint8 asb[46];
|
|
} Sense;
|
|
|
|
/***
|
|
*** The DeviceHandle is pretty much our device abstraction layer.
|
|
***
|
|
* It contains info about the opened device and the inserted medium.
|
|
*/
|
|
|
|
typedef struct _DeviceHandle
|
|
{ /*
|
|
* OS-specific data for device access
|
|
*/
|
|
#if defined(SYS_LINUX) || defined(SYS_NETBSD)
|
|
int fd; /* device file descriptor */
|
|
#elif defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
|
|
struct cam_device *camdev; /* camlib device handle */
|
|
union ccb *ccb;
|
|
#endif
|
|
|
|
/*
|
|
* Simulated images
|
|
*/
|
|
|
|
LargeFile *simImage; /* Image for simulation mode */
|
|
int pass; /* provided by the reader to simulate failure in specific passes */
|
|
|
|
/*
|
|
* OS-independent data about the device
|
|
*/
|
|
|
|
char *device; /* /dev/foo or whatever the OS uses to name it */
|
|
char devinfo[34]; /* whole device info string from INQUIRY */
|
|
char vendor[34]; /* vendor and product info only */
|
|
|
|
Sense sense; /* sense data from last operation */
|
|
int senseSize; /* OS may have differently sized struct */
|
|
|
|
double singleRate; /* supposed KB/sec @ single speed */
|
|
int maxRate; /* guessed maximum transfer rate */
|
|
int clusterSize; /* number of sectors per cluster */
|
|
|
|
/*
|
|
* Raw reading support
|
|
*/
|
|
|
|
int canReadDefective; /* TRUE if drive claims to raw read uncorrectable sectors */
|
|
int canC2Scan; /* TRUE if drive supports C2 error scanning */
|
|
int c2[MAX_CLUSTER_SIZE]; /* C2 errors per sector */
|
|
unsigned char previousReadMode;/* read mode prior to switching to raw reads */
|
|
unsigned char previousRetries; /* retries prior to switching */
|
|
unsigned char currentReadMode; /* current raw read mode */
|
|
RawBuffer *rawBuffer; /* for performing raw read analysis */
|
|
int (*read)(struct _DeviceHandle*, unsigned char*, int, int);
|
|
int (*readRaw)(struct _DeviceHandle*, unsigned char*, int, int);
|
|
|
|
/*
|
|
* Information about currently inserted medium
|
|
*/
|
|
|
|
gint64 sectors; /* actually used number of sectors */
|
|
int sessions; /* number of sessions */
|
|
int layers; /* and layers */
|
|
char manuID[20]; /* Manufacturer info from ADIP/lead-in */
|
|
int mainType; /* CD or DVD */
|
|
int subType; /* see enum below */
|
|
char *typeDescr; /* human readable form of subType */
|
|
int bookType; /* book type */
|
|
char *bookDescr; /* human readable of above */
|
|
int profile; /* profile selected by drive */
|
|
char *profileDescr; /* human readable form of above */
|
|
char *shortProfile; /* short version of above */
|
|
int isDash; /* DVD- */
|
|
int isPlus; /* DVD+ */
|
|
int incomplete; /* disc is not finalized or otherwise broken */
|
|
int discStatus; /* obtained from READ DISC INFORMATION query */
|
|
int rewriteable;
|
|
char *mediumDescr; /* textual description of medium */
|
|
|
|
/*
|
|
* size alternatives from different sources
|
|
*/
|
|
|
|
gint64 readCapacity; /* value returned by READ CAPACITY */
|
|
gint64 userAreaSize; /* size of user area according to DVD Info struct */
|
|
gint64 blankCapacity; /* blank capacity (maybe 0 if query failed) */
|
|
|
|
/*
|
|
* debugging stuff
|
|
*/
|
|
|
|
Bitmap *defects; /* for defect simulation */
|
|
} DeviceHandle;
|
|
|
|
/*
|
|
* Media types seem not to be standardized anywhere,
|
|
* so we make up our own here.
|
|
*/
|
|
|
|
#define MAIN_TYPE_MASK 0xf0
|
|
|
|
#define CD 0x10
|
|
#define DATA1 0x11
|
|
#define XA21 0x12
|
|
|
|
#define DVD 0x20
|
|
#define DVD_RAM 0x21
|
|
#define DVD_DASH_R 0x22
|
|
#define DVD_DASH_RW 0x23
|
|
#define DVD_PLUS_R 0x24
|
|
#define DVD_PLUS_RW 0x25
|
|
#define DVD_DASH_R_DL 0x26
|
|
#define DVD_DASH_RW_DL 0x27
|
|
#define DVD_PLUS_R_DL 0x28
|
|
#define DVD_PLUS_RW_DL 0x29
|
|
|
|
#define BD 0x40
|
|
#define BD_R 0x41
|
|
#define BD_RE 0x42
|
|
|
|
#define UNSUPPORTED 0x00
|
|
|
|
/* transport io modes */
|
|
|
|
#define DATA_WRITE 0
|
|
#define DATA_READ 1
|
|
#define DATA_NONE 2
|
|
|
|
/***
|
|
*** Exported functions
|
|
***/
|
|
|
|
/*
|
|
* OS-dependent wrappers from scsi-<os>.c
|
|
*/
|
|
|
|
DeviceHandle* OpenDevice(char*);
|
|
|
|
int SendPacket(DeviceHandle*, unsigned char*, int, unsigned char*, int, Sense*, int);
|
|
int SimulateSendPacket(DeviceHandle*, unsigned char*, int, unsigned char*, int, Sense*, int);
|
|
|
|
/***
|
|
*** scsi-layer.c
|
|
***
|
|
* The really user-visible stuff
|
|
*/
|
|
|
|
enum
|
|
{ MODE_PAGE_UNSET,
|
|
MODE_PAGE_SET
|
|
};
|
|
|
|
|
|
int QueryBlankCapacity(DeviceHandle*);
|
|
gint64 CurrentMediumSize(int);
|
|
void CloseDevice(DeviceHandle*);
|
|
|
|
int InquireDevice(DeviceHandle*, int);
|
|
void SetRawMode(DeviceHandle*, int);
|
|
|
|
void SpinupDevice(DeviceHandle*);
|
|
void LoadMedium(struct _DeviceHandle*, int);
|
|
int TestUnitReady(DeviceHandle*);
|
|
|
|
int ReadSectors(DeviceHandle*, unsigned char*, gint64, int);
|
|
int ReadSectorsFast(DeviceHandle*, unsigned char*, gint64, int);
|
|
|
|
#endif /* SCSI_LAYER_H */
|