diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2018-05-24 01:13:38 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2018-05-24 01:13:38 +0000 |
commit | 919290b79eb6649d6d05242180ddb3944ca9521b (patch) | |
tree | e2b2f839acafdc5493bb21e81e4361f37c8f4357 /src/sgp_dd.c | |
parent | 26e76bf6c671941fec1a8d2b3fb53fcd64993577 (diff) | |
download | sg3_utils-919290b79eb6649d6d05242180ddb3944ca9521b.tar.gz |
add SG_LIB_LOGIC_ERROR and SG_LIB_CONTRADICT; implement across many utilities and increase usage of sg_convert_errno()
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@774 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sgp_dd.c')
-rw-r--r-- | src/sgp_dd.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/sgp_dd.c b/src/sgp_dd.c index de9697ea..68eeeda0 100644 --- a/src/sgp_dd.c +++ b/src/sgp_dd.c @@ -60,7 +60,7 @@ #include "sg_pr2serr.h" -static const char * version_str = "5.63 20180502"; +static const char * version_str = "5.64 20180523"; #define DEF_BLOCK_SIZE 512 #define DEF_BLOCKS_PER_TRANSFER 128 @@ -1148,7 +1148,7 @@ main(int argc, char * argv[]) char * buf; char inf[INOUTF_SZ]; char outf[INOUTF_SZ]; - int res, k; + int res, k, err; int64_t in_num_sect = 0; int64_t out_num_sect = 0; pthread_t threads[MAX_NUM_THREADS]; @@ -1353,10 +1353,11 @@ main(int argc, char * argv[]) flags |= O_SYNC; if ((rcoll.infd = open(inf, flags)) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scould not open %s for sg " "reading", my_name, inf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err);; } if (sg_prepare(rcoll.infd, rcoll.bs, rcoll.bpt)) return SG_LIB_FILE_ERROR; @@ -1371,20 +1372,22 @@ main(int argc, char * argv[]) flags |= O_SYNC; if ((rcoll.infd = open(inf, flags)) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scould not open %s for reading", my_name, inf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } else if (skip > 0) { off64_t offset = skip; offset *= rcoll.bs; /* could exceed 32 here! */ if (lseek64(rcoll.infd, offset, SEEK_SET) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scouldn't skip to required " "position on %s", my_name, inf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } } } @@ -1406,10 +1409,11 @@ main(int argc, char * argv[]) flags |= O_SYNC; if ((rcoll.outfd = open(outf, flags)) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scould not open %s for sg " "writing", my_name, outf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } if (sg_prepare(rcoll.outfd, rcoll.bs, rcoll.bpt)) @@ -1430,18 +1434,20 @@ main(int argc, char * argv[]) flags |= O_APPEND; if ((rcoll.outfd = open(outf, flags, 0666)) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scould not open %s for " "writing", my_name, outf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } } else { /* raw output file */ if ((rcoll.outfd = open(outf, O_WRONLY)) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scould not open %s for raw " "writing", my_name, outf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } } if (seek > 0) { @@ -1449,10 +1455,11 @@ main(int argc, char * argv[]) offset *= rcoll.bs; /* could exceed 32 bits here! */ if (lseek64(rcoll.outfd, offset, SEEK_SET) < 0) { + err = errno; snprintf(ebuff, EBUFF_SZ, "%scouldn't seek to required " "position on %s", my_name, outf); perror(ebuff); - return SG_LIB_FILE_ERROR; + return sg_convert_errno(err); } } } |