I build my own virtual file system in C.
Now I want to implement some sort of defragmantation method, where it looks for gaps and closes them.
So if file 1 is size 10 and on position X and file 2 is size 20 and on position Z, I want it to get moved to position Y.
My idea now is to take the size File 2, substract it from the size of File 1 and use the outcome to shift File 2 to the left as high as the outcome.
I have a pseudo code, because I can't come up with a working solution:
for (int i = 0; i < files; i++)
//look for inconsistencies/gaps.
if (found gaps)
file 2 - file 1 = x;
shiftfiletotheleft x bytes;
Thanks for ideas and answers in advance.