filename | src/gdrom/gddriver.h |
changeset | 1023:264e2fd90be8 |
prev | 837:4eae2ddccf9c |
next | 1025:f32183d273fb |
author | nkeynes |
date | Mon Jun 08 04:12:21 2009 +0000 (12 years ago) |
permissions | -rw-r--r-- |
last change | General cleanup of the GD-rom subsystem - merge gdrom_image_t and gdrom_disc_t - Abstract MMC devices using a lower-level scsi transport - OSX: only look at the whole disc device, and ignore partitions |
file | annotate | diff | log | raw |
1.1 --- a/src/gdrom/gddriver.h Thu Aug 28 01:39:51 2008 +00001.2 +++ b/src/gdrom/gddriver.h Mon Jun 08 04:12:21 2009 +00001.3 @@ -32,15 +32,11 @@1.5 #define MAX_SECTOR_SIZE 23521.7 +#define CD_MSF_START 150 /* MSF numbering starts after the initial pregap */1.8 #define CD_FRAMES_PER_SECOND 751.9 #define CD_SECONDS_PER_MINUTE 601.10 #define CD_FRAMES_PER_MINUTE (CD_FRAMES_PER_SECOND*CD_SECONDS_PER_MINUTE)1.12 -struct gdrom_toc {1.13 - uint32_t track[99];1.14 - uint32_t first, last, leadout;1.15 -};1.16 -1.17 #define GDROM_PREGAP 150 /* Sectors */1.19 extern uint32_t gdrom_sector_size[];1.20 @@ -75,8 +71,8 @@1.21 */1.22 #define IDE_DISC_READY 0x01 /* ored with above */1.23 #define IDE_DISC_IDLE 0x02 /* ie spun-down */1.24 -#define IDE_DISC_NONE 0x061.26 +#define IDE_DISC_NONE 0x061.27 #define IDE_DISC_AUDIO 0x001.28 #define IDE_DISC_CDROM 0x101.29 #define IDE_DISC_CDROMXA 0x201.30 @@ -94,11 +90,30 @@1.31 uint32_t lba; /* start sector address */1.32 uint32_t sector_size; /* For convenience, determined by mode */1.33 uint32_t sector_count;1.34 - uint32_t offset; /* File offset of start of track - image files only */1.35 - FILE *file;1.36 + uint32_t offset; /* File offset of start of track (image files only) */1.37 + FILE *file; /* Per-track file handle (if any) */1.38 } *gdrom_track_t;1.40 struct gdrom_disc {1.41 + int disc_type; /* One of the IDE_DISC_* flags */1.42 + const gchar *name; /* Device name / Image filename (owned) */1.43 + const gchar *display_name; /* User-friendly device name, if any (owned) */1.44 + gchar mcn[14]; /* Media catalogue number */1.45 + char title[129]; /* Disc title (if any) from bootstrap */1.46 + int track_count;1.47 + struct gdrom_track track[99];1.48 + FILE *file; /* Image file / device handle */1.49 + void *impl_data; /* Implementation private data */1.50 +1.51 + /* Check for media change. If the media cannot change (ie image file)1.52 + * or is notified asynchonously, this should be a no-op. In the event of1.53 + * a change, this function should update the structure according to the1.54 + * new media (including TOC), and return TRUE.1.55 + * @return TRUE if the media has changed since the last check, otherwise1.56 + * FALSE.1.57 + */1.58 + gboolean (*check_status)( struct gdrom_disc *disc );1.59 +1.60 /**1.61 * Read a single sector from the disc at the specified logical address.1.62 * @param disc pointer to the disc structure1.63 @@ -113,70 +128,85 @@1.64 unsigned char *buf, uint32_t *length );1.66 /**1.67 - * Read the TOC from the disc and write it into the specified buffer.1.68 - * The method is responsible for returning the data in gd-rom1.69 - * format.1.70 - * @param disc pointer to the disc structure1.71 - * @param buf buffer to receive data (0x198 bytes long)1.72 - */1.73 - gdrom_error_t (*read_toc)(struct gdrom_disc *disc, unsigned char *buf);1.74 -1.75 - /**1.76 - * Read the information for the specified sector and return it in the1.77 - * supplied buffer.1.78 - * @param disc pointer to the disc structure1.79 - * @param session of interest. If 0, return end of disc information.1.80 - * @param buf buffer to receive data (6 bytes)1.81 - */1.82 - gdrom_error_t (*read_session)(struct gdrom_disc *disc, int session, unsigned char *buf);1.83 -1.84 - /**1.85 - * Read the position information (subchannel) for the specified sector1.86 - * and return it in the supplied buffer. This method does not need to1.87 - * write the first 4 bytes of the buffer.1.88 - * @param disc pointer to the disc structure1.89 - * @param lba sector to get position information for1.90 - * @param buf buffer to receive data (14 bytes)1.91 - */1.92 - gdrom_error_t (*read_position)(struct gdrom_disc *disc, uint32_t lba, unsigned char *buf);1.93 -1.94 - /**1.95 - * Return the current disc status, expressed as a combination of the1.96 - * IDE_DISC_* flags above.1.97 - * @param disc pointer to the disc structure1.98 - * @return an integer status value.1.99 - */1.100 - int (*drive_status)(struct gdrom_disc *disc);1.101 -1.102 - /**1.103 * Begin playing audio from the given lba address on the disc.1.104 */1.105 gdrom_error_t (*play_audio)(struct gdrom_disc *disc, uint32_t lba, uint32_t endlba);1.107 + /**1.108 + * Stop audio playback1.109 + */1.110 + gdrom_error_t (*stop_audio)(struct gdrom_disc *disc);1.111 +1.112 /**1.113 * Executed once per time slice to perform house-keeping operations1.114 * (checking disc status, media changed, etc).1.115 */1.116 uint32_t (*run_time_slice)( struct gdrom_disc *disc, uint32_t nanosecs );1.118 - /**1.119 - * Close the disc and release any storage or resources allocated including1.120 - * the disc structure itself.1.121 - */1.122 - void (*close)( struct gdrom_disc *disc );1.123 - const gchar *name; /* Device name / Image filename */1.124 - char title[129]; /* Disc title (if any) */1.125 + /**1.126 + * Release all memory and system resources, including the gdrom_disc itself.1.127 + * (implicitly calls close() if not already closed.1.128 + * @param disc The disc to destroy1.129 + * @param close_fh if TRUE, close the main file/device, otherwise leave open.1.130 + * This is mainly used when the handle will be immediately reused.1.131 + */1.132 + void (*destroy)( struct gdrom_disc *disc, gboolean close_fh );1.133 };1.135 -typedef struct gdrom_image {1.136 - struct gdrom_disc disc;1.137 - int disc_type;1.138 - int track_count;1.139 - struct gdrom_track track[99];1.140 - gchar mcn[14]; /* Media catalogue number */1.141 - FILE *file; /* Open file stream */1.142 - void *private; /* image private data */1.143 -} *gdrom_image_t;1.144 +/**1.145 + * Low-level SCSI transport provided to the main SCSI/MMC driver. When used1.146 + * this will be set as the disc->impl_data field.1.147 + * Note: For symmetry there should be a packet_write variant, but we don't1.148 + * currently need it for anything. YAGNI, etc.1.149 + */1.150 +typedef struct gdrom_scsi_transport {1.151 + /* Execute a read command (ie a command that returns a block of data in1.152 + * response, not necessarily a CD read).1.153 + * @param scsi The disc to execute the command1.154 + * @param cmd The 12-byte command packet1.155 + * @param buf The buffer to receive the read results1.156 + * @param length On entry, the size of buf. Modified on exit to the number1.157 + * of bytes actually read.1.158 + * @return PKT_ERR_OK on success, otherwise the host error code.1.159 + */1.160 + gdrom_error_t (*packet_read)( struct gdrom_disc *disc,1.161 + unsigned char *cmd, unsigned char *buf,1.162 + unsigned int *length );1.163 +1.164 + /* Execute a generic command that does not write or return any data.1.165 + * (eg play audio).1.166 + * @param scsi The disc to execute the command1.167 + * @param cmd The 12-byte command packet1.168 + * @return PKT_ERR_OK on success, otherwise the host error code.1.169 + */1.170 + gdrom_error_t (*packet_cmd)( struct gdrom_disc *disc,1.171 + unsigned char *cmd );1.172 +1.173 + /* Return TRUE if the media has changed since the last call, otherwise1.174 + * FALSE. This method is used to implement the disc-level check_status1.175 + * and should have no side-effects.1.176 + */1.177 + gboolean (*media_changed)( struct gdrom_disc *disc );1.178 +} *gdrom_scsi_transport_t;1.179 +1.180 +/**1.181 + * Allocate a new gdrom_disc_t and initialize the filename and file fields.1.182 + * The disc is otherwise uninitialized - this is an internal method for use1.183 + * by the concrete implementations.1.184 + */1.185 +gdrom_disc_t gdrom_disc_new(const gchar *filename, FILE *f);1.186 +1.187 +/**1.188 + * Construct a new SCSI/MMC disc using the supplied transport implementation.1.189 + */1.190 +gdrom_disc_t gdrom_scsi_disc_new(const gchar *filename, FILE *f, gdrom_scsi_transport_t transport);1.191 +1.192 +/**1.193 + * Construct a new image file using the default methods.1.194 + */1.195 +gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );1.196 +1.197 +#define SCSI_TRANSPORT(disc) ((gdrom_scsi_transport_t)disc->impl_data)1.199 /**1.200 *1.201 @@ -194,27 +224,14 @@1.202 extern struct gdrom_image_class cdrom_device_class;1.204 /**1.205 - * Construct a new image file using the default methods.1.206 + * Determine the track number containing the specified sector by lba.1.207 */1.208 -gdrom_disc_t gdrom_image_new( const gchar *filename, FILE *f );1.209 +int gdrom_disc_get_track_by_lba( gdrom_disc_t image, uint32_t lba );1.211 /**1.212 - * Destroy an image data structure without closing the file1.213 - * (Intended for use from image loaders only)1.214 + * Default disc destroy method, for chaining from subclasses1.215 */1.216 -void gdrom_image_destroy_no_close( gdrom_disc_t d );1.217 -1.218 -/**1.219 - * Determine the track number containing the specified sector by lba.1.220 - */1.221 -int gdrom_image_get_track_by_lba( gdrom_image_t image, uint32_t lba );1.222 -1.223 -/**1.224 - * Given a base filename (eg for a .cue file), generate the path for the given1.225 - * find_name relative to the original file.1.226 - * @return a newly allocated string.1.227 - */1.228 -gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );1.229 +void gdrom_disc_destroy( gdrom_disc_t disc, gboolean close_fh );1.231 gdrom_device_t gdrom_device_new( const gchar *name, const gchar *dev_name );1.233 @@ -230,13 +247,10 @@1.234 void gdrom_extract_raw_data_sector( char *sector_data, int mode, unsigned char *buf, uint32_t *length );1.236 /**1.237 - * Parse a format 2 TOC, and write the results into the supplied disc structure.1.238 + * Check the disc for a useable DC bootstrap, and update the disc1.239 + * with the title accordingly.1.240 + * @return TRUE if we found a bootstrap, otherwise FALSE.1.241 */1.242 -void mmc_parse_toc2( gdrom_image_t disc, unsigned char *buf );1.243 -1.244 -/**1.245 - * Construct a Read CD command for the given sector + mode1.246 - */1.247 -void mmc_make_read_cd_cmd( char *cmd, uint32_t sector, int mode );1.248 +gboolean gdrom_disc_read_title( gdrom_disc_t disc );1.250 #endif /* !lxdream_gddriver_H */
.