Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pub fn inode_get_project(inode: u64) -> u16 {
(inode >> 48) as u16
}
pub fn inode_get_category(inode: u64) -> u8 {
((inode >> 40) & 0xff) as u8
}
pub fn inode_get_item(inode: u64) -> u32 {
((inode >> 8) & 0xffffffff) as u32
}
pub fn inode_get_reserved(inode: u64) -> u8 {
(inode & 0xff) as u8
}
pub fn inode_create(project: u16, category: u8, item: u32, reserved: u8) -> u64 {
let inode: u64 = ((project as u64) << 48) | ((category as u64) << 40) | ((item as u64) << 8) | (reserved as u64);
return inode;
}
fn main() {
// let inode = inode_create(1, 2, 3, 4);
// println!("{}, {}", inode_get_project(inode), inode_get_category(inode));
// let inode: u64 = (65535 << 48) + (255 << 40) + (0xffffffff << 8) + 255;
let inode = inode_create(65535, 255, 0xffffffff, 255);
println!("project - {}", inode_get_project(inode));
println!("category - {}", inode_get_category(inode));
println!("item - {}", inode_get_item(inode));
println!("reserved - {}", inode_get_reserved(inode));
// println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment