Ejemplo n.º 1
0
        public bool Ioctl(ScsiPassThroughWrapper sptw)
        {
            IntPtr bufferPointer = IntPtr.Zero;
            bool   ioresult      = false;

            try
            {
                Int32 bufferSize = Marshal.SizeOf(sptw.sptBuffered);

                bufferPointer = Marshal.AllocHGlobal(bufferSize);
                Marshal.StructureToPtr(sptw.sptBuffered, bufferPointer, true);

                ioresult = DeviceIoControl(this.handle, (uint)IoctlCodes.IOCTL_SCSI_PASS_THROUGH_DIRECT, bufferPointer, (UInt32)bufferSize,
                                           bufferPointer, (UInt32)bufferSize, out UInt32 bytesReturned, IntPtr.Zero) && (bytesReturned > 0);

                if (ioresult)
                {
                    sptw.sptBuffered = (ScsiPassThroughBuffered)Marshal.PtrToStructure(bufferPointer, typeof(ScsiPassThroughBuffered));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(bufferPointer);
            }

            return(ioresult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wrapper calling low level function DeviceIoControl
        /// </summary>
        /// <param name="sptw">scsi params</param>
        /// <returns></returns>
        public bool Ioctl(ScsiPassThroughWrapper sptw)
        {
            IntPtr bufferPointer = IntPtr.Zero;
            bool   ioresult      = false;

            try
            {
                Int32 bufferSize = Marshal.SizeOf(sptw.sptBuffered);

                bufferPointer = Marshal.AllocHGlobal(bufferSize);
                Marshal.StructureToPtr(sptw.sptBuffered, bufferPointer, true);

                ioresult = DeviceIoControl(this.handle, (uint)IoctlCodes.IOCTL_SCSI_PASS_THROUGH_DIRECT, bufferPointer, (UInt32)bufferSize,
                                           bufferPointer, (UInt32)bufferSize, out UInt32 bytesReturned, IntPtr.Zero) && (bytesReturned > 0);

                if (ioresult)
                {
                    sptw.sptBuffered = (ScsiPassThroughBuffered)Marshal.PtrToStructure(bufferPointer, typeof(ScsiPassThroughBuffered));
                }
                else
                {
                    this.lastError = GetLastError();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("IO Ctl FAIL: {0}", e.Message);
            }
            finally
            {
                Marshal.FreeHGlobal(bufferPointer);
            }

            return(ioresult);
        }
Ejemplo n.º 3
0
 public ScsiCommand(ScsiPassThroughWrapper sptw)
 {
     this.Sptw = sptw;
 }