Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / tt / mini_isam / issync.c
1 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
2 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
3 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
4 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
5 /*%%  $XConsortium: issync.c /main/3 1995/10/23 11:45:20 rswiston $                                                      */
6 #ifndef lint
7 static char sccsid[] = "@(#)issync.c 1.7 89/07/17 Copyr 1988 Sun Micro";
8 #endif
9 /*
10  * Copyright (c) 1988 by Sun Microsystems, Inc.
11  */
12
13 /*
14  * issync.c
15  *
16  * Description:
17  *      Sync all kernel buffers to the disk.
18  *
19  * Note: issync() flushes changed kernel buffers that are local to
20  *      the application that issued the call.
21  * 
22  * See sync(2) UNIX manual for what actually happens if sync() is called.
23  */
24
25 #include "isam_impl.h"
26 #include <sys/file.h>
27 #include <sys/time.h>
28
29 /*
30  * int  issync()
31  */
32
33 int 
34 issync()
35 {
36     return iscntl(ALLISFD, ISCNTL_FSYNC);
37 }
38
39 /*
40  * int  isfsync(fd)
41  */
42
43 int 
44 isfsync(isfd)
45     int         isfd;
46 {
47     return iscntl(isfd, ISCNTL_FSYNC);
48 }
49
50
51 _issync()
52 {
53     int         i;
54
55     for (i = 0; i < MAXISFD; i++)
56         (void)_isfsync(i);
57
58     return (ISOK);
59 }
60
61 _isfsync(isfd)
62     int         isfd;
63 {
64     register Fab        *fab;
65     Fcb                 *fcb;
66     int                 ret;
67
68     /*
69      * Get File Access Block.
70      */
71     if ((fab = _isfd_find(isfd)) == NULL) {
72         _setiserrno2(ENOTOPEN, '9', '0');
73         return (ISERROR);
74     }
75
76     /*
77      * Check that the open mode was ISINPUT, or ISINOUT.
78      */
79     if (fab->openmode != OM_INPUT && fab->openmode != OM_INOUT) {
80         _setiserrno2(ENOTOPEN, '9', '0');
81         return (ISERROR);
82     }
83
84     _isam_entryhook();
85
86     /*
87      * Get FCB corresponding to the isfhandle handle.
88      */
89     if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
90         _isam_exithook();
91         ret = ISERROR;
92     }
93     else {
94
95         if (fcb->datfd != -1)
96             (void)fsync(fcb->datfd);
97
98         if (fcb->indfd != -1)
99             (void)fsync(fcb->indfd);
100
101         if (fcb->varfd != -1)
102             (void)fsync(fcb->varfd);
103
104         _amseterrcode(&fab->errcode, ISOK);
105         _isam_exithook();
106         ret = ISOK;
107     }
108
109     _seterr_errcode(&fab->errcode);
110
111     return (ret);                            /* Successful write */
112 }