VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/File.h
blob: 5bb25a01d7446a6eeacc11b38a75a79b734380c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 Derived from source code of TrueCrypt 7.1a, which is
 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
 by the TrueCrypt License 3.0.

 Modifications and additions to the original source code (contained in this file)
 and all other portions of this file are Copyright (c) 2013-2016 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages.
*/

#ifndef TC_HEADER_Platform_File
#define TC_HEADER_Platform_File

#include "PlatformBase.h"
#include "Buffer.h"
#include "FilesystemPath.h"
#include "SystemException.h"

namespace VeraCrypt
{
	class File
	{
	public:
		enum FileOpenMode
		{
			CreateReadWrite,
			CreateWrite,
			OpenRead,
			OpenWrite,
			OpenReadWrite
		};

		enum FileShareMode
		{
			ShareNone,
			ShareRead,
			ShareReadWrite,
			ShareReadWriteIgnoreLock
		};

		enum FileOpenFlags
		{
			// Bitmap
			FlagsNone = 0,
			PreserveTimestamps = 1 << 0,
			DisableWriteCaching = 1 << 1
		};

#ifdef TC_WINDOWS
		typedef FILE* SystemFileHandleType;
#else
		typedef int SystemFileHandleType;
#endif

		File () : FileIsOpen (false), SharedHandle (false) { }
		virtual ~File ();

		void AssignSystemHandle (SystemFileHandleType openFileHandle, bool sharedHandle = true)
		{
			if (FileIsOpen)
				Close();
			FileHandle = openFileHandle;
			FileIsOpen = true;
			SharedHandle = sharedHandle;
		}

		void Close ();
		static void Copy (const FilePath &sourcePath, const FilePath &destinationPath, bool preserveTimestamps = true);
		void Delete ();
		void Flush () const;
		uint32 GetDeviceSectorSize () const;
		static size_t GetOptimalReadSize () { return OptimalReadSize; }
		static size_t GetOptimalWriteSize ()  { return OptimalWriteSize; }
		uint64 GetPartitionDeviceStartOffset () const;
		bool IsOpen () const { return FileIsOpen; }
		FilePath GetPath () const;
		uint64 Length () const;
		void Open (const FilePath &path, FileOpenMode mode = OpenRead, FileShareMode shareMode = ShareReadWrite, FileOpenFlags flags = FlagsNone);
		uint64 Read (const BufferPtr &buffer) const;
		void ReadCompleteBuffer (const BufferPtr &buffer) const;
		uint64 ReadAt (const BufferPtr &buffer, uint64 position) const;
		void SeekAt (uint64 position) const;
		void SeekEnd (int ofset) const;
		void Write (const ConstBufferPtr &buffer) const;
		void Write (const ConstBufferPtr &buffer, size_t length) const { Write (buffer.GetRange (0, length)); }
		void WriteAt (const ConstBufferPtr &buffer, uint64 position) const;

	protected:
		void ValidateState () const;

		static const size_t OptimalReadSize = 256 * 1024;
		static const size_t OptimalWriteSize = 256 * 1024;

		bool FileIsOpen;
		FileOpenFlags mFileOpenFlags;
		bool SharedHandle;
		FilePath Path;
		SystemFileHandleType FileHandle;

#ifdef TC_WINDOWS
#else
		time_t AccTime;
		time_t ModTime;
#endif

	private:
		File (const File &);
		File &operator= (const File &);
	};
}

