Added sceKernelRmdir (#1137)

* add sceKernelRmdir

* since result is remove count, probably don't use that

* fixes + posix_rmdir

* fix return value problem
This commit is contained in:
ElBread3 2024-09-30 06:25:25 -05:00 committed by GitHub
parent fc6c755e5a
commit 603f709784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 2 deletions

View File

@ -192,8 +192,9 @@ int IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, FileS
#endif
if (!IsOpen()) {
LOG_ERROR(Common_Filesystem, "Failed to open the file at path={}",
PathToUTF8String(file_path));
const auto ec = std::error_code{result, std::generic_category()};
LOG_ERROR(Common_Filesystem, "Failed to open the file at path={}, error_message={}",
PathToUTF8String(file_path), ec.message());
}
return result;

View File

@ -314,6 +314,58 @@ int PS4_SYSV_ABI posix_mkdir(const char* path, u16 mode) {
return result;
}
int PS4_SYSV_ABI sceKernelRmdir(const char* path) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
bool ro = false;
const std::filesystem::path dir_name = mnt->GetHostPath(path, &ro);
if (dir_name.empty()) {
LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, permission denied",
fmt::UTF(dir_name.u8string()));
return SCE_KERNEL_ERROR_EACCES;
}
if (ro) {
LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, directory is read only",
fmt::UTF(dir_name.u8string()));
return SCE_KERNEL_ERROR_EROFS;
}
if (!std::filesystem::is_directory(dir_name)) {
LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, path is not a directory",
fmt::UTF(dir_name.u8string()));
return ORBIS_KERNEL_ERROR_ENOTDIR;
}
if (!std::filesystem::exists(dir_name)) {
LOG_INFO(Kernel_Fs, "Failed to remove directory: {}, no such file or directory",
fmt::UTF(dir_name.u8string()));
return ORBIS_KERNEL_ERROR_ENOENT;
}
std::error_code ec;
int result = std::filesystem::remove_all(dir_name, ec);
if (!ec) {
LOG_DEBUG(Kernel_Fs, "Removed directory: {}", fmt::UTF(dir_name.u8string()));
return ORBIS_OK;
}
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, error_code={}",
fmt::UTF(dir_name.u8string()), ec.message());
return ErrnoToSceKernelError(ec.value());
}
int PS4_SYSV_ABI posix_rmdir(const char* path) {
int result = sceKernelRmdir(path);
if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_rmdir: error = {}", result);
ErrSceToPosix(result);
return -1;
}
return result;
}
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();
@ -574,6 +626,8 @@ void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("AqBioC2vF3I", "libScePosix", 1, "libkernel", 1, 1, posix_read);
LIB_FUNCTION("1-LFLmRFxxM", "libkernel", 1, "libkernel", 1, 1, sceKernelMkdir);
LIB_FUNCTION("JGMio+21L4c", "libScePosix", 1, "libkernel", 1, 1, posix_mkdir);
LIB_FUNCTION("naInUjYt3so", "libkernel", 1, "libkernel", 1, 1, sceKernelRmdir);
LIB_FUNCTION("c7ZnT7V1B98", "libScePosix", 1, "libkernel", 1, 1, posix_rmdir);
LIB_FUNCTION("eV9wAD2riIA", "libkernel", 1, "libkernel", 1, 1, sceKernelStat);
LIB_FUNCTION("kBwCPsYX-m4", "libkernel", 1, "libkernel", 1, 1, sceKernelFStat);
LIB_FUNCTION("mqQMh1zPPT8", "libScePosix", 1, "libkernel", 1, 1, posix_fstat);