From: Rob Browning Date: Sat, 30 May 2015 16:18:13 +0000 (-0500) Subject: Add offset argument to fadvise_done X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=de7ccab9ea2b7fa0937ca1aea5d88d97b06893cd;p=packages%2Fb%2Fbup.git Add offset argument to fadvise_done ...and make it private for now. Thanks to Tilo Schwarz for pointing out that an earlier version ignored an offset of zero. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c index caa5c02..3ad7666 100644 --- a/lib/bup/_helpers.c +++ b/lib/bup/_helpers.c @@ -945,11 +945,18 @@ static PyObject *open_noatime(PyObject *self, PyObject *args) static PyObject *fadvise_done(PyObject *self, PyObject *args) { int fd = -1; - long long ofs = 0; - if (!PyArg_ParseTuple(args, "iL", &fd, &ofs)) + long long llofs, lllen = 0; + if (!PyArg_ParseTuple(args, "iLL", &fd, &llofs, &lllen)) return NULL; + off_t ofs, len; + if (!INTEGRAL_ASSIGNMENT_FITS(&ofs, llofs)) + return PyErr_Format(PyExc_OverflowError, + "fadvise offset overflows off_t"); + if (!INTEGRAL_ASSIGNMENT_FITS(&len, lllen)) + return PyErr_Format(PyExc_OverflowError, + "fadvise length overflows off_t"); #ifdef POSIX_FADV_DONTNEED - posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED); + posix_fadvise(fd, ofs, len, POSIX_FADV_DONTNEED); #endif return Py_BuildValue(""); } diff --git a/lib/bup/hashsplit.py b/lib/bup/hashsplit.py index 571ddf6..048347b 100644 --- a/lib/bup/hashsplit.py +++ b/lib/bup/hashsplit.py @@ -41,6 +41,13 @@ class Buf: return len(self.data) - self.start +def _fadvise_done(f, ofs, len): + assert(ofs >= 0) + assert(len >= 0) + if len > 0 and hasattr(f, 'fileno'): + _helpers.fadvise_done(f.fileno(), ofs, len) + + def readfile_iter(files, progress=None): for filenum,f in enumerate(files): ofs = 0 @@ -52,7 +59,7 @@ def readfile_iter(files, progress=None): ofs += len(b) # Warning: ofs == 0 means 'done with the whole file' # This will only happen here when the file is empty - fadvise_done(f, ofs) + _fadvise_done(f, 0, ofs) if not b: break yield b @@ -191,9 +198,3 @@ def open_noatime(name): except: pass raise - - -def fadvise_done(f, ofs): - assert(ofs >= 0) - if ofs > 0 and hasattr(f, 'fileno'): - _helpers.fadvise_done(f.fileno(), ofs)