Page 1 of 1

FAT compatibility - increasing file size

Posted: Fri Sep 01, 2006 9:27 am
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? ???

Re:FAT compatibility - increasing file size

Posted: Fri Sep 01, 2006 9:32 am
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?

Re:FAT compatibility - increasing file size

Posted: Fri Sep 01, 2006 11:24 am
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?

Re:FAT compatibility - increasing file size

Posted: Sat Sep 02, 2006 2:05 am
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.

Re:FAT compatibility - increasing file size

Posted: Sun Sep 03, 2006 5:10 am
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?

Re:FAT compatibility - increasing file size

Posted: Sun Sep 03, 2006 8:49 am
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.