| <html lang="en"> |
| <head> |
| <title>Data consistency and durability - The GNU Fortran Compiler</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="The GNU Fortran Compiler"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Compiler-Characteristics.html#Compiler-Characteristics" title="Compiler Characteristics"> |
| <link rel="prev" href="Thread_002dsafety-of-the-runtime-library.html#Thread_002dsafety-of-the-runtime-library" title="Thread-safety of the runtime library"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1999-2013 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Funding Free Software'', the Front-Cover |
| Texts being (a) (see below), and with the Back-Cover Texts being (b) |
| (see below). A copy of the license is included in the section entitled |
| ``GNU Free Documentation License''. |
| |
| (a) The FSF's Front-Cover Text is: |
| |
| A GNU Manual |
| |
| (b) The FSF's Back-Cover Text is: |
| |
| You have freedom to copy and modify this GNU Manual, like GNU |
| software. Copies published by the Free Software Foundation raise |
| funds for GNU development.--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Data-consistency-and-durability"></a> |
| <p> |
| Previous: <a rel="previous" accesskey="p" href="Thread_002dsafety-of-the-runtime-library.html#Thread_002dsafety-of-the-runtime-library">Thread-safety of the runtime library</a>, |
| Up: <a rel="up" accesskey="u" href="Compiler-Characteristics.html#Compiler-Characteristics">Compiler Characteristics</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">5.4 Data consistency and durability</h3> |
| |
| <p><a name="index-consistency_002c-durability-328"></a> |
| This section contains a brief overview of data and metadata |
| consistency and durability issues when doing I/O. |
| |
| <p>With respect to durability, GNU Fortran makes no effort to ensure that |
| data is committed to stable storage. If this is required, the GNU |
| Fortran programmer can use the intrinsic <code>FNUM</code> to retrieve the |
| low level file descriptor corresponding to an open Fortran unit. Then, |
| using e.g. the <code>ISO_C_BINDING</code> feature, one can call the |
| underlying system call to flush dirty data to stable storage, such as |
| <code>fsync</code> on POSIX, <code>_commit</code> on MingW, or <code>fcntl(fd, |
| F_FULLSYNC, 0)</code> on Mac OS X. The following example shows how to call |
| fsync: |
| |
| <pre class="smallexample"> ! Declare the interface for POSIX fsync function |
| interface |
| function fsync (fd) bind(c,name="fsync") |
| use iso_c_binding, only: c_int |
| integer(c_int), value :: fd |
| integer(c_int) :: fsync |
| end function fsync |
| end interface |
| |
| ! Variable declaration |
| integer :: ret |
| |
| ! Opening unit 10 |
| open (10,file="foo") |
| |
| ! ... |
| ! Perform I/O on unit 10 |
| ! ... |
| |
| ! Flush and sync |
| flush(10) |
| ret = fsync(fnum(10)) |
| |
| ! Handle possible error |
| if (ret /= 0) stop "Error calling FSYNC" |
| </pre> |
| <p>With respect to consistency, for regular files GNU Fortran uses |
| buffered I/O in order to improve performance. This buffer is flushed |
| automatically when full and in some other situations, e.g. when |
| closing a unit. It can also be explicitly flushed with the |
| <code>FLUSH</code> statement. Also, the buffering can be turned off with the |
| <code>GFORTRAN_UNBUFFERED_ALL</code> and |
| <code>GFORTRAN_UNBUFFERED_PRECONNECTED</code> environment variables. Special |
| files, such as terminals and pipes, are always unbuffered. Sometimes, |
| however, further things may need to be done in order to allow other |
| processes to see data that GNU Fortran has written, as follows. |
| |
| <p>The Windows platform supports a relaxed metadata consistency model, |
| where file metadata is written to the directory lazily. This means |
| that, for instance, the <code>dir</code> command can show a stale size for a |
| file. One can force a directory metadata update by closing the unit, |
| or by calling <code>_commit</code> on the file descriptor. Note, though, |
| that <code>_commit</code> will force all dirty data to stable storage, which |
| is often a very slow operation. |
| |
| <p>The Network File System (NFS) implements a relaxed consistency model |
| called open-to-close consistency. Closing a file forces dirty data and |
| metadata to be flushed to the server, and opening a file forces the |
| client to contact the server in order to revalidate cached |
| data. <code>fsync</code> will also force a flush of dirty data and metadata |
| to the server. Similar to <code>open</code> and <code>close</code>, acquiring and |
| releasing <code>fcntl</code> file locks, if the server supports them, will |
| also force cache validation and flushing dirty data and metadata. |
| |
| <!-- --> |
| <!-- Extensions --> |
| <!-- --> |
| <!-- Maybe this chapter should be merged with the 'Standards' section, --> |
| <!-- whenever that is written :-) --> |
| </body></html> |
| |