Esempio n. 1
0
        public static string FormatExtentType(ExtentType type)
        {
            switch (type)
            {
            case ExtentType.Flat:
                return("FLAT");

            case ExtentType.Sparse:
                return("SPARSE");

            case ExtentType.Zero:
                return("ZERO");

            case ExtentType.Vmfs:
                return("VMFS");

            case ExtentType.VmfsSparse:
                return("VMFSSPARSE");

            case ExtentType.VmfsRdm:
                return("VMFSRDM");

            case ExtentType.VmfsRaw:
                return("VMFSRAW");

            default:
                throw new ArgumentException("Unknown extent type", "type");
            }
        }
Esempio n. 2
0
        private static void CreateExtent(Stream extentStream, long size, ExtentType type, long descriptorLength, out long descriptorStart)
        {
            if (type == ExtentType.Flat || type == ExtentType.Vmfs)
            {
                extentStream.SetLength(size);
                descriptorStart = 0;
                return;
            }

            if (type == ExtentType.Sparse)
            {
                CreateSparseExtent(extentStream, size, descriptorLength, out descriptorStart);
                return;
            }
            else if (type == ExtentType.VmfsSparse)
            {
                ServerSparseExtentHeader header = CreateServerSparseExtentHeader(size);

                extentStream.Position = 0;
                extentStream.Write(header.GetBytes(), 0, 4 * Sizes.Sector);

                byte[] blankGlobalDirectory = new byte[header.NumGdEntries * 4];
                extentStream.Write(blankGlobalDirectory, 0, blankGlobalDirectory.Length);

                descriptorStart = 0;
                return;
            }
            else
            {
                throw new NotImplementedException("Extent type not implemented");
            }
        }
Esempio n. 3
0
 public Extent(Nucleus nucleus, ExtentType type)
 {
     Nucleus    = nucleus;
     Type       = type;
     _hashcode  = 23;
     _hashcode *= 17 + Nucleus.GetHashCode();
 }
Esempio n. 4
0
 public ExtentDescriptor(ExtentAccess access, long size, ExtentType type, string fileName, long offset)
 {
     _access        = access;
     _sizeInSectors = size;
     _type          = type;
     _fileName      = fileName;
     _offset        = offset;
 }
 public ExtentDescriptor(ExtentAccess access, long size, ExtentType type, string fileName, long offset)
 {
     _access = access;
     _sizeInSectors = size;
     _type = type;
     _fileName = fileName;
     _offset = offset;
 }
Esempio n. 6
0
 public HardDiskExtent(ExtentAccess access, long capacity, ExtentType type, string file)
 {
     this.ExtentAccess = access;
     this.Capacity = capacity;
     this.ExtentType = type;
     this.FileName = file;
     this.Offset = 0;
 }
Esempio n. 7
0
        public static ExtentType[] ToMetadata(ExtentsULong extents)
        {
            if (extents == null)
            {
                return(null);
            }

            Tuple <ulong, ulong>[] tuples = extents.ToArray();
            ExtentType[]           array  = new ExtentType[tuples.Length];

            for (ulong i = 0; i < (ulong)array.LongLength; i++)
            {
                array[i] = new ExtentType {
                    Start = tuples[i].Item1, End = tuples[i].Item2
                }
            }
            ;

            return(array);
        }
Esempio n. 8
0
        protected Layer(string name, string layers, IBBox bbox,
                        string srs, string description, double?maxResolution,
                        Size size, int levels, Resolutions resolutions,
                        string extension, string mimeType, ICache cache,
                        string watermarkImage, float?watermarkOpacity,
                        ExtentType extentType, object units, string tmsType)
        {
            Name        = name;
            Description = description;
            if (string.IsNullOrEmpty(layers))
            {
                Layers = name;
            }

            BBox        = bbox;
            Size        = size;
            Units       = units;
            Srs         = srs;
            Extension   = extension;
            ContentType = string.IsNullOrEmpty(mimeType) ? Format : mimeType;
            Cache       = cache;
            //Debug = debug;
            ExtentType = extentType;
            TmsType    = tmsType;
            _levels    = levels;
            if (resolutions != null)
            {
                Resolutions = resolutions;
            }
            else
            {
                MaxResolution = maxResolution;
            }
            WatermarkImage   = watermarkImage;
            WatermarkOpacity = watermarkOpacity;
        }
