blob: b650ba9c81b788cf54a486cb095fdf889fc01434 [file] [log] [blame]
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[repr(C, packed)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Superblock {
pub magic0: u64,
pub magic1: u64,
pub version: u32,
pub flags: u32,
pub block_size: u32,
pub unused: u32,
pub data_block_count: u64,
pub journal_block_count: u64,
pub inode_count: u64,
pub alloc_block_count: u64,
pub alloc_inode_count: u64,
}
#[repr(C, packed)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Extent {
pub size: u16,
pub offset_hi: u16,
pub offset_lo: u32,
}
impl Extent {
pub fn offset(&self) -> usize {
//let hi = self.offset_hi as usize;
//let lo = self.offset_lo as usize;
//return (hi << 32) | lo;
return self.offset_lo as usize;
}
}
#[repr(C, packed)]
#[derive(Debug, Copy, Clone, Default)]
pub struct NodeHeader {
pub flags: u16,
pub version: u16,
pub next_node: u32,
}
impl NodeHeader {
pub const FLAG_INODE: u16 = 0b0000000000000001;
pub const FLAG_EXTENT: u16 = 0b0000000000000010;
}
#[repr(C, packed)]
#[derive(Debug, Copy, Clone, Default)]
pub struct Inode {
pub header: NodeHeader,
pub hash0: u64,
pub hash1: u64,
pub hash2: u64,
pub hash3: u64,
pub blob_size: u64,
pub block_count: u32,
pub extent_count: u16,
pub padding: u16,
pub inline_extent: Extent,
}
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct ExtentContainer {
pub header: NodeHeader,
pub previous_node: u32,
pub extent_count: u16,
pub reserved: u16,
pub extents: [Extent; 6],
}
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct Transaction {
pub op: u16,
pub size: u16,
pub addr: u32,
}
#[test]
fn size_check() {
use core::mem::*;
assert_eq!(size_of::<Extent>(), 8);
assert_eq!(size_of::<Inode>(), 64);
assert_eq!(size_of::<ExtentContainer>(), 64);
}