Mind Bending

Python Logo

In the last post I’ve shown how to enumerate all storage devices connected to your PC using Python and UDisks. In this post I’ll show how to work with DeviceKit Disks interface.

Fist lets read some documentations! The UDisks documentation is divided in five sections:

  • Disks interface;
  • Device interface;
  • Adapter interface;
  • Expander interface;
  • Port interface.

In this series of posts I’ll focus in the fist two sections, witch provide more information and therefore are the most useful. In this post I’ll focus in the Disks interface witch provides: information about the UDisks itself and methods to enumerate devices;

I’ve used some of the UDisks test suite to understand some of the functionalities.

First:
Check the UDisks daemon version;
Second:
Ensure if that the daemon isn’t inhibited during your application startup;
Third:
If your application is going to use LUKS, check if it is supported;
Fourth:
It is important to make sure that the file system that you will work with is supported by the daemon. Also, ensure the operation you want to run is supported on the file system.  It’s highly recommended to perform a check before some tasks like create a file system, mount, unmount and etc.

More information about the presented properties can be found here could be found in their old documentation.

>>> # Written by Magnun Leno. License: GPLv3
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>> proxy = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
>>> iface = dbus.Interface(proxy, "org.freedesktop.UDisks")
>>>
>>> print "Daemon Version",proxy.Get('org.freedesktop.UDisks', 'DaemonVersion')
Daemon Version 1.0.2
>>>
>>> print "Daemon is Inhibited",proxy.Get('org.freedesktop.UDisks', 'daemon-is-inhibited')
Daemon is Inhibited 0
>>>
>>> print "Support LUKS",proxy.Get('org.freedesktop.UDisks', 'supports-luks-devices')
Support LUKS 1
>>>
>>> formatting = '''id: %s;
... name: %s;
... supports_unix_owners: %s;
... can_mount: %s;
... can_create: %s;
... max_label_len: %s;
... supports_label_rename: %s;
... supports_online_label_rename: %s;
... supports_fsck: %s;
... supports_online_fsck: %s;
... supports_resize_enlarge: %s;
... supports_online_resize_enlarge: %s;
... supports_resize_shrink: %s;
... supports_online_resize_shrink: %s;n'''
>>>
>>>
>>> for fs_info in proxy.Get('', 'KnownFilesystems'):
...     print formatting%tuple(fs_info)
...
id: vfat;
name: FAT;
supports_unix_owners: 0;
can_mount: 1;
can_create: 1;
max_label_len: 254;
supports_label_rename: 1;
supports_online_label_rename: 0;
supports_fsck: 1;
supports_online_fsck: 0;
supports_resize_enlarge: 0;
supports_online_resize_enlarge: 0;
supports_resize_shrink: 0;
supports_online_resize_shrink: 0;

id: ext2;
name: Linux Ext2;
supports_unix_owners: 1;
can_mount: 1;
can_create: 1;
max_label_len: 16;
supports_label_rename: 1;
supports_online_label_rename: 1;
supports_fsck: 1;
supports_online_fsck: 0;
supports_resize_enlarge: 1;
supports_online_resize_enlarge: 1;
supports_resize_shrink: 1;
supports_online_resize_shrink: 1;

Part of this output is trunked. Currently, it’s supported 9 file sistems: FAT, Linux Ext2, Linux Ext3, Linux Ext4, XFS, ReiserFS, Minix, NTFS and Swap Space. A little detail: FAT includes FAT16 and FAT32.

In the next post we’ll take a look on how to enumerate an find devices.

Magnun

Magnun

Graduated in Telecommunication Engineering, but currently working with GNU/Linux infrastructure and in the spare time I'm an Open Source programmer (Python and C), a drawer and author in the Mind Bending Blog.


Comments

comments powered by Disqus