mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-24 00:00:19 +03:00
In an effort to rewrite `bch2_read_super` from C to Rust, it is neccessary to have `opt_get!` macro defined, and some FMODE_* consts (defined as macro in `include/linux/blkdev.h`) defined as Rust const. Bindgen is currently unable to exapnd C functional macro [1], this this commit use the workaround as introduced in [2]. [1] https://github.com/rust-lang/rust-bindgen/issues/753 [2] https://github.com/rust-lang/rust-bindgen/issues/753#issuecomment-608546390 Signed-off-by: TruongSinh Tran-Nguyen <i@truongsinh.pro>
36 lines
754 B
Rust
36 lines
754 B
Rust
#[macro_export]
|
|
macro_rules! opt_set {
|
|
($opts:ident, $n:ident, $v:expr) => {
|
|
bch_bindgen::paste! {
|
|
$opts.$n = $v;
|
|
$opts.[<set_ $n _defined>](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
|
|
}
|
|
}
|
|
};
|
|
}
|