aboutsummaryrefslogtreecommitdiff
path: root/src/sg_raw.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2017-12-07 13:32:05 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2017-12-07 13:32:05 +0000
commitefe114304fdf1c20afd491eacfd1aade4b136ca5 (patch)
treeb1672761995949e914d9821fa33b157ed1ce80ab /src/sg_raw.c
parent0693a6de283a5802c480ff352b2933b87020cd42 (diff)
downloadsg3_utils-efe114304fdf1c20afd491eacfd1aade4b136ca5.tar.gz
add include/sg_pt_linux.h lib/sg_pt_linux_nvme.c and .gitignore; sg_write_x: almost finished; more NVMe work (for sg_ses)
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@733 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sg_raw.c')
-rw-r--r--src/sg_raw.c65
1 files changed, 5 insertions, 60 deletions
diff --git a/src/sg_raw.c b/src/sg_raw.c
index 0f513e4c..537b9b1d 100644
--- a/src/sg_raw.c
+++ b/src/sg_raw.c
@@ -32,7 +32,7 @@
#include "sg_pr2serr.h"
#include "sg_unaligned.h"
-#define SG_RAW_VERSION "0.4.18 (2017-10-09)"
+#define SG_RAW_VERSION "0.4.19 (2017-12-06)"
#ifdef SG_LIB_WIN32
#ifndef HAVE_SYSCONF
@@ -275,63 +275,6 @@ process_cl(struct opts_t * op, int argc, char *argv[])
return 0;
}
-/* Allocate aligned memory (heap) starting on page boundary */
-static unsigned char *
-my_memalign(int length, unsigned char ** wrkBuffp, const struct opts_t * op)
-{
- size_t psz;
- unsigned char * res;
-
-#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
- psz = sysconf(_SC_PAGESIZE); /* POSIX.1 (was getpagesize()) */
-#elif defined(SG_LIB_WIN32)
- psz = win_pagesize();
-#else
- psz = 4096; /* give up, pick likely figure */
-#endif
-
-#ifdef HAVE_POSIX_MEMALIGN
- {
- int err;
- void * wp = NULL;
-
- err = posix_memalign(&wp, psz, length);
- if (err || (NULL == wp)) {
- pr2serr("posix_memalign: error [%d], out of memory?\n", err);
- return NULL;
- }
- memset(wp, 0, length);
- if (wrkBuffp)
- *wrkBuffp = (unsigned char *)wp;
- res = (unsigned char *)wp;
- if (op->verbose > 3)
- pr2serr("%s: posix, len=%d, wrkBuffp=%p, psz=%d, rp=%p\n",
- __func__, length, (void *)*wrkBuffp, (int)psz,
- (void *)res);
- return res;
- }
-#else
- {
- unsigned char * wrkBuff;
-
- wrkBuff = (unsigned char*)calloc(length + psz, 1);
- if (NULL == wrkBuff) {
- if (wrkBuffp)
- *wrkBuffp = NULL;
- return NULL;
- } else if (wrkBuffp)
- *wrkBuffp = wrkBuff;
- res = (unsigned char *)(((uintptr_t)wrkBuff + psz - 1) &
- (~(psz - 1)));
- if (op->verbose > 3)
- pr2serr("%s: hack, len=%d, wrkBuffp=%p, psz=%d, rp=%p\n",
- __func__, length, (void *)*wrkBuffp, (int)psz,
- (void *)res);
- return res;
- }
-#endif
-}
-
static int
skip(int fd, off_t offset)
{
@@ -392,7 +335,8 @@ fetch_dataout(struct opts_t * op)
}
}
- buf = my_memalign(op->dataout_len, &wrkBuf, op);
+ buf = sg_memalign(op->dataout_len, 0 /* page_size */, &wrkBuf,
+ op->verbose > 3);
if (buf == NULL) {
perror("malloc");
goto bail;
@@ -528,7 +472,8 @@ main(int argc, char *argv[])
set_scsi_pt_data_out(ptvp, dxfer_buffer_out, op->dataout_len);
}
if (op->do_datain) {
- dxfer_buffer_in = my_memalign(op->datain_len, &wrkBuf, op);
+ dxfer_buffer_in = sg_memalign(op->datain_len, 0 /* page_size */,
+ &wrkBuf, op->verbose > 3);
if (dxfer_buffer_in == NULL) {
perror("malloc");
ret = SG_LIB_CAT_OTHER;