I wrote https://github.com/chenxiaolong/MSD for exactly that. It's a small wrapper around the Linux kernel's mass storage emulation support (CONFIG_USB_CONFIGFS_MASS_STORAGE). It can emulate a read-only optical drive, a readable disk, or a writable disk.
It is compatible with both older devices that configure USB via init scripts and newer devices that use Android's USB gadget HAL, but it does require Android 11+.
It is compatible with both older devices that configure USB via init scripts and newer devices that use Android's USB gadget HAL, but it does require Android 11+.