Beispiel #1
0
 internal MBRPartition(IBMPartitionInformation info, MBR mbr)
 {
     Mbr    = mbr;
     Start  = info.StartLBA;
     Length = info.LengthLBA;
     //Identifier = info.PartitionType;
     blockDev = mbr.blockdevice;
 }
Beispiel #2
0
        private void FinishBuildDisksLinux()
        {
            // Maybe the returned layout is partial because disks are loops (proxied Linux VM backup...)
            List <string> loopNames = new List <string>();

            foreach (IDiskElement elt in layout.Entries)
            {
                if (elt is Disk && ((Disk)elt).Type == DiskType.Loop /*&& ((Disk)elt).Enabled*/)
                {
                    Disk disk = (Disk)elt;
                    loopH = new LinuxLoopDeviceHelper();
                    try{
                        string loopPath = loopH.GetLoop(disk.ProxiedPath, "");
                        Logger.Append(Severity.DEBUG, "Obtained loop device " + loopPath + " for fuse device " + disk.ProxiedPath);
                        disk.ProxiedPath = loopPath;
                        if (loopPath != null)
                        {
                            loopNames.Add(loopPath.Substring(loopPath.LastIndexOf("/") + 1));
                            Console.WriteLine(" #### Added loopPath  " + loopPath.Substring(loopPath.LastIndexOf("/")));
                        }
                    }
                    catch (Exception e) {
                        Logger.Append(Severity.ERROR, "Couldn't create loop device for disk '" + disk.ProxiedPath + "' : " + e.Message);
                    }

                    /*
                     * Logger.Append(Severity.DEBUG, "Disk '"+disk.ProxiedPath+"' got loop entry "+loopPath);
                     * // update disk proxied path, since we'll have to use instead of the original proxied path
                     * // wich is now useless for the rest of operations
                     * disk.ProxiedPath = loopPath;
                     *
                     *
                     * }
                     * else{
                     * Logger.Append(Severity.WARNING, "Disk '"+disk.ProxiedPath+"' could'nt got a loop device entry.");
                     * disk.Enabled = false;
                     * }*/
                }
            }

            //If we are asked to manage loop devices, call Linux discoverer  to the rescue
            // and replace actual layout by the one we got from it
            if (loopNames.Count > 0)
            {
                lsd           = new LinuxStorageDiscoverer();
                lsd.LogEvent += LogReceivedEvent;
                lsd.Initialize(loopNames, Path.Combine(Utilities.ConfigManager.GetValue("Storage.IndexPath"), "tmp"));
                StorageLayout fromLinuxDiscovererLayout = lsd.BuildStorageLayout();

                foreach (IDiskElement ldlEntry in fromLinuxDiscovererLayout.Entries)
                {
                    foreach (IDiskElement elt in layout.Entries)
                    {
                        if (!(elt is Disk) || !(ldlEntry is Disk))
                        {
                            continue;
                        }
                        Console.WriteLine("vmware disk path=" + elt.Path + ", proxiedpath=" + ((Disk)elt).ProxiedPath + ", linuxdisco path=" + ldlEntry.Path + ", linuxdisco proxiedpath=" + ((Disk)ldlEntry).ProxiedPath);
                        if (((Disk)elt).ProxiedPath == ((Disk)ldlEntry).Path)
                        {
                            foreach (IDiskElement newE in ldlEntry.Children)
                            {
                                elt.AddChild(newE);
                            }
                        }
                    }
                }
            }
            //disk.Children.AddRange(lsd.GetSysfsPartitions(disk.ProxiedPath, ""));


            // Now, we should have everything that is was possible to gather about disk layout.
            // Finish it by parsing MBR/bootmanager and compare partitions layouts
            foreach (IDiskElement elt in layout.Entries)
            {
                if (!(elt is Disk))
                {
                    continue;
                }
                Disk d = (Disk)elt;
                if (d.BlockStream == null)
                {
                    Logger.Append(Severity.ERROR, "No access to block device '" + d.Path + "' stream, cannot finish building disk layout");
                    continue;
                }
                d.MbrBytes = new byte[512];
                d.BlockStream.Read(d.MbrBytes, 0, 512);
                MBR mbr = new MBR(d.MbrBytes);
                d.Signature = mbr.DiskSignature;

                /*if(d.TreatAsLoop)
                 *      disk.Children.AddRange(lsd.GetSysfsPartitions(disk.ProxiedPath, ""));
                 * else
                 *      disk.Children.AddRange(lsd.GetSysfsPartitions(disk.Path, ""));*/
                foreach (Partition p in GetPartitionsFromMBR(d))
                {
                    bool ofound = false;
                    foreach (IDiskElement dskE in d.Children)
                    {
                        //Console.WriteLine ("     EEEEEEEEEEEE  current elt is "+dskE.ToString());
                        if (!(dskE is Partition))
                        {
                            continue;
                        }

                        Partition tempP = (Partition)dskE;
                        //Console.WriteLine ("     EEEEEEEEEEEE MBR says : "+p.ToString());
                        //Console.WriteLine ("     EEEEEEEEEEEEinside layout.children.Children : "+tempP.ToString());
                        if (tempP.Offset != p.Offset)
                        {
                            continue;
                        }
                        ofound = true;
                        if (dskE.Size == 0)
                        {
                            Logger.Append(Severity.TRIVIA, "added 'size' information to partition with offset " + dskE.Offset);
                            dskE.Size = p.Size;
                        }
                        if (dskE.Size != p.Size)
                        {
                            Logger.Append(Severity.WARNING, "Mismatch in 'size' information between discoverer and MBR for partition with offset " + dskE.Offset
                                          + ", trusting MBR");
                            dskE.Size = p.Size;
                        }
                        tempP.Type = p.Type;
                        break;
                    }
                    if (!ofound)                     // MBR partition undected by storage discoverer
                    {
                        Logger.Append(Severity.TRIVIA, "Adding new partition from MBR, previously undiscovered. Partition is " + p.ToString());
                        elt.AddChild(p);
                    }
                }
            }
        }
