MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / CryptMoveFileInternal

Function CryptMoveFileInternal

cppcryptfs/dokan/cryptdokan.cpp:1106–1242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1104// see comment in CryptMoveFile() about what the repair stuff is for
1105
1106static NTSTATUS CryptMoveFileInternal(LPCWSTR FileName, // existing file name
1107 LPCWSTR NewFileName,
1108 BOOL ReplaceIfExisting,
1109 PDOKAN_FILE_INFO DokanFileInfo,
1110 bool &needRepair, bool repairName) {
1111
1112 needRepair = false;
1113
1114 string actual_encrypted;
1115 FileNameEnc filePath(DokanFileInfo, FileName);
1116 FileNameEnc newFilePath(DokanFileInfo, NewFileName, &actual_encrypted,
1117 repairName);
1118
1119 DbgPrint(L"MoveFile %s -> %s\n\n", FileName, NewFileName);
1120
1121 HANDLE handle;
1122 DWORD bufferSize;
1123 BOOL result;
1124 size_t newFilePathLen;
1125
1126 PFILE_RENAME_INFO renameInfo = NULL;
1127
1128 handle = (HANDLE)DokanFileInfo->Context;
1129 if (!handle || handle == INVALID_HANDLE_VALUE) {
1130 DbgPrint(L"\tinvalid handle\n\n");
1131 return STATUS_INVALID_HANDLE;
1132 }
1133
1134 auto new_path = static_cast<const WCHAR*>(newFilePath);
1135
1136 if (new_path == nullptr) {
1137 // this can happen e.g. if we can't read a diriv in the "to" path
1138 auto lasterr = GetLastError();
1139 DbgPrint(L"\tnewFilePath is null, last error was %u\n", lasterr);
1140 // we return accessed denied because whatever error really happened might
1141 // not make any sense to the caller.
1142 return STATUS_ACCESS_DENIED;
1143 }
1144
1145 newFilePathLen = wcslen(newFilePath);
1146
1147 // the FILE_RENAME_INFO struct has space for one WCHAR for the name at
1148 // the end, so that
1149 // accounts for the null terminator
1150
1151 bufferSize = (DWORD)(sizeof(FILE_RENAME_INFO) +
1152 newFilePathLen * sizeof(newFilePath[0]));
1153
1154 renameInfo = (PFILE_RENAME_INFO)malloc(bufferSize);
1155 if (!renameInfo) {
1156 return STATUS_BUFFER_OVERFLOW;
1157 }
1158 ZeroMemory(renameInfo, bufferSize);
1159
1160 renameInfo->ReplaceIfExists =
1161 ReplaceIfExisting
1162 ? TRUE
1163 : FALSE; // some warning about converting BOOL to BOOLEAN

Callers 1

Calls 13

DbgPrintFunction · 0.85
ToNtStatusFunction · 0.85
delete_fileFunction · 0.85
IsCaseInsensitiveMethod · 0.80
FileExistedMethod · 0.80
CorrectCasePathMethod · 0.80
sizeMethod · 0.80
renameMethod · 0.80
RenameMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected