Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. // Sets the file_info struct for the file with the given handle. This sets the
  2. // file size, creation time, etc.
  3. NTSTATUS CloudStorageFs::GetFileInfoHelper(const FileDescription& file_description, Fsp::FileSystemBase::FileInfo* file_info) {
  4. BY_HANDLE_FILE_INFORMATION by_handle_file_info;
  5.  
  6. if (!GetFileInformationByHandle(file_description.handle, &by_handle_file_info)) {
  7. return FspNtStatusFromWin32(GetLastError());
  8. }
  9.  
  10. file_info->FileAttributes = by_handle_file_info.dwFileAttributes;
  11. file_info->ReparseTag = 0;
  12. file_info->AllocationSize = RoundToAllocationUnit(file_info->FileSize);
  13. file_info->CreationTime = GetUint64FromLowAndHigh(
  14. by_handle_file_info.ftCreationTime.dwLowDateTime,
  15. by_handle_file_info.ftCreationTime.dwHighDateTime);
  16. file_info->LastAccessTime = GetUint64FromLowAndHigh(
  17. by_handle_file_info.ftLastAccessTime.dwLowDateTime,
  18. by_handle_file_info.ftLastAccessTime.dwHighDateTime);
  19. file_info->LastWriteTime = GetUint64FromLowAndHigh(
  20. by_handle_file_info.ftLastWriteTime.dwLowDateTime,
  21. by_handle_file_info.ftLastWriteTime.dwHighDateTime);
  22. file_info->ChangeTime = file_info->LastWriteTime;
  23. file_info->IndexNumber = 0;
  24. file_info->HardLinks = 0;
  25.  
  26. // If a ghost file, we have to pull the size from GCS.
  27. if (file_description.is_ghost) {
  28. std::uint64_t size;
  29. bool exists = gcs_client_.GetSize(file_description.name, &size);
  30. if (!exists) {
  31. return ERROR_FILE_NOT_FOUND;
  32. }
  33. file_info->FileSize = size;
  34. return STATUS_SUCCESS;
  35. }
  36.  
  37. // Otherwise get the file size as normal.
  38. file_info->FileSize = GetUint64FromLowAndHigh(
  39. by_handle_file_info.nFileSizeLow, by_handle_file_info.nFileSizeHigh);
  40.  
  41. // Finally set directory attributes if applicable.
  42. if (by_handle_file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  43. file_info->FileAttributes =
  44. file_info->FileAttributes | FILE_ATTRIBUTE_DIRECTORY;
  45. }
  46.  
  47. return STATUS_SUCCESS;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement