Пример #1
0
        private HardDiskExtent ParseExtentDescriptor(string line)
        {
            if (!line.StartsWith ("RW") && !line.StartsWith ("RDONLY") && !line.StartsWith ("NOACCESS"))
                return null;

            string[] splitLine = line.Split (new char[] { ' ' }, 5);
            if (splitLine.Length < 4) {
                return null;
            }

            ExtentAccess access;
            long extentCapacity;
            ExtentType extentType;
            string extentFile;

            try {
                access = Utility.ParseExtentAccess (splitLine[0]);
            } catch {
                return null;
            }

            try {
                extentCapacity = Int64.Parse (splitLine[1]);
            } catch {
                return null;
            }

            try {
                extentType = Utility.ParseExtentType (splitLine[2]);
            } catch {
                return null;
            }

            extentFile = Path.Combine (Path.GetDirectoryName (file), Utility.StripDoubleQuotes (splitLine[3]));

            HardDiskExtent extent = new HardDiskExtent (access, extentCapacity, extentType, extentFile);

            try {
                extent.Offset = Int64.Parse (splitLine[4]);
            } catch {
            }

            return extent;
        }
Пример #2
0
        public void Create(ProgressHandler handler)
        {
            if (type == HardDiskType.SplitFlat ||
                type == HardDiskType.SingleFlat) {
                CheckDiskSpace ();
            }

            extents.Clear ();

            CalculateGeometry ();

            string extentFormatString = Path.Combine (Path.GetDirectoryName (file),
                                                      Path.GetFileNameWithoutExtension (file) + "-{0}.vmdk");

            if (type == HardDiskType.SplitFlat ||
                type == HardDiskType.SplitSparse) {

                long extentRemainder = 0;
                int numMaxExtents = (int) Math.DivRem (GetCapacityInSectors (), SectorsIn2Gb, out extentRemainder);

                for (int i = 0; i < numMaxExtents; i++) {
                    HardDiskExtent extent = new HardDiskExtent (ExtentAccess.ReadWrite, SectorsIn2Gb,
                                                                type == HardDiskType.SplitFlat ? ExtentType.Flat : ExtentType.Sparse,
                                                                String.Format (extentFormatString, i));
                    extents.Add (extent);
                }

                if (extentRemainder > 0) {
                    extents.Add (new HardDiskExtent (ExtentAccess.ReadWrite, extentRemainder,
                                                     type == HardDiskType.SplitFlat ? ExtentType.Flat : ExtentType.Sparse,
                                                     String.Format (extentFormatString, numMaxExtents)));
                }
            } else {
                extents.Add (new HardDiskExtent (ExtentAccess.ReadWrite, GetCapacityInSectors (),
                                                 type == HardDiskType.SingleFlat ? ExtentType.Flat : ExtentType.Sparse,
                                                 String.Format (extentFormatString, 0)));
            }

            WriteDescriptor ();
            for (int i = 0; i < extents.Count; i++) {
                HardDiskExtent extent = extents[i];
                if (handler == null) {
                    extent.Create ();
                } else {
                    extent.Create (delegate (object o, ProgressArgs args) {
                        double progress = (double) i / (double) extents.Count;
                        progress += args.Progress * ((double) 1 / (double) extents.Count);
                        handler (this, new ProgressArgs (progress));
                    });
                }
            }
        }