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);
21static int cddrv_dummy();
22
23static iop_device_ops_t Cddrv_ops = {
24 &cddrv_adddrv,
25 &cddrv_deldrv,
26 &cddrv_dummy,
27 &cddrv_open,
28 &cddrv_close,
29 &cddrv_read,
30 &cddrv_write,
31 &cddrv_lseek,
32 &cddrv_ioctl,
33 &cddrv_dummy,
34 &cddrv_dummy,
35 &cddrv_dummy,
36 &cddrv_dummy,
37 &cddrv_dummy,
38 &cddrv_dummy,
39 &cddrv_dummy,
40 &cddrv_dummy};
41
42static iop_device_t Cddrv = {"cdrom", 16u, 0u, "ATAPI_C/DVD-ROM", &Cddrv_ops};
43
44static int cddrv_adddrv(iop_device_t *drv)
45{
46 (void)drv;
47
48 return 0;
49}
50
51static int cddrv_deldrv(iop_device_t *drv)
52{
53 (void)drv;
54
55 return 0;
56}
57
58static int cddrv_open(iop_file_t *io, const char *name, int flg)
59{
60 int ret;
61 struct cdfs_file *v9;
62 struct cdfs_file *file;
63 acUint32 d_size;
64 struct cdfs_dirent dirent;
65
66 ret = 1;
67 while ( ret > 0 )
68 {
69 int ret_v2;
70
71 if ( io->unit )
72 {
73 return -ENXIO;
74 }
75 if ( flg != 1 )
76 {
77 return -EINVAL;
78 }
79 ret_v2 = cdfs_lookup(&dirent, name, strlen(name));
80 if ( ret_v2 >= 0 )
81 {
82 break;
83 }
84 ret = cdfs_recover(ret_v2);
85 }
86 if ( (dirent.d_ftype & 2) != 0 )
87 {
88 return -EISDIR;
89 }
90 v9 = (struct cdfs_file *)AllocSysMemory(1, 16, 0);
91 file = v9;
92 if ( !v9 )
93 {
94 return -ENOMEM;
95 }
96 io->privdata = v9;
97 v9->f_lsn = dirent.d_lsn;
98 d_size = dirent.d_size;
99 file->f_pos = 0;
100 file->f_size = d_size;
101 return 0;
102}
103
104static int cddrv_close(iop_file_t *io)
105{
106 void *ptr;
107
108 ptr = io->privdata;
109 io->privdata = 0;
110 if ( ptr )
111 FreeSysMemory(ptr);
112 return 0;
113}
114
115static int cddrv_read(iop_file_t *io, void *buf, int cnt)
116{
117 if ( !buf || !cnt )
118 return 0;
119 return cdfs_read((struct cdfs_file *)io->privdata, buf, cnt);
120}
121
122static int cddrv_write(iop_file_t *io, void *buf, int cnt)
123{
124 (void)io;
125 (void)buf;
126 (void)cnt;
127
128 return -EROFS;
129}
130
131static int cddrv_lseek(iop_file_t *io, int offset, int whence)
132{
133 struct cdfs_file *file;
134 acUint32 size;
135
136 file = (struct cdfs_file *)io->privdata;
137 size = file->f_size;
138 if ( whence == 1 )
139 {
140 offset += file->f_pos;
141 }
142 else if ( whence == 2 )
143 {
144 offset += size;
145 }
146 if ( size < (unsigned int)offset )
147 offset = file->f_size;
148 file->f_pos = offset;
149 return offset;
150}
151
152static int cddrv_ioctl(iop_file_t *io, int cmd, void *arg)
153{
154 (void)io;
155 (void)cmd;
156 (void)arg;
157
158 return -EINVAL;
159}
160
161static int cddrv_dummy()
162{
163 return -EINVAL;
164}
165
166int cddrv_module_start(int argc, char **argv)
167{
168 int v2;
169 int v3;
170
171 (void)argc;
172 (void)argv;
173 v2 = AddDrv(&Cddrv);
174 v3 = 0;
175 if ( v2 < 0 )
176 return -16;
177 return v3;
178}
179
180int cddrv_module_stop()
181{
182 int v0;
183 int v1;
184
185 v0 = DelDrv(Cddrv.name);
186 v1 = 0;
187 if ( v0 < 0 )
188 return -16;
189 return v1;
190}
191
192int cddrv_module_restart(int argc, char **argv)
193{
194 (void)argc;
195 (void)argv;
196
197 return -88;
198}
199
200int cddrv_module_status()
201{
202 return 0;
203}
#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