private void resumeOperationMenuItem_Click(object sender, EventArgs e)
        {
            DynamicVolume     volume = (DynamicVolume)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Key;
            DynamicDiskExtent extent = (DynamicDiskExtent)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Value;

            List <DynamicDisk> dynamicDisks = GetDynamicDisks();
            List <DynamicDisk> diskGroup    = DynamicDiskHelper.FindDiskGroup(dynamicDisks, volume.DiskGroupGuid);

            ResumeForm   resumeForm = new ResumeForm(diskGroup, volume, extent);
            DialogResult result     = resumeForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                UpdateView();
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    MessageBox.Show("Click OK to Continue", "Operation completed successfully");
                }
                else
                {
                    string message = OperatingSystemHelper.GetUpdateMessage();
                    MessageBox.Show(message, "Operation completed successfully");
                }
            }
        }
Example #2
0
        private void listDisks_SelectedIndexChanged(object sender, EventArgs e)
        {
            DynamicDisk   dynamicDisk        = (DynamicDisk)listDisks.SelectedValue;
            PrivateHeader privateHeader      = dynamicDisk.PrivateHeader;
            long          publicRegionEndLBA = (long)(privateHeader.PublicRegionStartLBA + privateHeader.PublicRegionSizeLBA);

            numericDiskOffset.Minimum = (long)privateHeader.PublicRegionStartLBA * dynamicDisk.BytesPerSector;
            numericDiskOffset.Maximum = publicRegionEndLBA * dynamicDisk.BytesPerSector - m_extent.Size;
            if (dynamicDisk.Disk != m_extent.Disk)
            {
                DiskExtent allocation = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, m_extent.Size);
                numericDiskOffset.Enabled = (allocation != null);
                btnOK.Enabled             = (allocation != null);
                if (allocation != null)
                {
                    numericDiskOffset.Value    = allocation.FirstSector * allocation.BytesPerSector;
                    m_previousSuffixIndex      = 0;
                    listSuffixes.SelectedIndex = 0;
                    CompactNumericOffset();
                }
            }
            else
            {
                numericDiskOffset.Enabled  = true;
                btnOK.Enabled              = true;
                numericDiskOffset.Value    = m_extent.FirstSector * m_extent.Disk.BytesPerSector;
                m_previousSuffixIndex      = 0;
                listSuffixes.SelectedIndex = 0;
                CompactNumericOffset();
            }
        }
        private void extendFileSystemMenuItem_Click(object sender, EventArgs e)
        {
            Volume volume = ((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Key;

            List <DynamicDisk> diskGroup = null;

            if (volume is DynamicVolume)
            {
                List <DynamicDisk> dynamicDisks = GetDynamicDisks();
                diskGroup = DynamicDiskHelper.FindDiskGroup(dynamicDisks, ((DynamicVolume)volume).DiskGroupGuid);
            }

            ExtendFileSystemForm extendFileSystem = new ExtendFileSystemForm(diskGroup, volume);
            DialogResult         result           = extendFileSystem.ShowDialog();

            if (result == DialogResult.OK)
            {
                UpdateView();
                if (Environment.OSVersion.Version.Major >= 6 && volume is DynamicVolume)
                {
                    //MessageBox.Show("Please go to Disk Management and reactivate the disk group", "Operation completed successfully");
                    MessageBox.Show("Click OK to Continue", "Operation completed successfully");
                }
            }
        }
        private void addDiskToVolumeMenuItem_Click(object sender, EventArgs e)
        {
            DynamicVolume     volume = (DynamicVolume)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Key;
            DynamicDiskExtent extent = (DynamicDiskExtent)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Value;

            List <DynamicDisk> dynamicDisks = GetDynamicDisks();
            List <DynamicDisk> diskGroup    = DynamicDiskHelper.FindDiskGroup(dynamicDisks, volume.DiskGroupGuid);

            AddDiskForm  addDisk = new AddDiskForm(diskGroup, volume);
            DialogResult result  = addDisk.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    // Windows 7 / 2008 will likely make changes to the disk group, it will be marked as 'dirty' if we don't wait
                    Thread.Sleep(Windows6WaitTimeBeforeRefresh);
                }
                UpdateView();
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    //MessageBox.Show("Please go to Disk Management and reactivate the disk group", "Operation completed successfully");
                    MessageBox.Show("The volume has been extended successfully.\nyou can now proceed to extend the underlying file system.", "Operation completed successfully");
                }
                else
                {
                    string message = "The volume has been extended successfully.\nyou can now proceed to extend the underlying file system.";
                    message += "\n\n" + OperatingSystemHelper.GetUpdateMessage();
                    MessageBox.Show(message, "Operation completed successfully");
                }
            }
        }
        private void moveExtentMenuItem_Click(object sender, EventArgs e)
        {
            DynamicVolume     volume = (DynamicVolume)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Key;
            DynamicDiskExtent extent = (DynamicDiskExtent)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Value;

            List <DynamicDisk> dynamicDisks = GetDynamicDisks();
            List <DynamicDisk> diskGroup    = DynamicDiskHelper.FindDiskGroup(dynamicDisks, volume.DiskGroupGuid);

            bool isBootVolume;

            if (RetainHelper.IsVolumeRetained(volume, out isBootVolume))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("You're trying to move a retained volume (volume that has a partition");
                builder.AppendLine("associated with it).");
                builder.AppendLine("If an operating system is present on this volume, a reconfiguration");
                builder.AppendLine("might be necessary before you could boot it successfully.");
                builder.AppendLine("This operation is currently not supported.");
                MessageBox.Show(builder.ToString(), "Warning");
                return;
            }

            if (DynamicDiskPartitionerResumeRecord.HasValidSignature(volume.ReadSector(0)))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("There is already an operation in progress");
                builder.AppendLine("Use the RESUME command to resume the operation");
                MessageBox.Show(builder.ToString(), "Error");
                return;
            }

            MoveExtentForm moveExtent = new MoveExtentForm(diskGroup, volume, extent);
            DialogResult   result     = moveExtent.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    // Windows 7 / 2008 will likely make changes to the disk group, it will be marked as 'dirty' if we don't wait
                    Thread.Sleep(Windows6WaitTimeBeforeRefresh);
                }
                UpdateView();
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    //MessageBox.Show("Please go to Disk Management and reactivate the disk group", "Operation completed successfully");
                    MessageBox.Show("Click OK to Continue", "Operation completed successfully");
                }
                else
                {
                    string message = OperatingSystemHelper.GetUpdateMessage();
                    MessageBox.Show(message, "Operation completed successfully");
                }
            }
        }
        private void createVolumeMenuItem_Click(object sender, EventArgs e)
        {
            DiskExtent extent = (DiskExtent)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Value;

            List <DynamicDisk> dynamicDisks = GetDynamicDisks();
            DynamicDisk        disk         = DynamicDisk.ReadFromDisk(extent.Disk);
            List <DynamicDisk> diskGroup    = DynamicDiskHelper.FindDiskGroup(dynamicDisks, disk.DiskGroupGuid);

            CreateVolumeForm createVolume = new CreateVolumeForm(diskGroup, extent);
            DialogResult     result       = createVolume.ShowDialog();

            if (result == DialogResult.OK)
            {
                UpdateView();
            }
        }
