summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoverstreet <kent.overstreet@gmail.com>2024-07-20 19:37:06 -0400
committerGitHub <noreply@github.com>2024-07-20 19:37:06 -0400
commit201b1e82167074b716a869ab35cfc4f9b485dd48 (patch)
tree40e9213ae0af8ee4450406885cb8cc1cdd64a750
parent52b9e813bdc826d5dc8d140645166feece0ec43a (diff)
parentcdcc241167414d2f95539dbcad0caa614484615a (diff)
Merge pull request #315 from tmuehlbacher/variety-changes
Variety changes
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock46
-rw-r--r--Cargo.toml3
-rw-r--r--src/commands/mount.rs50
-rw-r--r--src/logging.rs29
5 files changed, 64 insertions, 66 deletions
diff --git a/.gitignore b/.gitignore
index d346831e..2accefbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,8 +10,6 @@ TAGS
cscope*
bcachefs-tools
compile_commands.json
-tests/test_helper
-tests/__pycache__/
# dot-files that we don't want to ignore
!.gitignore
diff --git a/Cargo.lock b/Cargo.lock
index a4f1ed44..a7856599 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -73,7 +73,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bcachefs-tools"
-version = "1.9.5"
+version = "0.0.0"
dependencies = [
"anyhow",
"bch_bindgen",
@@ -85,6 +85,7 @@ dependencies = [
"errno 0.2.8",
"libc",
"log",
+ "owo-colors",
"rustix",
"strum",
"strum_macros",
@@ -258,9 +259,7 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580"
dependencies = [
- "is-terminal",
"log",
- "termcolor",
]
[[package]]
@@ -307,12 +306,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
-name = "hermit-abi"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
-
-[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -322,17 +315,6 @@ dependencies = [
]
[[package]]
-name = "is-terminal"
-version = "0.4.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
-dependencies = [
- "hermit-abi",
- "libc",
- "windows-sys 0.52.0",
-]
-
-[[package]]
name = "itertools"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -429,6 +411,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
+name = "owo-colors"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f"
+
+[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -568,15 +556,6 @@ dependencies = [
]
[[package]]
-name = "termcolor"
-version = "1.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
-dependencies = [
- "winapi-util",
-]
-
-[[package]]
name = "terminal_size"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -644,15 +623,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
-name = "winapi-util"
-version = "0.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
-dependencies = [
- "windows-sys 0.52.0",
-]
-
-[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8520f55f..b3991a09 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,5 @@
[package]
name = "bcachefs-tools"
-version = "1.9.5"
authors = ["Yuxuan Shui <yshuiv7@gmail.com>", "Kayla Firestack <dev@kaylafire.me>", "Kent Overstreet <kent.overstreet@linux.dev>" ]
edition = "2021"
rust-version = "1.70"
@@ -25,11 +24,11 @@ strum = { version = "0.26", features = ["derive"] }
strum_macros = "0.26"
zeroize = { version = "1", features = ["std", "zeroize_derive"] }
rustix = { version = "0.38.34", features = ["termios"] }
+owo-colors = "4"
[dependencies.env_logger]
version = "0.10"
default-features = false
-features = ["auto-color"]
[profile.release]
strip = "none"
diff --git a/src/commands/mount.rs b/src/commands/mount.rs
index 0f39214c..3a524c5c 100644
--- a/src/commands/mount.rs
+++ b/src/commands/mount.rs
@@ -48,7 +48,10 @@ fn mount_inner(
let err = errno::errno().0;
- if ret == 0 || (err != libc::EACCES && err != libc::EROFS) || (mountflags & libc::MS_RDONLY) != 0 {
+ if ret == 0
+ || (err != libc::EACCES && err != libc::EROFS)
+ || (mountflags & libc::MS_RDONLY) != 0
+ {
break;
}
@@ -333,35 +336,38 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> {
// Grab the udev information once
let udev_info = udev_bcachefs_info()?;
- let (devices, mut sbs) = if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') {
- devs_str_sbs_from_uuid(&udev_info, uuid)?
- } else if cli.dev.contains(':') {
- // If the device string contains ":" we will assume the user knows the
- // entire list. If they supply a single device it could be either the FS
- // only has 1 device or it's only 1 of a number of devices which are
- // part of the FS. This appears to be the case when we get called during
- // fstab mount processing and the fstab specifies a UUID.
-
- let sbs = cli
- .dev
- .split(':')
- .map(read_super_silent)
- .collect::<Result<Vec<_>>>()?;
-
- (cli.dev.clone(), sbs)
- } else {
- devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))?
- };
+ let (devices, mut sbs) =
+ if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') {
+ devs_str_sbs_from_uuid(&udev_info, uuid)?
+ } else if cli.dev.contains(':') {
+ // If the device string contains ":" we will assume the user knows the
+ // entire list. If they supply a single device it could be either the FS
+ // only has 1 device or it's only 1 of a number of devices which are
+ // part of the FS. This appears to be the case when we get called during
+ // fstab mount processing and the fstab specifies a UUID.
+
+ let sbs = cli
+ .dev
+ .split(':')
+ .map(read_super_silent)
+ .collect::<Result<Vec<_>>>()?;
+
+ (cli.dev.clone(), sbs)
+ } else {
+ devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))?
+ };
ensure!(!sbs.is_empty(), "No device(s) to mount specified");
let first_sb = &sbs[0];
if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } {
- handle_unlock(cli, &first_sb)?;
+ handle_unlock(cli, first_sb)?;
}
for sb in &mut sbs {
- unsafe { bch_bindgen::sb_io::bch2_free_super(sb); }
+ unsafe {
+ bch_bindgen::sb_io::bch2_free_super(sb);
+ }
}
drop(sbs);
diff --git a/src/logging.rs b/src/logging.rs
index 98ca091f..7b113b6a 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -1,9 +1,12 @@
+use std::io::Write;
+
use env_logger::WriteStyle;
-use log::LevelFilter;
+use log::{Level, LevelFilter};
+use owo_colors::{OwoColorize, Style};
pub fn setup(verbose: u8, color: bool) {
let level_filter = match verbose {
- 0 => LevelFilter::Off,
+ 0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
@@ -19,5 +22,27 @@ pub fn setup(verbose: u8, color: bool) {
.filter_level(level_filter)
.write_style(style)
.parse_env("BCACHEFS_LOG")
+ .format(move |buf, record| {
+ let style = if style == WriteStyle::Never {
+ Style::new()
+ } else {
+ match record.level() {
+ Level::Trace => Style::new().cyan(),
+ Level::Debug => Style::new().blue(),
+ Level::Info => Style::new().green(),
+ Level::Warn => Style::new().yellow(),
+ Level::Error => Style::new().red().bold(),
+ }
+ };
+
+ writeln!(
+ buf,
+ "[{:<5} {}:{}] {}",
+ record.level().style(style),
+ record.file().unwrap(),
+ record.line().unwrap(),
+ record.args()
+ )
+ })
.init();
}