summaryrefslogtreecommitdiff
path: root/rust-src/src/lib.rs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-01-03 22:31:36 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-21 01:03:08 -0500
commit28f703cc256fb6ae209aba1d1fe509d603de1735 (patch)
tree220fc0e14cd29a3b56fe18dc8594d7bb4fe66718 /rust-src/src/lib.rs
parentda6a35689518599b381c285cd9505ab8d58f7c73 (diff)
Rust now integrated into bcachefs binary
Rust is now required for building the bcachefs tool, and rust code is now fully integrated with the C codebase - meaning it is possible to call back and forth. The mount helper is now a subcommand, 'mount.bcachefs' is now a small shell wrapper that invokes 'bcachefs mount'. This will make it easier to start rewriting other subcommands in rust, and eventually the whole command line interface. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'rust-src/src/lib.rs')
-rw-r--r--rust-src/src/lib.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/rust-src/src/lib.rs b/rust-src/src/lib.rs
new file mode 100644
index 00000000..b2f0aaa7
--- /dev/null
+++ b/rust-src/src/lib.rs
@@ -0,0 +1,33 @@
+pub mod filesystem;
+pub mod key;
+pub mod cmd_mount;
+
+pub mod err {
+ pub enum GError {
+ Unknown {
+ message: std::borrow::Cow<'static, String>,
+ },
+ }
+ pub type GResult<T, E, OE> = ::core::result::Result<::core::result::Result<T, E>, OE>;
+ pub type Result<T, E> = GResult<T, E, GError>;
+}
+
+#[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
+ }
+ };
+}
+
+#[derive(Debug)]
+struct ErrnoError(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 {}