本文整理汇总了C++中pr2serr函数的典型用法代码示例。如果您正苦于以下问题:C++ pr2serr函数的具体用法?C++ pr2serr怎么用?C++ pr2serr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pr2serr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: usage
static void
usage()
{
pr2serr("Usage: sg_referrals [--help] [--hex] [--lba=LBA] "
"[--maxlen=LEN]\n"
" [--one-segment] [--raw] [--readonly] "
"[--verbose]\n"
" [--version] DEVICE\n"
" where:\n"
" --help|-h print out usage message\n"
" --hex|-H output in hexadecimal\n"
" --lba=LBA|-l LBA starting LBA (logical block address) "
"(def: 0)\n"
" --maxlen=LEN|-m LEN max response length (allocation "
"length in cdb)\n"
" (def: 0 -> %d bytes)\n",
DEF_REFER_BUFF_LEN );
pr2serr(" --one-segment|-s return information about the specified "
"segment only\n"
" --raw|-r output in binary\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string and exit\n\n"
"Performs a SCSI REPORT REFERRALS command (SBC-3)\n"
);
}
示例2: write2wfn
static void
write2wfn(FILE * fp, struct opts_t * op)
{
int k, n;
size_t s;
char b[128];
if (op->do_hex) {
for (k = 0, n = 0; k < op->sense_len; ++k) {
n += sprintf(b + n, "0x%02x,", op->sense[k]);
if (15 == (k % 16)) {
b[n] = '\n';
s = fwrite(b, 1, n + 1, fp);
if ((int)s != (n + 1))
pr2serr("only able to write %d of %d bytes to %s\n",
(int)s, n + 1, op->wfname);
n = 0;
}
}
if (n > 0) {
b[n] = '\n';
s = fwrite(b, 1, n + 1, fp);
if ((int)s != (n + 1))
pr2serr("only able to write %d of %d bytes to %s\n", (int)s,
n + 1, op->wfname);
}
} else {
s = fwrite(op->sense, 1, op->sense_len, fp);
if ((int)s != op->sense_len)
pr2serr("only able to write %d of %d bytes to %s\n", (int)s,
op->sense_len, op->wfname);
}
}
示例3: calc_duration_throughput
static void
calc_duration_throughput(int contin)
{
struct timeval end_tm, res_tm;
double a, b;
if (start_tm_valid && (start_tm.tv_sec || start_tm.tv_usec)) {
gettimeofday(&end_tm, NULL);
res_tm.tv_sec = end_tm.tv_sec - start_tm.tv_sec;
res_tm.tv_usec = end_tm.tv_usec - start_tm.tv_usec;
if (res_tm.tv_usec < 0) {
--res_tm.tv_sec;
res_tm.tv_usec += 1000000;
}
a = res_tm.tv_sec;
a += (0.000001 * res_tm.tv_usec);
b = (double)blk_sz * (req_count - dd_count);
pr2serr("time to transfer data%s: %d.%06d secs",
(contin ? " so far" : ""), (int)res_tm.tv_sec,
(int)res_tm.tv_usec);
if ((a > 0.00001) && (b > 511))
pr2serr(" at %.2f MB/sec\n", b / (a * 1000000.0));
else
pr2serr("\n");
}
}
示例4: sg_ll_read_buffer_10
/* Invokes a SCSI READ BUFFER(10) command (spc5r02). Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
static int
sg_ll_read_buffer_10(int sg_fd, int rb_mode, int rb_mode_sp, int rb_id,
uint32_t rb_offset, void * resp, int mx_resp_len,
int * residp, bool noisy, int verbose)
{
int k, ret, res, sense_cat;
uint8_t rb10_cb[SG_READ_BUFFER_10_CMDLEN] =
{SG_READ_BUFFER_10_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
rb10_cb[1] = (uint8_t)(rb_mode & 0x1f);
if (rb_mode_sp)
rb10_cb[1] |= (uint8_t)((rb_mode_sp & 0x7) << 5);
rb10_cb[2] = (uint8_t)rb_id;
sg_put_unaligned_be24(rb_offset, rb10_cb + 3);
sg_put_unaligned_be24(mx_resp_len, rb10_cb + 6);
if (verbose) {
pr2serr(" Read buffer(10) cdb: ");
for (k = 0; k < SG_READ_BUFFER_10_CMDLEN; ++k)
pr2serr("%02x ", rb10_cb[k]);
pr2serr("\n");
}
ptvp = construct_scsi_pt_obj();
if (NULL == ptvp) {
pr2serr("Read buffer(10): out of memory\n");
return -1;
}
set_scsi_pt_cdb(ptvp, rb10_cb, sizeof(rb10_cb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_in(ptvp, (uint8_t *)resp, mx_resp_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
ret = sg_cmds_process_resp(ptvp, "Read buffer(10)", res, mx_resp_len,
sense_b, noisy, verbose, &sense_cat);
if (-1 == ret)
ret = sg_convert_errno(get_scsi_pt_os_err(ptvp));
else if (-2 == ret) {
switch (sense_cat) {
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
ret = sense_cat;
break;
}
} else {
if ((verbose > 2) && (ret > 0)) {
pr2serr(" Read buffer(10): response%s\n",
(ret > 256 ? ", first 256 bytes" : ""));
hex2stderr((const uint8_t *)resp, (ret > 256 ? 256 : ret), -1);
}
ret = 0;
}
if (residp)
*residp = get_scsi_pt_resid(ptvp);
destruct_scsi_pt_obj(ptvp);
return ret;
}
示例5: usage
static void
usage()
{
pr2serr("Usage: "
"sg_bg_ctl [--ctl=CTL] [--help] [--time=TN] [--verbose] "
"[--version]\n"
" DEVICE\n");
pr2serr(" where:\n"
" --ctl=CTL|-c CTL CTL is background operation control "
"value\n"
" default: 0 -> don't change background "
"operations\n"
" 1 -> start; 2 -> stop\n"
" --help|-h print out usage message\n"
" --time=TN|-t TN TN (units 100 ms) is max time to perform "
"background\n"
" operations (def: 0 -> no limit)\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string and exit\n\n"
"Performs a SCSI BACKGROUND CONTROL command. It can start or "
"stop\n'advanced background operations'. Operations started by "
"this command\n(i.e. when ctl=1) are termed as 'host initiated' "
"and allow a resource or\nthin provisioned device (disk) to "
"perform garbage collection type operations.\nThese may "
"degrade performance while they occur. Hence it is best to\n"
"perform this action while the computer is not too busy.\n");
}
示例6: process_read_long
/* Returns 0 if successful */
static int
process_read_long(int sg_fd, bool do_16, bool pblock, bool correct,
uint64_t llba, void * data_out, int xfer_len, int verbose)
{
int offset, res;
const char * ten_or;
char b[80];
if (do_16)
res = sg_ll_read_long16(sg_fd, pblock, correct, llba, data_out,
xfer_len, &offset, true, verbose);
else
res = sg_ll_read_long10(sg_fd, pblock, correct, (unsigned int)llba,
data_out, xfer_len, &offset, true, verbose);
ten_or = do_16 ? "16" : "10";
switch (res) {
case 0:
break;
case SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO:
pr2serr("<<< device indicates 'xfer_len' should be %d >>>\n",
xfer_len - offset);
break;
default:
sg_get_category_sense_str(res, sizeof(b), b, verbose);
pr2serr(" SCSI READ LONG (%s): %s\n", ten_or, b);
break;
}
return res;
}
示例7: print_stats
static void
print_stats()
{
if (0 != dd_count)
pr2serr(" remaining block count=%" PRId64 "\n", dd_count);
pr2serr("%" PRId64 "+%d records in\n", in_full - in_partial, in_partial);
pr2serr("%" PRId64 "+%d records out\n", out_full - out_partial,
out_partial);
}
示例8: list_op_abbrevs
static void
list_op_abbrevs()
{
struct smp_val_name * vnp;
pr2serr(" Valid operation abbreviations are:\n");
for (vnp = op_abbrev; vnp->name; ++vnp)
pr2serr(" %s\n", vnp->name);
}
示例9: fail_all_paths
static int fail_all_paths(int fd, int use_6_byte)
{
unsigned char fail_paths_pg[308];
struct rdac_legacy_page *rdac_page;
struct rdac_expanded_page *rdac_page_exp;
struct rdac_page_common *rdac_common = NULL;
int res;
char b[80];
memset(fail_paths_pg, 0, 308);
if (use_6_byte) {
memcpy(fail_paths_pg, mode6_hdr, 4);
memcpy(fail_paths_pg + 4, block_descriptor, 8);
rdac_page = (struct rdac_legacy_page *)(fail_paths_pg + 4 + 8);
rdac_page->page_code = RDAC_CONTROLLER_PAGE;
rdac_page->page_length = RDAC_CONTROLLER_PAGE_LEN;
rdac_common = &rdac_page->attr;
} else {
memcpy(fail_paths_pg, mode10_hdr, 8);
rdac_page_exp = (struct rdac_expanded_page *)
(fail_paths_pg + 8);
rdac_page_exp->page_code = RDAC_CONTROLLER_PAGE | 0x40;
rdac_page_exp->subpage_code = 0x1;
sg_put_unaligned_be16(EXPANDED_LUN_SPACE_PAGE_LEN,
rdac_page_exp->page_length + 0);
rdac_common = &rdac_page_exp->attr;
}
rdac_common->current_mode_lsb = RDAC_FAIL_ALL_PATHS;
rdac_common->quiescence = RDAC_QUIESCENCE_TIME;
rdac_common->options = RDAC_FORCE_QUIESCENCE;
if (use_6_byte) {
res = sg_ll_mode_select6(fd, 1 /* pf */, 0 /* sp */,
fail_paths_pg, 118,
1, (do_verbose ? 2 : 0));
} else {
res = sg_ll_mode_select10(fd, 1 /* pf */, 0 /* sp */,
fail_paths_pg, 308,
1, (do_verbose ? 2: 0));
}
switch (res) {
case 0:
if (do_verbose)
pr2serr("fail paths successful\n");
break;
default:
sg_get_category_sense_str(res, sizeof(b), b, do_verbose);
pr2serr("fail paths failed: %s\n", b);
break;
}
return res;
}
示例10: my_memalign
/* 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
}
示例11: ll_sync_cache_16
static int
ll_sync_cache_16(int sg_fd, int sync_nv, int immed, int group,
uint64_t lba, unsigned int num_lb, int to_secs,
int noisy, int verbose)
{
int res, ret, k, sense_cat;
unsigned char sc_cdb[SYNCHRONIZE_CACHE16_CMDLEN] =
{ SYNCHRONIZE_CACHE16_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
if (sync_nv)
sc_cdb[1] |= 4; /* obsolete in sbc3r35d */
if (immed)
sc_cdb[1] |= 2;
sg_put_unaligned_be64(lba, sc_cdb + 2);
sc_cdb[14] = group & 0x1f;
sg_put_unaligned_be32((uint32_t)num_lb, sc_cdb + 10);
if (verbose) {
pr2serr(" synchronize cache(16) cdb: ");
for (k = 0; k < SYNCHRONIZE_CACHE16_CMDLEN; ++k)
pr2serr("%02x ", sc_cdb[k]);
pr2serr("\n");
}
ptvp = construct_scsi_pt_obj();
if (NULL == ptvp) {
pr2serr("synchronize cache(16): out of memory\n");
return -1;
}
set_scsi_pt_cdb(ptvp, sc_cdb, sizeof(sc_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
res = do_scsi_pt(ptvp, sg_fd, to_secs, verbose);
ret = sg_cmds_process_resp(ptvp, "synchronize cache(16)", res, 0,
sense_b, noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
switch (sense_cat) {
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
ret = sense_cat;
break;
}
} else
ret = 0;
destruct_scsi_pt_obj(ptvp);
return ret;
}
示例12: sg_ll_rep_timestamp
/* Invokes a SCSI REPORT TIMESTAMP command. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
static int
sg_ll_rep_timestamp(int sg_fd, void * resp, int mx_resp_len, int * residp,
int noisy, int verbose)
{
int k, ret, res, sense_cat;
unsigned char rtCmdBlk[REP_TIMESTAMP_CMDLEN] =
{SG_MAINTENANCE_IN, REP_TIMESTAMP_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
sg_put_unaligned_be32((uint32_t)mx_resp_len, rtCmdBlk + 6);
if (verbose) {
pr2serr(" Report timestamp cdb: ");
for (k = 0; k < REP_TIMESTAMP_CMDLEN; ++k)
pr2serr("%02x ", rtCmdBlk[k]);
pr2serr("\n");
}
ptvp = construct_scsi_pt_obj();
if (NULL == ptvp) {
pr2serr("%s: out of memory\n", __func__);
return -1;
}
set_scsi_pt_cdb(ptvp, rtCmdBlk, sizeof(rtCmdBlk));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_in(ptvp, (unsigned char *)resp, mx_resp_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
ret = sg_cmds_process_resp(ptvp, "report timestamp", res, mx_resp_len,
sense_b, noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
switch (sense_cat) {
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
ret = sense_cat;
break;
}
} else
ret = 0;
k = get_scsi_pt_resid(ptvp);
if (residp)
*residp = k;
if ((verbose > 2) && ((mx_resp_len - k) > 0)) {
pr2serr("Parameter data returned:\n");
dStrHexErr((const char *)resp, mx_resp_len - k,
((verbose > 3) ? -1 : 1));
}
destruct_scsi_pt_obj(ptvp);
return ret;
}
示例13: print_modes
static void
print_modes(void)
{
const struct mode_s *mp;
pr2serr("The modes parameter argument can be numeric (hex or decimal)\n"
"or symbolic:\n");
for (mp = modes; mp->mode_string; ++mp) {
pr2serr(" %2d (0x%02x) %-16s%s\n", mp->mode, mp->mode,
mp->mode_string, mp->comment);
}
}
示例14: sg_ll_set_timestamp
/* Invokes the SET TIMESTAMP command. Return of 0 -> success, various
* SG_LIB_CAT_* positive values or -1 -> other errors */
static int
sg_ll_set_timestamp(int sg_fd, void * paramp, int param_len, int noisy,
int verbose)
{
int k, ret, res, sense_cat;
unsigned char stCmdBlk[SET_TIMESTAMP_CMDLEN] =
{SG_MAINTENANCE_OUT, SET_TIMESTAMP_SA, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0};
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
sg_put_unaligned_be32(param_len, stCmdBlk + 6);
if (verbose) {
pr2serr(" Set timestamp cdb: ");
for (k = 0; k < SET_TIMESTAMP_CMDLEN; ++k)
pr2serr("%02x ", stCmdBlk[k]);
pr2serr("\n");
if ((verbose > 1) && paramp && param_len) {
pr2serr(" set timestamp parameter list:\n");
dStrHexErr((const char *)paramp, param_len, -1);
}
}
ptvp = construct_scsi_pt_obj();
if (NULL == ptvp) {
pr2serr("%s: out of memory\n", __func__);
return -1;
}
set_scsi_pt_cdb(ptvp, stCmdBlk, sizeof(stCmdBlk));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
ret = sg_cmds_process_resp(ptvp, "set timestamp", res, 0, sense_b, noisy,
verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
switch (sense_cat) {
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
ret = sense_cat;
break;
}
} else
ret = 0;
destruct_scsi_pt_obj(ptvp);
return ret;
}
示例15: decode_all_sa_s
static void
decode_all_sa_s(const unsigned char * rabp, int len, const struct opts_t * op)
{
if (op->do_hex && (2 != op->do_hex)) {
dStrHex((const char *)rabp, len, ((1 == op->do_hex) ? 1 : -1));
return;
}
switch (op->sa) {
case RA_ATTR_VAL_SA:
decode_attr_vals(rabp + 4, len - 4, op);
break;
case RA_ATTR_LIST_SA:
decode_attr_list(rabp + 4, len - 4, false, op);
break;
case RA_LV_LIST_SA:
if ((0 == op->quiet) || op->verbose)
printf("Logical volume list:\n");
if (len < 4) {
pr2serr(">>> response length unexpectedly short: %d bytes\n",
len);
break;
}
printf(" First logical volume number: %u\n", rabp[2]);
printf(" Number of logical volumes available: %u\n", rabp[3]);
break;
case RA_PART_LIST_SA:
if ((0 == op->quiet) || op->verbose)
printf("Partition number list:\n");
if (len < 4) {
pr2serr(">>> response length unexpectedly short: %d bytes\n",
len);
break;
}
printf(" First partition number: %u\n", rabp[2]);
printf(" Number of partitions available: %u\n", rabp[3]);
break;
case RA_SMC2_SA:
printf("Used by SMC-2, not information, output in hex:\n");
dStrHex((const char *)rabp, len, 0);
break;
case RA_SUP_ATTR_SA:
decode_attr_list(rabp + 4, len - 4, true, op);
break;
default:
printf("Unrecognized service action [0x%x], response in hex:\n",
op->sa);
dStrHex((const char *)rabp, len, 0);
break;
}
}