Hi,
OSDesign wrote:I see specs of filesystems supporting journal, its a kind of log, showing what job this file receive.
But this kind of filesystem is not oversized for each file ? I mean if I modify a jpg file hunder of time, that will take a lot of space to keep each modifications between each save.
The journal itself is only really used to fix things up later - for e.g. if the computer crashes (or loses power) in the middle of writing new data to a disk (leaving corrupt data) then you'd use the journal to restore the file system to a usable state.
For example, lets say you're creating a new file - you'd put "creating directory entry" into the journal, then create the directory entry, then put "creating initial file data" into the journal and create the file data, then put "marking sectors used" into the journal and mark them as used. After this you'd put a "checkpoint" into the journal. When the file system is first mounted you'd check the journal and see if there's anything after the last checkpoint (any operations that didn't complete).
If the computer died after the directory entry was created then you'd have a directory entry pointing to data that didn't get written. In this case the journal would contain "creating directory entry" without the data or checkpoint, allowing you delete the directory entry quickly.
If the last thing in the journal was "marking sectors used" then you might be able to quickly mark those sectors as used when the computer reboots. That's the basic idea behind journalling anyway - being able to quickly fix the file system if data corruption was possible.
As you can see, the journal itself never needs to contain any file data - only small "tokens" possibly followed by some sector/cluster numbers. You can also delete anything in the journal that is older than the most recent checkpoint. The journal itself doesn't need to be large at all.
Of course you should be careful with the order you do things in so that you need to updte the journal less. Returning to the previous example, what if you wrote the file's data then marked the sectors as used and then created the directory entry for it? In this case you'd only need 2 entries in the journal instead of 3.
There's are alternatives to journalling too - ignore the issue (data loss), check the entire file system for corruption each time you boot (very slow), or find another way to get the same results.
OSDesign wrote:Do you have any idea how to not have a fragmented filesystem ? I can't see how we can not have a fragmented filesystem because when we deletre/write files on hdd the next file we write doest necessary fit into the space the last file before deleting it.
It's easy to prevent "file fragmentation" - if you're creating a new file look for a space that is large enough for the entire file and issue an error if there isn't a large enough free area. If you're making a file larger (appending data), look for a free area large enough for the old data and the new data, then copy all the old data and the new/appended data to the new space, then free the old version.
The problem here is that it's very slow to add data to an existing file, and you end up with a lot of fragmented free space.
A better approach would be to allow fragmentation (both file fragmentation and free space fragmentation) and have a defragmenter running in the background, so that the file system gets defragmented automatically when the computer isn't doing anything important.
You could combine these though - prevent file fragmentation when possible and
defragment files and free space in the background.
Designing a crappy file system isn't too hard, but designing a fast reliable file system is very difficult - many things to worry about.
Cheers,
Brendan