12#define NEWLIB_PORT_AWARE
15#include "iomanx_irx.h"
16#include "filexio_irx.h"
19#include "bdmfs_fatfs_irx.h"
20#include "usbmass_bd_irx.h"
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
28extern int kputs(
char *s);
32static void expect(
const char *name,
int ok)
34 printf(
"devctl-test: [%s] %s\n", ok ?
"PASS" :
"FAIL", name);
39static void load(
const char *name,
void *buf,
unsigned int size)
44 printf(
"devctl-test: %s id=%d ret=%d\n", name,
id, ret);
47static int mounted(
const char *path)
49 int fd = fileXioDopen(path);
60 uint64_t total = 0, free_bytes = 0;
66 load(
"iomanx", iomanx_irx, size_iomanx_irx);
67 load(
"filexio", filexio_irx, size_filexio_irx);
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);
74 for (
int i = 0; i < 100 && !mounted(
"mass0:/"); i++)
76 expect(
"mass0: mounted", mounted(
"mass0:/"));
78 ret = fileXioDevctl(
"mass0:", DEVCTL_GET_SECTOR_SIZE, NULL, 0, §or,
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);
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);
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);
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);
95 fileXioDevctl(
"mass5:", DEVCTL_STOP_UNIT, NULL, 0, NULL, 0);
96 expect(
"STOP_UNIT on a missing unit leaves mass0: mounted", mounted(
"mass0:/"));
98 fileXioDevctl(
"mass0:", DEVCTL_STOP_UNIT, NULL, 0, NULL, 0);
99 expect(
"STOP_UNIT on mass0: unmounts it", !mounted(
"mass0:/"));
101 fileXioDevctl(
"mass:", DEVCTL_STOP_ALL, NULL, 0, NULL, 0);
102 expect(
"STOP_ALL succeeds without crashing", 1);
104 kputs(failures ?
"bdmfs-devctl: FAIL\n" :
"bdmfs-devctl: PASS\n");
105 printf(
"[ps2rig] exit=%d\n", failures ? 1 : 0);
int SifExecModuleBuffer(void *ptr, u32 size, u32 arg_len, const char *args, int *mod_res)
int sbv_patch_disable_prefix_check(void)
int sbv_patch_enable_lmb(void)