Index: Doc/library/os.rst =================================================================== --- Doc/library/os.rst (revision 65574) +++ Doc/library/os.rst (working copy) @@ -577,7 +577,19 @@ Truncate the file corresponding to file descriptor *fd*, so that it is at most *length* bytes in size. Availability: Macintosh, Unix. +.. function:: fullfsync(fd) + Force disks to write file with filedescriptor *fd* to the actual physical media. + + Although :func:`fsync` flushes the operating system's file buffer to the storage device, + unsaved data may be waiting in the hardware write buffers on the storage device itself. + Certain operating systems (so far, only OS X) provide ``fullfsync`` to request that + the storage device flush its write buffer. + + If you're starting with a Python file object *f*, first do ``f.flush()``, then + ``os.fsync(f.fileno())``, and finally ``os.fullfsync(f.fileno())``, to ensure that + file *f* is completely saved to the storage media. Availability: OS X starting in 2.6. + .. function:: isatty(fd) Return ``True`` if the file descriptor *fd* is open and connected to a Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 65574) +++ Modules/posixmodule.c (working copy) @@ -1853,6 +1853,29 @@ } #endif /* HAVE_FSYNC */ +#ifdef F_FULLFSYNC +PyDoc_STRVAR(posix_fullfsync__doc__, +"fullfsync(fildes)\n\n\ +force storage device to write file with filedescriptor to the final physical media."); + +static PyObject * +posix_fullfsync(PyObject *self, PyObject *fdobj) +{ + int res; + int fd; + fd = PyObject_AsFileDescriptor(fdobj); + if (fd < 0) + return NULL; + Py_BEGIN_ALLOW_THREADS + res = fcntl(fd, F_FULLFSYNC, 0); + Py_END_ALLOW_THREADS + if (res < 0) + return posix_error(); + Py_INCREF(Py_None); + return Py_None; +} +#endif /* F_FULLFSYNC */ + #ifdef HAVE_FDATASYNC #ifdef __hpux @@ -8538,6 +8561,9 @@ #ifdef HAVE_FSYNC {"fsync", posix_fsync, METH_O, posix_fsync__doc__}, #endif +#ifdef F_FULLFSYNC + {"fullfsync", posix_fullfsync, METH_O, posix_fullfsync__doc__}, +#endif #ifdef HAVE_FDATASYNC {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__}, #endif