コード例 #1
0
        public override void Init()
        {
            if (DriveType == ATA.SpecLevel.Null)
            {
                return;
            }
            if (DriveType == ATA.SpecLevel.ATA)
            {
                SendCmd(ATA.Cmd.Identify);
            }
            else
            {
                SendCmd(ATA.Cmd.IdentifyPacket);
            }
            var xBuff = (ushort *)Heap.alloc(512);

            for (int i = 0; i < 256; i++)
            {
                xBuff[i] = IOPort.inw(IOData);
            }
            SerialNo    = GetString(xBuff, 10, 20);
            FirmwareRev = GetString(xBuff, 23, 8);
            ModelNo     = GetString(xBuff, 27, 40);
            BlockCount  = ((uint)xBuff[61] << 16 | xBuff[60]) - 1;
            LBA48Bit    = (xBuff[83] & 0x40) != 0;
            if (LBA48Bit)
            {
                BlockCount = ((ulong)xBuff[102] << 32 | (ulong)xBuff[101] << 16 | (ulong)xBuff[100]) - 1;
            }
            byte *xMbrData = (byte *)Heap.alloc(512);

            ReadBlock(0, 1, xMbrData);
            MBR xMBR = new MBR();

            xMBR.Setup(this, xMbrData);

            int parts = 0;

            for (int i = 0; i < xMBR.partitions.Length; i++)
            {
                if (xMBR.partitions[i] != null)
                {
                    DeviceManager.AllDevices.Add(xMBR.partitions[i]);
                    parts++;
                }
            }
            Console.Write(mControllerID == ControllerIdEnum.Primary ? "Primary" : "Secondary");
            Console.Write(" drive on ");
            Console.Write(mBusPosition == BusPositionEnum.Master ? "Master" : "Slave");
            Console.Write(" bus with ");
            Console.Write(parts);
            Console.WriteLine(" partitions");
        }
コード例 #2
0
        public ATADiskDrive(bool primary, ATAControllerIdEnum aControllerId, ATABusPositionEnum aBusPosition, ATASpecLevel mDriveType)
        {
            var xBAR0 = (ushort)(!primary ? 0x0170 : 0x01F0);
            var xBAR1 = (ushort)(!primary ? 0x0374 : 0x03F4);

            IOControl      = (ushort)(xBAR1 + 2);
            IOCommand      = (ushort)(xBAR0 + 7);
            IOData         = (ushort)xBAR0;
            IOStatus       = (ushort)(xBAR0 + 7);
            IODeviceSelect = (ushort)(xBAR0 + 6);
            IOLBA0         = (ushort)(xBAR0 + 3);
            IOLBA1         = (ushort)(xBAR0 + 4);
            IOLBA2         = (ushort)(xBAR0 + 5);
            IOSectorCount  = (ushort)(xBAR0 + 2);
            mControllerID  = aControllerId;
            mBusPosition   = aBusPosition;
            DriveType      = mDriveType;

            if (DriveType == ATASpecLevel.ATA)
            {
                SendATACmd(ATACmd.Identify, IOCommand, IOStatus);
            }
            else
            {
                SendATACmd(ATACmd.IdentifyPacket, IOCommand, IOStatus);
            }
            var xBuff = (ushort *)Heap.alloc(512);

            for (int i = 0; i < 256; i++)
            {
                ushort read  = IOPort.inw(IOData);
                byte   upper = (byte)(read >> 8);
                byte   lower = (byte)read;
                xBuff[i] = (ushort)((lower << 8) | upper);
            }

            SerialNo    = GetString(xBuff, 10, 20);
            FirmwareRev = GetString(xBuff, 23, 8);
            ModelNo     = GetString(xBuff, 27, 40);
            DeviceLa    = GetString(xBuff, 54, 40);
            uint  l   = 0;
            byte *ptr = DeviceLa;

            while (*ptr != 0)
            {
                ptr++;
                l++;
            }
            char[] tmp = new char[l];
            for (int i = 0; i < l; i++)
            {
                tmp[i] = (char)DeviceLa[i];
            }
            Label = new string(tmp);

            BlockCount = ((uint)xBuff[61] << 16 | xBuff[60]) - 1;
            LBA48Bit   = (xBuff[83] & 0x40) != 0;
            if (LBA48Bit)
            {
                BlockCount = ((ulong)xBuff[102] << 32 | (ulong)xBuff[101] << 16 | (ulong)xBuff[100]) - 1;
            }
            byte *xMbrData = (byte *)Heap.alloc(512);

            ReadBlock(0, 1, xMbrData);
            MBR xMBR = new MBR();

            xMBR.Setup(this, xMbrData);

            for (int i = 0; i < xMBR.partitions.Count; i++)
            {
                DetectedPartitions.Add(xMBR.partitions[i]);
            }
        }