Hello everyone,
i implemented fat32 read support in my kernel, and it is now working fine (except that i did not implemented reading a file at a specific offset, but anyway).
I wanted to fully implement fat32 support, so i need file and directory creation, file writing, and file and directory deletion.
I read the FAT article on the wiki, and the FAT32 one by Requimrar, but i did not find them useful for write support.
I have read the microsoft "fatgen103.doc" document, but again even if read support, and lfn stuff is really clear i could not find useful information for write support.
I have 3 questions :
- How do i find an 'empty' or free to use cluster on the drive ? Do i need to look in the FAT, and where ?
- How do i create a directory or a file ? I am supposed to create a new entry in the FAT, right ? but how do i do that ? (where to write it, with what data)
- How do i allocate a cluster for a file or a directory, if the file data becomes too big for the current cluster ? (that cluster address must then be written in the FAT, right ? so that we can follow the cluster chain)
I tried to understand the concepts behind the file system, but i can't deny that i don't really know what are the data in the FAT itself, as all i've done for now using the fat is following cluster chain.
Thanks for using your time for me (and sorry if my english is bad) !
[SOLVED] FAT32 write support
-
- Member
- Posts: 43
- Joined: Sun Aug 20, 2017 10:59 am
[SOLVED] FAT32 write support
Last edited by vhaudiquet on Wed Sep 13, 2017 1:51 pm, edited 3 times in total.
Re: FAT32 write support
yes, any FAT entry marked "free" is free, empty, and can be used for storing a file- How do i find an 'empty' or free to use cluster on the drive ? Do i need to look in the FAT, and where ?
where doesn't matter (that is a matter of implementation and optimization)
just to note: a 0 value means the cluster is free to be used
a directory is just a file that contains other files (really very simple)- How do i create a directory or a file ? I am supposed to create a new entry in the FAT, right ? but how do i do that ? (where to write it, with what data)
for both these are the things that need to be done:
find a free cluster to use in the FAT table, if you need more than 1 cluster, find more clusters
mark the last cluster in the chain as EOF (iirc that should be 0xFFFFFF8... but check the docs and don't rely on me to be correct)
if you are using more than 1 cluster, make all other clusters point to the next cluster in the list
find an available free slot in the parent directory list, and fill it with the proper name, size, attributes, and starting cluster
your directory entry points to the first cluster (this is how you mark which file the cluster is used by), and mark each cluster in the FAT table with the next cluster used by the file, the last cluster should be marked as EOF- How do i allocate a cluster for a file or a directory, if the file data becomes too big for the current cluster ? (that cluster address must then be written in the FAT, right ? so that we can follow the cluster chain)
if you need to grow a file larger, it is really easy:
just get a new free cluster (any cluster previously marked 0) and mark that as EOF, and point the previous final cluster to the new cluster (don't forget to update the file size in the directory)
FAT tables are very simple: its a linked list, where the directory entry points to the start, and each entry then points to the next entryI tried to understand the concepts behind the file system, but i can't deny that i don't really know what are the data in the FAT itself, as all i've done for now using the fat is following cluster chain.
0 means unused (free, available for use)
any cluster > EOF means bad cluster (probably the disk is damaged in that spot and cannot be reliably read/written)
Re: FAT32 write support
@OP: Remember to add the "." and ".." entriesJAAman wrote:a directory is just a file that contains other files (really very simple)- How do i create a directory or a file ? I am supposed to create a new entry in the FAT, right ? but how do i do that ? (where to write it, with what data)
for both these are the things that need to be done:
I believe FFFFFF8 - FFFFFFE are bad clusters and FFFFFFF is EOF, but I must admit I'm not sure either.JAAman wrote: mark the last cluster in the chain as EOF (iirc that should be 0xFFFFFF8... but check the docs and don't rely on me to be correct)
if you are using more than 1 cluster, make all other clusters point to the next cluster in the list
find an available free slot in the parent directory list, and fill it with the proper name, size, attributes, and starting cluster
You find free clusters and mark them either as EOF (if they're the last one) or mark them with the number of the next cluster- How do i allocate a cluster for a file or a directory, if the file data becomes too big for the current cluster ? (that cluster address must then be written in the FAT, right ? so that we can follow the cluster chain)
I think you're 99% of the way there! You already know how to read a FAT volume; just think about what steps had to be taken to get the data you're reading onto the disk.I tried to understand the concepts behind the file system, but i can't deny that i don't really know what are the data in the FAT itself, as all i've done for now using the fat is following cluster chain.
Re: FAT32 write support
just checked FATgen and we were both wrong...
0xFFFFFF8 - 0xFFFFFFF are all EOF (or the spec calls it EOC -- End Of Clusterchain)
0xFFFFFF7 == BAD_CLUSTER
0xFFFFFF8 - 0xFFFFFFF are all EOF (or the spec calls it EOC -- End Of Clusterchain)
0xFFFFFF7 == BAD_CLUSTER
-
- Member
- Posts: 43
- Joined: Sun Aug 20, 2017 10:59 am
Re: FAT32 write support
Thanks to both of you guys !
I started implementing that and that was actually easier than i thought ; with your explanations, i even rewritten some part of the read process to cache the FAT table entirely (to improve performance)...
I started implementing that and that was actually easier than i thought ; with your explanations, i even rewritten some part of the read process to cache the FAT table entirely (to improve performance)...