Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/libs/prx/libkernel/File/src/Stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,10 @@ int APS5_VABI sceKernelGetdirentries(int fd, char* buf, int nbytes, int64_t* bas
File::RefuseArchivedFile(fd, "getdirentries");
if (buf == nullptr) return SceErrorFromErrno(GUEST_EFAULT);
if (nbytes <= 0) return SceErrorFromErrno(GUEST_EINVAL);
if (!File::DirectoryDescriptorPath(fd)) {
if (WithoutParameterHandler([fd] { return ::_get_osfhandle(fd); }) == -1) return SceErrorFromErrno(GUEST_EBADF);
return SceErrorFromErrno(GUEST_EINVAL);
}
if (basep != nullptr) *basep = 0;
return File::ReadDirectoryDescriptor(fd, buf, nbytes);
}
Expand All @@ -1002,6 +1006,9 @@ int APS5_VABI sceKernelGetdirentries(int fd, char* buf, int nbytes, int64_t* bas
constexpr std::size_t GuestMaxName = 255;
if (buf == nullptr) return SceErrorFromErrno(GUEST_EFAULT);
if (nbytes <= 0) return SceErrorFromErrno(GUEST_EINVAL);
struct stat status{};
if (::fstat(fd, &status) != 0) return SceErrorFromErrno(errno);
if (!S_ISDIR(status.st_mode)) return SceErrorFromErrno(GUEST_EINVAL);
const off_t base = ::lseek(fd, 0, SEEK_CUR);
if (base < 0) return SceErrorFromErrno(errno);
if (basep != nullptr) *basep = static_cast<int64_t>(base);
Expand Down
2 changes: 1 addition & 1 deletion core/libs/tests/GuestDirectoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void CheckName(const std::u8string& utf8Name) {
Require(sceKernelGetdents(directory, buffer.data(), 8) == 0);
Require(sceKernelGetdents(directory, buffer.data(), 256) == 0);
Require(sceKernelClose(directory) == 0);
Require(sceKernelGetdents(-1, buffer.data(), 256) == SCE_KERNEL_ERROR_ENOTDIR);
Require(sceKernelGetdents(-1, buffer.data(), 256) == SCE_KERNEL_ERROR_EBADF);
std::filesystem::remove_all(root);
}

Expand Down
4 changes: 2 additions & 2 deletions core/libs/tests/GuestDirectoryClose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void Check(bool value, int line) {
}
#define Require(value) Check((value), __LINE__)

static constexpr int ErrorEnotdir = static_cast<int>(0x80020014u);
static constexpr int ErrorEinval = static_cast<int>(0x80020016u);

static void VerifyCloseReuse(const std::filesystem::path& root, const char* scenario,
bool useUnderscoreClose) {
Expand All @@ -49,7 +49,7 @@ static void VerifyCloseReuse(const std::filesystem::path& root, const char* scen
Require(file == directory);

std::array<char, 256> entries{};
Require(sceKernelGetdents(file, entries.data(), static_cast<int>(entries.size())) == ErrorEnotdir);
Require(sceKernelGetdents(file, entries.data(), static_cast<int>(entries.size())) == ErrorEinval);
Require((useUnderscoreClose ? _close_nid_postfix(file) : close_nid_postfix(file)) == 0);
}

Expand Down
9 changes: 9 additions & 0 deletions core/libs/tests/GuestFilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ int APS5_VABI mkdir_nid_postfix(const char*, unsigned short);
int APS5_VABI sceKernelOpen(const char*, int, unsigned short);
int APS5_VABI sceKernelClose(int);
int APS5_VABI sceKernelGetdents(int, char*, int);
int APS5_VABI getdents_nid_postfix(int, char*, int);
int APS5_VABI getdirentries_nid_postfix(int, char*, int, int64_t*);
std::int64_t APS5_VABI sceKernelRead(int, void*, std::size_t);
std::int64_t APS5_VABI sceKernelReadv(int, const void*, int);
std::int64_t APS5_VABI sceKernelPread(int, void*, std::size_t, std::int64_t);
Expand Down Expand Up @@ -833,6 +835,13 @@ int main() {
Require(sceKernelPwrite(directoryDescriptor, "x", 1, 0) == static_cast<int>(0x80020009u));
std::vector<char> listing(4096);
Require(sceKernelGetdents(directoryDescriptor, listing.data(), static_cast<int>(listing.size())) > 0);
const int plainFile = open_nid_postfix(presentName.c_str(), 0, 0);
Require(plainFile >= 0);
Require(sceKernelGetdents(plainFile, listing.data(), static_cast<int>(listing.size())) == static_cast<int>(0x80020016u));
Require(getdents_nid_postfix(plainFile, listing.data(), static_cast<int>(listing.size())) == -1 && *__error_nid_postfix() == 22);
int64_t plainBase = 0;
Require(getdirentries_nid_postfix(plainFile, listing.data(), static_cast<int>(listing.size()), &plainBase) == -1 && *__error_nid_postfix() == 22);
Require(close_nid_postfix(plainFile) == 0);
Require(close_nid_postfix(directoryDescriptor) == 0);
const int flaggedDirectory = sceKernelOpen(rootName.c_str(), 0x20000, 0);
Require(flaggedDirectory >= 0 && sceKernelClose(flaggedDirectory) == 0);
Expand Down
Loading