95
104
#define WRITE_LONG_16_SA 0x11
107
/* Invokes a SCSI GET LBA STATUS command (SBC). Returns 0 -> success,
108
* SG_LIB_CAT_INVALID_OP -> GET LBA STATUS not supported,
109
* SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
110
* SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
112
sg_ll_get_lba_status(int sg_fd, uint64_t start_llba, void * resp,
113
int alloc_len, int noisy, int verbose)
115
int k, res, sense_cat, ret;
116
unsigned char getLbaStatCmd[SERVICE_ACTION_IN_16_CMDLEN];
117
unsigned char sense_b[SENSE_BUFF_LEN];
118
struct sg_pt_base * ptvp;
120
memset(getLbaStatCmd, 0, sizeof(getLbaStatCmd));
121
getLbaStatCmd[0] = SERVICE_ACTION_IN_16_CMD;
122
getLbaStatCmd[1] = GET_LBA_STATUS_SA;
124
getLbaStatCmd[2] = (start_llba >> 56) & 0xff;
125
getLbaStatCmd[3] = (start_llba >> 48) & 0xff;
126
getLbaStatCmd[4] = (start_llba >> 40) & 0xff;
127
getLbaStatCmd[5] = (start_llba >> 32) & 0xff;
128
getLbaStatCmd[6] = (start_llba >> 24) & 0xff;
129
getLbaStatCmd[7] = (start_llba >> 16) & 0xff;
130
getLbaStatCmd[8] = (start_llba >> 8) & 0xff;
131
getLbaStatCmd[9] = start_llba & 0xff;
132
getLbaStatCmd[10] = (alloc_len >> 24) & 0xff;
133
getLbaStatCmd[11] = (alloc_len >> 16) & 0xff;
134
getLbaStatCmd[12] = (alloc_len >> 8) & 0xff;
135
getLbaStatCmd[13] = alloc_len & 0xff;
136
if (NULL == sg_warnings_strm)
137
sg_warnings_strm = stderr;
139
fprintf(sg_warnings_strm, " Get LBA status cmd: ");
140
for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k)
141
fprintf(sg_warnings_strm, "%02x ", getLbaStatCmd[k]);
142
fprintf(sg_warnings_strm, "\n");
145
ptvp = construct_scsi_pt_obj();
147
fprintf(sg_warnings_strm, "get LBA status: out of memory\n");
150
set_scsi_pt_cdb(ptvp, getLbaStatCmd, sizeof(getLbaStatCmd));
151
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
152
set_scsi_pt_data_in(ptvp, (unsigned char *)resp, alloc_len);
153
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
154
ret = sg_cmds_process_resp(ptvp, "get LBA status", res, alloc_len,
155
sense_b, noisy, verbose, &sense_cat);
158
else if (-2 == ret) {
160
case SG_LIB_CAT_NOT_READY:
161
case SG_LIB_CAT_ILLEGAL_REQ:
162
case SG_LIB_CAT_INVALID_OP:
163
case SG_LIB_CAT_UNIT_ATTENTION:
164
case SG_LIB_CAT_ABORTED_COMMAND:
167
case SG_LIB_CAT_RECOVERED:
168
case SG_LIB_CAT_NO_SENSE:
177
destruct_scsi_pt_obj(ptvp);
98
181
/* Invokes a SCSI REPORT TARGET PORT GROUPS command. Return of 0 -> success,
99
182
* SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported,
100
183
* SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
1760
1843
destruct_scsi_pt_obj(ptvp);
1847
/* Invokes a SCSI UNMAP command. Return of 0 -> success,
1848
* SG_LIB_CAT_INVALID_OP -> command not supported,
1849
* SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
1850
* SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
1852
sg_ll_unmap(int sg_fd, int group_num, int timeout_secs, void * paramp,
1853
int param_len, int noisy, int verbose)
1855
int k, res, ret, sense_cat, tmout;
1856
unsigned char uCmdBlk[UNMAP_CMDLEN] =
1857
{UNMAP_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1858
unsigned char sense_b[SENSE_BUFF_LEN];
1859
struct sg_pt_base * ptvp;
1861
tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT;
1862
uCmdBlk[7] = group_num & 0x1f;
1863
uCmdBlk[7] = (param_len >> 8) & 0xff;
1864
uCmdBlk[8] = param_len & 0xff;
1865
if (NULL == sg_warnings_strm)
1866
sg_warnings_strm = stderr;
1868
fprintf(sg_warnings_strm, " unmap cdb: ");
1869
for (k = 0; k < UNMAP_CMDLEN; ++k)
1870
fprintf(sg_warnings_strm, "%02x ", uCmdBlk[k]);
1871
fprintf(sg_warnings_strm, "\n");
1872
if ((verbose > 1) && paramp && param_len) {
1873
fprintf(sg_warnings_strm, " unmap parameter list:\n");
1874
dStrHex((const char *)paramp, param_len, -1);
1878
ptvp = construct_scsi_pt_obj();
1880
fprintf(sg_warnings_strm, "unmap: out of memory\n");
1883
set_scsi_pt_cdb(ptvp, uCmdBlk, sizeof(uCmdBlk));
1884
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
1885
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
1886
res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
1887
ret = sg_cmds_process_resp(ptvp, "unmap", res, 0,
1888
sense_b, noisy, verbose, &sense_cat);
1891
else if (-2 == ret) {
1892
switch (sense_cat) {
1893
case SG_LIB_CAT_INVALID_OP:
1894
case SG_LIB_CAT_ILLEGAL_REQ:
1895
case SG_LIB_CAT_UNIT_ATTENTION:
1896
case SG_LIB_CAT_ABORTED_COMMAND:
1899
case SG_LIB_CAT_RECOVERED:
1900
case SG_LIB_CAT_NO_SENSE:
1909
destruct_scsi_pt_obj(ptvp);
1913
/* Invokes a SCSI READ BLOCK LIMITS command. Return of 0 -> success,
1914
* SG_LIB_CAT_INVALID_OP -> Read block limits not supported,
1915
* SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
1916
* SG_LIB_CAT_ABORTED_COMMAND,
1917
* SG_LIB_NOT_READY (shouldn't happen), -1 -> other failure */
1919
sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len,
1920
int noisy, int verbose)
1922
int k, ret, res, sense_cat;
1923
unsigned char rlCmdBlk[READ_BLOCK_LIMITS_CMDLEN] =
1924
{READ_BLOCK_LIMITS_CMD, 0, 0, 0, 0, 0};
1925
unsigned char sense_b[SENSE_BUFF_LEN];
1926
struct sg_pt_base * ptvp;
1928
if (NULL == sg_warnings_strm)
1929
sg_warnings_strm = stderr;
1931
fprintf(sg_warnings_strm, " read block limits cdb: ");
1932
for (k = 0; k < READ_BLOCK_LIMITS_CMDLEN; ++k)
1933
fprintf(sg_warnings_strm, "%02x ", rlCmdBlk[k]);
1934
fprintf(sg_warnings_strm, "\n");
1937
ptvp = construct_scsi_pt_obj();
1939
fprintf(sg_warnings_strm, "read block limits: out of memory\n");
1942
set_scsi_pt_cdb(ptvp, rlCmdBlk, sizeof(rlCmdBlk));
1943
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
1944
set_scsi_pt_data_in(ptvp, (unsigned char *)resp, mx_resp_len);
1945
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
1946
ret = sg_cmds_process_resp(ptvp, "read block limits", res, mx_resp_len,
1947
sense_b, noisy, verbose, &sense_cat);
1950
else if (-2 == ret) {
1951
switch (sense_cat) {
1952
case SG_LIB_CAT_INVALID_OP:
1953
case SG_LIB_CAT_ILLEGAL_REQ:
1954
case SG_LIB_CAT_ABORTED_COMMAND:
1955
case SG_LIB_CAT_NOT_READY: /* shouldn't happen ?? */
1958
case SG_LIB_CAT_RECOVERED:
1959
case SG_LIB_CAT_NO_SENSE:
1968
destruct_scsi_pt_obj(ptvp);