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
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()
59 pub fn crypt(&self) -> Option<&bch_sb_field_crypt> {
61 let ptr = bch2_sb_field_get(self as *const _ as *mut _, bch_sb_field_type::BCH_SB_FIELD_crypt) as *const u8;
65 let offset = offset_of!(bch_sb_field_crypt, field);
66 Some(&*((ptr.sub(offset)) as *const _))
70 pub fn uuid(&self) -> uuid::Uuid {
71 uuid::Uuid::from_bytes(self.user_uuid.b)
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();
81 d: [0, 0, dword1, dword2],
86 pub fn sb(&self) -> &bch_sb {
90 pub fn bdev(&self) -> &block_device {
91 unsafe { &*self.bdev }
97 #[derive(Debug, Default, Copy, Clone)]
98 pub struct bch_extent_ptr {
99 pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
102 #[repr(C, packed(8))]
103 pub struct btree_node {
109 pub _ptr: bch_extent_ptr,
110 pub format: bkey_format,
111 pub __bindgen_anon_1: btree_node__bindgen_ty_1,
114 #[repr(C, packed(8))]
116 #[derive(Debug, Default, Copy, Clone)]
117 pub struct bch_extent_crc32 {
118 pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>,
123 pub enum rhash_lock_head {}
124 pub enum srcu_struct {}