附录 B. sg_header,原始的sg控制结构

以下是sg驱动程序的原始接口结构,其历史可以追溯到1991年。带有“[o]+”标记的字段元素是由sg版本2驱动程序添加的,该驱动程序于1999年4月首次放入lk 2.2.6。
struct sg_header
{
    int pack_len;    /* [o] */
    int reply_len;   /* [i] */
    int pack_id;     /* [i->o] */
    int result;      /* [o] */
    unsigned int twelve_byte:1;     /* [i] */
    unsigned int target_status:5;   /* [o]+ */
    unsigned int host_status:8;     /* [o]+ */
    unsigned int driver_status:8;   /* [o]+ */
    unsigned int other_flags:10;    /* unused */
    unsigned char sense_buffer[SG_MAX_SENSE]; /* [o] */
};      /* This structure is 36 bytes long on i386 */
SCSI命令通过对sg设备名称(例如 /dev/sg0)的 write() 调用发送。写入 write() 的数据格式为 <a_sg_header_obj + scsi_command [ + data_to_write]>。“data_to_write”组件仅在 SCSI 命令将数据传输到 SCSI 设备时才需要。对 sg 设备名称的相应 read() 调用将产生 <a_sg_header_obj [ + data_to_read]> 格式的数据。

此接口在 www.torque.net/sg/p/scsi-generic.txt 文件中进行了完整描述,该文件记录了 sg 版本 2 驱动程序。

由于许多 Linux 应用程序使用此接口,因此驱动程序的此版本(即版本 3)仍然支持它。只有其最反常的特性已被修改,并且没有主要的应用程序报告在较新的驱动程序之上运行旧应用程序时出现任何问题。