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 <stdint.h>
5#include <unistd.h>
6
7#include <sifrpc.h>
8#include <loadfile.h>
9#include <iopcontrol.h>
10#include <sbv_patches.h>
11
12#define NEWLIB_PORT_AWARE
13#include <fileXio_rpc.h>
14
15#include "iomanx_irx.h"
16#include "filexio_irx.h"
17#include "usbd_irx.h"
18#include "bdm_irx.h"
19#include "bdmfs_fatfs_irx.h"
20#include "usbmass_bd_irx.h"
21
22#define DEVCTL_STOP_UNIT 0x0000
23#define DEVCTL_STOP_ALL 0x0001
24#define DEVCTL_GET_SECTOR_SIZE 0x0002
25#define DEVCTL_GET_TOTAL_SIZE 0x0003
26#define DEVCTL_GET_FREE_SIZE 0x0004
27
28extern int kputs(char *s);
29
30static int failures;
31
32static void expect(const char *name, int ok)
33{
34 printf("devctl-test: [%s] %s\n", ok ? "PASS" : "FAIL", name);
35 if (!ok)
36 failures++;
37}
38
39static void load(const char *name, void *buf, unsigned int size)
40{
41 int ret = -1;
42 int id = SifExecModuleBuffer(buf, size, 0, NULL, &ret);
43
44 printf("devctl-test: %s id=%d ret=%d\n", name, id, ret);
45}
46
47static int mounted(const char *path)
48{
49 int fd = fileXioDopen(path);
50
51 if (fd < 0)
52 return 0;
53 fileXioDclose(fd);
54 return 1;
55}
56
57int main(void)
58{
59 uint32_t sector = 0;
60 uint64_t total = 0, free_bytes = 0;
61 int ret;
62
63 SifInitRpc(0);
66 load("iomanx", iomanx_irx, size_iomanx_irx);
67 load("filexio", filexio_irx, size_filexio_irx);
68 fileXioInit();
69 load("usbd", usbd_irx, size_usbd_irx);
70 load("bdm", bdm_irx, size_bdm_irx);
71 load("bdmfs_fatfs", bdmfs_fatfs_irx, size_bdmfs_fatfs_irx);
72 load("usbmass_bd", usbmass_bd_irx, size_usbmass_bd_irx);
73
74 for (int i = 0; i < 100 && !mounted("mass0:/"); i++)
75 usleep(100 * 1000);
76 expect("mass0: mounted", mounted("mass0:/"));
77
78 ret = fileXioDevctl("mass0:", DEVCTL_GET_SECTOR_SIZE, NULL, 0, &sector, sizeof(sector));
79 printf("devctl-test: sector size ret=%d value=%u\n", ret, (unsigned)sector);
80 expect("sector size is 512", ret == 0 && sector == 512);
81
82 ret = fileXioDevctl("mass0:", DEVCTL_GET_TOTAL_SIZE, NULL, 0, &total, sizeof(total));
83 printf("devctl-test: total ret=%d bytes=%u (%u MiB)\n", ret, (unsigned)total, (unsigned)(total >> 20));
84 expect("total size is a non-zero multiple of 512", ret == 0 && total > 0 && total % 512 == 0);
85
86 ret = fileXioDevctl("mass0:", DEVCTL_GET_FREE_SIZE, NULL, 0, &free_bytes, sizeof(free_bytes));
87 printf("devctl-test: free ret=%d bytes=%u (%u MiB)\n", ret, (unsigned)free_bytes, (unsigned)(free_bytes >> 20));
88 expect("free size is non-zero and not above total", ret == 0 && free_bytes > 0 && free_bytes <= total);
89
90 ret = fileXioDevctl("mass0:", DEVCTL_GET_TOTAL_SIZE, NULL, 0, &total, 4);
91 expect("short output buffer rejected", ret < 0);
92 ret = fileXioDevctl("mass0:", 0x00FF, NULL, 0, NULL, 0);
93 expect("unknown code rejected", ret < 0);
94
95 fileXioDevctl("mass5:", DEVCTL_STOP_UNIT, NULL, 0, NULL, 0);
96 expect("STOP_UNIT on a missing unit leaves mass0: mounted", mounted("mass0:/"));
97
98 fileXioDevctl("mass0:", DEVCTL_STOP_UNIT, NULL, 0, NULL, 0);
99 expect("STOP_UNIT on mass0: unmounts it", !mounted("mass0:/"));
100
101 fileXioDevctl("mass:", DEVCTL_STOP_ALL, NULL, 0, NULL, 0);
102 expect("STOP_ALL succeeds without crashing", 1);
103
104 kputs(failures ? "bdmfs-devctl: FAIL\n" : "bdmfs-devctl: PASS\n");
105 printf("[ps2rig] exit=%d\n", failures ? 1 : 0);
106 SleepThread();
107 return 0;
108}
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)