-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
use mdev::setup_log; | ||
use tracing::{debug, error}; | ||
use walkdir::WalkDir; | ||
|
||
#[derive(Parser)] | ||
struct Opt { | ||
/// Verbose mode, logs to stderr | ||
#[arg(short, long, action = clap::ArgAction::Count)] | ||
verbose: u8, | ||
|
||
/// Path where the sysfs is mounted | ||
#[arg(short, long, default_value = "/sys")] | ||
sysfs_mount: PathBuf, | ||
} | ||
|
||
impl Opt { | ||
fn setup_log(&self) -> anyhow::Result<()> { | ||
setup_log(self.verbose) | ||
} | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let opt = Opt::parse(); | ||
|
||
opt.setup_log()?; | ||
|
||
let classdir = WalkDir::new(opt.sysfs_mount.join("class")) | ||
.follow_links(true) | ||
.max_depth(4) | ||
.into_iter(); | ||
let busdir = WalkDir::new(opt.sysfs_mount.join("bus")) | ||
.follow_links(true) | ||
.max_depth(3) | ||
.into_iter(); | ||
|
||
for entry in classdir | ||
.chain(busdir) | ||
.filter_map(|e| e.ok().filter(|e| e.file_name().eq("uevent"))) | ||
{ | ||
debug!("{entry:?}"); | ||
let p = entry.path(); | ||
std::fs::write(p, "add").unwrap_or_else(|e| error!("cannot write to {}: {e}", p.display())); | ||
} | ||
|
||
Ok(()) | ||
} |