Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 17
Updating File State Information
The preceding example is changed to reflect the use of synchronization information:
Execution ----->...Update control and application state
resumes here ...Update sync block...
err = POSITION (F1, -1D); /*position to
eof*/
err = WRITE (F1, buf);
***Primary fails here***
Restart point
...Backup takes over...
...Receive sync information
err = POSITION (F1, -1D); /*position to
eof*/
err = WRITE (F1, buf);/*System detects
that*/
/*operation has*/
/*already been*/
/*performed and*/
/*returns
completion*/
/*status*/
In this case, the write by the primary process completed successfully. On the second
pass, the backup process receives a saved copy of the response made to the primary
process before it failed.
See below for more information on buffered file operations.
Updating File State for Buffered File Operations
File operations can be buffered; however, the buffer is not part of the file state. This
affects input and output streams differently.
For an input stream, the file position is a component of the file state. The call to
__ns_fset_file_state updates the file position for the backup process to the file
position of the primary process at the time __ns_fget_file_state was called.
Thus, buffering is not a problem for a disk-based input stream. However, buffered but
unread input from a nondisk device will be lost. Buffering can be disabled by calling
the setvbuf or setnbuf function.
Note. When buffered file operations are used, a call to a write function in your program does
not necessarily correspond to exactly one write operation at the operating-system level, where
the sync-depth value applies. An operating-system write operation is performed only in the
following situations:
A flush operation is performed (for example, fflush, fclose, or exit is called).
The buffer is filled (buffer sizes are documented in the C/C++ Programmer’s Guide).