00001 00004 /* Copyright (C) 2006,2007,2008,2009 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef XAPIAN_INCLUDED_FLINT_IO_H 00022 #define XAPIAN_INCLUDED_FLINT_IO_H 00023 00024 #include <sys/types.h> 00025 #include "safefcntl.h" 00026 #include "safeunistd.h" 00027 00033 inline bool flint_io_sync(int fd) 00034 { 00035 #ifdef F_FULLFSYNC 00036 /* Only supported on Mac OS X (at the time of writing at least). 00037 * 00038 * This call ensures that data has actually been written to disk, not just 00039 * to the drive's write cache, so it provides better protection from power 00040 * failures, etc. It does take longer though. 00041 * 00042 * According to the sqlite sources, this shouldn't fail on a local FS so 00043 * a failure means that the file system doesn't support this operation and 00044 * therefore it's best to fallback to fdatasync()/fsync(). 00045 */ 00046 if (fcntl(fd, F_FULLFSYNC, 0) == 0) 00047 return true; 00048 #endif 00049 00050 #if defined HAVE_FDATASYNC 00051 // If we have it, prefer fdatasync() over fsync() as the former avoids 00052 // updating the access time so is probably a little more efficient. 00053 return fdatasync(fd) == 0; 00054 #elif defined HAVE_FSYNC 00055 return fsync(fd) == 0; 00056 #elif defined __WIN32__ 00057 return _commit(fd) == 0; 00058 #else 00059 # error Cannot implement flint_io_sync() without fdatasync(), fsync(), or _commit() 00060 #endif 00061 } 00062 00070 size_t flint_io_read(int fd, char * p, size_t n, size_t min); 00071 00073 void flint_io_write(int fd, const char * p, size_t n); 00074 00075 #endif