withBlockArray :: MonadIO m => RawDevice -> ByteAddr -> ByteAddr -> (ByteAddr -> STPrimArray RealWorld Pinned Word8 -> m a) -> m a
withBlockArray r@(RawDevice _ _ lgBlockBytes) seek len f = 
  let blockBytes = rawDeviceBlockBytes r
      seek' = getLen seek
      len' = getLen len
      start = (seek' `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
      end = ((seek' + len' + up (getLen blockBytes) - 1) `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
  in liftIO (stToIO $ newAlignedPinnedWord8Array blockBytes $ unsafeLen $ fromJust $ unapply super $ end - start) >>= 
     f (unsafeLen start)
withBlockArray :: MonadIO m => RawDevice -> ByteAddr -> ByteAddr -> (ByteAddr -> STPrimArray RealWorld Pinned Word8 -> m a) -> m a
withBlockArray r@(RawDevice _ _ lgBlockBytes) seek len f = 
  let blockBytes = rawDeviceBlockBytes r
      seek' = getLen seek
      len' = getLen len
      start = (seek' `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
      end = ((seek' + len' + up (getLen blockBytes) - 1) `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
  in liftIO (stToIO $ newAlignedPinnedWord8Array blockBytes $ unsafeLen $ fromJust $ unapply super $ end - start) >>= 
     f (unsafeLen start)
withBlockArray r@(RawDevice _ _ lgBlockBytes) seek len f = 
  let blockBytes = rawDeviceBlockBytes r
      seek' = getLen seek
      len' = getLen len
      start = (seek' `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
      end = ((seek' + len' + up (getLen blockBytes) - 1) `shiftR` lgBlockBytes) `shiftL` lgBlockBytes
  in liftIO (stToIO $ newAlignedPinnedWord8Array blockBytes $ unsafeLen $ fromJust $ unapply super $ end - start) >>= 
     f (unsafeLen start)