示例#1
0
        public DiskGeometry GetDiskGeometry(SafeHandle hDevice)
        {
            DiskGeometry geometry = new DiskGeometry();
            SafeAllocHandle <DISK_GEOMETRY> diskGeoPtr = null;

            try {
                diskGeoPtr = new SafeAllocHandle <DISK_GEOMETRY>();
                bool success = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, IntPtr.Zero, 0,
                                               diskGeoPtr, diskGeoPtr.SizeOf, out uint bytesReturns, IntPtr.Zero);
                if (!success || bytesReturns == 0)
                {
                    m_Win32Error = Marshal.GetLastWin32Error();
                    return(null);
                }
                DISK_GEOMETRY diskGeo = diskGeoPtr.ToStructure();
                geometry.MediaType         = diskGeo.MediaType;
                geometry.Cylinders         = diskGeo.Cylinders;
                geometry.TracksPerCylinder = diskGeo.TracksPerCylinder;
                geometry.SectorsPerTrack   = diskGeo.SectorsPerTrack;
                geometry.BytesPerSector    = diskGeo.BytesPerSector;
            } finally {
                if (diskGeoPtr != null)
                {
                    diskGeoPtr.Close();
                }
            }
            return(geometry);
        }
示例#2
0
        private void AddGeometry(IDictionary <string, ResultOrError <DiskGeometry> > dictionary, string path, XmlElement node)
        {
            if (node == null)
            {
                return;
            }
            if (dictionary.ContainsKey(path))
            {
                return;
            }

            // Because this is a complex type, The XML will always return the default value.
            ResultOrError <DiskGeometry> result = GetResultOrError <DiskGeometry>(node);

            if (result != null)
            {
                dictionary.Add(path, result);
                return;
            }

            string       mediaType = node["MediaType"].Attributes["result"].Value;
            string       cylinders = node["Cylinders"].Attributes["result"].Value;
            string       tracks    = node["TracksPerCylinder"].Attributes["result"].Value;
            string       sectors   = node["SectorsPerTrack"].Attributes["result"].Value;
            string       bytes     = node["BytesPerSector"].Attributes["result"].Value;
            DiskGeometry diskGeo   = new DiskGeometry()
            {
                MediaType         = (MediaType)int.Parse(mediaType, CultureInfo.InvariantCulture),
                Cylinders         = int.Parse(cylinders, CultureInfo.InvariantCulture),
                TracksPerCylinder = int.Parse(tracks, CultureInfo.InvariantCulture),
                SectorsPerTrack   = int.Parse(sectors, CultureInfo.InvariantCulture),
                BytesPerSector    = int.Parse(bytes, CultureInfo.InvariantCulture),
            };

            dictionary.Add(path, new ResultOrError <DiskGeometry>(diskGeo));
        }