File System/Container Layout Advice

Soldato
Joined
7 Apr 2004
Posts
4,212
Hi,

Im after some advice on how to design a very simple 'file system', specifically a format for a file to contain other files. Think of a zip file with no compression.

So i have a base file of constant x size, that can contain x number of other files within it. These files can be added or deleted.

Now my main problem here is fragmentation. My current design has a main file header, which keeps track of the number of files and total volume size, checksums etc.

Then each file has a 'node' data structure, containing file size, name and offset within the container. So by finding a files node I now know where the file is within the container, and can extract it or delete it.

This in theory will work fine, but say i have 1000 files within the container and delete 200, the result will be a mess and inserting new files will not be easy.

The best thing i can think of is to position files sequentially after a delete operation, this way new files can be inserted onto the end with ease. But moving and repositioning all the files when one is deleted wont be nice on performance.

Can anyone give me some pointers on the best way to approach this? I really want to keep things as simple as possible, it will eventually be inplemented with C.

The Zip file format is like this:
zipformatnq3.jpg


That is perfect for me, but how does it avoid fragmentation if files are deleted?

Thanks,
Jack
 
Last edited:
Why not use an existing container like tar?

I am guessing this is a homework thing.

You could split the container and files into fixed length sectors, then in the header store all the sectors that make up a file?
That way even if the file does become fragmented you can reuse empty sectors when adding new files.
 
I am guessing this is a homework thing.

You could split the container and files into fixed length sectors, then in the header store all the sectors that make up a file?
That way even if the file does become fragmented you can reuse empty sectors when adding new files.

Thanks I like the sound of that idea, sounds like it could work quite well in this context.
 
Back
Top Bottom