Example #7
0
        public static List <DiskExtent> GetUnallocatedExtents(List <Disk> disks)
        {
            List <DiskExtent> extents = new List <DiskExtent>();

            foreach (Disk disk in disks)
            {
                if (DynamicDisk.IsDynamicDisk(disk))
                {
                    DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk);
                    extents.AddRange(DynamicDiskHelper.GetUnallocatedExtents(dynamicDisk));
                }
                else
                {
                    extents.AddRange(BasicDiskHelper.GetUnallocatedExtents(disk));
                }
            }
            return(extents);
        }
Example #8
0
 private void UpdateExtentSize()
 {
     if (listDisks.CheckedIndices.Count > 0)
     {
         long minExtentSize = Int64.MaxValue;
         foreach (int checkedIndex in listDisks.CheckedIndices)
         {
             long extentSize = DynamicDiskHelper.GetMaxNewExtentLength(m_diskGroup[checkedIndex]);
             if (extentSize < minExtentSize)
             {
                 minExtentSize = extentSize;
             }
         }
         long minExtentSizeInMB = minExtentSize / 1024 / 1024;
         numericExtentSize.Maximum = minExtentSizeInMB;
         numericExtentSize.Value   = minExtentSizeInMB;
         btnOK.Enabled             = (minExtentSizeInMB > 0);
     }
     else
     {
         btnOK.Enabled = false;
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            DynamicDisk targetDynamicDisk = (DynamicDisk)listDisks.SelectedValue;
            Raid5Volume raid5Volume       = (Raid5Volume)m_volume;
            DiskExtent  newExtent         = DynamicDiskHelper.FindExtentAllocation(targetDynamicDisk, raid5Volume.ColumnSize);

            if (newExtent == null)
            {
                MessageBox.Show("The disk specified does not contain enough free space.", "Error");
                return;
            }

            List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(raid5Volume.DiskGroupGuid);
            DiskGroupDatabase  database  = DiskGroupDatabase.ReadFromDisks(diskGroup, raid5Volume.DiskGroupGuid);

            if (database.AreDisksMissing)
            {
                DialogResult disksMissingResult = MessageBox.Show("Some of the disks in this disk group are missing, Continue anyway?", "Warning", MessageBoxButtons.YesNo);
                if (disksMissingResult != DialogResult.Yes)
                {
                    return;
                }
            }

            DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup);

            if (result == DiskGroupLockResult.CannotLockDisk)
            {
                MessageBox.Show("Unable to lock all disks!", "Error");
            }
            else if (result == DiskGroupLockResult.CannotLockVolume)
            {
                MessageBox.Show("Unable to lock all volumes!", "Error");
            }
            else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly)
            {
                MessageBox.Show("One or more disks are offline or set to readonly.", "Error");
            }
            else if (result == DiskGroupLockResult.CannotTakeDiskOffline)
            {
                MessageBox.Show("Failed to take all dynamic disks offline!", "Error");
            }
            else if (result == DiskGroupLockResult.Success)
            {
                listDisks.Enabled   = false;
                btnCancel.Enabled   = false;
                btnOK.Enabled       = false;
                progressBar.Visible = true;

                long   bytesTotal   = raid5Volume.Size;
                long   bytesCopied  = 0;
                Thread workerThread = new Thread(delegate()
                {
                    m_isWorking = true;
                    AddDiskToArrayHelper.AddDiskToRaid5Volume(database, raid5Volume, newExtent, ref bytesCopied);
                    m_isWorking = false;
                });
                workerThread.Start();

                new Thread(delegate()
                {
                    while (workerThread.IsAlive)
                    {
                        Thread.Sleep(250);
                        int progress = (int)(100 * (double)bytesCopied / bytesTotal);
                        this.Invoke((MethodInvoker) delegate()
                        {
                            progressBar.Value = progress;
                        });
                    }

                    this.Invoke((MethodInvoker) delegate()
                    {
                        DiskGroupHelper.UnlockDiskGroup(m_diskGroup);
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    });
                }).Start();
            }
        }
