4

Is there a way to guarantee that a file on Windows (using the NTFS file system) will use contiguous sectors on the hard disk? In other words, the first chunk of the file will be stored in a certain sector, the second chunk of the file will be stored in the next sector, and so on.

I should add that I want to be able to create this file programmatically, so I'd rather not just ask the user to defrag their harddrive after creating this file. If there is a way to programmatically defrag just the file that I create, then that would be OK too.

e-sushi
  • 13,786
  • 10
  • 38
  • 57
Terry
  • 581
  • 3
  • 9
  • 17
  • Can you update your post with the purpose of doing this? I assume it's for performance, but trying to optimize a file's location on the disk seems a bit over the top to me. If you clarify what you're trying to do maybe there is another approach we can offer that will solve your problem. – Tim Frey Sep 10 '08 at 20:44

3 Answers3

7

I would start here:

http://technet.microsoft.com/en-us/sysinternals/bb897428.aspx

and follow Mark's documentation of the defrag stuff:

http://technet.microsoft.com/en-us/sysinternals/bb897427.aspx

Will Dean
  • 39,055
  • 11
  • 90
  • 118
1

I know of no such guarantees.

But also keep in mind that NTFS "files" are comprised of multiple data streams. So you are actually looking for a way to guarantee that a stream is contiguous.

Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
0

I believe there's no way to achieve that. You can only defragment the file after it's been written.

gabr
  • 26,580
  • 9
  • 75
  • 141