fs: Actually functional linux case insensitive search

This commit is contained in:
IndecisiveTurtle 2024-07-15 03:37:30 +03:00
parent 26f8fbf628
commit dbeed80e3b
7 changed files with 145 additions and 108 deletions

View file

@ -58,7 +58,7 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
if (directory) {
file->is_directory = true;
file->m_guest_name = path;
file->m_host_name = mnt->GetHostDirectory(file->m_guest_name);
file->m_host_name = mnt->GetHostPath(file->m_guest_name);
if (!std::filesystem::is_directory(file->m_host_name)) { // directory doesn't exist
h->DeleteHandle(handle);
return ORBIS_KERNEL_ERROR_ENOTDIR;
@ -72,7 +72,7 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
}
} else {
file->m_guest_name = path;
file->m_host_name = mnt->GetHostFile(file->m_guest_name);
file->m_host_name = mnt->GetHostPath(file->m_guest_name);
int e = 0;
if (read) {
e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read);
@ -165,8 +165,7 @@ int PS4_SYSV_ABI sceKernelUnlink(const char* path) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string host_path = mnt->GetHostFile(path);
const auto host_path = mnt->GetHostPath(path);
if (host_path.empty()) {
return SCE_KERNEL_ERROR_EACCES;
}
@ -250,7 +249,7 @@ int PS4_SYSV_ABI sceKernelMkdir(const char* path, u16 mode) {
return SCE_KERNEL_ERROR_EINVAL;
}
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string dir_name = mnt->GetHostFile(path);
const auto dir_name = mnt->GetHostPath(path);
if (std::filesystem::exists(dir_name)) {
return SCE_KERNEL_ERROR_EEXIST;
}
@ -279,7 +278,7 @@ int PS4_SYSV_ABI posix_mkdir(const char* path, u16 mode) {
int PS4_SYSV_ABI sceKernelStat(const char* path, OrbisKernelStat* sb) {
LOG_INFO(Kernel_Fs, "(PARTIAL) path = {}", path);
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto& path_name = mnt->GetHostFile(path);
const auto path_name = mnt->GetHostPath(path);
std::memset(sb, 0, sizeof(OrbisKernelStat));
const bool is_dir = std::filesystem::is_directory(path_name);
const bool is_file = std::filesystem::is_regular_file(path_name);
@ -314,7 +313,7 @@ int PS4_SYSV_ABI posix_stat(const char* path, OrbisKernelStat* sb) {
int PS4_SYSV_ABI sceKernelCheckReachability(const char* path) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string path_name = mnt->GetHostFile(path);
const auto path_name = mnt->GetHostPath(path);
if (!std::filesystem::exists(path_name)) {
return SCE_KERNEL_ERROR_ENOENT;
}

View file

@ -222,7 +222,7 @@ s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t arg
}
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto path = mnt->GetHostFile(moduleFileName);
const auto path = mnt->GetHostPath(moduleFileName);
// Load PRX module and relocate any modules that import it.
auto* linker = Common::Singleton<Core::Linker>::Instance();

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/libraries/libc/libc_stdio.h"
@ -10,11 +10,12 @@ namespace Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
FILE* f = std::fopen(mnt->GetHostFile(filename).c_str(), mode);
const auto host_path = mnt->GetHostPath(filename);
FILE* f = std::fopen(host_path.c_str(), mode);
if (f != nullptr) {
LOG_INFO(Lib_LibC, "fopen = {}", mnt->GetHostFile(filename).c_str());
LOG_INFO(Lib_LibC, "fopen = {}", host_path.native());
} else {
LOG_INFO(Lib_LibC, "fopen can't open = {}", mnt->GetHostFile(filename).c_str());
LOG_INFO(Lib_LibC, "fopen can't open = {}", host_path.native());
}
return f;
}

View file

@ -15,7 +15,8 @@
#include "error_codes.h"
namespace Libraries::SaveData {
static std::string g_mount_point = "/savedata0"; // temp mount point (todo)
static constexpr std::string_view g_mount_point = "/savedata0"; // temp mount point (todo)
std::string game_serial;
int PS4_SYSV_ABI sceSaveDataAbort() {
@ -50,11 +51,11 @@ int PS4_SYSV_ABI sceSaveDataChangeInternal() {
int PS4_SYSV_ABI sceSaveDataCheckBackupData(const OrbisSaveDataCheckBackupData* check) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string mount_dir = mnt->GetHostFile(check->dirName->data);
const auto mount_dir = mnt->GetHostPath(check->dirName->data);
if (!std::filesystem::exists(mount_dir)) {
return ORBIS_SAVE_DATA_ERROR_NOT_FOUND;
}
LOG_INFO(Lib_SaveData, "called = {}", mount_dir);
LOG_INFO(Lib_SaveData, "called = {}", mount_dir.native());
return ORBIS_OK;
}
@ -317,14 +318,14 @@ int PS4_SYSV_ABI sceSaveDataGetSaveDataMemory2(OrbisSaveDataMemoryGet2* getParam
return false;
}
file.Seek(getParam->data->offset);
size_t nbytes = file.ReadRaw<u8>(getParam->data->buf, getParam->data->bufSize);
file.ReadRaw<u8>(getParam->data->buf, getParam->data->bufSize);
LOG_INFO(Lib_SaveData, "called: bufSize = {}, offset = {}", getParam->data->bufSize,
getParam->data->offset);
}
if (getParam->param != nullptr) {
Common::FS::IOFile file1(mount_dir / "param.txt", Common::FS::FileAccessMode::Read);
size_t nbytes = file1.ReadRaw<u8>(getParam->param, sizeof(OrbisSaveDataParam));
Common::FS::IOFile file(mount_dir / "param.txt", Common::FS::FileAccessMode::Read);
file.ReadRaw<u8>(getParam->param, sizeof(OrbisSaveDataParam));
}
return ORBIS_OK;
@ -394,13 +395,13 @@ int PS4_SYSV_ABI sceSaveDataIsMounted() {
int PS4_SYSV_ABI sceSaveDataLoadIcon(const OrbisSaveDataMountPoint* mountPoint,
OrbisSaveDataIcon* icon) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string mount_dir = mnt->GetHostFile(mountPoint->data);
LOG_INFO(Lib_SaveData, "called: dir = {}", mount_dir);
const auto mount_dir = mnt->GetHostPath(mountPoint->data);
LOG_INFO(Lib_SaveData, "called: dir = {}", mount_dir.native());
if (icon != nullptr) {
Common::FS::IOFile file(mount_dir + "/save_data.png", Common::FS::FileAccessMode::Read);
Common::FS::IOFile file(mount_dir / "save_data.png", Common::FS::FileAccessMode::Read);
icon->bufSize = file.GetSize();
size_t nbytes = file.ReadRaw<u8>(icon->buf, icon->bufSize);
file.ReadRaw<u8>(icon->buf, icon->bufSize);
}
return ORBIS_OK;
}
@ -409,6 +410,7 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode,
OrbisSaveDataMountResult* mount_result) {
const auto& mount_dir = Common::FS::GetUserPath(Common::FS::PathType::SaveDataDir) /
std::to_string(user_id) / game_serial / dir_name;
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
switch (mount_mode) {
case ORBIS_SAVE_DATA_MOUNT_MODE_RDONLY:
case ORBIS_SAVE_DATA_MOUNT_MODE_RDWR:
@ -417,9 +419,8 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode,
if (!std::filesystem::exists(mount_dir)) {
return ORBIS_SAVE_DATA_ERROR_NOT_FOUND;
}
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
mount_result->mount_status = 0;
std::strncpy(mount_result->mount_point.data, g_mount_point.c_str(), 16);
g_mount_point.copy(mount_result->mount_point.data, 16);
mnt->Mount(mount_dir, mount_result->mount_point.data);
} break;
case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE:
@ -431,16 +432,15 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode,
ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON:
case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF |
ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
if (std::filesystem::exists(mount_dir)) {
std::strncpy(mount_result->mount_point.data, g_mount_point.c_str(), 16);
g_mount_point.copy(mount_result->mount_point.data, 16);
mnt->Mount(mount_dir, mount_result->mount_point.data);
mount_result->required_blocks = 0;
mount_result->mount_status = 0;
return ORBIS_SAVE_DATA_ERROR_EXISTS;
}
if (std::filesystem::create_directories(mount_dir)) {
std::strncpy(mount_result->mount_point.data, g_mount_point.c_str(), 16);
g_mount_point.copy(mount_result->mount_point.data, 16);
mnt->Mount(mount_dir, mount_result->mount_point.data);
mount_result->mount_status = 1;
}
@ -451,8 +451,7 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode,
if (!std::filesystem::exists(mount_dir)) {
std::filesystem::create_directories(mount_dir);
}
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::strncpy(mount_result->mount_point.data, g_mount_point.c_str(), 16);
g_mount_point.copy(mount_result->mount_point.data, 16);
mnt->Mount(mount_dir, mount_result->mount_point.data);
mount_result->mount_status = 1;
} break;
@ -534,12 +533,12 @@ int PS4_SYSV_ABI sceSaveDataRestoreLoadSaveDataMemory() {
int PS4_SYSV_ABI sceSaveDataSaveIcon(const OrbisSaveDataMountPoint* mountPoint,
const OrbisSaveDataIcon* icon) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string mount_dir = mnt->GetHostFile(mountPoint->data);
LOG_INFO(Lib_SaveData, "called = {}", mount_dir);
const auto mount_dir = mnt->GetHostPath(mountPoint->data);
LOG_INFO(Lib_SaveData, "called = {}", mount_dir.native());
if (icon != nullptr) {
Common::FS::IOFile file(mount_dir + "/save_data.png", Common::FS::FileAccessMode::Write);
file.WriteRaw<u8>((void*)icon->buf, icon->bufSize);
if (icon != nullptr) {
Common::FS::IOFile file(mount_dir / "save_data.png", Common::FS::FileAccessMode::Write);
file.WriteRaw<u8>(icon->buf, icon->bufSize);
}
return ORBIS_OK;
}
@ -558,12 +557,13 @@ int PS4_SYSV_ABI sceSaveDataSetParam(const OrbisSaveDataMountPoint* mountPoint,
OrbisSaveDataParamType paramType, const void* paramBuf,
size_t paramBufSize) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string mount_dir = mnt->GetHostFile(mountPoint->data);
LOG_INFO(Lib_SaveData, "called = {}, mountPoint->data = {}", mount_dir, mountPoint->data);
const auto mount_dir = mnt->GetHostPath(mountPoint->data);
LOG_INFO(Lib_SaveData, "called = {}, mountPoint->data = {}", mount_dir.native(),
mountPoint->data);
if (paramBuf != nullptr) {
Common::FS::IOFile file(mount_dir + "/param.txt", Common::FS::FileAccessMode::Write);
file.WriteRaw<u8>((void*)paramBuf, paramBufSize);
Common::FS::IOFile file(mount_dir / "param.txt", Common::FS::FileAccessMode::Write);
file.WriteRaw<u8>(paramBuf, paramBufSize);
}
return ORBIS_OK;
}
@ -711,24 +711,23 @@ int PS4_SYSV_ABI sceSaveDataUmountSys() {
int PS4_SYSV_ABI sceSaveDataUmountWithBackup(const OrbisSaveDataMountPoint* mountPoint) {
LOG_ERROR(Lib_SaveData, "called = {}", std::string(mountPoint->data));
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::string mount_dir = mnt->GetHostFile(mountPoint->data);
const auto mount_dir = mnt->GetHostPath(mountPoint->data);
if (!std::filesystem::exists(mount_dir)) {
return ORBIS_SAVE_DATA_ERROR_NOT_FOUND;
} else {
std::filesystem::path mnt_dir(mount_dir);
std::filesystem::create_directories(mnt_dir.parent_path() / "backup");
for (const auto& entry : std::filesystem::recursive_directory_iterator(mnt_dir)) {
const auto& path = entry.path();
std::filesystem::path target_path = mnt_dir.parent_path() / "backup";
if (std::filesystem::is_regular_file(path)) {
std::filesystem::copy(path, target_path,
std::filesystem::copy_options::overwrite_existing);
}
}
mnt->Unmount(mount_dir, mountPoint->data);
}
std::filesystem::create_directories(mount_dir.parent_path() / "backup");
for (const auto& entry : std::filesystem::recursive_directory_iterator(mount_dir)) {
const auto& path = entry.path();
const auto target_path = mount_dir.parent_path() / "backup";
if (std::filesystem::is_regular_file(path)) {
std::filesystem::copy(path, target_path,
std::filesystem::copy_options::overwrite_existing);
}
}
mnt->Unmount(mount_dir, mountPoint->data);
return ORBIS_OK;
}