-
Notifications
You must be signed in to change notification settings - Fork 155
bdm MBR add support for VBR #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@fjtrujy @uyjulian @rickgaiser |
|
bump! this will help with a lot of things and solve a lot of problems |
|
The only job of the MBR driver is to split 1 single block device (a USB stick for instance), into 1 or more smaller block devices (partitions). This can also be done recursively, for instance with extended boot records (EBR). What exactly is the role of the VBR, and by do we need it in our case? I would expect a USB stick to be formatted as:
Then inside each partition (with or without VBR ?) I would expect the FAT32/exFat driver to be able to process the contents. Does the MBR driver fail to properly find all available partitions? |
MBR driver is doing some partitions checks in part_driver_mbr.c which are not correct and trying to mount invalid MBR.
Think of it as just one single partition right at start and with as much sectors as the device.
This the case of VBR here pretty much, which is making a lot of devices invalid.
Correct but not everything that looks like MBR is actually MBR.
This is not main problem right now.
It's even worse! MBR driver is parsing bad and invalid MBR and even trying to mount them! This is because it thinks all MBR are correct as long as they have MBR signature (two bytes at the end of the sector) but it so happens ironically that a VDR might have it too.
The exfat fails to process the partition because it's invalid and it will fail somewhere. Or worse it will make it work sometimes but with very bad max sector count etc (whatever was random garbage in there).
MBR code had a few bugs which make it process invalid or random partitions sometimes. I have over 8 devices which were formatted by Windows 10/11 all of them having VDR and the bdm drivers acting funny. Depending on what garbage is in partition data they sometimes randomly mount stuff and will corrupt everything. |
|
@rickgaiser here is an example of a perfectly VALID usb device working on older drivers, on Windows and everywhere else. Guess what partitions is MBR driver trying to mount which the exFat drivers later refuse them. |
|
Maybe another case here? |
|
Assuming a block device with no partitioning, just FAT32/exFat directly, the intended parsing of block devices is:
The root cause I think is the MBR driver mounting the exFat partition, becouse of the VBR that looks like an MBR, but isn't. Instead of failing, your proposed solution lets the MBR driver mounts the exfat partition, and then creates another block device, with the exact same properties as the original block device: ps2sdk/iop/fs/bdm/src/part_driver_mbr.c Lines 103 to 112 in 1c6f598
Resulting in:
In theory this can cause an endless recursive loop, becouse what happens if the MBR driver is requested again if it can handle the newly registered block device? But I guess by luck/accident this psuedo block device will be handled by the exFat driver first. If the parsing of partitions was done properly, the entire ps2sdk/iop/fs/bdm/src/part_driver_mbr.c Lines 152 to 153 in 1c6f598
Would cause the MBR mount to fail. I think the only missing thing in the current MBR driver are the missing sanity checks for the partition table entries. Can you try with only the following changes?: The first check you already added, but the second check was only present in edit: Code above changed so that all 4 entries are valid. So instead of |
This the case we are trying to fix. They seem to be all failing.
MBR is trying to parse invalid parts and it's not even checking if they are valid or even if they were actually mounted at all.
where is the part which checks for FAT/exFAT? part_driver_mbr.c and part_driver_gpt.c do the check for MBR and GPT, where is FAT/exFAT done?
No, because mountCount is not a safe way to tell. It does not reflect if the mount actually worked. It just increases on every loop but the parts fail to register and then return valid(meaning bdm validated the driver as MBR which is incorrect because bdm is not even checking if the MBR is correct other than the signature bytes) which fails everything.
No, we need partitions checks at start because first we need to validate if this is real and legit MBR or not. This must be done before trying to do anything at all with your partitions. If there is exFAT driver than it defaults too after trying MBR and GPT, then the solution is to simply return -1 right after partitions_sanity_check_mbr. |
@rickgaiser |
That's wrong, lets fix that first. I think my proposed solution will do just that. Did you try?
That's actually what "BDM" should do. MBR and GPT are drivers, they could have been implemented in a separate irx module, but they are integrated into bdm for ease of use. It's done in bdm here: Lines 154 to 157 in 608331b
All registered driver are asked 1-by-1 if they can handle the a specific block device. The sequence depends on what driver is registered first, but in general this will result in MBR -> GPT -> exFat (if loaded). So from this loop, the sequence to try and mount a USB stick without MBR should be:
See the loop above. Each time a new block device is registered (a partition is also a block device), all filesystems (MBR, GPT and exFat) will be asked by the above loop if they can handle that block device. Again with the sequence MBR -> GPT -> exFat.
I think you're right and that's the best solution. Can you make and test the change? |
|
@rickgaiser where is the registered exFAT driver then that will handle return -1 for partitions_sanity_check_mbr? |
|
I don't think I understand the question...
The exFat driver is here:
Only the MBR driver will do MBR sanity checking. The exfat driver will only do exfat sanity checking. The VBR should just be some ignored piece of reserved data at the beginning of the exfat partition, right? |
What you call exFAT driver is FAT and exFAT driver support too? |
Yes, that's the one and only BDM exFat driver. I assumed you knew since you're trying to fix: "Latest bdm exFAT drivers fail". It's a port of fatfs: http://elm-chan.org/fsw/ff/00index_e.html
You're making a PR to ps2sdk so I assume you can compile ps2sdk and have it already. |
|
@rickgaiser think it's better now? Can't see why build is failing. |
bdm MBR add extra checks for invalid MBR (VBR)
This reverts commit c6d8c19.
This reverts commit afc3279.
This reverts commit c6d8c19.


Latest bdm exFAT drivers fail on some FAT32 drivers. Looks like bdm has forgot to add support for VBR.
On invalid MBR records it is trying to mount invalid partitions. This restores that functionality. Many of the such devices are formatted this way to bypass FAT32 max limit of 32GB in Windows.
Alternatively someone needs to add better support for VBR. Sometimes a VBR can be valid and not even have MBR signature in the end of first sector. For now this will do.
The original authors of bdm are welcomed to give their insight.
resolves DKWDRV/DKWDRV#82
Possible impacts OPL since a long time already?
resolves ps2homebrew/Open-PS2-Loader#1311
resolves ps2homebrew/Open-PS2-Loader#1295
resolves ps2homebrew/Open-PS2-Loader#1271
resolves ps2homebrew/Open-PS2-Loader#1493