Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2021, Luca Fulchir <luker@fenrirproject.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
use super::DeviceMsg;
use ::std::sync::{mpsc, Arc, Condvar, Mutex};
pub async fn scanner(
logger: Arc<::slog::Logger>,
cfg: Arc<dfim::config::Config>,
udev: super::UdevSend,
tx: mpsc::Sender<DeviceMsg>,
cvar: Arc<Condvar>,
) -> 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(())
}