Skip to content

๐Ÿ”Œ Device โ€‹

The device crate defines typed control-command contracts for device files.

Role โ€‹

  • Provides shared command identifiers/payload types that callers and drivers both understand.
  • Keeps command ABI definitions centralized instead of duplicating command numbers in each consumer.

Boundaries โ€‹

  • In scope: command typing, payload enums, define_command! declarations.
  • Out of scope: any actual device behavior, state, or runtime mounting logic.

Internal structure โ€‹

  • lib.rs: exports command families.
  • hash.rs: hash-specific types and commands.
    • HashAlgorithm enum.
    • RESET and SET_ALGORITHM command definitions.

Runtime interaction โ€‹

  • Callers issue File::control(...) on mounted device nodes (for example /devices/hasher).
  • Drivers decode the same command identifiers to execute implementation-specific behavior.

Dependency model โ€‹

  • Depends on File system for ControlCommand abstractions and macro support.
  • Consumed by higher-level crates such as Authentication and driver implementations.

Failure semantics โ€‹

  • This crate does not execute I/O; operational failures occur in driver or VFS layers.
  • Type/identifier mismatches are surfaced when commands are cast/handled at runtime boundaries.

Extension points โ€‹

  • Add new command families as separate modules (mirroring hash.rs).
  • Preserve existing command IDs to keep backward-compatible control ABI.

Contract vs implementation โ€‹

  • Contract: stable typed command IDs + payload schemas.
  • Current implementation: only hash-device contract family is defined in-tree.

Limitations and trade-offs โ€‹

  • Narrow scope means low coupling, but functionality depends on external driver support.
  • Command evolution requires ABI discipline once IDs are consumed by executables/modules.

References โ€‹