1 /* 2 libdiscmage.h - libdiscmage 3 4 Copyright (c) 2002 - 2004 NoisyB 5 Copyright (c) 2002 - 2004, 2018, 2020 - 2021 dbjh 6 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 #ifndef LIBDISCMAGE_H 23 #define LIBDISCMAGE_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <stdio.h> // FILENAME_MAX 30 31 #if !(defined __MSDOS__ || defined _MSC_VER) 32 // We cannot use config.h (for HAVE_INTTYPES_H), because this header file may be 33 // installed in a system include directory 34 #include <inttypes.h> 35 #else // __MSDOS__, _WIN32 (VC++) 36 #ifndef OWN_INTTYPES 37 #define OWN_INTTYPES // signal that these are defined 38 typedef unsigned char uint8_t; 39 typedef signed char int8_t; 40 typedef unsigned short int uint16_t; 41 typedef signed short int int16_t; 42 typedef unsigned int uint32_t; 43 typedef signed int int32_t; 44 #ifndef _WIN32 45 typedef unsigned long long int uint64_t; 46 typedef signed long long int int64_t; 47 #else 48 typedef unsigned __int64 uint64_t; 49 typedef signed __int64 int64_t; 50 #endif 51 #endif // OWN_INTTYPES 52 #endif 53 54 #define DM_VERSION_MAJOR 0 55 #define DM_VERSION_MINOR 0 56 #define DM_VERSION_STEP 7 57 58 59 // a CD can have max. 99 tracks; this value might change in the future 60 #define DM_MAX_TRACKS 99 61 62 #ifdef _MSC_VER 63 #pragma warning(push) 64 #pragma warning(disable: 4820) // 'bytes' bytes padding added after construct 'member_name' 65 #endif 66 typedef struct 67 { 68 // TODO?: replace those uint32_t with uint64_t or so... 69 70 // some formats use to have the tracks "embedded" (like: cdi, nrg, etc..) 71 // this is the start offset inside the image 72 uint32_t track_start; // in bytes 73 uint32_t track_end; // in bytes 74 75 int16_t pregap_len; // in sectors 76 uint32_t track_len; // in sectors 77 uint32_t total_len; // in sectors; pregap_len + track_len == total_len 78 // (less if the track is truncated) 79 80 int16_t postgap_len;// in sectors 81 int16_t start_lba; // in sectors 82 83 // start of the iso header inside the track (inside the image) 84 int32_t iso_header_start; // if -1 then no iso header 85 86 int8_t mode; // 0 == AUDIO, 1 == MODE1, 2 == MODE2 87 uint16_t sector_size; // in bytes; includes seek_header + seek_ecc 88 int16_t seek_header; // in bytes 89 int16_t seek_ecc; // in bytes 90 91 const char *desc; // deprecated 92 int id; // DM_AUDIO, DM_MODE1_2048, ... 93 } dm_track_t; 94 95 96 typedef struct 97 { 98 int type; // image type DM_CDI, DM_NRG, DM_TOC, etc. 99 char *desc; // like type but more verbose 100 int flags; // DM_FIX, ... 101 char fname[FILENAME_MAX]; // filename of image 102 uint32_t version; // version of image (used by CDI and NRG) 103 104 int sessions; // # of sessions 105 int tracks; // # of tracks 106 107 dm_track_t track[DM_MAX_TRACKS]; // array of dm_track_t 108 uint8_t session[DM_MAX_TRACKS + 1]; // array of uint32_t with tracks per session 109 110 // some image formats (CDI) use embedded headers instead of TOC or CUE files 111 int header_start; 112 int header_len; // if header_len == 0 then no header(!) 113 114 char misc[4096]; // miscellaneous information about proprietary images (other.c) 115 } dm_image_t; 116 #ifdef _MSC_VER 117 #pragma warning(pop) 118 #endif 119 120 121 /* 122 dm_get_version() returns version of libdiscmage as uint32_t 123 dm_get_version_s() returns version of libdiscmage as string 124 dm_open() this is the first function to call with the filename of the 125 image; it will try to recognize the image format, etc. 126 dm_reopen() like dm_open() but can reuse an existing dm_image_t 127 dm_close() the last function; close image 128 dm_fdopen() returns a FILE ptr from the start of a track (in image) 129 TODO: dm_seek() seek for tracks inside image 130 dm_fseek (image, 2, SEEK_END); 131 will seek to the end of the 2nd track in image 132 dm_set_gauge() enter here the name of a function that takes two integers 133 gauge (pos, total) 134 { 135 printf ("%d of %d done", pos, total); 136 } 137 dm_nfo() display dm_image_t 138 dm_read() read single sector from track (in image) 139 TODO: dm_write() write single sector to track (in image) 140 141 dm_toc_read() read TOC sheet into dm_image_t (deprecated) 142 dm_toc_write() write dm_image_t as TOC sheet (deprecated) 143 dm_cue_read() read CUE sheet into dm_image_t (deprecated) 144 dm_cue_write() write dm_image_t as CUE sheet (deprecated) 145 dm_disc_read() deprecated reading or writing images is done 146 by those scripts in contrib/ (deprecated) 147 dm_disc_write() deprecated reading or writing images is done 148 by those scripts in contrib/ (deprecated) 149 */ 150 extern uint32_t dm_get_version (void); 151 extern const char *dm_get_version_s (void); 152 extern void dm_set_gauge (void (*gauge) (int, int)); 153 154 extern dm_image_t *dm_open (const char *fname, uint32_t flags); 155 extern dm_image_t *dm_reopen (const char *fname, uint32_t flags, dm_image_t *image); 156 extern int dm_close (dm_image_t *image); 157 158 //extern int dm_seek (FILE *fp, int track_num, int how); 159 extern FILE *dm_fdopen (dm_image_t *image, int track_num, const char *mode); 160 //#define DM_NFO_ANSI_COLOR 1 161 //#define DM_NFO_VERBOSE 2 162 extern void dm_nfo (const dm_image_t *image, int verbose, int ansi_color); 163 164 extern int dm_read (char *buffer, int track_num, int sector, const dm_image_t *image); 165 extern int dm_write (const char *buffer, int track_num, int sector, const dm_image_t *image); 166 167 extern dm_image_t *dm_toc_read (dm_image_t *image, const char *toc_sheet); 168 extern int dm_toc_write (const dm_image_t *image); 169 170 extern dm_image_t *dm_cue_read (dm_image_t *image, const char *cue_sheet); 171 extern int dm_cue_write (const dm_image_t *image); 172 173 extern int dm_disc_read (const dm_image_t *image); 174 extern int dm_disc_write (const dm_image_t *image); 175 176 177 /* 178 dm_rip() convert/rip a track from an image 179 TODO: DM_FILES rip files from track instead of track 180 DM_WAV convert possible audio track to wav (instead of raw) 181 DM_2048 (bin2iso) convert binary sector_size to 2048 bytes 182 (could result in a malformed output image) 183 TODO: DM_FIX (isofix) takes an ISO image with PVD pointing 184 to bad DR offset and add padding data so actual DR 185 gets located in right absolute address. 186 Original boot area, PVD, SVD and VDT are copied to 187 the start of new, fixed ISO image. 188 Supported input images are: 2048, 2336, 189 2352 and 2056 bytes per sector. All of them are 190 converted to 2048 bytes per sector when writing 191 excluding 2056 image which is needed by Mac users. 192 */ 193 #define DM_CDMAGE 0 194 #define DM_FILES 1 195 #define DM_WAV 2 196 #define DM_2048 4 197 #define DM_FIX 8 198 extern int dm_rip (const dm_image_t *image, int track_num, uint32_t flags); 199 200 #ifdef __cplusplus 201 } 202 #endif 203 204 #endif // LIBDISCMAGE_H 205