Logic in Disk Defragmantation & Disk Check

c#, defragmentation, disk, windows

Solution

For completeness sake, here's a C# API wrapper for defragmentation:

http://blogs.msdn.com/jeffrey_wall/archive/2004/09/13/229137.aspx

Defragmentation with these APIs is (supposed to be) very safe nowadays. You shouldn't be able to corrupt the file system even if you wanted to.

Commercial defragmentation programs use the same APIs.

Problem

What is the logic behind disk defragmentation and Disk Check in Windows? Can I do it using C# coding?

Original source