diff options
author | Jeremy Katz <katzj@redhat.com> | 2005-04-27 19:16:32 +0000 |
---|---|---|
committer | Jeremy Katz <katzj@redhat.com> | 2005-04-27 19:16:32 +0000 |
commit | 1d49dcb4af158993f15eebf7f57e79b4f7414c6c (patch) | |
tree | cbe77eb9e87ea1ddf151de584358a5d1c734138d /isys | |
parent | ef4500f90907c5de5f73c8c840854f92aaca52c2 (diff) | |
download | anaconda-1d49dcb4af158993f15eebf7f57e79b4f7414c6c.tar.gz anaconda-1d49dcb4af158993f15eebf7f57e79b4f7414c6c.tar.xz anaconda-1d49dcb4af158993f15eebf7f57e79b4f7414c6c.zip |
2005-04-27 Jeremy Katz <katzj@redhat.com>
* isys/isys.c (doDevSpaceFree): Apply Jindrich Novy's patch to fix
space calculation on > 2 TB devices (#155709)
Diffstat (limited to 'isys')
-rw-r--r-- | isys/isys.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/isys/isys.c b/isys/isys.c index 1d8f5def3..ec0d4f818 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -881,9 +881,23 @@ static PyObject * doGetRaidChunkSize(PyObject * s, PyObject * args) { return Py_BuildValue("i", sb.chunk_size / 1024); } +static int get_bits(unsigned long long v) { + int b = 0; + + if ( v & 0xffffffff00000000LLU ) { b += 32; v >>= 32; } + if ( v & 0xffff0000LLU ) { b += 16; v >>= 16; } + if ( v & 0xff00LLU ) { b += 8; v >>= 8; } + if ( v & 0xf0LLU ) { b += 4; v >>= 4; } + if ( v & 0xcLLU ) { b += 2; v >>= 2; } + if ( v & 0x2LLU ) b++; + + return v ? b + 1 : b; +} + static PyObject * doDevSpaceFree(PyObject * s, PyObject * args) { char * path; struct statfs sb; + unsigned long long size; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; @@ -892,7 +906,13 @@ static PyObject * doDevSpaceFree(PyObject * s, PyObject * args) { return NULL; } - return Py_BuildValue("l", (long) sb.f_bfree * (sb.f_bsize / 1024) / (1024)); + /* Calculate a saturated addition to prevent oveflow. */ + if ( get_bits(sb.f_bfree) + get_bits(sb.f_bsize) <= 64 ) + size = (unsigned long long)sb.f_bfree * sb.f_bsize; + else + size = ~0LLU; + + return PyLong_FromUnsignedLongLong(size>>20); } static PyObject * doRaidStop(PyObject * s, PyObject * args) { |