Implement FAT12/FAT16?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Implement FAT12/FAT16?

Post by NunoLava1998 »

For initialization of my assembly kernel, i will implement a FAT12 or FAT16 file system or FAT28 (FAT32) or even ExFAT aka the real FAT32 into my OS.
However, the solutiosn i find on OSDev or the internet either don't mention anything or are way too long and assuming i'm using a bootloader (i'm in the kernel already and i'm using %include, sorry but no). Can anyone provide code on this?
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Implement FAT12/FAT16?

Post by glauxosdever »

Hi,


Did you get your bootloader to load the kernel from sector 2? If not, then you have other priorities to fulfill first.


Regards,
glauxosdever
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Implement FAT12/FAT16?

Post by NunoLava1998 »

glauxosdever wrote:Hi,


Did you get your bootloader to load the kernel from sector 2? If not, then you have other priorities to fulfill first.


Regards,
glauxosdever
Yes, i'm starting from scratch and i have tested it before. The StackOverflow answer which i copy from has upvotes and does work.
And if you're wondering, here is the link where i usually get my go-to-second-sector bootloaders:
http://www.stackoverflow.com/questions/ ... ond-sector
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Implement FAT12/FAT16?

Post by iansjack »

NunoLava1998 wrote:Can anyone provide code on this?
Probably not.

Honestly, most of us here do OS deving as just a hobby and at your age this is certainly true. So learn how FAT filesystems work and have fun writing your own code to access them. For goodness sake, don't just cut and paste other people's code without understanding it. What's the point of that?

As for your problems with GRUB (going slightly off topic) or your problem getting a C kernel to work - solve them! If you give up whenever you have a slight setback then you are never going to do anything useful, or even interesting. Things don't "just happen". There is always a reason and discovering that reason is the way that you will learn. Eventually you will be able to do original work.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Implement FAT12/FAT16?

Post by BenLunt »

iansjack wrote:So learn how FAT filesystems work and have fun writing your own code to access them. For goodness sake, don't just cut and paste other people's code without understanding it. What's the point of that?
I agree here. The enjoyment that comes with this kind of work, at least for me and I am sure many others, is the act of learning about how things work and creating the code to do it yourself.

I understand that looking at other's code can help, I do it often, but the actual work, and learning how to make it work is and should be the best part.

The FAT file system is quite simple, especially compared to other more modern file systems. You have a BPB, one or more FAT's, a root directory block, and the the data block. That's it. Depending on the size of the FAT, you either have 12-, 16-, or 32-bits per entry. Depending on the cluster size, you have 1, 2, 4, 8, ... sectors per cluster. (Side note, the file system should have no idea nor dependency on the size of a sector).

Read the documentation, found at http://www.fysnet.net/docs/fatgen103.pdf and many other places, learn how a file is stored on the disk, as well as the meta-data (the filename, size, etc.) is stored.

A FAT file system can also have Long File Names. These long file names are stored in the Meta-data area just like normal short names with a single modification to the attributes field to indicate a LFN. However, please note that Microsoft still owns the patent on this technique, though I don't think anyone is going to complain too much anymore.

If you wish, I have written a book that included this FAT file system, showing the layout of each section, how the file system is used, and, dare I say, it does include source code. If a book will suite you better, have a look at http://www.fysnet.net/the_virtual_file_system.htm. If you would rather not, there are numerous references to the FAT file system on the internet. It just takes a little effort to stop and study it first.

