aboutsummaryrefslogtreecommitdiff
path: root/lib/sg_pt_dummy.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2021-06-11 03:57:05 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2021-06-11 03:57:05 +0000
commitbee57c535c29a01cadfaa660d8c0182288960c33 (patch)
tree2a9355f53953526dc12f101d6bf6b26962f5dbbe /lib/sg_pt_dummy.c
parent30363466e3580cae5f428c9bf35caa934cef469b (diff)
downloadsg3_utils-bee57c535c29a01cadfaa660d8c0182288960c33.tar.gz
sg_read_buffer: fix --length= problem; pt: new configure option --enable-pt_dummy builds the library with sg_pt_dummy.c instead of OS specific code
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@904 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib/sg_pt_dummy.c')
-rw-r--r--lib/sg_pt_dummy.c362
1 files changed, 362 insertions, 0 deletions
diff --git a/lib/sg_pt_dummy.c b/lib/sg_pt_dummy.c
new file mode 100644
index 00000000..be84b503
--- /dev/null
+++ b/lib/sg_pt_dummy.c
@@ -0,0 +1,362 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+
+#include "sg_pt.h"
+#include "sg_lib.h"
+#include "sg_pr2serr.h"
+
+/* Version 1.01 20210609 */
+
+/* Simply defines all the functions needed by the pt interface (see sg_pt.h).
+ * They do nothing. This allows decoding of hex files (e.g. with the --in=
+ * or --inhex= option) with utilities like sg_vpd and sg_logs. */
+
+struct sg_pt_dummy {
+ int dummy;
+};
+
+struct sg_pt_base {
+ struct sg_pt_dummy impl;
+};
+
+
+/* Returns >= 0 if successful. If error in Unix returns negated errno. */
+int
+scsi_pt_open_device(const char * device_name, bool read_only, int verbose)
+{
+ int oflags = 0 /* O_NONBLOCK*/ ;
+
+ oflags |= (read_only ? O_RDONLY : O_RDWR);
+ return scsi_pt_open_flags(device_name, oflags, verbose);
+}
+
+/* Similar to scsi_pt_open_device() but takes Unix style open flags OR-ed
+ * together. The 'flags' argument is ignored in OSF-1.
+ * Returns >= 0 if successful, otherwise returns negated errno. */
+int
+scsi_pt_open_flags(const char * device_name, int flags, int verbose)
+{
+ if (device_name) {}
+ if (flags) {}
+ if (verbose) {}
+ errno = EINVAL;
+ return -1;
+}
+
+/* Returns 0 if successful. If error in Unix returns negated errno. */
+int
+scsi_pt_close_device(int device_fd)
+{
+ if (device_fd) {}
+ return 0;
+}
+
+struct sg_pt_base *
+construct_scsi_pt_obj_with_fd(int device_fd, int verbose)
+{
+ struct sg_pt_dummy * ptp;
+
+ if (device_fd) {}
+ ptp = (struct sg_pt_dummy *)malloc(sizeof(struct sg_pt_dummy));
+ if (ptp) {
+ memset(ptp, 0, sizeof(struct sg_pt_dummy));
+ } else if (verbose)
+ pr2ws("%s: malloc() out of memory\n", __func__);
+ return (struct sg_pt_base *)ptp;
+}
+
+struct sg_pt_base *
+construct_scsi_pt_obj(void)
+{
+ return construct_scsi_pt_obj_with_fd(-1, 0);
+}
+
+void
+destruct_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (ptp)
+ free(ptp);
+}
+
+void
+clear_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (ptp) {
+ ptp->dummy = 0;
+ }
+}
+
+void
+partial_clear_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (NULL == ptp)
+ return;
+ ptp->dummy = 0;
+}
+
+void
+set_scsi_pt_cdb(struct sg_pt_base * vp, const uint8_t * cdb,
+ int cdb_len)
+{
+ if (vp) {}
+ if (cdb) {}
+ if (cdb_len) {}
+}
+
+int
+get_scsi_pt_cdb_len(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 6;
+}
+
+uint8_t *
+get_scsi_pt_cdb_buf(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return NULL;
+}
+
+void
+set_scsi_pt_sense(struct sg_pt_base * vp, uint8_t * sense,
+ int max_sense_len)
+{
+ if (vp) {}
+ if (sense) {}
+ if (max_sense_len) {}
+}
+
+/* from device */
+void
+set_scsi_pt_data_in(struct sg_pt_base * vp, uint8_t * dxferp,
+ int dxfer_len)
+{
+ if (vp) {}
+ if (dxferp) {}
+ if (dxfer_len) {}
+}
+
+/* to device */
+void
+set_scsi_pt_data_out(struct sg_pt_base * vp, const uint8_t * dxferp,
+ int dxfer_len)
+{
+ if (vp) {}
+ if (dxferp) {}
+ if (dxfer_len) {}
+}
+
+void
+set_scsi_pt_packet_id(struct sg_pt_base * vp, int pack_id)
+{
+ if (vp) {}
+ if (pack_id) {}
+}
+
+void
+set_scsi_pt_tag(struct sg_pt_base * vp, uint64_t tag)
+{
+ if (vp) {}
+ if (tag) {}
+}
+
+void
+set_scsi_pt_task_management(struct sg_pt_base * vp, int tmf_code)
+{
+ if (vp) {}
+ if (tmf_code) {}
+}
+
+void
+set_scsi_pt_task_attr(struct sg_pt_base * vp, int attrib, int priority)
+{
+ if (vp) {}
+ if (attrib) {}
+ if (priority) {}
+}
+
+void
+set_scsi_pt_flags(struct sg_pt_base * vp, int flags)
+{
+ if (vp) {}
+ if (flags) {}
+}
+
+int
+do_scsi_pt(struct sg_pt_base * vp, int device_fd, int time_secs, int verbose)
+{
+ if (vp) {}
+ if (device_fd) {}
+ if (time_secs) {}
+ if (verbose) {}
+ return 0;
+}
+
+int
+get_scsi_pt_result_category(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_resid(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+void
+get_pt_req_lengths(const struct sg_pt_base * vp, int * req_dinp,
+ int * req_doutp)
+{
+ if (vp) {}
+ if (req_dinp) {}
+ if (req_doutp) {}
+}
+
+void
+get_pt_actual_lengths(const struct sg_pt_base * vp, int * act_dinp,
+ int * act_doutp)
+{
+ if (vp) {}
+ if (act_dinp) {}
+ if (act_doutp) {}
+}
+
+
+int
+get_scsi_pt_status_response(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_sense_len(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+uint8_t *
+get_scsi_pt_sense_buf(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return NULL;
+}
+
+int
+get_scsi_pt_duration_ms(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+/* If not available return 0 otherwise return number of nanoseconds that the
+ * lower layers (and hardware) took to execute the command just completed. */
+uint64_t
+get_pt_duration_ns(const struct sg_pt_base * vp __attribute__ ((unused)))
+{
+ return 0;
+}
+
+int
+get_scsi_pt_transport_err(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_os_err(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+bool
+pt_device_is_nvme(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return false;
+}
+
+char *
+get_scsi_pt_transport_err_str(const struct sg_pt_base * vp, int max_b_len,
+ char * b)
+{
+ if (vp) {}
+ if (max_b_len) {}
+ if (b) {}
+ return NULL;
+}
+
+char *
+get_scsi_pt_os_err_str(const struct sg_pt_base * vp, int max_b_len, char * b)
+{
+ if (vp) {}
+ if (max_b_len) {}
+ if (b) {}
+ return NULL;
+}
+
+int
+do_nvm_pt(struct sg_pt_base * vp, int submq, int timeout_secs, int verbose)
+{
+ if (vp) { }
+ if (submq) { }
+ if (timeout_secs) { }
+ if (verbose) { }
+ return SCSI_PT_DO_NOT_SUPPORTED;
+}
+
+int
+check_pt_file_handle(int device_fd, const char * device_name, int vb)
+{
+ if (device_fd) {}
+ if (device_name) {}
+ if (vb) {}
+ return 0;
+}
+
+/* If a NVMe block device (which includes the NSID) handle is associated
+ * with 'vp', then its NSID is returned (values range from 0x1 to
+ * 0xffffffe). Otherwise 0 is returned. */
+uint32_t
+get_pt_nvme_nsid(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
+
+uint32_t
+get_pt_result(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}