private void btnAddVolume_Click(object sender, EventArgs e)
        {
            SelectVolumeForm selectVolume = new SelectVolumeForm();
            DialogResult     result       = selectVolume.ShowDialog();

            if (result == DialogResult.OK)
            {
                VolumeDisk volumeDisk = new VolumeDisk(selectVolume.SelectedVolume, selectVolume.IsReadOnly);
                AddDisk(volumeDisk);
            }
        }
Exemple #2
0
        private void btnAddVolume_Click(object sender, EventArgs e)
        {
#if Win32
            SelectVolumeForm selectVolume = new SelectVolumeForm();
            DialogResult     result       = selectVolume.ShowDialog();
            if (result == DialogResult.OK)
            {
                VolumeDisk volumeDisk = new VolumeDisk(selectVolume.SelectedVolume);
                if (selectVolume.IsReadOnly)
                {
                    volumeDisk.IsReadOnly = true;
                }
                AddDisk(volumeDisk);
            }
#endif
        }
Exemple #3
0
        public static void AttachCommand(string[] args)
        {
            if (m_server != null)
            {
                Console.WriteLine("Server is already running");
                return;
            }

            if (args.Length >= 2)
            {
                KeyValuePairList <string, string> parameters = ParseParameters(args, 2);
                if (!VerifyParameters(parameters, "vdisk", "disk", "volume", "readonly", "target"))
                {
                    Console.WriteLine();
                    Console.WriteLine("Invalid parameter");
                    HelpAttach();
                    return;
                }

                switch (args[1].ToLower())
                {
                case "vdisk":
                {
                    if (m_selectedDisk == null)
                    {
                        Console.WriteLine("No disk has been selected");
                        break;
                    }

                    if (!(m_selectedDisk is DiskImage))
                    {
                        Console.WriteLine("Selected disk is not a disk image");
                        break;
                    }

                    DiskImage disk = (DiskImage)m_selectedDisk;
                    string    defaultStorageTargetName = Path.GetFileNameWithoutExtension(disk.Path);
                    string    defaultTargetName        = DefaultTargetIQN + ":" + defaultStorageTargetName.Replace(" ", ""); // spaces are not allowed
                    AttachISCSIDisk(disk, defaultTargetName, parameters);
                    break;
                }

                case "disk":
                {
                    if (m_selectedDisk == null)
                    {
                        Console.WriteLine("Error: No disk has been selected.");
                        break;
                    }

                    if (!(m_selectedDisk is PhysicalDisk))
                    {
                        Console.WriteLine("Error: The selected disk is not a physical disk.");
                        break;
                    }

                    bool         isAttachmentReadOnly = parameters.ContainsKey("readonly");
                    PhysicalDisk disk = (PhysicalDisk)m_selectedDisk;
                    if (!isAttachmentReadOnly)
                    {
                        if (Environment.OSVersion.Version.Major >= 6)
                        {
                            bool isDiskReadOnly;
                            bool isOnline = disk.GetOnlineStatus(out isDiskReadOnly);
                            if (isOnline)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Error: The selected disk must be taken offline.");
                                break;
                            }

                            if (!isAttachmentReadOnly && isDiskReadOnly)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Error: The selected disk is set to readonly!");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine();
                            // Locking mechanism is not implemented
                            Console.Write("Warning: if a volume on this disk is mounted locally, data corruption may occur!");
                        }
                    }
                    string defaultStorageTargetName = string.Format("disk{0}", disk.PhysicalDiskIndex);
                    string defaultTargetName        = DefaultTargetIQN + ":" + defaultStorageTargetName;
                    AttachISCSIDisk(disk, defaultTargetName, parameters);
                    break;
                }

                case "volume":
                {
                    if (m_selectedVolume == null)
                    {
                        Console.WriteLine("No volume has been selected.");
                        break;
                    }

                    VolumeDisk virtualDisk          = new VolumeDisk(m_selectedVolume);
                    string     defaultTargetName    = DefaultTargetIQN + ":Volume";
                    bool       isAttachmentReadOnly = parameters.ContainsKey("readonly");
                    if (!isAttachmentReadOnly)
                    {
                        if (Environment.OSVersion.Version.Major >= 6)
                        {
                            if (m_selectedVolume is DynamicVolume)
                            {
                                foreach (DiskExtent extent in ((DynamicVolume)m_selectedVolume).Extents)
                                {
                                    if (extent.Disk is PhysicalDisk)
                                    {
                                        bool isDiskReadOnly;
                                        bool isOnline = ((PhysicalDisk)extent.Disk).GetOnlineStatus(out isDiskReadOnly);
                                        if (isOnline)
                                        {
                                            Console.WriteLine("Error: All disks containing the volume must be taken offline.");
                                            return;
                                        }

                                        if (isDiskReadOnly)
                                        {
                                            Console.WriteLine("Error: A disk containing the volume is set to readonly.");
                                            return;
                                        }
                                    }
                                }
                            }
                            else if (m_selectedVolume is Partition)
                            {
                                Disk disk = ((Partition)m_selectedVolume).Disk;
                                if (disk is PhysicalDisk)
                                {
                                    bool isDiskReadOnly;
                                    bool isOnline = ((PhysicalDisk)disk).GetOnlineStatus(out isDiskReadOnly);

                                    if (isOnline)
                                    {
                                        Console.WriteLine("Error: The disk containing the volume must be taken offline.");
                                        return;
                                    }

                                    if (isDiskReadOnly)
                                    {
                                        Console.WriteLine("Error: The disk containing the volume is set to readonly.");
                                        return;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine();
                            // Locking mechanism is not implemented
                            Console.WriteLine("Warning: if this volume is mounted locally, data corruption may occur!");
                        }
                    }
                    AttachISCSIDisk(virtualDisk, defaultTargetName, parameters);
                    break;
                }

                default:
                {
                    Console.WriteLine();
                    Console.WriteLine("Invalid argument.");
                    HelpAttach();
                    break;
                }
                }
            }
            else
            {
                HelpAttach();
            }
        }