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.
This commit is contained in:
Jorijn van der Graaf 2026-09-02 21:09:44 +02:00
commit 3768c2e8b4

View file

@ -337,6 +337,15 @@ void ServeGpFile(std::span<std::byte> 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.