Ejemplo n.º 1
0
        public void Dispose()
        {
            MemoryStream     ms          = CreateSequencedMemStream(100, false);
            BlockCacheStream cacheStream = new BlockCacheStream(SparseStream.FromStream(ms, Ownership.Dispose), Ownership.Dispose);

            cacheStream.Dispose();

            try
            {
                cacheStream.Position = 0;
                cacheStream.ReadByte();
                Assert.True(false, "Cache stream should have failed - disposed");
            }
            catch (ObjectDisposedException)
            {
            }

            try
            {
                ms.Position = 0;
                ms.ReadByte();
                Assert.True(false, "Cache stream should have failed - disposed");
            }
            catch (ObjectDisposedException)
            {
            }
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (_bitmap != null)
     {
         _bitmap.Dispose();
         _bitmap = null;
     }
 }
Ejemplo n.º 3
0
        public BitArray GetClusterUsage()
        {
            if (vhd.masterBootRecord.partition[Partition].PartitionType != 7)
            {
                return(null);
            }

            try
            {
                DiscUtils.VolumeManager volMgr = new VolumeManager();
                using (VirtualDisk virtualDisk = VirtualDisk.OpenDisk(vhd.footer.FileName, FileAccess.Read))
                {
                    volMgr.AddDisk(virtualDisk);

                    using (Stream partitionStream = volMgr.GetPhysicalVolumes()[Partition].Open())
                    {
                        //if (!string.IsNullOrEmpty(VolumeId))
                        //{
                        //    partitionStream = volMgr.GetVolume(VolumeId).Open();
                        //}
                        //else if (Partition >= 0)
                        //{
                        //    partitionStream = volMgr.GetPhysicalVolumes()[Partition].Open();
                        //}
                        //else
                        //{
                        //    partitionStream = volMgr.GetLogicalVolumes()[0].Open();
                        //}

                        SparseStream cacheStream = SparseStream.FromStream(partitionStream, Ownership.None);
                        cacheStream = new BlockCacheStream(cacheStream, Ownership.None);
                        try
                        {
                            fs = new NtfsFileSystem(cacheStream);
                        }
                        catch
                        {
                            cacheStream.Dispose();
                            return(null);
                        }


                        fs.NtfsOptions.HideHiddenFiles = false;
                        fs.NtfsOptions.HideSystemFiles = false;
                        fs.NtfsOptions.HideMetafiles   = false;

                        BitArray ba = fs.BuildClusterBitArray();

                        fs.Dispose();
                        cacheStream.Dispose();
                        partitionStream.Dispose();


                        ClusterBitArray = ba;
                    }
                }
            }
            catch (VhdReadException ex)
            {
                this.vhd.vhdReadException = ex;
                return(null);
            }

            return(ClusterBitArray);

            /*
             * ClusterMap clusterMap = null;
             * try
             * {
             *  clusterMap = fs.BuildClusterMap();
             * }
             * catch (IOException ex)
             * {
             *  // TODO: Need to some error notfication
             *  // MessageBox.Show(ex.Message, "Exception");
             *  return null;
             * }
             *
             *
             * BitArray ba = new BitArray((int)fs.TotalClusters);
             */

            //UsedClusters = 0;
            //FreeClusters = 0;
            //TotalClusters = fs.TotalClusters;

            //for (int i = 0; i < TotalClusters; i++)
            //{
            //    if (clusterMap.ClusterToPaths(i).Length > 0)
            //    {
            //        UsedClusters++;
            //        ba.Set(i, true);
            //    }
            //    else
            //    {
            //        FreeClusters++;
            //    }
            //}

            /*
             * ClusterForm cf = new ClusterForm();
             * cf.Icon = Icon;
             * cf.Text = Text + " - Cluster Map";
             * cf.clusterBitmaps1.Clusters = ba;
             * cf.Show();
             */
            //cf.clusterBitmaps1.GradientStart = Color.WhiteSmoke;
            //cf.clusterBitmaps1.GradientEnd = Color.Black;
            //cf.clusterBitmaps1.GradientSteps = 8;
        }