diff --git a/contrib/win32/openssh/install-sshd.ps1 b/contrib/win32/openssh/install-sshd.ps1 index 4fad07ab9..cd02164dd 100644 --- a/contrib/win32/openssh/install-sshd.ps1 +++ b/contrib/win32/openssh/install-sshd.ps1 @@ -81,7 +81,7 @@ if (Test-Path $sshAgentRegPath) $moduliPath = Join-Path $PSScriptRoot "moduli" if (Test-Path $moduliPath -PathType Leaf) { - Repair-ModuliFilePermission -FilePath $moduliPath @psBoundParameters + Repair-ModuliFilePermission -FilePath $moduliPath @psBoundParameters -confirm:$false } #register etw provider diff --git a/contrib/win32/win32compat/fileio.c b/contrib/win32/win32compat/fileio.c index e165564d8..cb918ef2d 100644 --- a/contrib/win32/win32compat/fileio.c +++ b/contrib/win32/win32compat/fileio.c @@ -673,6 +673,37 @@ WriteCompletionRoutine(_In_ DWORD dwErrorCode, *((__int64*)&lpOverlapped->Offset) += dwNumberOfBytesTransfered; } +int +fileio_write_wrapper(struct w32_io* pio, const void* buf, size_t bytes_to_copy) +{ + int bytes_written = 0; + if (bytes_to_copy <= WRITE_BUFFER_SIZE) { + bytes_written = fileio_write(pio, buf, bytes_to_copy); + return bytes_written; + } + + void* chunk_buf = NULL; + int chunk_count = 0; + int bytes_copied = -1; + int chunk_size = 0; + + for (int i = 0; i < bytes_to_copy; i += WRITE_BUFFER_SIZE, chunk_count++) { + chunk_buf = (BYTE*)buf + chunk_count * WRITE_BUFFER_SIZE; + chunk_size = ((bytes_to_copy - i) >= WRITE_BUFFER_SIZE) ? WRITE_BUFFER_SIZE : (bytes_to_copy - i); + bytes_written = fileio_write(pio, chunk_buf, chunk_size); + + if (bytes_written == -1) + return bytes_copied; + + if (bytes_copied == -1) + bytes_copied = 0; + + bytes_copied += bytes_written; + } + return bytes_copied; + +} + /* write() implementation */ int fileio_write(struct w32_io* pio, const void *buf, size_t max_bytes) diff --git a/contrib/win32/win32compat/w32fd.c b/contrib/win32/win32compat/w32fd.c index dace55258..9e87d929a 100644 --- a/contrib/win32/win32compat/w32fd.c +++ b/contrib/win32/win32compat/w32fd.c @@ -558,7 +558,7 @@ w32_write(int fd, const void *buf, size_t max) if (fd_table.w32_ios[fd]->type == SOCK_FD) return socketio_send(fd_table.w32_ios[fd], buf, max, 0); - return fileio_write(fd_table.w32_ios[fd], buf, max); + return fileio_write_wrapper(fd_table.w32_ios[fd], buf, max); } int diff --git a/contrib/win32/win32compat/w32fd.h b/contrib/win32/win32compat/w32fd.h index 67e5c3dac..0f1ee3a08 100644 --- a/contrib/win32/win32compat/w32fd.h +++ b/contrib/win32/win32compat/w32fd.h @@ -158,6 +158,7 @@ struct w32_io* fileio_afunix_socket(); int fileio_connect(struct w32_io*, char*); struct w32_io* fileio_open(const char *pathname, int flags, mode_t mode); int fileio_read(struct w32_io* pio, void *dst, size_t max); +int fileio_write_wrapper(struct w32_io* pio, const void* buf, size_t bytes_to_copy); int fileio_write(struct w32_io* pio, const void *buf, size_t max); int fileio_fstat(struct w32_io* pio, struct _stat64 *buf); int fileio_stat(const char *path, struct _stat64 *buf);