Ejemplo n.º 1
0
 /// <summary>
 /// Expands the size of a layer to at least [size] bytes.
 /// </summary>
 /// <param name="path">The path to the layer.</param>
 /// <param name="size">The size to expand the layer to in bytes. The layer will be expanded if size is larger than the current size of the layer.</param>
 public static void ExpandSandboxSize(string path, UInt64 size)
 {
     using (var info = new DriverInfoHelper())
     {
         StorageFunctions.ExpandSandboxSize(ref info.Data, Path.GetFullPath(path), size);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Exports the contents a layer or sandbox to the specified directory. Only the files and
        /// registry keys that were changed are exported.
        /// </summary>
        /// <param name="path">The path to the layer or sandbox.</param>
        /// <param name="exportPath">The path of the exported files. This directory will be created and must not already exist.</param>
        /// <param name="layers">A list of parent layers.</param>
        public static void ExportLayer(string path, string exportPath, IList <Layer> layers)
        {
            path = Path.GetFullPath(path);
            if (Directory.Exists(exportPath))
            {
                throw new IOException(string.Format("Directory {0} already exists.", exportPath));
            }

            Directory.CreateDirectory(exportPath);
            try
            {
                using (var info = new DriverInfoHelper())
                    using (var descriptors = new LayerHelper(layers))
                    {
                        StorageFunctions.ActivateLayer(ref info.Data, path);
                        try
                        {
                            StorageFunctions.ExportLayer(ref info.Data, path, exportPath, descriptors.Data, descriptors.Data.Length);
                        }
                        finally
                        {
                            StorageFunctions.DeactivateLayer(ref info.Data, path);
                        }
                    }
            }
            catch (Exception)
            {
                Directory.Delete(exportPath, true);
                throw;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Destroys a layer or sandbox.
 /// </summary>
 /// <param name="path">The path to the layer or sandbox.</param>
 public static void DestroyLayer(string path)
 {
     using (var info = new DriverInfoHelper())
     {
         StorageFunctions.DestroyLayer(ref info.Data, Path.GetFullPath(path));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Dismounts a sandbox that was mounted but never dismounted.
 /// </summary>
 /// <param name="path">The path to the sandbox.</param>
 public static void DismountSandbox(string path)
 {
     using (var info = new DriverInfoHelper())
     {
         StorageFunctions.DeactivateLayer(ref info.Data, path);
     }
 }
Ejemplo n.º 5
0
 public void Dispose()
 {
     using (var info = new DriverInfoHelper())
     {
         StorageFunctions.DeactivateLayer(ref info.Data, _path);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new layer from the exported contents of another layer.
 /// </summary>
 /// <param name="path">The path of the new layer.</param>
 /// <param name="importPath">The path of the exported files.</param>
 /// <param name="layers">A list of parent layers.</param>
 public static void ImportLayer(string path, string importPath, IList <Layer> layers)
 {
     using (var info = new DriverInfoHelper())
         using (var descriptors = new LayerHelper(layers))
         {
             StorageFunctions.ImportLayer(ref info.Data, Path.GetFullPath(path), importPath, descriptors.Data, descriptors.Data.Length);
         }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new storage sandbox at the given directory path.
 /// </summary>
 /// <param name="path">A path to the new sandbox.</param>
 /// <param name="layers">A list of parent layers.</param>
 public static void CreateSandbox(string path, IList <Layer> layers)
 {
     using (var info = new DriverInfoHelper())
         using (var descriptors = new LayerHelper(layers))
         {
             StorageFunctions.CreateSandboxLayer(ref info.Data, Path.GetFullPath(path), null, descriptors.Data, descriptors.Data.Length);
         }
 }
Ejemplo n.º 8
0
            internal MountedSandbox(string path, IList <Layer> layers)
            {
                using (var info = new DriverInfoHelper())
                    using (var descriptors = new LayerHelper(layers))
                    {
                        StorageFunctions.ActivateLayer(ref info.Data, path);
                        try
                        {
                            StorageFunctions.PrepareLayer(ref info.Data, path, descriptors.Data, descriptors.Data.Length);
                            var mountPath = new StringBuilder(260);
                            var length    = new UIntPtr((uint)mountPath.Capacity);
                            StorageFunctions.GetLayerMountPath(ref info.Data, path, ref length, mountPath);
                            _mountPath = mountPath.ToString();
                        }
                        catch (Exception)
                        {
                            StorageFunctions.DeactivateLayer(ref info.Data, path);
                            throw;
                        }
                    }

                _path = path;
            }
Ejemplo n.º 9
0
 /// <summary>
 /// Post-processes an extracted utility VM image, preparing it for use. The contents of the image are expected
 /// to be at [path]\Files.
 /// </summary>
 /// <param name="path">The path to the utility VM image.</param>
 public static void ProcessUtilityVMImage(string path)
 {
     StorageFunctions.ProcessUtilityImage(Path.GetFullPath(path));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Post-processes an extracted base layer, preparing it for use. The contents of the layer are expected
 /// to be at [path]\Files.
 /// </summary>
 /// <param name="path">The path to the base layer.</param>
 public static void ProcessBaseLayer(string path)
 {
     StorageFunctions.ProcessBaseImage(Path.GetFullPath(path));
 }