★ wanayoo — archive 1999 http://icewalkers.com/doclib/howtos/SCSI-Programming-HOWTO-11.htmlNouvelle recherche | Portail wanayoo
Name:   Pass:    
Subscribe to IceWalkers Free NewsLetter




















LittleIgloo.org - a HOT Linux Place
see all



Year 2000 most disappointing thing was:

Y2K Bug
NASDAQ
Delayed Linux Kernel 2.4
Butterfly ballots
Pentium IV
Nothing. That was a great year!

  View results
  Previous polls
 
 Search Howtos: Match: Sort by:



Linux HOWTOs  |  HOWTOs Index



The Linux SCSI programming HOWTO: Example Using Sense Buffer Next Previous Contents

11. Example Using Sense Buffer

Here we will use the TEST UNIT READY command to check whether media is loaded into our device. The header declarations and function handle_SCSI_cmd from the inquiry example will be needed as well.

                        Table 73: TEST UNIT READY Command
+=====-========-========-========-========-========-========-========-========+
|  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
|Byte |        |        |        |        |        |        |        |        |
|=====+=======================================================================|
| 0   |                           Operation Code (00h)                        |
|-----+-----------------------------------------------------------------------|
| 1   | Logical Unit Number      |                  Reserved                  |
|-----+-----------------------------------------------------------------------|
| 2   |                           Reserved                                    |
|-----+-----------------------------------------------------------------------|
| 3   |                           Reserved                                    |
|-----+-----------------------------------------------------------------------|
| 4   |                           Reserved                                    |
|-----+-----------------------------------------------------------------------|
| 5   |                           Control                                     |
+=============================================================================+

Here is the function which implements it:

#define TESTUNITREADY_CMD 0
#define TESTUNITREADY_CMDLEN 6

#define ADD_SENSECODE 12
#define ADD_SC_QUALIFIER 13
#define NO_MEDIA_SC 0x3a
#define NO_MEDIA_SCQ 0x00

int TestForMedium ( void )
{
  /* request READY status */
  static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
      TESTUNITREADY_CMD, /* command */
                      0, /* lun/reserved */
                      0, /* reserved */
                      0, /* reserved */
                      0, /* reserved */
                      0};/* control */

  memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );

  /*
   * +------------------+
   * | struct sg_header | <- cmd
   * +------------------+
   * | copy of cmdblk   | <- cmd + SCSI_OFF
   * +------------------+
   */

  if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd, 
                            0, NULL)) {
      fprintf (stderr, "Test unit ready failed\n");
      exit(2);
  }

  return
   *(((struct sg_header*)cmd)->sense_buffer +ADD_SENSECODE) != 
                                                        NO_MEDIA_SC ||
   *(((struct sg_header*)cmd)->sense_buffer +ADD_SC_QUALIFIER) != 
                                                        NO_MEDIA_SCQ;
}

Combined with this main function we can do the check.

void main( void )
{
  fd = open(DEVICE, O_RDWR);
  if (fd < 0) {
    fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
    exit(1);
  }

  /* look if medium is loaded */

  if (!TestForMedium()) {
    printf("device is unloaded\n");
  } else {
    printf("device is loaded\n");
  }
}

The file generic_demo.c from the appendix contains both examples.


Next Previous Contents


HOWTOs Index

 
  
 
 
 


QCad 1.4.6
galeon 0.10.1
cdrecord 1.10a14-2
lilo 21.7
PostgreSQL 7.1beta5
Gnumeric 0.63



FVWM 2.2.5
XEmacs 21.2.45
ImPress 1.1-b7
dhcpcd 1.3.19-pl7
WebSupport 2.0.11
Partition Image 0.5.4
Komba 0.7
Ishmail 2.0.0
libxml 2.3.2
LilyPond 1.3.131
AbiWord 0.7.13
asmutils 0.13
Spat 1.0.1
ht://Dig 3.2.0b3
VisualRoute 5.1b
ManEdit 0.4i
eXtrans 1.1.1.b
mpatrol 1.4.0
parsecfg 3.6.6