简体   繁体   中英

Tool to move the clusters/sectors for a file

I know when a file is allocated on a file system, such as NTFS or FAT32, the file system will allocated some clusters/sectors for it. After the file is allocated, is there a tool that can move the clusters allocated to the file from one location to another, and update the file system meta data as well? This is just like a defragment for a file manually.

Quoting MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363911(v=vs.85).aspx

To defragment a file Use the FSCTL_GET_VOLUME_BITMAP control code to find a place on the volume that is large enough to accept an entire file. Note If necessary, move other files to make a place that is large enough. Ideally, there is enough unallocated clusters after the first extent of the file that you can move subsequent extents into the space after the first extent. Use the FSCTL_GET_RETRIEVAL_POINTERS control code to get a map of the current layout of the file on the disk. Walk the RETRIEVAL_POINTERS_BUFFER structure returned by FSCTL_GET_RETRIEVAL_POINTERS. Use the FSCTL_MOVE_FILE control code to move each cluster as you walk the structure. Note You may need to renew either the bitmap or the retrieval structure, or both at various times as other processes write to the disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM