public List <Partition> GetAllPartitions(IDiskElement root) { List <Partition> partitions = new List <Partition>(); /*List<IDiskElement>*/ System.Collections.ObjectModel.ReadOnlyCollection <IDiskElement> rootElts = null; if (root == null) { rootElts = this.Entries.AsReadOnly(); } else { rootElts = root.Children; if (root is Partition) { partitions.Add((Partition)root); } } foreach (IDiskElement de in rootElts) { Console.WriteLine(" ->" + de.ToString()); //if(de is FileSystem) fsl.Add((FileSystem)de); partitions.AddRange(GetAllPartitions(de)); } return(partitions); }
public bool Equals(IDiskElement other) { if (this.GetType() != other.GetType()) { return(false); } if (this.Path != other.Path) { return(false); } if (this.Id != other.Id) { return(false); } return(true); }
public bool Equals(IDiskElement other) { if (this.GetType() != other.GetType()) { return(false); } if (this.Offset != other.Offset) { return(false); } /*if(this.Id != other.Id) * return false;*/ return(true); }
/// <summary> /// Gets all present and mounted FileSystems as a flat List /// </summary> /// <returns> /// The filesystems. /// </returns> /// <param name='element'> /// Element. /// </param> //private List<IDiskElement> current = null; // not thread safe... /*public IEnumerable<FileSystem> GetAllFileSystems(List<IDiskElement> current){ * //if(current == null) current = this.Entries; * foreach(IDiskElement element in current){ * Console.WriteLine (" #GetAllFileSystems : scanning "+element.ToString()); * if(element is FileSystem){ * Console.WriteLine ("GetAllFileSystems : got fs "+element.Path); * yield return((FileSystem)element); * } * else{ * if(element.Children == null) { * Console.WriteLine (" #No child "); * Console.WriteLine (" #No child ("+element.Children.Count+")"); * continue; * } * //current = element.Children; * GetAllFileSystems(element.Children); * } * * } * //Logger.Append(Severity.DEBUG2, "Found "+filesystems.Count+" mounted filesystems."); * * }*/ /*public List<FileSystem> GetAllFileSystems(){ * List<FileSystem> fsl = new List<FileSystem>(); * foreach(IDiskElement de in this.Entries) * foreach(var elt in this.GetChildrenFlat()) * if(elt is FileSystem) * fsl.Add((FileSystem)elt); * return fsl; * }*/ /*public List<FileSystem> GetAllFileSystems(){ * >>>>>>> .r813 * List<FileSystem> fsl = new List<FileSystem>(); * foreach(IDiskElement de in this.Entries){ * Console.WriteLine (" ->"+de.ToString()); * if(de is FileSystem) fsl.Add((FileSystem)de); * foreach(var elt in de.Children){ * Console.WriteLine (" ------>"+elt.ToString()); * if(elt.GetType() == typeof(FileSystem)){ fsl.Add((FileSystem)elt);} * foreach(var elt2 in elt.Children){ * Console.WriteLine (" ---------->"+elt2.ToString()); * if(elt2 is FileSystem) fsl.Add((FileSystem)elt2); * } * } * } * return fsl; * }*/ public List <FileSystem> GetAllFileSystems(IDiskElement root) { List <FileSystem> fsl = new List <FileSystem>(); /*List<IDiskElement> */ System.Collections.ObjectModel.ReadOnlyCollection <IDiskElement> rootElts = null; if (root == null) { rootElts = this.Entries.AsReadOnly(); } else { rootElts = root.Children; if (root is FileSystem) { fsl.Add((FileSystem)root); } } foreach (IDiskElement de in rootElts) { Console.WriteLine(" ->" + de.ToString()); fsl.AddRange(GetAllFileSystems(de)); } return(fsl); }
private List <FileSystem> GetFileSystems(IDiskElement element) { return(default(List <FileSystem>)); }
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); }
public void AddChild(IDiskElement elt) { this.children.Add(elt); elt.Parents.Add(this); }