Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the specified disk device.
        /// </summary>
        /// <param name="aDiskDevice">The disk device to initialize.</param>
        public static void InitDisk(DiskDevice aDiskDevice)
        {
            //TODO - Add more partitioning schemes.


            if (InitAsISO9660(aDiskDevice))
            {
#if FSM_TRACE
                BasicConsole.WriteLine("ISO9660 CD/DVD disc detected!");
                BasicConsole.DelayOutput(3);
#endif
            }
            //Must check for GPT before MBR because GPT uses a protective
            //  MBR entry so will be seen as valid MBR.
            else if (InitAsGPT(aDiskDevice))
            {
#if FSM_TRACE
                BasicConsole.WriteLine("GPT formatted disk detected!");
                BasicConsole.DelayOutput(3);
#endif
            }
            else if (!InitAsMBR(aDiskDevice))
            {
                ExceptionMethods.Throw(new FOS_System.Exceptions.NotSupportedException("Non MBR/EBR/GPT/ISO9660 formatted disks not supported."));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Processes a valid GUID partition table to initialize its partitions.
 /// </summary>
 /// <param name="aGPT">The GPT to process.</param>
 /// <param name="aDiskDevice">The disk device from which the GPT was read.</param>
 private static void ProcessGPT(GPT aGPT, DiskDevice aDiskDevice)
 {
     for (int i = 0; i < aGPT.Partitions.Count; i++)
     {
         GPT.PartitionInfo aPartInfo = (GPT.PartitionInfo)aGPT.Partitions[i];
         Partitions.Add(new Partition(aDiskDevice, aPartInfo.FirstLBA, aPartInfo.LastLBA - aPartInfo.FirstLBA));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Processes a valid master boot record to initialize its partitions.
 /// </summary>
 /// <param name="anMBR">The MBR to process.</param>
 /// <param name="aDiskDevice">The disk device from which the MBR was read.</param>
 private static void ProcessMBR(MBR anMBR, DiskDevice aDiskDevice)
 {
     for (int i = 0; i < anMBR.NumPartitions; i++)
     {
         MBR.PartitionInfo aPartInfo = anMBR.Partitions[i];
         if (aPartInfo.EBRLocation != 0)
         {
             byte[] EBRData = new byte[512];
             aDiskDevice.ReadBlock(aPartInfo.EBRLocation, 1U, EBRData);
             EBR newEBR = new EBR(EBRData);
             ProcessMBR(newEBR, aDiskDevice);
         }
         else
         {
             Partitions.Add(new Partition(aDiskDevice, aPartInfo.StartSector, aPartInfo.SectorCount));
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to initialise a disk treating it as MBR formatted.
        /// </summary>
        /// <param name="aDiskDevice">The disk to initialise.</param>
        /// <returns>True if a valid MBR was detected and the disk was successfully initialised. Otherwise, false.</returns>
        private static bool InitAsMBR(DiskDevice aDiskDevice)
        {
#if FSM_TRACE
            BasicConsole.WriteLine("Attempting to read MBR...");
#endif
            byte[] MBRData = new byte[512];
            aDiskDevice.ReadBlock(0UL, 1U, MBRData);
#if FSM_TRACE
            BasicConsole.WriteLine("Read potential MBR data. Attempting to init MBR...");
#endif
            MBR TheMBR = new MBR(MBRData);

            if (!TheMBR.IsValid)
            {
                return false;
            }
            else
            {
#if FSM_TRACE
                BasicConsole.WriteLine("Valid MBR found.");
#endif
                ProcessMBR(TheMBR, aDiskDevice);

                return true;
            }
        }
Ejemplo n.º 5
0
 private static void ProcessISO9660(Disk.ISO9660 aISO9660, DiskDevice aDiskDevice)
 {
     for (int i = 0; i < aISO9660.VolumeDescriptors.Count; i++)
     {
         Disk.ISO9660.VolumeDescriptor volDescrip = (Disk.ISO9660.VolumeDescriptor)aISO9660.VolumeDescriptors[i];
         if (volDescrip is Disk.ISO9660.PrimaryVolumeDescriptor)
         {
             Partitions.Add(volDescrip);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Attempts to initialise a disk treating it as GPT formatted.
 /// </summary>
 /// <param name="aDiskDevice">The disk to initialise.</param>
 /// <returns>True if a valid GPT was detected and the disk was successfully initialised. Otherwise, false.</returns>
 private static bool InitAsGPT(DiskDevice aDiskDevice)
 {
     GPT TheGPT = new GPT(aDiskDevice);
     if (!TheGPT.IsValid)
     {
         return false;
     }
     else
     {
         ProcessGPT(TheGPT, aDiskDevice);
         return true;
     }
 }
Ejemplo n.º 7
0
        private static bool InitAsISO9660(DiskDevice aDiskDevice)
        {
            // Must check for ISO9660 only on CD/DVD drives
            if (aDiskDevice is Hardware.ATA.PATAPI)
            {
                Disk.ISO9660 TheISO9660 = new Disk.ISO9660(aDiskDevice);

#if FSM_TRACE
                TheISO9660.Print();
#endif
                ProcessISO9660(TheISO9660, aDiskDevice);

                return true;
            }

            return false;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new partition.
 /// </summary>
 /// <param name="aDiskDevice">The disk device on which the partition resides.</param>
 /// <param name="aStartingSector">The sector number at which the partition starts.</param>
 /// <param name="aSectorCount">The number of sectors in the partition.</param>
 public Partition(DiskDevice aDiskDevice, UInt64 aStartingSector, UInt64 aSectorCount)
 {
     TheDiskDevice = aDiskDevice;
     StartingSector = aStartingSector;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets the first partition, if any, of the specified disk.
 /// </summary>
 /// <param name="disk">The disk to get the first partition of.</param>
 /// <returns>The partition or null if none found.</returns>
 public static Partition GetFirstPartition(DiskDevice disk)
 {
     for (int i = 0; i < FOS_System.IO.FileSystemManager.Partitions.Count; i++)
     {
         FOS_System.IO.Partition part = (FOS_System.IO.Partition)FOS_System.IO.FileSystemManager.Partitions[i];
         if (part.TheDiskDevice == disk)
         {
             return part;
         }
     }
     return null;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Determines whether the specified disk has had any valid partitions detected.
 /// </summary>
 /// <param name="disk">The disk to check.</param>
 /// <returns>Whether the specified disk has had any valid partitions detected.</returns>
 public static bool HasPartitions(DiskDevice disk)
 {
     for (int i = 0; i < FOS_System.IO.FileSystemManager.Partitions.Count; i++)
     {
         FOS_System.IO.Partition part = (FOS_System.IO.Partition)FOS_System.IO.FileSystemManager.Partitions[i];
         if (part.TheDiskDevice == disk)
         {
             return true;
         }
     }
     return false;
 }