Exemple #1
0
        /// <summary>
        /// Attempts to initialise the ATA drive.
        /// </summary>
        protected void InitDrive()
        {
            // At this point, DiscoverDrive has been called, but the additional identification data
            // has not been read

            // If it's a PATAPI drive, we need to send the IDENTIFY_PACKET command
            if (mDriveType == SpecLevel.PATAPI)
            {
                Reset();
                SendCmd(Cmd.IdentifyPacket);
            }

            // Read Identification Space of the Device
            var deviceInfoBuffer = new UInt16[256];

            IO.Data.Read_UInt16s(deviceInfoBuffer);
            mSerialNo    = GetString(deviceInfoBuffer, 10, 20).Trim();
            mFirmwareRev = GetString(deviceInfoBuffer, 23, 8).Trim();
            mModelNo     = GetString(deviceInfoBuffer, 27, 40).Trim();

            // Hitachi hardrives found in real-world hardware failed in that:
            //      They only work with one-sector writes at a time
            //  This may be due to the fact that I'm working with old laptops and a sample size of one
            //  Hitachi drive. Newer drives may work properly. All drives will work with a max size of
            //  one though.
            //
            //  Fujitsu drives suffer a similar fault.
            if (mModelNo.StartsWith("Hitachi") || mModelNo.StartsWith("FUJITSU"))
            {
                maxWritePioBlocks = 1;
            }

            //Words (61:60) shall contain the value one greater than the total number of user-addressable
            //sectors in 28-bit addressing and shall not exceed 0x0FFFFFFF.
            // We need 28 bit addressing - small drives on VMWare and possibly other cases are 28 bit
            blockCount = ((UInt32)deviceInfoBuffer[61] << 16 | deviceInfoBuffer[60]) - 1;

            //Words (103:100) shall contain the value one greater than the total number of user-addressable
            //sectors in 48-bit addressing and shall not exceed 0x0000FFFFFFFFFFFF.
            //The contents of words (61:60) and (103:100) shall not be used to determine if 48-bit addressing is
            //supported. IDENTIFY DEVICE bit 10 word 83 indicates support for 48-bit addressing.
            bool xLba48Capable = (deviceInfoBuffer[83] & 0x400) != 0;

            if (xLba48Capable)
            {
                blockCount = ((UInt64)deviceInfoBuffer[103] << 48 | (UInt64)deviceInfoBuffer[102] << 32 | (UInt64)deviceInfoBuffer[101] << 16 | (UInt64)deviceInfoBuffer[100]) - 1;
                mLBA48Mode = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Parses a string as an signed decimal integer.
        /// </summary>
        /// <param name="str">The string to parse.</param>
        /// <returns>The parsed int.</returns>
        public static int Parse_DecimalSigned(FOS_System.String str)
        {
            bool neg    = str.StartsWith("-");
            int  result = (int)Parse_DecimalUnsigned(str, (neg ? 1 : 0));

            if (neg)
            {
                result *= -1;
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Attempts to initialise the ATA drive.
        /// </summary>
        protected void InitDrive()
        {
            // At this point, DiscoverDrive has been called, but the additional identification data 
            // has not been read

            // If it's a PATAPI drive, we need to send the IDENTIFY_PACKET command
            if (mDriveType == SpecLevel.PATAPI)
            {
                Reset();
                SendCmd(Cmd.IdentifyPacket);
            }

            // Read Identification Space of the Device
            var deviceInfoBuffer = new UInt16[256];
            IO.Data.Read_UInt16s(deviceInfoBuffer);
            mSerialNo = GetString(deviceInfoBuffer, 10, 20).Trim();
            mFirmwareRev = GetString(deviceInfoBuffer, 23, 8).Trim();
            mModelNo = GetString(deviceInfoBuffer, 27, 40).Trim();

            // Hitachi hardrives found in real-world hardware failed in that:
            //      They only work with one-sector writes at a time
            //  This may be due to the fact that I'm working with old laptops and a sample size of one
            //  Hitachi drive. Newer drives may work properly. All drives will work with a max size of 
            //  one though.
            //  
            //  Fujitsu drives suffer a similar fault.
            if (mModelNo.StartsWith("Hitachi") || mModelNo.StartsWith("FUJITSU"))
            {
                maxWritePioBlocks = 1;
            }

            //Words (61:60) shall contain the value one greater than the total number of user-addressable
            //sectors in 28-bit addressing and shall not exceed 0x0FFFFFFF. 
            // We need 28 bit addressing - small drives on VMWare and possibly other cases are 28 bit
            blockCount = ((UInt32)deviceInfoBuffer[61] << 16 | deviceInfoBuffer[60]) - 1;

            //Words (103:100) shall contain the value one greater than the total number of user-addressable
            //sectors in 48-bit addressing and shall not exceed 0x0000FFFFFFFFFFFF.
            //The contents of words (61:60) and (103:100) shall not be used to determine if 48-bit addressing is
            //supported. IDENTIFY DEVICE bit 10 word 83 indicates support for 48-bit addressing.
            bool xLba48Capable = (deviceInfoBuffer[83] & 0x400) != 0;
            if (xLba48Capable)
            {
                blockCount = ((UInt64)deviceInfoBuffer[103] << 48 | (UInt64)deviceInfoBuffer[102] << 32 | (UInt64)deviceInfoBuffer[101] << 16 | (UInt64)deviceInfoBuffer[100]) - 1;
                mLBA48Mode = true;
            }
        }