|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 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; } ! 72: bool IsOpen () const { return FileIsOpen; } ! 73: FilePath GetPath () const; ! 74: uint64 Length () const; ! 75: void Open (const FilePath &path, FileOpenMode mode = OpenRead, FileShareMode shareMode = ShareReadWrite, FileOpenFlags flags = FlagsNone); ! 76: uint64 Read (const BufferPtr &buffer) const; ! 77: void ReadCompleteBuffer (const BufferPtr &buffer) const; ! 78: uint64 ReadAt (const BufferPtr &buffer, uint64 position) const; ! 79: void SeekAt (uint64 position) const; ! 80: void SeekEnd (int ofset) const; ! 81: void Write (const ConstBufferPtr &buffer) const; ! 82: void Write (const ConstBufferPtr &buffer, size_t length) const { Write (buffer.GetRange (0, length)); } ! 83: void WriteAt (const ConstBufferPtr &buffer, uint64 position) const; ! 84: ! 85: protected: ! 86: void ValidateState () const; ! 87: ! 88: static const size_t OptimalReadSize = 65536; // Specifies the most efficient size of a single read operation ! 89: static const size_t OptimalWriteSize = 65536; // Specifies the most efficient size of a single write operation ! 90: ! 91: bool FileIsOpen; ! 92: FileOpenFlags mFileOpenFlags; ! 93: bool SharedHandle; ! 94: FilePath Path; ! 95: SystemFileHandleType FileHandle; ! 96: ! 97: #ifdef TC_WINDOWS ! 98: #else ! 99: time_t AccTime; ! 100: time_t ModTime; ! 101: #endif ! 102: ! 103: private: ! 104: File (const File &); ! 105: File &operator= (const File &); ! 106: }; ! 107: } ! 108: ! 109: #endif // TC_HEADER_Platform_File
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.