Skip to content

Commit 47dcf7a

Browse files
committed
Add bdfs driver for when the entire block device = iso
1 parent 207df5b commit 47dcf7a

File tree

9 files changed

+356
-2
lines changed

9 files changed

+356
-2
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ IOPCORE_DEBUG?=0
33

44
all:
55
$(MAKE) -C iop/atad_emu all DEBUG=$(IOPCORE_DEBUG)
6+
$(MAKE) -C iop/bdfs all DEBUG=$(IOPCORE_DEBUG)
67
$(MAKE) -C iop/cdvdfsv all DEBUG=$(IOPCORE_DEBUG)
78
$(MAKE) -C iop/cdvdman_emu all DEBUG=$(IOPCORE_DEBUG)
89
$(MAKE) -C iop/cdvdman_esr1 all DEBUG=$(IOPCORE_DEBUG)
@@ -31,6 +32,7 @@ format:
3132

3233
clean:
3334
$(MAKE) -C iop/atad_emu clean
35+
$(MAKE) -C iop/bdfs clean
3436
$(MAKE) -C iop/cdvdfsv clean
3537
$(MAKE) -C iop/cdvdman_emu clean
3638
$(MAKE) -C iop/cdvdman_esr1 clean

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Options:
5959
6060
-bsdfs=<driver> Backing store fileystem drivers, supported are:
6161
- exfat (default)
62-
- hdl
62+
- hdl (HD Loader)
63+
- bd (Block Device)
6364
6465
-dvd=<mode> DVD emulation mode, supported are:
6566
- no (default)
@@ -110,4 +111,5 @@ Usage examples:
110111
neutrino.elf -bsd=usb -dvd=mass:path/to/filename.iso
111112
neutrino.elf -bsd=ata -dvd=mass:path/to/filename.iso
112113
neutrino.elf -bsd=ata -bsdfs=hdl -dvd=hdl:filename.iso
114+
neutrino.elf -bsd=udpbd -bsdfs=bd -dvd=bdfs:udp0p0
113115
```

ee/loader/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ copy:
143143
rm -rf modules
144144
mkdir -p modules
145145
cp ../../iop/atad_emu/irx/atad_emu.irx modules
146+
cp ../../iop/bdfs/irx/bdfs.irx modules
146147
cp ../../iop/cdvdfsv/irx/cdvdfsv.irx modules
147148
cp ../../iop/cdvdman_emu/irx/cdvdman_emu.irx modules
148149
cp ../../iop/cdvdman_esr1/irx/cdvdman_esr1.irx modules

ee/loader/config/bsdfs-bd.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Name of loaded config, to show to user
2+
name = "Block Device filesystem driver"
3+
4+
# Drivers this driver depends on (config file must exist)
5+
#depends = ["i_bdm"]
6+
7+
# Modules to load in load environment
8+
[[module]]
9+
file = "bdfs.irx"
10+
env = ["LE"]

ee/loader/src/main.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ void print_usage()
7171
printf("\n");
7272
printf(" -bsdfs=<driver> Backing store fileystem drivers, supported are:\n");
7373
printf(" - exfat (default)\n");
74-
printf(" - hdl\n");
74+
printf(" - hdl (HD Loader)\n");
75+
printf(" - bd (Block Device)\n");
7576
printf("\n");
7677
printf(" -dvd=<mode> DVD emulation mode, supported are:\n");
7778
printf(" - no (default)\n");
@@ -122,6 +123,7 @@ void print_usage()
122123
printf(" neutrino.elf -bsd=usb -dvd=mass:path/to/filename.iso\n");
123124
printf(" neutrino.elf -bsd=ata -dvd=mass:path/to/filename.iso\n");
124125
printf(" neutrino.elf -bsd=ata -bsdfs=hdl -dvd=hdl:filename.iso\n");
126+
printf(" neutrino.elf -bsd=udpbd -bsdfs=bd -dvd=bdfs:udp0p0\n");
125127
}
126128

127129
#define MOD_ENV_LE (1<<0)

iop/bdfs/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
IOP_OBJS = bdfs.o imports.o
2+
3+
include ../../Defs.make
4+
include ../Rules.bin.make
5+
include ../Rules.make

iop/bdfs/src/bdfs.c

+302
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
#include <loadcore.h>
2+
#include <iomanX.h>
3+
#include <errno.h>
4+
#include <string.h>
5+
#include <sysclib.h>
6+
#include <stdint.h>
7+
#include <bdm.h>
8+
#include <usbhdfsd-common.h>
9+
#include "mprintf.h"
10+
11+
#define MODNAME "bdfs"
12+
IRX_ID(MODNAME, 1, 1);
13+
14+
uint64_t file_offset = 0;
15+
uint64_t file_size = 0;
16+
struct block_device *bd = NULL;
17+
18+
int bdfs_init(iomanX_iop_device_t *d)
19+
{
20+
M_DEBUG("%s()\n", __FUNCTION__);
21+
// Return succes
22+
return 0;
23+
}
24+
int bdfs_deinit(iomanX_iop_device_t *d)
25+
{
26+
M_DEBUG("%s()\n", __FUNCTION__);
27+
return 0;
28+
}
29+
int bdfs_format(iomanX_iop_file_t *f, const char *unk1, const char *unk2, void *unk3, int unk4)
30+
{
31+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
32+
return -EIO;
33+
}
34+
int bdfs_open(iomanX_iop_file_t *f, const char *name, int mode, int unk)
35+
{
36+
struct block_device *pbd[10];
37+
char bdname[10];
38+
int i;
39+
40+
M_DEBUG("%s(%s, 0x%x)\n", __FUNCTION__, name, mode);
41+
42+
while (name[0] == '/' || name[0] == '\\') {
43+
M_DEBUG("ignoring leading '/'\n");
44+
name++;
45+
}
46+
47+
file_offset = 0;
48+
file_size = 0;
49+
bd = NULL;
50+
51+
bdm_get_bd(pbd, 10);
52+
for (i = 0; i < 10; i++) {
53+
sprintf(bdname, "%s%dp%d", pbd[i]->name, pbd[i]->devNr, pbd[i]->parNr);
54+
M_DEBUG("- BD[%d] = %s\n", i, bdname);
55+
if (strcmp(bdname, name) == 0) {
56+
bd = pbd[i];
57+
file_size = pbd[i]->sectorCount * 512;
58+
return 1; // the 1 and only file descriptor, for now...
59+
}
60+
}
61+
62+
return -EIO;
63+
}
64+
int bdfs_close(iomanX_iop_file_t *f)
65+
{
66+
M_DEBUG("%s()\n", __FUNCTION__);
67+
return 0;
68+
}
69+
70+
u8 sector_buffer[512];
71+
int bdfs_read(iomanX_iop_file_t *f, void *buffer, int size)
72+
{
73+
M_DEBUG("%s(0x%x, %d)\n", __FUNCTION__, buffer, size);
74+
75+
int size_left = size;
76+
while (size_left > 0) {
77+
unsigned int file_sector = file_offset / 512;
78+
unsigned int file_sector_offset = file_offset & 511;
79+
int size_read = size_left;
80+
81+
if (size_read > (512 - file_sector_offset))
82+
size_read = 512 - file_sector_offset;
83+
84+
M_DEBUG("reading %d bytes from lba %d, offset %d\n", size_read, file_sector, file_sector_offset);
85+
86+
if (size_read == 512) {
87+
// Read whole sector
88+
if (bd->read(bd, file_sector, buffer, 1) != 1)
89+
return -EIO;
90+
}
91+
else {
92+
// Read part of sector via bounce buffer
93+
if (bd->read(bd, file_sector, sector_buffer, 1) != 1)
94+
return -EIO;
95+
memcpy(buffer, sector_buffer + file_sector_offset, size_read);
96+
}
97+
98+
buffer += size_read;
99+
size_left -= size_read;
100+
file_offset += size_read;
101+
}
102+
return size;
103+
}
104+
int bdfs_write(iomanX_iop_file_t *f, void *buffer, int size)
105+
{
106+
M_DEBUG("%s(0x%x, %d) - not supported\n", __FUNCTION__, buffer, size);
107+
return -EIO;
108+
}
109+
s64 bdfs_lseek64(iomanX_iop_file_t *, s64 offset, int whence);
110+
int bdfs_lseek(iomanX_iop_file_t *f, int offset, int whence)
111+
{
112+
M_DEBUG("%s(%d, %d)\n", __FUNCTION__, offset, whence);
113+
return bdfs_lseek64(f, offset, whence);
114+
}
115+
int bdfs_ioctl(iomanX_iop_file_t *f, int, void *)
116+
{
117+
M_DEBUG("%s()\n", __FUNCTION__);
118+
return -EIO;
119+
}
120+
int bdfs_remove(iomanX_iop_file_t *f, const char *)
121+
{
122+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
123+
return -EIO;
124+
}
125+
int bdfs_mkdir(iomanX_iop_file_t *f, const char *path, int unk)
126+
{
127+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
128+
return -EIO;
129+
}
130+
int bdfs_rmdir(iomanX_iop_file_t *f, const char *path)
131+
{
132+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
133+
return -EIO;
134+
}
135+
int bdfs_dopen(iomanX_iop_file_t *f, const char *path)
136+
{
137+
M_DEBUG("%s()\n", __FUNCTION__);
138+
return -EIO;
139+
}
140+
int bdfs_dclose(iomanX_iop_file_t *f)
141+
{
142+
M_DEBUG("%s()\n", __FUNCTION__);
143+
return -EIO;
144+
}
145+
int bdfs_dread(iomanX_iop_file_t *f, iox_dirent_t *dirent)
146+
{
147+
M_DEBUG("%s()\n", __FUNCTION__);
148+
return -EIO;
149+
}
150+
int bdfs_getstat(iomanX_iop_file_t *f, const char *name, iox_stat_t *stat)
151+
{
152+
M_DEBUG("%s()\n", __FUNCTION__);
153+
return -EIO;
154+
}
155+
int bdfs_chstat(iomanX_iop_file_t *f, const char *name, iox_stat_t *stat, unsigned int)
156+
{
157+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
158+
return -EIO;
159+
}
160+
/* Extended ops start here. */
161+
int bdfs_rename(iomanX_iop_file_t *, const char *, const char *)
162+
{
163+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
164+
return -EIO;
165+
}
166+
int bdfs_chdir(iomanX_iop_file_t *, const char *)
167+
{
168+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
169+
return -EIO;
170+
}
171+
int bdfs_sync(iomanX_iop_file_t *, const char *, int)
172+
{
173+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
174+
return -EIO;
175+
}
176+
int bdfs_mount(iomanX_iop_file_t *, const char *, const char *, int, void *, int)
177+
{
178+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
179+
return -EIO;
180+
}
181+
int bdfs_umount(iomanX_iop_file_t *, const char *)
182+
{
183+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
184+
return -EIO;
185+
}
186+
s64 bdfs_lseek64(iomanX_iop_file_t *, s64 offset, int whence)
187+
{
188+
M_DEBUG("%s(%d, %d)\n", __FUNCTION__, offset, whence);
189+
190+
switch (whence) {
191+
case SEEK_SET: file_offset = offset; break;
192+
case SEEK_CUR: file_offset += offset; break;
193+
case SEEK_END: file_offset = file_size + offset; break;
194+
default:
195+
return -1;
196+
}
197+
198+
return file_offset;
199+
}
200+
int bdfs_devctl(iomanX_iop_file_t *, const char *, int, void *, unsigned int, void *, unsigned int)
201+
{
202+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
203+
return -EIO;
204+
}
205+
int bdfs_symlink(iomanX_iop_file_t *, const char *, const char *)
206+
{
207+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
208+
return -EIO;
209+
}
210+
int bdfs_readlink(iomanX_iop_file_t *, const char *, char *, unsigned int)
211+
{
212+
M_DEBUG("%s() - not supported\n", __FUNCTION__);
213+
return -EIO;
214+
}
215+
int bdfs_ioctl2(iomanX_iop_file_t *, int cmd, void *data, unsigned int datalen, void *rdata, unsigned int rdatalen)
216+
{
217+
int ret = -EINVAL;
218+
219+
M_DEBUG("%s(%d)\n", __FUNCTION__, cmd);
220+
221+
switch (cmd) {
222+
case USBMASS_IOCTL_GET_DRIVERNAME:
223+
ret = *(int *)bd->name;
224+
break;
225+
case USBMASS_IOCTL_GET_FRAGLIST:
226+
// Check for a return buffer and copy the device number. If no buffer is provided return an error.
227+
if (rdata == NULL || rdatalen < sizeof(bd_fragment_t))
228+
{
229+
ret = -EINVAL;
230+
break;
231+
}
232+
// Block device always has 1 fragment
233+
{
234+
bd_fragment_t *f = (bd_fragment_t*)rdata;
235+
f[0].sector = bd->sectorOffset;
236+
f[0].count = bd->sectorCount;
237+
}
238+
ret = 1;
239+
break;
240+
case USBMASS_IOCTL_GET_DEVICE_NUMBER:
241+
{
242+
// Check for a return buffer and copy the device number. If no buffer is provided return an error.
243+
if (rdata == NULL || rdatalen < sizeof(u32))
244+
{
245+
ret = -EINVAL;
246+
break;
247+
}
248+
*(u32*)rdata = bd->devNr;
249+
ret = 0;
250+
break;
251+
}
252+
}
253+
254+
return ret;
255+
}
256+
257+
iomanX_iop_device_ops_t bdfs_device_ops = {
258+
bdfs_init,
259+
bdfs_deinit,
260+
bdfs_format,
261+
bdfs_open,
262+
bdfs_close,
263+
bdfs_read,
264+
bdfs_write,
265+
bdfs_lseek,
266+
bdfs_ioctl,
267+
bdfs_remove,
268+
bdfs_mkdir,
269+
bdfs_rmdir,
270+
bdfs_dopen,
271+
bdfs_dclose,
272+
bdfs_dread,
273+
bdfs_getstat,
274+
bdfs_chstat,
275+
bdfs_rename,
276+
bdfs_chdir,
277+
bdfs_sync,
278+
bdfs_mount,
279+
bdfs_umount,
280+
bdfs_lseek64,
281+
bdfs_devctl,
282+
bdfs_symlink,
283+
bdfs_readlink,
284+
bdfs_ioctl2
285+
};
286+
287+
const char bdfs_fs_name[] = "bdfs";
288+
iomanX_iop_device_t bdfs_device = {
289+
bdfs_fs_name,
290+
IOP_DT_FSEXT | IOP_DT_FS,
291+
1,
292+
bdfs_fs_name,
293+
&bdfs_device_ops};
294+
295+
int _start(int argc, char *argv[])
296+
{
297+
M_DEBUG("Block Device read-only filesystem driver\n");
298+
299+
AddDrv(&bdfs_device);
300+
301+
return MODULE_RESIDENT_END;
302+
}

iop/bdfs/src/imports.lst

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
bdm_IMPORTS_start
2+
I_bdm_get_bd
3+
bdm_IMPORTS_end
4+
5+
iomanX_IMPORTS_start
6+
I_AddDrv
7+
iomanX_IMPORTS_end
8+
9+
#ifdef DEBUG
10+
stdio_IMPORTS_start
11+
I_printf
12+
stdio_IMPORTS_end
13+
#endif
14+
15+
sysclib_IMPORTS_start
16+
I_sprintf
17+
I_memcpy
18+
I_strcmp
19+
sysclib_IMPORTS_end

0 commit comments

Comments
 (0)