Hello
I have a problem with ioctl call.
My code:
Code:
if (ioctl (fd, SG_IO, &sg_io))
{
return -1;
}
fd:
Code:
fd = open (file, O_RDWR|O_NONBLOCK)
SG_IO from sg.h
Code:
/* synchronous SCSI command ioctl, (only in version 3 interface) */
#define SG_IO 0x2285 /* similar effect as write() followed by read() */
sg_io is a struct
Code:
typedef struct sg_io_hdr
{
int interface_id; /* [i] 'S' for SCSI generic (required) */
int dxfer_direction; /* [i] data transfer direction */
unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
unsigned char mx_sb_len; /* [i] max length to write to sbp */
unsigned short int iovec_count; /* [i] 0 implies no scatter gather */
unsigned int dxfer_len; /* [i] byte count of data transfer */
void * dxferp; /* [i], [*io] points to data transfer memory
or scatter gather list */
unsigned char * cmdp; /* [i], [*i] points to command to perform */
unsigned char * sbp; /* [i], [*o] points to sense_buffer memory */
unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */
int pack_id; /* [i->o] unused internally (normally) */
void * usr_ptr; /* [i->o] unused internally */
unsigned char status; /* [o] scsi status */
unsigned char masked_status;/* [o] shifted, masked scsi status */
unsigned char msg_status; /* [o] messaging level data (optional) */
unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
unsigned short int host_status; /* [o] errors from host adapter */
unsigned short int driver_status;/* [o] errors from software driver */
int resid; /* [o] dxfer_len - actual_transferred */
unsigned int duration; /* [o] time taken by cmd (unit: millisec) */
unsigned int info; /* [o] auxiliary information */
} sg_io_hdr_t;
The struct is filled with data on different places in code.
But now to the important things. I'm building my own MMC commands and send them over ioctl to my DVD drive.
Code:
int err = 0;
Scsi_Command cmd;
cmd.associate (device);
cmd[0] = 0x35; // Synchronize Cache
cmd[1] = 0x00; // Immed
cmd[2] = 0x00; // Logical Block Address (drive may ignore this)
cmd[3] = 0x00; // Logical Block Address (drive may ignore this)
cmd[4] = 0x00; // Logical Block Address (drive may ignore this)
cmd[5] = 0x00; // Logical Block Address (drive may ignore this)
cmd[6] = 0x00; // Reserved
cmd[7] = 0x00; // Number of blocks (drive may ignore this)
cmd[8] = 0x00; // Number of blocks (drive may ignore this)
cmd[9] = 0x00; // Control
err = cmd.transport (); // -> ioctl
// err = cmd.transport (WRITE, buffer, 4); // testing
return err;
Thats working fine.
But my drive have also a few non standard MMC commands. I have tested three of them, but only one has worked. With the other two commands i get -1 back from the ioctl call and the errno variable is set. In errno i find a "14 - Bad address" error.
I have searched and found that Bad address means with the third parameter (sg_io) in the ioctl commando is something wrong (But i don't understand what it is).
I don't understand why i get this error. All standard MMC commands are working fine and the one none standard command also works.
On windows all the commands are working (also send over ioctl)
Code:
SendScsiCommand(hbd, output, prds, SCSI_PASS_THROUGH_DIRECT_ENGINE.SCSI_IOCTL_DATA_OUT, counter, mem);
What have i overseen?