From f5baaf48e3e82b1caf9f5cd1207d4d6feba3a2e5 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Mon, 15 Jan 2024 23:41:02 -0700 Subject: move Rust sources to top level, C sources into c_src This moves the Rust sources out of rust_src/ and into the top level. Running the bcachefs executable out of the development tree is now: $ ./target/release/bcachefs command or $ cargo run --profile release -- command instead of "./bcachefs command". Building and installing is still: $ make && make install Signed-off-by: Thomas Bertschinger Signed-off-by: Kent Overstreet --- rust-src/.gitignore | 15 - rust-src/Cargo.lock | 838 ------------------------- rust-src/Cargo.toml | 27 - rust-src/README.md | 62 -- rust-src/bch_bindgen/.gitignore | 15 - rust-src/bch_bindgen/Cargo.lock | 250 -------- rust-src/bch_bindgen/Cargo.toml | 22 - rust-src/bch_bindgen/build.rs | 117 ---- rust-src/bch_bindgen/rustfmt.toml | 3 - rust-src/bch_bindgen/src/bcachefs.rs | 112 ---- rust-src/bch_bindgen/src/bkey.rs | 125 ---- rust-src/bch_bindgen/src/btree.rs | 197 ------ rust-src/bch_bindgen/src/errcode.rs | 40 -- rust-src/bch_bindgen/src/fs.rs | 27 - rust-src/bch_bindgen/src/keyutils.rs | 6 - rust-src/bch_bindgen/src/keyutils_wrapper.h | 1 - rust-src/bch_bindgen/src/lib.rs | 168 ----- rust-src/bch_bindgen/src/libbcachefs_wrapper.h | 22 - rust-src/bch_bindgen/src/opts.rs | 35 -- rust-src/bch_bindgen/src/rs.rs | 29 - rust-src/build.rs | 21 - rust-src/rustfmt.toml | 3 - rust-src/src/bcachefs.rs | 120 ---- rust-src/src/commands/cmd_completions.rs | 19 - rust-src/src/commands/cmd_list.rs | 168 ----- rust-src/src/commands/cmd_mount.rs | 251 -------- rust-src/src/commands/logger.rs | 28 - rust-src/src/commands/mod.rs | 31 - rust-src/src/key.rs | 144 ----- 29 files changed, 2896 deletions(-) delete mode 100644 rust-src/.gitignore delete mode 100644 rust-src/Cargo.lock delete mode 100644 rust-src/Cargo.toml delete mode 100644 rust-src/README.md delete mode 100644 rust-src/bch_bindgen/.gitignore delete mode 100644 rust-src/bch_bindgen/Cargo.lock delete mode 100644 rust-src/bch_bindgen/Cargo.toml delete mode 100644 rust-src/bch_bindgen/build.rs delete mode 100644 rust-src/bch_bindgen/rustfmt.toml delete mode 100644 rust-src/bch_bindgen/src/bcachefs.rs delete mode 100644 rust-src/bch_bindgen/src/bkey.rs delete mode 100644 rust-src/bch_bindgen/src/btree.rs delete mode 100644 rust-src/bch_bindgen/src/errcode.rs delete mode 100644 rust-src/bch_bindgen/src/fs.rs delete mode 100644 rust-src/bch_bindgen/src/keyutils.rs delete mode 100644 rust-src/bch_bindgen/src/keyutils_wrapper.h delete mode 100644 rust-src/bch_bindgen/src/lib.rs delete mode 100644 rust-src/bch_bindgen/src/libbcachefs_wrapper.h delete mode 100644 rust-src/bch_bindgen/src/opts.rs delete mode 100644 rust-src/bch_bindgen/src/rs.rs delete mode 100644 rust-src/build.rs delete mode 100644 rust-src/rustfmt.toml delete mode 100644 rust-src/src/bcachefs.rs delete mode 100644 rust-src/src/commands/cmd_completions.rs delete mode 100644 rust-src/src/commands/cmd_list.rs delete mode 100644 rust-src/src/commands/cmd_mount.rs delete mode 100644 rust-src/src/commands/logger.rs delete mode 100644 rust-src/src/commands/mod.rs delete mode 100644 rust-src/src/key.rs (limited to 'rust-src') diff --git a/rust-src/.gitignore b/rust-src/.gitignore deleted file mode 100644 index 644cd426..00000000 --- a/rust-src/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -# Needed by nix -# Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/rust-src/Cargo.lock b/rust-src/Cargo.lock deleted file mode 100644 index 3e7eea92..00000000 --- a/rust-src/Cargo.lock +++ /dev/null @@ -1,838 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "anstream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is-terminal", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" - -[[package]] -name = "anstyle-parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "anstyle-wincon" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" -dependencies = [ - "anstyle", - "windows-sys 0.48.0", -] - -[[package]] -name = "anyhow" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bcachefs-tools" -version = "0.3.1" -dependencies = [ - "anyhow", - "atty", - "bch_bindgen", - "byteorder", - "clap", - "clap_complete", - "colored", - "either", - "errno 0.2.8", - "gag", - "libc", - "log", - "rpassword", - "udev", - "uuid", -] - -[[package]] -name = "bch_bindgen" -version = "0.1.0" -dependencies = [ - "anyhow", - "bindgen", - "bitfield", - "bitflags 1.3.2", - "byteorder", - "memoffset", - "paste", - "pkg-config", - "uuid", -] - -[[package]] -name = "bindgen" -version = "0.64.0" -source = "git+https://evilpiepirate.org/git/rust-bindgen.git#f773267b090bf16b9e8375fcbdcd8ba5e88806a8" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 1.0.109", -] - -[[package]] -name = "bitfield" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clang-sys" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" -dependencies = [ - "glob", - "libc", -] - -[[package]] -name = "clap" -version = "4.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] - -[[package]] -name = "clap_builder" -version = "4.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", - "terminal_size", -] - -[[package]] -name = "clap_complete" -version = "4.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc443334c81a804575546c5a8a79b4913b50e28d69232903604cada1de817ce" -dependencies = [ - "clap", -] - -[[package]] -name = "clap_derive" -version = "4.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "clap_lex" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "colored" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" -dependencies = [ - "is-terminal", - "lazy_static", - "windows-sys 0.48.0", -] - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - -[[package]] -name = "filedescriptor" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e" -dependencies = [ - "libc", - "thiserror", - "winapi", -] - -[[package]] -name = "gag" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a713bee13966e9fbffdf7193af71d54a6b35a0bb34997cd6c9519ebeb5005972" -dependencies = [ - "filedescriptor", - "tempfile", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.3", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "is-terminal" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" -dependencies = [ - "hermit-abi 0.3.3", - "rustix 0.38.30", - "windows-sys 0.52.0", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" - -[[package]] -name = "libudev-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" -dependencies = [ - "libc", - "pkg-config", -] - -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "linux-raw-sys" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "pkg-config" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" - -[[package]] -name = "proc-macro2" -version = "1.0.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "rpassword" -version = "4.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99371657d3c8e4d816fb6221db98fa408242b0b53bac08f8676a41f8554fe99f" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno 0.3.8", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - -[[package]] -name = "rustix" -version = "0.38.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" -dependencies = [ - "bitflags 2.4.1", - "errno 0.3.8", - "libc", - "linux-raw-sys 0.4.12", - "windows-sys 0.52.0", -] - -[[package]] -name = "shlex" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tempfile" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix 0.38.30", - "windows-sys 0.52.0", -] - -[[package]] -name = "terminal_size" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" -dependencies = [ - "rustix 0.37.27", - "windows-sys 0.48.0", -] - -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "udev" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebdbbd670373442a12fe9ef7aeb53aec4147a5a27a00bbc3ab639f08f48191a" -dependencies = [ - "libc", - "libudev-sys", - "pkg-config", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "uuid" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.0", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" -dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/rust-src/Cargo.toml b/rust-src/Cargo.toml deleted file mode 100644 index 66d7bc6a..00000000 --- a/rust-src/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "bcachefs-tools" -version = "0.3.1" -authors = ["Yuxuan Shui ", "Kayla Firestack ", "Kent Overstreet " ] -edition = "2021" -rust-version = "1.65" - -[[bin]] -name = "bcachefs" -path = "src/bcachefs.rs" - -[dependencies] -atty = "0.2.14" -log = { version = "0.4", features = ["std"] } -colored = "2" -clap = { version = "4.0.32", features = ["derive", "wrap_help"] } -clap_complete = "4.3.2" -anyhow = "1.0" -libc = "0.2.69" -udev = "0.7.0" -uuid = "1.2.2" -gag = "1.0.0" -errno = "0.2" -either = "1.5" -rpassword = "4" -bch_bindgen = { path = "bch_bindgen" } -byteorder = "1.3" diff --git a/rust-src/README.md b/rust-src/README.md deleted file mode 100644 index e4700f6b..00000000 --- a/rust-src/README.md +++ /dev/null @@ -1,62 +0,0 @@ -Usage -===== - -``` -bcachefs-mount 0.1.0 -Mount a bcachefs filesystem by its UUID - -USAGE: - bcachefs-mount [OPTIONS] - -FLAGS: - -h, --help - Prints help information - - -V, --version - Prints version information - - -OPTIONS: - -o - Mount options [default: ] - - -p, --password - Where the password would be loaded from. - - Possible values are: "fail" - don't ask for password, fail if filesystem is encrypted; "wait" - wait for - password to become available before mounting; "ask" - prompt the user for password; [default: fail] - -ARGS: - - External UUID of the bcachefs filesystem - - - Where the filesystem should be mounted -``` - -Caveats -======= - -* `--password ask` is not yet implemented, but you can use `--password wait`, and load the key with `bcachefs unlock`. - -Build -===== - -```sh -$ git submodule update --init --recursive -$ cargo build --release -``` - -Binary will be built in `target/release/bcachefs-mount` - -Dependencies: - -* rust -* blkid -* uuid -* liburcu -* libsodium -* zlib -* liblz4 -* libzstd -* libkeyutils diff --git a/rust-src/bch_bindgen/.gitignore b/rust-src/bch_bindgen/.gitignore deleted file mode 100644 index 0aa133ac..00000000 --- a/rust-src/bch_bindgen/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -# Required By Nix -# Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/rust-src/bch_bindgen/Cargo.lock b/rust-src/bch_bindgen/Cargo.lock deleted file mode 100644 index 521c77c2..00000000 --- a/rust-src/bch_bindgen/Cargo.lock +++ /dev/null @@ -1,250 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bch_bindgen" -version = "0.1.0" -dependencies = [ - "anyhow", - "bindgen", - "bitfield", - "bitflags", - "byteorder", - "memoffset", - "paste", - "pkg-config", - "uuid", -] - -[[package]] -name = "bindgen" -version = "0.64.0" -source = "git+https://evilpiepirate.org/git/rust-bindgen.git#f773267b090bf16b9e8375fcbdcd8ba5e88806a8" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", -] - -[[package]] -name = "bitfield" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "clang-sys" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" -dependencies = [ - "glob", - "libc", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "pkg-config" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" - -[[package]] -name = "proc-macro2" -version = "1.0.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "shlex" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "uuid" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" diff --git a/rust-src/bch_bindgen/Cargo.toml b/rust-src/bch_bindgen/Cargo.toml deleted file mode 100644 index 33090ae9..00000000 --- a/rust-src/bch_bindgen/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "bch_bindgen" -version = "0.1.0" -authors = [ "Kayla Firestack ", "Yuxuan Shui ", "Kent Overstreet " ] -edition = "2021" - -[lib] -crate-type = ["lib"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -anyhow = "1.0" -uuid = "1.2.2" -bitfield = "0.14.0" -memoffset = "0.8.0" -byteorder = "1.3" -bitflags = "1.3.2" -paste = "1.0.11" - -[build-dependencies] -pkg-config = "0.3" -bindgen = { git = "https://evilpiepirate.org/git/rust-bindgen.git", default-features = false } diff --git a/rust-src/bch_bindgen/build.rs b/rust-src/bch_bindgen/build.rs deleted file mode 100644 index d9805a8d..00000000 --- a/rust-src/bch_bindgen/build.rs +++ /dev/null @@ -1,117 +0,0 @@ - -#[derive(Debug)] -pub struct Fix753 {} -impl bindgen::callbacks::ParseCallbacks for Fix753 { - fn item_name(&self, original_item_name: &str) -> Option { - Some(original_item_name.trim_start_matches("Fix753_").to_owned()) - } -} - -fn main() { - use std::path::PathBuf; - - println!("cargo:rerun-if-changed=src/libbcachefs_wrapper.h"); - - let out_dir: PathBuf = std::env::var_os("OUT_DIR") - .expect("ENV Var 'OUT_DIR' Expected") - .into(); - let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR") - .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected") - .into(); - - let libbcachefs_inc_dir = std::path::Path::new("../.."); - - let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs"); - let bindings = bindgen::builder() - .header( - top_dir - .join("src") - .join("libbcachefs_wrapper.h") - .display() - .to_string(), - ) - .clang_arg(format!( - "-I{}", - libbcachefs_inc_dir.join("include").display() - )) - .clang_arg(format!("-I{}", libbcachefs_inc_dir.display())) - .clang_arg("-DZSTD_STATIC_LINKING_ONLY") - .clang_arg("-DNO_BCACHEFS_FS") - .clang_arg("-D_GNU_SOURCE") - .clang_arg("-DRUST_BINDGEN") - .clang_arg("-fkeep-inline-functions") - .derive_debug(true) - .derive_default(true) - .layout_tests(true) - .default_enum_style(bindgen::EnumVariation::Rust { - non_exhaustive: true, - }) - .allowlist_function("bcachefs_usage") - .allowlist_function("raid_init") - .allowlist_function("cmd_.*") - .allowlist_function(".*_cmds") - .allowlist_function(".*bch2_.*") - .allowlist_function("bio_.*") - .allowlist_function("derive_passphrase") - .allowlist_function("request_key") - .allowlist_function("add_key") - .allowlist_function("keyctl_search") - .allowlist_function("match_string") - .allowlist_function("printbuf.*") - .blocklist_type("bch_extent_ptr") - .blocklist_type("btree_node") - .blocklist_type("bch_extent_crc32") - .blocklist_type("rhash_lock_head") - .blocklist_type("srcu_struct") - .allowlist_var("BCH_.*") - .allowlist_var("KEY_SPEC_.*") - .allowlist_var("Fix753_FMODE_.*") - .allowlist_var("bch.*") - .allowlist_var("__bch2.*") - .allowlist_var("__BTREE_ITER.*") - .allowlist_var("BTREE_ITER.*") - .blocklist_item("bch2_bkey_ops") - .allowlist_type("bch_.*") - .allowlist_type("fsck_err_opts") - .rustified_enum("fsck_err_opts") - .allowlist_type("nonce") - .no_debug("bch_replicas_padded") - .newtype_enum("bch_kdf_types") - .rustified_enum("bch_key_types") - .opaque_type("gendisk") - .opaque_type("gc_stripe") - .opaque_type("open_bucket.*") - .opaque_type("replicas_delta_list") - .no_copy("btree_trans") - .no_copy("printbuf") - .no_partialeq("bkey") - .no_partialeq("bpos") - .generate_inline_functions(true) - .parse_callbacks(Box::new(Fix753 {})) - .generate() - .expect("BindGen Generation Failiure: [libbcachefs_wrapper]"); - bindings - .write_to_file(out_dir.join("bcachefs.rs")) - .expect("Writing to output file failed for: `bcachefs.rs`"); - - let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib"); - let bindings = bindgen::builder() - .header( - top_dir - .join("src") - .join("keyutils_wrapper.h") - .display() - .to_string(), - ) - .clang_args( - keyutils - .include_paths - .iter() - .map(|p| format!("-I{}", p.display())), - ) - .generate() - .expect("BindGen Generation Failiure: [Keyutils]"); - bindings - .write_to_file(out_dir.join("keyutils.rs")) - .expect("Writing to output file failed for: `keyutils.rs`"); -} diff --git a/rust-src/bch_bindgen/rustfmt.toml b/rust-src/bch_bindgen/rustfmt.toml deleted file mode 100644 index 42f2ad7c..00000000 --- a/rust-src/bch_bindgen/rustfmt.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Default settings, i.e. idiomatic rust -edition = "2021" -newline_style = "Unix" \ No newline at end of file diff --git a/rust-src/bch_bindgen/src/bcachefs.rs b/rust-src/bch_bindgen/src/bcachefs.rs deleted file mode 100644 index 8e897c08..00000000 --- a/rust-src/bch_bindgen/src/bcachefs.rs +++ /dev/null @@ -1,112 +0,0 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(unused)] - -include!(concat!(env!("OUT_DIR"), "/bcachefs.rs")); - -use bitfield::bitfield; -bitfield! { - pub struct bch_scrypt_flags(u64); - pub N, _: 15, 0; - pub R, _: 31, 16; - pub P, _: 47, 32; -} -bitfield! { - pub struct bch_crypt_flags(u64); - pub TYPE, _: 4, 0; -} -use memoffset::offset_of; -impl bch_sb_field_crypt { - pub fn scrypt_flags(&self) -> Option { - use std::convert::TryInto; - match bch_kdf_types(bch_crypt_flags(self.flags).TYPE().try_into().ok()?) { - bch_kdf_types::BCH_KDF_SCRYPT => Some(bch_scrypt_flags(self.kdf_flags)), - _ => None, - } - } - pub fn key(&self) -> &bch_encrypted_key { - &self.key - } -} -impl PartialEq for bch_sb { - fn eq(&self, other: &Self) -> bool { - self.magic.b == other.magic.b - && self.user_uuid.b == other.user_uuid.b - && self.block_size == other.block_size - && self.version == other.version - && self.uuid.b == other.uuid.b - && self.seq == other.seq - } -} - -impl bch_sb { - pub fn crypt(&self) -> Option<&bch_sb_field_crypt> { - unsafe { - let ptr = bch2_sb_field_get_id( - self as *const _ as *mut _, - bch_sb_field_type::BCH_SB_FIELD_crypt, - ) as *const u8; - if ptr.is_null() { - None - } else { - let offset = offset_of!(bch_sb_field_crypt, field); - Some(&*((ptr.sub(offset)) as *const _)) - } - } - } - pub fn uuid(&self) -> uuid::Uuid { - uuid::Uuid::from_bytes(self.user_uuid.b) - } - - /// Get the nonce used to encrypt the superblock - pub fn nonce(&self) -> nonce { - use byteorder::{LittleEndian, ReadBytesExt}; - let mut internal_uuid = &self.uuid.b[..]; - let dword1 = internal_uuid.read_u32::().unwrap(); - let dword2 = internal_uuid.read_u32::().unwrap(); - nonce { - d: [0, 0, dword1, dword2], - } - } -} -impl bch_sb_handle { - pub fn sb(&self) -> &bch_sb { - unsafe { &*self.sb } - } - - pub fn bdev(&self) -> &block_device { - unsafe { &*self.bdev } - } -} - -#[repr(C)] -// #[repr(align(8))] -#[derive(Debug, Default, Copy, Clone)] -pub struct bch_extent_ptr { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, -} - -#[repr(C, packed(8))] -pub struct btree_node { - pub csum: bch_csum, - pub magic: __le64, - pub flags: __le64, - pub min_key: bpos, - pub max_key: bpos, - pub _ptr: bch_extent_ptr, - pub format: bkey_format, - pub __bindgen_anon_1: btree_node__bindgen_ty_1, -} - -#[repr(C, packed(8))] -// #[repr(align(8))] -#[derive(Debug, Default, Copy, Clone)] -pub struct bch_extent_crc32 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - pub csum: __u32, -} - -// #[repr(u8)] -pub enum rhash_lock_head {} -pub enum srcu_struct {} diff --git a/rust-src/bch_bindgen/src/bkey.rs b/rust-src/bch_bindgen/src/bkey.rs deleted file mode 100644 index d4830839..00000000 --- a/rust-src/bch_bindgen/src/bkey.rs +++ /dev/null @@ -1,125 +0,0 @@ -#![allow(non_camel_case_types)] - -use crate::c; -use crate::fs::Fs; -use crate::btree::BtreeIter; -use crate::printbuf_to_formatter; -use std::fmt; -use std::marker::PhantomData; -use std::mem::transmute; - -pub struct BkeySC<'a> { - pub k: &'a c::bkey, - pub v: &'a c::bch_val, - pub(crate) iter: PhantomData<&'a mut BtreeIter<'a>> -} - -pub enum BkeyValC<'a> { - deleted, - whiteout, - error, - cookie(&'a c::bch_cookie), - hash_whiteout(&'a c::bch_hash_whiteout), - btree_ptr(&'a c::bch_btree_ptr), - extent(&'a c::bch_extent), - reservation(&'a c::bch_reservation), - inode(&'a c::bch_inode), - inode_generation(&'a c::bch_inode_generation), - dirent(&'a c::bch_dirent), - xattr(&'a c::bch_xattr), - alloc(&'a c::bch_alloc), - quota(&'a c::bch_quota), - stripe(&'a c::bch_stripe), - reflink_p(&'a c::bch_reflink_p), - reflink_v(&'a c::bch_reflink_v), - inline_data(&'a c::bch_inline_data), - btree_ptr_v2(&'a c::bch_btree_ptr_v2), - indirect_inline_data(&'a c::bch_indirect_inline_data), - alloc_v2(&'a c::bch_alloc_v2), - subvolume(&'a c::bch_subvolume), - snapshot(&'a c::bch_snapshot), - inode_v2(&'a c::bch_inode_v2), - alloc_v3(&'a c::bch_alloc_v3), - set, - lru(&'a c::bch_lru), - alloc_v4(&'a c::bch_alloc_v4), - backpointer(&'a c::bch_backpointer), - inode_v3(&'a c::bch_inode_v3), - bucket_gens(&'a c::bch_bucket_gens), - snapshot_tree(&'a c::bch_snapshot_tree), - logged_op_truncate(&'a c::bch_logged_op_truncate), - logged_op_finsert(&'a c::bch_logged_op_finsert), -} - -impl<'a, 'b> BkeySC<'a> { - unsafe fn to_raw(&self) -> c::bkey_s_c { - c::bkey_s_c { k: self.k, v: self.v } - } - - pub fn to_text(&'a self, fs: &'b Fs) -> BkeySCToText<'a, 'b> { - BkeySCToText { k: self, fs } - } - - pub fn v(&'a self) -> BkeyValC { - let ty: c::bch_bkey_type = unsafe { transmute(self.k.type_ as u32) }; - - use c::bch_bkey_type::*; - use BkeyValC::*; - match ty { - KEY_TYPE_deleted => deleted, - KEY_TYPE_whiteout => whiteout, - KEY_TYPE_error => error, - KEY_TYPE_cookie => cookie(unsafe { transmute(self.v) }), - KEY_TYPE_hash_whiteout => hash_whiteout(unsafe { transmute(self.v) }), - KEY_TYPE_btree_ptr => btree_ptr(unsafe { transmute(self.v) }), - KEY_TYPE_extent => extent(unsafe { transmute(self.v) }), - KEY_TYPE_reservation => reservation(unsafe { transmute(self.v) }), - KEY_TYPE_inode => inode(unsafe { transmute(self.v) }), - KEY_TYPE_inode_generation => inode_generation(unsafe { transmute(self.v) }), - KEY_TYPE_dirent => dirent(unsafe { transmute(self.v) }), - KEY_TYPE_xattr => xattr(unsafe { transmute(self.v) }), - KEY_TYPE_alloc => alloc(unsafe { transmute(self.v) }), - KEY_TYPE_quota => quota(unsafe { transmute(self.v) }), - KEY_TYPE_stripe => stripe(unsafe { transmute(self.v) }), - KEY_TYPE_reflink_p => reflink_p(unsafe { transmute(self.v) }), - KEY_TYPE_reflink_v => reflink_v(unsafe { transmute(self.v) }), - KEY_TYPE_inline_data => inline_data(unsafe { transmute(self.v) }), - KEY_TYPE_btree_ptr_v2 => btree_ptr_v2(unsafe { transmute(self.v) }), - KEY_TYPE_indirect_inline_data => indirect_inline_data(unsafe { transmute(self.v) }), - KEY_TYPE_alloc_v2 => alloc_v2(unsafe { transmute(self.v) }), - KEY_TYPE_subvolume => subvolume(unsafe { transmute(self.v) }), - KEY_TYPE_snapshot => snapshot(unsafe { transmute(self.v) }), - KEY_TYPE_inode_v2 => inode_v2(unsafe { transmute(self.v) }), - KEY_TYPE_alloc_v3 => inode_v3(unsafe { transmute(self.v) }), - KEY_TYPE_set => set, - KEY_TYPE_lru => lru(unsafe { transmute(self.v) }), - KEY_TYPE_alloc_v4 => alloc_v4(unsafe { transmute(self.v) }), - KEY_TYPE_backpointer => backpointer(unsafe { transmute(self.v) }), - KEY_TYPE_inode_v3 => inode_v3(unsafe { transmute(self.v) }), - KEY_TYPE_bucket_gens => bucket_gens(unsafe { transmute(self.v) }), - KEY_TYPE_snapshot_tree => snapshot_tree(unsafe { transmute(self.v) }), - KEY_TYPE_logged_op_truncate => logged_op_truncate(unsafe { transmute(self.v) }), - KEY_TYPE_logged_op_finsert => logged_op_finsert(unsafe { transmute(self.v) }), - KEY_TYPE_MAX => unreachable!(), - } - } -} - -impl<'a> From<&'a c::bkey_i> for BkeySC<'a> { - fn from(k: &'a c::bkey_i) -> Self { - BkeySC { k: &k.k, v: &k.v, iter: PhantomData } - } -} - -pub struct BkeySCToText<'a, 'b> { - k: &'a BkeySC<'a>, - fs: &'b Fs, -} - -impl<'a, 'b> fmt::Display for BkeySCToText<'a, 'b> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - unsafe { - printbuf_to_formatter(f, |buf| c::bch2_bkey_val_to_text(buf, self.fs.raw, self.k.to_raw())) - } - } -} diff --git a/rust-src/bch_bindgen/src/btree.rs b/rust-src/bch_bindgen/src/btree.rs deleted file mode 100644 index 09e86b34..00000000 --- a/rust-src/bch_bindgen/src/btree.rs +++ /dev/null @@ -1,197 +0,0 @@ -use crate::SPOS_MAX; -use crate::c; -use crate::bkey::BkeySC; -use crate::fs::Fs; -use crate::errcode::{bch_errcode, errptr_to_result_c}; -use crate::printbuf_to_formatter; -use std::fmt; -use std::marker::PhantomData; -use std::mem::MaybeUninit; -use bitflags::bitflags; - -pub struct BtreeTrans<'f> { - raw: *mut c::btree_trans, - fs: PhantomData<&'f Fs> -} - -impl<'f> BtreeTrans<'f> { - pub fn new(fs: &'f Fs) -> BtreeTrans { - unsafe { - BtreeTrans { raw: &mut *c::__bch2_trans_get(fs.raw, 0), fs: PhantomData } - } - } -} - -impl<'f> Drop for BtreeTrans<'f> { - fn drop(&mut self) { - unsafe { c::bch2_trans_put(&mut *self.raw) } - } -} - -bitflags! { - pub struct BtreeIterFlags: u16 { - const SLOTS = c::BTREE_ITER_SLOTS as u16; - const INTENT = c::BTREE_ITER_INTENT as u16; - const PREFETCH = c::BTREE_ITER_PREFETCH as u16; - const IS_EXTENTS = c::BTREE_ITER_IS_EXTENTS as u16; - const NOT_EXTENTS = c::BTREE_ITER_NOT_EXTENTS as u16; - const CACHED = c::BTREE_ITER_CACHED as u16; - const KEY_CACHED = c::BTREE_ITER_WITH_KEY_CACHE as u16; - const WITH_UPDATES = c::BTREE_ITER_WITH_UPDATES as u16; - const WITH_JOURNAL = c::BTREE_ITER_WITH_JOURNAL as u16; - const __ALL_SNAPSHOTS = c::__BTREE_ITER_ALL_SNAPSHOTS as u16; - const ALL_SNAPSHOTS = c::BTREE_ITER_ALL_SNAPSHOTS as u16; - const FILTER_SNAPSHOTS = c::BTREE_ITER_FILTER_SNAPSHOTS as u16; - const NOPRESERVE = c::BTREE_ITER_NOPRESERVE as u16; - const CACHED_NOFILL = c::BTREE_ITER_CACHED_NOFILL as u16; - const KEY_CACHE_FILL = c::BTREE_ITER_KEY_CACHE_FILL as u16; - } -} - -pub struct BtreeIter<'t> { - raw: c::btree_iter, - trans: PhantomData<&'t BtreeTrans<'t>>, -} - -impl<'t> BtreeIter<'t> { - pub fn new(trans: &'t BtreeTrans<'t>, btree: c::btree_id, pos: c::bpos, flags: BtreeIterFlags) -> BtreeIter<'t> { - unsafe { - let mut iter: MaybeUninit = MaybeUninit::uninit(); - - c::bch2_trans_iter_init_outlined( - trans.raw, - iter.as_mut_ptr(), - btree, - pos, - flags.bits as u32); - - BtreeIter { raw: iter.assume_init(), trans: PhantomData } - } - } - - pub fn peek_upto<'i>(&'i mut self, end: c::bpos) -> Result, bch_errcode> { - unsafe { - let k = c::bch2_btree_iter_peek_upto(&mut self.raw, end); - errptr_to_result_c(k.k) - .map(|_| if !k.k.is_null() { Some(BkeySC { k: &*k.k, v: &*k.v, iter: PhantomData }) } else { None } ) - } - } - - pub fn peek(&mut self) -> Result, bch_errcode> { - self.peek_upto(SPOS_MAX) - } - - pub fn peek_and_restart(&mut self) -> Result, bch_errcode> { - unsafe { - let k = c::bch2_btree_iter_peek_and_restart_outlined(&mut self.raw); - - errptr_to_result_c(k.k) - .map(|_| if !k.k.is_null() { Some(BkeySC{ k: &*k.k, v: &*k.v, iter: PhantomData }) } else { None } ) - } - } - - pub fn advance(&mut self) { - unsafe { - c::bch2_btree_iter_advance(&mut self.raw); - } - } -} - -impl<'t> Drop for BtreeIter<'t> { - fn drop(&mut self) { - unsafe { c::bch2_trans_iter_exit(self.raw.trans, &mut self.raw) } - } -} - -pub struct BtreeNodeIter<'t> { - raw: c::btree_iter, - trans: PhantomData<&'t BtreeTrans<'t>>, -} - -impl<'t> BtreeNodeIter<'t> { - pub fn new(trans: &'t BtreeTrans<'t>, - btree: c::btree_id, - pos: c::bpos, - locks_want: u32, - depth: u32, - flags: BtreeIterFlags) -> BtreeNodeIter { - unsafe { - let mut iter: MaybeUninit = MaybeUninit::uninit(); - c::bch2_trans_node_iter_init( - trans.raw, - iter.as_mut_ptr(), - btree, - pos, - locks_want, - depth, - flags.bits as u32); - - BtreeNodeIter { raw: iter.assume_init(), trans: PhantomData } - } - } - - pub fn peek<'i>(&'i mut self) -> Result, bch_errcode> { - unsafe { - let b = c::bch2_btree_iter_peek_node(&mut self.raw); - errptr_to_result_c(b).map(|b| if !b.is_null() { Some(&*b) } else { None }) - } - } - - pub fn peek_and_restart<'i>(&'i mut self) -> Result, bch_errcode> { - unsafe { - let b = c::bch2_btree_iter_peek_node_and_restart(&mut self.raw); - errptr_to_result_c(b).map(|b| if !b.is_null() { Some(&*b) } else { None }) - } - } - - pub fn advance<'i>(&'i mut self) { - unsafe { - c::bch2_btree_iter_next_node(&mut self.raw); - } - } - - pub fn next<'i>(&'i mut self) -> Result, bch_errcode> { - unsafe { - let b = c::bch2_btree_iter_next_node(&mut self.raw); - errptr_to_result_c(b).map(|b| if !b.is_null() { Some(&*b) } else { None }) - } - } -} - -impl<'t> Drop for BtreeNodeIter<'t> { - fn drop(&mut self) { - unsafe { c::bch2_trans_iter_exit(self.raw.trans, &mut self.raw) } - } -} - -impl<'b, 'f> c::btree { - pub fn to_text(&'b self, fs: &'f Fs) -> BtreeNodeToText<'b, 'f> { - BtreeNodeToText { b: &self, fs } - } - - pub fn ondisk_to_text(&'b self, fs: &'f Fs) -> BtreeNodeOndiskToText<'b, 'f> { - BtreeNodeOndiskToText { b: &self, fs } - } -} - -pub struct BtreeNodeToText<'b, 'f> { - b: &'b c::btree, - fs: &'f Fs, -} - -impl<'b, 'f> fmt::Display for BtreeNodeToText<'b, 'f> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - printbuf_to_formatter(f, |buf| unsafe { c::bch2_btree_node_to_text(buf, self.fs.raw, self.b) }) - } -} - -pub struct BtreeNodeOndiskToText<'b, 'f> { - b: &'b c::btree, - fs: &'f Fs, -} - -impl<'b, 'f> fmt::Display for BtreeNodeOndiskToText<'b, 'f> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - printbuf_to_formatter(f, |buf| unsafe { c::bch2_btree_node_ondisk_to_text(buf, self.fs.raw, self.b) }) - } -} diff --git a/rust-src/bch_bindgen/src/errcode.rs b/rust-src/bch_bindgen/src/errcode.rs deleted file mode 100644 index 4d75f1d2..00000000 --- a/rust-src/bch_bindgen/src/errcode.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::bcachefs; -use std::ffi::CStr; -use std::fmt; - -pub use crate::c::bch_errcode; - -impl fmt::Display for bch_errcode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = unsafe { CStr::from_ptr(bcachefs::bch2_err_str(*self as i32)) }; - write!(f, "{:?}", s) - } -} - -/* Can we make a function generic over ptr constness? */ - -pub fn errptr_to_result(p: *mut T) -> Result<*mut T, bch_errcode> { - let addr = p as usize; - let max_err: isize = -4096; - if addr > max_err as usize { - let addr = addr as i32; - let err: bch_errcode = unsafe { std::mem::transmute(-addr) }; - Err(err) - } else { - Ok(p) - } -} - -pub fn errptr_to_result_c(p: *const T) -> Result<*const T, bch_errcode> { - let addr = p as usize; - let max_err: isize = -4096; - if addr > max_err as usize { - let addr = addr as i32; - let err: bch_errcode = unsafe { std::mem::transmute(-addr) }; - Err(err) - } else { - Ok(p) - } -} - -impl std::error::Error for bch_errcode {} diff --git a/rust-src/bch_bindgen/src/fs.rs b/rust-src/bch_bindgen/src/fs.rs deleted file mode 100644 index b26c51b6..00000000 --- a/rust-src/bch_bindgen/src/fs.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::ffi::CString; -use std::os::unix::ffi::OsStrExt; -use std::path::PathBuf; -use crate::c; -use crate::errcode::{bch_errcode, errptr_to_result}; - -pub struct Fs { - pub raw: *mut c::bch_fs, -} - -impl Fs { - pub fn open(devs: &Vec, opts: c::bch_opts) -> Result { - let devs: Vec<_> = devs.iter() - .map(|i| CString::new(i.as_os_str().as_bytes()).unwrap().into_raw()) - .collect(); - - let ret = unsafe { c::bch2_fs_open(devs[..].as_ptr(), devs.len() as u32, opts) }; - - errptr_to_result(ret).map(|fs| Fs { raw: fs}) - } -} - -impl Drop for Fs { - fn drop(&mut self) { - unsafe { c::bch2_fs_stop(self.raw) } - } -} diff --git a/rust-src/bch_bindgen/src/keyutils.rs b/rust-src/bch_bindgen/src/keyutils.rs deleted file mode 100644 index 30fc56f9..00000000 --- a/rust-src/bch_bindgen/src/keyutils.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(unused)] - -include!(concat!(env!("OUT_DIR"), "/keyutils.rs")); diff --git a/rust-src/bch_bindgen/src/keyutils_wrapper.h b/rust-src/bch_bindgen/src/keyutils_wrapper.h deleted file mode 100644 index 857cee2e..00000000 --- a/rust-src/bch_bindgen/src/keyutils_wrapper.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs deleted file mode 100644 index 4c549442..00000000 --- a/rust-src/bch_bindgen/src/lib.rs +++ /dev/null @@ -1,168 +0,0 @@ -pub mod bcachefs; -pub mod btree; -pub mod bkey; -pub mod errcode; -pub mod keyutils; -pub mod rs; -pub mod fs; -pub mod opts; -pub use paste::paste; - -pub mod c { - pub use crate::bcachefs::*; -} - -use c::bpos as Bpos; - -pub const fn spos(inode: u64, offset: u64, snapshot: u32) -> Bpos { - Bpos { inode, offset, snapshot } -} - -pub const fn pos(inode: u64, offset: u64) -> Bpos { - spos(inode, offset, 0) -} - -pub const POS_MIN: Bpos = spos(0, 0, 0); -pub const POS_MAX: Bpos = spos(u64::MAX, u64::MAX, 0); -pub const SPOS_MAX: Bpos = spos(u64::MAX, u64::MAX, u32::MAX); - -use std::cmp::Ordering; - -impl PartialEq for Bpos { - fn eq(&self, other: &Self) -> bool { - self.cmp(other) == Ordering::Equal - } -} - -impl Eq for Bpos {} - -impl PartialOrd for Bpos { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for Bpos { - fn cmp(&self, other: &Self) -> Ordering { - let l_inode = self.inode; - let r_inode = other.inode; - let l_offset = self.offset; - let r_offset = other.offset; - let l_snapshot = self.snapshot; - let r_snapshot = other.snapshot; - - l_inode.cmp(&r_inode) - .then(l_offset.cmp(&r_offset)) - .then(l_snapshot.cmp(&r_snapshot)) - } -} - -use std::ffi::CStr; -use std::fmt; - -impl fmt::Display for c::btree_id { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = unsafe { CStr::from_ptr(c::bch2_btree_id_str(*self)) }; - let s = s.to_str().unwrap(); - write!(f, "{}", s) - } -} - -use std::str::FromStr; -use std::ffi::CString; - -use std::error::Error; - -#[derive(Debug)] -pub struct InvalidBtreeId; - -impl fmt::Display for InvalidBtreeId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "invalid btree id") - } -} - -impl Error for InvalidBtreeId { -} - -impl FromStr for c::btree_id { - type Err = InvalidBtreeId; - - fn from_str(s: &str) -> Result { - let s = CString::new(s).unwrap(); - let p = s.as_ptr(); - - let v = unsafe {c::match_string(c::__bch2_btree_ids[..].as_ptr(), (-(1 as isize)) as usize, p)}; - if v >= 0 { - Ok(unsafe { std::mem::transmute(v) }) - } else { - Err(InvalidBtreeId) - } - } -} - -impl c::printbuf { - fn new() -> c::printbuf { - let mut buf: c::printbuf = Default::default(); - - buf.set_heap_allocated(true); - buf - } -} - -impl Drop for c::printbuf { - fn drop(&mut self) { - unsafe { c::bch2_printbuf_exit(self) } - } -} - -impl fmt::Display for Bpos { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut buf = c::printbuf::new(); - - unsafe { c::bch2_bpos_to_text(&mut buf, *self) }; - - let s = unsafe { CStr::from_ptr(buf.buf) }; - let s = s.to_str().unwrap(); - write!(f, "{}", s) - } -} - -impl FromStr for c::bpos { - type Err = InvalidBtreeId; - - fn from_str(s: &str) -> Result { - if s == "POS_MIN" { - return Ok(POS_MIN); - } - - if s == "POS_MAX" { - return Ok(POS_MAX); - } - - if s == "SPOS_MAX" { - return Ok(SPOS_MAX); - } - - let mut fields = s.split(':'); - let ino_str = fields.next().ok_or(InvalidBtreeId)?; - let off_str = fields.next().ok_or(InvalidBtreeId)?; - let snp_str = fields.next(); - - let ino: u64 = ino_str.parse().map_err(|_| InvalidBtreeId)?; - let off: u64 = off_str.parse().map_err(|_| InvalidBtreeId)?; - let snp: u32 = snp_str.map(|s| s.parse().ok()).flatten().unwrap_or(0); - - Ok(c::bpos { inode: ino, offset: off, snapshot: snp }) - } -} - -pub fn printbuf_to_formatter(f: &mut fmt::Formatter<'_>, func: F) -> fmt::Result - where F: Fn(*mut c::printbuf) { - let mut buf = c::printbuf::new(); - - func(&mut buf); - - let s = unsafe { CStr::from_ptr(buf.buf) }; - f.write_str(s.to_str().unwrap()) -} diff --git a/rust-src/bch_bindgen/src/libbcachefs_wrapper.h b/rust-src/bch_bindgen/src/libbcachefs_wrapper.h deleted file mode 100644 index 5fb42613..00000000 --- a/rust-src/bch_bindgen/src/libbcachefs_wrapper.h +++ /dev/null @@ -1,22 +0,0 @@ -#include "../libbcachefs/super-io.h" -#include "../libbcachefs/checksum.h" -#include "../libbcachefs/bcachefs_format.h" -#include "../libbcachefs/btree_cache.h" -#include "../libbcachefs/btree_iter.h" -#include "../libbcachefs/debug.h" -#include "../libbcachefs/errcode.h" -#include "../libbcachefs/error.h" -#include "../libbcachefs/opts.h" -#include "../libbcachefs.h" -#include "../crypto.h" -#include "../include/linux/bio.h" -#include "../include/linux/blkdev.h" -#include "../cmds.h" -#include "../raid/raid.h" - - -#define MARK_FIX_753(req_name) const blk_mode_t Fix753_##req_name = req_name; - -MARK_FIX_753(BLK_OPEN_READ); -MARK_FIX_753(BLK_OPEN_WRITE); -MARK_FIX_753(BLK_OPEN_EXCL); diff --git a/rust-src/bch_bindgen/src/opts.rs b/rust-src/bch_bindgen/src/opts.rs deleted file mode 100644 index d38d469c..00000000 --- a/rust-src/bch_bindgen/src/opts.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[macro_export] -macro_rules! opt_set { - ($opts:ident, $n:ident, $v:expr) => { - bch_bindgen::paste! { - $opts.$n = $v; - $opts.[](1) - } - }; -} - -#[macro_export] -macro_rules! opt_defined { - ($opts:ident, $n:ident) => { - bch_bindgen::paste! { - $opts.[< $n _defined>]() - } - }; -} - -#[macro_export] -macro_rules! opt_get { - ($opts:ident, $n:ident) => { - if bch_bindgen::opt_defined!($opts, $n) == 0 { - bch_bindgen::paste! { - unsafe { - bch_bindgen::bcachefs::bch2_opts_default.$n - } - } - } else { - bch_bindgen::paste! { - $opts.$n - } - } - }; -} diff --git a/rust-src/bch_bindgen/src/rs.rs b/rust-src/bch_bindgen/src/rs.rs deleted file mode 100644 index 24594ae1..00000000 --- a/rust-src/bch_bindgen/src/rs.rs +++ /dev/null @@ -1,29 +0,0 @@ -use anyhow::anyhow; -use crate::bcachefs; -use crate::bcachefs::*; -use crate::errcode::bch_errcode; - -pub fn read_super_opts( - path: &std::path::Path, - mut opts: bch_opts, -) -> anyhow::Result { - use std::os::unix::ffi::OsStrExt; - let path = std::ffi::CString::new(path.as_os_str().as_bytes()).unwrap(); - - let mut sb = std::mem::MaybeUninit::zeroed(); - - let ret = - unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) }; - - if ret != 0 { - let err: bch_errcode = unsafe { ::std::mem::transmute(ret) }; - Err(anyhow!(err)) - } else { - Ok(unsafe { sb.assume_init() }) - } -} - -pub fn read_super(path: &std::path::Path) -> anyhow::Result { - let opts = bcachefs::bch_opts::default(); - read_super_opts(path, opts) -} diff --git a/rust-src/build.rs b/rust-src/build.rs deleted file mode 100644 index e4662bd7..00000000 --- a/rust-src/build.rs +++ /dev/null @@ -1,21 +0,0 @@ -fn main() { - println!("cargo:rustc-link-search=.."); - println!("cargo:rerun-if-changed=../libbcachefs.a"); - println!("cargo:rustc-link-lib=static:+whole-archive=bcachefs"); - - println!("cargo:rustc-link-lib=urcu"); - println!("cargo:rustc-link-lib=zstd"); - println!("cargo:rustc-link-lib=blkid"); - println!("cargo:rustc-link-lib=uuid"); - println!("cargo:rustc-link-lib=sodium"); - println!("cargo:rustc-link-lib=z"); - println!("cargo:rustc-link-lib=lz4"); - println!("cargo:rustc-link-lib=zstd"); - println!("cargo:rustc-link-lib=udev"); - println!("cargo:rustc-link-lib=keyutils"); - println!("cargo:rustc-link-lib=aio"); - - if std::env::var("BCACHEFS_FUSE").is_ok() { - println!("cargo:rustc-link-lib=fuse3"); - } -} diff --git a/rust-src/rustfmt.toml b/rust-src/rustfmt.toml deleted file mode 100644 index 42f2ad7c..00000000 --- a/rust-src/rustfmt.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Default settings, i.e. idiomatic rust -edition = "2021" -newline_style = "Unix" \ No newline at end of file diff --git a/rust-src/src/bcachefs.rs b/rust-src/src/bcachefs.rs deleted file mode 100644 index 95f5e1f0..00000000 --- a/rust-src/src/bcachefs.rs +++ /dev/null @@ -1,120 +0,0 @@ -mod commands; -mod key; - -use std::ffi::CString; - -use commands::cmd_completions::cmd_completions; -use commands::cmd_list::cmd_list; -use commands::cmd_mount::cmd_mount; -use commands::logger::SimpleLogger; -use bch_bindgen::c; - -#[derive(Debug)] -pub struct ErrnoError(pub errno::Errno); -impl std::fmt::Display for ErrnoError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - self.0.fmt(f) - } -} - -impl std::error::Error for ErrnoError {} - -fn handle_c_command(args: Vec, symlink_cmd: Option<&str>) -> i32 { - let mut argv: Vec<_> = args.clone(); - - let cmd = match symlink_cmd { - Some(s) => s.to_string(), - None => argv.remove(1), - }; - - let argc: i32 = argv.len().try_into().unwrap(); - - let argv: Vec<_> = argv - .iter() - .map(|s| CString::new(s.as_str()).unwrap()) - .collect(); - let argv: Vec<_> = argv.iter().map(|s| s.as_ptr()).collect(); - let argv = argv.as_ptr() as *mut *mut i8; - - // The C functions will mutate argv. It shouldn't be used after this block. - unsafe { - match cmd.as_str() { - "--help" => { - c::bcachefs_usage(); - 0 - }, - "data" => c::data_cmds(argc, argv), - "device" => c::device_cmds(argc, argv), - "dump" => c::cmd_dump(argc, argv), - "format" => c::cmd_format(argc, argv), - "fs" => c::fs_cmds(argc, argv), - "fsck" => c::cmd_fsck(argc, argv), - "list_journal" => c::cmd_list_journal(argc, argv), - "kill_btree_node" => c::cmd_kill_btree_node(argc, argv), - "migrate" => c::cmd_migrate(argc, argv), - "migrate-superblock" => c::cmd_migrate_superblock(argc, argv), - "mkfs" => c::cmd_format(argc, argv), - "remove-passphrase" => c::cmd_remove_passphrase(argc, argv), - "reset-counters" => c::cmd_reset_counters(argc, argv), - "set-option" => c::cmd_set_option(argc, argv), - "set-passphrase" => c::cmd_set_passphrase(argc, argv), - "setattr" => c::cmd_setattr(argc, argv), - "show-super" => c::cmd_show_super(argc, argv), - "subvolume" => c::subvolume_cmds(argc, argv), - "unlock" => c::cmd_unlock(argc, argv), - "version" => c::cmd_version(argc, argv), - - #[cfg(fuse)] - "fusemount" => c::cmd_fusemount(argc, argv), - - _ => { - println!("Unknown command {}", cmd); - c::bcachefs_usage(); - 1 - } - } - } -} - -fn main() { - let args: Vec = std::env::args().collect(); - - let symlink_cmd: Option<&str> = if args[0].contains("mkfs") { - Some("mkfs") - } else if args[0].contains("fsck") { - Some("fsck") - } else if args[0].contains("mount.fuse") { - Some("fusemount") - } else if args[0].contains("mount") { - Some("mount") - } else { - None - }; - - if symlink_cmd.is_none() && args.len() < 2 { - println!("missing command"); - unsafe { c::bcachefs_usage() }; - std::process::exit(1); - } - - unsafe { c::raid_init() }; - - log::set_boxed_logger(Box::new(SimpleLogger)).unwrap(); - log::set_max_level(log::LevelFilter::Warn); - - let cmd = match symlink_cmd { - Some(s) => s, - None => args[1].as_str(), - }; - - let ret = match cmd { - "completions" => cmd_completions(args[1..].to_vec()), - "list" => cmd_list(args[1..].to_vec()), - "mount" => cmd_mount(args, symlink_cmd), - _ => handle_c_command(args, symlink_cmd), - }; - - if ret != 0 { - std::process::exit(1); - } -} diff --git a/rust-src/src/commands/cmd_completions.rs b/rust-src/src/commands/cmd_completions.rs deleted file mode 100644 index 53cdd643..00000000 --- a/rust-src/src/commands/cmd_completions.rs +++ /dev/null @@ -1,19 +0,0 @@ -use clap::{Command, CommandFactory, Parser}; -use clap_complete::{generate, Generator, Shell}; -use std::io; - -/// Generate shell completions -#[derive(clap::Parser, Debug)] -pub struct Cli { - shell: Shell, -} - -fn print_completions(gen: G, cmd: &mut Command) { - generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); -} - -pub fn cmd_completions(argv: Vec) -> i32 { - let cli = Cli::parse_from(argv); - print_completions(cli.shell, &mut super::Cli::command()); - 0 -} diff --git a/rust-src/src/commands/cmd_list.rs b/rust-src/src/commands/cmd_list.rs deleted file mode 100644 index cb352916..00000000 --- a/rust-src/src/commands/cmd_list.rs +++ /dev/null @@ -1,168 +0,0 @@ -use atty::Stream; -use log::{error}; -use bch_bindgen::bcachefs; -use bch_bindgen::opt_set; -use bch_bindgen::fs::Fs; -use bch_bindgen::bkey::BkeySC; -use bch_bindgen::btree::BtreeTrans; -use bch_bindgen::btree::BtreeIter; -use bch_bindgen::btree::BtreeNodeIter; -use bch_bindgen::btree::BtreeIterFlags; -use clap::{Parser}; - -fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> { - let trans = BtreeTrans::new(fs); - let mut iter = BtreeIter::new(&trans, opt.btree, opt.start, - BtreeIterFlags::ALL_SNAPSHOTS| - BtreeIterFlags::PREFETCH); - - while let Some(k) = iter.peek_and_restart()? { - if k.k.p > opt.end { - break; - } - - println!("{}", k.to_text(fs)); - iter.advance(); - } - - Ok(()) -} - -fn list_btree_formats(fs: &Fs, opt: Cli) -> anyhow::Result<()> { - let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); - - while let Some(b) = iter.peek_and_restart()? { - if b.key.k.p > opt.end { - break; - } - - println!("{}", b.to_text(fs)); - iter.advance(); - } - - Ok(()) -} - -fn list_btree_nodes(fs: &Fs, opt: Cli) -> anyhow::Result<()> { - let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); - - while let Some(b) = iter.peek_and_restart()? { - if b.key.k.p > opt.end { - break; - } - - println!("{}", BkeySC::from(&b.key).to_text(fs)); - iter.advance(); - } - - Ok(()) -} - -fn list_nodes_ondisk(fs: &Fs, opt: Cli) -> anyhow::Result<()> { - let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); - - while let Some(b) = iter.peek_and_restart()? { - if b.key.k.p > opt.end { - break; - } - - println!("{}", b.ondisk_to_text(fs)); - iter.advance(); - } - - Ok(()) -} - -#[derive(Clone, clap::ValueEnum, Debug)] -enum Mode { - Keys, - Formats, - Nodes, - NodesOndisk, -} - -/// List filesystem metadata in textual form -#[derive(Parser, Debug)] -pub struct Cli { - /// Btree to list from - #[arg(short, long, default_value_t=bcachefs::btree_id::BTREE_ID_extents)] - btree: bcachefs::btree_id, - - /// Btree depth to descend to (0 == leaves) - #[arg(short, long, default_value_t=0)] - level: u32, - - /// Start position to list from - #[arg(short, long, default_value="POS_MIN")] - start: bcachefs::bpos, - - /// End position - #[arg(short, long, default_value="SPOS_MAX")] - end: bcachefs::bpos, - - #[arg(short, long, default_value="keys")] - mode: Mode, - - /// Check (fsck) the filesystem first - #[arg(short, long, default_value_t=false)] - fsck: bool, - - /// Force color on/off. Default: autodetect tty - #[arg(short, long, action = clap::ArgAction::Set, default_value_t=atty::is(Stream::Stdout))] - colorize: bool, - - /// Verbose mode - #[arg(short, long)] - verbose: bool, - - #[arg(required(true))] - devices: Vec, -} - -fn cmd_list_inner(opt: Cli) -> anyhow::Result<()> { - let mut fs_opts: bcachefs::bch_opts = Default::default(); - - opt_set!(fs_opts, nochanges, 1); - opt_set!(fs_opts, read_only, 1); - opt_set!(fs_opts, norecovery, 1); - opt_set!(fs_opts, degraded, 1); - opt_set!(fs_opts, errors, bcachefs::bch_error_actions::BCH_ON_ERROR_continue as u8); - - if opt.fsck { - opt_set!(fs_opts, fix_errors, bcachefs::fsck_err_opts::FSCK_FIX_yes as u8); - opt_set!(fs_opts, norecovery, 0); - } - - if opt.verbose { - opt_set!(fs_opts, verbose, 1); - } - - let fs = Fs::open(&opt.devices, fs_opts)?; - - match opt.mode { - Mode::Keys => list_keys(&fs, opt), - Mode::Formats => list_btree_formats(&fs, opt), - Mode::Nodes => list_btree_nodes(&fs, opt), - Mode::NodesOndisk => list_nodes_ondisk(&fs, opt), - } -} - -pub fn cmd_list(argv: Vec) -> i32 { - let opt = Cli::parse_from(argv); - colored::control::set_override(opt.colorize); - if let Err(e) = cmd_list_inner(opt) { - error!("Fatal error: {}", e); - 1 - } else { - 0 - } -} diff --git a/rust-src/src/commands/cmd_mount.rs b/rust-src/src/commands/cmd_mount.rs deleted file mode 100644 index b120c91e..00000000 --- a/rust-src/src/commands/cmd_mount.rs +++ /dev/null @@ -1,251 +0,0 @@ -use atty::Stream; -use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle, opt_set}; -use log::{info, debug, error, LevelFilter}; -use clap::{Parser}; -use uuid::Uuid; -use std::path::PathBuf; -use crate::key; -use crate::key::KeyLocation; -use std::ffi::{CString, c_char, c_void}; -use std::os::unix::ffi::OsStrExt; - -fn mount_inner( - src: String, - target: impl AsRef, - fstype: &str, - mountflags: libc::c_ulong, - data: Option, -) -> anyhow::Result<()> { - - // bind the CStrings to keep them alive - let src = CString::new(src)?; - let target = CString::new(target.as_ref().as_os_str().as_bytes())?; - let data = data.map(CString::new).transpose()?; - let fstype = CString::new(fstype)?; - - // convert to pointers for ffi - let src = src.as_c_str().to_bytes_with_nul().as_ptr() as *const c_char; - let target = target.as_c_str().to_bytes_with_nul().as_ptr() as *const c_char; - let data = data.as_ref().map_or(std::ptr::null(), |data| { - data.as_c_str().to_bytes_with_nul().as_ptr() as *const c_void - }); - let fstype = fstype.as_c_str().to_bytes_with_nul().as_ptr() as *const c_char; - - let ret = { - info!("mounting filesystem"); - // REQUIRES: CAP_SYS_ADMIN - unsafe { libc::mount(src, target, fstype, mountflags, data) } - }; - match ret { - 0 => Ok(()), - _ => Err(crate::ErrnoError(errno::errno()).into()), - } -} - -/// Parse a comma-separated mount options and split out mountflags and filesystem -/// specific options. -fn parse_mount_options(options: impl AsRef) -> (Option, libc::c_ulong) { - use either::Either::*; - debug!("parsing mount options: {}", options.as_ref()); - let (opts, flags) = options - .as_ref() - .split(",") - .map(|o| match o { - "dirsync" => Left(libc::MS_DIRSYNC), - "lazytime" => Left(1 << 25), // MS_LAZYTIME - "mand" => Left(libc::MS_MANDLOCK), - "noatime" => Left(libc::MS_NOATIME), - "nodev" => Left(libc::MS_NODEV), - "nodiratime" => Left(libc::MS_NODIRATIME), - "noexec" => Left(libc::MS_NOEXEC), - "nosuid" => Left(libc::MS_NOSUID), - "relatime" => Left(libc::MS_RELATIME), - "remount" => Left(libc::MS_REMOUNT), - "ro" => Left(libc::MS_RDONLY), - "rw" => Left(0), - "strictatime" => Left(libc::MS_STRICTATIME), - "sync" => Left(libc::MS_SYNCHRONOUS), - "" => Left(0), - o @ _ => Right(o), - }) - .fold((Vec::new(), 0), |(mut opts, flags), next| match next { - Left(f) => (opts, flags | f), - Right(o) => { - opts.push(o); - (opts, flags) - } - }); - - ( - if opts.len() == 0 { - None - } else { - Some(opts.join(",")) - }, - flags, - ) -} - -fn mount( - device: String, - target: impl AsRef, - options: impl AsRef, -) -> anyhow::Result<()> { - let (data, mountflags) = parse_mount_options(options); - - info!( - "mounting bcachefs filesystem, {}", - target.as_ref().display() - ); - mount_inner(device, target, "bcachefs", mountflags, data) -} - -fn read_super_silent(path: &std::path::PathBuf) -> anyhow::Result { - // Stop libbcachefs from spamming the output - let _gag = gag::BufferRedirect::stdout().unwrap(); - - let mut opts = bcachefs::bch_opts::default(); - opt_set!(opts, noexcl, 1); - - bch_bindgen::rs::read_super_opts(&path, opts) -} - -fn get_devices_by_uuid(uuid: Uuid) -> anyhow::Result> { - debug!("enumerating udev devices"); - let mut udev = udev::Enumerator::new()?; - - udev.match_subsystem("block")?; - - let devs = udev - .scan_devices()? - .into_iter() - .filter_map(|dev| dev.devnode().map(ToOwned::to_owned)) - .map(|dev| (dev.clone(), read_super_silent(&dev))) - .filter_map(|(dev, sb)| sb.ok().map(|sb| (dev, sb))) - .filter(|(_, sb)| sb.sb().uuid() == uuid) - .collect(); - Ok(devs) -} - -/// Mount a bcachefs filesystem by its UUID. -#[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -pub struct Cli { - /// Where the password would be loaded from. - /// - /// Possible values are: - /// "fail" - don't ask for password, fail if filesystem is encrypted; - /// "wait" - wait for password to become available before mounting; - /// "ask" - prompt the user for password; - #[arg(short, long, default_value = "ask", verbatim_doc_comment)] - key_location: KeyLocation, - - /// Device, or UUID= - dev: String, - - /// Where the filesystem should be mounted. If not set, then the filesystem - /// won't actually be mounted. But all steps preceeding mounting the - /// filesystem (e.g. asking for passphrase) will still be performed. - mountpoint: Option, - - /// Mount options - #[arg(short, default_value = "")] - options: String, - - /// Force color on/off. Default: autodetect tty - #[arg(short, long, action = clap::ArgAction::Set, default_value_t=atty::is(Stream::Stdout))] - colorize: bool, - - /// Verbose mode - #[arg(short, long, action = clap::ArgAction::Count)] - verbose: u8, -} - -fn devs_str_sbs_from_uuid(uuid: String) -> anyhow::Result<(String, Vec)> { - debug!("enumerating devices with UUID {}", uuid); - - let devs_sbs = Uuid::parse_str(&uuid) - .map(|uuid| get_devices_by_uuid(uuid))??; - - let devs_str = devs_sbs - .iter() - .map(|(dev, _)| dev.to_str().unwrap()) - .collect::>() - .join(":"); - - let sbs: Vec = devs_sbs.iter().map(|(_, sb)| *sb).collect(); - - Ok((devs_str, sbs)) - -} - -fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> { - let (devs, sbs) = if opt.dev.starts_with("UUID=") { - let uuid = opt.dev.replacen("UUID=", "", 1); - devs_str_sbs_from_uuid(uuid)? - } else if opt.dev.starts_with("OLD_BLKID_UUID=") { - let uuid = opt.dev.replacen("OLD_BLKID_UUID=", "", 1); - devs_str_sbs_from_uuid(uuid)? - } else { - let mut sbs = Vec::new(); - - for dev in opt.dev.split(':') { - let dev = PathBuf::from(dev); - sbs.push(read_super_silent(&dev)?); - } - - (opt.dev, sbs) - }; - - if sbs.len() == 0 { - Err(anyhow::anyhow!("No device found from specified parameters"))?; - } else if unsafe { bcachefs::bch2_sb_is_encrypted(sbs[0].sb) } { - key::prepare_key(&sbs[0], opt.key_location)?; - } - - if let Some(mountpoint) = opt.mountpoint { - info!( - "mounting with params: device: {}, target: {}, options: {}", - devs, - mountpoint.to_string_lossy(), - &opt.options - ); - - mount(devs, mountpoint, &opt.options)?; - } else { - info!( - "would mount with params: device: {}, options: {}", - devs, - &opt.options - ); - } - - Ok(()) -} - -pub fn cmd_mount(mut argv: Vec, symlink_cmd: Option<&str>) -> i32 { - // 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. - if symlink_cmd.is_none() { - argv.remove(0); - } - - let opt = Cli::parse_from(argv); - - // @TODO : more granular log levels via mount option - log::set_max_level(match opt.verbose { - 0 => LevelFilter::Warn, - 1 => LevelFilter::Trace, - 2_u8..=u8::MAX => todo!(), - }); - - colored::control::set_override(opt.colorize); - if let Err(e) = cmd_mount_inner(opt) { - error!("Fatal error: {}", e); - 1 - } else { - info!("Successfully mounted"); - 0 - } -} diff --git a/rust-src/src/commands/logger.rs b/rust-src/src/commands/logger.rs deleted file mode 100644 index 2cd7b363..00000000 --- a/rust-src/src/commands/logger.rs +++ /dev/null @@ -1,28 +0,0 @@ -use colored::Colorize; -use log::{Level, Metadata, Record}; - -pub struct SimpleLogger; - -impl log::Log for SimpleLogger { - fn enabled(&self, _: &Metadata) -> bool { - true - } - - fn log(&self, record: &Record) { - let debug_prefix = match record.level() { - Level::Error => "ERROR".bright_red(), - Level::Warn => "WARN".bright_yellow(), - Level::Info => "INFO".green(), - Level::Debug => "DEBUG".bright_blue(), - Level::Trace => "TRACE".into(), - }; - println!( - "{} - {}: {}", - debug_prefix, - record.module_path().unwrap_or_default().bright_black(), - record.args() - ); - } - - fn flush(&self) {} -} diff --git a/rust-src/src/commands/mod.rs b/rust-src/src/commands/mod.rs deleted file mode 100644 index e05a0848..00000000 --- a/rust-src/src/commands/mod.rs +++ /dev/null @@ -1,31 +0,0 @@ -use clap::Subcommand; - -pub mod logger; -pub mod cmd_mount; -pub mod cmd_list; -pub mod cmd_completions; - -#[derive(clap::Parser, Debug)] -#[command(name = "bcachefs")] -pub struct Cli { - #[command(subcommand)] - subcommands: Subcommands, -} - -#[derive(Subcommand, Debug)] -enum Subcommands { - List(cmd_list::Cli), - Mount(cmd_mount::Cli), - Completions(cmd_completions::Cli), -} - -#[macro_export] -macro_rules! c_str { - ($lit:expr) => { - unsafe { - std::ffi::CStr::from_ptr(concat!($lit, "\0").as_ptr() as *const std::os::raw::c_char) - .to_bytes_with_nul() - .as_ptr() as *const std::os::raw::c_char - } - }; -} diff --git a/rust-src/src/key.rs b/rust-src/src/key.rs deleted file mode 100644 index 93daa263..00000000 --- a/rust-src/src/key.rs +++ /dev/null @@ -1,144 +0,0 @@ -use log::{info}; -use bch_bindgen::bcachefs::bch_sb_handle; -use clap::builder::PossibleValue; -use crate::c_str; -use anyhow::anyhow; - -#[derive(Clone, Debug)] -pub enum KeyLocation { - None, - Fail, - Wait, - Ask, -} - -impl std::str::FromStr for KeyLocation { - type Err = anyhow::Error; - fn from_str(s: &str) -> anyhow::Result { - match s { - ""|"none" => Ok(KeyLocation::None), - "fail" => Ok(KeyLocation::Fail), - "wait" => Ok(KeyLocation::Wait), - "ask" => Ok(KeyLocation::Ask), - _ => Err(anyhow!("invalid password option")), - } - } -} - -impl clap::ValueEnum for KeyLocation { - fn value_variants<'a>() -> &'a [Self] { - &[ - KeyLocation::None, - KeyLocation::Fail, - KeyLocation::Wait, - KeyLocation::Ask, - ] - } - - fn to_possible_value(&self) -> Option { - Some(match self { - Self::None => PossibleValue::new("none").alias(""), - Self::Fail => PossibleValue::new("fail"), - Self::Wait => PossibleValue::new("wait"), - Self::Ask => PossibleValue::new("ask"), - }) - } -} - -fn check_for_key(key_name: &std::ffi::CStr) -> anyhow::Result { - use bch_bindgen::keyutils::{self, keyctl_search}; - let key_name = key_name.to_bytes_with_nul().as_ptr() as *const _; - let key_type = c_str!("user"); - - let key_id = unsafe { keyctl_search(keyutils::KEY_SPEC_USER_KEYRING, key_type, key_name, 0) }; - if key_id > 0 { - info!("Key has became available"); - Ok(true) - } else { - match errno::errno().0 { - libc::ENOKEY | libc::EKEYREVOKED => Ok(false), - _ => Err(crate::ErrnoError(errno::errno()).into()), - } - } -} - -fn wait_for_key(uuid: &uuid::Uuid) -> anyhow::Result<()> { - let key_name = std::ffi::CString::new(format!("bcachefs:{}", uuid)).unwrap(); - loop { - if check_for_key(&key_name)? { - break Ok(()); - } - - std::thread::sleep(std::time::Duration::from_secs(1)); - } -} - -const BCH_KEY_MAGIC: &str = "bch**key"; -fn ask_for_key(sb: &bch_sb_handle) -> anyhow::Result<()> { - use bch_bindgen::bcachefs::{self, bch2_chacha_encrypt_key, bch_encrypted_key, bch_key}; - use byteorder::{LittleEndian, ReadBytesExt}; - use std::os::raw::c_char; - - let key_name = std::ffi::CString::new(format!("bcachefs:{}", sb.sb().uuid())).unwrap(); - if check_for_key(&key_name)? { - return Ok(()); - } - - let bch_key_magic = BCH_KEY_MAGIC.as_bytes().read_u64::().unwrap(); - let crypt = sb.sb().crypt().unwrap(); - let pass = if atty::is(atty::Stream::Stdin) { - rpassword::read_password_from_tty(Some("Enter passphrase: "))? - } else { - let mut line = String::new(); - std::io::stdin().read_line(&mut line)?; - line - }; - let pass = std::ffi::CString::new(pass.trim_end())?; // bind to keep the CString alive - let mut output: bch_key = unsafe { - bcachefs::derive_passphrase( - crypt as *const _ as *mut _, - pass.as_c_str().to_bytes_with_nul().as_ptr() as *const _, - ) - }; - - let mut key = crypt.key().clone(); - let ret = unsafe { - bch2_chacha_encrypt_key( - &mut output as *mut _, - sb.sb().nonce(), - &mut key as *mut _ as *mut _, - std::mem::size_of::() as usize, - ) - }; - if ret != 0 { - Err(anyhow!("chacha decryption failure")) - } else if key.magic != bch_key_magic { - Err(anyhow!("failed to verify the password")) - } else { - let key_type = c_str!("user"); - let ret = unsafe { - bch_bindgen::keyutils::add_key( - key_type, - key_name.as_c_str().to_bytes_with_nul() as *const _ as *const c_char, - &output as *const _ as *const _, - std::mem::size_of::() as usize, - bch_bindgen::keyutils::KEY_SPEC_USER_KEYRING, - ) - }; - if ret == -1 { - Err(anyhow!("failed to add key to keyring: {}", errno::errno())) - } else { - Ok(()) - } - } -} - -pub fn prepare_key(sb: &bch_sb_handle, password: KeyLocation) -> anyhow::Result<()> { - info!("checking if key exists for filesystem {}", sb.sb().uuid()); - match password { - KeyLocation::Fail => Err(anyhow!("no key available")), - KeyLocation::Wait => Ok(wait_for_key(&sb.sb().uuid())?), - KeyLocation::Ask => ask_for_key(sb), - _ => Err(anyhow!("no keyoption specified for locked filesystem")), - } -} -- cgit v1.2.3