/* PFS mounting derived from VitaShell/FMVita, Copyright (C) TheFloW. */ #include #include #include #include #include #include #include "../../modules/user/vitashell_user.h" #include "pfs.h" #define FM_TITLEID "FILEMGR01" static char s_mountPoint[16]; static SceUID s_kernelMod = -1; static SceUID s_userMod = -1; /* The project has a tiny ScePaf taihen compatibility header, so declare the real loader syscall used by VitaShell explicitly here. */ typedef struct { size_t size; SceUID pid; size_t args; void *argp; int flags; } FmTaiModuleArgs; extern SceUID taiLoadStartKernelModuleForUser(const char *path, FmTaiModuleArgs *args); int pfsInitModules(void) { if (s_userMod >= 0) return 0; /* If VitaShellKernel2 is already resident, loading it simply fails and the user bridge binds to the existing exported library. */ FmTaiModuleArgs moduleArgs; memset(&moduleArgs, 0, sizeof(moduleArgs)); moduleArgs.size = sizeof(moduleArgs); s_kernelMod = taiLoadStartKernelModuleForUser("app0:module/kernel.skprx", &moduleArgs); s_userMod = sceKernelLoadStartModule("app0:module/user.suprx", 0, NULL, 0, NULL, NULL); return s_userMod < 0 ? s_userMod : 0; } int pfsMount(const char *path) { static const int fallbackIds[] = { 0x6E, 0x12E, 0x12F, 0x3E8, 0x3E9, 0x3EA, 0x3ED, 0x3EE }; char klicensee[0x10]; ShellMountIdArgs args; int res = pfsInitModules(); if (res < 0) return res; memset(klicensee, 0, sizeof(klicensee)); memset(s_mountPoint, 0, sizeof(s_mountPoint)); memset(&args, 0, sizeof(args)); args.process_titleid = FM_TITLEID; args.path = path; args.klicensee = klicensee; args.mount_point = s_mountPoint; /* Try the mount class matching the container first. Some firmware accepts a different class but exposes an empty mount, notably for addcont. */ int preferred = -1; if (!strncasecmp(path, "ux0:addcont/", 12)) preferred = 0x3EA; else if (!strncasecmp(path, "ux0:patch/", 10) || !strncasecmp(path, "grw0:patch/", 11)) preferred = 0x3E9; else if (!strncasecmp(path, "ux0:app/", 8) || !strncasecmp(path, "gro0:app/", 9) || !strncasecmp(path, "vs0:app/", 8)) preferred = 0x3E8; else if (!strncasecmp(path, "ux0:appmeta/", 12)) preferred = 0x6E; else if (!strncasecmp(path, "ux0:user/00/savedata/", 21)) preferred = 0x3ED; else if (!strncasecmp(path, "ur0:user/00/savedata/", 21)) preferred = 0x3EE; else if (!strncasecmp(path, "ur0:user/00/trophy/data/", 24)) preferred = 0x12F; if (preferred >= 0) { args.id = preferred; res = shellUserMountById(&args); if (res >= 0) return res; } for (unsigned i = 0; i < sizeof(fallbackIds) / sizeof(fallbackIds[0]); i++) { if (fallbackIds[i] == preferred) continue; args.id = fallbackIds[i]; res = shellUserMountById(&args); if (res >= 0) return res; } return sceAppMgrGameDataMount(path, 0, 0, s_mountPoint); } int pfsUmount(void) { if (!s_mountPoint[0]) return 0; int res = sceAppMgrUmount(s_mountPoint); if (res >= 0) memset(s_mountPoint, 0, sizeof(s_mountPoint)); return res; } const char *pfsMountPoint(void) { return s_mountPoint; } int pfsIsProtectedContainer(const char *path) { static const char *containers[] = { "ux0:app", "gro0:app", "vs0:app", "ux0:patch", "grw0:patch", "ux0:addcont", "ux0:appmeta", "ux0:user/00/savedata", "ur0:user/00/savedata", "ur0:user/00/trophy/data" }; if (!path) return 0; for (unsigned i = 0; i < sizeof(containers) / sizeof(containers[0]); i++) { if (!strcasecmp(path, containers[i])) return 1; } return 0; } int pfsShouldMount(const char *path) { if (!path || !path[0]) return 0; char marker[1024]; SceIoStat stat; snprintf(marker, sizeof(marker), "%s/sce_pfs", path); memset(&stat, 0, sizeof(stat)); return sceIoGetstat(marker, &stat) >= 0 && SCE_S_ISDIR(stat.st_mode); }