public static void TestOverlappedWriteAndOverlappedRead(string path, long size) { RawDiskImage disk = RawDiskImage.Create(path, size); disk.ExclusiveLock(true); int totalSectors = (int)Math.Min(disk.TotalSectors, Int32.MaxValue); Parallel.For(0, totalSectors, 1, 4, delegate(int sectorIndex) { byte[] pattern = GetTestPattern(sectorIndex, RawDiskImage.DefaultBytesPerSector); disk.WriteSectors(sectorIndex, pattern); }); Parallel.For(0, totalSectors, 1, 4, delegate(int sectorIndex) { byte[] pattern = GetTestPattern(sectorIndex, RawDiskImage.DefaultBytesPerSector); byte[] sectorBytes = disk.ReadSector(sectorIndex); if (!ByteUtils.AreByteArraysEqual(pattern, sectorBytes)) { throw new InvalidDataException("Test failed"); } }); disk.ReleaseLock(); }
public static void TestSimultaneousWriteAndRead(string path, long size) { RawDiskImage disk = RawDiskImage.Create(path, size); disk.ExclusiveLock(true); int totalSectors = (int)Math.Min(disk.TotalSectors, Int32.MaxValue); Parallel.For(0, totalSectors / 2, 1, 4, delegate(int sectorHint) { long sectorIndex = sectorHint * 2; byte[] pattern = GetTestPattern(sectorIndex, 2, RawDiskImage.DefaultBytesPerSector); disk.WriteSectors(sectorIndex, pattern); if (sectorIndex > 100) { long sectorIndexToVerify = sectorIndex - 100; byte[] expectedPattern = GetTestPattern(sectorIndexToVerify, 2, RawDiskImage.DefaultBytesPerSector); byte[] sectorBytes = disk.ReadSectors(sectorIndexToVerify, 2); if (!ByteUtils.AreByteArraysEqual(sectorBytes, expectedPattern)) { throw new InvalidDataException("Test failed"); } } }); disk.ReleaseLock(); }
public static void TestWriteRead(string path, long size) { RawDiskImage disk = RawDiskImage.Create(path, size); disk.ExclusiveLock(); for (long sectorIndex = 0; sectorIndex < disk.TotalSectors; sectorIndex += PhysicalDisk.MaximumDirectTransferSizeLBA) { long leftToWrite = disk.TotalSectors - sectorIndex; int sectorsToWrite = (int)Math.Min(leftToWrite, PhysicalDisk.MaximumDirectTransferSizeLBA); byte[] pattern = GetTestPattern(sectorIndex, sectorsToWrite, RawDiskImage.DefaultBytesPerSector); disk.WriteSectors(sectorIndex, pattern); } for (long sectorIndex = 0; sectorIndex < disk.TotalSectors; sectorIndex += PhysicalDisk.MaximumDirectTransferSizeLBA) { long leftToRead = disk.TotalSectors - sectorIndex; int sectorsToRead = (int)Math.Min(leftToRead, PhysicalDisk.MaximumDirectTransferSizeLBA); byte[] pattern = GetTestPattern(sectorIndex, sectorsToRead, RawDiskImage.DefaultBytesPerSector); byte[] sectorBytes = disk.ReadSectors(sectorIndex, sectorsToRead); if (!ByteUtils.AreByteArraysEqual(pattern, sectorBytes)) { throw new InvalidDataException("Test failed"); } } disk.ReleaseLock(); }
private void MainForm_Load(object sender, EventArgs e) { Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; this.Text += " v" + version.ToString(3); m_server.OnLogEntry += Program.OnLogEntry; List <IPAddress> localIPs = GetHostIPAddresses(); KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>(); list.Add("Any", IPAddress.Any); foreach (IPAddress address in localIPs) { list.Add(address.ToString(), address); } comboIPAddress.DataSource = list; comboIPAddress.DisplayMember = "Key"; comboIPAddress.ValueMember = "Value"; lblStatus.Text = "Author: Tal Aloni ([email protected])"; #if Win32 if (!SecurityHelper.IsAdministrator()) { lblStatus.Text = "Some features require administrator privileges and have been disabled"; } #endif //test string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1) { //to do /* * if (args[0].Equals("DiskImage", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(DiskImage.GetDiskImage(args[2], false)); } */ } if (System.IO.File.Exists("config.xml") && args.Length <= 1) { XmlDocument XmlDocObj = new XmlDocument(); XmlDocObj.Load("config.xml"); XmlNode node = XmlDocObj.SelectSingleNode("//target"); string targetname = ""; string targetpath = ""; string targettype = ""; string targetsize = ""; string targetdiskindex = ""; if (node.Attributes["name"] != null) { targetname = node.Attributes["name"].Value; } if (node.Attributes["path"] != null) { targetpath = node.Attributes["path"].Value; } if (node.Attributes["class"] != null) { targettype = node.Attributes["class"].Value; } if (node.Attributes["size"] != null) { targetsize = node.Attributes["size"].Value; } if (node.Attributes["index"] != null) { targetdiskindex = node.Attributes["index"].Value; } if (targetname != "") { // List <Disk> m_disks = new List <Disk>(); if (targettype.Equals("RAMDisk", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(new RAMDisk(int.Parse(targetsize) * 1024 * 1024)); } if (targettype.Equals("DiskImage", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(DiskImage.GetDiskImage(targetpath, false)); } if (targettype.Equals("createDiskImage", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(VirtualHardDisk.CreateFixedDisk(targetpath, long.Parse(targetsize) * 1024 * 1024)); } if (targettype.Equals("createRawDiskImage", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(RawDiskImage.Create(targetpath, long.Parse(targetsize) * 1024 * 1024)); } if (targettype.Equals("PhysicalDisk", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(new PhysicalDisk(int.Parse(targetdiskindex))); } ISCSITarget target = new ISCSITarget(targetname, m_disks); ((SCSI.VirtualSCSITarget)target.SCSITarget).OnLogEntry += Program.OnLogEntry; target.OnAuthorizationRequest += new EventHandler <AuthorizationRequestArgs>(ISCSITarget_OnAuthorizationRequest); target.OnSessionTermination += new EventHandler <SessionTerminationArgs>(ISCSITarget_OnSessionTermination); m_targets.Add(target); // try { m_server.AddTarget(target); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error"); return; } listTargets.Items.Add(target.TargetName); } } }