Ejemplo 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");
            }
        }
Ejemplo 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");
            }
        }
Ejemplo n.º 3
0
 public Extent(Nucleus nucleus, ExtentType type)
 {
     Nucleus    = nucleus;
     Type       = type;
     _hashcode  = 23;
     _hashcode *= 17 + Nucleus.GetHashCode();
 }
Ejemplo 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;
 }
Ejemplo n.º 5
0
 public ExtentDescriptor(ExtentAccess access, long size, ExtentType type, string fileName, long offset)
 {
     _access = access;
     _sizeInSectors = size;
     _type = type;
     _fileName = fileName;
     _offset = offset;
 }
Ejemplo 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;
 }
Ejemplo 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);
        }
Ejemplo 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;
        }
Ejemplo 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");
            }
        }
Ejemplo n.º 10
0
 private static void CreateExtent(Stream extentStream, long size, ExtentType type)
 {
     long descriptorStart;
     CreateExtent(extentStream, size, type, 0, out descriptorStart);
 }
Ejemplo n.º 11
0
        private static void CreateExtent(Stream extentStream, long size, ExtentType type)
        {
            long descriptorStart;

            CreateExtent(extentStream, size, type, 0, out descriptorStart);
        }
Ejemplo 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));
        }
Ejemplo 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");
     }
 }
Ejemplo n.º 14
0
			public nameEnumerator(ExtentType par) 
			{
                this.SetSamplerState(0, SamplerStateparent = par;
                this.SetSamplerState(0, SamplerStatenIndex = -1;
			}
Ejemplo n.º 15
0
 public static string ExtentTypeToString(ExtentType type)
 {
     switch (type) {
     case ExtentType.Flat:
         return "FLAT";
     case ExtentType.Sparse:
         return "SPARSE";
     default:
         return null;
     }
 }