SuperFloppyFormatter returning FAT32 for anything over 512 MB?

不打扰是莪最后的温柔 提交于 2019-12-13 06:06:59

问题


I am using the de.waldheinz.fs libraries in relation to the Android jobb tool, and I came across something that seems rather bizarre. In the file de.waldheinz.fs.fat.SuperFloppyFormatter.java:304 I find this:

public static FatType fatTypeFromSize(long sizeInBytes) {
    final long sizeInMb = sizeInBytes / (1024 * 1024);
    if (sizeInMb < 4) return FatType.FAT12;
    else if (sizeInMb < 512) return FatType.FAT16;
    else return FatType.FAT32;      
}

FatType here is the enum de.waldheinz.fs.fat.FatType, but the implementation is straightforward enough here. My issue really pertains to the line else if (sizeInMB < 512) return FatType.FAT16;, but the check for FAT12 is equally bothersome.

The maximum size supported by a FAT12 drive is 32 MB, and for a FAT16 drive is 2 GB. Why is this library imposing these limits at 4 MB and 512 MB? It appears that the author may have based this on a rather naive understanding of how FAT12 and FAT16 work. < 4MB would of course be <= 4095 KB. 4095 being 0xFFF in hexadecimal, or 1111 1111 1111 in binary...this effectively represents 12 bits...

I'll admit that I don't know much about FAT myself (I still don't fully understand sectors vs clusters, how the total available size is calculated, etc.). Perhaps someone who better understands these things could confirm if there's a technical reason why this implementation should be considered "right"? Because it looks like the exact cause for my problems.

Thanks!


回答1:


FAT12 is only 16MB, not 32MB.

Probably the author is checking the number of clusters which are:

For FAT12: 4086 (cluster size 0.5 - 4 KB)

For FAT16: 65526 (cluster size 2 - 32 KB) (not clear why he's checking with 512 then).

For FAT32: ~268,435,456 (cluster size 4 - 32 KB)

Details here: http://www.pcguide.com/ref/hdd/file/partSizes-c.html

Report the issue in that library ;)




回答2:


The larger that one makes a FAT cluster, the more inefficient the filesystem becomes with small files. Moving up to the next FAT size is an effort to balance efficiency.



来源:https://stackoverflow.com/questions/18924872/superfloppyformatter-returning-fat32-for-anything-over-512-mb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!