-- |Get the read write rates from the disk (in bytes/s)
getDiskReadWrite :: DiskHandle -> IO (Int, Int)
getDiskReadWrite (DiskH _ fs readrefs writerefs timeref) = do
  contents <- mapM readValues fs
  time <- getPOSIXTime
  let nreads = map (\c -> (c !! 2) * sectorSize) contents
  let writes = map (\c -> (c !! 6) * sectorSize) contents
  oreads <- mapM readIORef readrefs
  owrites <- mapM readIORef writerefs
  otime <- readIORef timeref
  let creads = zipWith (-) nreads oreads
  let cwrites = zipWith (-) writes owrites
  let ctime = time - otime
  _ <- sequence $zipWith writeIORef readrefs nreads
  _ <- sequence $zipWith writeIORef writerefs writes
  writeIORef timeref time
  return (sum $map (`sdivBound` round ctime) creads, sum $map (`sdivBound` round ctime) cwrites)


-- |Get the space left on the disk
getDiskReadWrite :: DiskHandle -> IO (Int, Int)
getDiskReadWrite (DiskH _ fs readrefs writerefs timeref) = do
  contents <- mapM readValues fs
  time <- getPOSIXTime
  let nreads = map (\c -> (c !! 2) * sectorSize) contents
  let writes = map (\c -> (c !! 6) * sectorSize) contents
  oreads <- mapM readIORef readrefs
  owrites <- mapM readIORef writerefs
  otime <- readIORef timeref
  let creads = zipWith (-) nreads oreads
  let cwrites = zipWith (-) writes owrites
  let ctime = time - otime
  _ <- sequence $zipWith writeIORef readrefs nreads
  _ <- sequence $zipWith writeIORef writerefs writes
  writeIORef timeref time
  return (sum $map (`sdivBound` round ctime) creads, sum $map (`sdivBound` round ctime) cwrites)


-- |Get the space left on the disk
getDiskReadWrite (DiskH _ fs readrefs writerefs timeref) = do
  contents <- mapM readValues fs
  time <- getPOSIXTime
  let nreads = map (\c -> (c !! 2) * sectorSize) contents
  let writes = map (\c -> (c !! 6) * sectorSize) contents
  oreads <- mapM readIORef readrefs
  owrites <- mapM readIORef writerefs
  otime <- readIORef timeref
  let creads = zipWith (-) nreads oreads
  let cwrites = zipWith (-) writes owrites
  let ctime = time - otime
  _ <- sequence $zipWith writeIORef readrefs nreads
  _ <- sequence $zipWith writeIORef writerefs writes
  writeIORef timeref time
  return (sum $map (`sdivBound` round ctime) creads, sum $map (`sdivBound` round ctime) cwrites)


-- |Get the space left on the disk