Paths

Top-level directories are drives; global lookup accepts data-relative paths:

Guest pathData-directory path
drive:/filedrive/file
/fileroot/file

IFileSystem: mount-relative /; reject drive prefixes and escaping ... Normalize separators/.; case-sensitive. Missing root/ is virtual until mutation. Saves use save/<type>, and an Account save its user's save/user.<uid> (32 hex digits, users/users.ini's, Usage). The first user's, while it has no folder, is played where an older version left it: save/user, the one Account save before there were users, else a nonempty save/system (Deprecations). With save/user and its folder both there the game stops and leaves both, for the player to keep one.

save_layout=global (the default) keeps the saves apart from the game, in the data folder's save/ (users/'s folder), as the console keeps them:

SaveFolder
Accountsave/user.<uid>/<title ID>/
Devicesave/device/<title ID>/
BCATsave/bcat/<title ID>/
Cache storagesave/cache/<title ID>/<index>/
System, SystemBcatsave/system/<save ID>/, save/sysbcat/<save ID>/

Temporary storage stays the game's save/temp, and every save of a program with no title ID of its own (a homebrew's) stays in its own folder. save_layout=game keeps each in the game's save/<type> as above. Each of those folders is a graft of the index, writable: the ones there at startup are indexed then (fs_saves_init, after the users), and one made later is made empty, so nothing is enumerated after startup (fs_tree_graft_new). A save only the other layout holds is played where it is, the game's log and stderr saying once a run where it goes; both holding one stops the game, which leaves both.

An Account, Device or BCAT save's Commit writes its note, <its folder>.version beside it on the host and out of every mount: program= (the title ID that ran, an update's own), version= (its content meta's, when known) and display=. Opening a save whose note names a newer version of the same game, by the content meta versions when both are known, else by the numbers of the display versions, warns once with both, and the crash, svcBreak and BRK reports repeat the line (fs_save_report).

A save is kept as the console keeps one in a folder of the host (its DirectorySaveDataFileSystem). Its folder holds 0/, the save's last commit, 1/, the copy the game works in and the only one it sees, and the file snx-journaled, which says the folder is laid out so:

WhenWhat happens
The save is opened1/ becomes a copy of 0/: what a run wrote and did not commit is gone. With no 0/, a commit was cut short: it is finished from 1/, and the log says so
The game writesin 1/ alone
Commit, CommitSaveDatarefused (WriteModeFileNotClosed, the file named in the log, which the SDK stops the game on) while a file of the save is open for writing. Else 0/ is renamed _/, _/ becomes a copy of 1/ and is renamed 0/

The first rename is the commit. A game that dies before it leaves the last commit; one that dies after it leaves 1/ whole and no 0/, which the next open or commit finishes. 0/ is never written in place, so the game's death at any moment leaves the last commit or the new one, never part of a save (filesystem_save_kill kills it at each step). Nothing is synced to the disk: a host that loses power during a commit, while the system still holds the bytes of 1/, can lose both. Each open and each commit copies the save whole. A save opened while it is open shares the one working copy (the console refuses the second mount; here save/system can be several saves' folder). Temporary storage has no commit and is written where it is. What the folder holds beside 0/, 1/ and snx-journaled (a save pasted into it by hand) the game does not read: the log names the first such entry once a run for each save type, and that a save's files go in 0/. A commit of several saves at once (nn::fs::Commit of a list of mount names) has no native answer: its SDK code asks fsp-srv, and sm stops the game.

A save's folder with files in it and no snx-journaled is one an older version kept, the game's own files in the folder itself (a game's own folders may be named 0 and 1). It is played where it is and written in place, so a game killed while it saves there leaves part of a save; the log names the folder once a run for each save type, the launcher lists it, and Settings > App > Move Old Files moves its files into 0/ and writes snx-journaled (Deprecations).

Init rejects scan/stat errors, symlinks/junctions, regular-file hardlinks, special files and invalid names, and the game stops with the path it stopped at and why in the line before (fs: could not index the game's files in ...: .../sdmc/shared is a symbolic link, which the index follows only as a folder at the top of the game's data folder). A mod's RomFS refused so is left out, the line saying why.

One link is followed: a symbolic link (on Windows a junction too) to a folder at the top of the data folder, such as an sdmc/ or a save/ kept on another disk or shared with another program. The folder it points at is indexed in its place as a writable graft (link_folder), so the game reads and changes the files where they are. Still refused: a link anywhere below the top, in the data folder or in the folder a link points at (nothing scanned can lead back, so there is no cycle to detect), a link to a file, a link to nothing, and a link to a folder the index already holds, to one in it or around it (the data folder, another link's folder, a save's or the RomFS's graft): two names for one file would each keep a size of their own, which is why hard links are refused. Nothing removes or renames the link or the folder it points at: fs_tree_remove on it empties the folder, and removing the game's folder (snx_remove_tree) takes the link and leaves the folder. mods/ is read apart from the index: as a link it is read through, but a mod that is a link, or whose exefs/ or romfs/ is one, is left out, a line in the log naming it. Tree limits: 4096-byte path buffers including NUL, 256 directory levels below the data root. IPC requests allow 0x300-byte paths excluding NUL. Host limits also apply.


Made from docs/platforms/nx/filesystem.md at 69237645142c. GPL-3.0-or-later.