git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / include / formats / cdfs.h
CommitLineData
3719602c
PC
1/* Copyright (C) 2010-2020 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (cdfs.h).
5 * ---------------------------------------------------------------------------------------
6 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
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.
21 */
22
23#ifndef __RARCH_CDFS_H
24#define __RARCH_CDFS_H
25
26#include <streams/interface_stream.h>
27
28RETRO_BEGIN_DECLS
29
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)
32 */
33
34typedef struct cdfs_track_t
35{
36 intfstream_t* stream;
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;
41} cdfs_track_t;
42
43typedef struct cdfs_file_t
44{
45 struct cdfs_track_t* track;
46 int first_sector;
47 int current_sector;
48 int sector_buffer_valid;
49 unsigned int current_sector_offset;
50 unsigned int size;
51 unsigned int pos;
52 uint8_t sector_buffer[2048];
53} cdfs_file_t;
54
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)
59 */
60int cdfs_open_file(cdfs_file_t* file, cdfs_track_t* stream, const char* path);
61
62void cdfs_close_file(cdfs_file_t* file);
63
64int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len);
65
66int64_t cdfs_get_size(cdfs_file_t* file);
67
68int64_t cdfs_tell(cdfs_file_t* file);
69
70int64_t cdfs_seek(cdfs_file_t* file, int64_t offset, int whence);
71
72void cdfs_seek_sector(cdfs_file_t* file, unsigned int sector);
73
74uint32_t cdfs_get_num_sectors(cdfs_file_t* file);
75
76uint32_t cdfs_get_first_sector(cdfs_file_t* file);
77
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.
80 *
81 * supported files:
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
85 *
86 * for bin/cue files, the following storage modes are supported:
87 * MODE2/2352
88 * MODE1/2352
89 * MODE1/2048 - untested
90 * MODE2/2336 - untested
91 */
92cdfs_track_t* cdfs_open_track(const char* path, unsigned int track_index);
93
94/* opens the first data track in a CD or virtual CD file. see cdfs_open_track for supported file formats
95 */
96cdfs_track_t* cdfs_open_data_track(const char* path);
97
98/* opens a raw track file for a CD or virtual CD.
99 *
100 * supported files:
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
105 */
106cdfs_track_t* cdfs_open_raw_track(const char* path);
107
108/* closes the CD or virtual CD track and frees the associated memory */
109void cdfs_close_track(cdfs_track_t* track);
110
111RETRO_END_DECLS
112
113#endif /* __RARCH_CDFS_H */