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
4 changes: 4 additions & 0 deletions core/libs/prx/libkernel/File/src/Open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ static int OpenNative(const std::filesystem::path& native, int flags, std::uint1
const auto status = std::filesystem::status(native, error);
if (std::filesystem::exists(status) && !std::filesystem::is_directory(status)) return SceErrorFromErrno(ENOTDIR);
}
if ((flags & (SCE_KERNEL_O_CREAT | SCE_KERNEL_O_EXCL)) == (SCE_KERNEL_O_CREAT | SCE_KERNEL_O_EXCL) && native.has_filename()) {
const DWORD attributes = GetFileAttributesW(native.c_str());
if (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) return SceErrorFromErrno(EEXIST);
}
#endif
if ((flags & SCE_KERNEL_O_NOFOLLOW) != 0 && (flags & (SCE_KERNEL_O_CREAT | SCE_KERNEL_O_EXCL)) != (SCE_KERNEL_O_CREAT | SCE_KERNEL_O_EXCL)) {
constexpr int GuestEmlink = 31;
Expand Down
21 changes: 21 additions & 0 deletions core/libs/tests/GuestFilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,27 @@ int main() {
Require(fchflags_nid_postfix(-1, 0) == -1 && *__error_nid_postfix() == 9);
const int flaggedRoot = sceKernelOpen(root.string().c_str(), 0x20000, 0);
Require(flaggedRoot >= 0 && fchflags_nid_postfix(flaggedRoot, 0) == 0 && sceKernelClose(flaggedRoot) == 0);
const auto exclusiveLink = root / "exclusive.link";
const auto exclusiveTarget = root / "exclusive-target.txt";
#ifdef _WIN32
const bool exclusiveLinked = CreateSymbolicLinkW(exclusiveLink.wstring().c_str(), L"exclusive-target.txt",
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) != 0;
#else
std::error_code exclusiveLinkError;
std::filesystem::create_symlink("exclusive-target.txt", exclusiveLink, exclusiveLinkError);
const bool exclusiveLinked = !exclusiveLinkError;
#endif
if (exclusiveLinked) {
Require(open_nid_postfix(exclusiveLink.string().c_str(), 0xa01, 0644) == -1 && *__error_nid_postfix() == 17);
Require(sceKernelOpen(exclusiveLink.string().c_str(), 0xa01, 0644) == static_cast<int>(0x80020011u));
Require(!std::filesystem::exists(exclusiveTarget));
const int exclusiveCreated = open_nid_postfix(exclusiveLink.string().c_str(), 0x201, 0644);
Require(exclusiveCreated >= 0 && close_nid_postfix(exclusiveCreated) == 0 && std::filesystem::is_regular_file(exclusiveTarget));
Require(open_nid_postfix(exclusiveLink.string().c_str(), 0xa01, 0644) == -1 && *__error_nid_postfix() == 17);
Require(unlink_nid_postfix(exclusiveLink.string().c_str()) == 0 && unlink_nid_postfix(exclusiveTarget.string().c_str()) == 0);
} else {
std::fprintf(stderr, "symbolic links unavailable: the O_EXCL link cases not tested\n");
}
int flaggedPipe[2];
Require(pipe_nid_postfix(flaggedPipe) == 0);
Require(fchflags_nid_postfix(flaggedPipe[0], 0) == -1 && *__error_nid_postfix() == 22);
Expand Down
Loading