sg_dd.c (sg3_utils-1.47r908.tgz) | : | sg_dd.c (sg3_utils-1.47r915.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 73 | skipping to change at line 73 | |||
#ifdef HAVE_GETRANDOM | #ifdef HAVE_GETRANDOM | |||
#include <sys/random.h> /* for getrandom() system call */ | #include <sys/random.h> /* for getrandom() system call */ | |||
#endif | #endif | |||
#include "sg_lib.h" | #include "sg_lib.h" | |||
#include "sg_cmds_basic.h" | #include "sg_cmds_basic.h" | |||
#include "sg_cmds_extra.h" | #include "sg_cmds_extra.h" | |||
#include "sg_io_linux.h" | #include "sg_io_linux.h" | |||
#include "sg_unaligned.h" | #include "sg_unaligned.h" | |||
#include "sg_pr2serr.h" | #include "sg_pr2serr.h" | |||
static const char * version_str = "6.27 20210601"; | static const char * version_str = "6.29 20210906"; | |||
#define ME "sg_dd: " | #define ME "sg_dd: " | |||
#define STR_SZ 1024 | #define STR_SZ 1024 | |||
#define INOUTF_SZ 512 | #define INOUTF_SZ 512 | |||
#define EBUFF_SZ 768 | #define EBUFF_SZ 768 | |||
#define DEF_BLOCK_SIZE 512 | #define DEF_BLOCK_SIZE 512 | |||
#define DEF_BLOCKS_PER_TRANSFER 128 | #define DEF_BLOCKS_PER_TRANSFER 128 | |||
#define DEF_BLOCKS_PER_2048TRANSFER 32 | #define DEF_BLOCKS_PER_2048TRANSFER 32 | |||
skipping to change at line 177 | skipping to change at line 177 | |||
static int coe_count = 0; | static int coe_count = 0; | |||
static int cmd_timeout = DEF_TIMEOUT; /* in milliseconds */ | static int cmd_timeout = DEF_TIMEOUT; /* in milliseconds */ | |||
static uint32_t glob_pack_id = 0; /* pre-increment */ | static uint32_t glob_pack_id = 0; /* pre-increment */ | |||
static struct timeval start_tm; | static struct timeval start_tm; | |||
static uint8_t * zeros_buff = NULL; | static uint8_t * zeros_buff = NULL; | |||
static uint8_t * free_zeros_buff = NULL; | static uint8_t * free_zeros_buff = NULL; | |||
static int read_long_blk_inc = READ_LONG_DEF_BLK_INC; | static int read_long_blk_inc = READ_LONG_DEF_BLK_INC; | |||
static long seed; | static long seed; | |||
#ifdef HAVE_SRAND48_R /* gcc extension. N.B. non-reentrant version slower */ | ||||
static struct drand48_data drand;/* opaque, used by srand48_r and mrand48_r */ | static struct drand48_data drand;/* opaque, used by srand48_r and mrand48_r */ | |||
#endif | ||||
static const char * proc_allow_dio = "/proc/scsi/sg/allow_dio"; | static const char * proc_allow_dio = "/proc/scsi/sg/allow_dio"; | |||
struct flags_t { | struct flags_t { | |||
bool append; | bool append; | |||
bool dio; | bool dio; | |||
bool direct; | bool direct; | |||
bool dpo; | bool dpo; | |||
bool dsync; | bool dsync; | |||
bool excl; | bool excl; | |||
skipping to change at line 2110 | skipping to change at line 2112 | |||
if (ssz < (ssize_t)sizeof(seed)) { | if (ssz < (ssize_t)sizeof(seed)) { | |||
pr2serr("getrandom() failed, ret=%d\n", (int)ssz); | pr2serr("getrandom() failed, ret=%d\n", (int)ssz); | |||
seed = (long)time(NULL); | seed = (long)time(NULL); | |||
} | } | |||
} | } | |||
#else | #else | |||
seed = (long)time(NULL); /* use seconds since epoch as proxy */ | seed = (long)time(NULL); /* use seconds since epoch as proxy */ | |||
#endif | #endif | |||
if (verbose > 1) | if (verbose > 1) | |||
pr2serr("seed=%ld\n", seed); | pr2serr("seed=%ld\n", seed); | |||
#ifdef HAVE_SRAND48_R | ||||
srand48_r(seed, &drand); | srand48_r(seed, &drand); | |||
#else | ||||
srand48(seed); | ||||
#endif | ||||
} else if (iflag.zero) { | } else if (iflag.zero) { | |||
ccp = "<zero bytes>"; | ccp = "<zero bytes>"; | |||
cc2p = "00"; | cc2p = "00"; | |||
} | } | |||
if (ccp) { | if (ccp) { | |||
if (inf[0]) { | if (inf[0]) { | |||
pr2serr("iflag=%s and if=%s contradict\n", cc2p, inf); | pr2serr("iflag=%s and if=%s contradict\n", cc2p, inf); | |||
return SG_LIB_CONTRADICT; | return SG_LIB_CONTRADICT; | |||
} | } | |||
in_type = FT_RANDOM_0_FF; | in_type = FT_RANDOM_0_FF; | |||
skipping to change at line 2387 | skipping to change at line 2393 | |||
else { | else { | |||
int kk, j; | int kk, j; | |||
const int jbump = sizeof(uint32_t); | const int jbump = sizeof(uint32_t); | |||
long rn; | long rn; | |||
uint8_t * bp; | uint8_t * bp; | |||
bp = wrkPos; | bp = wrkPos; | |||
for (kk = 0; kk < blocks; ++kk, bp += blk_sz) { | for (kk = 0; kk < blocks; ++kk, bp += blk_sz) { | |||
for (j = 0; j < blk_sz; j += jbump) { | for (j = 0; j < blk_sz; j += jbump) { | |||
/* mrand48 takes uniformly from [-2^31, 2^31) */ | /* mrand48 takes uniformly from [-2^31, 2^31) */ | |||
#ifdef HAVE_SRAND48_R | ||||
mrand48_r(&drand, &rn); | mrand48_r(&drand, &rn); | |||
#else | ||||
rn = mrand48(); | ||||
#endif | ||||
*((uint32_t *)(bp + j)) = (uint32_t)rn; | *((uint32_t *)(bp + j)) = (uint32_t)rn; | |||
} | } | |||
} | } | |||
} | } | |||
bytes_read = res; | bytes_read = res; | |||
in_full += blocks; | in_full += blocks; | |||
} else { | } else { | |||
while (((res = read(infd, wrkPos, blocks * blk_sz)) < 0) && | while (((res = read(infd, wrkPos, blocks * blk_sz)) < 0) && | |||
((EINTR == errno) || (EAGAIN == errno) || | ((EINTR == errno) || (EAGAIN == errno) || | |||
(EBUSY == errno))) | (EBUSY == errno))) | |||
End of changes. 7 change blocks. | ||||
1 lines changed or deleted | 11 lines changed or added |