Search
lxdream.org :: lxdream/src/drivers/cdrom/cdimpl.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/cdrom/cdimpl.h
changeset 1097:d4807997e450
author nkeynes
date Thu Feb 23 14:59:58 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change mem_stream_class should be static (to avoid potential conflicts with the
real one)
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Copyright (c) 2009 Nathan Keynes.
     5  *
     6  * Internal CD-ROM implementation header
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program 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
    16  * GNU General Public License for more details.
    17  */
    19 #ifndef cdrom_cdimpl_H
    20 #define cdrom_cdimpl_H 1
    22 #include "drivers/cdrom/cdrom.h"
    23 #include "drivers/cdrom/drive.h"
    24 #include <stdio.h>
    26 #ifdef __cplusplus
    27 extern "C" {
    28 #endif
    30 /**
    31  * Disc factory implementation, to construct cdrom_disc_t objects from a file
    32  * (if possible).
    33  */
    34 typedef struct cdrom_disc_factory {
    35     /* Human-readable name for the discs constructed by the factory */
    36     const char *display_name;
    37     /* Default file extension for supported discs */
    38     const char *extension;
    40     /* Test if the given file is facially valid for the factory
    41      * (that is, it passes all file magic etc checks)
    42      */
    43     gboolean (*is_valid_file)(FILE *f);
    45     /* Perform any additional initialization needed for the disc type
    46      * (run after the default initialization). May be NULL if no init
    47      * is needed
    48      * @return TRUE on success, FALSE on error.
    49      */ 
    50     gboolean (*init)(cdrom_disc_t disc, ERROR *err);
    52     /* Read the table of contents from the given file, and update the disc
    53      * accordingly. On error, set the err message and return FALSE.
    54      */
    55     gboolean (*read_toc)(cdrom_disc_t disc, ERROR *err);
    57 } *cdrom_disc_factory_t;
    59 /**
    60  * Low-level SCSI transport provided to the main SCSI/MMC driver. When used
    61  * this will be set as the disc->impl_data field.
    62  * Note: For symmetry there should be a packet_write variant, but we don't
    63  * currently need it for anything. YAGNI, etc.
    64  */
    65 typedef struct cdrom_scsi_transport {
    66         /* Execute a read command (ie a command that returns a block of data in
    67          * response, not necessarily a CD read).
    68          * @param disc The disc to execute the command
    69          * @param cmd  The 12-byte command packet
    70          * @param buf  The buffer to receive the read results
    71          * @param length On entry, the size of buf. Modified on exit to the number
    72          *        of bytes actually read.
    73          * @return PKT_ERR_OK on success, otherwise the host error code.
    74          */
    75         cdrom_error_t (*packet_read)( struct cdrom_disc *disc,
    76                                       char *cmd, unsigned char *buf,
    77                                       unsigned int *length );
    79         /* Execute a generic command that does not write or return any data.
    80          * (eg play audio).
    81          * @param scsi The disc to execute the command
    82          * @param cmd  The 12-byte command packet
    83          * @return PKT_ERR_OK on success, otherwise the host error code.
    84          */
    85         cdrom_error_t (*packet_cmd)( struct cdrom_disc *disc,
    86                                      char *cmd );
    88         /* Return TRUE if the media has changed since the last call, otherwise
    89          * FALSE. This method is used to implement the disc-level check_status
    90          * and should have no side-effects.
    91          */
    92         gboolean (*media_changed)( struct cdrom_disc *disc );
    93 } *cdrom_scsi_transport_t;
    95 #define SCSI_TRANSPORT(disc)  ((cdrom_scsi_transport_t)disc->impl_data)
    97 /**
    98  * Initialize a previously allocated cdrom_disc_t.
    99  */
   100 cdrom_disc_t cdrom_disc_init( cdrom_disc_t disc, const char *filename );
   102 /**
   103  * Allocate and initialize a new cdrom_disc_t with the defaults for image files
   104  */
   105 cdrom_disc_t cdrom_disc_new( const char *name, ERROR *err );
   107 /**
   108  * Read the table of contents from a scsi disc.
   109  */
   110 gboolean cdrom_disc_scsi_read_toc( cdrom_disc_t disc, ERROR *err );
   112 /**
   113  * Allocate and initialize a new cdrom_disc_t using a scsi transport.
   114  */
   115 cdrom_disc_t cdrom_disc_scsi_new( const char *name, cdrom_scsi_transport_t transport, ERROR *err );
   117 /**
   118  * Allocate and initialize a new cdrom_disc_t using a scsi transport and an
   119  * open file
   120  */
   121 cdrom_disc_t cdrom_disc_scsi_new_file( FILE *f, const char *filename, cdrom_scsi_transport_t transport, ERROR *err );
   124 void cdrom_disc_scsi_init( cdrom_disc_t disc, cdrom_scsi_transport_t scsi );
   126 /**
   127  * Compute derived values for the TOC where they have not already been set
   128  *   - Determine disc leadout from end of the last track
   129  *   - Set the disc type to the based on the track types present.
   130  */
   131 void cdrom_disc_finalize_toc( cdrom_disc_t disc );
   133 /**
   134  * Clear all TOC values in preparation for replacing with a new TOC
   135  */
   136 void cdrom_disc_clear_toc( cdrom_disc_t disc );
   138 /**
   139  * Re-read the table of contents of the disc
   140  */
   141 gboolean cdrom_disc_read_toc( cdrom_disc_t disc, ERROR *err );
   143 /**
   144  * track source for a host CD-ROM device, for use by host implementations
   145  */
   146 sector_source_t track_sector_source_new( cdrom_disc_t disc, sector_mode_t mode, cdrom_lba_t lba, cdrom_count_t count );
   148 /**
   149  * Get the base file used by the cdrom, or NULL if there is no such file.
   150  */
   151 FILE *cdrom_disc_get_base_file( cdrom_disc_t disc );
   153 #define cdrom_disc_get_base_fd(disc) fileno(cdrom_disc_get_base_file(disc))
   155 /**
   156  * Default disc destructor method
   157  */
   158 void default_cdrom_disc_destroy( sector_source_t device );
   160 /******************** Physical drive support *********************/
   162 /**
   163  * Add a physical drive to the list.
   164  * @return the new cdrom_drive_t entry. If the drive was already in the list,
   165  * returns the existing entry instead and does not add a new one.
   166  */
   167 cdrom_drive_t cdrom_drive_add( const char *name, const char *display_name, cdrom_drive_open_fn_t open_fn );
   169 /**
   170  * Remove a physical drive from the list, specified by name.
   171  * @return TRUE if the drive was removed, FALSE if the drive was not in the list.
   172  */
   173 gboolean cdrom_drive_remove( const char *name );
   175 /**
   176  * Clear the cdrom drive list.
   177  */
   178 void cdrom_drive_remove_all();
   180 /************************* MMC support ***************************/
   182 /**
   183  * Parse a standard MMC format-2 TOC into the disc structure.
   184  */
   185 void mmc_parse_toc2( cdrom_disc_t disc, unsigned char *buf );
   187 /**
   188  * Read a standard MMC inquiry response, returning a newly allocated string
   189  * of the form "<vendor> <product> <revision>"
   190  */
   191 const char *mmc_parse_inquiry( unsigned char *buf );
   195 #ifdef __cplusplus
   196 }
   197 #endif
   199 #endif /* !cdrom_cdimpl_H */
.