5 Overview Of Device Programming

Contents of this section

The header file drivers/scsi/sg.h under the Linux source tree contains a description of the interface (this is based on kernel version 1.1.68):

struct sg_header
 {
  int pack_len;
                   /* length of incoming packet <4096 (including header) */
  int reply_len;   /* maximum length <4096 of expected reply */
  int pack_id;     /* id number of packet */
  int result;      /* 0==ok, otherwise refer to errno codes */
  unsigned int twelve_byte:1;
               /* Force 12 byte command length for group 6 & 7 commands  */
  unsigned int other_flags:31;                  /* for future use */
  unsigned char sense_buffer[16]; /* used only by reads */
  /* command follows then data for command */
 };

This structure describes how a SCSI command is to be processed and has room to hold the results of the execution of the command. The individual structure components will be discussed later in section sec-header .

The general way of exchanging data with the generic driver is as follows: to send a command to an open generic device, write() a block with this structure to it:

                             struct sg_header
                               SCSI command
                                input data

To obtain the result of a command, read() a block with this similar structure:

                             struct sg_header
                               output data

This is a general overview of the process. The following sections describe each of the steps in more detail.

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter