device_enumerator

1. Overview

The device_enumerator.cpp file discovers block devices and produces device models for the graphical and scanning layers.

This is an implementation file. It contains executable logic for the subsystem, including parsing, I/O, validation, recovery flow, or graphical behavior declared by the corresponding interface.

Its paired source or interface file is device_enumerator.hpp.

Primary responsibilities:

  • Enumerate physical disks, partitions and images
  • Collect labels, sizes and device metadata
  • Filter unsuitable pseudo-devices
  • Present stable device identifiers

2. File Identity and Scope

  • Source path: src/device_enumerator.cpp
  • Language: C++
  • File role: implementation file
  • Physical lines: 96
  • Non-empty lines: 81
  • SHA-256: 8dc22efbff7a5fd7936edc32a2c491cfcf6c780af3f26742ed825bf51860aef3

The declarations in this file use the global namespace.


3. Dependencies

3.1 Project Headers

  • device_health_probe.hpp
  • device_enumerator.hpp

3.2 Standard and External Headers

  • filesystem
  • fstream
  • sstream
  • string
  • vector

These dependencies define the file’s compile-time integration with the recovery engine, GTK interface, on-disk format decoders, operating-system services, or C++ standard library.


4. Declared Types

No class, structure, or enumeration definition is declared directly in this file.


5. Constants and Configuration Values

No preprocessor or compile-time constants were detected as top-level declarations in this file.

5.1 Operational Strings, Paths, Formats, or Commands

The following code literals are operationally relevant and may identify filesystem paths, helper commands, formats, signatures, or subsystem labels:

  • /sys/block
  • /dev/

6. Data Members and Persistent State

No class data members are declared directly in this file, or the file primarily implements methods declared elsewhere.


7. API and Function Inventory

The following callable interfaces or definitions were detected:

  • std::string trim(const std::string&s) – Implements the operation identified by this API and updates or returns the associated state.
  • std::string read_text_file(const fs::path&p) – Reads or derives the requested information and returns or stores the decoded result.
  • uint64_t read_u64_file(const fs::path&p) – Reads or derives the requested information and returns or stores the decoded result.
  • bool starts_with(const std::string&s,const std::string&prefix) – Implements the operation identified by this API and updates or returns the associated state.
  • bool is_real_disk_name(const std::string&name) – Evaluates the stated condition and returns the corresponding Boolean result.
  • std::vector<DeviceInfo> DeviceEnumerator::enumerate_linux_block_devices(bool include_health_probe) – Implements the operation identified by this API and updates or returns the associated state.

8. Operational Flow

The subsystem represented by this file normally participates in the following flow:

  1. Enumerate physical disks, partitions and images.
  2. Collect labels, sizes and device metadata.
  3. Filter unsuitable pseudo-devices.
  4. Present stable device identifiers.
  5. Expose or execute the detected APIs: trim, read_text_file, read_u64_file, starts_with, is_real_disk_name, enumerate_linux_block_devices.
  6. Return explicit results, progress data, recovered records, or diagnostics to the calling layer.

9. Validation and Error Handling

  • Byte offsets, sizes and lengths must be validated before arithmetic and before every read to avoid overflow and out-of-bounds access.
  • Input and output paths require existence checks, permission handling and safe destination construction.

10. Runtime, Concurrency, and Resource Management

  • I/O: filesystem and raw-source operations can fail partially and must preserve exact byte counts and diagnostic context.
  • Privileges: some paths involve raw devices, mappings or mounts and therefore require carefully bounded elevated execution.
  • File descriptors and streams must be closed on success, cancellation and error paths.
  • Temporary loop devices, mappings and mounts require deterministic reverse-order cleanup.

11. Security and Data-Recovery Considerations

  • Recovery code should prefer read-only source access and avoid writing to the original damaged medium.
  • Raw devices and image files are treated as untrusted binary input; every offset and length must remain bounded by the source size.
  • Operations that open block devices, create mappings or mount filesystems require elevated privileges and should expose the smallest possible privileged surface.

12. Implementation Considerations

  • The implementation should remain aligned with declarations in the paired header and preserve documented return-value semantics.
  • Large-device arithmetic uses 64-bit values; additions and multiplications should be checked before use as offsets or allocation sizes.
  • Filesystem operations can cross trust boundaries and should use normalized, contained destination paths.

13. Integration with the Recovery Pipeline

  • The file belongs to the source-discovery, parsing or support layer.
  • Its results feed scanner, recovery or reporting modules through shared models.
  • The API should remain deterministic so higher layers can combine results safely.

14. Licensing and Provenance

No explicit copyright or software-license statement was detected in the opening section of this individual file. Distribution terms should therefore be verified against the project-level license and repository metadata.

The SHA-256 value in this document can be used to associate the generated documentation with the exact source version analyzed.