Esempio n. 9
0
        private static void CreateExtent(Stream extentStream, long size, ExtentType type, long descriptorLength, out long descriptorStart)
        {
            if (type == ExtentType.Flat || type == ExtentType.Vmfs)
            {
                extentStream.SetLength(size);
                descriptorStart = 0;
                return;
            }

            if (type == ExtentType.Sparse)
            {
                CreateSparseExtent(extentStream, size, descriptorLength, out descriptorStart);
                return;
            }
            else if(type == ExtentType.VmfsSparse)
            {
                ServerSparseExtentHeader header = CreateServerSparseExtentHeader(size);

                extentStream.Position = 0;
                extentStream.Write(header.GetBytes(), 0, 4 * Sizes.Sector);

                byte[] blankGlobalDirectory = new byte[header.NumGdEntries * 4];
                extentStream.Write(blankGlobalDirectory, 0, blankGlobalDirectory.Length);

                descriptorStart = 0;
                return;
            }
            else
            {
                throw new NotImplementedException("Extent type not implemented");
            }
        }
Esempio n. 10
0
 private static void CreateExtent(Stream extentStream, long size, ExtentType type)
 {
     long descriptorStart;
     CreateExtent(extentStream, size, type, 0, out descriptorStart);
 }
Esempio n. 11
0
        private static void CreateExtent(Stream extentStream, long size, ExtentType type)
        {
            long descriptorStart;

            CreateExtent(extentStream, size, type, 0, out descriptorStart);
        }
Esempio n. 12
0
        private static DiskImageFile DoInitialize(FileLocator fileLocator, string file, long capacity, DiskCreateType type, DescriptorFile baseDescriptor)
        {
            if (type == DiskCreateType.MonolithicSparse)
            {
                // MonolithicSparse is a special case, the descriptor is embedded in the file itself...
                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    long descriptorStart;
                    CreateExtent(fs, capacity, ExtentType.Sparse, 10 * Sizes.OneKiB, out descriptorStart);

                    ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, ExtentType.Sparse, file, 0);
                    fs.Position = descriptorStart * Sizes.Sector;
                    baseDescriptor.Extents.Add(extent);
                    baseDescriptor.Write(fs);
                }
            }
            else
            {
                ExtentType extentType           = CreateTypeToExtentType(type);
                long       totalSize            = 0;
                List <ExtentDescriptor> extents = new List <ExtentDescriptor>();
                if (type == DiskCreateType.MonolithicFlat || type == DiskCreateType.VmfsSparse || type == DiskCreateType.Vmfs)
                {
                    string adornment = "flat";
                    if (type == DiskCreateType.VmfsSparse)
                    {
                        adornment = string.IsNullOrEmpty(baseDescriptor.ParentFileNameHint) ? "sparse" : "delta";
                    }

                    string fileName = AdornFileName(file, adornment);

                    using (Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        CreateExtent(fs, capacity, extentType);
                        extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, extentType, fileName, 0));
                        totalSize = capacity;
                    }
                }
                else if (type == DiskCreateType.TwoGbMaxExtentFlat || type == DiskCreateType.TwoGbMaxExtentSparse)
                {
                    int i = 1;
                    while (totalSize < capacity)
                    {
                        string adornment;
                        if (type == DiskCreateType.TwoGbMaxExtentSparse)
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "s{0:x3}", i);
                        }
                        else
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "{0:x6}", i);
                        }

                        string fileName = AdornFileName(file, adornment);

                        using (Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                        {
                            long extentSize = Math.Min(2 * Sizes.OneGiB - Sizes.OneMiB, capacity - totalSize);
                            CreateExtent(fs, extentSize, extentType);
                            extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, extentSize / Sizes.Sector, extentType, fileName, 0));
                            totalSize += extentSize;
                        }

                        ++i;
                    }
                }
                else
                {
                    throw new NotSupportedException("Creating disks of this type is not supported");
                }

                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    baseDescriptor.Extents.AddRange(extents);
                    baseDescriptor.Write(fs);
                }
            }

            return(new DiskImageFile(fileLocator, file, FileAccess.ReadWrite));
        }
Esempio n. 13
0
 public static string FormatExtentType(ExtentType type)
 {
     switch (type)
     {
         case ExtentType.Flat:
             return "FLAT";
         case ExtentType.Sparse:
             return "SPARSE";
         case ExtentType.Zero:
             return "ZERO";
         case ExtentType.Vmfs:
             return "VMFS";
         case ExtentType.VmfsSparse:
             return "VMFSSPARSE";
         case ExtentType.VmfsRdm:
             return "VMFSRDM";
         case ExtentType.VmfsRaw:
             return "VMFSRAW";
         default:
             throw new ArgumentException("Unknown extent type", "type");
     }
 }
Esempio n. 14
0
			public nameEnumerator(ExtentType par) 
			{
                this.SetSamplerState(0, SamplerStateparent = par;
                this.SetSamplerState(0, SamplerStatenIndex = -1;
			}
Esempio n. 15
0
 public static string ExtentTypeToString(ExtentType type)
 {
     switch (type) {
     case ExtentType.Flat:
         return "FLAT";
     case ExtentType.Sparse:
         return "SPARSE";
     default:
         return null;
     }
 }