#endif // TC_HEADER_Platform_File
)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="Release" IntermediateDirectory="Release" ConfigurationType="0" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" > <Tool Name="VCNMakeTool" BuildCommandLine="echo ------ Building veracrypt.sys: Release x86 ------&#x0D;&#x0A;cmd.exe /c BuildDriver.cmd -build -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;&#x0D;&#x0A;if errorlevel 1 exit %errorlevel%&#x0D;&#x0A;echo.&#x0D;&#x0A;echo ------ Building veracrypt.sys: Release x64 ------&#x0D;&#x0A;BuildDriver.cmd -build -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" ReBuildCommandLine="echo ------ Rebuilding veracrypt.sys: Release x86 ------&#x0D;&#x0A;cmd.exe /c BuildDriver.cmd -rebuild -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;&#x0D;&#x0A;if errorlevel 1 exit %errorlevel%&#x0D;&#x0A;echo.&#x0D;&#x0A;echo ------ Rebuilding veracrypt.sys: Release x64 ------&#x0D;&#x0A;BuildDriver.cmd -rebuild -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" CleanCommandLine="echo ------ Cleaning veracrypt.sys: Release x86 ------&#x0D;&#x0A;cmd.exe /c BuildDriver.cmd -clean -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;&#x0D;&#x0A;if errorlevel 1 exit %errorlevel%&#x0D;&#x0A;echo.&#x0D;&#x0A;echo ------ Cleaning veracrypt.sys: Release x64 ------&#x0D;&#x0A;BuildDriver.cmd -clean -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" Output="" PreprocessorDefinitions="TC_WINDOWS_DRIVER" IncludeSearchPath="&quot;$(ProjectDir)&quot;;&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(WINDDK_ROOT)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> <Configuration Name="Release x86|Win32" OutputDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="0" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" > <Tool Name="VCNMakeTool" BuildCommandLine="BuildDriver.cmd -build -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" ReBuildCommandLine="BuildDriver.cmd -rebuild -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" CleanCommandLine="BuildDriver.cmd -clean -release -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" Output="" PreprocessorDefinitions="TC_WINDOWS_DRIVER" IncludeSearchPath="&quot;$(ProjectDir)&quot;;&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(WINDDK_ROOT)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> <Configuration Name="Debug x86|Win32" OutputDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="0" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" > <Tool Name="VCNMakeTool" BuildCommandLine="if exist $(SolutionDir)\Mount\Debug\VeraCrypt.exe ( copy $(SolutionDir)\Mount\Debug\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\i386\VeraCrypt.exe &gt;NUL:&#x0D;&#x0A;) else ( copy $(SolutionDir)\Mount\Release\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\i386\VeraCrypt.exe &gt;NUL: )&#x0D;&#x0A;&#x0D;&#x0A;BuildDriver.cmd -build -debug -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" ReBuildCommandLine="if exist $(SolutionDir)\Mount\Debug\VeraCrypt.exe ( copy $(SolutionDir)\Mount\Debug\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\i386\VeraCrypt.exe &gt;NUL:&#x0D;&#x0A;) else ( copy $(SolutionDir)\Mount\Release\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\i386\VeraCrypt.exe &gt;NUL: )&#x0D;&#x0A;&#x0D;&#x0A;BuildDriver.cmd -rebuild -debug -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" CleanCommandLine="BuildDriver.cmd -clean -debug -x86 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" Output="$(ProjectDir)\obj_driver_debug\i386\VeraCrypt.exe" PreprocessorDefinitions="DEBUG;_DEBUG;TC_WINDOWS_DRIVER" IncludeSearchPath="&quot;$(ProjectDir)&quot;;&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(WINDDK_ROOT)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> <Configuration Name="Release x64|Win32" OutputDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="0" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" > <Tool Name="VCNMakeTool" BuildCommandLine="BuildDriver.cmd -build -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" ReBuildCommandLine="BuildDriver.cmd -rebuild -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" CleanCommandLine="BuildDriver.cmd -clean -release -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" Output="" PreprocessorDefinitions="TC_WINDOWS_DRIVER" IncludeSearchPath="&quot;$(ProjectDir)&quot;;&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(WINDDK_ROOT)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> <Configuration Name="Debug x64|Win32" OutputDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="0" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" > <Tool Name="VCNMakeTool" BuildCommandLine="if exist $(SolutionDir)\Mount\Debug\VeraCrypt.exe ( copy $(SolutionDir)\Mount\Debug\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\amd64\VeraCrypt.exe &gt;NUL:&#x0D;&#x0A;) else ( copy $(SolutionDir)\Mount\Release\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\amd64\VeraCrypt.exe &gt;NUL: )&#x0D;&#x0A;&#x0D;&#x0A;BuildDriver.cmd -build -debug -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" ReBuildCommandLine="if exist $(SolutionDir)\Mount\Debug\VeraCrypt.exe ( copy $(SolutionDir)\Mount\Debug\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\amd64\VeraCrypt.exe &gt;NUL:&#x0D;&#x0A;) else ( copy $(SolutionDir)\Mount\Release\VeraCrypt.exe $(ProjectDir)\obj_driver_debug\amd64\VeraCrypt.exe &gt;NUL: )&#x0D;&#x0A;&#x0D;&#x0A;BuildDriver.cmd -rebuild -debug -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" CleanCommandLine="BuildDriver.cmd -clean -debug -x64 &quot;$(SolutionDir)\Common&quot; &quot;$(SolutionDir)\Crypto&quot; &quot;$(ProjectDir)&quot;" Output="$(ProjectDir)\obj_driver_debug\amd64\VeraCrypt.exe" PreprocessorDefinitions="DEBUG;_DEBUG;TC_WINDOWS_DRIVER" IncludeSearchPath="&quot;$(ProjectDir)&quot;;&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(WINDDK_ROOT)\inc\ddk&quot;;&quot;$(WINDDK_ROOT)\inc\api&quot;" ForcedIncludes="" AssemblySearchPath="" ForcedUsingAssemblies="" CompileAsManaged="" /> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="Source Files" Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File RelativePath=".\DriveFilter.c" > </File> <File RelativePath=".\DumpFilter.c" > </File> <File RelativePath=".\EncryptedIoQueue.c" > </File> <File RelativePath=".\Ntdriver.c" > </File> <File RelativePath=".\Ntvol.c" > </File> <File RelativePath=".\VolumeFilter.c" > </File> <Filter Name="Common" > <File RelativePath="..\Common\Cache.c" > </File> <File RelativePath="..\Common\Crc.c" > </File> <File RelativePath="..\Common\Crypto.c" > </File> <File RelativePath="..\Common\EncryptionThreadPool.c" > </File> <File RelativePath="..\Common\Endian.c" > </File> <File RelativePath="..\Common\GfMul.c" > </File> <File RelativePath="..\Common\Pkcs5.c" > </File> <File RelativePath="..\Common\Tests.c" > </File> <File RelativePath="..\Common\Volumes.c" > </File> <File RelativePath="..\Common\Wipe.c" > </File> <File RelativePath="..\Common\Xts.c" > </File> </Filter> <Filter Name="Crypto" > <File RelativePath="..\Crypto\Aes_hw_cpu.asm" > </File> <File RelativePath="..\Crypto\Aes_x64.asm" > </File> <File RelativePath="..\Crypto\Aes_x86.asm" > </File> <File RelativePath="..\Crypto\Aeskey.c" > </File> <File RelativePath="..\Crypto\Aestab.c" > </File> <File RelativePath="..\Crypto\Rmd160.c" > </File> <File RelativePath="..\Crypto\Serpent.c" > </File> <File RelativePath="..\Crypto\Sha2.c" > </File> <File RelativePath="..\Crypto\Twofish.c" > </File> <File RelativePath="..\Crypto\Whirlpool.c" > </File> </Filter> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File RelativePath="..\Common\Apidrvr.h" > </File> <File RelativePath="..\Common\Cache.h" > </File> <File RelativePath="..\Common\Common.h" > </File> <File RelativePath=".\DriveFilter.h" > </File> <File RelativePath=".\DumpFilter.h" > </File> <File RelativePath=".\EncryptedIoQueue.h" > </File> <File RelativePath="..\Common\EncryptionThreadPool.h" > </File> <File RelativePath="..\Common\GfMul.h" > </File> <File RelativePath=".\Ntdriver.h" > </File> <File RelativePath=".\Ntvol.h" > </File> <File RelativePath=".\resource.h" > </File> <File RelativePath="..\Common\Tcdefs.h" > </File> <File RelativePath=".\VolumeFilter.h" > </File> <File RelativePath="..\Common\Volumes.h" > </File> <File RelativePath="..\Common\Wipe.h" > </File> <File RelativePath="..\Common\Xts.h" > </File> </Filter> <Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" > <File RelativePath=".\Driver.rc" > </File> </Filter> <Filter Name="Build Files" > <File RelativePath=".\BuildDriver.cmd" > </File> <File RelativePath=".\Makefile" > </File> <File RelativePath=".\Sources" > </File> <Filter Name="Common" > <File RelativePath="..\Common\Makefile" > </File> <File RelativePath="..\Common\Sources" > </File> </Filter> <Filter Name="Crypto" > <File RelativePath="..\Crypto\Makefile" > </File> <File RelativePath="..\Crypto\Makefile.inc" > </File> <File RelativePath="..\Crypto\Sources" > </File> </Filter> </Filter> </Files> <Globals> </Globals> </VisualStudioProject>