3

Working in Golang / Ubuntu Environment

Facing Issues in these areas

func exec_ioctl(hdr *SgIoHdr) error {

f, err := os.Open("dev/sg1")  //The Status returned by err is always 3

if err != nil {

    return err

}

if err := Ioctl(uintptr(f.Fd()), SG_IO, uintptr(unsafe.Pointer(hdr))); 
err != nil {
    return err
}

What is the right command to open the drive?**

2. //Read16

sendCMD := []byte {0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00} 

cmdBuf := make([]byte, 16)

senseBuf := make([]byte, 512)

ioHdr   := SgIoHdr{
        InterfaceID:    int32('S'),                     
        DxferDirection: SG_DXFER_FROM_DEV,        
        CmdLen:         uint16(len(sendCMD )),           
        MxSbLen:        SENSE_BUF_LEN,           
        DxferLen:       uint32(len(cmdBuf )),               
        Dxferp:         &cmdBuf [0],
        SCmd:           sendCMD [0],
        Sbp:            &senseBuf[0],
        Timeout:        60000,
    }

err :=  exec_ioctl(&ioHdr)

    if err != nil {

        return err
    }


func Ioctl(fd, cmd, ptr uintptr) error {

    _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, cmd, ptr)

}

When trying to read the data returned by drive, it always returns 00

Even if a wrong Opcode is sent to the drive, err always returns 0 ie SCSI_STATUS IS GOOD

Is there any issue in the Read16 command ?

3. How to send WRITEATOMIC command to the drive like Read16?

createproblem
  • 1,542
  • 16
  • 30

0 Answers0