Skip to content

Commit

Permalink
port zfs send -R
Browse files Browse the repository at this point in the history
use WriteFile instead of write in libzfs_sendrecv.c
  • Loading branch information
jheuking committed Mar 5, 2019
1 parent d07aab9 commit 25f8a67
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,27 @@ dump_record(dmu_replay_record_t *drr, void *payload, int payload_len,
}
(void) fletcher_4_incremental_native(
&drr->drr_u.drr_checksum.drr_checksum, sizeof (zio_cksum_t), zc);

#ifdef WIN32
DWORD byteswritten = 0;
if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) {
return (GetLastError());
}
#else
if (write(outfd, drr, sizeof (*drr)) == -1)
return (errno);
#endif
if (payload_len != 0) {
(void) fletcher_4_incremental_native(payload, payload_len, zc);
#ifdef WIN32
byteswritten = 0;
if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) {
return (GetLastError());
}
#else
if (write(outfd, payload, payload_len) == -1)
return (errno);
#endif
}
return (0);
}
Expand Down Expand Up @@ -1423,7 +1438,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
}

err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj,
fromorigin, sdd->outfd, flags, sdd->debugnv);
fromorigin, sdd->outfd, flags, sdd->debugnv);

if (sdd->progress) {
(void) pthread_cancel(tid);
Expand Down Expand Up @@ -1987,11 +2002,19 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
bzero(&drr, sizeof (drr));
drr.drr_type = DRR_END;
drr.drr_u.drr_end.drr_checksum = zc;
#ifdef WIN32
DWORD byteswritten;
if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) {
err = GetLastError();
goto stderr_out;
}
#else
err = write(outfd, &drr, sizeof (drr));
if (err == -1) {
err = errno;
goto stderr_out;
}
#endif

err = 0;
}
Expand Down Expand Up @@ -2135,10 +2158,18 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
*/
dmu_replay_record_t drr = { 0 };
drr.drr_type = DRR_END;
#ifdef WIN32
DWORD byteswritten = 0;
if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) {
return (zfs_standard_error(zhp->zfs_hdl,
GetLastError(), errbuf));
}
#else
if (write(outfd, &drr, sizeof (drr)) == -1) {
return (zfs_standard_error(zhp->zfs_hdl,
errno, errbuf));
}
#endif
}

return (err || sdd.err);
Expand Down

0 comments on commit 25f8a67

Please sign in to comment.