upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/file_system.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-23 13:07:27 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 06:54:36 -0500
commit297ad8685486dc9523d492e8fce19ae4aa52429b (patch)
tree8c6dd4aebf02ba920e9d77a4bcae73dab11c8cd0 /runtime/shims/file_system.cpp
parent21625bca8c675c62f9dbffc318ce6a59d57faf31 (diff)
file_system: T: is a folder of each process's own in the overlay
T:\ mapped to <overlay>\.gta6rt-temp, one folder shared by every run and kept between runs. The title makes its crash dump and crash log there with CREATE_NEW, and a name an earlier run (or a second process) had left failed with ERROR_FILE_EXISTS (80), so no report landed (old upstream issue 7913, measured by Spacecer2 under Wine 11.22). T:\ now names <overlay>\.gta6rt-temp\<YYYYMMDD-HHMMSS-mmm>-pid<id>, the process's start time in UTC and its id, made on the first T: call. The start time keeps a reused process id (Wine hands each fresh prefix the same small ids) out of an old run's folder. T:\.. cannot climb into the shared folder, T:\ itself still cannot be removed or moved, and earlier runs' folders are kept so their crash files can be read. GAME: and G: are unchanged. rt::fs::scratch_dir() returns the folder, and the startup line names it: "console paths: GAME: -> ..., writes -> ..., T: -> ...". The two CMake checks of that line (run_tiny_game_console_paths, run_tiny_game_dir) and the synthetic test of the first now expect the T: part. file_system_test: a CREATE_NEW of a name earlier runs left in .gta6rt-temp succeeds and lands in the process's own folder; the folder is stable for the process; a second process (the test started again) creating the same name on the same overlay succeeds in a folder of its own; GAME: reads and writes are unchanged. On main these fail with ERROR_FILE_EXISTS (80), in this process and in the second one. Restored from old upstream PR 8161 and ported onto the new main: the folder is made through main's win32_io_path, so long overlay roots keep working, and the scratch-folder check of the write-open path is kept. Main's long-overlay T: check now finds scratch.bin in the process's own folder below .gta6rt-temp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/file_system.cpp')
-rw-r--r--runtime/shims/file_system.cpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp
index 75f5e9810..97dad46df 100644
--- a/runtime/shims/file_system.cpp
+++ b/runtime/shims/file_system.cpp
@@ -6,7 +6,8 @@
6// here (docs/runtime_imports.md, "Console paths and the write overlay"; the prefixes come from ivall/xcl, 6// here (docs/runtime_imports.md, "Console paths and the write overlay"; the prefixes come from ivall/xcl,
7// GPL-2.0-only, as facts). The rules: 7// GPL-2.0-only, as facts). The rules:
8// - "GAME:" (any case, "\\" or "/") maps under --game-dir, "G:\\" is the same folder and "T:\\" a scratch folder in 8// - "GAME:" (any case, "\\" or "/") maps under --game-dir, "G:\\" is the same folder and "T:\\" a scratch folder in
9// the overlay (RT-218); any other path is a host path and goes to the host; 9// the overlay (RT-218), <overlay>\\.gta6rt-temp\\<run>, a new one for every process; any other path is a host
10// path and goes to the host;
10// - an open that can write, and DeleteFile, go to the overlay (--overlay, default <game-dir>\\overlay), so the 11// - an open that can write, and DeleteFile, go to the overlay (--overlay, default <game-dir>\\overlay), so the
11// package stays exactly as installed. A write-open of a package file copies it into the overlay first, so 12// package stays exactly as installed. A write-open of a package file copies it into the overlay first, so
12// OPEN_EXISTING keeps its bytes; a delete of a package file leaves an empty marker under 13// OPEN_EXISTING keeps its bytes; a delete of a package file leaves an empty marker under
@@ -48,7 +49,7 @@ namespace {
48constexpr wchar_t kGamePrefix[] = L"game:"; 49constexpr wchar_t kGamePrefix[] = L"game:";
49constexpr size_t kGamePrefixLength = 5; 50constexpr size_t kGamePrefixLength = 5;
50constexpr wchar_t kDeletedDir[] = L".gta6rt-deleted"; 51constexpr wchar_t kDeletedDir[] = L".gta6rt-deleted";
51constexpr wchar_t kScratchDir[] = L".gta6rt-temp"; // what "T:\" names, inside the overlay 52constexpr wchar_t kScratchDir[] = L".gta6rt-temp"; // holds one folder per process; "T:\" names this process's
52// A removed package folder is marked by this file inside its marker folder: the marker folder itself can already 53// A removed package folder is marked by this file inside its marker folder: the marker folder itself can already
53// exist because files below it were deleted, and that alone does not hide the folder. 54// exist because files below it were deleted, and that alone does not hide the folder.
54constexpr wchar_t kRemovedDirMarker[] = L".gta6rt-dir"; 55constexpr wchar_t kRemovedDirMarker[] = L".gta6rt-dir";
@@ -166,9 +167,34 @@ std::filesystem::path win32_find_path(const std::filesystem::path& path, const s
166// other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so 167// other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so
167// a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:, 168// a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:,
168// or a path GetModuleFileName handed back) stays a host path, and so does every G:/T: path while no roots are 169// or a path GetModuleFileName handed back) stays a host path, and so does every G:/T: path while no roots are
169// configured. The scratch folder lives in the overlay, as `.gta6rt-temp`. 170// configured. The scratch folder lives in the overlay, as `.gta6rt-temp\<run>`, one per process (scratch_run()).
170enum class Drive { None, Game, Scratch }; 171enum class Drive { None, Game, Scratch };
171 172
173// The name of this process's T: folder below `.gta6rt-temp`: the process's start time (UTC, to the millisecond) and
174// its id, e.g. "20261123-181502-123-pid4242". On the console T: is the title's own temporary drive, empty at launch
175// and shared with nothing; one folder that every run shared kept the files earlier runs left, so a title that makes a
176// file there with CREATE_NEW (its crash dump and crash log, measured under Wine) got ERROR_FILE_EXISTS. The start
177// time keeps a reused process id from landing in an old run's folder; the folders of earlier runs are left in place
178// for whoever wants to read what those runs wrote.
179const std::wstring& scratch_run() {
180 static const std::wstring name = [] {
181 const DWORD last_error = ::GetLastError();
182 FILETIME created{}, exited{}, kernel{}, user{};
183 SYSTEMTIME t{};
184 if (!::GetProcessTimes(::GetCurrentProcess(), &created, &exited, &kernel, &user) ||
185 !::FileTimeToSystemTime(&created, &t))
186 ::GetSystemTime(&t);
187 wchar_t buffer[64];
188 const unsigned long pid = ::GetCurrentProcessId();
189 std::swprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), L"%04u%02u%02u-%02u%02u%02u-%03u-pid%lu",
190 unsigned{t.wYear}, unsigned{t.wMonth}, unsigned{t.wDay}, unsigned{t.wHour}, unsigned{t.wMinute},
191 unsigned{t.wSecond}, unsigned{t.wMilliseconds}, pid);
192 ::SetLastError(last_error);
193 return std::wstring(buffer);
194 }();
195 return name;
196}
197
172Drive console_drive(const std::wstring& path, size_t& prefix_length) { 198Drive console_drive(const std::wstring& path, size_t& prefix_length) {
173 if (path.size() >= kGamePrefixLength && lower(path.substr(0, kGamePrefixLength)) == kGamePrefix) { 199 if (path.size() >= kGamePrefixLength && lower(path.substr(0, kGamePrefixLength)) == kGamePrefix) {
174 prefix_length = kGamePrefixLength; 200 prefix_length = kGamePrefixLength;
@@ -191,10 +217,12 @@ Parsed parse_console(const std::wstring& path, std::vector<std::wstring>& parts)
191 parts.clear(); 217 parts.clear();
192 if (drive == Drive::Scratch) { 218 if (drive == Drive::Scratch) {
193 parts.push_back(kScratchDir); 219 parts.push_back(kScratchDir);
220 parts.push_back(scratch_run());
194 const std::filesystem::path overlay = roots().overlay; 221 const std::filesystem::path overlay = roots().overlay;
195 const DWORD last_error = ::GetLastError(); 222 const DWORD last_error = ::GetLastError();
196 std::error_code ec; 223 std::error_code ec;
197 if (!overlay.empty()) std::filesystem::create_directories(win32_io_path(overlay / kScratchDir), ec); 224 if (!overlay.empty())
225 std::filesystem::create_directories(win32_io_path(overlay / kScratchDir / scratch_run()), ec);
198 ::SetLastError(last_error); 226 ::SetLastError(last_error);
199 } 227 }
200 const size_t floor = parts.size(); // ".." may not climb out of the drive's own root 228 const size_t floor = parts.size(); // ".." may not climb out of the drive's own root
@@ -226,7 +254,7 @@ Parsed parse_console(const std::wstring& path, std::vector<std::wstring>& parts)
226 if (!flush()) return Parsed::Refused; 254 if (!flush()) return Parsed::Refused;
227 // The overlay's own folders are not part of the title's GAME: tree: hidden from its listings (internal_dir) and 255 // The overlay's own folders are not part of the title's GAME: tree: hidden from its listings (internal_dir) and
228 // refused as an explicit path too, in every spelling the loop above normalises (case, slashes, "." and ".."). 256 // refused as an explicit path too, in every spelling the loop above normalises (case, slashes, "." and "..").
229 // T: still names the scratch folder: its first part is pushed above, not parsed from the title's path. 257 // T: still names the scratch folder: its first two parts are pushed above, not parsed from the title's path.
230 if (drive == Drive::Game && !parts.empty() && internal_dir(parts.front().c_str())) return Parsed::Refused; 258 if (drive == Drive::Game && !parts.empty() && internal_dir(parts.front().c_str())) return Parsed::Refused;
231 return Parsed::Console; 259 return Parsed::Console;
232} 260}
@@ -243,7 +271,7 @@ std::filesystem::path disk_path(const std::filesystem::path& root, const std::ve
243 271
244bool drive_root(const std::wstring& path, const std::vector<std::wstring>& parts) { 272bool drive_root(const std::wstring& path, const std::vector<std::wstring>& parts) {
245 size_t prefix_length = 0; 273 size_t prefix_length = 0;
246 return parts.empty() || (parts.size() == 1 && console_drive(path, prefix_length) == Drive::Scratch); 274 return parts.empty() || (parts.size() == 2 && console_drive(path, prefix_length) == Drive::Scratch);
247} 275}
248 276
249struct Target { 277struct Target {
@@ -682,6 +710,11 @@ std::filesystem::path overlay_dir() {
682 return g_overlay_dir; 710 return g_overlay_dir;
683} 711}
684 712
713std::filesystem::path scratch_dir() {
714 const std::filesystem::path overlay = overlay_dir();
715 return overlay.empty() ? overlay : overlay / kScratchDir / scratch_run();
716}
717
685// gta6rt --trace FILE: a failed open of a guest path goes to the startup trace as a "file_open_failed" event (the 718// gta6rt --trace FILE: a failed open of a guest path goes to the startup trace as a "file_open_failed" event (the
686// path the title passed, the Win32 error, the caller as module+RVA), so a boot that stops on a missing or refused 719// path the title passed, the Win32 error, the caller as module+RVA), so a boot that stops on a missing or refused
687// file names it. Failures only, and at most 256 of them, so a title probing many optional files can't fill the file. 720// file names it. Failures only, and at most 256 of them, so a title probing many optional files can't fill the file.