Jump to content

mmioFlush

From EDM2

The mmioFlush function writes the contents of an I/O buffer to the physical disk if the buffer has been modified. It can also be used to empty the buffer without deallocating it.

Syntax

#define INCL_MMIOOS2
#include <os2.h>

USHORT mmioFlush(HMMIO hmmio, USHORT usFlags);

Parameters

hmmio (HMMIO) - input
The open file handle returned by mmioOpen.
usFlags (USHORT) - input
Specifies the behavior of the flush operation:
  • 0: Writes the buffer to disk if it is "dirty" (has been written into).
  • MMIO_EMPTYBUF: Empties the I/O buffer. While the buffer remains allocated, the `pchNext` field in the MMIOINFO structure is set to point to `pchEndRead`, effectively marking it as empty.

Return Values

rc (USHORT)
Returns a code indicating the result:
  • MMIO_SUCCESS: The function succeeded (0).
  • MMIOERR_INVALID_HANDLE: The file handle is not valid.
  • MMIOERR_CANNOTWRITE: The buffer could not be written (e.g., disk full).
  • MMIOERR_WRITE_FAILED: A hardware error occurred during the write process.
  • MMIOERR_NO_BUFFER_ALLOCATED: No buffer is associated with this handle.
  • MMIOERR_NO_FLUSH_NEEDED: The buffer was already empty or not modified.
  • MMIOERR_NO_FLUSH_FOR_MEM_FILE: Flushing is not supported for memory (MEM) files.

Remarks

This function is only applicable to file handles set up for buffered I/O. If you have written data using mmioWrite or by directly manipulating the buffer after a call to mmioGetInfo, mmioFlush ensures those changes are committed to the storage medium.

It is important to note that a successful call to `mmioWrite` does not guarantee the data is on the disk; it may only reside in the memory buffer. Therefore, `mmioFlush` might return an error (like disk full) even if previous write operations appeared successful.

Example Code

The following example demonstrates how to ensure all buffered data is written to the disk:

   HMMIO  hmmio1;
   USHORT rc;

   /* ... perform buffered writes ... */

   /* Force the buffer to be written to disk */
   rc = mmioFlush(hmmio1, 0);

   if (rc != MMIO_SUCCESS) {
      if (rc == MMIOERR_CANNOTWRITE) {
         /* Handle disk full error */
      } else {
         /* Handle other errors */
      }
   }

Related Functions