1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (cdfs.h).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __RARCH_CDFS_H
24 #define __RARCH_CDFS_H
26 #include <streams/interface_stream.h>
30 /* these functions provide an interface for locating and reading files within a data track
31 * of a CD (following the ISO-9660 directory structure definition)
34 typedef struct cdfs_track_t
37 unsigned int stream_sector_size;
38 unsigned int stream_sector_header_size;
39 unsigned int first_sector_offset;
40 unsigned int first_sector_index;
43 typedef struct cdfs_file_t
45 struct cdfs_track_t* track;
48 int sector_buffer_valid;
49 unsigned int current_sector_offset;
52 uint8_t sector_buffer[2048];
55 /* opens the specified file within the CD or virtual CD.
56 * if path is NULL, will open the raw CD (useful for
57 * reading CD without having to worry about sector sizes,
58 * headers, or checksum data)
60 int cdfs_open_file(cdfs_file_t* file, cdfs_track_t* stream, const char* path);
62 void cdfs_close_file(cdfs_file_t* file);
64 int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len);
66 int64_t cdfs_get_size(cdfs_file_t* file);
68 int64_t cdfs_tell(cdfs_file_t* file);
70 int64_t cdfs_seek(cdfs_file_t* file, int64_t offset, int whence);
72 void cdfs_seek_sector(cdfs_file_t* file, unsigned int sector);
74 uint32_t cdfs_get_num_sectors(cdfs_file_t* file);
76 uint32_t cdfs_get_first_sector(cdfs_file_t* file);
78 /* opens the specified track in a CD or virtual CD file - the resulting stream should be passed to
79 * cdfs_open_file to get access to a file within the CD.
82 * real CD - path will be in the form "cdrom://drive1.cue" or "cdrom://d:/drive.cue"
83 * bin/cue - path will point to the cue file
84 * chd - path will point to the chd file
86 * for bin/cue files, the following storage modes are supported:
89 * MODE1/2048 - untested
90 * MODE2/2336 - untested
92 cdfs_track_t* cdfs_open_track(const char* path, unsigned int track_index);
94 /* opens the first data track in a CD or virtual CD file. see cdfs_open_track for supported file formats
96 cdfs_track_t* cdfs_open_data_track(const char* path);
98 /* opens a raw track file for a CD or virtual CD.
101 * real CD - path will be in the form "cdrom://drive1-track01.bin" or "cdrom://d:/drive-track01.bin"
102 * NOTE: cue file for CD must be opened first to populate vfs_cdrom_toc.
103 * bin - path will point to the bin file
104 * iso - path will point to the iso file
106 cdfs_track_t* cdfs_open_raw_track(const char* path);
108 /* closes the CD or virtual CD track and frees the associated memory */
109 void cdfs_close_track(cdfs_track_t* track);
113 #endif /* __RARCH_CDFS_H */