+struct globals {
+ off_t out_full, out_part, in_full, in_part;
+#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ unsigned long long total_bytes;
+ unsigned long long begin_time_us;
+#endif
+ int flags;
+} FIX_ALIASING;
+#define G (*(struct globals*)&bb_common_bufsiz1)
+#define INIT_G() do { \
+ /* we have to zero it out because of NOEXEC */ \
+ memset(&G, 0, sizeof(G)); \
+} while (0)
+
+enum {
+ /* Must be in the same order as OP_conv_XXX! */
+ /* (see "flags |= (1 << what)" below) */
+ FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
+ FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
+ FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
+ FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
+ FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
+ /* end of conv flags */
+ /* start of input flags */
+ FLAG_IFLAG_SHIFT = 5,
+ FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
+ /* end of input flags */
+ FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
+ FLAG_COUNT = 1 << 7,
+ FLAG_STATUS = 1 << 8,
+ FLAG_STATUS_NONE = 1 << 9,
+ FLAG_STATUS_NOXFER = 1 << 10,
+};
+
+static void dd_output_status(int UNUSED_PARAM cur_signal)
+{
+#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ double seconds;
+ unsigned long long bytes_sec;
+ unsigned long long now_us = monotonic_us(); /* before fprintf */
+#endif
+
+ /* Deliberately using %u, not %d */
+ fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
+ "%"OFF_FMT"u+%"OFF_FMT"u records out\n",
+ G.in_full, G.in_part,
+ G.out_full, G.out_part);
+
+#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+# if ENABLE_FEATURE_DD_STATUS
+ if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */
+ return;
+ //TODO: should status=none make dd stop reacting to USR1 entirely?
+ //So far we react to it (we print the stats),
+ //status=none only suppresses final, non-USR1 generated status message.
+# endif
+ fprintf(stderr, "%llu bytes (%sB) copied, ",
+ G.total_bytes,
+ /* show fractional digit, use suffixes */
+ make_human_readable_str(G.total_bytes, 1, 0)
+ );
+ /* Corner cases:
+ * ./busybox dd </dev/null >/dev/null
+ * ./busybox dd bs=1M count=2000 </dev/zero >/dev/null
+ * (echo DONE) | ./busybox dd >/dev/null
+ * (sleep 1; echo DONE) | ./busybox dd >/dev/null
+ */
+ seconds = (now_us - G.begin_time_us) / 1000000.0;
+ bytes_sec = G.total_bytes / seconds;
+ fprintf(stderr, "%f seconds, %sB/s\n",
+ seconds,
+ /* show fractional digit, use suffixes */
+ make_human_readable_str(bytes_sec, 1, 0)
+ );
+#endif
+}
+
+static ssize_t full_write_or_warn(const void *buf, size_t len,
+ const char *const filename)
+{
+ ssize_t n = full_write(ofd, buf, len);
+ if (n < 0)
+ bb_perror_msg("writing '%s'", filename);
+ return n;
+}
+
+static bool write_and_stats(const void *buf, size_t len, size_t obs,
+ const char *filename)