os_fsync.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  */
  7. #include "db_config.h"
  8. #ifndef lint
  9. static const char revid[] = "$Id: os_fsync.c,v 11.9 2000/04/04 23:29:20 ubell Exp $";
  10. #endif /* not lint */
  11. #ifndef NO_SYSTEM_INCLUDES
  12. #include <sys/types.h>
  13. #include <fcntl.h> /* XXX: Required by __hp3000s900 */
  14. #include <unistd.h>
  15. #include <string.h>
  16. #endif
  17. #include "db_int.h"
  18. #include "os_jump.h"
  19. #ifdef HAVE_VXWORKS
  20. #include "ioLib.h"
  21. #define fsync(fd) __vx_fsync(fd);
  22. int
  23. __vx_fsync(fd)
  24. int fd;
  25. {
  26. int ret;
  27. /*
  28.  * The results of ioctl are driver dependent.  Some will return the
  29.  * number of bytes sync'ed.  Only if it returns 'ERROR' should we
  30.  * flag it.
  31.  */
  32. if ((ret = ioctl(fd, FIOSYNC, 0)) != ERROR)
  33. return (0);
  34. return (ret);
  35. }
  36. #endif
  37. #ifdef __hp3000s900
  38. #define fsync(fd) __mpe_fsync(fd);
  39. int
  40. __mpe_fsync(fd)
  41. int fd;
  42. {
  43. extern FCONTROL(short, short, void *);
  44. FCONTROL(_MPE_FILENO(fd), 2, NULL); /* Flush the buffers */
  45. FCONTROL(_MPE_FILENO(fd), 6, NULL); /* Write the EOF */
  46. return (0);
  47. }
  48. #endif
  49. /*
  50.  * __os_fsync --
  51.  * Flush a file descriptor.
  52.  *
  53.  * PUBLIC: int __os_fsync __P((DB_ENV *, DB_FH *));
  54.  */
  55. int
  56. __os_fsync(dbenv, fhp)
  57. DB_ENV *dbenv;
  58. DB_FH *fhp;
  59. {
  60. int ret;
  61. /*
  62.  * Do nothing if the file descriptor has been marked as not requiring
  63.  * any sync to disk.
  64.  */
  65. if (F_ISSET(fhp, DB_FH_NOSYNC))
  66. return (0);
  67. ret = __db_jump.j_fsync != NULL ?
  68.     __db_jump.j_fsync(fhp->fd) : fsync(fhp->fd);
  69. if (ret != 0) {
  70. ret = __os_get_errno();
  71. __db_err(dbenv, "fsync %s", strerror(ret));
  72. }
  73. return (ret);
  74. }