"Fossies" - the Fresh Open Source Software Archive

Member "src/Boot/Windows/BootDiskIo.h" (10 Oct 2018, 3277 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 "BootDiskIo.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_Boot_BootDiskIo
   14 #define TC_HEADER_Boot_BootDiskIo
   15 
   16 #include "Bios.h"
   17 #include "BootDebug.h"
   18 #include "BootDefs.h"
   19 
   20 #define TC_MAX_BIOS_DISK_IO_RETRIES 5
   21 
   22 enum
   23 {
   24     BiosResultEccCorrected = 0x11
   25 };
   26 
   27 #pragma pack(1)
   28 
   29 struct PartitionEntryMBR
   30 {
   31     byte BootIndicator;
   32 
   33     byte StartHead;
   34     byte StartCylSector;
   35     byte StartCylinder;
   36 
   37     byte Type;
   38 
   39     byte EndHead;
   40     byte EndSector;
   41     byte EndCylinder;
   42 
   43     uint32 StartLBA;
   44     uint32 SectorCountLBA;
   45 };
   46 
   47 struct MBR
   48 {
   49     byte Code[446];
   50     PartitionEntryMBR Partitions[4];
   51     uint16 Signature;
   52 };
   53 
   54 struct BiosLbaPacket
   55 {
   56     byte Size;
   57     byte Reserved;
   58     uint16 SectorCount;
   59     uint32 Buffer;
   60     uint64 Sector;
   61 };
   62 
   63 #pragma pack()
   64 
   65 
   66 struct ChsAddress
   67 {
   68     uint16 Cylinder;
   69     byte Head;
   70     byte Sector;
   71 };
   72 
   73 struct Partition
   74 {
   75     byte Number;
   76     byte Drive;
   77     bool Active;
   78     uint64 EndSector;
   79     bool Primary;
   80     uint64 SectorCount;
   81     uint64 StartSector;
   82     byte Type;
   83 };
   84 
   85 struct DriveGeometry
   86 {
   87     uint16 Cylinders;
   88     byte Heads;
   89     byte Sectors;
   90 };
   91 
   92 
   93 #ifdef TC_BOOT_DEBUG_ENABLED
   94 void AcquireSectorBuffer ();
   95 void ReleaseSectorBuffer ();
   96 #else
   97 #   define AcquireSectorBuffer()
   98 #   define ReleaseSectorBuffer()
   99 #endif
  100 
  101 void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba);
  102 bool GetActivePartition (byte drive);
  103 BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent = false);
  104 BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly = false, Partition *findPartitionFollowingThis = nullptr, bool silent = false);
  105 bool IsLbaSupported (byte drive);
  106 void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs);
  107 void Print (const ChsAddress &chs);
  108 void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs = nullptr);
  109 void PrintSectorCountInMB (const uint64 &sectorCount);
  110 BiosResult ReadWriteMBR (bool write, byte drive, bool silent = false);
  111 BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
  112 BiosResult ReadSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
  113 BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
  114 BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent);
  115 BiosResult WriteSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
  116 BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
  117 
  118 extern byte SectorBuffer[TC_LB_SIZE];
  119 
  120 #endif // TC_HEADER_Boot_BootDiskIo