Merge pull request #444 from JohnRTitor/handle-dir-and-file-fsck

device-scan: instead of panicking handle when bcachefs is given directory or file as argument
This commit is contained in:
koverstreet 2025-10-06 10:30:59 -04:00 committed by GitHub
commit 36191ce280
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 15 deletions

View File

@ -1,6 +1,7 @@
{ {
lib, lib,
pkgs, pkgs,
stdenvNoCC,
# build time # build time
pkg-config, pkg-config,
@ -65,6 +66,17 @@ let
zlib zlib
zstd zstd
]; ];
checkFlags = lib.optionals (stdenvNoCC.hostPlatform.isAarch64) [
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_1"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_2"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_3"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_4"
];
checkPhaseCargoCommand = ''
cargo test --profile release -- --nocapture $checkFlags
'';
}; };
cargoArtifacts = craneLib.buildDepsOnly args; cargoArtifacts = craneLib.buildDepsOnly args;
@ -133,9 +145,10 @@ let
pnameSuffix = "-test"; pnameSuffix = "-test";
buildPhaseCargoCommand = ""; buildPhaseCargoCommand = "";
checkPhaseCargoCommand = '' checkPhaseCargoCommand = ''
make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a
cargo test --profile release -- --nocapture cargo test --profile release -- --nocapture $checkFlags
''; '';
} }
); );

24
flake.lock generated
View File

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1758686891, "lastModified": 1759511609,
"narHash": "sha256-Lq8JkwjSzv80T1i8KCvqAch75zwD98UKA+4atZjvfZ0=", "narHash": "sha256-uU6Dq5OUgI9pEiMDwZZhvsoxYD+36xKIkYyFXDr//6A=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "02063302383f43237602f5aea5a67766b08e4787", "rev": "c5b48a59ccd5179ea626f47b05d2828c37fb31b7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -36,11 +36,11 @@
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1756770412, "lastModified": 1759362264,
"narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=", "narHash": "sha256-wfG0S7pltlYyZTM+qqlhJ7GMw2fTF4mLKCIVhLii/4M=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "4524271976b625a4a605beefd893f270620fd751", "rev": "758cf7296bee11f1706a574c77d072b8a7baa881",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -71,11 +71,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1758427187, "lastModified": 1759381078,
"narHash": "sha256-pHpxZ/IyCwoTQPtFIAG2QaxuSm8jWzrzBGjwQZIttJc=", "narHash": "sha256-gTrEEp5gEspIcCOx9PD8kMaF1iEmfBcTbO0Jag2QhQs=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "554be6495561ff07b6c724047bdd7e0716aa7b46", "rev": "7df7ff7d8e00218376575f0acdcc5d66741351ee",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -118,11 +118,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1758681214, "lastModified": 1759544920,
"narHash": "sha256-8cW731vev6kfr58cILO2ZsjHwaPhm88dQ8Q6nTSjP9I=", "narHash": "sha256-yQwP0JOHi3Icq09GG5ufGuGrq2zIijglVFj3kkF2MHA=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "b12ed88d8d33d4f3cbc842bf29fad93bb1437299", "rev": "bd3a63bbff2c4cb3cd48e9d49f54c2ccad457f70",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -2,6 +2,7 @@ use std::{
ffi::{CStr, CString, c_char, c_int}, ffi::{CStr, CString, c_char, c_int},
collections::HashMap, collections::HashMap,
env, env,
fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
str, str,
}; };
@ -132,6 +133,15 @@ fn devs_str_sbs_from_device(
device: &Path, device: &Path,
opts: &bch_opts opts: &bch_opts
) -> anyhow::Result<Vec<(PathBuf, bch_sb_handle)>> { ) -> anyhow::Result<Vec<(PathBuf, bch_sb_handle)>> {
if let Ok(metadata) = fs::metadata(device) {
if metadata.is_dir() {
return Err(anyhow::anyhow!("'{}' is a directory, not a block device", device.display()));
}
if metadata.is_file() {
return Err(anyhow::anyhow!("'{}' is a regular file, not a block device", device.display()));
}
}
let dev_sb = read_super_silent(device, *opts)?; let dev_sb = read_super_silent(device, *opts)?;
if dev_sb.sb().number_of_devices() == 1 { if dev_sb.sb().number_of_devices() == 1 {
@ -199,7 +209,11 @@ pub extern "C" fn bch2_scan_device_sbs(device: *const c_char, ret: *mut sb_names
// how to initialize to default/empty? // how to initialize to default/empty?
let opts = bch_bindgen::opts::parse_mount_opts(None, None, true).unwrap_or_default(); let opts = bch_bindgen::opts::parse_mount_opts(None, None, true).unwrap_or_default();
let sbs = scan_sbs(&device, &opts).unwrap(); let sbs = scan_sbs(&device, &opts)
.unwrap_or_else(|e| {
eprintln!("bcachefs ({}): error reading superblock: {}", device, e);
std::process::exit(-1);
});
let mut sbs = sbs.iter() let mut sbs = sbs.iter()
.map(|(name, sb)| sb_name { .map(|(name, sb)| sb_name {
@ -225,5 +239,8 @@ pub extern "C" fn bch2_scan_devices(device: *const c_char) -> *mut c_char {
// how to initialize to default/empty? // how to initialize to default/empty?
let opts = bch_bindgen::opts::parse_mount_opts(None, None, true).unwrap_or_default(); let opts = bch_bindgen::opts::parse_mount_opts(None, None, true).unwrap_or_default();
CString::new(scan_devices(&device, &opts).unwrap()).unwrap().into_raw() CString::new(scan_devices(&device, &opts).unwrap_or_else(|e| {
eprintln!("bcachefs ({}): error reading superblock: {}", device, e);
std::process::exit(-1);
})).unwrap().into_raw()
} }