diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2018-02-22 07:00:28 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2018-02-22 07:00:28 +0000 |
commit | 252086533f8af0736c2a4987cd70a44366837ec1 (patch) | |
tree | 1f9245e247673fdb6ebea13b9aa559e1f869d78c /include | |
parent | 39ea1b548f21c006c311ace897b221b100bfa88d (diff) | |
download | sg3_utils-252086533f8af0736c2a4987cd70a44366837ec1.tar.gz |
sg_lib: add sg_if_can2stdout(); use uint8_t instead of unsigned char; Windows pass-through work
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@754 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'include')
-rw-r--r-- | include/sg_cmds_basic.h | 33 | ||||
-rw-r--r-- | include/sg_cmds_extra.h | 7 | ||||
-rw-r--r-- | include/sg_io_linux.h | 10 | ||||
-rw-r--r-- | include/sg_lib.h | 79 | ||||
-rw-r--r-- | include/sg_lib_data.h | 10 | ||||
-rw-r--r-- | include/sg_linux_inc.h | 3 | ||||
-rw-r--r-- | include/sg_pt.h | 10 | ||||
-rw-r--r-- | include/sg_pt_linux.h | 2 |
8 files changed, 77 insertions, 77 deletions
diff --git a/include/sg_cmds_basic.h b/include/sg_cmds_basic.h index 507effad..12b8771c 100644 --- a/include/sg_cmds_basic.h +++ b/include/sg_cmds_basic.h @@ -2,7 +2,7 @@ #define SG_CMDS_BASIC_H /* - * Copyright (c) 2004-2017 Douglas Gilbert. + * Copyright (c) 2004-2018 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -58,7 +58,7 @@ sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp, * SG_LIB_CAT_ABORTED_COMMAND, * SG_LIB_CAT_NOT_READY -> device not ready, * -1 -> other failure */ int sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code, - int subpg_code, unsigned char * paramp, int param_len, + int subpg_code, uint8_t * paramp, int param_len, bool noisy, int verbose); /* Invokes a SCSI LOG SENSE command. Return of 0 -> success, @@ -67,13 +67,13 @@ int sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code, * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND, * -1 -> other failure */ int sg_ll_log_sense(int sg_fd, bool ppc, bool sp, int pc, int pg_code, - int subpg_code, int paramp, unsigned char * resp, + int subpg_code, int paramp, uint8_t * resp, int mx_resp_len, bool noisy, int verbose); /* Same as sg_ll_log_sense() apart from timeout_secs and residp. See * sg_ll_inquiry_v2() for their description */ int sg_ll_log_sense_v2(int sg_fd, bool ppc, bool sp, int pc, int pg_code, - int subpg_code, int paramp, unsigned char * resp, + int subpg_code, int paramp, uint8_t * resp, int mx_resp_len, int timeout_secs, int * residp, bool noisy, int verbose); @@ -199,15 +199,15 @@ int sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress, struct sg_simple_inquiry_resp { - unsigned char peripheral_qualifier; - unsigned char peripheral_type; - unsigned char byte_1; /* was 'rmb' prior to version 1.39 */ + uint8_t peripheral_qualifier; + uint8_t peripheral_type; + uint8_t byte_1; /* was 'rmb' prior to version 1.39 */ /* now rmb == !!(0x80 & byte_1) */ - unsigned char version; /* as per recent drafts: whole of byte 2 */ - unsigned char byte_3; - unsigned char byte_5; - unsigned char byte_6; - unsigned char byte_7; + uint8_t version; /* as per recent drafts: whole of byte 2 */ + uint8_t byte_3; + uint8_t byte_5; + uint8_t byte_6; + uint8_t byte_7; char vendor[9]; /* T10 field is 8 bytes, NUL char appended */ char product[17]; char revision[5]; @@ -227,7 +227,7 @@ int sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data, * MODE SENSE (6) and false for MODE SENSE (10). Returns >= 0 is successful * or -1 if failure. If there is a failure a message is written to err_buff * if it is non-NULL and err_buff_len > 0. */ -int sg_mode_page_offset(const unsigned char * resp, int resp_len, +int sg_mode_page_offset(const uint8_t * resp, int resp_len, bool mode_sense_6, char * err_buff, int err_buff_len); /* MODE SENSE commands yield a response that has header then zero or more @@ -238,7 +238,7 @@ int sg_mode_page_offset(const unsigned char * resp, int resp_len, * successful the block descriptor length (in bytes) is written to *bd_lenp. * Set mode_sense_6 to true for MODE SENSE (6) and false for MODE SENSE (10) * responses. Returns -1 if there is an error (e.g. response too short). */ -int sg_msense_calc_length(const unsigned char * resp, int resp_len, +int sg_msense_calc_length(const uint8_t * resp, int resp_len, bool mode_sense_6, int * bd_lenp); /* Fetches current, changeable, default and/or saveable modes pages as @@ -294,9 +294,8 @@ struct sg_pt_base; * output via 'o_sense_cat' pointer (if not NULL). Note that several sense * categories also have data in bytes received; -2 is still returned. */ int sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin, - int pt_res, int mx_di_len, - const unsigned char * sense_b, bool noisy, - int verbose, int * o_sense_cat); + int pt_res, int mx_di_len, const uint8_t * sense_b, + bool noisy, int verbose, int * o_sense_cat); /* NVMe devices use a different command set. This function will return true * if the device associated with 'pvtp' is a NVME device, else it will diff --git a/include/sg_cmds_extra.h b/include/sg_cmds_extra.h index fbc23773..d7b82320 100644 --- a/include/sg_cmds_extra.h +++ b/include/sg_cmds_extra.h @@ -42,11 +42,10 @@ extern "C" { * data may be placed in *sensep in which case sensep[0]==0x70, prior to * SAT-2 descriptor sense format was required (i.e. sensep[0]==0x72). */ -int sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len, +int sg_ll_ata_pt(int sg_fd, const uint8_t * cdbp, int cdb_len, int timeout_secs, void * dinp, void * doutp, int dlen, - unsigned char * sensep, int max_sense_len, - unsigned char * ata_return_dp, int max_ata_return_len, - int * residp, int verbose); + uint8_t * sensep, int max_sense_len, uint8_t * ata_return_dp, + int max_ata_return_len, int * residp, int verbose); /* Invokes a FORMAT UNIT (SBC-3) command. Return of 0 -> success, * SG_LIB_CAT_INVALID_OP -> Format unit not supported, diff --git a/include/sg_io_linux.h b/include/sg_io_linux.h index 21675090..42ab2352 100644 --- a/include/sg_io_linux.h +++ b/include/sg_io_linux.h @@ -2,14 +2,14 @@ #define SG_IO_LINUX_H /* - * Copyright (c) 2004-2017 Douglas Gilbert. + * Copyright (c) 2004-2018 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. */ /* - * Version 1.05 [20171009] + * Version 1.06 [20180119] */ /* @@ -147,7 +147,7 @@ void sg_print_driver_status(int driver_status); 'sg_warnings_fd' and returns 0. raw_sinfo indicates whether the raw sense buffer (in ASCII hex) should be printed. */ int sg_chk_n_print(const char * leadin, int masked_status, int host_status, - int driver_status, const unsigned char * sense_buffer, + int driver_status, const uint8_t * sense_buffer, int sb_len, bool raw_sinfo); /* The following function declaration is for the sg version 3 driver. */ @@ -165,10 +165,10 @@ bool sg_normalize_sense(const struct sg_io_hdr * hp, struct sg_scsi_sense_hdr * sshp); int sg_err_category(int masked_status, int host_status, int driver_status, - const unsigned char * sense_buffer, int sb_len); + const uint8_t * sense_buffer, int sb_len); int sg_err_category_new(int scsi_status, int host_status, int driver_status, - const unsigned char * sense_buffer, int sb_len); + const uint8_t * sense_buffer, int sb_len); /* The following function declaration is for the sg version 3 driver. */ int sg_err_category3(struct sg_io_hdr * hp); diff --git a/include/sg_lib.h b/include/sg_lib.h index 60c8fd04..073ce815 100644 --- a/include/sg_lib.h +++ b/include/sg_lib.h @@ -67,10 +67,10 @@ extern "C" { #define SAM_STAT_CHECK_CONDITION 0x2 #define SAM_STAT_CONDITION_MET 0x4 #define SAM_STAT_BUSY 0x8 -#define SAM_STAT_INTERMEDIATE 0x10 /* obsolete in SAM-4 */ +#define SAM_STAT_INTERMEDIATE 0x10 /* obsolete in SAM-4 */ #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 /* obsolete in SAM-4 */ #define SAM_STAT_RESERVATION_CONFLICT 0x18 -#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ +#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ #define SAM_STAT_TASK_SET_FULL 0x28 #define SAM_STAT_ACA_ACTIVE 0x30 #define SAM_STAT_TASK_ABORTED 0x40 @@ -139,22 +139,22 @@ const char * sg_lib_version(); /* Returns length of SCSI command given the opcode (first byte). * Yields the wrong answer for variable length commands (opcode=0x7f) * and potentially some vendor specific commands. */ -int sg_get_command_size(unsigned char cdb_byte0); +int sg_get_command_size(uint8_t cdb_byte0); /* Command name given pointer to the cdb. Certain command names * depend on peripheral type (give 0 or -1 if unknown). Places command * name into buff and will write no more than buff_len bytes. */ -void sg_get_command_name(const unsigned char * cdbp, int peri_type, - int buff_len, char * buff); +void sg_get_command_name(const uint8_t * cdbp, int peri_type, int buff_len, + char * buff); /* Command name given only the first byte (byte 0) of a cdb and * peripheral type (give 0 or -1 if unknown). */ -void sg_get_opcode_name(unsigned char cdb_byte0, int peri_type, int buff_len, +void sg_get_opcode_name(uint8_t cdb_byte0, int peri_type, int buff_len, char * buff); /* Command name given opcode (byte 0), service action and peripheral type. * If no service action give 0, if unknown peripheral type give 0 or -1 . */ -void sg_get_opcode_sa_name(unsigned char cdb_byte0, int service_action, +void sg_get_opcode_sa_name(uint8_t cdb_byte0, int service_action, int peri_type, int buff_len, char * buff); /* Fetch NVMe command name given first byte (byte offset 0 in 64 byte @@ -174,14 +174,14 @@ void sg_get_scsi_status_str(int scsi_status, int buff_len, char * buff); * The original sense buffer should be kept around for those cases * in which more information is required (e.g. the LBA of a MEDIUM ERROR). */ struct sg_scsi_sense_hdr { - unsigned char response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */ - unsigned char sense_key; - unsigned char asc; - unsigned char ascq; - unsigned char byte4; - unsigned char byte5; - unsigned char byte6; - unsigned char additional_length; + uint8_t response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */ + uint8_t sense_key; + uint8_t asc; + uint8_t ascq; + uint8_t byte4; + uint8_t byte5; + uint8_t byte6; + uint8_t additional_length; }; /* Maps the salient data from a sense buffer which is in either fixed or @@ -191,18 +191,18 @@ struct sg_scsi_sense_hdr { * is non-NULL then zero all fields and then set the appropriate fields in * that structure. sshp::additional_length is always 0 for response * codes 0x70 and 0x71 (fixed format). */ -bool sg_scsi_normalize_sense(const unsigned char * sensep, int sense_len, +bool sg_scsi_normalize_sense(const uint8_t * sensep, int sense_len, struct sg_scsi_sense_hdr * sshp); /* Attempt to find the first SCSI sense data descriptor that matches the * given 'desc_type'. If found return pointer to start of sense data * descriptor; otherwise (including fixed format sense data) returns NULL. */ -const unsigned char * sg_scsi_sense_desc_find(const unsigned char * sensep, - int sense_len, int desc_type); +const uint8_t * sg_scsi_sense_desc_find(const uint8_t * sensep, int sense_len, + int desc_type); /* Get sense key from sense buffer. If successful returns a sense key value * between 0 and 15. If sense buffer cannot be decode, returns -1 . */ -int sg_get_sense_key(const unsigned char * sensep, int sense_len); +int sg_get_sense_key(const uint8_t * sensep, int sense_len); /* Yield string associated with sense_key value. Returns 'buff'. */ char * sg_get_sense_key_str(int sense_key, int buff_len, char * buff); @@ -213,7 +213,7 @@ char * sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff); /* Returns true if valid bit set, false if valid bit clear. Irrespective the * information field is written out via 'info_outp' (except when it is * NULL). Handles both fixed and descriptor sense formats. */ -bool sg_get_sense_info_fld(const unsigned char * sensep, int sb_len, +bool sg_get_sense_info_fld(const uint8_t * sensep, int sb_len, uint64_t * info_outp); /* Returns true if fixed format or command specific information descriptor @@ -221,14 +221,14 @@ bool sg_get_sense_info_fld(const unsigned char * sensep, int sb_len, * specific information field (4 byte integer in fixed format, 8 byte * integer in descriptor format) is written out via 'cmd_spec_outp'. * Handles both fixed and descriptor sense formats. */ -bool sg_get_sense_cmd_spec_fld(const unsigned char * sensep, int sb_len, +bool sg_get_sense_cmd_spec_fld(const uint8_t * sensep, int sb_len, uint64_t * cmd_spec_outp); /* Returns true if any of the 3 bits (i.e. FILEMARK, EOM or ILI) are set. * In descriptor format if the stream commands descriptor not found * then returns false. Writes true or false corresponding to these bits to * the last three arguments if they are non-NULL. */ -bool sg_get_sense_filemark_eom_ili(const unsigned char * sensep, int sb_len, +bool sg_get_sense_filemark_eom_ili(const uint8_t * sensep, int sb_len, bool * filemark_p, bool * eom_p, bool * ili_p); @@ -238,7 +238,7 @@ bool sg_get_sense_filemark_eom_ili(const unsigned char * sensep, int sb_len, * field is not available returns false. Handles both fixed and descriptor * sense formats. N.B. App should multiply by 100 and divide by 65536 * to get percentage completion from given value. */ -bool sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len, +bool sg_get_sense_progress_fld(const uint8_t * sensep, int sb_len, int * progress_outp); /* Closely related to sg_print_sense(). Puts decoded sense data in 'buff'. @@ -248,7 +248,7 @@ bool sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len, * bytes written to 'buff' excluding the trailing '\0'. * N.B. prior to sg3_utils v 1.42 'leadin' was only prepended to the first * line output. Also this function returned type void. */ -int sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer, +int sg_get_sense_str(const char * leadin, const uint8_t * sense_buffer, int sb_len, bool raw_sinfo, int buff_len, char * buff); /* Decode descriptor format sense descriptors (assumes sense buffer is @@ -256,7 +256,7 @@ int sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer, * to 'b', NULL treated as "". Returns the number of bytes written to 'b' * excluding the trailing '\0'. */ int sg_get_sense_descriptors_str(const char * leadin, - const unsigned char * sense_buffer, + const uint8_t * sense_buffer, int sb_len, int blen, char * b); /* Decodes a designation descriptor (e.g. as found in the Device @@ -265,7 +265,7 @@ int sg_get_sense_descriptors_str(const char * leadin, * treated as "". Returns the number of bytes written to 'b' excluding the * trailing '\0'. */ int sg_get_designation_descriptor_str(const char * leadin, - const unsigned char * ddp, int dd_len, + const uint8_t * ddp, int dd_len, bool print_assoc, bool do_long, int blen, char * b); @@ -287,9 +287,8 @@ char * sg_get_trans_proto_str(int tpi, int buff_len, char * buff); /* Decode TransportID pointed to by 'bp' of length 'bplen'. Place decoded * string output in 'buff' which is also the return value. Each new line * is prefixed by 'leadin'. If leadin NULL treat as "". */ -char * sg_decode_transportid_str(const char * leadin, unsigned char * bp, - int bplen, bool only_one, int buff_len, - char * buff); +char * sg_decode_transportid_str(const char * leadin, uint8_t * bp, int bplen, + bool only_one, int buff_len, char * buff); /* Returns a designator's type string given 'val' (0 to 15 inclusive), * otherwise returns NULL. */ @@ -358,21 +357,23 @@ void sg_set_warnings_strm(FILE * warnings_strm); /* The following "print" functions send ACSII to 'sg_warnings_strm' file * descriptor (default value is stderr). 'leadin' is string prepended to * each line printed out, NULL treated as "". */ -void sg_print_command(const unsigned char * command); +void sg_print_command(const uint8_t * command); void sg_print_scsi_status(int scsi_status); /* 'leadin' is string prepended to each line printed out, NULL treated as * "". N.B. prior to sg3_utils v 1.42 'leadin' was only prepended to the * first line printed. */ -void sg_print_sense(const char * leadin, const unsigned char * sense_buffer, +void sg_print_sense(const char * leadin, const uint8_t * sense_buffer, int sb_len, bool raw_info); -/* Following examines exit_status and outputs a clear error message to - * warnings_strm (usually stderr) if one is known and returns true. - * Otherwise it doesn't print anything and returns false. Note that if - * exit_status==0 then returns true but prints nothing and if - * exit_status<0 ("some error occurred") false is returned. If leadin is - * non-NULL is will be printed before error message. */ +/* This examines exit_status and if an error message is known it is output + * to stdout/stderr and true is returned. If no error message is + * available nothing is output and false is returned. If exit_status is + * zero (no error) nothing is output and true is returned. If exit_status + * is negative then nothing is output and false is returned. If leadin is + * non-NULL then it is printed before the error message. All messages are + * a single line with a trailing LF. */ +bool sg_if_can2stdout(const char * leadin, int exit_status); bool sg_if_can2stderr(const char * leadin, int exit_status); /* Utilities can use these exit status values for syntax errors and @@ -433,7 +434,7 @@ bool sg_if_can2stderr(const char * leadin, int exit_status); /* Returns a SG_LIB_CAT_* value. If cannot decode sense_buffer or a less * common sense key then return SG_LIB_CAT_SENSE .*/ -int sg_err_category_sense(const unsigned char * sense_buffer, int sb_len); +int sg_err_category_sense(const uint8_t * sense_buffer, int sb_len); /* Here are some additional sense data categories that are not returned * by sg_err_category_sense() but are returned by some related functions. */ @@ -464,7 +465,7 @@ const char * sg_get_category_sense_str(int sense_cat, int buff_len, * descriptor; returns -1 if normal end condition and -2 for an abnormal * termination. Matches association, designator_type and/or code_set when * any of those values are greater than or equal to zero. */ -int sg_vpd_dev_id_iter(const unsigned char * initial_desig_desc, int page_len, +int sg_vpd_dev_id_iter(const uint8_t * initial_desig_desc, int page_len, int * off, int m_assoc, int m_desig_type, int m_code_set); diff --git a/include/sg_lib_data.h b/include/sg_lib_data.h index ba15248d..cff13ed9 100644 --- a/include/sg_lib_data.h +++ b/include/sg_lib_data.h @@ -60,15 +60,15 @@ struct sg_lib_value_name_t { }; struct sg_lib_asc_ascq_t { - unsigned char asc; /* additional sense code */ - unsigned char ascq; /* additional sense code qualifier */ + uint8_t asc; /* additional sense code */ + uint8_t ascq; /* additional sense code qualifier */ const char * text; }; struct sg_lib_asc_ascq_range_t { - unsigned char asc; /* additional sense code (ASC) */ - unsigned char ascq_min; /* ASCQ minimum in range */ - unsigned char ascq_max; /* ASCQ maximum in range */ + uint8_t asc; /* additional sense code (ASC) */ + uint8_t ascq_min; /* ASCQ minimum in range */ + uint8_t ascq_max; /* ASCQ maximum in range */ const char * text; }; diff --git a/include/sg_linux_inc.h b/include/sg_linux_inc.h index b587c6ca..1f760185 100644 --- a/include/sg_linux_inc.h +++ b/include/sg_linux_inc.h @@ -2,8 +2,9 @@ #define SG_LINUX_INC_H #ifdef SG_KERNEL_INCLUDES + #include <stdint.h> /* C99 header for exact integer types */ #define __user - typedef unsigned char u8; + typedef uint8_t u8; #include "/usr/src/linux/include/scsi/sg.h" #include "/usr/src/linux/include/scsi/scsi.h" #else diff --git a/include/sg_pt.h b/include/sg_pt.h index 7545d8b0..712e9075 100644 --- a/include/sg_pt.h +++ b/include/sg_pt.h @@ -90,20 +90,20 @@ int get_pt_file_handle(const struct sg_pt_base * objp); void clear_scsi_pt_obj(struct sg_pt_base * objp); /* Set the CDB (command descriptor block) */ -void set_scsi_pt_cdb(struct sg_pt_base * objp, const unsigned char * cdb, +void set_scsi_pt_cdb(struct sg_pt_base * objp, const uint8_t * cdb, int cdb_len); /* Set the sense buffer and the maximum length that it can handle */ -void set_scsi_pt_sense(struct sg_pt_base * objp, unsigned char * sense, +void set_scsi_pt_sense(struct sg_pt_base * objp, uint8_t * sense, int max_sense_len); /* Set a pointer and length to be used for data transferred from device */ void set_scsi_pt_data_in(struct sg_pt_base * objp, /* from device */ - unsigned char * dxferp, int dxfer_ilen); + uint8_t * dxferp, int dxfer_ilen); /* Set a pointer and length to be used for data transferred to device */ void set_scsi_pt_data_out(struct sg_pt_base * objp, /* to device */ - const unsigned char * dxferp, int dxfer_olen); + const uint8_t * dxferp, int dxfer_olen); /* Set a pointer and length to be used for metadata transferred to * (out_true=true) or from (out_true-false) device */ -void set_pt_metadata_xfer(struct sg_pt_base * objp, unsigned char * mdxferp, +void set_pt_metadata_xfer(struct sg_pt_base * objp, uint8_t * mdxferp, uint32_t mdxfer_len, bool out_true); /* The following "set_"s implementations may be dummies */ void set_scsi_pt_packet_id(struct sg_pt_base * objp, int pack_id); diff --git a/include/sg_pt_linux.h b/include/sg_pt_linux.h index fd98c328..92bae900 100644 --- a/include/sg_pt_linux.h +++ b/include/sg_pt_linux.h @@ -116,7 +116,7 @@ struct sg_pt_linux_scsi { void * mdxferp; uint8_t * nvme_id_ctlp; /* cached response to controller IDENTIFY */ uint8_t * free_nvme_id_ctlp; - unsigned char tmf_request[4]; + uint8_t tmf_request[4]; }; struct sg_pt_base { |