call FSCTL_DUPLICATE_EXTENTS_TO_FILE IOCTL see https://docs.microsoft.com/en-us/windows/win32/api/winioctl/ni-winioctl-fsctl_duplicate_extents_to_file memo: Overflow (cloneRegionSize is greater than file ends) is safe and just ignored by windows.
(dst, src *os.File, offset int64, cloneRegionSize int64)
| 133 | // |
| 134 | // memo: Overflow (cloneRegionSize is greater than file ends) is safe and just ignored by windows. |
| 135 | func callDuplicateExtentsToFile(dst, src *os.File, offset int64, cloneRegionSize int64) (err error) { |
| 136 | var ( |
| 137 | bytesReturned uint32 |
| 138 | overlapped windows.Overlapped |
| 139 | ) |
| 140 | |
| 141 | request := duplicateExtentsData{ |
| 142 | FileHandle: windows.Handle(src.Fd()), |
| 143 | SourceFileOffset: offset, |
| 144 | TargetFileOffset: offset, |
| 145 | ByteCount: cloneRegionSize, |
| 146 | } |
| 147 | |
| 148 | return windows.DeviceIoControl( |
| 149 | windows.Handle(dst.Fd()), |
| 150 | fsctlDuplicateExtentsToFile, |
| 151 | (*byte)(unsafe.Pointer(&request)), |
| 152 | uint32(unsafe.Sizeof(request)), |
| 153 | (*byte)(unsafe.Pointer(nil)), // = nullptr |
| 154 | 0, |
| 155 | &bytesReturned, |
| 156 | &overlapped) |
| 157 | } |
| 158 | |
| 159 | func roundUp(value, base int64) int64 { |
| 160 | mod := value % base |