Page suivantePage pr�c�denteTable des mati�res

11. Exemple d'utilisation du tampon SCSI

Nous allons utiliser ici la commande "TEST UNIT READY" pour contr�ler si un support est charg� dans notre p�riph�rique. Les d�clarations d'en-t�te et la fonction handle_SCSI_cmd de l'exemple de "Inquiry" seront aussi n�cessaires.

 Table 73: Commande TEST UNIT READY
+=====-========-========-========-========-========-========-========-========+
|  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
|Octet|        |        |        |        |        |        |        |        |
|=====+=======================================================================|
| 0   |                           Code op�ration (00h)                        |
|-----+-----------------------------------------------------------------------|
| 1   |Numero d'unit� logique LUN|                  R�serv�                   |
|-----+-----------------------------------------------------------------------|
| 2   |                           R�serv�                                     |
|-----+-----------------------------------------------------------------------|
| 3   |                           R�serv�                                     |
|-----+-----------------------------------------------------------------------|
| 4   |                           R�serv�                                     |
|-----+-----------------------------------------------------------------------|
| 5   |                           Contr�le                                    |
+=============================================================================+

Voici la fonction qui l'impl�mente :

#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 )
{
 /* demande le statut READY */
 static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
 TESTUNITREADY_CMD, /* commande */
 0, /* lun/r�serv� */
 0, /* r�serv� */
 0, /* r�serv� */
 0, /* r�serv� */
 0};/* contr�le */
 memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
 /*
 * +------------------+
 * | struct sg_header | <- commande
 * +------------------+
 * | copie de cmdblk  | <- commande + SCSI_OFF
 * +------------------+
 */
 if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd,
 0, NULL)) {
 fprintf (stderr, "Unite non prete\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;
}

Nous pouvons maintenant r�aliser le contr�le � l'aide de la fonction main :

void main( void )
{
 fd = open(DEVICE, O_RDWR);
 if (fd < 0) {
 fprintf( stderr, "Il faut les permissions lecture/ecriture pour "DEVICE".\n"
 );
 exit(1);
 }
 /* on regarde si le support est charge */
 if (!TestForMedium()) {
 printf("le support n'est pas charge\n");
 } else {
 printf("le support est charge\n");
 }
}

Le fichier generic_demo.c en annexe contient les deux exemples.


Page suivantePage pr�c�denteTable des mati�res

Hosting by: Hurra Communications GmbH
Generated: 2007-01-26 18:01:15