c8ee09d9971f7484264f89e07ad3eded891e4936
[oweals/cde.git] / cde / lib / tt / mini_isam / issync.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: issync.c /main/3 1995/10/23 11:45:20 rswiston $                                                      */
28 #ifndef lint
29 static char sccsid[] = "@(#)issync.c 1.7 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * issync.c
37  *
38  * Description:
39  *      Sync all kernel buffers to the disk.
40  *
41  * Note: issync() flushes changed kernel buffers that are local to
42  *      the application that issued the call.
43  * 
44  * See sync(2) UNIX manual for what actually happens if sync() is called.
45  */
46
47 #include "isam_impl.h"
48 #include <sys/file.h>
49 #include <sys/time.h>
50
51 /*
52  * int  issync()
53  */
54
55 int 
56 issync(void)
57 {
58     return iscntl(ALLISFD, ISCNTL_FSYNC);
59 }
60
61 /*
62  * int  isfsync(fd)
63  */
64
65 int 
66 isfsync(int isfd)
67 {
68     return iscntl(isfd, ISCNTL_FSYNC);
69 }
70
71
72 int _issync(void)
73 {
74     int         i;
75
76     for (i = 0; i < MAXISFD; i++)
77         (void)_isfsync(i);
78
79     return (ISOK);
80 }
81
82 int _isfsync(int isfd)
83 {
84     Fab *fab;
85     Fcb                 *fcb;
86     int                 ret;
87
88     /*
89      * Get File Access Block.
90      */
91     if ((fab = _isfd_find(isfd)) == NULL) {
92         _setiserrno2(ENOTOPEN, '9', '0');
93         return (ISERROR);
94     }
95
96     /*
97      * Check that the open mode was ISINPUT, or ISINOUT.
98      */
99     if (fab->openmode != OM_INPUT && fab->openmode != OM_INOUT) {
100         _setiserrno2(ENOTOPEN, '9', '0');
101         return (ISERROR);
102     }
103
104     _isam_entryhook();
105
106     /*
107      * Get FCB corresponding to the isfhandle handle.
108      */
109     if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
110         _isam_exithook();
111         ret = ISERROR;
112     }
113     else {
114
115         if (fcb->datfd != -1)
116             (void)fsync(fcb->datfd);
117
118         if (fcb->indfd != -1)
119             (void)fsync(fcb->indfd);
120
121         if (fcb->varfd != -1)
122             (void)fsync(fcb->varfd);
123
124         _amseterrcode(&fab->errcode, ISOK);
125         _isam_exithook();
126         ret = ISOK;
127     }
128
129     _seterr_errcode(&fab->errcode);
130
131     return (ret);                            /* Successful write */
132 }