1. Overview
The Device module provides block-device and filesystem management for BastionGuard Backup. It models Linux disks, partitions, mapped devices, mounts, filesystems, encryption state, capacity, and exposes discovery, mount, unmount, LUKS, and presentation helpers.
The implementation is written in Vala and uses GLib/GIO together with the application utility namespaces required by the file.
2. Dependencies and Integration
The module imports:
TeeJee.LoggingTeeJee.FileSystemTeeJee.ProcessHelperTeeJee.GtkHelper
Key runtime integrations include:
- GTK – graphical widgets, dialogs, images, event processing, or window lifecycle
- Gee – typed lists, maps, queues, or collection operations
- GIO/GLib streams – filesystem and process I/O
3. Declared Types
3.1 Device
public class Device : GLib.Object
This class encapsulates the state and operations described by this source file.
4. State, Properties, Constants, and Signals
Public and protected state
public static double KB– Runtime state used by the module.public static double MB– Runtime state used by the module.public static double GB– Runtime state used by the module.public static double KiB– Runtime state used by the module.public static double MiB– Runtime state used by the module.public static double GiB– Runtime state used by the module.public string device– Kernel or canonical device path.public string name– Name or identifier for name.public string kname– Runtime state used by the module.public string pkname– Runtime state used by the module.public string pkname_toplevel– Runtime state used by the module.public string mapped_name– Name or identifier for mapped name.public string uuid– Filesystem UUID.public string label– Filesystem or user-facing label.public string partuuid– Runtime state used by the module.public string partlabel– Runtime state used by the module.public int major– Runtime state used by the module.public int minor– Runtime state used by the module.public string device_mapper– Runtime state used by the module.public string device_by_uuid– Runtime state used by the module.public string device_by_label– Runtime state used by the module.public string device_by_partuuid– Runtime state used by the module.public string device_by_partlabel– Runtime state used by the module.public string type– Runtime state used by the module.public string fstype– Detected filesystem type.public int order– Runtime state used by the module.public string vendor– Runtime state used by the module.public string model– Runtime state used by the module.public string serial– Runtime state used by the module.public string revision– Runtime state used by the module.public bool removable– Boolean state controlling or reporting removable.public bool read_only– Boolean state controlling or reporting read only.public uint64 size_bytes– Total device size in bytes.public uint64 used_bytes– Used storage in bytes.public uint64 available_bytes– Size or capacity value associated with available bytes.public string used_percent– Runtime state used by the module.public string dist_info– Runtime state used by the module.public Gee.ArrayList<MountEntry> mount_points– Known mount locations.public Gee.ArrayList<string> symlinks– Collection storing runtime data for this component.public Device parent– Runtime state used by the module.public Gee.ArrayList<Device> children– Collection storing runtime data for this component.public uint64 free_bytes– Available storage in bytes.public string size– Size or capacity value associated with size.public string used– Runtime state used by the module.public string free– Runtime state used by the module.public bool is_mounted– Boolean state controlling or reporting mounted.public string full_name_with_alias– Name or identifier for full name with alias.public string full_name_with_parent– Name or identifier for full name with parent.public string short_name_with_alias– Name or identifier for short name with alias.public string short_name_with_parent– Name or identifier for short name with parent.public string device_name_with_parent– Name or identifier for device name with parent.
Internal state
private static string lsblk_version– Runtime state used by the module.private static bool lsblk_is_ancient– Boolean state controlling or reporting lsblk ancient.private static Gee.ArrayList<Device> device_list– Collection used to store device list.
5. Public API and Operational Methods
5.1 Device()
public Device()
Initializes the object state, allocates required collections or widgets, and applies constructor parameters.
5.2 test_lsblk_version()
public static void test_lsblk_version()
Runs diagnostic checks and logs the resulting capability or data output.
- Executes an external process or generated shell command and uses its return status as part of the result.
5.3 is_mounted_at_path()
public bool is_mounted_at_path(string subvolname, string mount_path)
Evaluates is mounted at path and returns a Boolean capability or state result.
5.4 type_is_raid()
public bool type_is_raid()
Evaluates type is raid and returns a Boolean capability or state result.
5.5 has_linux_filesystem()
public bool has_linux_filesystem()
Evaluates has linux filesystem and returns a Boolean capability or state result.
5.6 is_encrypted_partition()
public bool is_encrypted_partition()
Evaluates is encrypted partition and returns a Boolean capability or state result.
5.7 is_on_encrypted_partition()
public bool is_on_encrypted_partition()
Evaluates is on encrypted partition and returns a Boolean capability or state result.
5.8 is_lvm_partition()
public bool is_lvm_partition()
Evaluates is lvm partition and returns a Boolean capability or state result.
5.9 has_children()
public bool has_children()
Evaluates has children and returns a Boolean capability or state result.
5.10 first_linux_child()
public Device? first_linux_child()
Implements the first linux child operation for this module.
5.11 has_parent()
public bool has_parent()
Evaluates has parent and returns a Boolean capability or state result.
5.12 get_filesystems()
public static Gee.ArrayList<Device> get_filesystems(bool get_space = true, bool get_mounts = true)
Builds a consolidated filesystem inventory by combining LSBLK, BLKID, mount-table, disk-space, parent/child, and device-mapper information.
5.13 remove_parents()
public static int remove_parents(Gee.ArrayList<Device> list, Device dev)
Removes parents and reports whether cleanup completed successfully.
5.14 get_block_devices_using_lsblk()
public static Gee.ArrayList<Device> get_block_devices_using_lsblk(string dev_name = "")
Runs LSBLK in machine-readable key/value mode and converts each output row into a Device object.
- Executes an external process or generated shell command and uses its return status as part of the result.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
- Uses regular expressions to parse or validate text output.
- Catches runtime errors locally and reports them through the logging layer or return value.
5.15 get_block_devices_using_blkid()
public static Gee.ArrayList<Device> get_block_devices_using_blkid(string dev_name = "")
Runs BLKID and parses filesystem identifiers, labels, UUIDs, and types for detected block devices.
- Uses regular expressions to parse or validate text output.
- Catches runtime errors locally and reports them through the logging layer or return value.
5.16 get_disk_space_using_df()
public static Gee.ArrayList<Device> get_disk_space_using_df(string dev_name_or_mount_point = "")
Runs DF using byte units and parses capacity, usage, availability, filesystem type, and mount-point information.
- Executes an external process or generated shell command and uses its return status as part of the result.
5.17 get_mounted_filesystems_using_mtab()
public static Gee.ArrayList<Device> get_mounted_filesystems_using_mtab()
Returns or resolves mounted filesystems using mtab from the current state or underlying system data.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
5.18 get_device_by_uuid()
public static Device? get_device_by_uuid(string uuid)
Returns or resolves device by uuid from the current state or underlying system data.
5.19 get_device_by_name()
public static Device? get_device_by_name(string file_name)
Returns or resolves device by name from the current state or underlying system data.
5.20 get_device_by_path()
public static Device? get_device_by_path(string path_to_check)
Returns or resolves device by path from the current state or underlying system data.
5.21 get_device_uuid()
public static string get_device_uuid(string device)
Returns or resolves device uuid from the current state or underlying system data.
5.22 get_device_mount_points()
public static Gee.ArrayList<MountEntry> get_device_mount_points(string dev_name_or_uuid)
Returns or resolves device mount points from the current state or underlying system data.
5.23 device_is_mounted()
public static bool device_is_mounted(string dev_name_or_uuid)
Implements the device is mounted operation for this module.
5.24 mount_point_in_use()
public static bool mount_point_in_use(string mount_point)
Mounts the requested filesystem or resource using the supplied options and returns its resulting state or mount path.
5.25 resolve_device_name()
public static string resolve_device_name(string dev_alias)
Implements the resolve device name operation for this module.
5.26 find_device_in_list()
public static Device? find_device_in_list(Gee.ArrayList<Device> list, string _dev_alias)
Searches for device in list and returns the matching object or value.
5.27 copy_fields_from()
public void copy_fields_from(Device dev2)
Copies relevant values from the supplied source into the current object.
5.28 query_changes()
public Device? query_changes()
Queries changes and refreshes the associated object state.
5.29 query_disk_space()
public void query_disk_space()
Queries disk space and refreshes the associated object state.
5.30 automount_udisks()
public static bool automount_udisks(string dev_name_or_uuid, Gtk.Window? parent_window)
Mounts the requested filesystem or resource using the supplied options and returns its resulting state or mount path.
- Interacts with GTK/VTE objects and must execute UI changes on the graphical main context.
5.31 automount_udisks_iso()
public static bool automount_udisks_iso(string iso_file_path, out string loop_device, Gtk.Window? parent_window)
Mounts the requested filesystem or resource using the supplied options and returns its resulting state or mount path.
- Executes an external process or generated shell command and uses its return status as part of the result.
5.32 unmount_udisks()
public static bool unmount_udisks(string dev_name_or_uuid, Gtk.Window? parent_window)
Unmounts the requested filesystem or resource and reports the result.
- Interacts with GTK/VTE objects and must execute UI changes on the graphical main context.
5.33 luks_unlock()
public static Device? luks_unlock( Device luks_device, string mapped_name, string passphrase, Gtk.Window? parent_window, out string message, out string details)
Unlocks a LUKS container through udisks or cryptsetup-compatible behavior, optionally using a passphrase and parent GTK window, and returns the mapped child device.
- Interacts with GTK/VTE objects and must execute UI changes on the graphical main context.
- Processes credential-related values that should remain protected in memory and logs.
5.34 luks_lock()
public static bool luks_lock(string kname, Gtk.Window? parent_window)
Implements the luks lock operation for this module.
- Interacts with GTK/VTE objects and must execute UI changes on the graphical main context.
5.35 mount()
public static bool mount( string dev_name_or_uuid, string mount_point, string mount_options = "", bool silent = false)
Resolves the requested device identifier, creates the mount point, executes the mount command with optional options, and reports failure through logging.
- Executes an external process or generated shell command and uses its return status as part of the result.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
5.36 automount()
public static string automount( string dev_name_or_uuid, string mount_options = "", string mount_prefix = "/run")
Mounts the requested filesystem or resource using the supplied options and returns its resulting state or mount path.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
- Catches runtime errors locally and reports them through the logging layer or return value.
5.37 unmount()
public static bool unmount(string mount_point)
Unmounts a mount point and reports whether the operation completed successfully.
- Catches runtime errors locally and reports them through the logging layer or return value.
5.38 description()
public string description()
Builds a human-readable representation from the current object state.
5.39 description_formatted()
public string description_formatted()
Builds a human-readable representation from the current object state.
5.40 description_simple()
public string description_simple()
Builds a human-readable representation from the current object state.
5.41 description_simple_formatted()
public string description_simple_formatted()
Builds a human-readable representation from the current object state.
5.42 description_full_free()
public string description_full_free()
Builds a human-readable representation from the current object state.
5.43 description_full()
public string description_full()
Builds a human-readable representation from the current object state.
5.44 description_usage()
public string description_usage()
Builds a human-readable representation from the current object state.
5.45 description_free()
public string description_free()
Builds a human-readable representation from the current object state.
5.46 tooltip_text()
public string tooltip_text()
Builds a human-readable representation from the current object state.
5.47 test_all()
public static void test_all()
Runs diagnostic checks and logs the resulting capability or data output.
5.48 print_device_list()
public static void print_device_list(Gee.ArrayList<Device> list)
Formats and emits diagnostic information for device list.
5.49 print_device_mounts()
public static void print_device_mounts(Gee.ArrayList<Device> list)
Formats and emits diagnostic information for device mounts.
5.50 print_device_disk_space()
public static void print_device_disk_space(Gee.ArrayList<Device> list)
Formats and emits diagnostic information for device disk space.
6. Internal Helpers
6.1 find_child_devices()
private static void find_child_devices(Gee.ArrayList<Device> list, Device parent)
Searches for child devices and returns the matching object or value.
6.2 find_toplevel_parent()
private static void find_toplevel_parent(Gee.ArrayList<Device> list, Device dev)
Searches for toplevel parent and returns the matching object or value.
6.3 find_child_devices_using_dmsetup()
private static void find_child_devices_using_dmsetup(Gee.ArrayList<Device> list)
Searches for child devices using dmsetup and returns the matching object or value.
7. Filesystem Paths and Resource Locations
The source references the following absolute or template paths:
/boot/efi
/dev
/dev/
/dev/%s
/dev/disk/by-label/%s
/dev/disk/by-partlabel/%s
/dev/disk/by-partuuid/%s
/dev/disk/by-uuid/
/dev/disk/by-uuid/%s
/dev/dm
/dev/hd
/dev/mapper
/dev/mapper/
/dev/sd
/docker
/etc/mtab
/mnt/sdcard
/proc/mounts
/proc/self/mounts
/run
/sbin/blkid
Some values are templates completed at runtime with application names, process IDs, device identifiers, or file names.
8. External Commands and System Interfaces
The module constructs, checks, or parses commands containing:
/sbin/blkid
Failed to mount device '%s' at mount point '%s'
Failed to mount: %s
blkid:
btrfs
cat /proc/mounts | awk '{print $2}' | grep '%s' | sort -r | xargs umount
cryptsetup
cryptsetup luksClose %s
cryptsetup luksOpen '%s' '%s'
df -T -B1
dmsetup deps -o blkdevname
echo -n -e '%s' | cryptsetup luksOpen --key-file - '%s' '%s'\n
lsblk --bytes --pairs --output HOTPLUG,PKNAME,VENDOR,SERIAL,REV
lsblk --bytes --pairs --output NAME,KNAME,LABEL,UUID,TYPE,FSTYPE,SIZE,MOUNTPOINT,MODEL,RO,HOTPLUG,MAJ:MIN,PARTLABEL,PARTUUID,PKNAME,VENDOR,SERIAL,REV
lsblk --bytes --pairs --output NAME,KNAME,LABEL,UUID,TYPE,FSTYPE,SIZE,MOUNTPOINT,MODEL,RO,RM,MAJ:MIN
mount -o %s \"%s\" \"%s\"
mount \"%s\" \"%s\"
mount command: %s
udisksctl loop-setup -r -f '%s'
udisksctl mount -b '%s'
udisksctl unmount -b '%s'
Execution success is determined from command exit status and, where applicable, parsed standard output or standard error.
9. Operational Flow
- Read or discover source data and normalize it into the module data model.
- Transform raw values, command output, or metadata into structured or display-ready form.
- Apply the requested operation and update runtime or persistent state.
- Finalize the operation and release files, mounts, child processes, widgets, or cached state.
10. Error Handling and Diagnostics
- GLib and filesystem exceptions are caught locally in the operations that can fail.
- The TeeJee logging layer records errors, debug state, generated commands, and operational messages.
- Boolean, nullable, or empty-string return values communicate recoverable failures to callers.
- Some methods return detailed diagnostics through output parameters in addition to their primary status value.
11. Runtime and Security Considerations
- External commands: command availability, quoting, locale, privileges, and output format can affect behavior.
- Dynamic command construction: caller-controlled values must be validated and escaped before being inserted into shell commands.
- Sensitive data: credentials and passphrases should not be logged or persisted without protected storage and restrictive permissions.
- Linux-specific paths: the module depends on Linux virtual filesystems or privileged system directories.
- Output parsing: parsers depend on stable external-command or system-file formats and should be tested across distributions.
- Shared state: static caches and global switches are shared by all callers and are not automatically thread-isolated.
- GTK lifecycle: widgets and local main loops require a valid graphical context and careful close/destroy handling.
- Privilege and cleanup: mount or encryption operations should always pair successful setup with deterministic unmount or lock cleanup.
12. Licensing
The source is distributed under the GNU General Public License version 2 or any later version.
The source header identifies:
Copyright 2012-2018 Tony George <teejeetech@gmail.com>
