PgrAm wrote:
When I said 'format' I really meant to say filesystem, meaning fat, ext2, etc. Sorry. I'll try to update the question.
The same driver deals with different sized disks, but a different driver is needed when the filesystem is different.
No problem, sorry for my confusion. Typically, a file system format has some kind of "magic" marker - a particular value or sequence of bytes, at a particular offset from the start of the disk. Eg for ext2, see
https://www.nongnu.org/ext2-doc/ext2.html#superblock - the "magic number" in the superblock allows you to identify an ext2 filesystem. (Look for the bytes 0x53 0xEF at offset 1024+56 on the disk/partition).
So, either, you have a central resolver which looks for various of these markers, and dispatches the appropriate driver; or, you poll each driver in turn to see if it can recognize the filesystem on the device. Each method has particular benefits; for example, polling each driver in turn means you can keep the logic for identifying the filesystem within the driver, but it means you need to have drivers already loaded.