os_file_trim implements TRIM on Windows with DeviceIoControl(FSCTL_FILE_LEVEL_TRIM).
However is does not use DeviceIoControl correctly - since file is opened asynchronously, DeviceIoControl needs to be async as well - it to be passed valid OVERLAPPED as the last parameter.
MSDN says in the documentation of DeviceIoControl - https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx
"If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.
os_file_trim implements TRIM on Windows with DeviceIoControl(FSCTL_FILE_LEVEL_TRIM).
However is does not use DeviceIoControl correctly - since file is opened asynchronously, DeviceIoControl needs to be async as well - it to be passed valid OVERLAPPED as the last parameter.
MSDN says in the documentation of DeviceIoControl - https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx
"If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.