Esempio n. 1
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;
        }