Skip to content

SD card FAT format with multipartitions are not compatible with PC #5999

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

Closed
JaniSuonpera opened this issue Feb 2, 2018 · 10 comments · Fixed by #6074
Closed

SD card FAT format with multipartitions are not compatible with PC #5999

JaniSuonpera opened this issue Feb 2, 2018 · 10 comments · Fixed by #6074
Assignees

Comments

@JaniSuonpera
Copy link
Contributor

Description

  • Type: Bug
  • Priority: Major

Bug

Target
K64F

Toolchain:
GCC_ARM

mbed-os sha:
(git log -n1 --oneline)
caeaa49 (HEAD, tag: mbed-os-5.7.4, origin/mbed-os-5.7) Merge pull request #5954 from ARMmbed/release-candidate

Expected behavior

  • SD contains two partition which can not be read with PC but target K64F is still able to read/write SD card without any problem.

Actual behavior

  • SD parts partition type is unknown. (check with PC e.g. Linux program gparted )

Steps to reproduce
Initialize BlockDevice point to SD e.g. with
BlockDevice *bd = storage_selector();

// Create a partitions
MBRBlockDevice::partition(bd, 1, 0x83, 0, 10241024);
MBRBlockDevice::partition(bd, 2, 0x83, 1024
1024, 210241024);

// Create the block device that represents the partition
MBRBlockDevice part1(bd, 1);
MBRBlockDevice part2(bd, 2);

// Format the partitions with a FAT filesystem
FATFileSystem::format(&part1);
FATFileSystem::format(&part2);

Check SD card with PC.

@cmonr
Copy link
Contributor

cmonr commented Feb 2, 2018

@JaniSuonpera, are you attempting to access this partitioned micro SD card in Windows? Afaik, the Windows driver does not support viewing partitioned removable media.

If you're attempting to view this in Linux, could you provide system information on the machine?

@geky

@JaniSuonpera
Copy link
Contributor Author

@geky I have Lenovo desktop Linux (Ubuntu 16.04 LTS) PC. I have tested this with external (https://www.transcend-info.com/Products/No-331) and internal SD card reader. Result is same after formatting with K64F.

If I create partitions (FAT32) with Linux program gparted then Linux filemanager is able to mount both partitions from SD card. Same is case also with Windows 10 (Lenovo T460s) laptop with external SD card reader (https://www.transcend-info.com/Products/No-331). Formatting available partitions from SD card with mbed-os makes SD unreadable with PC. Linux shows that partition type is unknown.

There seems to be some issue to use MBRBlockDevice. If initialize CD card with PC to FAT32 single partition mode and use only BlockDevice pointer for format then SD card is readable with PC. I use MBRBlockDevice pointer for format then SD card is unreadable with PC.

FYI @JanneKiiskila

@geky geky self-assigned this Feb 13, 2018
@geky
Copy link
Contributor

geky commented Feb 13, 2018

Hi @JaniSuonpera, sorry for the delay.

It looks like there was a regression in the FAT filesystem regarding extra MBR blocks. Does #6074 fix your issue?

@JaniSuonpera
Copy link
Contributor Author

Hi @geky, I tested #6074. Formatting single partition FAT32 SD card is working fine.

For dual partition it depends, which kind partitions exists in SD card. If there are two FAT32 primary partitions then after format there are two FAT16 primary partitions. If there is one FAT32 primary partition and extended partition, which contains one FAT32 logical partition, then after format partition one is FAT16 and partition two is unknown type.

If create partitions with MBRBlockDevice::partition and format then both will be FAT16 primary partitions.

How I can create FAT32 partitions with MBRBlockDevice::partition? How about logical partitions? It is logical partitions supported?

@geky
Copy link
Contributor

geky commented Feb 13, 2018

Logical partitions are currently not supported. Though it would be a good idea to error rather than allowing the filesystem to overwrite logical partitions. I added a check for logical partitions to #6074.


As for why you can't create a FAT32 partition: it's not allowed. After partitioning your block device the number of clusters are small enough that they fit in FAT16, so it must be FAT16. There's actually no other identifier that marks the difference between the filesystems other than the cluster count.

Try formatting the FAT filesystem on your PC, it should still show up as FAT16.

Fortunately, FAT12/FAT16/FAT32 are all handled the same by host OSs. So you should be able to mount and use the filesystem without worrying about the difference between FAT12/FAT16/FAT32.

I wouldn't think of these as three different filesystems, because in order to support the full range of block device sizes you need to support all three.

@JaniSuonpera
Copy link
Contributor Author

I approve #6074. Please release it next mbed-os 5.7.X release.

These limitations must document somewhere.

@geky
Copy link
Contributor

geky commented Feb 14, 2018

Noted, I made another pr to mention this: #6095.

This patch has already been merged, so you can expect it on 5.7.6.

@JanneKiiskila
Copy link
Contributor

Thanks @geky for good & quick support!

@geky
Copy link
Contributor

geky commented Feb 14, 2018

Also thank @cmonr and the maintainers for the quick turnaround on prs : )

@cmonr
Copy link
Contributor

cmonr commented Feb 15, 2018

@geky It's easy when the PRs are small and well documented :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants