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

Method SetEndOfFile

libcppcryptfs/file/cryptfile.cpp:671–777  ·  view source on GitHub ↗

re-writes last block of necessary to account for file growing or shrinking if bSet is TRUE (the default), actually calls SetEndOfFile()

Source from the content-addressed store, hash-verified

669// re-writes last block of necessary to account for file growing or shrinking
670// if bSet is TRUE (the default), actually calls SetEndOfFile()
671BOOL
672CryptFileForward::SetEndOfFile(LONGLONG offset, BOOL bSet)
673{
674 if (m_real_file_size == (long long)-1)
675 return FALSE;
676
677 if (m_handle == NULL || m_handle == INVALID_HANDLE_VALUE)
678 return FALSE;
679
680 if (m_is_empty && offset != 0) {
681 if (!WriteVersionAndFileId())
682 return FALSE;
683 }
684
685 LARGE_INTEGER size_down;
686
687 size_down.QuadPart = m_real_file_size;
688
689 if (!adjust_file_offset_down(size_down)) {
690 return FALSE;
691 }
692
693 LARGE_INTEGER up_off;
694
695 if (bSet) {
696 up_off.QuadPart = offset;
697 if (!adjust_file_offset_up_truncate_zero(up_off))
698 return FALSE;
699 }
700
701 long long last_block;
702 int to_write;
703
704 bool growing = false;
705
706 if (offset < size_down.QuadPart) {
707 last_block = offset / PLAIN_BS;
708 to_write = (int)(offset % PLAIN_BS);
709 } else if (offset > size_down.QuadPart) {
710 last_block = size_down.QuadPart / PLAIN_BS;
711 to_write = size_down.QuadPart % PLAIN_BS ? (int)min(PLAIN_BS, offset - size_down.QuadPart) : 0;
712 growing = true;
713 } else {
714 to_write = 0;
715 }
716
717 if (to_write == 0) {
718 if (bSet) {
719 return SetEndOfFileInternal(up_off);
720 } else {
721 return TRUE;
722 }
723 }
724
725 // need to re-write truncated or expanded last block
726
727 unsigned char buf[PLAIN_BS];
728

Calls 8

adjust_file_offset_downFunction · 0.85
get_crypt_contextFunction · 0.85
read_blockFunction · 0.85
get_random_bytesFunction · 0.85
write_blockFunction · 0.85
GetConfigMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected