1fsync(3C)                Standard C Library Functions                fsync(3C)
2
3
4

NAME

6       fsync - synchronize changes to a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int fsync(int fildes);
12
13

DESCRIPTION

15       The fsync() function moves all modified data and attributes of the file
16       descriptor fildes to a storage device. When fsync()  returns,  all  in-
17       memory  modified  copies  of  buffers  associated with fildes have been
18       written to the physical medium. The fsync() function is different  from
19       sync(),  which schedules disk I/O for all files  but returns before the
20       I/O completes. The fsync() function forces all outstanding data  opera‐
21       tions  to  synchronized  file  integrity completion (see fcntl.h(3HEAD)
22       definition of O_SYNC.)
23
24
25       The fsync() function forces all currently queued I/O operations associ‐
26       ated  with the file indicated by the file descriptor fildes to the syn‐
27       chronized I/O completion state. All I/O  operations  are  completed  as
28       defined for synchronized I/O file integrity completion.
29

RETURN VALUES

31       Upon  successful  completion,  0 is returned. Otherwise, −1 is returned
32       and errno is set to indicate the error. If the fsync() function  fails,
33       outstanding I/O operations are not guaranteed to have been completed.
34

ERRORS

36       The fsync() function will fail if:
37
38       EBADF        The fildes argument is not a valid file descriptor.
39
40
41       EINTR        A  signal was caught during execution of the fsync() func‐
42                    tion.
43
44
45       EIO          An I/O error occurred while reading from or writing to the
46                    file system.
47
48
49       ENOSPC       There was no free space remaining on the device containing
50                    the file.
51
52
53       ETIMEDOUT    Remote connection timed out. This occurs when the file  is
54                    on  an  NFS file system mounted with the  soft option. See
55                    mount_nfs(1M).
56
57
58
59       In the event that any  of  the  queued  I/O  operations  fail,  fsync()
60       returns the error conditions defined for read(2) and write(2).
61

USAGE

63       The fsync() function should be used by applications that require that a
64       file be in a known state. For example, an application that  contains  a
65       simple  transaction  facility  might  use   fsync()  to ensure that all
66       changes to a file or files caused by a given transaction were  recorded
67       on a storage medium.
68
69
70       The  manner in which the data reach the physical medium depends on both
71       implementation and hardware.  The fsync() function returns  when  noti‐
72       fied by the device driver that the write has taken place.
73

ATTRIBUTES

75       See attributes(5) for descriptions of the following attributes:
76
77
78
79
80       ┌─────────────────────────────┬─────────────────────────────┐
81       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
82       ├─────────────────────────────┼─────────────────────────────┤
83       │Interface Stability          │Committed                    │
84       ├─────────────────────────────┼─────────────────────────────┤
85       │MT-Level                     │Async-Signal-Safe            │
86       ├─────────────────────────────┼─────────────────────────────┤
87       │Standard                     │See standards(5).            │
88       └─────────────────────────────┴─────────────────────────────┘
89

SEE ALSO

91       mount_nfs(1M),   read(2),  sync(2),  write(2),  fcntl.h(3HEAD),  fdata‐
92       sync(3C), attributes(5), standards(5)
93
94
95
96SunOS 5.11                        5 Feb 2008                         fsync(3C)
Impressum