/* * Cleanup any remaining I/O and flush output. If necesssary, output file * is truncated. */ static void dd_close(void) { if (cfunc == def) def_close(); else if (cfunc == block) block_close(); else if (cfunc == unblock) unblock_close(); if (ddflags & C_OSYNC && out.dbcnt < out.dbsz) { (void)memset(out.dbp, 0, out.dbsz - out.dbcnt); out.dbcnt = out.dbsz; } /* If there are pending sparse blocks, make sure * to write out the final block un-sparse */ if ((out.dbcnt == 0) && pending) { memset(out.db, 0, out.dbsz); out.dbcnt = out.dbsz; out.dbp = out.db + out.dbcnt; pending -= out.dbsz; } if (out.dbcnt) dd_out(1); /* * Reporting nfs write error may be defered until next * write(2) or close(2) system call. So, we need to do an * extra check. If an output is stdout, the file structure * may be shared among with other processes and close(2) just * decreases the reference count. */ if (out.fd == STDOUT_FILENO && fsync(out.fd) == -1 && errno != EINVAL) { fprintf(stderr, "fsync stdout: %s\n", strerror(errno)); exit(1); /* NOTREACHED */ } if (close(out.fd) == -1) { fprintf(stderr, "close: %s\n", strerror(errno)); exit(1); /* NOTREACHED */ } }
/* * Cleanup any remaining I/O and flush output. If necessary, output file * is truncated. */ static void dd_close(void) { if (cfunc == def) def_close(); else if (cfunc == block) block_close(); else if (cfunc == unblock) unblock_close(); if (ddflags & C_OSYNC && out.dbcnt && out.dbcnt < out.dbsz) { if (ddflags & (C_BLOCK|C_UNBLOCK)) memset(out.dbp, ' ', out.dbsz - out.dbcnt); else memset(out.dbp, 0, out.dbsz - out.dbcnt); out.dbcnt = out.dbsz; } if (out.dbcnt) dd_out(1); }