PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
cddrv.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "accdvd_internal.h"
12
13static int cddrv_adddrv(iop_device_t *drv);
14static int cddrv_deldrv(iop_device_t *drv);
15static int cddrv_open(iop_file_t *io, const char *name, int flg);
16static int cddrv_close(iop_file_t *io);
17static int cddrv_read(iop_file_t *io, void *buf, int cnt);
18static int cddrv_write(iop_file_t *io, void *buf, int cnt);
19static int cddrv_lseek(iop_file_t *io, int offset, int whence);
20static int cddrv_ioctl(iop_file_t *io, int cmd, void *arg);
21
22IOMAN_RETURN_VALUE_IMPL(EINVAL);
23
24static iop_device_ops_t Cddrv_ops = {
25 &cddrv_adddrv, // init
26 &cddrv_deldrv, // deinit
27 IOMAN_RETURN_VALUE(EINVAL), // format
28 &cddrv_open, // open
29 &cddrv_close, // close
30 &cddrv_read, // read
31 &cddrv_write, // write
32 &cddrv_lseek, // lseek
33 &cddrv_ioctl, // ioctl
34 IOMAN_RETURN_VALUE(EINVAL), // remove
35 IOMAN_RETURN_VALUE(EINVAL), // mkdir
36 IOMAN_RETURN_VALUE(EINVAL), // rmdir
37 IOMAN_RETURN_VALUE(EINVAL), // dopen
38 IOMAN_RETURN_VALUE(EINVAL), // dclose
39 IOMAN_RETURN_VALUE(EINVAL), // dread
40 IOMAN_RETURN_VALUE(EINVAL), // getstat
41 IOMAN_RETURN_VALUE(EINVAL), // chstat
42};
43
44static iop_device_t Cddrv = {"cdrom", 16u, 0u, "ATAPI_C/DVD-ROM", &Cddrv_ops};
45
46static int cddrv_adddrv(iop_device_t *drv)
47{
48 (void)drv;
49
50 return 0;
51}
52
53static int cddrv_deldrv(iop_device_t *drv)
54{
55 (void)drv;
56
57 return 0;
58}
59
60static int cddrv_open(iop_file_t *io, const char *name, int flg)
61{
62 int ret;
63 struct cdfs_file *v9;
64 struct cdfs_file *file;
65 acUint32 d_size;
66 struct cdfs_dirent dirent;
67
68 ret = 1;
69 while ( ret > 0 )
70 {
71 int ret_v2;
72
73 if ( io->unit )
74 {
75 return -ENXIO;
76 }
77 if ( flg != 1 )
78 {
79 return -EINVAL;
80 }
81 ret_v2 = cdfs_lookup(&dirent, name, strlen(name));
82 if ( ret_v2 >= 0 )
83 {
84 break;
85 }
86 ret = cdfs_recover(ret_v2);
87 }
88 if ( (dirent.d_ftype & 2) != 0 )
89 {
90 return -EISDIR;
91 }
92 v9 = (struct cdfs_file *)AllocSysMemory(1, 16, 0);
93 file = v9;
94 if ( !v9 )
95 {
96 return -ENOMEM;
97 }
98 io->privdata = v9;
99 v9->f_lsn = dirent.d_lsn;
100 d_size = dirent.d_size;
101 file->f_pos = 0;
102 file->f_size = d_size;
103 return 0;
104}
105
106static int cddrv_close(iop_file_t *io)
107{
108 void *ptr;
109
110 ptr = io->privdata;
111 io->privdata = 0;
112 if ( ptr )
113 FreeSysMemory(ptr);
114 return 0;
115}
116
117static int cddrv_read(iop_file_t *io, void *buf, int cnt)
118{
119 if ( !buf || !cnt )
120 return 0;
121 return cdfs_read((struct cdfs_file *)io->privdata, buf, cnt);
122}
123
124static int cddrv_write(iop_file_t *io, void *buf, int cnt)
125{
126 (void)io;
127 (void)buf;
128 (void)cnt;
129
130 return -EROFS;
131}
132
133static int cddrv_lseek(iop_file_t *io, int offset, int whence)
134{
135 struct cdfs_file *file;
136 acUint32 size;
137
138 file = (struct cdfs_file *)io->privdata;
139 size = file->f_size;
140 if ( whence == 1 )
141 {
142 offset += file->f_pos;
143 }
144 else if ( whence == 2 )
145 {
146 offset += size;
147 }
148 if ( size < (unsigned int)offset )
149 offset = file->f_size;
150 file->f_pos = offset;
151 return offset;
152}
153
154static int cddrv_ioctl(iop_file_t *io, int cmd, void *arg)
155{
156 (void)io;
157 (void)cmd;
158 (void)arg;
159
160 return -EINVAL;
161}
162
163int cddrv_module_start(int argc, char **argv)
164{
165 int v2;
166 int v3;
167
168 (void)argc;
169 (void)argv;
170 v2 = AddDrv(&Cddrv);
171 v3 = 0;
172 if ( v2 < 0 )
173 return -16;
174 return v3;
175}
176
177int cddrv_module_stop()
178{
179 int v0;
180 int v1;
181
182 v0 = DelDrv(Cddrv.name);
183 v1 = 0;
184 if ( v0 < 0 )
185 return -16;
186 return v1;
187}
188
189int cddrv_module_restart(int argc, char **argv)
190{
191 (void)argc;
192 (void)argv;
193
194 return -88;
195}
196
197int cddrv_module_status()
198{
199 return 0;
200}
#define ENXIO
Definition errno.h:31
#define EINVAL
Definition errno.h:63
#define ENOMEM
Definition errno.h:43
#define EROFS
Definition errno.h:79
#define EISDIR
Definition errno.h:61
void * privdata
Definition ioman.h:61
int unit
Definition ioman.h:57