I want to preface this by saying that the following is what worked for me. I can't guarantee it will work for you, but I wanted to document it here for the future in case I need it again or someone else finds it useful. I take no responsibility the possibility of this messing up your device even worse or not doing anything at all. I don't really understand why this worked for me.
First of all, reboot the device so that you're freshly in the TWRP recovery when you start executing the commands. The device seems to randomly reboot when in this state and it wouldn't be nice if that happened while re-creating the partition, so give yourself as much time as possible.
You will need adb on your PC to follow these steps. Explaining how to acquire it is out of scope for this guide, but I'm sure you can find instructions for your operating system online.
Note that you should not include the $
and #
when running the commands!
Once TWRP's splash screen appears on the device, quickly run this command on your PC:
$ adb shell
Make sure you start the adb server with the right permissions before you try this as starting it up takes some time.
Following that, run this (in the adb shell):
# mke2fs /dev/block/mmcblk0p30
This formats the userdata partition. Let this finish. For me, the device rebooted right after, but you may need to do it manually.
After the reboot, you should be booting back into Android assuming you have a working Android ROM on the device. If it seems to be stuck, wait a few minutes. If it still seems to be stuck, try giving the power button a short press. This worked for me for some reason. After this, set up the device, go into settings, enable USB debugging, and run this on your PC:
$ adb reboot bootloader
After this, flash TWRP 2.8.1.0 (Not sure whether this is necessary):
$ sudo fastboot flash recovery twrp-2.8.1.0-flo.img
Boot into it and observe it boot Android instead for some reason.
$ sudo fastboot reboot recovery
Reboot back into the "bootloader" (fastboot):
$ adb reboot bootloader
Now flash the latest TWRP again.
$ sudo fastboot flash recovery twrp-3.5.2_9-0-flo.img
And it should work. However, in my case, I have to re-flash TWRP after every boot of Android.
I'm not sure whether it is necessary to flash the older TWRP version for this to work, but I thought I'd include it just in case.
Credit goes to this forum post for giving me a vague outline on what to do: https://forum.xda-developers.com/t/q-flashed-twrp-and-now-cant-find-ext4-filesystem.3096502/ (archived version: https://web.archive.org/web/20210503093052/https://forum.xda-developers.com/t/q-flashed-twrp-and-now-cant-find-ext4-filesystem.3096502/)