Defrag design document



Defrag disk functionality

Overview

Defrag is a tool for managing the performance of your disks. As such it performs the following actions:

Check disk integrity

defragmentation doesn't start if any of the checks indicate a faulty file system.

Sort directory entries

defrag sorts all the directory entries taking into account long file name entries.

Disk access optimization

defrag contains various algorithms, including:

Disk integrity checks

Boot sector

FAT(s)

Directories

Sort algorithm

Unfragmenting files

Introduction

This section describes the design of the defragmentation algorithm that eventualy has to be put into FreeDOS defrag. This algorithm shall work on FAT12, FAT16 and FAT32, and will not interfere with long file name entries. Further more the algorithm will only be implemented once for all three kinds of FAT file systems.

The unfragmenting files algorithm consists mainly of two parts, called:

Fill free blocks:

This part will essentially take the largest free block on the disk and will move the largest fragmented file that fits into the free block to this free block. This will go on until there are no more fragmented files that fill in any of the free spaces. After that all filled clusters will be moved to the front of the disk until there is enough space to put a file in that position. At that moment the free blocks will be filled again.

This algorithm will continue until there are no more fragmented files or until all data is moved to the front of the disk.

Select and move to the front:

If there are files that are longer then the total free space on the disk the previous part will have left some files fragmented, in that case a second part will be performed.

This part will take the first fragmented file on the disk, move all data following that file to the end of the disk, making sure that enough space becomes available to put the rest of the fragmented file after the part that has already been found.

Special care has to be taken that the algoithm will leave the unmovable clusters where they are.

Fill free blocks



Select and move to the front



The FAT transformation engine



Disklib