1 #![allow(non_upper_case_globals)]
2 #![allow(non_camel_case_types)]
3 #![allow(non_snake_case)]
6 include!(concat!(env!("OUT_DIR"), "/bcachefs.rs"));
8 use bitfield::bitfield;
10 pub struct bch_scrypt_flags(u64);
16 pub struct bch_crypt_flags(u64);
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)),
28 pub fn key(&self) -> &bch_encrypted_key {
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
44 pub fn crypt(&self) -> Option<&bch_sb_field_crypt> {
46 let ptr = bch2_sb_field_get_id(
47 self as *const _ as *mut _,
48 bch_sb_field_type::BCH_SB_FIELD_crypt,
53 let offset = offset_of!(bch_sb_field_crypt, field);
54 Some(&*((ptr.sub(offset)) as *const _))
58 pub fn uuid(&self) -> uuid::Uuid {
59 uuid::Uuid::from_bytes(self.user_uuid.b)
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();
69 d: [0, 0, dword1, dword2],
74 pub fn sb(&self) -> &bch_sb {
78 pub fn bdev(&self) -> &block_device {
79 unsafe { &*self.bdev }
85 #[derive(Debug, Default, Copy, Clone)]
86 pub struct bch_extent_ptr {
87 pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
91 pub struct btree_node {
97 pub _ptr: bch_extent_ptr,
98 pub format: bkey_format,
99 pub __bindgen_anon_1: btree_node__bindgen_ty_1,
102 #[repr(C, packed(8))]
104 #[derive(Debug, Default, Copy, Clone)]
105 pub struct bch_extent_crc32 {
106 pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>,
111 pub enum rhash_lock_head {}
112 pub enum srcu_struct {}