Mosa.DeviceSystem.DiskGeometry.GuessGeometry C# (CSharp) Method

GuessGeometry() public method

Guesses the geometry.
public GuessGeometry ( ulong lba ) : void
lba ulong The lba.
return void
        public void GuessGeometry(ulong lba)
        {
            uint cylinderTimesHeads;

            if (lba > 65535 * 16 * 255)
                lba = 65535 * 16 * 255;

            if (lba >= 65535 * 16 * 63)
            {
                SectorsPerTrack = 255;
                Heads = 16;
                cylinderTimesHeads = (uint)(lba / SectorsPerTrack);
            }
            else
            {
                SectorsPerTrack = 17;
                cylinderTimesHeads = (uint)(lba / SectorsPerTrack);

                Heads = (byte)((cylinderTimesHeads + 1023) / 1024);

                if (Heads < 4)
                    Heads = 4;

                if (cylinderTimesHeads >= (Heads * 1024) || Heads > 16)
                {
                    SectorsPerTrack = 31;
                    Heads = 16;
                    cylinderTimesHeads = (uint)(lba / SectorsPerTrack);
                }

                if (cylinderTimesHeads >= (Heads * 1024))
                {
                    SectorsPerTrack = 63;
                    Heads = 16;
                    cylinderTimesHeads = (uint)(lba / SectorsPerTrack);
                }
            }

            Cylinders = (ushort)(cylinderTimesHeads / Heads);
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Writes the master boot block.
        /// </summary>
        /// <returns></returns>
        public bool Write()
        {
            if (!diskDevice.CanWrite)
            {
                return(false);
            }

            BinaryFormat masterboot = new BinaryFormat(new byte[512]);

            masterboot.SetUInt(MBR.DiskSignature, diskSignature);
            masterboot.SetUShort(MBR.MBRSignature, MBRConstant.MBRSignature);

            if (code != null)
            {
                for (uint index = 0; ((index < MBRConstant.CodeAreaSize) && (index < code.Length)); index++)
                {
                    masterboot.SetByte(index, code[index]);
                }
            }

            for (uint index = 0; index < MaxMBRPartitions; index++)
            {
                if (Partitions[index].TotalBlocks != 0)
                {
                    uint offset = MBR.FirstPartition + (index * 16);
                    masterboot.SetByte(offset + PartitionRecord.Status, (byte)(Partitions[index].Bootable ? 0x80 : 0x00));
                    masterboot.SetByte(offset + PartitionRecord.PartitionType, Partitions[index].PartitionType);
                    masterboot.SetUInt(offset + PartitionRecord.LBA, Partitions[index].StartLBA);
                    masterboot.SetUInt(offset + PartitionRecord.Sectors, Partitions[index].TotalBlocks);

                    DiskGeometry diskGeometry = new DiskGeometry();
                    diskGeometry.GuessGeometry(diskDevice.TotalBlocks);

                    CHS chsStart = new CHS();
                    CHS chsEnd   = new CHS();

                    chsStart.SetCHS(diskGeometry, Partitions[index].StartLBA);
                    chsEnd.SetCHS(diskGeometry, Partitions[index].StartLBA + Partitions[index].TotalBlocks - 1);

                    masterboot.SetByte(offset + PartitionRecord.FirstCRS, chsStart.Head);
                    masterboot.SetByte(offset + PartitionRecord.FirstCRS + 1, (byte)((chsStart.Sector & 0x3F) | ((chsStart.Cylinder >> 8) & 0x03)));
                    masterboot.SetByte(offset + PartitionRecord.FirstCRS + 2, (byte)(chsStart.Cylinder & 0xFF));
                    masterboot.SetByte(offset + PartitionRecord.LastCRS, chsEnd.Head);
                    masterboot.SetByte(offset + PartitionRecord.LastCRS + 1, (byte)((chsEnd.Sector & 0x3F) | ((chsEnd.Cylinder >> 8) & 0x03)));
                    masterboot.SetByte(offset + PartitionRecord.LastCRS + 2, (byte)(chsEnd.Cylinder & 0xFF));
                }
            }

            diskDevice.WriteBlock(0, 1, masterboot.Data);

            return(true);
        }
All Usage Examples Of Mosa.DeviceSystem.DiskGeometry::GuessGeometry