kernel: report /dev/random and /dev/urandom as character devices (#1140)

kernel: report entropy sources as character devices

Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
Henrique Reis Neves
2026-10-07 20:35:58 -03:00
committed by GitHub
parent 34f6fd1f5f
commit de62664908
2 changed files with 17 additions and 10 deletions
+15
View File
@@ -121,6 +121,20 @@ void CheckSaveRename(const std::filesystem::path &root,
"renamed save contents");
}
void TestRandomDevices() {
for (const auto* path : {"/dev/urandom", "/dev/random"}) {
const int fd = FileSystem::KernelOpen(path, 0, 0);
FileSystem::FileStat stat {};
Check(fd >= 3 && FileSystem::KernelFstat(fd, &stat) == OK &&
(stat.st_mode & 0170000) == 0020000,
"entropy sources are character devices");
std::array<uint8_t, 32> entropy {};
Check(FileSystem::KernelRead(fd, entropy.data(), entropy.size()) == entropy.size(),
"character device supplies requested entropy");
Check(FileSystem::KernelClose(fd) == OK, "close entropy source");
}
}
void TestSaveOpenVisibility() {
constexpr char Path[] = "/savedata0/visible-save.dat";
constexpr char Payload[] = "saved progress";
@@ -1398,6 +1412,7 @@ int main(int, char**) {
TempDirectory temporary;
FileSystem::Initialize();
TestRandomDevices();
CheckMountRoot(temporary.Path());
CheckUnmappedPaths(temporary.Path());
CheckArchiveMount(temporary.Path());