FAT FS on 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.
Post Reply
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

FAT FS on SD cards

Post by Chilly Willy » Mon Oct 20, 2014 9:16 pm

A number of us have SD adapters for the DC now, but all we've had in the official repo is an EXT2 filesystem. I'm used to working with ff, the FatFS from ELM-Chan. It has a license that is compatible with KOS, and is fairly good, so I decided to port it to the DC.

The archive contains two folders - libsdfs, which is the wrapper for ff, and sdfs_demo, which shows how to use it.

http://www.mediafire.com/download/cdjmj ... ibsdfs.zip

It's pretty simple. You make the following protos in your project, and add -lsdfs to your link objects.

Code: Select all

extern int fs_sd_init(void);
extern int fs_sd_shutdown(void);
Call fs_sd_init() to initialize the filesystem and you're all set. It inits the SD interface, mounts the first valid FAT partition, mounts the volume, and adds a virtual filesys for "/sd". As long as it succeeds, now you can just call the normal KOS file system calls with "/sd". When you're done, call fs_sd_shutdown() and it will close all open files and directories, unmount the volume, and shutdown the SD interface.

Supported vfs calls:
open
close
read
write
seek
tell
total
readdir
rename
unlink
stat
mkdir
rmdir
fcntl

I also added support for timestamps, so be sure your clock is set right. :D

The demo uses a simple file requester to allow you to select a file from the SD. It then copies that file into the root directory as "test_copy.bin" so that you can check how writing works. Press up/down to go through the list (left/right to move a page back/forward), A to select a file or enter a subdirectory, B to cancel (and not copy anything), and Y to go back one directory level.

Please let me know if you find any bugs.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 574
Joined: Fri Jun 18, 2010 9:29 pm
Has liked: 0
Been liked: 0

Re: FAT FS on SD cards

Post by PH3NOM » Tue Oct 21, 2014 10:54 pm

Glad to see you are still around Chilly!

Not sure when I'll get some time, but I will probably take a look at this at some point.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

Re: FAT FS on SD cards

Post by Chilly Willy » Wed Oct 22, 2014 12:33 am

I took a break from DC stuff for a while, but I'm back again. I always cycle through the consoles periodically to keep from getting burned out. :)

I need to update my Doom port. Maybe use the v2 of Chocolate Doom so folks can also play Stryfe and Heretic.
law56ker
DCEmu Cool Poster
DCEmu Cool Poster
Posts: 1024
Joined: Wed Oct 17, 2001 7:44 pm
Has liked: 0
Been liked: 0

Re: FAT FS on SD cards

Post by law56ker » Wed Oct 22, 2014 1:08 am

Welcome back Chilly, yes I'd love to see new dreamcast updates and maybe surprises!
Post Reply