Lots of improvements

- use Ctypes instead of hand-written stubs
- add unit tests (using losetup to create temporary devices)
- improve and document the API