diff --git a/implementations/main.cpp b/implementations/main.cpp index b3b2ce2..7ecb1d1 100644 --- a/implementations/main.cpp +++ b/implementations/main.cpp @@ -337,6 +337,15 @@ void ServeGpFile(std::span sb) { sfs::WriteReply(sb, EROFS, 0); return; } + // The group directory may not exist yet -- a store with no enrolments + // has no group at all, and open(O_CREAT) creates the file, never its + // parent. Without this a first enrolment into a fresh store fails with + // ENOENT, which QTEE reports as an I/O error indistinguishable from a + // real storage fault. + std::error_code ec; + std::filesystem::create_directories( + std::filesystem::path(*full).parent_path(), ec); + // O_RDWR | O_CREAT | O_SYNC and never O_TRUNC: QTEE writes a container // as write(0,4096), write(4096,N), write(0,4096), so truncating on open // leaves 4096 bytes where a 258850-byte template belongs.