CompanionLink does this when you request USB synchronization in your Android application: it cleans the data to SD, then exports the SD as storage ("drive") on the USB device, and then expects the user to manually signal the android when completed PC using SD and then turn off SD export to USB again. Although the CompanionLink application can be very frustrating, at least that part is (pretty much) reliable.
Unfortunately, I do not know the technical details, it is quite possible that I need to find out them in one of these months. If you can't get any relevance to Android docs, perhaps you could explore what CompanionLink does for android to implement this. The sequence described above is when it is configured to synchronize via USB from a PC to the desktop (PC).
Aside, it seems that the reason for this highly complicated process is that accessing the SD SD card directly and at least the currently used FAT FS card can only support one client: the phone itself or USB. imo would be extremely helpful if shared access to the SD was possible, but that would probably require deep android changes.
source share