hi,
DeviceIoControl(volumehandle, Consts.MoveFile, movefiledataPointer, movefiledataSize, IntPtr.Zero, 0, ref size, IntPtr.Zero)
i've been trying to get it to work... but i always get ERROR_INSUFFICIENT_BUFFER.
msdn[
^] says it happens when 'the output buffer is too small to receive any data, the call fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and lpBytesReturned is zero.' although in the
FSCTL_MOVE_FILE[
^] page it is said that lpOutBuffer must be NULL (IntPtr.Zero) and nOutBufferSize set to 0 !?!?!
tried in this order :
- rechecked types in movefiledata struct
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct MoveFileData
{
public IntPtr File;
public Int64 StartingVcn;
public Int64 StartingLcn;
public UInt32 ClusterCount;
}
GCHandle handle = GCHandle.Alloc(movefiledata, GCHandleType.Pinned);
IntPtr movefiledataPointer = handle.AddrOfPinnedObject();
uint movefiledataSize = (uint)Marshal.SizeOf(movefiledata);
- re-targeted compilation to x86
- hacked code so as size would increment on error (desperate)
- re-checked value of Consts.MoveFile against WinIoCtl.h
- re-checked types in MoveFileData against WinIoCtl.h
- posted question on codeproject.com ^_-
any idea???
:: update ::
this code is working perfectly !!!!
int _tmain(int argc, _TCHAR* argv[])
{
LPCWSTR name = L"\\\\.\\e:";
HANDLE volumehandle = CreateFileW(name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
HANDLE filehandle = CreateFileW(L"e:\\Temp\\4caf4c2.tmp", FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_POSIX_SEMANTICS, NULL);
MOVE_FILE_DATA move_data;
move_data.FileHandle = filehandle;
move_data.StartingVcn.QuadPart = 129;
move_data.StartingLcn.QuadPart = 1167419;
move_data.ClusterCount = (DWORD) 1;
DWORD bytes_ret;
BOOL ret = DeviceIoControl(volumehandle, FSCTL_MOVE_FILE, &move_data, sizeof(move_data), NULL, 0, &bytes_ret, NULL);
if (ret == 0)
{
DWORD lasterr = GetLastError();
std::printf("error hapened %u" , lasterr);
if (lasterr == ERROR_HANDLE_EOF)
return lasterr;
}
CloseHandle(filehandle);
CloseHandle(volumehandle);
return 0;
}