/* * Copyright (c) 2021, Luca Fulchir * * This file is part of dfim. * * dfim is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * dfim is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with dfim. If not, see . */ use super::DeviceMsg; use ::std::sync::{mpsc, Arc, Condvar, Mutex}; pub async fn scanner( logger: Arc<::slog::Logger>, cfg: Arc, udev: super::UdevSend, tx: mpsc::Sender, cvar: Arc, ) -> Result<(), ::std::io::Error> { let udev_ctx = udev.udev; // First setup the udev monitors, then enumerate all devices one, then just // wait for udev events // enumerate all devices let mut devices = ::udev::Enumerator::with_udev(udev_ctx.clone())?; devices.match_is_initialized().unwrap(); devices.match_subsystem("block").unwrap(); let dev_list = devices.scan_devices()?; for dev in dev_list { tx.send(DeviceMsg { handle: dev }); cvar.notify_one(); } Ok(()) }