问题
I have 20 files where the data structure is sector aligned to 4k in NTFS. I want to combine all files without copying any data. The goal is to write a sort of insert API that works by directly changing NTFS Virtual Clusters and Physical Clusters.
The goal is to have a file sized 1TB all from 50GB chunks without copying. All data is already on the disk and on the same volume. This would work by directly setting the NTFS logical cluster inside the file.
I can read the Virtual to Physical translation of the files with FSCTL_GET_RETRIEVAL_POINTERS
Source: VCN: 0 Cluster: 16 LCN: 54723798
Target: VCN: 0 Cluster: 160 LCN: 6172145
I tried to use the Windows Defrag API:
bool fResult = DeviceIoControl(
hVol,
FSCTL_MOVE_FILE,
p,
bufSize,
NULL,
0,
ref size,
NULL);
While this would be the perfect command for this, it cannot change the Physical adress of my source file to the physical adress of the target file: STATUS_ACCESS_DENIED. If I delete the Target file I can move the Physical Clusters, but the Target file is gone.
NTFS hard links would be good but I cannot create a hardlink to a subsection of another file.
I have administrator priviledges on the windows machine and I need to do this on the file system level not with the windows file API to avoid any copying. A solution would be to change the clusters by directly writing to the NTFS Master File Table.
Or by deleting the big file, changing all logical sectors of the 20 files to the deleted file sectors and then creating a file with specific already existing sectors.
A working solution would yield the result:
Source1: VCN: 0 Cluster: 16 LCN: 54723798
Source2: VCN: 0 Cluster: 16 LCN: 6172145
Target:
Extends 2:
VCN: 0 Cluster: 16 LCN: 54723798
VCN: 16 Cluster: 16 LCN: 6172145
To validate a change you can run a cmd windows as admin:
fsutil volume filelayout "C:\Data\BigFile.txt"
Any other idea or some C++/C code to change or insert a MFT entry would be welcome.
Update 1: I can read the MFT of the NTFS partition, but i really need someone who knows how to create or edit a fileentry. Other solutions are also welcome
来源:https://stackoverflow.com/questions/44347459/windows-how-to-change-or-insert-physical-sector-into-another-file