Beispiel #3
0
        private static List <Partition> GetPartitionsFromMBR(IDiskElement element)
        {
            //	foreach(IDiskElement subElts in element.Children){
            //check if there are already PartitionSchemes for this disk
            //if(
            //}
            List <Partition> partitions = new List <Partition>();

            //try to find if disk element has an MBR, and, if yes, read it and retrieve partitions
            Logger.Append(Severity.DEBUG, "Discovering block device '" + element.Path + "' partitions...");
            MBR mbr;

            if (element is Disk && ((Disk)element).MbrBytes != null)
            {
                Logger.Append(Severity.TRIVIA, "Disc has MBR sector attached");
                mbr = new MBR(((Disk)element).MbrBytes);
            }
            else if (!string.IsNullOrEmpty(element.Path))
            {
                mbr = new MBR(element.Path);
            }
            else
            {
                return(null);
            }

            //if (mbr.IsValid()){
            int i = 0;

            foreach (IBMPartitionInformation partition in mbr.Partitions)
            {
                if (partition.StartLBA == 0 && partition.LengthLBA == 0)
                {
                    continue;                     // unaffected partition
                }
                i++;
                Partition part = new Partition();

                /*if(Node.Utilities.PlatForm.IsUnixClient())
                 *      part.Path = "/dev/*/
                part.Bootable = partition.Bootable;
                part.Schema   = PartitionSchemes.Classical;
                part.Type     = partition.PartitionType;
                part.Offset   = partition.StartLBA;
                part.Size     = partition.LengthLBA * 512;                    // ????? s this correct?
                part.Parents.Add(element);
                Logger.Append(Severity.DEBUG, "Found partition, type " + part.Type.ToString() + ", offset " + part.Offset + ", size " + part.Size / 1024 / 1024 + "MB, bootable:" + part.Bootable);
                if (part.Type == PartitionTypes.LinuxExtended ||
                    part.Type == PartitionTypes.Microsoft_Extended ||
                    part.Type == PartitionTypes.Microsoft_Extended_LBA)
                {
                    try{
                        part.IsComplete  = false;
                        part.BlockStream = ((Disk)element).BlockStream;

                        //debug

                        List <Partition> extendedParts = GetExtendedPartitions(part, part.Offset, 0);

                        /*foreach(Partition extP in extendedParts)
                         *      Console.WriteLine (" EXTENDED : got "+extP.ToString());*/

                        partitions.AddRange(extendedParts);
                    }
                    catch (Exception e) {
                        Logger.Append(Severity.DEBUG, "Extended partition doesn't seem to have child partitions : " + e.ToString());
                    }
                }
                else if (part.Type == PartitionTypes.EFI_GPT_Disk || part.Type == PartitionTypes.EFI_System_Partition)
                {
                    Logger.Append(Severity.WARNING, "Found partitions indentifying themselves as GPT. GPT/EFI is not yet supported!");
                }
                else
                {
                    part.IsComplete = true;
                }
                partitions.Add(part);
            }
            //}
            //else

            return(partitions);
        }
Beispiel #4
0
 internal IBMPartitionInformation(MBR mbr, int index)
 {
     this.mbr    = mbr;
     this.offset = 446 + 16 * index;
 }