Update README.md
[nemesis.git] / Platform / File.h
1 /*
2  Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.
3
4  Governed by the TrueCrypt License 3.0 the full text of which is contained in
5  the file License.txt included in TrueCrypt binary and source code distribution
6  packages.
7 */
8
9 #ifndef TC_HEADER_Platform_File
10 #define TC_HEADER_Platform_File
11
12 #include "PlatformBase.h"
13 #include "Buffer.h"
14 #include "FilesystemPath.h"
15 #include "SystemException.h"
16
17 namespace TrueCrypt
18 {
19         class File
20         {
21         public:
22                 enum FileOpenMode
23                 {
24                         CreateReadWrite,
25                         CreateWrite,
26                         OpenRead,
27                         OpenWrite,
28                         OpenReadWrite
29                 };
30
31                 enum FileShareMode
32                 {
33                         ShareNone,
34                         ShareRead,
35                         ShareReadWrite,
36                         ShareReadWriteIgnoreLock
37                 };
38
39                 enum FileOpenFlags
40                 {
41                         // Bitmap
42                         FlagsNone = 0,
43                         PreserveTimestamps = 1 << 0,
44                         DisableWriteCaching = 1 << 1
45                 };
46
47 #ifdef TC_WINDOWS
48                 typedef FILE* SystemFileHandleType;
49 #else
50                 typedef int SystemFileHandleType;
51 #endif
52
53                 File () : FileIsOpen (false), SharedHandle (false) { }
54                 virtual ~File ();
55                         
56                 void AssignSystemHandle (SystemFileHandleType openFileHandle, bool sharedHandle = true)
57                 {
58                         if (FileIsOpen)
59                                 Close();
60                         FileHandle = openFileHandle;
61                         FileIsOpen = true;
62                         SharedHandle = sharedHandle;
63                 }
64
65                 void Close ();
66                 static void Copy (const FilePath &sourcePath, const FilePath &destinationPath, bool preserveTimestamps = true);
67                 void Delete ();
68                 void Flush () const;
69                 uint32 GetDeviceSectorSize () const;
70                 static size_t GetOptimalReadSize () { return OptimalReadSize; }
71                 static size_t GetOptimalWriteSize ()  { return OptimalWriteSize; }
72                 uint64 GetPartitionDeviceStartOffset () const;
73                 bool IsOpen () const { return FileIsOpen; }
74                 FilePath GetPath () const;
75                 uint64 Length () const;
76                 void Open (const FilePath &path, FileOpenMode mode = OpenRead, FileShareMode shareMode = ShareReadWrite, FileOpenFlags flags = FlagsNone);
77                 uint64 Read (const BufferPtr &buffer) const;
78                 void ReadCompleteBuffer (const BufferPtr &buffer) const;
79                 uint64 ReadAt (const BufferPtr &buffer, uint64 position) const;
80                 void SeekAt (uint64 position) const;
81                 void SeekEnd (int ofset) const;
82                 void Write (const ConstBufferPtr &buffer) const;
83                 void Write (const ConstBufferPtr &buffer, size_t length) const { Write (buffer.GetRange (0, length)); }
84                 void WriteAt (const ConstBufferPtr &buffer, uint64 position) const;
85                 
86         protected:
87                 void ValidateState () const;
88
89                 static const size_t OptimalReadSize = 256 * 1024;
90                 static const size_t OptimalWriteSize = 256 * 1024;
91
92                 bool FileIsOpen;
93                 FileOpenFlags mFileOpenFlags;
94                 bool SharedHandle;
95                 FilePath Path;
96                 SystemFileHandleType FileHandle;
97
98 #ifdef TC_WINDOWS
99 #else
100                 time_t AccTime;
101                 time_t ModTime;
102 #endif
103
104         private:
105                 File (const File &);
106                 File &operator= (const File &);
107         };
108 }
109
110 #endif // TC_HEADER_Platform_File
This page took 0.021746 seconds and 3 git commands to generate. Download a nemesis OSX (sierra+high sierra, tested/working) binary, with fuse-ext3 via e2fsprogs, at this link. application and installer are signed by screwjack, llc. must install fuse with macFUSE layer first.