On a side note, and for the pure fun of it, I created my own file system (http://www.fysnet.net/fysfs.htm). It isn't anything to call home about, nor will it break any records (no pun intended). It was simply for the enjoyment of doing it, and as a test to see if my driver code was completely filesystem independent. Later, I adopted the LeanFS file system (http://freedos-32.sourceforge.net/lean/) from FreeDOS and added a few things myself. The author was very charitable and allowed me to add to it.

There are many other file systems, Ext2/3/4, Reiser, BTRFS, NTFS (again patented), XFS, as well as many others. Once you get a working FAT driver (and I recommend you start there), you will want to move on to something more robust, secure, and capable of larger media.

Ben
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: Implement FAT12/FAT16?

Post by NunoLava1998 »

BenLunt wrote:
iansjack wrote:So learn how FAT filesystems work and have fun writing your own code to access them. For goodness sake, don't just cut and paste other people's code without understanding it. What's the point of that?
I agree here. The enjoyment that comes with this kind of work, at least for me and I am sure many others, is the act of learning about how things work and creating the code to do it yourself.

I understand that looking at other's code can help, I do it often, but the actual work, and learning how to make it work is and should be the best part.

The FAT file system is quite simple, especially compared to other more modern file systems. You have a BPB, one or more FAT's, a root directory block, and the the data block. That's it. Depending on the size of the FAT, you either have 12-, 16-, or 32-bits per entry. Depending on the cluster size, you have 1, 2, 4, 8, ... sectors per cluster. (Side note, the file system should have no idea nor dependency on the size of a sector).

Read the documentation, found at http://www.fysnet.net/docs/fatgen103.pdf and many other places, learn how a file is stored on the disk, as well as the meta-data (the filename, size, etc.) is stored.

A FAT file system can also have Long File Names. These long file names are stored in the Meta-data area just like normal short names with a single modification to the attributes field to indicate a LFN. However, please note that Microsoft still owns the patent on this technique, though I don't think anyone is going to complain too much anymore.

If you wish, I have written a book that included this FAT file system, showing the layout of each section, how the file system is used, and, dare I say, it does include source code. If a book will suite you better, have a look at http://www.fysnet.net/the_virtual_file_system.htm. If you would rather not, there are numerous references to the FAT file system on the internet. It just takes a little effort to stop and study it first.

On a side note, and for the pure fun of it, I created my own file system (http://www.fysnet.net/fysfs.htm). It isn't anything to call home about, nor will it break any records (no pun intended). It was simply for the enjoyment of doing it, and as a test to see if my driver code was completely filesystem independent. Later, I adopted the LeanFS file system (http://freedos-32.sourceforge.net/lean/) from FreeDOS and added a few things myself. The author was very charitable and allowed me to add to it.

There are many other file systems, Ext2/3/4, Reiser, BTRFS, NTFS (again patented), XFS, as well as many others. Once you get a working FAT driver (and I recommend you start there), you will want to move on to something more robust, secure, and capable of larger media.

Ben
I only realized that website is owned by you now. Congratiulations. And thank you for the information.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Implement FAT12/FAT16?

Post by JAAman »

BenLunt wrote: A FAT file system can also have Long File Names. These long file names are stored in the Meta-data area just like normal short names with a single modification to the attributes field to indicate a LFN. However, please note that Microsoft still owns the patent on this technique, though I don't think anyone is going to complain too much anymore.
... pretty sure that is wrong, I could be mistaken, but I believe the patent on that expired a couple years ago (iirc 1994, wasn't it? which would mean the patent would have expired in 2014...)
User avatar
hgoel
Member
Member
Posts: 89
Joined: Sun Feb 09, 2014 7:11 pm
Libera.chat IRC: hgoel
Location: Within a meter of a computer

Re: Implement FAT12/FAT16?

Post by hgoel »

JAAman wrote:
BenLunt wrote: A FAT file system can also have Long File Names. These long file names are stored in the Meta-data area just like normal short names with a single modification to the attributes field to indicate a LFN. However, please note that Microsoft still owns the patent on this technique, though I don't think anyone is going to complain too much anymore.
... pretty sure that is wrong, I could be mistaken, but I believe the patent on that expired a couple years ago (iirc 1994, wasn't it? which would mean the patent would have expired in 2014...)
This one is still left:
https://www.google.com/patents/US6286013
Should be expiring next year though.
"If the truth is a cruel mistress, than a lie must be a nice girl"
Working on Cardinal
Find me at [url=irc://chat.freenode.net:6697/Cardinal-OS]#Cardinal-OS[/url] on freenode!
azblue
Member
Member
Posts: 147
Joined: Sat Feb 27, 2010 8:55 pm

Re: Implement FAT12/FAT16?

Post by azblue »

NunoLava1998 wrote: However, the solutiosn i find on OSDev or the internet either don't mention anything or are way too long and assuming i'm using a bootloader (i'm in the kernel already and i'm using %include, sorry but no). Can anyone provide code on this?
You've found code that tells you how to deal with FAT filesystem(s) in a bootloader and can't figure out how to write that in your kernel? That makes me think you don't understand the filesystem or the code. Don't copy-paste. Learn.
Post Reply