]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/bch_bindgen/src/bcachefs.rs
New upstream snapshot
[bcachefs-tools-debian] / rust-src / 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 std::fmt::Debug for bch_sb {
44         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45                 f.debug_struct("bch_sb")
46                         .field("uuid", &self.uuid())
47                         .field("version", &(self.version, self.version_min))
48                         .field("block_size", &self.block_size)
49                         .field("device_idx", &self.dev_idx)
50                         .field("seq", &self.seq)
51                         .field("csum", &(self.csum.lo, self.csum.hi))
52                         .field("offset", &self.offset)
53                 .finish_non_exhaustive()
54     }
55 }
56
57
58 impl bch_sb {
59         pub fn crypt(&self) -> Option<&bch_sb_field_crypt> {
60                 unsafe {
61                         let ptr = bch2_sb_field_get(self as *const _ as *mut _, bch_sb_field_type::BCH_SB_FIELD_crypt) as *const u8;
62                         if ptr.is_null() {
63                                 None
64                         } else {
65                                 let offset = offset_of!(bch_sb_field_crypt, field);
66                                 Some(&*((ptr.sub(offset)) as *const _))
67                         }
68                 }
69         }
70         pub fn uuid(&self) -> uuid::Uuid {
71                 uuid::Uuid::from_bytes(self.user_uuid.b)
72         }
73
74         /// Get the nonce used to encrypt the superblock
75         pub fn nonce(&self) -> nonce {
76                 use byteorder::{LittleEndian, ReadBytesExt};
77                 let mut internal_uuid = &self.uuid.b[..];
78                 let dword1 = internal_uuid.read_u32::<LittleEndian>().unwrap();
79                 let dword2 = internal_uuid.read_u32::<LittleEndian>().unwrap();
80                 nonce {
81                         d: [0, 0, dword1, dword2],
82                 }
83         }
84 }
85 impl bch_sb_handle {
86         pub fn sb(&self) -> &bch_sb {
87                 unsafe { &*self.sb }
88         }
89
90         pub fn bdev(&self) -> &block_device {
91                 unsafe { &*self.bdev }
92         }
93 }
94
95 #[repr(C)]
96 // #[repr(align(8))]
97 #[derive(Debug, Default, Copy, Clone)]
98 pub struct bch_extent_ptr {
99         pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
100 }
101
102 #[repr(C, packed(8))]
103 pub struct btree_node {
104         pub csum: bch_csum,
105         pub magic: __le64,
106         pub flags: __le64,
107         pub min_key: bpos,
108         pub max_key: bpos,
109         pub _ptr: bch_extent_ptr,
110         pub format: bkey_format,
111         pub __bindgen_anon_1: btree_node__bindgen_ty_1,
112 }
113
114 #[repr(C, packed(8))]
115 // #[repr(align(8))]
116 #[derive(Debug, Default, Copy, Clone)]
117 pub struct bch_extent_crc32 {
118         pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>,
119         pub csum: __u32,
120 }
121
122 // #[repr(u8)]
123 pub enum rhash_lock_head {}
124 pub enum srcu_struct {}