Skip to content

brandonmenc/nerves_disk_manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NervesDiskManager

Monitors and reports changes to the disks attached to a Nerves device.

Installation

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

Example

NervesDiskMountExample is an example app that uses this module.

Todo

Lots. Not production ready.

See also

NervesMountManager

How it works

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.

About

Monitors the disks connected to a Nerves device.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages