Flash Media block driver problem!
From: Jinu M.
Date: Thu Apr 01 2004 - 05:11:18 EST
Hi All,
We are developing a block device driver (2.4.x kernel) for Flash Media devices over one of our storage media controllers. I should admit that this is the first time we are developing a block device driver under Linux.
Sorry if the question becomes too obvious to some.
We are facing a peculiar problem. If the flash media card had been formatted under Linux (either ext2 or FAT) the card was mounted successfully and we could read its contents. However if the card had never been on a Linux box, the file system in the card was not recognized properly (Error: VFAT bogus partition). If we format the card under Linux just once with FAT, then it will continue to work for Windows and Linux.
We have been able to figure out why the problem actually occurs. The reason is that Linux (our driver?) does not recognize several partitions in a single FAT12/FAT16 Flash Media card. According to the FAT12/FAT16 file system, the card should have a valid Master Boot Sector in the first logical sector. This master boot sector indicates how many partitions are in the disk and the start and end addresses along with their respective size. FAT12/FAT16 disks must also have a Partition Boot Sector. The partition boot sector contains the parameters of each partition.
Brand new SM or SD cards come pre-formatted with a FAT12/FAT16 file system, which includes a Master Boot Sector and one Partition Boot Sector for one single partition. Linux does not recognize this partitioned card with just one active partition. Actually, when you format a card with FAT12 or FAT16 under Linux, the OS creates one single partition but without a Master Boot Sector. That is, the first logical sector contains the Partition Boot Sector instead of the Master Boot Sector.
Windows does not have a problem reading cards without a Master Boot Sector as long as they have a valid Partition Boot Sector. That is why once you format a card with 'mkfs -t msdos /dev/ourdev' or similar command under Linux, the card will continue to work under Windows and Linux as well.
However, this behavior is not acceptable for our customers since Digital cameras do not recognize Flashmedia cards after they have been formatted under Linux (with our driver). Besides, end customers do not want to format the cards before they can use them under Linux. For instance, a customer buys a new card and takes some pictures with a digital camera and then inserts it in our reader. This will force the user to format the card in order to be able to use it with Linux, therefore destroying all its data.
We are *not* doing a "register_disk()" and "struct gendisk" structure in our driver right now. This is a Flash Media device which should not be partitioned. Is a register_disk() call still mandatory? Are we missing out something in the driver?
Thanks,
-Jinu
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/