The emulated FAT is flat in structure - its main idea is to allow files that are not really files (eg. dynamically generated or formatted data) to be presented to the USB-MSD host so that it can read it as if it were a file.
In order to do this each virtual file requires a bit of information so that its details can be returned and its content generated when requested. At some point there will not be enough memory to do this for a large number of files.
Yeah, the more I study the code, the more I was coming to this conclusion myself. It's great for the purpose you intended it for, but I'm thinking it may not be the right fit for my use. Which is fine, it just means I'll have to write a bit more code. :-)
In your case, when you have an SD card attached, I don't see exactly why you need to emulate its content when it can be so large. Why doesn't the USB-MSD directly access it?
In my case, the SD card isn't really attached to the Teensy. I've just been testing with a SD card in the Teensy, to get the USB MSD side of things ironed out, and working.
The actual media content is stored on a USB hard drive, that is connected to my Raspberry Pi, it needs to be this way, to satisfy other requirements of my project (i.e. I am serving the same media content up via Plex media server, to my kids and their devices, directly from the Raspberry Pi).
So, what I am aiming to do with the Teensy, is build a sort of media bridge, that can be connected to my car stereo on one end (via USB mass storage device, as that is the only input I have for the stereo, and I want to retain my stereo controls over the media, i.e. steering wheel controls to advance to the next song etc), and then on the other end, I was intending to use GPIO from the Teensy to the Raspberry Pi, to access the same media content that is already available over there, from the USB hard drive.
At this point, I'm leaning towards modifying your code, and hooking into the calls between the USB MSD layer, and the FAT layer, and conveying those across the GPIO, to the Pi, where I can write a separate FAT emulation layer, to republish the hard drive's contents. Or, if it's possible, maybe I can get low-level access to the drive, and just proxy the MSD requests back and forth. I've got to do some more research on the Pi side of things, and see what Linux will let me do with the attached drive. Either way, I'm pretty sure I'm going to do the FAT emulation on the Pi, because it has 1 GB of ram, and I have a bit more breathing room over there. :-)
As usual, thanks for the great info,
Chris