How to split a big XCI/NSP file to store it on a FAT32


splitting

Problem statement

Backing up a Switch game cartridge to XCI/NSP is fine and well. When backing up to a FAT32 partition, one ends up with a bunch of files, named 00, 01, etc1.

I made the tragic mistake reasonable choice of combining them to a single big file for archival purposes (cat 0* > backup.xci). When recently the time came to put the backup game on an SD card for reinstallation, I tripped over the “file too large” problem with FAT322.

This post explains how to split up a large XCI/NSP back to smaller files, and how to properly place it on a FAT32 partition (using nothing but Linux) so it can be immediately installed with something like DBI or Tinfoil.

Background (skip if in a hurry)

While plenty of “homebrew” things for the Switch are somewhat documented, most of it is in a language I find quite challenging to parse.

Worse yet, some details aren’t documented at all… and are instead encoded in source code of various homebrew utils3.

So while it’s rather trivial to use split utility (from coreutils) for file splitting, if you split the files at the maximum size (4294967295) or even at arbitrary multiples of 512 bytes (say, 4294966784), it will not work4.

The correct split size seems to be – tada! – 4294901760. I found it out by searching for 01 file on the SD card, and then looking at the size of one of the associated 00 files:

$ cd Nintendo/Contents/registered/00000070/$hash.nca
$ ls -l 00
-rwxr-xr-x 1 wejn wejn 4294901760 Apr  8 18:46 00
$ 

Another bit that’s poorly documented is the way Switch recognizes these split-files-in-a-directory as one big file. Answer: FAT archive bit set on the directory.

So if you dump a bunch of files named 00, 01, etc into a directory, and then set an FAT archive bit on it, voilà, Switch sees that directory as a single file.

Clever, really.

The way to set the archive bit from the linux command line? Using the fatattr utility (apt install fatattr)5. But again, reference to fatattr is not really easy to find either.

Solution

As described in the background section, splitting a big ass XCI/NSP file under Linux – to fit on a FAT32 partition (and be installable via DBI/Tinfoil) – is actually quite simple6:

# Move to target
cd /media/sdf1  # ← path to sd card's root
mkdir roms
cd roms

# Make "xci" directory, and set archive bit
mkdir some_game.xci
fatattr +a some_game.xci  # apt install fatattr if you don't have it

# Split up big ass xci to properly sized chunks
cd some_game.xci
split --verbose -a 2 -b 4294901760 -d /path/to/big/ass/game/file.xci ''

Closing words

I wouldn’t mind having most of the Switch stuff documented in a unix geek friendly fashion. Hell, I might even write up some of it myself.

In the meantime, if you trip over some superb documentation of Switch internals (on the level of this “guide” or better), would you mind sharing a link?

  1. Could also be a.xc0, a.xc1, or a.xci.00, a.xci.01, etc; depending on where it comes from.

  2. Because FAT32 is limited to 4GiB (232-1 bytes to be exact)

  3. Search around for nx xci split and you will find a bunch of tools. Many of them are windows-only, or at least targeting windows.

  4. Ask me how I know.

  5. You can do without fatattr. In Hekate’s Tools tab is a Fix archive bit that will fix the archive bits on your entire SD card. If you don’t mind the extra step.

  6. The example is for XCI, but the exact same recipe holds for NSP.