Unable to send SCSI commands to USB Drive


 
Thread Tools Search this Thread
Operating Systems Solaris Unable to send SCSI commands to USB Drive
# 8  
Old 02-25-2015
yes the device does show mounted. I can send files to/from the device i.e. read/write to device with standard copy/paste/cut opreations on JDE on solaris 10 but if i compile the code on gcc and run it on terminal for scsi communication using ioctl with the device the open command works but the ioctl command returns negative value.
Also the rmformat command shows the device detected and displays all the parameters

---------- Post updated at 11:40 PM ---------- Previous update was at 11:18 PM ----------

Code:
Volmgt Node: /vol/dev/aliases/rmdisk0
        Logical Node: /dev/rdsk/c2t0d0p0
        Physical Node: /pci@0,0/pci1028,211@1a,7/storage@3/disk@0,0
        Connected Device: NS                 1.00
        Device Type: Removable



this information is displayed when rmformat command is executed

---------- Post updated 02-25-15 at 02:59 AM ---------- Previous update was 02-24-15 at 11:40 PM ----------

Below is my code


________________________________________________________
Code:
int fd, res, i;

    const int t_length = 512; // 512 bytes transferred
    const unsigned char blocks = 1; // Blocks transferred
    unsigned char rdCmdBlk[SCSI_CDB_LEN] = { 0x28, // Command
    0, 0, 0, 0, 0, 0, 0, 0, 0 };
    unsigned char sense_b[SENSE_BUFF_LEN];
    sg_io_hdr_t io_hdr;

    // Open device
    fd = open(deviceName , O_RDWR|O_SYNC);
    
    printf("fd in write is : %d\n" , fd);
    
    // Prepare SCSI READ (10) command
    rdCmdBlk[2] = 0x00; // LBA
    rdCmdBlk[3] = 0x00; // LBA
    rdCmdBlk[4] = 0x00; // LBA
    rdCmdBlk[5] = 0x66; // LBA
    rdCmdBlk[8] = blocks; // transfer length

    // Prepare the sg_io_hdr_t structure
    memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
    io_hdr.interface_id = 'S';
    io_hdr.cmd_len = sizeof(rdCmdBlk);
    io_hdr.mx_sb_len = sizeof(sense_b);
    io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
    io_hdr.dxfer_len = t_length;
    io_hdr.dxferp = dataTxChallenge;
    io_hdr.cmdp = rdCmdBlk;
    io_hdr.sbp = sense_b;
    io_hdr.timeout = 5000;

    // Sends the command to device
    if ((res = ioctl(fd, SG_IO, &io_hdr)) < 0) 
    {
        
        close(fd);
}




printf("IOCTL RESULT :    %d",res);

printf("ERROR NO :    %d",errno);

_______________________________________________________
The return value of ioctl is -1 and errno is 25 which is

Code:
#define    ENOTTY    25    /* Inappropriate ioctl for device */


Last edited by Don Cragun; 02-25-2015 at 05:28 AM.. Reason: Add CODE tags.
# 9  
Old 02-25-2015
What's the value of errno before you make your call? Often things like printf() will make ioctl() calls which fail with ENOTTY.

If you want to be sure you get a clean errno value, you have to set it to zero yourself before you make your call.
# 10  
Old 02-26-2015
the value of errno before the call is 0. i also manually cleared it before making the ioctl call. please consider that the primary problem is working of ioctl to pass scsi command of read write to a USB mass storage device which is successfully opened by open() call.
I hope so you will be able to help me better with this reply
# 11  
Old 02-26-2015
The exact values of errno are important because it's an indicator of why something failed.

If you've set the value to errno to zero, and you know the value of errno is zero before you make your ioctl call, the code you posted does not represent the code you're running.

Also, you need to be aware that "errno" is defined by the C/C++ standard to be a macro. As such, if you use a debugger to examine the value of the "errno" symbol, you likely will not be seeing or setting the actual value used by your process. On Solaris, the value of errno actually used by your code is quite likely the dereferenced integer pointer returned by the libc function "___errno()", and not the global "errno" symbol.

It's kind of hard to help you when you're not precisely representing nor understanding what you're doing.
# 12  
Old 02-26-2015
Quote:
Originally Posted by danish2012
the value of errno before the call is 0. i also manually cleared it before making the ioctl call. please consider that the primary problem is working of ioctl to pass scsi command of read write to a USB mass storage device which is successfully opened by open() call.
I hope so you will be able to help me better with this reply
You are using Linux (or at list GLIBC) specific ioctls with Solaris. This can't work. Your code shouldn't even compile under Solaris so I guest you naively copied include files from a Linux machine to the Solaris one. You should have stated that in the first place to get a quicker answer.

Use the proper Solaris API, uscsi. Start with:

Code:
man uscsi

# 13  
Old 02-27-2015
Thanks for your reply yes i am truly new to it. And yes i applogize for giving less information.

I did what u asked me to. used USCSI Solaris API but it gives Segmetation Fault - core dumped here is the new code

Code:
#include <fcntl.h>
#include </usr/include/sys/scsi/impl/uscsi.h>

#define deviceName "/vol/dev/aliases/rmdisk0"
#define SCSI_CDB_LEN 10
#define SENSE_BUFF_LEN 18

