filename | src/drivers/cdrom/sector.h |
changeset | 1097:d4807997e450 |
next | 1107:7b279d10f46f |
author | nkeynes |
date | Sun Jan 31 18:35:06 2010 +1000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Refactor CDROM host support - Completely separate GDROM hardware (in gdrom/gdrom.c) from generic CDROM support (now in drivers/cdrom) - Add concept of 'sector sources' that can be mixed and matched to create cdrom discs (makes support of arbitrary disc types much simpler) |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/drivers/cdrom/sector.h Sun Jan 31 18:35:06 2010 +10001.3 @@ -0,0 +1,184 @@1.4 +/**1.5 + * $Id$1.6 + *1.7 + * low-level 'block device' for input to cdrom discs.1.8 + *1.9 + * Copyright (c) 2009 Nathan Keynes.1.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_sector_H1.23 +#define cdrom_sector_H 11.24 +1.25 +#include <stdio.h>1.26 +#include <glib/gtypes.h>1.27 +#include "drivers/cdrom/defs.h"1.28 +1.29 +#ifdef __cplusplus1.30 +extern "C" {1.31 +#endif1.32 +1.33 +/******************************** Sector Source ******************************/1.34 +#define SECTOR_SOURCE_TAG 0x424445561.35 +typedef struct sector_source *sector_source_t;1.36 +typedef enum {1.37 + NULL_SECTOR_SOURCE,1.38 + FILE_SECTOR_SOURCE,1.39 + DISC_SECTOR_SOURCE,1.40 + TRACK_SECTOR_SOURCE1.41 +} sector_source_type_t;1.42 +1.43 +typedef cdrom_error_t (*sector_source_read_fn_t)(sector_source_t, cdrom_lba_t, cdrom_count_t, unsigned char *outbuf);1.44 +typedef cdrom_error_t (*sector_source_read_sectors_fn_t)(sector_source_t, cdrom_lba_t, cdrom_count_t, cdrom_read_mode_t mode,1.45 + unsigned char *outbuf, size_t *length);1.46 +typedef void (*sector_source_destroy_fn_t)(sector_source_t);1.47 +1.48 +/**1.49 + * A 'sector source' is a read-only random-access data source that supports1.50 + * reads of arbitrary blocks within their capacity. A block device has a1.51 + * defined mode, block size, and block count.1.52 + *1.53 + * Source are ref-counted, and automatically destroyed when the reference1.54 + * count reaches 0.1.55 + */1.56 +struct sector_source {1.57 + uint32_t tag; /* sector source tag */1.58 + uint32_t ref_count; /* Reference count. Initialized to 0 */1.59 + sector_source_type_t type;1.60 +1.61 + sector_mode_t mode; /* Implies sector size. */1.62 + uint32_t size; /* Block count */1.63 +1.64 + /**1.65 + * Read blocks from the device using the native block size.1.66 + * @param buf Buffer to receive the blocks1.67 + * @param block First block to transfer (numbered from 0)1.68 + * @param block_count number of blocks to transfer.1.69 + * @return 0 on success, otherwise an error code.1.70 + */1.71 + sector_source_read_fn_t read_blocks;1.72 +1.73 + /**1.74 + * Read sectors from the device using the specified read mode, performing any1.75 + * necessary conversions.1.76 + */1.77 + sector_source_read_sectors_fn_t read_sectors;1.78 +1.79 + /**1.80 + * Release all resources and memory used by the device (note should never1.81 + * be called directly1.82 + */1.83 + sector_source_destroy_fn_t destroy;1.84 +1.85 +};1.86 +1.87 +/**1.88 + * Block device that always returns zeros.1.89 + */1.90 +sector_source_t null_sector_source_new( sector_mode_t mode, cdrom_count_t size );1.91 +1.92 +#define FILE_SECTOR_FULL_FILE ((cdrom_count_t)-1)1.93 +1.94 +/**1.95 + * File reader. Last block is 0-padded.1.96 + */1.97 +sector_source_t file_sector_source_new_filename( const gchar *filename, sector_mode_t mode,1.98 + uint32_t offset, cdrom_count_t sector_count );1.99 +sector_source_t file_sector_source_new( FILE *f, sector_mode_t mode, uint32_t offset, cdrom_count_t sector_count,1.100 + gboolean closeOnDestroy );1.101 +sector_source_t file_sector_source_new_full( FILE *f, sector_mode_t mode, gboolean closeOnDestroy );1.102 +1.103 +/**1.104 + * Construct a file source that shares its file descriptor with another1.105 + * file source.1.106 + */1.107 +sector_source_t file_sector_source_new_source( sector_source_t ref, sector_mode_t mode, uint32_t offset,1.108 + cdrom_count_t sector_count );1.109 +1.110 +/**1.111 + * Change the value of the source's closeOnDestroy flag1.112 + */1.113 +void file_sector_source_set_close_on_destroy( sector_source_t ref, gboolean closeOnDestroy );1.114 +1.115 +/**1.116 + * Retrieve the source's underlying FILE1.117 + */1.118 +FILE *file_sector_source_get_file( sector_source_t ref );1.119 +1.120 +/**1.121 + * Retrieve the source's underlying file descriptor1.122 + */1.123 +int file_sector_source_get_fd( sector_source_t ref );1.124 +1.125 +/**1.126 + * Increment the reference count for a block device.1.127 + */1.128 +void sector_source_ref( sector_source_t device );1.129 +1.130 +/**1.131 + * Unreference a block device. If decremented to 0, the device will be1.132 + * destroyed.1.133 + */1.134 +void sector_source_unref( sector_source_t device );1.135 +1.136 +/**1.137 + * Release an unbound block device. If the ref count is 0, the device is1.138 + * destroyed. Otherwise the function has no effect.1.139 + */1.140 +void sector_source_release( sector_source_t device );1.141 +1.142 +cdrom_error_t sector_source_read( sector_source_t device, cdrom_lba_t lba, cdrom_count_t block_count, unsigned char *buf );1.143 +1.144 +cdrom_error_t sector_source_read_sectors( sector_source_t device, cdrom_lba_t lba, cdrom_count_t block_count,1.145 + cdrom_read_mode_t mode, unsigned char *buf, size_t *length );1.146 +1.147 +/***** Internals for sector source implementations *****/1.148 +1.149 +/**1.150 + * Initialize a new (pre-allocated) sector source1.151 + */1.152 +sector_source_t sector_source_init( sector_source_t device, sector_source_type_t type, sector_mode_t mode, cdrom_count_t size,1.153 + sector_source_read_fn_t readfn, sector_source_destroy_fn_t destroyfn );1.154 +1.155 +/**1.156 + * Default sector source destructor method1.157 + */1.158 +void default_sector_source_destroy( sector_source_t device );1.159 +1.160 +1.161 +/**1.162 + * Extract the necessary fields from a single raw sector for the given read mode.1.163 + * @param raw_sector input raw 2352 byte sector1.164 + * @param mode sector mode and field specification flags1.165 + * @param buf output buffer for sector data1.166 + * @param length output length of sector written to buf1.167 + * @return CDROM_ERROR_OK on success, otherwise an appropriate error code.1.168 + */1.169 +cdrom_error_t sector_extract_from_raw( unsigned char *raw_sector, cdrom_read_mode_t mode, unsigned char *buf, size_t *length );1.170 +1.171 +/**1.172 + * Test if the given pointer is a valid sector source1.173 + */1.174 +#define IS_SECTOR_SOURCE(dev) ((dev) != NULL && ((sector_source_t)(dev))->tag == SECTOR_SOURCE_TAG)1.175 +1.176 + /**1.177 + * Test if the given pointer is a valid sector source of the given type1.178 + */1.179 +#define IS_SECTOR_SOURCE_TYPE(dev,id) (IS_SECTOR_SOURCE(dev) && ((sector_source_t)(dev))->type == id)1.180 +1.181 +1.182 +1.183 +#ifdef __cplusplus1.184 +}1.185 +#endif1.186 +1.187 +#endif /* !cdrom_sector_H */
.