FAT compatibility - increasing file size

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
OZ

FAT compatibility - increasing file size

Post by OZ »

hello,
at the moment im trying to implement a basic FAT12 support in my os.
While implementing a simple create_file function one faces the problem, that the cluster of the directory where we're supposed to create the file in is full. As the documentation on fat is not that extensive, I thought it should be as simple as adding another cluster into the working dir's chain. For my code this works an the dir grows, the file is created and it can be opened afterwards.
But if I mount the disk image in linux only the 16 entries that are stored in the first cluster show up, but not the one I just added.

This problem does only appear in this situation, while creating files in a directory with some empty slots left my code seems to be compatible with the way linux handles fat.
Therefore my question is if there is any further secret magic to be done to grow FAT directories or if my approach was right but my code must be wrong? ???
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:FAT compatibility - increasing file size

Post by Pype.Clicker »

i'd say that's basically how it works, except for the root directory.

you're trying to extend a sub-dir, right? not the root directory?
OZ

Re:FAT compatibility - increasing file size

Post by OZ »

no, it's not the root dir, that has got an fixed size.
I'm trying to grow a sub dir. Could it be an issue to mount a fat image through loopback in linux? Like the changes not visible due to still cached stuff?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:FAT compatibility - increasing file size

Post by Pype.Clicker »

there shouldn't be any issue with linux's loop device if you take the time to unmount (or at least sync) before you try to manipulate the image after you added files, etc.
OZ

Re:FAT compatibility - increasing file size

Post by OZ »

I died some further testing and the whole thing is quite mysterious.
When I create a multicluster sized file in a directory with some slots left, it shows up in linux. Therefore there shouldn't be an issue with the code that handles the chains.
When I create a file in a full directory that needs to grow by one cluster, it doesn't
show up in linux, but it shows up in my os if I list that dir after a reboot.
Therefore the changes get written to disk, but linux and windows both don't show them in this case.
Now this brings up one question, when this works pretty fine with my code, but linux and windows don't show new files in grown dirs, do they handle the FAT different? I only update the first FAT. Do linux and win sync both copies? Or could this be an issue?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re:FAT compatibility - increasing file size

Post by Combuster »

You just said it ;)
If you have two FATs they must match or the system would officially be inconsistent.

Now what could've happened:
If i had two FATs, i'd commit to the first, write the file, then commit to the second - if i'd stop somewhere in between, i could try to redo or rollback the transaction depending on wether the second fat is partially written or not, so in my case, i'd end up undoing the writes.
And iirc some os's only check the last fat for it being closer to the data and thus more cache-efficient to use than the first.

Both ways, you're screwed.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply