issync.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * issync.c
  33. *
  34. * Description:
  35. * Sync all kernel buffers to the disk.
  36. *
  37. * Note: issync() flushes changed kernel buffers that are local to
  38. * the application that issued the call.
  39. *
  40. * See sync(2) UNIX manual for what actually happens if sync() is called.
  41. */
  42. #include "isam_impl.h"
  43. #include <unistd.h>
  44. #include <sys/file.h>
  45. #include <sys/time.h>
  46. /*
  47. * int issync()
  48. */
  49. int
  50. issync(void)
  51. {
  52. return iscntl(ALLISFD, ISCNTL_FSYNC);
  53. }
  54. /*
  55. * int isfsync(fd)
  56. */
  57. int
  58. isfsync(int isfd)
  59. {
  60. return iscntl(isfd, ISCNTL_FSYNC);
  61. }
  62. int _issync(void)
  63. {
  64. int i;
  65. for (i = 0; i < MAXISFD; i++)
  66. (void)_isfsync(i);
  67. return (ISOK);
  68. }
  69. int _isfsync(int isfd)
  70. {
  71. Fab *fab;
  72. Fcb *fcb;
  73. int ret;
  74. /*
  75. * Get File Access Block.
  76. */
  77. if ((fab = _isfd_find(isfd)) == NULL) {
  78. _setiserrno2(ENOTOPEN, '9', '0');
  79. return (ISERROR);
  80. }
  81. /*
  82. * Check that the open mode was ISINPUT, or ISINOUT.
  83. */
  84. if (fab->openmode != OM_INPUT && fab->openmode != OM_INOUT) {
  85. _setiserrno2(ENOTOPEN, '9', '0');
  86. return (ISERROR);
  87. }
  88. _isam_entryhook();
  89. /*
  90. * Get FCB corresponding to the isfhandle handle.
  91. */
  92. if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
  93. _isam_exithook();
  94. ret = ISERROR;
  95. }
  96. else {
  97. if (fcb->datfd != -1)
  98. (void)fsync(fcb->datfd);
  99. if (fcb->indfd != -1)
  100. (void)fsync(fcb->indfd);
  101. if (fcb->varfd != -1)
  102. (void)fsync(fcb->varfd);
  103. _amseterrcode(&fab->errcode, ISOK);
  104. _isam_exithook();
  105. ret = ISOK;
  106. }
  107. _seterr_errcode(&fab->errcode);
  108. return (ret); /* Successful write */
  109. }