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
2010-05-13 23:32:20
A:
fsutil file getallocranges will show you the file's extents you will need admin rights.
Dominik Weber
2010-08-25 18:25:25
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
2010-08-25 18:48:03
A:
And, of course, "fragmentation" is suspect:
- 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).
- The file may be "contiguous" but across several cylinders. Even reading sequentially will result in seeks.
- 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
2010-09-17 21:33:35