Monitors and reports changes to the disks attached to a Nerves device.
The package can be installed by adding nerves_disk_manager
to your list of
dependencies in mix.exs
:
def deps do
[
{:nerves_disk_manager, git: "https://github.com/brandonmenc/nerves_disk_manager"}
]
end
NervesDiskMountExample is an example app that uses this module.
Lots. Not production ready.
NervesDiskManager.DiskWatcher
waits for block device changes in
SystemRegistry
.
iex> SystemRegistry.match(:_) |> get_in([:state, "subsystems", "block"])
SCSI disk device partitions (ex: a USB flash drive partition at /dev/sda1 ) are filtered out and their states are tracked. Three lists of disk partitions are maintained:
iex> SystemRegistry.match(:_) |> get_in([:state, :disks]) |> Map.keys()
[:added, :partitions, :removed]
:partitions
is a list of all the currently connected partitions. :added
is a
subset of :partitions
- a list of all the partitions that were connected since
the last time the state was updated. :removed
is a list of all the partitions
that were disconnected since the last time the state was updated. The format of
the entries in :added
and :removed
is the same as in :partitions
.
Let's say a USB drive was just plugged in:
iex> SystemRegistry.match(:_) |> get_in([:state, :disks])
%{added: ["sda1"], partitions: ["sda1"], removed: []}
Sometimes you just want to check :partitions
for a specific disk partition,
but you can also build more complex logic based on the :added
and :removed
lists.