libfatfs - FAT16 & FAT32 for SD Cards

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by BlueCrab »

SWAT wrote:but I just wanted to use KOS standard for all file systems.
Well, technically, this isn't a standard part of KOS either. It interfaces more nicely with the current version of KOS than the old FatFs port, but it still isn't a standard part of KOS. Currently, the only officially supported filesystem in KOS for SD cards is the one provided by libkosext2fs (which is obviously not FAT16/FAT32). Blame Microsoft's patents on long filename support in FAT32 for why I can't include a FAT filesystem driver in KOS that is of much use to most people.

Just wanted to clear that up before there's any sort of misunderstanding. :wink:
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by SWAT »

Yep i understand it, of course. I mean KOS style implement :)
Image
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by BB Hood »

Okay I updated the library. Found the bug that was causing problems for you SWAT and fixed it. It had to do with not getting the right start cluster of the file/folder.

I *also* had to take out the cluster list because when you open a large file(780 mb)... the cluster list takes up too much memory and crashes the dreamcast. Replaced it with int holding the starting cluster and an int holding the end cluster. Not as fast but saves ton of ram.

I would say that the only thing that really got slowed down because of this change is writing.

There are still some speed optimizations I can make...just wanted to put something that was working and usable. Let me know if you encounter anymore bugs.
Last edited by BB Hood on Tue Oct 22, 2013 6:49 am, edited 1 time in total.
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by SWAT »

Are you sure that the problem was just that? I'm tryed to open only small files and directories.
Image
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by BB Hood »

They are two different bugs. Your bug had to deal with me not taking into account the "higher" bits of the starting cluster for each file/folder. I first started out with getting my library to work with only FAT16 so I didn't have to worry or think about it.

For example this is the struct representing a file/folder entry:

Code: Select all

struct fat_dir_entry 
{
    unsigned char FileName[9];  
    unsigned char Ext[4];       
    unsigned char Attr;         
    unsigned char Res;        
    unsigned char CrtTimeTenth; 
    unsigned short CrtTime;    						   
    unsigned short CrtDate;    
    unsigned short LstAccDate;  
    unsigned short FstClusHI;   /* The high 16 bits of this entry's first cluster number. For FAT 12 and FAT 16 this is always zero. */
    unsigned short WrtTime;    
    unsigned short WrtDate;    
    unsigned short FstClusLO;   /* The low 16 bits of this entry's first cluster number */
    unsigned int FileSize;     
};
My library used to calculated the starting cluster like so: Starting cluster = var.FstClusLO;
This always worked for FAT16 but not FAT32. Changed it to : Starting cluster = ((var.FstClusHI << 16) | var.FstClusLO);

Sorry about my previous post being confusing. I edited it to make it more clear.
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libfatfs - FAT16 & FAT32 for SD Cards

Post by SWAT »

Now it is clear. Maybe I'll try it later and compare with my implementation in real case.
Image
Post Reply