mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-11-18 03:54:30 +01:00
kernel: return ENOENT from mkdir when the parent does not exist (#5399)
posix_mkdir used fs::create_directories, so mkdir("/data/a/b") with no
/data/a returned 0 and created both directories. On the console mkdir(2)
only creates the last component and fails with ENOENT when the parent is
missing, so sceKernelMkdir should return 0x80020002. Use
fs::create_directory and report ENOENT in that case.
Also check for a null path before logging it and calling strlen on it,
and report EFAULT like posix_rmdir does, instead of crashing.
This commit is contained in:
1 parent
6752d8b19e
commit
d415c71bfe
1 file changed
+9
-5
@@ -591,15 +591,15 @@ s64 PS4_SYSV_ABI sceKernelRead(s32 fd, void* buf, u64 nbytes) {
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI posix_mkdir(const char* path, u16 mode) {
|
||||
if (path == nullptr) {
|
||||
*__Error() = POSIX_EFAULT;
|
||||
return -1;
|
||||
}
|
||||
LOG_INFO(Kernel_Fs, "path = {} mode = {:#o}", path, mode);
|
||||
if (strlen(path) > 255) {
|
||||
*__Error() = POSIX_ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (path == nullptr) {
|
||||
*__Error() = POSIX_ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
std::string sanitized_path(path);
|
||||
while (sanitized_path.length() > 1 && sanitized_path.back() == '/') {
|
||||
sanitized_path.pop_back();
|
||||
@@ -621,7 +621,11 @@ s32 PS4_SYSV_ABI posix_mkdir(const char* path, u16 mode) {
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
if (dir_name.empty() || !fs::create_directories(dir_name, ec)) {
|
||||
if (dir_name.empty() || !fs::create_directory(dir_name, ec)) {
|
||||
if (ec == std::errc::no_such_file_or_directory) {
|
||||
*__Error() = POSIX_ENOENT;
|
||||
return -1;
|
||||
}
|
||||
*__Error() = (ec.value() == EACCES || ec.value() == EPERM) ? POSIX_EACCES : POSIX_EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user