A basic filesystem with ability to fragmentation
Posted: Sun Jul 01, 2018 4:16 pm
Hello everyone,
Suppose i had a UFS-like filesystem (The inode contains direct and indirect pointers to data blocks and file specific informations like access rights, creation time, owner ... etc) and i wanted to add a functionality to support the fragmentation of the last block. I mean, if the file doesn't fill the last block (Uses only a fraction of it - Only some few bytes are written at the end) then instead of allocating a whole block for it, we only allocate a fragment. The system should not keep a pre-allocated pool of free fragments but whenever a file asks for a fragment we can take a free block and divide it into fragments and use one of them. Of course, other fragments from the same block could be assigned to other files. The other fact is that the number of fragments per block is configurable at the moment of installing the filesystem (The fragment has a fixed size). The problem is that i can't figure out what is the best change or structure that i should give to the inode to support such a functionality ? So what do you propose for that ?
As an obvious solution we can have a distinct array of pointers to fragments on the inode (Because the file can use up to N - 1 fragments with N the number of fragments per block) but the size of the array in this case should also be configurable (that means its size changes) but the array is located on the inode and no one wants to have a variable sized inode for it's filesystem, that will be very confusing and will complicate the implementation of the filesystem. That's why i was thinking of something different but i can't figure it out.
If someone is ever wondering, the question is actually from the book : The design of the UNIX operating system by Maurice J. Bach. I am self taught, by the way.
Suppose i had a UFS-like filesystem (The inode contains direct and indirect pointers to data blocks and file specific informations like access rights, creation time, owner ... etc) and i wanted to add a functionality to support the fragmentation of the last block. I mean, if the file doesn't fill the last block (Uses only a fraction of it - Only some few bytes are written at the end) then instead of allocating a whole block for it, we only allocate a fragment. The system should not keep a pre-allocated pool of free fragments but whenever a file asks for a fragment we can take a free block and divide it into fragments and use one of them. Of course, other fragments from the same block could be assigned to other files. The other fact is that the number of fragments per block is configurable at the moment of installing the filesystem (The fragment has a fixed size). The problem is that i can't figure out what is the best change or structure that i should give to the inode to support such a functionality ? So what do you propose for that ?
As an obvious solution we can have a distinct array of pointers to fragments on the inode (Because the file can use up to N - 1 fragments with N the number of fragments per block) but the size of the array in this case should also be configurable (that means its size changes) but the array is located on the inode and no one wants to have a variable sized inode for it's filesystem, that will be very confusing and will complicate the implementation of the filesystem. That's why i was thinking of something different but i can't figure it out.
If someone is ever wondering, the question is actually from the book : The design of the UNIX operating system by Maurice J. Bach. I am self taught, by the way.