summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-06-25 14:01:20 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2025-06-25 14:01:22 -0400
commitffd8765ec62d006414176f49139856751150b768 (patch)
tree854871b820a53b6b06e65d78c6a95b7f5234ca71
parent84f7b2fdc3ba8e1a7bb7f33da8c67d1dda36f86a (diff)
mount: check if bcachefs module is loaded
This lets us print out a more useful error. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--src/commands/mount.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/commands/mount.rs b/src/commands/mount.rs
index 1b8f444a..883a0d11 100644
--- a/src/commands/mount.rs
+++ b/src/commands/mount.rs
@@ -376,7 +376,24 @@ pub struct Cli {
verbose: u8,
}
+fn require_bcachefs_module() {
+ let path = Path::new("/sys/module/bcachefs");
+
+ if !path.exists() {
+ let _ = std::process::Command::new("modprobe")
+ .arg("bcachefs")
+ .status();
+
+ if !path.exists() {
+ error!("bcachefs module not loaded?");
+ std::process::exit(1);
+ }
+ }
+}
+
pub fn mount(mut argv: Vec<String>, symlink_cmd: Option<&str>) -> std::process::ExitCode {
+ require_bcachefs_module();
+
// If the bcachefs tool is being called as "bcachefs mount dev ..." (as opposed to via a
// symlink like "/usr/sbin/mount.bcachefs dev ...", then we need to pop the 0th argument
// ("bcachefs") since the CLI parser here expects the device at position 1.