Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_fsync.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_fsync.c,v 12.3 2005/09/07 17:30:20 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <fcntl.h>                      /* Required on some platforms. */
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 
00021 #ifdef  HAVE_VXWORKS
00022 #include "ioLib.h"
00023 
00024 #define fsync(fd)       __vx_fsync(fd)
00025 
00026 int
00027 __vx_fsync(fd)
00028         int fd;
00029 {
00030         int ret;
00031 
00032         /*
00033          * The results of ioctl are driver dependent.  Some will return the
00034          * number of bytes sync'ed.  Only if it returns 'ERROR' should we
00035          * flag it.
00036          */
00037         if ((ret = ioctl(fd, FIOSYNC, 0)) != ERROR)
00038                 return (0);
00039         return (ret);
00040 }
00041 #endif
00042 
00043 #ifdef __hp3000s900
00044 #define fsync(fd)       __mpe_fsync(fd)
00045 
00046 int
00047 __mpe_fsync(fd)
00048         int fd;
00049 {
00050         extern FCONTROL(short, short, void *);
00051 
00052         FCONTROL(_MPE_FILENO(fd), 2, NULL);     /* Flush the buffers */
00053         FCONTROL(_MPE_FILENO(fd), 6, NULL);     /* Write the EOF */
00054         return (0);
00055 }
00056 #endif
00057 
00058 /*
00059  * __os_fsync --
00060  *      Flush a file descriptor.
00061  *
00062  * PUBLIC: int __os_fsync __P((DB_ENV *, DB_FH *));
00063  */
00064 int
00065 __os_fsync(dbenv, fhp)
00066         DB_ENV *dbenv;
00067         DB_FH *fhp;
00068 {
00069         int ret;
00070 
00071         /* Check for illegal usage. */
00072         DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
00073 
00074         /*
00075          * Do nothing if the file descriptor has been marked as not requiring
00076          * any sync to disk.
00077          */
00078         if (F_ISSET(fhp, DB_FH_NOSYNC))
00079                 return (0);
00080 
00081         if (DB_GLOBAL(j_fsync) != NULL)
00082                 ret = DB_GLOBAL(j_fsync)(fhp->fd);
00083         else
00084 #if defined(F_FULLFSYNC)
00085                 RETRY_CHK((fcntl(fhp->fd, F_FULLFSYNC, 0)), ret);
00086 #elif defined(HAVE_FDATASYNC)
00087                 RETRY_CHK((fdatasync(fhp->fd)), ret);
00088 #else
00089                 RETRY_CHK((fsync(fhp->fd)), ret);
00090 #endif
00091 
00092         if (ret != 0)
00093                 __db_err(dbenv, "fsync %s", strerror(ret));
00094         return (ret);
00095 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2