From 3768c2e8b4f00825aefec9a7100d7f216f0aa000 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 2 Sep 2026 21:09:44 +0200 Subject: [PATCH] Create a container's parent directory on write A store with no enrolments has no group directory, and open(O_CREAT) creates the file but never its parent. A first enrolment into a fresh store therefore failed with ENOENT, which QTEE reports as an I/O error -- indistinguishable from a real storage fault, and the same -5 a refused RPMB write produces. --- implementations/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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.