views:

35

answers:

4

Is there a tool that would show me for a specific file on disk, how fragmented it is? (How many seeks does physical disk need to make if I were to read that file in a linear fashion)

+2  A: 

You can use DeviceIoControl with FSCTL_GET_VOLUME_BITMAP, FSCTL_GET_RETRIEVAL_POINTERS and FSCTL_MOVE_FILE see http://msdn.microsoft.com/en-us/library/aa363911(v=VS.85).aspx.

You can find different code example if you search for this FSCTL_MOVE_FILE. One is with native windows API: http://www.kessels.com/defrag/Defrag.c another in .NET http://blogs.msdn.com/jeffrey_wall/archive/2004/09/13/229137.aspx.

Oleg
A: 

fsutil file getallocranges will show you the file's extents you will need admin rights.

Dominik Weber
A: 

The Sysinternals tool contig with parameter -a can do this for a file or all files in a folder and its subfolders.

Albin Sunnanbo
A: 

And, of course, "fragmentation" is suspect:

  1. The file may be in pieces in the same cylinder. No seek overhead, just rotational latency. Or not as the pieces may be an optimal order (chances are near zero for this one).
  2. The file may be "contiguous" but across several cylinders. Even reading sequentially will result in seeks.
  3. The file may be on a stripe set and you have no idea where the boundaries are. You may skip to another controller, another spindle, or another partition on the same drive.

Be careful about what conclusions you draw.

MJZ