WriteFile and partial writes

noname 141 Reputation points
2021-10-03T12:55:09.027+00:00

Is it possible for WriteFile() to perform a partial write? Let's say we want to write 100 bytes to a file and only 50 bytes can be written (for example, the disk is full). Would WriteFile() return success and *lpNumberOfBytesWritten would be 50? Would WriteFile() return error and *lpNumberOfBytesWritten would be 50?

When using asynchronous I/O (opening the file with FILE_FLAG_OVERLAPPED and passing a pointer to an overlapped struct in WriteFile()): can the data be partially written to disk (for example, 50 bytes can be immediately written to the file but not the remainder 50 bytes)? would WriteFile() return success and *lpNumberOfBytesWritten would be 50? would WriteFile() return error (ERROR_IO_PENDING) and *lpNumberOfBytesWritten would be 50?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points
    2021-10-03T16:17:51.24+00:00

    Whether using synchronous or asynchronous I/O if a call to WriteFile is unable to write the number of bytes specified because the disk is full then the write fails, 0 bytes are reported as written, and the last error code is set to 112 (There is not enough space on the disk).

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful