]> git.sesse.net Git - bcachefs-tools-debian/blob - bch_bindgen/src/bcachefs.rs
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / bch_bindgen / src / bcachefs.rs
1 #![allow(non_upper_case_globals)]
2 #![allow(non_camel_case_types)]
3 #![allow(non_snake_case)]
4 #![allow(unused)]
5
6 include!(concat!(env!("OUT_DIR"), "/bcachefs.rs"));
7
8 use bitfield::bitfield;
9 bitfield! {
10     pub struct bch_scrypt_flags(u64);
11     pub N, _: 15, 0;
12     pub R, _: 31, 16;
13     pub P, _: 47, 32;
14 }
15 bitfield! {
16     pub struct bch_crypt_flags(u64);
17     pub TYPE, _: 4, 0;
18 }
19 use memoffset::offset_of;
20 impl bch_sb_field_crypt {
21     pub fn scrypt_flags(&self) -> Option<bch_scrypt_flags> {
22         use std::convert::TryInto;
23         match bch_kdf_types(bch_crypt_flags(self.flags).TYPE().try_into().ok()?) {
24             bch_kdf_types::BCH_KDF_SCRYPT => Some(bch_scrypt_flags(self.kdf_flags)),
25             _ => None,
26         }
27     }
28     pub fn key(&self) -> &bch_encrypted_key {
29         &self.key
30     }
31 }
32 impl PartialEq for bch_sb {
33     fn eq(&self, other: &Self) -> bool {
34         self.magic.b == other.magic.b
35             && self.user_uuid.b == other.user_uuid.b
36             && self.block_size == other.block_size
37             && self.version == other.version
38             && self.uuid.b == other.uuid.b
39             && self.seq == other.seq
40     }
41 }
42
43 impl bch_sb {
44     pub fn crypt(&self) -> Option<&bch_sb_field_crypt> {
45         unsafe {
46             let ptr = bch2_sb_field_get_id(
47                 self as *const _ as *mut _,
48                 bch_sb_field_type::BCH_SB_FIELD_crypt,
49             ) as *const u8;
50             if ptr.is_null() {
51                 None
52             } else {
53                 let offset = offset_of!(bch_sb_field_crypt, field);
54                 Some(&*((ptr.sub(offset)) as *const _))
55             }
56         }
57     }
58     pub fn uuid(&self) -> uuid::Uuid {
59         uuid::Uuid::from_bytes(self.user_uuid.b)
60     }
61
62     /// Get the nonce used to encrypt the superblock
63     pub fn nonce(&self) -> nonce {
64         use byteorder::{LittleEndian, ReadBytesExt};
65         let mut internal_uuid = &self.uuid.b[..];
66         let dword1 = internal_uuid.read_u32::<LittleEndian>().unwrap();
67         let dword2 = internal_uuid.read_u32::<LittleEndian>().unwrap();
68         nonce {
69             d: [0, 0, dword1, dword2],
70         }
71     }
72 }
73 impl bch_sb_handle {
74     pub fn sb(&self) -> &bch_sb {
75         unsafe { &*self.sb }
76     }
77
78     pub fn bdev(&self) -> &block_device {
79         unsafe { &*self.bdev }
80     }
81 }
82
83 // #[repr(u8)]
84 pub enum rhash_lock_head {}
85 pub enum srcu_struct {}