libdiscmage.h 7.8 KB

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