filename | src/drivers/cdrom/cdimpl.h |
changeset | 1097:d4807997e450 |
author | nkeynes |
date | Sat Jan 26 14:00:48 2013 +1000 (11 years ago) |
permissions | -rw-r--r-- |
last change | Change glib includes to #include <glib.h> rather than the individual headers, as recent glib versions are breaking on this |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/drivers/cdrom/cdimpl.h Sat Jan 26 14:00:48 2013 +10001.3 @@ -0,0 +1,199 @@1.4 +/**1.5 + * $Id$1.6 + *1.7 + * Copyright (c) 2009 Nathan Keynes.1.8 + *1.9 + * Internal CD-ROM implementation header1.10 + *1.11 + * This program is free software; you can redistribute it and/or modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.14 + * (at your option) any later version.1.15 + *1.16 + * This program is distributed in the hope that it will be useful,1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.19 + * GNU General Public License for more details.1.20 + */1.21 +1.22 +#ifndef cdrom_cdimpl_H1.23 +#define cdrom_cdimpl_H 11.24 +1.25 +#include "drivers/cdrom/cdrom.h"1.26 +#include "drivers/cdrom/drive.h"1.27 +#include <stdio.h>1.28 +1.29 +#ifdef __cplusplus1.30 +extern "C" {1.31 +#endif1.32 +1.33 +/**1.34 + * Disc factory implementation, to construct cdrom_disc_t objects from a file1.35 + * (if possible).1.36 + */1.37 +typedef struct cdrom_disc_factory {1.38 + /* Human-readable name for the discs constructed by the factory */1.39 + const char *display_name;1.40 + /* Default file extension for supported discs */1.41 + const char *extension;1.42 +1.43 + /* Test if the given file is facially valid for the factory1.44 + * (that is, it passes all file magic etc checks)1.45 + */1.46 + gboolean (*is_valid_file)(FILE *f);1.47 +1.48 + /* Perform any additional initialization needed for the disc type1.49 + * (run after the default initialization). May be NULL if no init1.50 + * is needed1.51 + * @return TRUE on success, FALSE on error.1.52 + */1.53 + gboolean (*init)(cdrom_disc_t disc, ERROR *err);1.54 +1.55 + /* Read the table of contents from the given file, and update the disc1.56 + * accordingly. On error, set the err message and return FALSE.1.57 + */1.58 + gboolean (*read_toc)(cdrom_disc_t disc, ERROR *err);1.59 +1.60 +} *cdrom_disc_factory_t;1.61 +1.62 +/**1.63 + * Low-level SCSI transport provided to the main SCSI/MMC driver. When used1.64 + * this will be set as the disc->impl_data field.1.65 + * Note: For symmetry there should be a packet_write variant, but we don't1.66 + * currently need it for anything. YAGNI, etc.1.67 + */1.68 +typedef struct cdrom_scsi_transport {1.69 + /* Execute a read command (ie a command that returns a block of data in1.70 + * response, not necessarily a CD read).1.71 + * @param disc The disc to execute the command1.72 + * @param cmd The 12-byte command packet1.73 + * @param buf The buffer to receive the read results1.74 + * @param length On entry, the size of buf. Modified on exit to the number1.75 + * of bytes actually read.1.76 + * @return PKT_ERR_OK on success, otherwise the host error code.1.77 + */1.78 + cdrom_error_t (*packet_read)( struct cdrom_disc *disc,1.79 + char *cmd, unsigned char *buf,1.80 + unsigned int *length );1.81 +1.82 + /* Execute a generic command that does not write or return any data.1.83 + * (eg play audio).1.84 + * @param scsi The disc to execute the command1.85 + * @param cmd The 12-byte command packet1.86 + * @return PKT_ERR_OK on success, otherwise the host error code.1.87 + */1.88 + cdrom_error_t (*packet_cmd)( struct cdrom_disc *disc,1.89 + char *cmd );1.90 +1.91 + /* Return TRUE if the media has changed since the last call, otherwise1.92 + * FALSE. This method is used to implement the disc-level check_status1.93 + * and should have no side-effects.1.94 + */1.95 + gboolean (*media_changed)( struct cdrom_disc *disc );1.96 +} *cdrom_scsi_transport_t;1.97 +1.98 +#define SCSI_TRANSPORT(disc) ((cdrom_scsi_transport_t)disc->impl_data)1.99 +1.100 +/**1.101 + * Initialize a previously allocated cdrom_disc_t.1.102 + */1.103 +cdrom_disc_t cdrom_disc_init( cdrom_disc_t disc, const char *filename );1.104 +1.105 +/**1.106 + * Allocate and initialize a new cdrom_disc_t with the defaults for image files1.107 + */1.108 +cdrom_disc_t cdrom_disc_new( const char *name, ERROR *err );1.109 +1.110 +/**1.111 + * Read the table of contents from a scsi disc.1.112 + */1.113 +gboolean cdrom_disc_scsi_read_toc( cdrom_disc_t disc, ERROR *err );1.114 +1.115 +/**1.116 + * Allocate and initialize a new cdrom_disc_t using a scsi transport.1.117 + */1.118 +cdrom_disc_t cdrom_disc_scsi_new( const char *name, cdrom_scsi_transport_t transport, ERROR *err );1.119 +1.120 +/**1.121 + * Allocate and initialize a new cdrom_disc_t using a scsi transport and an1.122 + * open file1.123 + */1.124 +cdrom_disc_t cdrom_disc_scsi_new_file( FILE *f, const char *filename, cdrom_scsi_transport_t transport, ERROR *err );1.125 +1.126 +1.127 +void cdrom_disc_scsi_init( cdrom_disc_t disc, cdrom_scsi_transport_t scsi );1.128 +1.129 +/**1.130 + * Compute derived values for the TOC where they have not already been set1.131 + * - Determine disc leadout from end of the last track1.132 + * - Set the disc type to the based on the track types present.1.133 + */1.134 +void cdrom_disc_finalize_toc( cdrom_disc_t disc );1.135 +1.136 +/**1.137 + * Clear all TOC values in preparation for replacing with a new TOC1.138 + */1.139 +void cdrom_disc_clear_toc( cdrom_disc_t disc );1.140 +1.141 +/**1.142 + * Re-read the table of contents of the disc1.143 + */1.144 +gboolean cdrom_disc_read_toc( cdrom_disc_t disc, ERROR *err );1.145 +1.146 +/**1.147 + * track source for a host CD-ROM device, for use by host implementations1.148 + */1.149 +sector_source_t track_sector_source_new( cdrom_disc_t disc, sector_mode_t mode, cdrom_lba_t lba, cdrom_count_t count );1.150 +1.151 +/**1.152 + * Get the base file used by the cdrom, or NULL if there is no such file.1.153 + */1.154 +FILE *cdrom_disc_get_base_file( cdrom_disc_t disc );1.155 +1.156 +#define cdrom_disc_get_base_fd(disc) fileno(cdrom_disc_get_base_file(disc))1.157 +1.158 +/**1.159 + * Default disc destructor method1.160 + */1.161 +void default_cdrom_disc_destroy( sector_source_t device );1.162 +1.163 +/******************** Physical drive support *********************/1.164 +1.165 +/**1.166 + * Add a physical drive to the list.1.167 + * @return the new cdrom_drive_t entry. If the drive was already in the list,1.168 + * returns the existing entry instead and does not add a new one.1.169 + */1.170 +cdrom_drive_t cdrom_drive_add( const char *name, const char *display_name, cdrom_drive_open_fn_t open_fn );1.171 +1.172 +/**1.173 + * Remove a physical drive from the list, specified by name.1.174 + * @return TRUE if the drive was removed, FALSE if the drive was not in the list.1.175 + */1.176 +gboolean cdrom_drive_remove( const char *name );1.177 +1.178 +/**1.179 + * Clear the cdrom drive list.1.180 + */1.181 +void cdrom_drive_remove_all();1.182 +1.183 +/************************* MMC support ***************************/1.184 +1.185 +/**1.186 + * Parse a standard MMC format-2 TOC into the disc structure.1.187 + */1.188 +void mmc_parse_toc2( cdrom_disc_t disc, unsigned char *buf );1.189 +1.190 +/**1.191 + * Read a standard MMC inquiry response, returning a newly allocated string1.192 + * of the form "<vendor> <product> <revision>"1.193 + */1.194 +const char *mmc_parse_inquiry( unsigned char *buf );1.195 +1.196 +1.197 +1.198 +#ifdef __cplusplus1.199 +}1.200 +#endif1.201 +1.202 +#endif /* !cdrom_cdimpl_H */
.