Announcing libkosfat
- BlueCrab
- 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:
Announcing libkosfat
After all these years of KOS not having support for reading/writing FAT filesystems on SD cards and hard drives on g1ata (at least not in the canonical repository), I've finally decided it's time to rectify that situation. Over about the last week or so, I've been working on putting together a FAT library, and it's at a state where I've decided it's time to push it to the repository. The library is currently read-only, but that should hopefully be fixed in the very near future as I get time to finish up some of the loose ends.
The libkosfat library is completely custom written for KOS, and isn't based on any other FAT filesystem libraries. Why you may ask? Because when have I ever been known to take the easy way out of anything when it comes to KOS?
I've only very minimally tested the VFS functionality in the library at this point (and not actually with an SD card or a g1ata device at that), so if anyone would like to help test it out, I'd appreciate it. The interface is almost identical to libkosext2fs, so the sd/ext2fs example should be pretty easy to adapt for anyone who wants to help test things out.
The libkosfat library is completely custom written for KOS, and isn't based on any other FAT filesystem libraries. Why you may ask? Because when have I ever been known to take the easy way out of anything when it comes to KOS?
I've only very minimally tested the VFS functionality in the library at this point (and not actually with an SD card or a g1ata device at that), so if anyone would like to help test it out, I'd appreciate it. The interface is almost identical to libkosext2fs, so the sd/ext2fs example should be pretty easy to adapt for anyone who wants to help test things out.
- ThePerfectK
- Insane DCEmu
- Posts: 147
- Joined: Thu Apr 27, 2006 10:15 am
- Has thanked: 27 times
- Been thanked: 35 times
Re: Announcing libkosfat
This is seriously perfect timing for me. Thanks so much for this!!
Still Thinking!~~
- BB Hood
- DC Developer
- Posts: 189
- Joined: Fri Mar 30, 2007 12:09 am
- Has thanked: 41 times
- Been thanked: 10 times
Re: Announcing libkosfat
Made an attempt at this 6 years ago. Got it working for the most part. Here is the archived repo: https://github.com/andressbarajas/libfatfs
Feel free to use anything from it.
Feel free to use anything from it.
-
- DCEmu Webmaster
- Posts: 16373
- Joined: Wed Mar 14, 2001 6:00 pm
- Location: New Orleans, LA
- Has thanked: 103 times
- Been thanked: 90 times
- Contact:
Re: Announcing libkosfat
Very nice! Perhaps this will motivate me to finish up my new modded DC with a cleanly installed IDE connector.
It's thinking...
- Protofall
- DCEmu Freak
- Posts: 78
- Joined: Sun Jan 14, 2018 8:03 pm
- Location: Emu land
- Has thanked: 21 times
- Been thanked: 18 times
- Contact:
Re: Announcing libkosfat
Thanks for the new feature BlueCrab, much appriciated
I'll do some testing when I get time, but that probably won't be for a few weeks. I'll definitely be using this feature in my next project/s.
I'll do some testing when I get time, but that probably won't be for a few weeks. I'll definitely be using this feature in my next project/s.
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
- Protofall
- DCEmu Freak
- Posts: 78
- Joined: Sun Jan 14, 2018 8:03 pm
- Location: Emu land
- Has thanked: 21 times
- Been thanked: 18 times
- Contact:
Re: Announcing libkosfat
Actually, I have a bit of time to test right now. I started working on a basic program that uses a FAT formatted SD card, but I can't get it to compile. I've updated my copy of KOS and recompiled and I get the error "/opt/toolchains/dc/sh-elf/lib/gcc/sh-elf/4.7.3/../../../../sh-elf/bin/ld: cannot find -lkosfatfs". I copied the ext2 compiler library flag format, but it seems I'm wrong. What do I need to pass it?
Incase its something else, here's my code: https://github.com/Protofall/Homebrew-T ... P/fatTests
I'm also unsure what partition_type to check since there seems to be many (Near 100) FAT partition types according to wikipedia (However its much less if I choose to only support FAT32). I ask because for ext2 I only had to check "0x83" hence I think I'm missing something here.
EDIT 1:
I figured out its "-lkosfat" without the fs at the end. It compiles now.
EDIT 2:
When testing, function "fs_fat_mount()" throws an error/-1. My SD card is formatted as FAT32 and I can confirm it is plugged in correctly since another program I found can see the SD card and interact with it.
Incase its something else, here's my code: https://github.com/Protofall/Homebrew-T ... P/fatTests
I'm also unsure what partition_type to check since there seems to be many (Near 100) FAT partition types according to wikipedia (However its much less if I choose to only support FAT32). I ask because for ext2 I only had to check "0x83" hence I think I'm missing something here.
EDIT 1:
I figured out its "-lkosfat" without the fs at the end. It compiles now.
EDIT 2:
When testing, function "fs_fat_mount()" throws an error/-1. My SD card is formatted as FAT32 and I can confirm it is plugged in correctly since another program I found can see the SD card and interact with it.
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
- BlueCrab
- The Crabby Overlord
- Posts: 5652
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Announcing libkosfat
As the first post says, write support isn't in there right now. Right now, you're getting a -1 return from fs_fat_mount() because you're trying to mount it read/write.
As for the partition type, per Wikipedia, there's a lot of them that map to FAT: https://en.wikipedia.org/wiki/Partition_type . You're probably better off just not checking it, to be honest (as hopefully the underlying code would return an error if you tried to mount something that wasn't FAT).
As for the partition type, per Wikipedia, there's a lot of them that map to FAT: https://en.wikipedia.org/wiki/Partition_type . You're probably better off just not checking it, to be honest (as hopefully the underlying code would return an error if you tried to mount something that wasn't FAT).
- Protofall
- DCEmu Freak
- Posts: 78
- Joined: Sun Jan 14, 2018 8:03 pm
- Location: Emu land
- Has thanked: 21 times
- Been thanked: 18 times
- Contact:
Re: Announcing libkosfat
Oh of course, I wasn't thinking when I tried to mount it in rw mode. Good to know about the partition type thing tooBlueCrab wrote: ↑Sat Aug 10, 2019 8:56 am As the first post says, write support isn't in there right now. Right now, you're getting a -1 return from fs_fat_mount() because you're trying to mount it read/write.
As for the partition type, per Wikipedia, there's a lot of them that map to FAT: https://en.wikipedia.org/wiki/Partition_type . You're probably better off just not checking it, to be honest (as hopefully the underlying code would return an error if you tried to mount something that wasn't FAT).
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>
Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
- BlueCrab
- The Crabby Overlord
- Posts: 5652
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: Announcing libkosfat
So, as of a few minutes before writing this post, I've pushed mostly complete write support up to the repository (after a long afternoon of bug testing). There's only two small notes about the write support at the moment:
1. New files/directories can only be created with 8.3 names -- long file names aren't supported for creation yet (you should be able to open/write to existing ones just fine, though).
2. rename() support isn't implemented yet (although, I don't suppose that's really that big of a deal).
If anyone tests things and finds issues, please let me know!
1. New files/directories can only be created with 8.3 names -- long file names aren't supported for creation yet (you should be able to open/write to existing ones just fine, though).
2. rename() support isn't implemented yet (although, I don't suppose that's really that big of a deal).
If anyone tests things and finds issues, please let me know!
- These users thanked the author BlueCrab for the post (total 2):
- ThePerfectK • BB Hood
- ThePerfectK
- Insane DCEmu
- Posts: 147
- Joined: Thu Apr 27, 2006 10:15 am
- Has thanked: 27 times
- Been thanked: 35 times
Re: Announcing libkosfat
Thank you so much for working on this! I'll give it a look over in the morning.
Still Thinking!~~
- ThePerfectK
- Insane DCEmu
- Posts: 147
- Joined: Thu Apr 27, 2006 10:15 am
- Has thanked: 27 times
- Been thanked: 35 times
Re: Announcing libkosfat
Tested this out, works great! Thought it wasn't working for a bit, but turns out I hadn't built the newest version yet. Thanks for the effort!
I think I've discovered a bug, however. Going with what protofall was doing above, I tried to write a program that loaded a second binary off of the SD card and executed it. My program does two things, first it runs through the arch_exec example from the kos folder, with all the appropriate ext2 calls changed to their fat counterparts. Then, after going through that example, it loads a program from the sd card, and executes it.
Well, if I define ENABLE_WRITE, when the program tries to branch execution, I'll get a segment fault error. Doesn't matter if the write is creating a new file on the card or not, just writing to the card seems to cause the segment fault error with the program's execution. If I take the same code, and disable ENABLE_WRITE, the program branches execution without fault.
EDIT: If I open a file for writing, then close it, then load a binary and branch execution, I get a seg fault. However, if I open a file for writing, then close it, then open any other file for writing, then close that file, then load a binary and branch execution, it'll run fine. I have to make sure I close a file and then open a file again for writing in order to avoid seg fault.
I'll put my code online later tonight so you can inspect, I'm running late for work as is.
I think I've discovered a bug, however. Going with what protofall was doing above, I tried to write a program that loaded a second binary off of the SD card and executed it. My program does two things, first it runs through the arch_exec example from the kos folder, with all the appropriate ext2 calls changed to their fat counterparts. Then, after going through that example, it loads a program from the sd card, and executes it.
Well, if I define ENABLE_WRITE, when the program tries to branch execution, I'll get a segment fault error. Doesn't matter if the write is creating a new file on the card or not, just writing to the card seems to cause the segment fault error with the program's execution. If I take the same code, and disable ENABLE_WRITE, the program branches execution without fault.
EDIT: If I open a file for writing, then close it, then load a binary and branch execution, I get a seg fault. However, if I open a file for writing, then close it, then open any other file for writing, then close that file, then load a binary and branch execution, it'll run fine. I have to make sure I close a file and then open a file again for writing in order to avoid seg fault.
I'll put my code online later tonight so you can inspect, I'm running late for work as is.
Still Thinking!~~