Example #10
0
        public static List <DynamicDisk> GetPhysicalDynamicDisks(Guid diskGroupGuid)
        {
            List <DynamicDisk> dynamicDisks = GetPhysicalDynamicDisks();

            return(DynamicDiskHelper.FindDiskGroup(dynamicDisks, diskGroupGuid));
        }
Example #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            DynamicDisk targetDisk = (DynamicDisk)listDisks.SelectedValue;
            long        offset     = GetDiskOffset();
            bool        isSameDisk = (targetDisk.Disk == m_extent.Disk);

            if (!DynamicDiskHelper.IsMoveLocationValid(m_extent, targetDisk, offset))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("Invalid offset specified.");
                builder.AppendLine();
                builder.AppendLine("The following conditions must be met:");
                builder.AppendLine("1. The destination must reside inside the data portion of the disk.");
                builder.AppendLine("2. The destination must not be used by any other extents.");
                builder.AppendLine("3. The offset must be aligned to sector size.");
                builder.AppendLine("4. Source and destination disk must have the same sector size.");
                MessageBox.Show(builder.ToString(), "Error");
                return;
            }

            if (isSameDisk && offset == m_extent.FirstSector * m_extent.BytesPerSector)
            {
                MessageBox.Show("Source and destination are the same.", "Error");
                return;
            }

            DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup, targetDisk.DiskGroupGuid);

            if (database.AreDisksMissing)
            {
                DialogResult disksMissingResult = MessageBox.Show("Some of the disks in this disk group are missing, Continue anyway?", "Warning", MessageBoxButtons.YesNo);
                if (disksMissingResult != DialogResult.Yes)
                {
                    return;
                }
            }

            DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup);

            if (result == DiskGroupLockResult.CannotLockDisk)
            {
                MessageBox.Show("Unable to lock all disks!", "Error");
            }
            else if (result == DiskGroupLockResult.CannotLockVolume)
            {
                MessageBox.Show("Unable to lock all volumes!", "Error");
            }
            else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly)
            {
                MessageBox.Show("One or more disks are offline or set to readonly.", "Error");
            }
            else if (result == DiskGroupLockResult.CannotTakeDiskOffline)
            {
                MessageBox.Show("Failed to take all dynamic disks offline!", "Error");
            }
            else if (result == DiskGroupLockResult.Success)
            {
                listDisks.Enabled         = false;
                numericDiskOffset.Enabled = false;
                listSuffixes.Enabled      = false;
                btnCancel.Enabled         = false;
                btnOK.Enabled             = false;
                progressBar.Visible       = true;

                long       firstSector  = offset / targetDisk.BytesPerSector;
                DiskExtent targetExtent = new DiskExtent(targetDisk.Disk, firstSector, m_extent.Size);
                long       bytesTotal   = m_extent.Size;
                long       bytesCopied  = 0;
                Thread     workerThread = new Thread(delegate()
                {
                    m_isWorking = true;
                    if (isSameDisk)
                    {
                        MoveExtentHelper.MoveExtentWithinSameDisk(database, m_volume, m_extent, targetExtent, ref bytesCopied);
                    }
                    else
                    {
                        MoveExtentHelper.MoveExtentToAnotherDisk(database, m_volume, m_extent, targetExtent, ref bytesCopied);
                    }
                    m_isWorking = false;
                });
                workerThread.Start();

                new Thread(delegate()
                {
                    while (workerThread.IsAlive)
                    {
                        Thread.Sleep(250);
                        int progress = (int)(100 * (double)bytesCopied / bytesTotal);
                        this.Invoke((MethodInvoker) delegate()
                        {
                            progressBar.Value = progress;
                        });
                    }

                    this.Invoke((MethodInvoker) delegate()
                    {
                        DiskGroupHelper.UnlockDiskGroup(m_diskGroup);
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    });
                }).Start();
            }
        }
