示例#1
0
        public override void ReadDiskInformation()
        {
            // IOCTL_DISK_GET_DRIVE_GEOMETRY

            DiskGeometry = DeviceIoControl <Kernel32.DISK_GEOMETRY>(Kernel32.IOCTL_DISK_GET_DRIVE_GEOMETRY);

            BytesPerSector = DiskGeometry.BytesPerSector;

            // IOCTL_DISK_GET_DRIVE_LAYOUT

            var delta = Marshal.SizeOf(typeof(Kernel32.PARTITION_INFORMATION));

            var bytes = DeviceIoControl(Kernel32.IOCTL_DISK_GET_DRIVE_LAYOUT, Marshal.SizeOf(typeof(Kernel32.DRIVE_LAYOUT_INFORMATION)), delta * 4);

            DriveLayoutInformation = MarshalEx.BytesToStruct <Kernel32.DRIVE_LAYOUT_INFORMATION>(bytes);

            PartitionInformation = new Kernel32.PARTITION_INFORMATION[DriveLayoutInformation.PartitionCount];

            var offset = Marshal.SizeOf(typeof(Kernel32.DRIVE_LAYOUT_INFORMATION));

            for (var i = 0; i < DriveLayoutInformation.PartitionCount; i++)
            {
                PartitionInformation[i] = MarshalEx.BytesToStruct <Kernel32.PARTITION_INFORMATION>(bytes, offset, delta);

                offset += delta;
            }
        }
示例#2
0
        // DeviceIoControl

        public TypeOut DeviceIoControl <TypeOut>(UInt32 ioControlCode) where TypeOut : struct
        {
            var outBuffer = MarshalEx.AllocateBytesForStruct <TypeOut>();

            DeviceIoControl(ioControlCode, null, outBuffer);

            return(MarshalEx.BytesToStruct <TypeOut>(outBuffer));
        }
示例#3
0
        public TypeOut DeviceIoControl <TypeIn, TypeOut>(UInt32 ioControlCode, TypeIn inStruct) where TypeIn : struct where TypeOut : struct
        {
            var inBuffer  = MarshalEx.StructToBytes <TypeIn>(inStruct);
            var outBuffer = MarshalEx.AllocateBytesForStruct <TypeOut>();

            DeviceIoControl(ioControlCode, inBuffer, outBuffer);

            return(MarshalEx.BytesToStruct <TypeOut>(outBuffer));
        }
示例#4
0
        public override void ReadDiskInformation()
        {
            // PARTITION_INFORMATION

            PartitionInformation = DeviceIoControl <Kernel32.PARTITION_INFORMATION>(Kernel32.IOCTL_DISK_GET_PARTITION_INFO);

            Byte[] sector = Read(0, 512);
            VolumeBootRecord = MarshalEx.BytesToStruct <VolumeBootRecord>(sector);

            BytesPerSector = VolumeBootRecord.BiosParameterBlock.BytesPerSector;
        }