07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

一切准备好了之后,我们就可以把data 数组,这个包含36 个字符的信息发送到scsi 命令指定的位置了,<br />

即srb 指定的位置.这正是278 行中, usb_stor_set_xfer_buf 的所作所为.<br />

在接着讲278 行这个函数usb_stor_set_xfer_buf 之前,先解释一下之前定义data_ptr[36]时初始化<br />

的前8 个元素.她们的含义都和scsi 协议规定的对应.data_ptr[0]不用说了,data_ptr[1]被赋为0x80,<br />

这表明这个设备是可移除的,data_ptr[2]被赋为0x02 这说明设备遵循SCSI-2 协议,data_ptr[3]被赋<br />

为<br />

0x02,说明数据格式遵循国际标准化组织所规定的格式,而data_ptr[4]被称为additional length,附加参<br />

数的长度,即除了用这么一个标准格式的数据响应之外,可能还会返回更多的一些信息.这里设置的是0x1F.<br />

彼岸花的传说(七)<br />

很显然,我们是把为INQUIRY 命令准备的数据保存到了我们自己定义的一个结构体中,即struct<br />

data_ptr[36],但是我们是为了回应一个SCSI 命令,最终需要知道答案的是scsi 核心层.正是它们传递了<br />

一个scsi_cmnd 结构体下来,即srb.struct scsi_cmnd 中有两个成员, unsigned request_bufflen 和<br />

void *request_buffer,小宇宙告诉我们,应该把data 数组中的数据传送到request_buffer 中去,这<br />

样,scsi 核心层就知道去哪里获取结果.没错,当时就是这样!<br />

usb_stor_set_xfer_buf()这个函数来自,drivers/usb/storage/protocol.c 中.<br />

281 /* Store the contents <strong>of</strong> buffer into srb's transfer buffer and set the<br />

282 * SCSI residue. */<br />

283 void usb_stor_set_xfer_buf(unsigned char *buffer,<br />

284 unsigned int buflen, struct scsi_cmnd *srb)<br />

285 {<br />

286 unsigned int index = 0, <strong>of</strong>fset = 0;<br />

287<br />

288 usb_stor_access_xfer_buf(buffer, buflen, srb, &index, &<strong>of</strong>fset,<br />

289 TO_XFER_BUF);<br />

290 if (buflen < srb->request_bufflen)<br />

291 srb->resid = srb->request_bufflen - buflen;<br />

292 }<br />

主要调用的又是usb_stor_access_xfer_buf()函数,这个函数也来自同一个文<br />

件,drivers/usb/storage/protocol.c,<br />

185<br />

/***********************************************************************<br />

186 * Scatter-gather transfer buffer access routines<br />

187 *****************************************************************<br />

132<br />

******/<br />

188<br />

189 /* Copy a buffer <strong>of</strong> length buflen to/from the srb's transfer buffer.<br />

190 * (Note: for scatter-gather transfers (srb->use_sg > 0), srb->request_buffer<br />

191 * points to a list <strong>of</strong> s-g entries and we ignore srb->request_bufflen.<br />

192 * For non-scatter-gather transfers, srb->request_buffer points to the<br />

193 * transfer buffer itself and srb->request_bufflen is the buffer's length.)<br />

194 * Update the *index and *<strong>of</strong>fset variables so that the next copy will

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!