"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/File.h" (10 Oct 2018, 3019 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "File.h" see the Fossies "Dox" file reference documentation.

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