/usr/share/doc/HOWTO/ja-html/SCSI-Programming-HOWTO-8.html is in doc-linux-ja-html 2006.05.25-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21">
<TITLE>The Linux SCSI programming HOWTO: $B%X%C%@9=B$BN(B</TITLE>
<LINK HREF="SCSI-Programming-HOWTO-9.html" REL=next>
<LINK HREF="SCSI-Programming-HOWTO-7.html" REL=previous>
<LINK HREF="SCSI-Programming-HOWTO.html#toc8" REL=contents>
</HEAD>
<BODY>
<A HREF="SCSI-Programming-HOWTO-9.html">$B<!$N%Z!<%8(B</A>
<A HREF="SCSI-Programming-HOWTO-7.html">$BA0$N%Z!<%8(B</A>
<A HREF="SCSI-Programming-HOWTO.html#toc8">$BL\<!$X(B</A>
<HR>
<H2><A NAME="s8">8.</A> <A HREF="SCSI-Programming-HOWTO.html#toc8">$B%X%C%@9=B$BN(B</A></H2>
<P>
<A NAME="sec-header"></A>
$B%X%C%@9=B$BN(B <CODE>struct sg_header</CODE> $B$O%"%W%j%1!<%7%g%s$H%+!<%M%k%I%i%$%P$N(B
$B4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</P>
<DT><B>int result</B><DD><P><CODE>read</CODE> $B$"$k$$$O(B <CODE>write</CODE> $B8F$S=P$7$N7k2L%3!<%I!#(B
$B$3$l$O(B($B$?$^$K(B)$BHFMQ%I%i%$%P(B($B%+!<%M%k(B)$BB&$+$iDj5A$5$l$^$9!#(B
<CODE>write</CODE> $B$r8F=P$9A0$K$O(B NULL $B$K$7$F$*$/$N$,0BA4$G$9!#(B
$B$3$l$i$N%3!<%I$O(B <CODE>errno.h</CODE> $B$K$*$$$FDj5A$5$l$F$$$^$9(B(0 $B$O%(%i!<$J$7$r0UL#(B)$B!#(B</P>
<DT><B>unsigned int twelve_byte:1</B><DD><P>$B$3$N%U%#!<%k%I$OHsI8=`$N%Y%s%@8GM-$N%3%^%s%I$r;HMQ$9$k;~$K$@$1I,MW$G$9(B
(0xf0 - 0xff $B$NHO0O(B)$B!#$3$l$i$N%3%^%s%I$N%3%^%s%ID9$,(B 10 $B$G$O$J$/(B 12 $B$N(B
$B$H$-$O!"$3$N%U%#!<%k%I$O(B write $B$N8F$S=P$7$NA0$K(B 1 $B$K%;%C%H$5$l$M$P$J$j$^$;$s!#(B
$B$=$l0J30%3%^%s%ID9$O%5%]!<%H$5$l$F$$$^$;$s!#$3$l$O%"%W%j%1!<%7%g%sB&$+$i(B
$BDj5A$5$l$^$9!#(B</P>
<DT><B>unsigned char sense_buffer[16]</B><DD><P>$B$3$N%P%C%U%!$O%3%^%s%I$,40?k$7$?8e(B(<CODE>read()</CODE> $B$N8F$S=P$7$N8e(B)$B$G%;%C%H$5$l(B
SCSI $B$N%;%s%9%3!<%I$r4^$s$G$$$^$9!#%3%^%s%I$N7k2L$K$h$C$F$O$3$3$+$i(B
$BFI$_=P$5$M$P$J$i$J$$$b$N$b$"$j$^$9(B($BNc$($P(B <CODE>TESTUNITREADY</CODE>)$B!#(B
$BDL>o$O(B 0 $B%P%$%H$7$+$"$j$^$;$s!#$3$N%U%#!<%k%I$NCM$OHFMQ%I%i%$%P(B
($B%+!<%M%k(B)$BB&$+$i%;%C%H$5$l$^$9!#(B</P>
</DL>
</P>
<P>$B<!$N8+K\$N4X?t$OD>@\HFMQ%+!<%M%k%I%i%$%P$K:nMQ$7$^$9!#%X%C%@9=B$BN$rDj5A$7!"(B
<CODE>write</CODE> $B$rMQ$$$F%3%^%s%I$rAw=P$7!"(B<CODE>read</CODE> $B$K$h$C$F7k2L$r<u$1<h$j!"(B
$BB?>/$N(B($B8B$i$l$?(B)$B%(%i!<%A%'%C%/$r9T$$$^$9!#%;%s%9%P%C%U%!%G!<%?$O(B
$B=PNO%P%C%U%!$NCf$G<j$KF~$l$k$3$H$,$G$-$^$9(B($B%L%k%]%$%s%?$,M?$($i$l$F$$$J$$(B
$B8B$j!"$=$N>l9g$OF~NO%P%C%U%!Fb$K$"$j$^$9(B)$B!#$3$l$r0J2<$NNc$NCf$GMQ$$$k(B
$B$3$H$K$7$^$9!#(B</P>
<P>$BCm0U!'(B<CODE>DEVICE</CODE>$B$NCM$r$"$J$?$N%G%P%$%9$r5-=R$9$k$b$N$K@_Dj$7$F$/$@$5$$!#(B
<BLOCKQUOTE><CODE>
<PRE>
#define DEVICE "/dev/sgc"
/* $BHFMQ(B SCSI $B%$%s%?!<%U%'!<%9$r<B:]$KF0$+$7$F$_$k8+K\%W%m%0%i%`(B */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <scsi/sg.h>
#define SCSI_OFF sizeof(struct sg_header)
static unsigned char cmd[SCSI_OFF + 18]; /* SCSI $B%3%^%s%I(B $B%P%C%U%!(B */
int fd; /* SCSI $B%G%P%$%9(B/$B%U%!%$%k(B $B%G%#%9%/%j%W%?(B */
/* $B407k$7$?(B SCSI $B%3%^%s%I$r=hM}!#(B $BHFMQ(B SCSI $B%$%s%?!<%U%'!<%9$r;HMQ(B */
static int handle_SCSI_cmd(unsigned cmd_len, /* $B%3%^%s%ID9(B */
unsigned in_size, /* $BF~NO%G!<%?%5%$%:(B */
unsigned char *i_buff, /* $BF~NO%P%C%U%!(B */
unsigned out_size, /* $B=PNO%G!<%?%5%$%:(B */
unsigned char *o_buff /* $B=PNO%P%C%U%!(B */
)
{
int status = 0;
struct sg_header *sg_hd;
/* $B0BA4@-8!::(B */
if (!cmd_len) return -1; /* cmd_len != 0 $B$,I,MW(B */
if (!i_buff) return -1; /* $BF~NO%P%C%U%!$,(B NULL $B$G$J$$$3$H(B */
#ifdef SG_BIG_BUFF
if (SCSI_OFF + cmd_len + in_size > SG_BIG_BUFF) return -1;
if (SCSI_OFF + out_size > SG_BIG_BUFF) return -1;
#else
if (SCSI_OFF + cmd_len + in_size > 4096) return -1;
if (SCSI_OFF + out_size > 4096) return -1;
#endif
if (!o_buff) out_size = 0; /* $B=PNO%P%C%U%!$J$7!"=PNO%5%$%:$J$7(B */
/* $BHFMQ(B SCSI $B%G%P%$%9%X%C%@$N9=C[(B */
sg_hd = (struct sg_header *) i_buff;
sg_hd->reply_len = SCSI_OFF + out_size;
sg_hd->twelve_byte = cmd_len == 12;
sg_hd->result = 0;
#if 0
sg_hd->pack_len = SCSI_OFF + cmd_len + in_size; /* $BITMW(B */
sg_hd->pack_id; /* $BL$;HMQ(B */
sg_hd->other_flags; /* $BL$;HMQ(B */
#endif
/* $B%3%^%s%IAw=P(B */
status = write( fd, i_buff, SCSI_OFF + cmd_len + in_size );
if ( status < 0 || status != SCSI_OFF + cmd_len + in_size ||
sg_hd->result ) {
/* $B$J$s$i$+$N%(%i!<$,H/@8(B */
fprintf( stderr, "write(generic) result = 0x%x cmd = 0x%x\n",
sg_hd->result, i_buff[SCSI_OFF] );
perror("");
return status;
}
if (!o_buff) o_buff = i_buff; /* $B%P%C%U%!$N%]%$%s%?$r%A%'%C%/(B */
/* $B7k2L$r2s<}(B */
status = read( fd, o_buff, SCSI_OFF + out_size);
if ( status < 0 || status != SCSI_OFF + out_size || sg_hd->result ) {
/* $B$J$s$i$+$N%(%i!<$,H/@8(B */
fprintf( stderr, "read(generic) status = 0x%x, result = 0x%x, "
"cmd = 0x%x\n",
status, sg_hd->result, o_buff[SCSI_OFF] );
fprintf( stderr, "read(generic) sense "
"%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
sg_hd->sense_buffer[0], sg_hd->sense_buffer[1],
sg_hd->sense_buffer[2], sg_hd->sense_buffer[3],
sg_hd->sense_buffer[4], sg_hd->sense_buffer[5],
sg_hd->sense_buffer[6], sg_hd->sense_buffer[7],
sg_hd->sense_buffer[8], sg_hd->sense_buffer[9],
sg_hd->sense_buffer[10], sg_hd->sense_buffer[11],
sg_hd->sense_buffer[12], sg_hd->sense_buffer[13],
sg_hd->sense_buffer[14], sg_hd->sense_buffer[15]);
if (status < 0)
perror("");
}
/* $B<u$1<h$k$Y$-$b$N$r<u$1<h$C$?$+$I$&$+$r$_$k(B */
if (status == SCSI_OFF + out_size) status = 0; /* $BA4It$b$i$C$?(B */
return status; /* 0 $B$O%(%i!<$J$7$r0UL#(B */
}
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>$B$3$l$O:G=i$O$$$/$V$s$+J#;($K$_$($k$+$b$7$l$^$;$s$,!"%3!<%I$N$[$H$s$I(B
$B$O%(%i!<$N%A%'%C%/$HJs9p$G$9(B($B$3$l$O%3!<%I$,F0:n$9$k$h$&$K$J$C$?$"$H$G$b(B
$BLr$KN)$A$^$9(B)$B!#(B</P>
<P><CODE>Handle_SCSI_cmd</CODE> $B$OA4$F$N(B SCSI $B%3%^%s%I$N<oN`$KBP$7$F$N0lHLE*$J(B
$B7A<0$rHw$($F$$$F!"0J2<$N$h$&$KJ,N`$5$l$^$9!'(B</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
$B!!!!!!!!%G!<%?%b!<%I!!!!!!!!!!(B| $B%3%^%s%I$NNc(B
===============================================
$B!!F~NO!&=PNO%G!<%?$H$b$K$J$7!!(B| test unit ready
$BF~NO%G!<%?$J$7!"=PNO%G!<%?$"$j(B| inquiry, read
$BF~NO%G!<%?$"$j!"=PNO%G!<%?$J$7(B| mode select, write
$B!!F~NO!&=PNO%G!<%?$H$b$K$"$j!!(B| mode sense
</PRE>
</CODE></BLOCKQUOTE>
</P>
<HR>
<A HREF="SCSI-Programming-HOWTO-9.html">$B<!$N%Z!<%8(B</A>
<A HREF="SCSI-Programming-HOWTO-7.html">$BA0$N%Z!<%8(B</A>
<A HREF="SCSI-Programming-HOWTO.html#toc8">$BL\<!$X(B</A>
</BODY>
</HTML>
|