/// <summary></summary> /// <param name="directoryOrFile">Either the path to a virutal hard disk image file or a directory containing multiple images.</param> public Zfs(string directoryOrFile) { //make sure we correctly set the size of structs assertStructSize <zio_gbh_phys_t>(zio_gbh_phys_t.SPA_GANGBLOCKSIZE); mHdds = LeafVdevInfo.GetLeafVdevs(directoryOrFile); try { Load(); } catch { foreach (var hdd in mHdds) { hdd.Dispose(); } throw; } }
public static List <LeafVdevInfo> GetLeafVdevs(string dirOrFile) { var ret = new List <LeafVdevInfo>(); try { FileInfo[] files; if (File.Exists(dirOrFile)) { files = new FileInfo[] { new FileInfo(dirOrFile) }; } else { files = new DirectoryInfo(dirOrFile).GetFiles(); } foreach (var fi in files) { Func <FileHardDisk, HardDisk> factory; if (!sFileFormats.TryGetValue(fi.Extension, out factory)) { continue; } var file = new FileHardDisk(fi.FullName); var partition = factory(file); var vdev = new LeafVdevInfo(partition); ret.Add(vdev); } } catch { foreach (var leaf in ret) { leaf.Dispose(); } throw; } return(ret); }