+/* The difference in seconds between two times in "timeval" format. */
+double time_diff(struct timeval start, struct timeval end)
+{
+ return (end.tv_sec - start.tv_sec)
+ + (end.tv_usec - start.tv_usec) / 1E6;
+}
+
- rnc.log_fd = open(rnc.log_file, O_RDWR|O_CREAT|O_DIRECT, S_IRUSR|S_IWUSR);
+ flags = opt_directio ? O_RDWR|O_CREAT|O_DIRECT : O_RDWR|O_CREAT;
+ rnc.log_fd = open(rnc.log_file, flags, S_IRUSR|S_IWUSR);
-static int copy_data_forward(int fd_old, int fd_new, size_t block_size, void *buf)
+static int copy_data_forward(int fd_old, int fd_new, size_t block_size, void *buf, uint64_t *bytes)
-static int copy_data_backward(int fd_old, int fd_new, size_t block_size, void *buf)
+static int copy_data_backward(int fd_old, int fd_new, size_t block_size, void *buf, uint64_t *bytes)
{
ssize_t s1, s2, working_offset, working_block;
int j;
{
ssize_t s1, s2, working_offset, working_block;
int j;
- r = copy_data_forward(fd_old, fd_new, block_size, buf);
+ r = copy_data_forward(fd_old, fd_new, block_size, buf, &bytes);
- r = copy_data_backward(fd_old, fd_new, block_size, buf);
+ r = copy_data_backward(fd_old, fd_new, block_size, buf, &bytes);
+
+ gettimeofday(&end_time, NULL);
+
+ if (write_log() < 0)
+ log_err("Log write error, ignored.\n");
+
+ tdiff = time_diff(start_time, end_time);
+ log_err("Time elapsed %.2f seconds, %" PRIu64 " MB written, speed %.2f MB/s\n",
+ tdiff, bytes / 1024 / 1024, (double)(bytes / 1024 / 1024) / tdiff);
{ "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
{ "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL },
{ "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL },
{ "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
{ "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL },
{ "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL },
+ { "use-directio", '\0', POPT_ARG_NONE, &opt_directio, 0, N_("Use direct-io when accesing devices."), NULL },
+ { "write-log", '\0', POPT_ARG_NONE, &opt_write_log, 0, N_("Update log file after every block."), NULL },