Python interface

While imount heavily utilizes the Python API of imagemounter, this API is also available for other classes.

Data structure

The basic structure of imagemounter is the imagemounter.ImageParser class, which provides access to underlying imagemounter.Disk and imagemounter.Volume objects. Each file name passed to a new imagemounter.ImageParser object results in one imagemounter.Disk object. imagemounter.Volume objects are created by analysis of the Disk object (each volume generates one object, even if it is not mountable), and each imagemounter.Volume can have one or more subvolumes.

For instance, a LUKS volume may contain a LVM system that contains a Ext volume. This would create a Disk with a Volume containing a Volume which contains the actual Ext Volume. Subvolumes are managed through imagemounter.VolumeSystem`s, which is used by both the :class:`Volume and Disk classes.

Most operations are managed on a Volume level, although individual disk file mounting (and volume detection) is performed on a Disk level and reconstruction is performed on a ImageParser level. This means the following main parts make up the Python package:

  • imagemounter.ImageParser, maintaining a list of Disks, providing several methods that are carried out on all disks (e.g. mount) and reconstruct.
  • imagemounter.Disk, which represents a single disk iamge and can be mounted, and maintain volumes. It is also responsible for maintaining the write cache. Although a Disk is able to detect volumes, a Volume has similar capabilities.
  • imagemounter.Volume, which can detect its own type and fill its stats, can be mounted, and maintain subvolumes.
  • imagemounter.VolumeSystem, which is used to manage subvolumes and can detect volumes from a volume system.

All three classes maintain an init() method that yields the volumes below it. You should call clean() on the parser as soon as you are done; you may also call unmount() on separate volumes or disks, which will also unmount all volumes below it. Warning: unmounting one of the RAID volumes in a RAID array, causes the entire array to be unmounted.

Reference

If you utilize the API, you typically only require the ImageParser object, e.g.:

parser = ImageParser(['/path/to/disk'])
for v in parser.init():
    print v.size
root = parser.reconstruct()
print root.mountpoint
parser.clean()

The best example of the use of the Python interface is the imount command. The entirety of all methods and attributes is documented below.

ImageParser

Disk

Volume

VolumeSystem

Unmounter