xref: /illumos-gate/usr/src/cmd/hal/utils/cdutils.c (revision 8cd4c226)
118c2aff7Sartem /***************************************************************************
218c2aff7Sartem  *
3e6996a4dSartem  * cdutils.c : CD/DVD utilities
418c2aff7Sartem  *
5*8cd4c226SXiaolin Zhang - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
618c2aff7Sartem  * Use is subject to license terms.
718c2aff7Sartem  *
818c2aff7Sartem  * Licensed under the Academic Free License version 2.1
918c2aff7Sartem  *
1018c2aff7Sartem  **************************************************************************/
1118c2aff7Sartem 
1218c2aff7Sartem 
1318c2aff7Sartem #ifdef HAVE_CONFIG_H
1418c2aff7Sartem #  include <config.h>
1518c2aff7Sartem #endif
1618c2aff7Sartem 
1718c2aff7Sartem #include <stdio.h>
1818c2aff7Sartem #include <sys/types.h>
1918c2aff7Sartem #include <sys/scsi/impl/uscsi.h>
2018c2aff7Sartem #include <string.h>
2118c2aff7Sartem #include <strings.h>
2218c2aff7Sartem #include <unistd.h>
2318c2aff7Sartem #include <stdlib.h>
2418c2aff7Sartem #include <errno.h>
2518c2aff7Sartem #include <fcntl.h>
2618c2aff7Sartem #include <sys/dkio.h>
2718c2aff7Sartem #include <libintl.h>
2818c2aff7Sartem 
2918c2aff7Sartem #include <logger.h>
3018c2aff7Sartem 
3118c2aff7Sartem #include "cdutils.h"
3218c2aff7Sartem 
3318c2aff7Sartem #define	RQLEN	32
3418c2aff7Sartem #define SENSE_KEY(rqbuf)        (rqbuf[2])      /* scsi error category */
3518c2aff7Sartem #define ASC(rqbuf)              (rqbuf[12])     /* additional sense code */
3618c2aff7Sartem #define ASCQ(rqbuf)             (rqbuf[13])     /* ASC qualifier */
3718c2aff7Sartem 
3818c2aff7Sartem #define	GET16(a) (((a)[0] << 8) | (a)[1])
3918c2aff7Sartem #define	GET32(a) (((a)[0] << 24) | ((a)[1] << 16) | ((a)[2] << 8) | (a)[3])
4018c2aff7Sartem 
4118c2aff7Sartem #define	CD_USCSI_TIMEOUT	60
4218c2aff7Sartem 
4318c2aff7Sartem void
uscsi_cmd_init(struct uscsi_cmd * scmd,char * cdb,int cdblen)4418c2aff7Sartem uscsi_cmd_init(struct uscsi_cmd *scmd, char *cdb, int cdblen)
4518c2aff7Sartem {
4618c2aff7Sartem 	bzero(scmd, sizeof (*scmd));
4718c2aff7Sartem 	bzero(cdb, cdblen);
4818c2aff7Sartem 	scmd->uscsi_cdb = cdb;
49