sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
main.c
1#include <kernel.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
5
6#include <sifrpc.h>
7#include <loadfile.h>
8#include <sbv_patches.h>
9
10#define NEWLIB_PORT_AWARE
11#include <fileXio_rpc.h>
12#include <io_common.h>
13
14#include "iomanx_irx.h"
15#include "filexio_irx.h"
16#include "bdm_irx.h"
17#include "bdmfs_fatfs_irx.h"
18#include "ramdisk_bd_irx.h"
19
20extern int kputs(char *s);
21
22static int failures;
23
24static void expect(const char *name, int ok)
25{
26 printf("driver-blockdev: [%s] %s\n", ok ? "PASS" : "FAIL", name);
27 if (!ok)
28 failures++;
29}
30
31static int load(const char *name, void *buf, unsigned int size)
32{
33 int ret = -1;
34 int id = SifExecModuleBuffer(buf, size, 0, NULL, &ret);
35
36 printf("driver-blockdev: %s id=%d ret=%d\n", name, id, ret);
37 return id > 0 && ret != 1;
38}
39
40static int mounted(const char *path)
41{
42 int fd = fileXioDopen(path);
43
44 if (fd < 0)
45 return 0;
46 fileXioDclose(fd);
47 return 1;
48}
49
50static int read_file(const char *path, char *buf, int size)
51{
52 int fd = fileXioOpen(path, FIO_O_RDONLY);
53 int n;
54
55 if (fd < 0)
56 return fd;
57 n = fileXioRead(fd, buf, size - 1);
58 fileXioClose(fd);
59 if (n >= 0)
60 buf[n] = '\0';
61 return n;
62}
63
64int main(void)
65{
66 static const char hello[] = "hello from the ramdisk\n";
67 static const char note[] = "written by the EE through fileXio\n";
68 char buf[128];
69 int fd, n;
70
71 SifInitRpc(0);
74 load("iomanx", iomanx_irx, size_iomanx_irx);
75 load("filexio", filexio_irx, size_filexio_irx);
76 fileXioInit();
77 load("bdm", bdm_irx, size_bdm_irx);
78 load("bdmfs_fatfs", bdmfs_fatfs_irx, size_bdmfs_fatfs_irx);
79 expect("ramdisk_bd loads and stays resident", load("ramdisk_bd", ramdisk_bd_irx, size_ramdisk_bd_irx));
80
81 for (int i = 0; i < 50 && !mounted("ram0:/"); i++)
82 usleep(100 * 1000);
83 expect("ram0: mounted", mounted("ram0:/"));
84
85 n = read_file("ram0:/HELLO.TXT", buf, sizeof(buf));
86 printf("driver-blockdev: HELLO.TXT read=%d\n", n);
87 expect("HELLO.TXT holds the seeded text", n == (int)strlen(hello) && strcmp(buf, hello) == 0);
88
89 fd = fileXioOpen("ram0:/NOTE.TXT", FIO_O_WRONLY | FIO_O_CREAT | FIO_O_TRUNC, 0666);
90 n = fd >= 0 ? fileXioWrite(fd, (void *)note, strlen(note)) : fd;
91 if (fd >= 0)
92 fileXioClose(fd);
93 expect("NOTE.TXT written", n == (int)strlen(note));
94
95 n = read_file("ram0:/NOTE.TXT", buf, sizeof(buf));
96 expect("NOTE.TXT reads back the same bytes", n == (int)strlen(note) && strcmp(buf, note) == 0);
97
98 n = read_file("ram0:/MISSING.TXT", buf, sizeof(buf));
99 expect("a missing file fails to open", n < 0);
100
101 kputs(failures ? "driver-blockdev: FAIL\n" : "driver-blockdev: PASS\n");
102 printf("[ps2rig] exit=%d\n", failures ? 1 : 0);
103 SleepThread();
104 return 0;
105}
int SifExecModuleBuffer(void *ptr, u32 size, u32 arg_len, const char *args, int *mod_res)
Definition loadfile.c:314
int sbv_patch_disable_prefix_check(void)
int sbv_patch_enable_lmb(void)