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

Method Write

libcppcryptfs/file/cryptfile.cpp:367–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365
366
367BOOL CryptFileForward::Write(const unsigned char *buf, DWORD buflen, LPDWORD pNwritten, LONGLONG offset, BOOL bWriteToEndOfFile, BOOL bPagingIo)
368{
369
370 if (m_real_file_size == (long long)-1)
371 return FALSE;
372
373 if (!pNwritten || !buf)
374 return FALSE;
375
376 *pNwritten = 0;
377
378 if (buflen < 1)
379 return TRUE;
380
381 BOOL bRet = TRUE;
382
383 if (bWriteToEndOfFile) {
384 LARGE_INTEGER l;
385 l.QuadPart = m_real_file_size;
386 if (!adjust_file_offset_down(l))
387 return FALSE;
388 offset = l.QuadPart;
389 } else {
390 if (bPagingIo) {
391 LARGE_INTEGER l;
392 l.QuadPart = m_real_file_size;
393 if (!adjust_file_offset_down(l))
394 return FALSE;
395
396 if (offset >= l.QuadPart)
397 {
398 DbgPrint(L"CryptFile paging io past end of file, return\n");
399 *pNwritten = 0;
400 return true;
401 }
402
403 if ((offset + buflen) > l.QuadPart)
404 {
405 DbgPrint(L"CryptFile addjusting write length due to paging io\n");
406 buflen = (DWORD)(l.QuadPart - offset);
407 }
408 }
409 }
410
411 // if we're going to increase the size of the file we need
412 // to hold onto exclusive access
413
414 bool bGrowingFile = false;
415
416 if (m_is_empty) {
417 bGrowingFile = true;
418 if (!WriteVersionAndFileId())
419 return FALSE;
420 } else {
421 LARGE_INTEGER size_down;
422 size_down.QuadPart = m_real_file_size;
423 adjust_file_offset_down(size_down);
424

Callers 2

Calls 10

adjust_file_offset_downFunction · 0.85
DbgPrintFunction · 0.85
get_crypt_contextFunction · 0.85
get_random_bytesFunction · 0.85
write_blockFunction · 0.85
read_blockFunction · 0.85
GetConfigMethod · 0.80
GetIoBufferMethod · 0.80
ReleaseIoBufferMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected