]> arthur.barton.de Git - bup.git/commitdiff
Add offset argument to fadvise_done
authorRob Browning <rlb@defaultvalue.org>
Sat, 30 May 2015 16:18:13 +0000 (11:18 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 20 Jun 2015 15:24:26 +0000 (10:24 -0500)
...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 <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c
lib/bup/hashsplit.py

index caa5c021c183d2a98f5d8f74e4fe2e44f71d4ec7..3ad766667b8d5d6b55fcde9c0000cc0ae12c42d6 100644 (file)
@@ -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("");
 }
index 571ddf6434ac1723c1948ffc5c4ba6f59843a72c..048347b2fdd312be787c7cfd3dbf7d6eb9820446 100644 (file)
@@ -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)