Exemplo n.º 1
0
        private void InitiateCommon(string dosName, FileAccess access)
        {
            Debug.WriteLine("Initiating with " + dosName);

            DiskHandle    = PlatformShim.CreateDeviceHandle(dosName, access);
            DosDeviceName = dosName;

            if (DiskHandle.IsInvalid)
            {
                throw new ArgumentException("Invalid diskName: " + dosName);
            }

            _access = access;

            _deviceIo = new DiskDeviceWrapper(DiskHandle);
            _diskFs   = new FileStream(DiskHandle, _access);

            _diskInfo     = _deviceIo.DiskGetDriveGeometry();
            _deviceLength = _deviceIo.DiskGetLengthInfo();
        }
Exemplo n.º 2
0
        private static void ExampleDiskIO()
        {
            const string drive = @"\\.\PhysicalDrive0";

            Console.WriteLine(@"## Exmaple on {0} ##", drive);
            SafeFileHandle hddHandle = CreateFile(drive, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);

            if (hddHandle.IsInvalid)
            {
                int lastError = Marshal.GetLastWin32Error();

                Console.WriteLine(@"!! Invalid {0}; Error ({1}): {2}", drive, lastError, new Win32Exception(lastError).Message);
                Console.WriteLine();
                return;
            }

            using (DiskDeviceWrapper diskIo = new DiskDeviceWrapper(hddHandle, true))
            {
                DISK_GEOMETRY_EX info = diskIo.DiskGetDriveGeometryEx();

                Console.WriteLine("Sector size: " + info.Geometry.BytesPerSector);

                switch (info.PartitionInformation.PartitionStyle)
                {
                case PartitionStyle.PARTITION_STYLE_MBR:
                    Console.WriteLine("MBR Id: " + info.PartitionInformation.MbrSignature);
                    break;

                case PartitionStyle.PARTITION_STYLE_GPT:
                    Console.WriteLine("GPT GUID: " + info.PartitionInformation.GptGuidId);
                    break;
                }

                PARTITION_INFORMATION_EX partitionInfo = diskIo.DiskGetPartitionInfoEx();

                Console.WriteLine("Partition style: " + partitionInfo.PartitionStyle);
            }

            Console.WriteLine();
        }
Exemplo n.º 3
0
 public DiskExGet(SafeFileHandle diskHandle)
 {
     dge  = null;
     pie  = null;
     dlie = null;
     da   = null;
     sddp = null;
     try
     {
         DiskDeviceWrapper diskDeviceWrapper = new DiskDeviceWrapper(diskHandle, false);
         try
         {
             dge = diskDeviceWrapper.DiskGetDriveGeometryEx();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             pie = diskDeviceWrapper.DiskGetPartitionInfoEx();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             dlie = diskDeviceWrapper.DiskGetDriveLayoutEx();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             vip = diskDeviceWrapper.DiskGetSmartVersion();     // <- PCIE SSD's and Raid controllers can have this disabled thus throwing an exception
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             //DISK_CACHE_INFORMATION dci = diskDeviceWrapper.DiskGetCacheInformation();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             da = diskDeviceWrapper.DiskGetDiskAttributes();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         try
         {
             // Some drives do not return data.
             StorageDeviceWrapperEx sdw = new StorageDeviceWrapperEx(diskHandle, false);
             sddp = sdw.StorageGetDeviceProperty();
         }
         catch (Exception e)
         {
             Log.Warn(e);
         }
         //MountManagerWrapper mmw = new MountManagerWrapper(disk.DiskHandle, false);
         //List<MountPoint> mps = mmw.MountQueryPoints();
     }
     catch (Exception e)
     {
         Log.Warn(e);
     }
 }