int main()
{
    int fd, res, i;
    unsigned char data[512]={0xe1,0xe2,0xe3,0xe4};
    const int t_length = 512; // 512 bytes transferred
    const unsigned char blocks = 1; // Blocks transferred
    unsigned char rdCmdBlk[SCSI_CDB_LEN] = { 0x2a, // Command
    0, 0, 0, 0, 0, 0, 0, 0, 0 };
    unsigned char sense_b[SENSE_BUFF_LEN];
    struct uscsi_cmd    *cmd1;
    
    // Open device
    fd = open(deviceName , O_RDWR);
    
    printf("fd in write is : %d\n" , fd);
    
    // Prepare SCSI  (10) command
    rdCmdBlk[2] = 0x00; // LBA
    rdCmdBlk[3] = 0x00; // LBA
    rdCmdBlk[4] = 0x00; // LBA
    rdCmdBlk[5] = 0x42; // LBA
    rdCmdBlk[8] = blocks; // transfer length
  
    
    cmd1->uscsi_flags= USCSI_WRITE;
    cmd1->uscsi_buflen =t_length;
    cmd1->uscsi_bufaddr =  data;
    cmd1->uscsi_timeout = 5000;
    cmd1->uscsi_cdb = (caddr_t) &rdCmdBlk;
    cmd1->uscsi_cdblen = SCSI_CDB_LEN;




    

    // Sends the command to device
    if ((res = ioctl(fd,USCSICMD,&cmd1)) < 0) 
    {
        
        close(fd);

printf("IOCTL FAILS:    %d",res);
        return -1;
    }
printf("IOCTL SUCCESS :     %d",res);
    
    
         close(fd);
        return 0;


}

# 14  
Old 02-27-2015
Quote:
Originally Posted by danish2012
I did what u asked me to. used USCSI Solaris API but it gives Segmetation Fault - core dumped here is the new code
That's no surprise. You do not allocate space for cmd1.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Unable to mount USB Pen drive on my Server

Hello Gurus!! Very recently i tried to mount a USB pen drive onto my solaris 10 (X4170 model) server. As i understand, in ideal scenarios it should get mounted automatically, but it did not happen. Neither anything is shown in "iostat -En" output or "rmformat -l" about the pen drive. I also... (10 Replies)
Discussion started by: EmbedUX
10 Replies

2. Hardware

SCSI drive

Hi i ahve a SCSI drive that it use to work but now is not working. The Sun machine can not read the drive. My question is there is any other way to get the data back from the SCSI drive? I think if i replace the chip board on teh SCSI drive it might help to just buy a new Board but there is any... (4 Replies)
Discussion started by: percel
4 Replies

3. Hardware

Help with scsi tape drive problem

I've had a scsi hard drive, scsi tape drive, and cd rom working off an adaptec 29160 controller. Everything worked great until a few days ago. I begin getting tar format errors (running sco 5.0.6) on the tape drive and occasionally the entire system would hang up while trying to access data on... (0 Replies)
Discussion started by: powwm
0 Replies

4. SCO

mounting USB floppy drive /Flash drive in OSR 6.0

Can anybody help me out to mount USB flash /floppy drive in sco openserver 6.0 . (5 Replies)
Discussion started by: sureshdrajan
5 Replies

5. SCO

Installing SCSI Tape drive

Hello, I'm having some issues with installing SCSI tape drive on SCO 5.0.6 hardware config shows the following adapters %adapter 0xE800-0xE8FF 10 - type=alad ha=0 bus=0 id=7 fts=sto %adapter 0x0170-0x0177 15 - type=IDE ctlr=secondary dvr=wd %adapter - 3 - ... (3 Replies)
Discussion started by: ananth_ak
3 Replies

6. Filesystems, Disks and Memory

Dead SCSI drive

I have 2 dead SCSI drives. Can anyone tell me a good way to repair the disks??? Please! (1 Reply)
Discussion started by: disturbe_d
1 Replies

7. Filesystems, Disks and Memory

The best partitioning schem for a 250GB Sata hard drive & a 75GB SCSI hard drive

Hi I have 2 75GB SCSI hard drives and 2 250GB SATA hard drives which are using RAID Level 1 respectively. I wana have both FTP and Apache installed on them as services. I'm wondering what's the best partitioning schem? I wana use FC3 as my OS, so, I thought I can use the 75GB hard drive as the /... (0 Replies)
Discussion started by: sirbijan
0 Replies

8. Filesystems, Disks and Memory

Adding new SCSI drive

DG Aviion (intel h/w) R4.20MU04 I plugged two new drives into my SCSI array, and need instructions on how to configure the filesystems...I've worked on Solaris (on Sun HW) boxes in the past, never has the pleasure of doing it on a DG. 1) Must I reboot for the system to "see" the drives? When... (0 Replies)
Discussion started by: iwasbornin1970
0 Replies

9. UNIX for Dummies Questions & Answers

scsi drive addon

Adding another scsi drive, no name, it came with the instruction manual in japanese, so of no use. We need to format it, it only shows up as 14 gigs, when we know it is a 40 gig drive, but have no specs on the cyl, etc. Combing through faqs, one of my coworkers found a blurb that unix won't... (1 Reply)
Discussion started by: kymberm
1 Replies

10. UNIX for Dummies Questions & Answers

Scsi tape drive.

I'm running SCO OS 505 on a Compaq proliant 1600, and my tape drive will just not work. It was working properly and whent to Sh?ts when I tried to get the cd rom working. I have uninstalled any configured tape drive and rebooted and then configured a tape drive and rebooted still nothing. I'm... (4 Replies)
Discussion started by: kikkin
4 Replies
Login or Register to Ask a Question