1
0
This commit is contained in:
Scott E. Graves
2017-03-26 03:19:50 -05:00
parent a2f41eed1c
commit dfc5ed91dd

View File

@@ -121,7 +121,7 @@ private:
if (!_fileListStopRequested) if (!_fileListStopRequested)
{ {
// TODO Change to WaitForSingleObject() for immediate termination // TODO Change to WaitForSingleObject() for immediate termination
Sleep(5000); Sleep(1000);
} }
} }
})); }));
@@ -431,6 +431,8 @@ private:
} }
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanFindFiles(cachePath, rootPath, siaQuery))); CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanFindFiles(cachePath, rootPath, siaQuery)));
// TODO Grab live filesystem items
auto dirList = siaFileTree->QueryDirectories(rootPath); auto dirList = siaFileTree->QueryDirectories(rootPath);
for (auto& dir : dirList) for (auto& dir : dirList)
@@ -476,8 +478,8 @@ private:
HANDLE handle = reinterpret_cast<HANDLE>(id); HANDLE handle = reinterpret_cast<HANDLE>(id);
if (!DokanFileInfo->IsDirectory) if (!DokanFileInfo->IsDirectory)
{ {
LARGE_INTEGER li; LARGE_INTEGER li = { 0 };
li.LowPart = ::GetFileSize(handle, reinterpret_cast<LPDWORD>(&li.HighPart)); ::GetFileSizeEx(handle, &li);
HandleFileClose(filePath, id, li.QuadPart); HandleFileClose(filePath, id, li.QuadPart);
} }
::CloseHandle(reinterpret_cast<HANDLE>(DokanFileInfo->Context)); ::CloseHandle(reinterpret_cast<HANDLE>(DokanFileInfo->Context));
@@ -620,6 +622,7 @@ private:
if (!handle || (handle == INVALID_HANDLE_VALUE)) if (!handle || (handle == INVALID_HANDLE_VALUE))
{ {
// TODO Need to add to cache if missing
handle = ::CreateFile(&filePath[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); handle = ::CreateFile(&filePath[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE)
{ {
@@ -679,9 +682,8 @@ private:
opened = TRUE; opened = TRUE;
} }
DWORD fileSizeHigh = 0; LARGE_INTEGER li = { 0 };
DWORD fileSizeLow = ::GetFileSize(handle, &fileSizeHigh); if (!::GetFileSizeEx(handle, &li))
if (fileSizeLow == INVALID_FILE_SIZE)
{ {
DWORD error = GetLastError(); DWORD error = GetLastError();
if (opened) if (opened)
@@ -689,8 +691,6 @@ private:
return DokanNtStatusFromWin32(error); return DokanNtStatusFromWin32(error);
} }
UINT64 fileSize = (static_cast<UINT64>(fileSizeHigh) << 32) | fileSizeLow;
LARGE_INTEGER distanceToMove; LARGE_INTEGER distanceToMove;
if (DokanFileInfo->WriteToEndOfFile) if (DokanFileInfo->WriteToEndOfFile)
{ {
@@ -709,7 +709,7 @@ private:
// Paging IO cannot write after allocate file size. // Paging IO cannot write after allocate file size.
if (DokanFileInfo->PagingIo) if (DokanFileInfo->PagingIo)
{ {
if (static_cast<UINT64>(Offset) >= fileSize) if (static_cast<UINT64>(Offset) >= li.QuadPart)
{ {
*NumberOfBytesWritten = 0; *NumberOfBytesWritten = 0;
if (opened) if (opened)
@@ -717,9 +717,9 @@ private:
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if ((static_cast<UINT64>(Offset) + NumberOfBytesToWrite) > fileSize) if ((static_cast<UINT64>(Offset) + NumberOfBytesToWrite) > li.QuadPart)
{ {
UINT64 bytes = fileSize - Offset; UINT64 bytes = li.QuadPart - Offset;
if (bytes >> 32) if (bytes >> 32)
{ {
NumberOfBytesToWrite = static_cast<DWORD>(bytes & 0xFFFFFFFFUL); NumberOfBytesToWrite = static_cast<DWORD>(bytes & 0xFFFFFFFFUL);
@@ -731,7 +731,7 @@ private:
} }
} }
if (static_cast<UINT64>(Offset) > fileSize) if (static_cast<UINT64>(Offset) > li.QuadPart)
{ {
// In the mirror sample helperZeroFileData is not necessary. NTFS will // In the mirror sample helperZeroFileData is not necessary. NTFS will
// zero a hole. // zero a hole.
@@ -749,15 +749,16 @@ private:
} }
} }
if (!::WriteFile(handle, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten, nullptr)) if (::WriteFile(handle, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten, nullptr))
{ {
// TODO Set status to changed
}
else
{
DWORD error = GetLastError(); DWORD error = GetLastError();
if (opened) if (opened)
CloseHandle(handle); CloseHandle(handle);
return DokanNtStatusFromWin32(error); return DokanNtStatusFromWin32(error);
}
else {
} }
// close the file when it is reopene bxkjuoqoa'qq d // close the file when it is reopene bxkjuoqoa'qq d
@@ -769,29 +770,31 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_SetEndOfFile(LPCWSTR FileName, LONGLONG ByteOffset, PDOKAN_FILE_INFO DokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_SetEndOfFile(LPCWSTR FileName, LONGLONG ByteOffset, PDOKAN_FILE_INFO DokanFileInfo)
{ {
HANDLE handle; NTSTATUS ret = STATUS_SUCCESS;
LARGE_INTEGER offset;
handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!handle || handle == INVALID_HANDLE_VALUE) if (!handle || (handle == INVALID_HANDLE_VALUE))
{ {
return STATUS_INVALID_HANDLE; ret = STATUS_INVALID_HANDLE;
} }
else
{
// TODO Set status to changed
LARGE_INTEGER offset;
offset.QuadPart = ByteOffset;
if (!::SetFilePointerEx(handle, offset, nullptr, FILE_BEGIN))
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
}
else if (!::SetEndOfFile(handle))
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
}
}
offset.QuadPart = ByteOffset; return ret;
if (!::SetFilePointerEx(handle, offset, nullptr, FILE_BEGIN))
{
DWORD error = GetLastError();
return DokanNtStatusFromWin32(error);
}
if (!::SetEndOfFile(handle))
{
DWORD error = GetLastError();
return DokanNtStatusFromWin32(error);
}
return STATUS_SUCCESS;
} }
static void DOKAN_CALLBACK Sia_Cleanup(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) static void DOKAN_CALLBACK Sia_Cleanup(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
@@ -802,10 +805,11 @@ private:
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!DokanFileInfo->IsDirectory) if (!DokanFileInfo->IsDirectory)
{ {
LARGE_INTEGER li; LARGE_INTEGER li = { 0 };
li.LowPart = ::GetFileSize(handle, reinterpret_cast<LPDWORD>(&li.HighPart)); ::GetFileSizeEx(handle, &li);
HandleFileClose(filePath, DokanFileInfo->Context, li.QuadPart); HandleFileClose(filePath, DokanFileInfo->Context, li.QuadPart);
} }
::CloseHandle(handle); ::CloseHandle(handle);
DokanFileInfo->Context = 0; DokanFileInfo->Context = 0;
} }
@@ -898,6 +902,7 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_DeleteFileW(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_DeleteFileW(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
{ {
// TODO Handle files that aren't cached // TODO Handle files that aren't cached
NTSTATUS ret = STATUS_SUCCESS;
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
FilePath filePath(GetCacheLocation(), FileName); FilePath filePath(GetCacheLocation(), FileName);
@@ -905,76 +910,81 @@ private:
DWORD dwAttrib = ::GetFileAttributes(&filePath[0]); DWORD dwAttrib = ::GetFileAttributes(&filePath[0]);
if ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) if ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
{ {
return STATUS_ACCESS_DENIED; ret = STATUS_ACCESS_DENIED;
} }
else if (handle && (handle != INVALID_HANDLE_VALUE))
if (handle && (handle != INVALID_HANDLE_VALUE))
{ {
FILE_DISPOSITION_INFO fdi; FILE_DISPOSITION_INFO fdi;
fdi.DeleteFile = DokanFileInfo->DeleteOnClose; fdi.DeleteFile = DokanFileInfo->DeleteOnClose;
if (!::SetFileInformationByHandle(handle, FileDispositionInfo, &fdi, sizeof(FILE_DISPOSITION_INFO))) if (!::SetFileInformationByHandle(handle, FileDispositionInfo, &fdi, sizeof(FILE_DISPOSITION_INFO)))
{ {
return DokanNtStatusFromWin32(GetLastError()); ret = DokanNtStatusFromWin32(GetLastError());
} }
} }
return STATUS_SUCCESS; return ret;
} }
static NTSTATUS DOKAN_CALLBACK Sia_MoveFileW(LPCWSTR FileName, LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO DokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_MoveFileW(LPCWSTR FileName, LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO DokanFileInfo)
{ {
// TODO Handle files that aren't cached // TODO Handle files that aren't cached
NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), FileName); FilePath filePath(GetCacheLocation(), FileName);
FilePath newFilePath(GetCacheLocation(), NewFileName); FilePath newFilePath(GetCacheLocation(), NewFileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!handle || (handle == INVALID_HANDLE_VALUE)) if (!handle || (handle == INVALID_HANDLE_VALUE))
{ {
return STATUS_INVALID_HANDLE; ret = STATUS_INVALID_HANDLE;
} }
else
size_t len = wcslen(&newFilePath[0]);
DWORD bufferSize = static_cast<DWORD>(sizeof(FILE_RENAME_INFO) + (len * sizeof(newFilePath[0])));
PFILE_RENAME_INFO renameInfo = static_cast<PFILE_RENAME_INFO>(malloc(bufferSize));
if (!renameInfo)
{ {
return STATUS_BUFFER_OVERFLOW; size_t len = wcslen(&newFilePath[0]);
DWORD bufferSize = static_cast<DWORD>(sizeof(FILE_RENAME_INFO) + (len * sizeof(newFilePath[0])));
PFILE_RENAME_INFO renameInfo = static_cast<PFILE_RENAME_INFO>(malloc(bufferSize));
if (renameInfo)
{
::ZeroMemory(renameInfo, bufferSize);
renameInfo->ReplaceIfExists = ReplaceIfExisting ? TRUE : FALSE; // some warning about converting BOOL to BOOLEAN
renameInfo->RootDirectory = nullptr; // hope it is never needed, shouldn't be
renameInfo->FileNameLength = static_cast<DWORD>(len) * sizeof(newFilePath[0]); // they want length in bytes
wcscpy_s(renameInfo->FileName, len + 1, &newFilePath[0]);
BOOL result = ::SetFileInformationByHandle(handle, FileRenameInfo, renameInfo, bufferSize);
free(renameInfo);
if (!result)
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
}
}
else
{
ret = STATUS_BUFFER_OVERFLOW;
}
} }
::ZeroMemory(renameInfo, bufferSize);
renameInfo->ReplaceIfExists = ReplaceIfExisting ? TRUE : FALSE; // some warning about converting BOOL to BOOLEAN return ret;
renameInfo->RootDirectory = nullptr; // hope it is never needed, shouldn't be
renameInfo->FileNameLength = static_cast<DWORD>(len) * sizeof(newFilePath[0]); // they want length in bytes
wcscpy_s(renameInfo->FileName, len + 1, &newFilePath[0]);
BOOL result = ::SetFileInformationByHandle(handle, FileRenameInfo, renameInfo, bufferSize);
free(renameInfo);
if (result)
{
return STATUS_SUCCESS;
}
else
{
DWORD error = GetLastError();
return DokanNtStatusFromWin32(error);
}
} }
static NTSTATUS DOKAN_CALLBACK Sia_SetFileAttributesW(LPCWSTR FileName, DWORD FileAttributes, PDOKAN_FILE_INFO DokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_SetFileAttributesW(LPCWSTR FileName, DWORD FileAttributes, PDOKAN_FILE_INFO DokanFileInfo)
{ {
UNREFERENCED_PARAMETER(DokanFileInfo); UNREFERENCED_PARAMETER(DokanFileInfo);
NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), FileName); FilePath filePath(GetCacheLocation(), FileName);
if (!::SetFileAttributes(&filePath[0], FileAttributes)) if (!::SetFileAttributes(&filePath[0], FileAttributes))
{ {
DWORD error = GetLastError(); DWORD error = GetLastError();
return DokanNtStatusFromWin32(error); ret = DokanNtStatusFromWin32(error);
} }
return STATUS_SUCCESS; return ret;
} }
static NTSTATUS DOKAN_CALLBACK Sia_GetFileSecurityW( static NTSTATUS DOKAN_CALLBACK Sia_GetFileSecurityW(
@@ -1057,7 +1067,6 @@ private:
FilePath filePath(GetCacheLocation(), FileName); FilePath filePath(GetCacheLocation(), FileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!handle || (handle == INVALID_HANDLE_VALUE)) if (!handle || (handle == INVALID_HANDLE_VALUE))
{ {
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
@@ -1074,39 +1083,42 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_SetAllocationSize(LPCWSTR FileName, LONGLONG AllocSize, PDOKAN_FILE_INFO DokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_SetAllocationSize(LPCWSTR FileName, LONGLONG AllocSize, PDOKAN_FILE_INFO DokanFileInfo)
{ {
NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), FileName); FilePath filePath(GetCacheLocation(), FileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context); HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!handle || (handle == INVALID_HANDLE_VALUE)) if (!handle || (handle == INVALID_HANDLE_VALUE))
{ {
return STATUS_INVALID_HANDLE; ret = STATUS_INVALID_HANDLE;
} }
else
LARGE_INTEGER fileSize;
if (::GetFileSizeEx(handle, &fileSize))
{ {
if (AllocSize < fileSize.QuadPart) LARGE_INTEGER fileSize = { 0 };
if (::GetFileSizeEx(handle, &fileSize))
{ {
fileSize.QuadPart = AllocSize; if (AllocSize < fileSize.QuadPart)
if (!::SetFilePointerEx(handle, fileSize, nullptr, FILE_BEGIN))
{ {
DWORD error = GetLastError(); fileSize.QuadPart = AllocSize;
return DokanNtStatusFromWin32(error); if (!::SetFilePointerEx(handle, fileSize, nullptr, FILE_BEGIN))
} {
DWORD error = GetLastError();
if (!::SetEndOfFile(handle)) ret = DokanNtStatusFromWin32(error);
{ }
DWORD error = GetLastError(); else if (!::SetEndOfFile(handle))
return DokanNtStatusFromWin32(error); {
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
}
} }
} }
else
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
}
} }
else
{ return ret;
DWORD error = GetLastError();
return DokanNtStatusFromWin32(error);
}
return STATUS_SUCCESS;
} }
public: public: