|
|
1.1 root 1: /*
1.1.1.4 root 2: Copyright (c) 2008-2009 TrueCrypt Foundation. All rights reserved.
1.1 root 3:
1.1.1.6 ! root 4: Governed by the TrueCrypt License 2.8 the full text of which is contained
1.1 root 5: in the file License.txt included in TrueCrypt binary and source code
6: distribution 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; }
1.1.1.3 root 72: uint64 GetPartitionDeviceStartOffset () const;
1.1 root 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:
1.1.1.4 root 89: static const size_t OptimalReadSize = 256 * 1024;
90: static const size_t OptimalWriteSize = 256 * 1024;
1.1 root 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 archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.