Example #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int diskCount = listDisks.CheckedIndices.Count;

            if (rbSimple.Checked && diskCount != 1)
            {
                MessageBox.Show("You must select a single disk in order to create a simple volume.", "Error");
                return;
            }

            if (rbRaid5.Checked)
            {
                if (chkDegraded.Checked && diskCount < 2)
                {
                    MessageBox.Show("You must select at least 2 disks in order to create a degraded RAID-5 volume.", "Error");
                    return;
                }

                if (!chkDegraded.Checked && diskCount < 3)
                {
                    MessageBox.Show("You must select at least 3 disks in order to create a RAID-5 volume.", "Error");
                    return;
                }
            }

            long extentSizeInBytes    = (long)numericExtentSize.Value * 1024 * 1024;
            List <DiskExtent> extents = new List <DiskExtent>();

            foreach (int checkedIndex in listDisks.CheckedIndices)
            {
                DynamicDisk dynamicDisk = m_diskGroup[checkedIndex];
                DiskExtent  extent      = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, extentSizeInBytes);
                if (extent == null)
                {
                    MessageBox.Show("One of the disks does not contain enough free space", "Error");
                    return;
                }
                extents.Add(extent);
            }

            DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup);

            if (result == DiskGroupLockResult.CannotLockDisk)
            {
                MessageBox.Show("Unable to lock all disks!", "Error");
            }
            else if (result == DiskGroupLockResult.CannotLockVolume)
            {
                MessageBox.Show("Unable to lock all volumes!", "Error");
            }
            else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly)
            {
                MessageBox.Show("One or more disks are offline or set to readonly.", "Error");
            }
            else if (result == DiskGroupLockResult.CannotTakeDiskOffline)
            {
                MessageBox.Show("Failed to take all dynamic disks offline!", "Error");
            }
            else if (result == DiskGroupLockResult.Success)
            {
                DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup)[0];
                if (rbSimple.Checked)
                {
                    VolumeManagerDatabaseHelper.CreateSimpleVolume(database, extents[0]);
                }
                else
                {
                    VolumeManagerDatabaseHelper.CreateRAID5Volume(database, extents, chkDegraded.Checked);
                }

                DiskGroupHelper.UnlockDiskGroup(m_diskGroup);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }