github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/linux/dev_sg.txt (about)

     1  # Copyright 2018 syzkaller project authors. All rights reserved.
     2  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  include <linux/types.h>
     5  include <uapi/linux/fs.h>
     6  include <scsi/sg.h>
     7  include <scsi/scsi.h>
     8  include <scsi/scsi_ioctl.h>
     9  include <uapi/linux/blktrace_api.h>
    10  
    11  resource fd_sg[fd_block_trace]
    12  
    13  syz_open_dev$sg(dev ptr[in, string["/dev/sg#"]], id intptr, flags flags[open_flags]) fd_sg
    14  
    15  ioctl$SG_IO(fd fd_sg, cmd const[SG_IO], arg ptr[in, sg_io_hdr])
    16  ioctl$SG_SET_TIMEOUT(fd fd_sg, cmd const[SG_SET_TIMEOUT], arg ptr[in, int32])
    17  ioctl$SG_GET_TIMEOUT(fd fd_sg, cmd const[SG_GET_TIMEOUT], arg const[0])
    18  ioctl$SG_GET_LOW_DMA(fd fd_sg, cmd const[SG_GET_LOW_DMA], arg ptr[out, int32])
    19  ioctl$SG_GET_SCSI_ID(fd fd_sg, cmd const[SG_GET_SCSI_ID], arg ptr[out, array[int8, SG_SCSI_ID_T_SIZE]])
    20  ioctl$SG_SET_FORCE_PACK_ID(fd fd_sg, cmd const[SG_SET_FORCE_PACK_ID], arg ptr[in, bool32])
    21  ioctl$SG_GET_PACK_ID(fd fd_sg, cmd const[SG_GET_PACK_ID], arg ptr[out, int32])
    22  ioctl$SG_GET_NUM_WAITING(fd fd_sg, cmd const[SG_GET_NUM_WAITING], arg ptr[out, int32])
    23  ioctl$SG_GET_SG_TABLESIZE(fd fd_sg, cmd const[SG_GET_SG_TABLESIZE], arg ptr[out, int32])
    24  ioctl$SG_SET_RESERVED_SIZE(fd fd_sg, cmd const[SG_SET_RESERVED_SIZE], arg ptr[in, int32])
    25  ioctl$SG_GET_RESERVED_SIZE(fd fd_sg, cmd const[SG_GET_RESERVED_SIZE], arg ptr[out, int32])
    26  ioctl$SG_GET_COMMAND_Q(fd fd_sg, cmd const[SG_GET_COMMAND_Q], arg ptr[out, int32])
    27  ioctl$SG_GET_KEEP_ORPHAN(fd fd_sg, cmd const[SG_GET_KEEP_ORPHAN], arg ptr[out, int32])
    28  ioctl$SG_GET_VERSION_NUM(fd fd_sg, cmd const[SG_GET_VERSION_NUM], arg ptr[out, int32])
    29  ioctl$SG_GET_ACCESS_COUNT(fd fd_sg, cmd const[SG_GET_ACCESS_COUNT], arg ptr[out, int32])
    30  ioctl$SG_EMULATED_HOST(fd fd_sg, cmd const[SG_EMULATED_HOST], arg ptr[out, int32])
    31  ioctl$SG_SET_COMMAND_Q(fd fd_sg, cmd const[SG_SET_COMMAND_Q], arg ptr[in, bool32])
    32  ioctl$SG_SET_KEEP_ORPHAN(fd fd_sg, cmd const[SG_SET_KEEP_ORPHAN], arg ptr[in, int32])
    33  ioctl$SG_NEXT_CMD_LEN(fd fd_sg, cmd const[SG_NEXT_CMD_LEN], arg ptr[in, int32[0:SG_MAX_CDB_SIZE]])
    34  ioctl$SG_SET_DEBUG(fd fd_sg, cmd const[SG_SET_DEBUG], arg ptr[in, bool32])
    35  ioctl$SG_SCSI_RESET(fd fd_sg, cmd const[SG_SCSI_RESET], arg const[0])
    36  ioctl$SG_GET_REQUEST_TABLE(fd fd_sg, cmd const[SG_GET_REQUEST_TABLE], arg ptr[out, array[int8, SG_REQUEST_TABLE_SIZE]])
    37  
    38  ioctl$SG_BLKSECTGET(fd fd_sg, cmd const[BLKSECTGET], arg ptr[out, intptr])
    39  ioctl$SG_BLKTRACESETUP(fd fd_sg, cmd const[BLKTRACESETUP], arg ptr[in, blk_user_trace_setup])
    40  ioctl$SG_BLKTRACESTART(fd fd_sg, cmd const[BLKTRACESTART], arg const[0])
    41  ioctl$SG_BLKTRACESTOP(fd fd_sg, cmd const[BLKTRACESTOP], arg const[0])
    42  ioctl$SG_BLKTRACETEARDOWN(fd fd_sg, cmd const[BLKTRACETEARDOWN], arg const[0])
    43  
    44  ioctl$SCSI_IOCTL_SEND_COMMAND(fd fd_sg, cmd const[SCSI_IOCTL_SEND_COMMAND], arg ptr[in, scsi_ioctl_command])
    45  ioctl$SCSI_IOCTL_TEST_UNIT_READY(fd fd_sg, cmd const[SCSI_IOCTL_TEST_UNIT_READY])
    46  ioctl$SCSI_IOCTL_DOORLOCK(fd fd_sg, cmd const[SCSI_IOCTL_DOORLOCK])
    47  ioctl$SCSI_IOCTL_DOORUNLOCK(fd fd_sg, cmd const[SCSI_IOCTL_DOORUNLOCK])
    48  ioctl$SCSI_IOCTL_START_UNIT(fd fd_sg, cmd const[SCSI_IOCTL_START_UNIT])
    49  ioctl$SCSI_IOCTL_STOP_UNIT(fd fd_sg, cmd const[SCSI_IOCTL_STOP_UNIT])
    50  ioctl$SCSI_IOCTL_SYNC(fd fd_sg, cmd const[SCSI_IOCTL_SYNC])
    51  ioctl$SCSI_IOCTL_BENCHMARK_COMMAND(fd fd_sg, cmd const[SCSI_IOCTL_BENCHMARK_COMMAND])
    52  ioctl$SCSI_IOCTL_GET_BUS_NUMBER(fd fd_sg, cmd const[SCSI_IOCTL_GET_BUS_NUMBER], arg ptr[out, int32])
    53  ioctl$SCSI_IOCTL_GET_PCI(fd fd_sg, cmd const[SCSI_IOCTL_GET_PCI], arg ptr[out, array[int8, 20]])
    54  ioctl$SCSI_IOCTL_PROBE_HOST(fd fd_sg, cmd const[SCSI_IOCTL_PROBE_HOST], arg ptr[out, scsi_ioctl_probe_host_out_buffer])
    55  ioctl$SCSI_IOCTL_GET_IDLUN(fd fd_sg, cmd const[SCSI_IOCTL_GET_IDLUN], arg ptr[out, scsi_idlun])
    56  
    57  sg_io_hdr {
    58  	interface_id	flags[sg_interface_id, int32]
    59  	dxfer_direction	flags[sg_dxfer_direction, int32]
    60  	cmd_len		len[cmdp, int8]
    61  	mx_sb_len	int8
    62  	data		sg_io_hdr_data
    63  	cmdp		ptr[in, array[int8]]
    64  	sbp		ptr[out, array[int8]]
    65  	timeout		int32
    66  	flags		flags[sg_flags, int32]
    67  	pack_id		int32[-1:3]
    68  	usr_ptr		ptr[out, int8]
    69  	status		const[0, int8]
    70  	masked_status	const[0, int8]
    71  	msg_status	const[0, int8]
    72  	sb_len_wr	const[0, int8]
    73  	host_status	const[0, int16]
    74  	driver_status	const[0, int16]
    75  	resid		const[0, int32]
    76  	duration	const[0, int32]
    77  	info		const[0, int32]
    78  } [packed, size[SG_IO_HDR_SIZE]]
    79  
    80  sg_io_hdr_data [
    81  	buffer	sg_io_hdr_data_buffer
    82  	scatter	sg_io_hdr_data_scatter
    83  ]
    84  
    85  sg_io_hdr_data_buffer {
    86  	iovec_count	const[0, int16]
    87  	dxfer_len	bytesize[dxferp, int32]
    88  	dxferp		ptr[out, array[int8]]
    89  } [packed]
    90  
    91  sg_io_hdr_data_scatter {
    92  	iovec_count	len[dxferp, int16]
    93  	dxfer_len	const[0, int32]
    94  	dxferp		ptr[in, array[iovec_out]]
    95  } [packed]
    96  
    97  scsi_ioctl_command {
    98  	inlen	len[data, int32]
    99  	outlen	int32
   100  	opcode	int32
   101  # TODO: this needs improvement: there are some command headers depending on opcode
   102  # and inlen only describes data past header.
   103  	data	array[int8]
   104  }
   105  
   106  scsi_idlun {
   107  	dev_id		int32
   108  	host_unique_id	int32
   109  }
   110  
   111  scsi_ioctl_probe_host_out_buffer {
   112  	len	bytesize[data, int32]
   113  	data	array[int8]
   114  }
   115  
   116  sg_interface_id = 0, 'S'
   117  sg_dxfer_direction = SG_DXFER_NONE, SG_DXFER_TO_DEV, SG_DXFER_FROM_DEV, SG_DXFER_TO_FROM_DEV, SG_DXFER_UNKNOWN
   118  sg_flags = SG_FLAG_DIRECT_IO, SG_FLAG_UNUSED_LUN_INHIBIT, SG_FLAG_MMAP_IO, SG_FLAG_NO_DXFER, SG_FLAG_Q_AT_TAIL, SG_FLAG_Q_AT_HEAD
   119  
   120  define SG_MAX_CDB_SIZE	252
   121  define SG_REQUEST_TABLE_SIZE	SG_MAX_QUEUE * sizeof(sg_req_info_t)
   122  define SG_IO_HDR_SIZE	sizeof(struct sg_io_hdr)
   123  define SG_SCSI_ID_T_SIZE	sizeof(sg_scsi_id_t)